NewInspectorPanelView.st
changeset 39 03af455029eb
parent 35 6f1565819b63
child 327 0040d47658c6
equal deleted inserted replaced
38:7b75ce74d9e1 39:03af455029eb
    13 examples
    13 examples
    14 "
    14 "
    15     example 1
    15     example 1
    16     =========
    16     =========
    17 
    17 
       
    18                                                                         [exBegin]
    18     |top slv|
    19     |top slv|
    19 
    20 
    20     top := StandardSystemView new extent:600@400.
    21     top := StandardSystemView new extent:600@400.
    21     slv := NewInspector::InspectorPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    22     slv := NewInspector::InspectorPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
    22     slv inspect:top.
    23     slv inspect:top.
    23     slv action:[:el|Transcript showCR:el].
    24     slv action:[:el|Transcript showCR:el].
    24     top open.
    25     top open.
       
    26                                                                         [exEnd]
    25 
    27 
    26 
    28 
    27     example 2
    29     example 2
    28     =========
    30     =========
    29 
    31                                                                         [exBegin]
    30     |top slv edt a vvp|
    32     |top slv edt a vvp|
    31 
    33 
    32     a := Array new:5.
    34     a := Array new:5.
    33     a at:4 put:(Array new:6).
    35     a at:4 put:(Array new:6).
    34 
    36 
    42 
    44 
    43     slv action:[:el| Transcript showCR:(el printString)].
    45     slv action:[:el| Transcript showCR:(el printString)].
    44     slv inspect:a.
    46     slv inspect:a.
    45 
    47 
    46     top open.
    48     top open.
    47 
    49                                                                         [exEnd]
    48 
       
    49 
       
    50 "
    50 "
    51 ! !
    51 ! !
    52 
    52 
    53 !InspectorPanelView class methodsFor:'constants'!
    53 !InspectorPanelView class methodsFor:'constants'!
    54 
    54 
    55 minDepth
    55 minDepth
    56     "returns the maximum of views
    56     "returns the minimum of views assigned to a panel
    57     "
    57     "
    58     ^ 4
    58     ^ 4
    59 ! !
    59 ! !
    60 
    60 
    61 !InspectorPanelView methodsFor:'accessing'!
    61 !InspectorPanelView methodsFor:'accessing'!
   136 !InspectorPanelView methodsFor:'accessing selections'!
   136 !InspectorPanelView methodsFor:'accessing selections'!
   137 
   137 
   138 inspectedObject
   138 inspectedObject
   139     "returns the current inspected object
   139     "returns the current inspected object
   140     "
   140     "
   141     |i el|
   141     ^ self findLastValidListWithSelection inspectedObject
   142 
       
   143     rightHistory notEmpty ifTrue:[
       
   144         el := rightHistory last
       
   145     ] ifFalse:[
       
   146         el := listViews findLast:[:v|v hasSelection].
       
   147         el := listViews at:el.
       
   148     ].
       
   149     ^ el inspectedObject
       
   150 !
   142 !
   151 
   143 
   152 selectedInstanceVar
   144 selectedInstanceVar
   153     "returns the current selected instance var
   145     "returns the current selected instance var
   154     "
   146     "
   155     |el|
   147     ^ self findLastValidListWithSelection selectedInstanceVar
   156 
       
   157     rightHistory notEmpty ifTrue:[
       
   158         el := rightHistory last
       
   159     ] ifFalse:[
       
   160         el := listViews findLast:[:v|v hasSelection].
       
   161         el := listViews at:el
       
   162     ].
       
   163     ^ el selectedInstanceVar
       
   164 ! !
   148 ! !
   165 
   149 
   166 !InspectorPanelView methodsFor:'actions'!
   150 !InspectorPanelView methodsFor:'actions'!
   167 
   151 
   168 accept:aText notifying:aView
   152 accept:aText notifying:aView
   169     self doItOrAccept:[:v|v accept:aText notifying:aView]
   153     "evaluating aText on the last selected instance var. on success the views
       
   154      are updated.
       
   155     "
       
   156     self doItOrAccept:[:aList|aList accept:aText notifying:aView]
   170 !
   157 !
   171 
   158 
   172 doIt:aCode notifying:aView
   159 doIt:aCode notifying:aView
   173     ^ self doItOrAccept:[:v|v doIt:aCode notifying:aView]
   160     "evaluating aCode on the selected instance var; on success the views
       
   161      are updated.
       
   162     "
       
   163     ^ self doItOrAccept:[:aList|aList doIt:aCode notifying:aView]
   174 !
   164 !
   175 
   165 
   176 inspect:anObject
   166 inspect:anObject
   177     "change the inspected object
   167     "change the inspected object and all views
   178     "
   168     "
   179     |view|
   169     |view|
   180 
   170 
   181     view := listViews first.
   171     view := listViews first.
   182     leftHistory  removeAll.
   172     leftHistory  removeAll.
   188 ! !
   178 ! !
   189 
   179 
   190 !InspectorPanelView methodsFor:'event handling'!
   180 !InspectorPanelView methodsFor:'event handling'!
   191 
   181 
   192 handlesKeyPress:key inView:someView
   182 handlesKeyPress:key inView:someView
       
   183     "all keys are handled by this instance itself
       
   184     "
   193     ^ true
   185     ^ true
   194 
   186 
   195 !
   187 !
   196 
   188 
   197 keyPress:key x:x y:y view:someView
   189 keyPress:key x:x y:y view:someView
   198 
   190     "handle some special keys
       
   191     "
   199     key == #CursorLeft  ifTrue:[^ self moveContentsRight:1].
   192     key == #CursorLeft  ifTrue:[^ self moveContentsRight:1].
   200     key == #CursorRight ifTrue:[^ self moveContentsLeft:1 ].
   193     key == #CursorRight ifTrue:[^ self moveContentsLeft:1 ].
   201 
   194 
   202     someView keyPress:key x:x y:y.
   195     someView keyPress:key x:x y:y.
   203 
   196 
   204 !
   197 !
   205 
   198 
   206 singleClickAt:anIndex
   199 singleClickAt:anIndex
   207     "the view changed its selection caused by a single click
   200     "the view at an index changed its selection caused by a single click
   208     "
   201     "
   209     |view start sivar|
   202     |view start sivar|
   210 
   203 
   211     rightHistory removeAll.
   204     rightHistory removeAll.
   212 
   205 
   484 
   477 
   485     view := listViews at:anIndex.
   478     view := listViews at:anIndex.
   486     view hasSelection ifFalse:[^ nil].
   479     view hasSelection ifFalse:[^ nil].
   487     inst := view selectedInstanceVar.
   480     inst := view selectedInstanceVar.
   488 
   481 
   489     menu := PopUpMenu labels:#( 'update' '-')
   482     menu := PopUpMenu labels:#( 'update' )
   490                    selectors:#( #update  nil)
   483                    selectors:#( #update  )
   491                     receiver:self.
   484                     receiver:self.
   492 
   485 
   493     menu actionAt:#update put:[
   486     menu actionAt:#update put:[
   494         view updateList.
   487         view update.
   495 
   488 
   496         listViews from:(anIndex + 1) do:[:v|
   489         listViews from:(anIndex + 1) do:[:v|
   497             (view selectedInstanceType) ~~ #directory ifTrue:[
   490             (view selectedInstanceType) ~~ #directory ifTrue:[
   498                 v inspect:nil
   491                 v inspect:nil
   499             ] ifFalse:[
   492             ] ifFalse:[
   502             ]
   495             ]
   503         ].
   496         ].
   504         self update
   497         self update
   505     ].
   498     ].
   506 
   499 
       
   500     (InspectorList isTraceable:inst) ifFalse:[
       
   501         ^ menu
       
   502     ].
       
   503 
   507     menu  addLabels:#(
   504     menu  addLabels:#(
       
   505                       '-'
   508                       'trace'
   506                       'trace'
   509                       'trap'
   507                       'trap'
   510                       'untrace / untrap'
   508                       'untrace / untrap'
   511                      )
   509                      )
   512           selectors:#(
   510           selectors:#(
       
   511                       nil
   513                       trace
   512                       trace
   514                       trap
   513                       trap
   515                       untrace
   514                       untrace
   516                      ).
   515                      ).
   517 
   516 
   535 ! !
   534 ! !
   536 
   535 
   537 !InspectorPanelView methodsFor:'private'!
   536 !InspectorPanelView methodsFor:'private'!
   538 
   537 
   539 doItOrAccept:aBlock
   538 doItOrAccept:aBlock
   540     "handle a doIt or accept action
   539     "handle a doIt or accept action; on success all the folloed views are
   541     "
   540      updated
   542     |index view ivar rslt last stop|
   541     "
   543 
   542     |index list result instVar|
   544     last := listViews last.
   543 
   545     self moveContentsLeft:(rightHistory size).
   544     list    := self findLastValidListWithSelection.
   546 
   545     result  := aBlock value:list.
   547     last hasSelection ifTrue:[
   546     instVar := list selectedInstanceVar.
   548         self moveContentsLeft:1.
   547     index   := listViews findLast:[:v|v == list].
   549         index := (listViews size) - 1
   548 
   550     ] ifFalse:[
   549     (index ~~ 0 and:[index ~~ listViews size]) ifTrue:[
   551         index := listViews findLast:[:v|v hasSelection].
   550         index := index + 1.
   552     ].
   551         (list selectedInstanceType) == #directory ifTrue:[
       
   552             (listViews at:index) inspect:instVar
       
   553         ] ifFalse:[
       
   554             (listViews at:index) inspect:nil
       
   555         ].
       
   556         self update
       
   557     ].
       
   558     valueChangedAction notNil ifTrue:[
       
   559         valueChangedAction value:instVar
       
   560     ].
       
   561     ^ result
       
   562 !
       
   563 
       
   564 findLastValidListWithSelection
       
   565     "returns last valid list with a selection; if no selection exists in any
       
   566      view, the list assigned to the inspected object is returned
       
   567     "
       
   568     |index|
       
   569 
       
   570     rightHistory notEmpty ifTrue:[
       
   571         ^ rightHistory first
       
   572     ].
       
   573     index := listViews findLast:[:v| v hasSelection ].
   553 
   574 
   554     index ~~ 0 ifTrue:[
   575     index ~~ 0 ifTrue:[
   555         view := listViews at:index.
   576         ^ listViews at:index
   556         rslt := aBlock value:view.
   577     ].
   557         stop := listViews size.
   578 
   558         ivar := view selectedInstanceVar.
   579     leftHistory notEmpty ifTrue:[^ leftHistory last]
   559 
   580                         ifFalse:[^ listViews at:1]
   560         index == stop ifTrue:[
       
   561             self moveContentsLeft:1.
       
   562         ] ifFalse:[
       
   563             index := index + 1.
       
   564 
       
   565             (view selectedInstanceType) == #directory ifTrue:[
       
   566                 (listViews at:index) inspect:ivar
       
   567             ] ifFalse:[
       
   568                 (listViews at:index) inspect:nil
       
   569             ].
       
   570             self update.
       
   571         ].
       
   572 
       
   573         valueChangedAction notNil ifTrue:[
       
   574             valueChangedAction value:ivar
       
   575         ]
       
   576     ].
       
   577     ^ rslt
       
   578 !
   581 !
   579 
   582 
   580 update
   583 update
   581     "update labels and scrollbar
   584     "update labels and scrollbar
   582     "
   585     "
   646 
   649 
   647 
   650 
   648 !
   651 !
   649 
   652 
   650 createViewWithoutRedraw
   653 createViewWithoutRedraw
   651     "add a new view at end
   654     "add a new view at end of the panel
   652     "
   655     "
   653     |view frame label index|
   656     |view frame label index|
   654 
   657 
   655     frame := SimpleView in:hzpView.
   658     frame := SimpleView in:hzpView.
   656 
   659 
   686 ! !
   689 ! !
   687 
   690 
   688 !InspectorPanelView methodsFor:'scrolling-basic'!
   691 !InspectorPanelView methodsFor:'scrolling-basic'!
   689 
   692 
   690 moveContentsLeft:nTimes
   693 moveContentsLeft:nTimes
   691     "move the contents of each view one position left
   694     "move the contents of all views one position left
   692     "
   695     "
   693     |fView stop assoc inspObj pView index|
   696     |fView stop assoc inspObj pView index|
   694 
   697 
   695     (nTimes < 1 or:[listViews last isEmpty]) ifTrue:[
   698     (nTimes < 1 or:[listViews last isEmpty]) ifTrue:[
   696         ^ self
   699         ^ self
   700     stop  := (listViews size) - 1.
   703     stop  := (listViews size) - 1.
   701     fView := listViews first.
   704     fView := listViews first.
   702     pView := listViews at:stop.
   705     pView := listViews at:stop.
   703 
   706 
   704 
   707 
   705     [   leftHistory add:fView listHolder.
   708     [   leftHistory add:(fView list).
   706 
   709 
   707         1 to:stop do:[:i|
   710         1 to:stop do:[:i|
   708             (listViews at:i) updateFromView:(listViews at:(i+1))
   711             (listViews at:i) list:(listViews at:(i+1))
   709         ].
   712         ].
   710 
   713 
   711         rightHistory notEmpty ifTrue:[
   714         rightHistory notEmpty ifTrue:[
   712             (listViews last) updateFromList:(rightHistory removeLast)
   715             (listViews last) list:(rightHistory removeLast)
   713         ] ifFalse:[
   716         ] ifFalse:[
   714             (listViews last) inspect:(pView selectedInstanceVar)
   717             (listViews last) inspect:(pView selectedInstanceVar)
   715         ].
   718         ].
   716         ((index := index - 1) == 0 or:[listViews last isEmpty])
   719         ((index := index - 1) == 0 or:[listViews last isEmpty])
   717 
   720 
   722 
   725 
   723 
   726 
   724 !
   727 !
   725 
   728 
   726 moveContentsRight:nTimes
   729 moveContentsRight:nTimes
   727     "move the contents of all listViews one position right
   730     "move the contents of all views one position right
   728     "
   731     "
   729     |view assoc size index lView fView|
   732     |view assoc size index lView fView|
   730 
   733 
   731     size := leftHistory size.
   734     size := leftHistory size.
   732 
   735 
   738         lView := listViews last.
   741         lView := listViews last.
   739         fView := listViews first.
   742         fView := listViews first.
   740 
   743 
   741         1 to:index do:[:i|
   744         1 to:index do:[:i|
   742             lView hasSelection ifTrue:[
   745             lView hasSelection ifTrue:[
   743                 rightHistory add:(lView listHolder)
   746                 rightHistory add:(lView list)
   744             ].
   747             ].
   745             size to:2 by:-1 do:[:i|
   748             size to:2 by:-1 do:[:i|
   746                 (listViews at:i) updateFromView:(listViews at:(i-1))
   749                 (listViews at:i) list:(listViews at:(i-1))
   747             ].
   750             ].
   748             fView updateFromList:(leftHistory removeLast)
   751             fView list:(leftHistory removeLast)
   749         ].
   752         ].
   750         self update
   753         self update
   751     ]
   754     ]
   752 
   755 
   753 !
   756 !
   754 
   757 
   755 scrollTo:nPercent
   758 scrollTo:nPercent
   756     "set views dependant on scroll bar
   759     "set views and contents dependant on scroll bar
   757     "
   760     "
   758     |dY no noScr pR|
   761     |dY no noScr pR|
   759 
   762 
   760     noScr := listViews size + leftHistory size + rightHistory size.
   763     noScr := listViews size + leftHistory size + rightHistory size.
   761 
   764