Tools__ViewTreeApplication.st
changeset 2758 c61fe917957a
parent 2757 6c83d6b487b2
child 2759 d9a8fc3f0dc7
equal deleted inserted replaced
2757:6c83d6b487b2 2758:c61fe917957a
   751 ! !
   751 ! !
   752 
   752 
   753 !ViewTreeInspectorApplication methodsFor:'change & update'!
   753 !ViewTreeInspectorApplication methodsFor:'change & update'!
   754 
   754 
   755 selectionChanged
   755 selectionChanged
   756     "called if the selection changed"
       
   757 
       
   758     |info view item|
   756     |info view item|
   759 
   757 
   760     item := model selectedItem.
   758     item := model selectedItem.
   761 
   759 
   762     item notNil ifTrue:[ |state|
   760     item notNil ifTrue:[ |state|
   800 ! !
   798 ! !
   801 
   799 
   802 !ViewTreeInspectorApplication methodsFor:'event processing'!
   800 !ViewTreeInspectorApplication methodsFor:'event processing'!
   803 
   801 
   804 processButtonMotionEvent:ev
   802 processButtonMotionEvent:ev
   805     "handle a button motion event"
       
   806 
       
   807     |click rootView|
   803     |click rootView|
   808 
   804 
   809     motionAction isNil ifTrue:[^ self].
   805     motionAction isNil ifTrue:[^ self].
   810 
   806 
   811     (rootView := model rootView) isNil ifTrue:[
   807     (rootView := model rootView) isNil ifTrue:[
   824         ]
   820         ]
   825     ].
   821     ].
   826 !
   822 !
   827 
   823 
   828 processButtonPressEvent:ev
   824 processButtonPressEvent:ev
   829     "handle a buttopn press event"
       
   830 
       
   831     |rootView sensor lastRectangle|
   825     |rootView sensor lastRectangle|
   832 
   826 
   833     rootView    := model rootView.
   827     rootView    := model rootView.
   834     sensor      := model rootView sensor.
   828     sensor      := model rootView sensor.
   835     clickedItem := model listOfItems detectItemRespondsToView:(ev view).
   829     clickedItem := model listOfItems detectItemRespondsToView:(ev view).
   868         lastRectangle
   862         lastRectangle
   869     ].
   863     ].
   870 !
   864 !
   871 
   865 
   872 processButtonReleaseEvent:anEvent
   866 processButtonReleaseEvent:anEvent
   873     "handle a button release event"
       
   874 
       
   875     |rootView rectangle newItems widget origin|
   867     |rootView rectangle newItems widget origin|
   876 
   868 
   877     (rootView := model rootView) isNil ifTrue:[
   869     (rootView := model rootView) isNil ifTrue:[
   878         clickedItem := motionAction := nil.
   870         clickedItem := motionAction := nil.
   879         ^ self
   871         ^ self
   896     ].
   888     ].
   897     model value:newItems.
   889     model value:newItems.
   898 !
   890 !
   899 
   891 
   900 processEvent:anEvent
   892 processEvent:anEvent
   901     "process an event"
       
   902 
       
   903     |button menu|
   893     |button menu|
   904 
   894 
   905     anEvent isKeyPressEvent ifTrue:[ ^ self processKeyPressEvent:anEvent ].
   895     anEvent isKeyPressEvent ifTrue:[ self processKeyPressEvent:anEvent. ^ self  ].
   906     anEvent isButtonEvent  ifFalse:[ ^ self ].
   896     anEvent isButtonEvent  ifFalse:[ ^ self ].
   907 
   897 
   908     button := anEvent button.
   898     button := anEvent button.
   909 
   899 
   910     (button == 2 or:[button == #menu]) ifTrue:[
   900     (button == 2 or:[button == #menu]) ifTrue:[
   911         motionAction isNil ifTrue:[
   901         motionAction isNil ifTrue:[
   912             anEvent isButtonPressEvent ifTrue:[
   902             anEvent isButtonPressEvent ifTrue:[
   913                 self selectOnClickHolder value ifTrue:[
   903                 self selectOnClickHolder value ifTrue:[
   914                     menu := self middleButtonMenu value.
   904                     menu := self middleButtonMenu value.
   915                     menu notNil ifTrue:[
   905                     menu notNil ifTrue:[
   916                         menu := MenuPanel menu:(Menu new fromLiteralArrayEncoding:menu)
   906                         menu := MenuPanel 
   917                                       receiver:self.
   907                                     menu:(Menu new fromLiteralArrayEncoding:menu)
       
   908                                     receiver:self.
   918                         menu startUp.
   909                         menu startUp.
   919                     ]
   910                     ]
   920                 ].
   911                 ].
   921             ].
   912             ].
   922             clickedItem := nil.
   913             clickedItem := nil.
   923         ].
   914         ].
   924         ^ self
   915         ^ self
   925     ].
   916     ].
   926 
   917 
   927     anEvent isButtonPressEvent  ifTrue:[ ^ self processButtonPressEvent:anEvent  ].
   918     anEvent isButtonPressEvent  ifTrue:[ self processButtonPressEvent:anEvent. ^ self ].
   928     anEvent isButtonMotionEvent ifTrue:[ ^ self processButtonMotionEvent:anEvent ].
   919     anEvent isButtonMotionEvent ifTrue:[ self processButtonMotionEvent:anEvent. ^ self ].
   929 
   920 
   930     anEvent isButtonReleaseEvent ifTrue:[
   921     anEvent isButtonReleaseEvent ifTrue:[
   931         self selectOnClickHolder value ifTrue:[
   922         self selectOnClickHolder value ifTrue:[
   932             self processButtonReleaseEvent:anEvent
   923             self processButtonReleaseEvent:anEvent
   933         ].
   924         ].
   940         ].
   931         ].
   941     ].
   932     ].
   942 !
   933 !
   943 
   934 
   944 processKeyPressEvent:anEvent
   935 processKeyPressEvent:anEvent
   945     "process an key press event"
       
   946 
       
   947     |item prnt idx key max next|
   936     |item prnt idx key max next|
   948 
   937 
   949     key := anEvent key.
   938     key := anEvent key.
   950     key isSymbol ifFalse:[^ self].
   939     key isSymbol ifFalse:[^ self].
   951 
   940 
   969     prnt isNil ifTrue:[
   958     prnt isNil ifTrue:[
   970         "/ is the root item
   959         "/ is the root item
   971         (key == #CursorUp or:[key == #CursorLeft]) ifTrue:[item := model listOfItems last]
   960         (key == #CursorUp or:[key == #CursorLeft]) ifTrue:[item := model listOfItems last]
   972                                                   ifFalse:[item := item at:1 ifAbsent:item].
   961                                                   ifFalse:[item := item at:1 ifAbsent:item].
   973 
   962 
   974       ^ model selectedItem:item
   963         ^ model selectedItem:item
   975     ].
   964     ].
   976     key == #CursorLeft ifTrue:[ ^ model selectedItem:prnt ].
   965     key == #CursorLeft ifTrue:[ ^ model selectedItem:prnt ].
   977 
   966 
   978     key == #CursorRight ifTrue:[
   967     key == #CursorRight ifTrue:[
   979         next := item at:1 ifAbsent:nil.
   968         next := item at:1 ifAbsent:nil.
   980         next notNil ifTrue:[ model selectedItem:next ].
   969         next notNil ifTrue:[ model selectedItem:next ].
   981       ^ self
   970         ^ self
   982     ].
   971     ].
   983 
   972 
   984     max := prnt size.
   973     max := prnt size.
   985 
   974 
   986     key == #CursorUp ifTrue:[
   975     key == #CursorUp ifTrue:[
   987         idx := prnt identityIndexOf:item.
   976         idx := prnt identityIndexOf:item.
   988         idx == 1 ifTrue:[idx := max + 1].
   977         idx == 1 ifTrue:[idx := max + 1].
   989         model selectedItem:(prnt at:idx - 1).
   978         model selectedItem:(prnt at:idx - 1).
   990       ^ self.
   979         ^ self.
   991     ].
   980     ].
   992 
   981 
   993     key == #CursorDown ifTrue:[
   982     key == #CursorDown ifTrue:[
   994         idx := prnt identityIndexOf:item.
   983         idx := prnt identityIndexOf:item.
   995         idx == max ifTrue:[idx := 0].
   984         idx == max ifTrue:[idx := 0].
   996         model selectedItem:(prnt at:idx + 1).
   985         model selectedItem:(prnt at:idx + 1).
   997       ^ self.
   986         ^ self.
   998     ].
   987     ].
   999 !
   988 !
  1000 
   989 
  1001 processMappedView:aView
   990 processMappedView:aView
  1002     "process a mapped event"
       
  1003 
       
  1004     |parent anchor|
   991     |parent anchor|
  1005 
   992 
  1006     parent := self listOfItems detectItemRespondsToView:aView.
   993     parent := self listOfItems detectItemRespondsToView:aView.
  1007     parent isNil ifTrue:[ ^ self ].
   994     parent isNil ifTrue:[ ^ self ].
  1008 
   995 
  1091 !ViewTreeInspectorApplication methodsFor:'menu specs'!
  1078 !ViewTreeInspectorApplication methodsFor:'menu specs'!
  1092 
  1079 
  1093 middleButtonMenu
  1080 middleButtonMenu
  1094     "returns the middleButton menu for the single selected item or nil"
  1081     "returns the middleButton menu for the single selected item or nil"
  1095 
  1082 
  1096     ^ [ model selectedItem notNil ifTrue:[self class middleButtonMenu]
  1083     ^ [ 
  1097                                  ifFalse:[nil]
  1084         model selectedItem notNil 
       
  1085             ifTrue:[self class middleButtonMenu]
       
  1086             ifFalse:[nil]
  1098       ]
  1087       ]
  1099 !
  1088 !
  1100 
  1089 
  1101 submenuApplications:aMenu
  1090 submenuApplications:aMenu
  1102     |applications menu item list addBlock|
  1091     |applications menu item list addBlock|
  1280     value := nil.
  1269     value := nil.
  1281 
  1270 
  1282     inst isNil ifTrue:[
  1271     inst isNil ifTrue:[
  1283         label := nil
  1272         label := nil
  1284     ] ifFalse:[
  1273     ] ifFalse:[
  1285         inst == view ifTrue:[ label := '== view itself' ]
  1274         inst == view ifTrue:[ 
  1286                     ifFalse:[ label := inst displayString.
  1275             label := '== view itself' 
  1287                               value := [view controller inspect].
  1276         ] ifFalse:[ 
  1288                             ].
  1277             label := inst displayString.
       
  1278             value := [view controller inspect].
       
  1279         ].
  1289     ].
  1280     ].
  1290     list add:(MenuDesc title:'controller' value:label action:value).
  1281     list add:(MenuDesc title:'controller' value:label action:value).
  1291 
  1282 
  1292     inst := view delegate.
  1283     inst := view delegate.
  1293     inst notNil ifTrue:[
  1284     inst notNil ifTrue:[
  1294         list add:(MenuDesc title:'delegate' value:(inst displayString) action:[ view delegate inspect ]).
  1285         list add:(MenuDesc title:'delegate' value:(inst displayString) action:[ view delegate inspect ]).
  1295     ].
  1286     ].
  1296 
  1287 
  1297     inst := view application.
  1288     inst := view application.
  1298 
  1289 
  1299     inst notNil ifTrue:[ |topAppl|
  1290     inst notNil ifTrue:[ 
       
  1291         |topAppl|
       
  1292 
  1300         list add:(MenuDesc title:'application' value:inst action:[ view application inspect ]).
  1293         list add:(MenuDesc title:'application' value:inst action:[ view application inspect ]).
  1301 
  1294 
  1302         topAppl := inst topApplication.
  1295         topAppl := inst topApplication.
  1303 
  1296 
  1304         (topAppl notNil and:[topAppl ~~ inst]) ifTrue:[
  1297         (topAppl notNil and:[topAppl ~~ inst]) ifTrue:[
  1394         list add:(MenuDesc title:'visibilityChannel'
  1387         list add:(MenuDesc title:'visibilityChannel'
  1395                            value:(value displayString)
  1388                            value:(value displayString)
  1396                           action:[view visibilityChannel inspect]).
  1389                           action:[view visibilityChannel inspect]).
  1397     ].
  1390     ].
  1398 
  1391 
  1399         
  1392     ^ MenuDesc buildFromList:list onGC:aMenu
  1400   ^ MenuDesc buildFromList:list onGC:aMenu
       
  1401 ! !
  1393 ! !
  1402 
  1394 
  1403 !ViewTreeInspectorApplication methodsFor:'private'!
  1395 !ViewTreeInspectorApplication methodsFor:'private'!
  1404 
  1396 
  1405 selectFocusView
  1397 selectFocusView
  1768 
  1760 
  1769     value notNil ifTrue:[
  1761     value notNil ifTrue:[
  1770         array at:2 put:(value printString, ' ')
  1762         array at:2 put:(value printString, ' ')
  1771     ].
  1763     ].
  1772 
  1764 
  1773   ^ MenuItem label:(MultiColListEntry fromStrings:array tabulatorSpecification:aTabSpec)
  1765    ^ MenuItem 
  1774              value:action
  1766         label:(MultiColListEntry fromStrings:array tabulatorSpecification:aTabSpec)
       
  1767         value:action
  1775 ! !
  1768 ! !
  1776 
  1769 
  1777 !ViewTreeInspectorApplication::MenuDesc methodsFor:'instance creation'!
  1770 !ViewTreeInspectorApplication::MenuDesc methodsFor:'instance creation'!
  1778 
  1771 
  1779 title:aTitle value:aValue action:anAction
  1772 title:aTitle value:aValue action:anAction
  1798     ^ title isNil
  1791     ^ title isNil
  1799 !
  1792 !
  1800 
  1793 
  1801 widthOn:aGC
  1794 widthOn:aGC
  1802     title isNil ifTrue:[^ 5].  "/ separator
  1795     title isNil ifTrue:[^ 5].  "/ separator
  1803   ^ title widthOn:aGC
  1796     ^ title widthOn:aGC
  1804 ! !
  1797 ! !
  1805 
  1798 
  1806 !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'building'!
  1799 !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'building'!
  1807 
  1800 
  1808 buildViewsFrom:aView
  1801 buildViewsFrom:aView