MenuEditor.st
changeset 1020 dcfbf3acb037
parent 1007 98f4db3e2d23
child 1023 b804e9608a61
equal deleted inserted replaced
1019:1629a7eecb33 1020:dcfbf3acb037
   133      )
   133      )
   134 
   134 
   135     "Modified: / 14.8.1998 / 14:46:36 / cg"
   135     "Modified: / 14.8.1998 / 14:46:36 / cg"
   136 ! !
   136 ! !
   137 
   137 
       
   138 !MenuEditor class methodsFor:'defaults'!
       
   139 
       
   140 defaultRetrieverClassList
       
   141     ^ #(Icon NewLauncher BrowserView)
       
   142 
       
   143 
       
   144 ! !
       
   145 
   138 !MenuEditor class methodsFor:'help specs'!
   146 !MenuEditor class methodsFor:'help specs'!
   139 
   147 
   140 helpSpec
   148 helpSpec
   141     "This resource specification was automatically generated
   149     "This resource specification was automatically generated
   142      by the UIHelpTool of ST/X."
   150      by the UIHelpTool of ST/X."
   168 'An action selector with 0, 1 (the argument field), or 2 (the selected item) arguments.'
   176 'An action selector with 0, 1 (the argument field), or 2 (the selected item) arguments.'
   169 
   177 
   170 #basicsArgument
   178 #basicsArgument
   171 'An argument passed to above selector, if it is a 1 or a 2 argument selector.'
   179 'An argument passed to above selector, if it is a 1 or a 2 argument selector.'
   172 
   180 
       
   181 #basicsChoice
       
   182 'A boolean holder, a boolean block, or a boolean method, specifying the choices state.'
       
   183 
       
   184 #basicsChoiceValue
       
   185 'That choices value (typically number or symbol).'
       
   186 
   173 #basicsIndication
   187 #basicsIndication
   174 'A boolean holder, a boolean block, or a boolean method, specifying the indication state.'
   188 'A boolean holder, a boolean block, or a boolean method, specifying the indication state.'
   175 
   189 
   176 #basicsChoice
       
   177 'A boolean holder, a boolean block, or a boolean method, specifying the choices state.'
       
   178 
       
   179 #basicsChoiceValue
       
   180 'That choices value (typically number or symbol).'
       
   181 
       
   182 #basicsIsButton
   190 #basicsIsButton
   183 'Turns on/off a button behavior.'
   191 'Turns on/off a button behavior.'
   184 
   192 
       
   193 #basicsKey
       
   194 'Internal key of the item (optional, for programmed accesses).'
       
   195 
   185 #basicsLabel
   196 #basicsLabel
   186 'Label of the item.'
   197 'Label of the item.'
   187 
   198 
   188 #basicsKey
       
   189 'Internal key of the item (optional, for programmed accesses).'
       
   190 
       
   191 #basicsMenu
   199 #basicsMenu
   192 'A value holder providing the sub menu to be opened if item is selected.'
   200 'A value holder providing the sub menu to be opened if item is selected.'
   193 
   201 
   194 #basicsMenuArgument
   202 #basicsMenuArgument
   195 'An argument passed with the menu selector.'
   203 'An argument passed with the menu selector.'
   204 'List of valid separators.'
   212 'List of valid separators.'
   205 
   213 
   206 #basicsTranslateLabel
   214 #basicsTranslateLabel
   207 'Translate the label via the classes resource file (internationalization).'
   215 'Translate the label via the classes resource file (internationalization).'
   208 
   216 
       
   217 #browseResource
       
   218 'Search for methods with image resource.'
       
   219 
   209 #detailsAccelerator
   220 #detailsAccelerator
   210 'Key to be pressed to select the menu item from the keyboard (accelerator key).'
   221 'Key to be pressed to select the menu item from the keyboard (accelerator key).'
   211 
   222 
   212 #detailsAccessCharaterPosition
   223 #detailsAccessCharaterPosition
   213 'Index of the access character position of the textual label (optional).'
   224 'Index of the access character position of the textual label (optional).'
   234 'Saves the menu spec (and the help spec, if modified).'
   245 'Saves the menu spec (and the help spec, if modified).'
   235 
   246 
   236 #fileSaveAs
   247 #fileSaveAs
   237 'Opens a dialog to save the menu spec (and the help spec, if modified).'
   248 'Opens a dialog to save the menu spec (and the help spec, if modified).'
   238 
   249 
   239 #historyMenuItem
       
   240 'Edit this menu specification.'
       
   241 
       
   242 #imageImageAndLabel
   250 #imageImageAndLabel
   243 'Toggles display of both image and textual label.'
   251 'Toggles display of both image and textual label.'
   244 
   252 
   245 #imageImageEditor
   253 #imageImageEditor
   246 'Opens an Image Editor on the resource method defined by retriever and selector.'
   254 'Opens an Image Editor on the resource method defined by retriever and selector.'
   247 
   255 
       
   256 #imageImageList
       
   257 'Currently existing image resources.'
       
   258 
   248 #imageRetriever
   259 #imageRetriever
   249 'Class implementing the image resource method. If no class is given, the current application class will be taken.'
   260 'Class implementing the image resource method. If no class is given, the current application class will be taken.'
   250 
   261 
   251 #imageSelector
   262 #imageSelector
   252 'Selector returning an image (sent to above or the application).'
   263 'Selector returning an image (sent to above or the application).'
   253 
   264 
   254 #imageImageList
       
   255 'Currently existing image resources.'
       
   256 
       
   257 #test
       
   258 'Displays the current menu (layout test).'
       
   259 )
   265 )
   260 
       
   261     "Modified: / 18.8.1998 / 16:19:13 / cg"
       
   262 ! !
   266 ! !
   263 
   267 
   264 !MenuEditor class methodsFor:'image specs'!
   268 !MenuEditor class methodsFor:'image specs'!
   265 
   269 
   266 linkSubmenuImage
   270 linkSubmenuImage
   999      
  1003      
  1000        #(#FullSpec
  1004        #(#FullSpec
  1001           #window: 
  1005           #window: 
  1002            #(#WindowSpec
  1006            #(#WindowSpec
  1003               #name: 'Image Item'
  1007               #name: 'Image Item'
  1004               #layout: #(#LayoutFrame 182 0 348 0 577 0 624 0)
  1008               #layout: #(#LayoutFrame 25 0 119 0 420 0 395 0)
  1005               #label: 'Image Item'
  1009               #label: 'Image Item'
  1006               #min: #(#Point 10 10)
  1010               #min: #(#Point 10 10)
  1007               #max: #(#Point 1280 1024)
  1011               #max: #(#Point 1280 1024)
  1008               #bounds: #(#Rectangle 182 348 578 625)
  1012               #bounds: #(#Rectangle 25 119 421 396)
  1009               #usePreferredExtent: false
  1013               #usePreferredExtent: false
  1010           )
  1014           )
  1011           #component: 
  1015           #component: 
  1012            #(#SpecCollection
  1016            #(#SpecCollection
  1013               #collection: 
  1017               #collection: 
  1023                  #(#LabelSpec
  1027                  #(#LabelSpec
  1024                     #name: 'retrieverLabel'
  1028                     #name: 'retrieverLabel'
  1025                     #layout: #(#AlignmentOrigin 107 0 26 0 1 0.5)
  1029                     #layout: #(#AlignmentOrigin 107 0 26 0 1 0.5)
  1026                     #activeHelpKey: #imageRetriever
  1030                     #activeHelpKey: #imageRetriever
  1027                     #label: 'Retriever:'
  1031                     #label: 'Retriever:'
       
  1032                     #resizeForLabel: true
  1028                     #adjust: #right
  1033                     #adjust: #right
  1029                     #resizeForLabel: true
  1034                 )
  1030                 )
  1035                  #(#ComboBoxSpec
  1031                  #(#InputFieldSpec
       
  1032                     #name: 'retrieverField'
  1036                     #name: 'retrieverField'
  1033                     #layout: #(#LayoutFrame 110 0 15 0 -5 1.0 37 0)
  1037                     #layout: #(#LayoutFrame 110 0 15 0 0 1.0 37 0)
  1034                     #activeHelpKey: #imageRetriever
  1038                     #activeHelpKey: #imageRetriever
  1035                     #tabable: true
  1039                     #tabable: true
  1036                     #model: #retriever
  1040                     #model: #retriever
  1037                     #type: #symbolOrNil
  1041                     #type: #symbolOrNil
  1038                     #acceptOnReturn: false
  1042                     #acceptOnReturn: false
  1039                     #acceptOnTab: false
  1043                     #acceptOnTab: false
  1040                     #group: #inputGroup
  1044                     #comboList: #retrieverClassList
  1041                 )
  1045                 )
  1042                  #(#LabelSpec
  1046                  #(#LabelSpec
  1043                     #name: 'iconLabel'
  1047                     #name: 'iconLabel'
  1044                     #layout: #(#AlignmentOrigin 107 0 51 0 1 0.5)
  1048                     #layout: #(#AlignmentOrigin 107 0 51 0 1 0.5)
  1045                     #activeHelpKey: #imageSelector
  1049                     #activeHelpKey: #imageSelector
  1046                     #label: 'Selector:'
  1050                     #label: 'Selector:'
       
  1051                     #resizeForLabel: true
  1047                     #adjust: #right
  1052                     #adjust: #right
  1048                     #resizeForLabel: true
       
  1049                 )
  1053                 )
  1050                  #(#InputFieldSpec
  1054                  #(#InputFieldSpec
  1051                     #name: 'iconField'
  1055                     #name: 'iconField'
  1052                     #layout: #(#LayoutFrame 110 0 40 0 -5 1.0 62 0)
  1056                     #layout: #(#LayoutFrame 110 0 40 0 -31 1.0 62 0)
  1053                     #activeHelpKey: #imageSelector
  1057                     #activeHelpKey: #imageSelector
  1054                     #tabable: true
  1058                     #tabable: true
  1055                     #model: #icon
  1059                     #model: #icon
       
  1060                     #group: #inputGroup
  1056                     #type: #symbolOrNil
  1061                     #type: #symbolOrNil
  1057                     #acceptOnReturn: false
  1062                     #acceptOnReturn: false
  1058                     #acceptOnTab: false
  1063                     #acceptOnTab: false
  1059                     #group: #inputGroup
       
  1060                 )
  1064                 )
  1061                  #(#ActionButtonSpec
  1065                  #(#ActionButtonSpec
  1062                     #name: 'imageEditorButton'
  1066                     #name: 'imageEditorButton'
  1063                     #layout: #(#LayoutFrame 5 0.6 67 0 -5 1 91 0)
  1067                     #layout: #(#LayoutFrame 19 0.6 128 0 -5 1 152 0)
  1064                     #activeHelpKey: #imageImageEditor
  1068                     #activeHelpKey: #imageImageEditor
  1065                     #label: 'Image Editor'
  1069                     #label: 'Image Editor'
  1066                     #tabable: true
  1070                     #tabable: true
  1067                     #model: #doEditImage
  1071                     #model: #doEditImage
  1068                 )
  1072                 )
  1069                  #(#SequenceViewSpec
  1073                  #(#SequenceViewSpec
  1070                     #name: 'systemOrUserImagesList'
  1074                     #name: 'systemOrUserImagesList'
       
  1075                     #layout: #(#LayoutFrame 22 0 67 0 11 0.6 200 0)
  1071                     #activeHelpKey: #imageImageList
  1076                     #activeHelpKey: #imageImageList
  1072                     #layout: #(#LayoutFrame 110 0 67 0 0 0.6 200 0)
       
  1073                     #model: #selectionOfImage
  1077                     #model: #selectionOfImage
  1074                     #menu: #menuEditImage
  1078                     #menu: #menuEditImage
  1075                     #hasHorizontalScrollBar: true
  1079                     #hasHorizontalScrollBar: true
  1076                     #hasVerticalScrollBar: true
  1080                     #hasVerticalScrollBar: true
  1077                     #miniScrollerHorizontal: true
  1081                     #miniScrollerHorizontal: true
  1078                     #doubleClickSelector: #doEditImage
  1082                     #doubleClickSelector: #doEditImage
  1079                     #valueChangeSelector: #imageSelected
  1083                     #valueChangeSelector: #imageSelected
  1080                     #useIndex: false
  1084                     #useIndex: false
  1081                     #sequenceList: #listOfImages
  1085                     #sequenceList: #listOfImages
  1082                 )
  1086                 )
       
  1087                  #(#ActionButtonSpec
       
  1088                     #name: 'browseButton'
       
  1089                     #layout: #(#LayoutFrame -26 1 41 0 -2 1 63 0)
       
  1090                     #activeHelpKey: #browseResource
       
  1091                     #label: '...'
       
  1092                     #model: #doBrowseForImageResource
       
  1093                 )
  1083               )
  1094               )
  1084           )
  1095           )
  1085       )
  1096       )
  1086 
       
  1087     "Modified: / 18.8.1998 / 16:17:59 / cg"
       
  1088 !
  1097 !
  1089 
  1098 
  1090 windowSpec
  1099 windowSpec
  1091     "This resource specification was automatically generated
  1100     "This resource specification was automatically generated
  1092      by the UIPainter of ST/X."
  1101      by the UIPainter of ST/X."
  1768      ].
  1777      ].
  1769 
  1778 
  1770      aClass isSymbol 
  1779      aClass isSymbol 
  1771         ifTrue:  [iconClass := Smalltalk at: aClass]
  1780         ifTrue:  [iconClass := Smalltalk at: aClass]
  1772         ifFalse: [iconClass := aClass].
  1781         ifFalse: [iconClass := aClass].
       
  1782      aClass isBehavior ifFalse:[
       
  1783         ^ #()
       
  1784      ].
  1773 
  1785 
  1774      imageMethodSelectors := OrderedCollection new.
  1786      imageMethodSelectors := OrderedCollection new.
  1775 
  1787 
  1776      iconClass withAllSuperclasses do:[:cls |
  1788      iconClass withAllSuperclasses do:[:cls |
  1777         cls class methodDictionary keysAndValuesDo: [:sel :m | 
  1789         cls class methodDictionary keysAndValuesDo: [:sel :m | 
  1778             (r := m resourceType == #image
  1790             ((r := m resourceType) == #image
  1779             or:[r == #programImage]) ifTrue:[
  1791             or:[r == #programImage]) ifTrue:[
  1780                 imageMethodSelectors add:sel
  1792                 imageMethodSelectors add:sel
  1781             ]
  1793             ]
  1782         ]
  1794         ]
  1783      ].
  1795      ].
  1975 
  1987 
  1976 update:something with:aParameter from:changedObject
  1988 update:something with:aParameter from:changedObject
  1977     super update:something with:aParameter from:changedObject.
  1989     super update:something with:aParameter from:changedObject.
  1978 
  1990 
  1979     changedObject == (aspects at:#retriever) ifTrue:[
  1991     changedObject == (aspects at:#retriever) ifTrue:[
  1980         self updateListOfImages
  1992         "/ self updateListOfImages.
       
  1993         self updateSelectionOfImage
  1981     ].
  1994     ].
  1982 
  1995 
  1983     "Modified: / 24.8.1998 / 21:47:48 / cg"
  1996     "Modified: / 24.8.1998 / 21:47:48 / cg"
  1984 !
  1997 !
  1985 
  1998 
  2020     self valueOfEnableMovingOut      value:false.
  2033     self valueOfEnableMovingOut      value:false.
  2021     self hasValidSingleSelection     value:false.
  2034     self hasValidSingleSelection     value:false.
  2022     self hasValidSelection           value:state.     
  2035     self hasValidSelection           value:state.     
  2023     self valueOfCanPaste             value:(self hasValidSingleSelection value or: [node == self treeView root]) & self valueOfCanPaste value. 
  2036     self valueOfCanPaste             value:(self hasValidSingleSelection value or: [node == self treeView root]) & self valueOfCanPaste value. 
  2024 
  2037 
       
  2038 
  2025 !
  2039 !
  2026 
  2040 
  2027 updateListAndSelectionOfImage
  2041 updateListAndSelectionOfImage
  2028     "updates the list and selection of image"
  2042     "updates the list and selection of image"
  2029 
  2043 
  2041         iconClass := Smalltalk at: iconClass
  2055         iconClass := Smalltalk at: iconClass
  2042     ].
  2056     ].
  2043 
  2057 
  2044     self listOfImages contents:
  2058     self listOfImages contents:
  2045         ((self class getAllImageSelectorsFrom: iconClass)
  2059         ((self class getAllImageSelectorsFrom: iconClass)
  2046             collect: [:sel| |image| image := iconClass perform: sel. LabelAndIcon icon:(image magnifiedBy: 22/image extent y ) string: sel]).
  2060             collect: [:sel| |image| 
  2047 
  2061                         image := iconClass perform: sel. 
  2048     "Modified: / 24.8.1998 / 21:29:24 / cg"
  2062                         image height > 22 ifTrue:[
       
  2063                             image := image magnifiedBy: 22/image extent y
       
  2064                         ].
       
  2065                         LabelAndIcon 
       
  2066                             icon:image 
       
  2067                             string:sel
       
  2068                      ]).
       
  2069 
  2049 !
  2070 !
  2050 
  2071 
  2051 updateSelectionOfImage
  2072 updateSelectionOfImage
  2052     "updates the selection of image"
  2073     "updates the selection of image"
  2053 
  2074 
  2128 
  2149 
  2129 !
  2150 !
  2130 
  2151 
  2131 menuChanged
  2152 menuChanged
  2132 
  2153 
  2133     |node item slc sel old|
  2154     |node item slc sel old myClass|
  2134 
  2155 
  2135     aspects do: [:holder| holder removeDependent:self].
  2156     aspects do: [:holder| holder removeDependent:self].
  2136     (node := self treeView selectedNode) notNil ifTrue:[
  2157     (node := self treeView selectedNode) notNil ifTrue:[
       
  2158         "/ cg: this is rubbish - should only clear
       
  2159         "/ item-specific aspects (if at all)
       
  2160         "/ (added a q&d kludge for #retrieverClassList - no time to investigate)
       
  2161 
  2137         aspects do:[:anAspect| 
  2162         aspects do:[:anAspect| 
  2138                         anAspect isBlock ifFalse:[anAspect value:nil]
  2163                         anAspect isBlock ifFalse:[
       
  2164                             anAspect == (aspects at:#retrieverClassList) ifFalse:[
       
  2165                                 anAspect value:nil
       
  2166                             ]
       
  2167                         ]
  2139                    ].
  2168                    ].
  2140         item := node contents.
  2169         item := node contents.
  2141         item toAspects:aspects.
  2170         item toAspects:aspects.
  2142 
  2171 
  2143         item isSeparator ifFalse:[
  2172         item isSeparator ifFalse:[
       
  2173             myClass := self class.
  2144             node parent isNil ifFalse:[
  2174             node parent isNil ifFalse:[
  2145                 node hasChildren ifTrue:[
  2175                 node hasChildren ifTrue:[
  2146                     slc := #slicesMenu
  2176                     slc := #slicesMenu
  2147                 ] ifFalse:[
  2177                 ] ifFalse:[
  2148                     item submenuChannel isNil ifTrue:[slc := #slicesItem]
  2178                     item submenuChannel isNil ifTrue:[slc := #slicesItem]
  2149                                              ifFalse:[slc := #slicesLink]
  2179                                              ifFalse:[slc := #slicesLink]
  2150                 ].
  2180                 ].
  2151                 slc := (self class perform:slc) copyWith:#( 'Help' #dummy ).
  2181                 slc := (myClass perform:slc) copyWith:#( 'Help' #dummy ).
  2152             ] ifTrue:[
  2182             ] ifTrue:[
  2153                 slc := self class perform:#slicesRootMenu
  2183                 slc := myClass perform:#slicesRootMenu
  2154             ].
  2184             ].
  2155         ] ifTrue:[
  2185         ] ifTrue:[
  2156             slc := self class perform:#slicesSeparatorMenu.
  2186             slc := myClass perform:#slicesSeparatorMenu.
  2157         ]
  2187         ]
  2158     ].
  2188     ].
  2159 
  2189 
  2160     self helpTool helpKey: self helpKey.
  2190     self helpTool helpKey: self helpKey.
  2161     "Next line helps me to preserve myself against unnecessary settings of
  2191     "Next line helps me to preserve myself against unnecessary settings of
  2239                                             with:[:a | a size == 0]
  2269                                             with:[:a | a size == 0]
  2240                                             argument:(aspects at:#indication)).
  2270                                             argument:(aspects at:#indication)).
  2241     aspects at:#choiceValueEnabled put:(BlockValue
  2271     aspects at:#choiceValueEnabled put:(BlockValue
  2242                                             with:[:a | a size > 0]
  2272                                             with:[:a | a size > 0]
  2243                                             argument:(aspects at:#choice)).
  2273                                             argument:(aspects at:#choice)).
       
  2274 
       
  2275     aspects at:#retrieverClassList put:self class defaultRetrieverClassList asValue.
  2244 
  2276 
  2245     "Modified: / 14.8.1998 / 15:07:58 / cg"
  2277     "Modified: / 14.8.1998 / 15:07:58 / cg"
  2246 !
  2278 !
  2247 
  2279 
  2248 openModalOnMenu: aMenu
  2280 openModalOnMenu: aMenu
  2302         aspects do:[:anAspect| anAspect value:nil].
  2334         aspects do:[:anAspect| anAspect value:nil].
  2303         node contents toAspects:aspects
  2335         node contents toAspects:aspects
  2304     ].
  2336     ].
  2305     self valueOfEnablingCommitButtons value: false.
  2337     self valueOfEnablingCommitButtons value: false.
  2306     modified := false
  2338     modified := false
       
  2339 !
       
  2340 
       
  2341 doBrowseForImageResource
       
  2342     "opens a browser on image-resource methods"
       
  2343 
       
  2344     |msg currClass w cls sel|
       
  2345 
       
  2346     currClass := (Smalltalk at: (aspects at: #retriever) value ? specClass).
       
  2347     msg := 
       
  2348         (ResourceSelectionBrowser
       
  2349             request: 'Use Image From Class'
       
  2350             onSuperclass: nil
       
  2351             andClass: currClass
       
  2352             andSelector: (aspects at: #icon)
       
  2353             withResourceTypes: #(image fileImage programImage)).
       
  2354 
       
  2355     msg notNil ifTrue:[
       
  2356         (w := msg asCollectionOfWords) size == 2 ifTrue:[
       
  2357             cls := w at:1.
       
  2358             sel := w at:2.
       
  2359             cls ~= currClass ifTrue:[
       
  2360                 (aspects at: #retriever) value:cls asSymbol.
       
  2361             ].
       
  2362             sel ~= (aspects at:#icon) ifTrue:[
       
  2363                 (aspects at: #icon) value:sel asSymbol.
       
  2364             ].
       
  2365             self updateSelectionOfImage
       
  2366         ].
       
  2367     ].
       
  2368 
       
  2369 
  2307 !
  2370 !
  2308 
  2371 
  2309 doEditImage
  2372 doEditImage
  2310     "opens a Image Editor on the resource retriever and the icon selector;
  2373     "opens a Image Editor on the resource retriever and the icon selector;
  2311      then updates the list of images and select the line of the image"
  2374      then updates the list of images and select the line of the image"