MenuEditor.st
changeset 1614 46cc531eecc6
parent 1610 cb3e093aa6d5
child 1617 dd4bd2e32826
equal deleted inserted replaced
1613:1d4f11252d3b 1614:46cc531eecc6
    12 
    12 
    13 "{ Package: 'stx:libtool2' }"
    13 "{ Package: 'stx:libtool2' }"
    14 
    14 
    15 ResourceSpecEditor subclass:#MenuEditor
    15 ResourceSpecEditor subclass:#MenuEditor
    16 	instanceVariableNames:'selectionHolder tabHolder listOfItems listOfTabs
    16 	instanceVariableNames:'selectionHolder tabHolder listOfItems listOfTabs
    17 		selectedSuperItems notifyDisabledCounter wizards listOfItemsView'
    17 		selectedSuperItems notifyDisabledCounter wizards listOfItemsView
       
    18 		redefineAspectMethods'
    18 	classVariableNames:'ImageRetrieverClasses'
    19 	classVariableNames:'ImageRetrieverClasses'
    19 	poolDictionaries:''
    20 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    21 	category:'Interface-UIPainter'
    21 !
    22 !
    22 
    23 
   344 #fileSaveAs
   345 #fileSaveAs
   345 'Open a dialog to save the menu spec (and the help spec, if modified).'
   346 'Open a dialog to save the menu spec (and the help spec, if modified).'
   346 
   347 
   347 #fileShowMenuSpec
   348 #fileShowMenuSpec
   348 'Opens a Workspace showing the current menu spec.'
   349 'Opens a Workspace showing the current menu spec.'
       
   350 
       
   351 #generateAspectMethods
       
   352 'Generates aspect methods for defined aspect selectors of the menu.'
   349 
   353 
   350 #hideMenuOnActivated
   354 #hideMenuOnActivated
   351 'If on, the menu hides itself after the item was activated.'
   355 'If on, the menu hides itself after the item was activated.'
   352 
   356 
   353 #horizontalLayout
   357 #horizontalLayout
   762         nil
   766         nil
   763         nil
   767         nil
   764       )
   768       )
   765 !
   769 !
   766 
   770 
       
   771 generateMenu
       
   772     "This resource specification was automatically generated
       
   773      by the MenuEditor of ST/X."
       
   774 
       
   775     "Do not manually edit this!! If it is corrupted,
       
   776      the MenuEditor may not be able to read the specification."
       
   777 
       
   778     "
       
   779      MenuEditor new openOnClass:MenuEditor andSelector:#generateMenu
       
   780      (Menu new fromLiteralArrayEncoding:(MenuEditor generateMenu)) startUp
       
   781     "
       
   782 
       
   783     <resource: #menu>
       
   784 
       
   785     ^ 
       
   786      #(#Menu
       
   787         #(
       
   788          #(#MenuItem
       
   789             #label: 'Aspect Methods'
       
   790             #value: #doGenerateAspectMethods
       
   791             #activeHelpKey: #generateAspectMethods
       
   792             #enabled: #hasValidSpecClass
       
   793           )
       
   794          )
       
   795         nil
       
   796         nil
       
   797       )
       
   798 !
       
   799 
   767 helpMenu
   800 helpMenu
   768     "This resource specification was automatically generated
   801     "This resource specification was automatically generated
   769      by the MenuEditor of ST/X."
   802      by the MenuEditor of ST/X."
   770 
   803 
   771     "Do not manually edit this!! If it is corrupted,
   804     "Do not manually edit this!! If it is corrupted,
   870          #(#MenuItem
   903          #(#MenuItem
   871             #label: 'History'
   904             #label: 'History'
   872             #translateLabel: true
   905             #translateLabel: true
   873             #activeHelpKey: #history
   906             #activeHelpKey: #history
   874             #submenuChannel: #menuHistory
   907             #submenuChannel: #menuHistory
       
   908           )
       
   909          #(#MenuItem
       
   910             #label: 'Generate'
       
   911             #translateLabel: true
       
   912             #activeHelpKey: #generate
       
   913             #submenuChannel: #generateMenu
       
   914             #keepLinkedMenu: true
   875           )
   915           )
   876          #(#MenuItem
   916          #(#MenuItem
   877             #label: '&Help'
   917             #label: '&Help'
   878             #translateLabel: true
   918             #translateLabel: true
   879             #startGroup: #right
   919             #startGroup: #right
  1683 initialize
  1723 initialize
  1684     "setup aspects, ...
  1724     "setup aspects, ...
  1685     "
  1725     "
  1686     super initialize.
  1726     super initialize.
  1687     notifyDisabledCounter := 0.
  1727     notifyDisabledCounter := 0.
       
  1728     redefineAspectMethods := true.
  1688 
  1729 
  1689     Item withAllSubclasses do:[:aClass|
  1730     Item withAllSubclasses do:[:aClass|
  1690         aClass addBindingsTo:aspects for:self.
  1731         aClass addBindingsTo:aspects for:self.
  1691     ].
  1732     ].
  1692 
  1733 
  1899 
  1940 
  1900     anItem notNil ifTrue:[ selection := Array with:anItem ]
  1941     anItem notNil ifTrue:[ selection := Array with:anItem ]
  1901 		 ifFalse:[ selection := #() ].
  1942 		 ifFalse:[ selection := #() ].
  1902 
  1943 
  1903     selectionHolder value:selection.
  1944     selectionHolder value:selection.
       
  1945 ! !
       
  1946 
       
  1947 !MenuEditor methodsFor:'user actions - aspects'!
       
  1948 
       
  1949 collectActionSelectors
       
  1950     |selectors|
       
  1951 
       
  1952     selectors := IdentitySet new.
       
  1953 
       
  1954     listOfItems root recursiveDo:[:el|
       
  1955         el actionSelectors do:[:s| selectors add:s ].
       
  1956     ].
       
  1957     ^ selectors asOrderedCollection
       
  1958 !
       
  1959 
       
  1960 collectAspectSelectors
       
  1961     |selectors|
       
  1962 
       
  1963     selectors := IdentitySet new.
       
  1964 
       
  1965     listOfItems root recursiveDo:[:el|
       
  1966         el aspectSelectors do:[:s| selectors add:s ].
       
  1967     ].
       
  1968     ^ selectors asOrderedCollection
       
  1969 !
       
  1970 
       
  1971 doGenerateAspectMethods
       
  1972     "genearte aspect messages
       
  1973     "
       
  1974     |cls stream code|
       
  1975 
       
  1976     specClass ifNil:[
       
  1977         self warn:'Define the class first !!'.
       
  1978       ^ self
       
  1979     ].
       
  1980 
       
  1981     cls := self resolveName:specClass.
       
  1982     cls ifNil:[
       
  1983         self warn:'Class ', specClass asString, ' does not exist!!'.
       
  1984       ^ self  
       
  1985     ].
       
  1986     stream := '' writeStream.
       
  1987 
       
  1988     self collectActionSelectors do:[:aSel|
       
  1989         code := self generateActionMethodFor:aSel inClass:cls.
       
  1990         code ifNotNil:[ stream nextPutAll:code ].
       
  1991     ].
       
  1992 
       
  1993     self collectAspectSelectors do:[:aSel|
       
  1994         code := self generateAspectMethodFor:aSel inClass:cls.
       
  1995         code ifNotNil:[ stream nextPutAll:code ].
       
  1996     ].
       
  1997 
       
  1998     code := stream contents.
       
  1999 
       
  2000     code size ~~ 0 ifTrue:[
       
  2001         code readStream fileIn
       
  2002     ].
       
  2003 !
       
  2004 
       
  2005 generateActionMethodFor:selector inClass:targetClass
       
  2006     "genearte aspect messages
       
  2007     "
       
  2008     | alreadyInSuperclass numArgs method args showIt code|
       
  2009 
       
  2010     (targetClass includesSelector:selector) ifTrue:[
       
  2011         "/ Transcript showCR:'#' , selector , ' skipped - already implemented in the class'.
       
  2012       ^ nil
       
  2013     ].
       
  2014 
       
  2015     alreadyInSuperclass := targetClass superclass canUnderstand:selector.
       
  2016 
       
  2017     alreadyInSuperclass ifTrue:[
       
  2018         redefineAspectMethods ifFalse:[
       
  2019             "/ Transcript showCR:'#' , selector , ' skipped - already implemented in superclass'.
       
  2020           ^ nil
       
  2021         ]
       
  2022     ].
       
  2023 
       
  2024     numArgs := selector numArgs.
       
  2025     method  := selector.
       
  2026 
       
  2027     numArgs == 1 ifTrue:[
       
  2028         args   := 'anArgument'.
       
  2029         showIt := ''' , anArgument printString , '' ...''.\'.
       
  2030     ] ifFalse:[    
       
  2031         args := ''.
       
  2032         showIt := ' ...''.\'.
       
  2033 
       
  2034         numArgs ~~ 0 ifTrue:[
       
  2035             method := ''.
       
  2036 
       
  2037             selector keywords keysAndValuesDo:[:i :key|
       
  2038                 method := method, key, 'arg', i printString, ' '
       
  2039             ]
       
  2040         ]
       
  2041     ].
       
  2042     code := '!!' , targetClass name , ' methodsFor:''menu actions''!!\\' ,
       
  2043                 method , args , '\' ,
       
  2044                 '    "automatically generated by MenuEditor ..."\\' ,
       
  2045                 '    "*** the code below performs no action"\' ,
       
  2046                 '    "*** (except for some feedback on the Transcript)"\' ,
       
  2047                 '    "*** Please change as required and accept in the browser."\' ,
       
  2048                 '    "*** (and replace this comment by something more useful ;-)"\' ,
       
  2049                 '\' .
       
  2050 
       
  2051     alreadyInSuperclass ifTrue:[
       
  2052         code := code ,
       
  2053                     '    "action for ' , selector , ' is already provided in a superclass."\' ,
       
  2054                     '    "It may be redefined here ..."\\'.
       
  2055     ] ifFalse:[
       
  2056         code := code ,
       
  2057                     '    "action to be added ..."\\'.
       
  2058     ].
       
  2059 
       
  2060     code := code ,
       
  2061                 '    Transcript showCR:self class name, '': '.
       
  2062     alreadyInSuperclass ifTrue:[
       
  2063         code := code , 'inherited '.
       
  2064     ].
       
  2065     code := code , 'action for ' , selector , showIt.
       
  2066 
       
  2067     alreadyInSuperclass ifTrue:[
       
  2068         code := code ,
       
  2069                         '    super ' , selector , args , '.\'.
       
  2070     ].
       
  2071 
       
  2072     code := code ,
       
  2073                 '!! !!\\'.
       
  2074     ^ code withCRs
       
  2075 !
       
  2076 
       
  2077 generateAspectMethodFor:aspect inClass:targetClass
       
  2078     "genearte aspect messages
       
  2079     "
       
  2080     | alreadyInSuperclass numArgs method args showIt code|
       
  2081 
       
  2082     (targetClass includesSelector:aspect) ifTrue:[
       
  2083         "/ Transcript showCR:'#' , aspect , ' skipped - already implemented in the class'.
       
  2084       ^ nil
       
  2085     ].
       
  2086 
       
  2087     alreadyInSuperclass := targetClass superclass canUnderstand:aspect.
       
  2088 
       
  2089     alreadyInSuperclass ifTrue:[
       
  2090         redefineAspectMethods ifFalse:[
       
  2091             "/ Transcript showCR:'#' , aspect , ' skipped - already implemented in superclass'.
       
  2092           ^ nil
       
  2093         ]
       
  2094     ].
       
  2095 
       
  2096     numArgs := aspect numArgs.
       
  2097     method  := aspect.
       
  2098 
       
  2099     numArgs == 1 ifTrue:[
       
  2100         args   := 'anArgument'.
       
  2101         showIt := ''' , anArgument printString , '' ...''.\'.
       
  2102     ] ifFalse:[    
       
  2103         args := ''.
       
  2104         showIt := ' ...''.\'.
       
  2105 
       
  2106         numArgs ~~ 0 ifTrue:[
       
  2107             method := ''.
       
  2108 
       
  2109             aspect keywords keysAndValuesDo:[:i :key|
       
  2110                 method := method, key, 'arg', i printString, ' '
       
  2111             ]
       
  2112         ]
       
  2113     ].
       
  2114     code := '!!' , targetClass name , ' methodsFor:''menu aspect''!!\\' ,
       
  2115                 method , args , '\' ,
       
  2116                 '    "automatically generated by MenuEditor ..."\\' ,
       
  2117                 '    "*** the code below creates a default model when invoked"\' ,
       
  2118                 '    "*** (which may not be the one you wanted)"\' ,
       
  2119                 '    "*** Please change as required and accept in the browser."\' ,
       
  2120                 '    "*** (and replace this comment by something more useful ;-)"\' ,
       
  2121                 '\' .
       
  2122 
       
  2123     alreadyInSuperclass ifTrue:[
       
  2124         code := code ,
       
  2125                     '    "aspect for ' , aspect , ' is already provided in a superclass."\' ,
       
  2126                     '    "It may be redefined here ..."\\'.
       
  2127     ] ifFalse:[
       
  2128         code := code ,
       
  2129                     '    "aspect to be added ..."\\'.
       
  2130     ].
       
  2131 
       
  2132     code := code ,
       
  2133                 '    Transcript showCR:self class name, '': '.
       
  2134     alreadyInSuperclass ifTrue:[
       
  2135         code := code , 'inherited '.
       
  2136     ].
       
  2137     code := code , 'aspect for ' , aspect , showIt, '\'.
       
  2138 
       
  2139     alreadyInSuperclass ifTrue:[
       
  2140         code := code ,
       
  2141                         '    ^ super ' , aspect , args , '.\'.
       
  2142     ] ifFalse:[
       
  2143         code := code ,
       
  2144                         '    ^ builder valueAspectFor:#' , aspect , ' initialValue:true.\'.
       
  2145    ].
       
  2146 
       
  2147     code := code ,
       
  2148                 '!! !!\\'.
       
  2149     ^ code withCRs
  1904 ! !
  2150 ! !
  1905 
  2151 
  1906 !MenuEditor methodsFor:'user actions - building'!
  2152 !MenuEditor methodsFor:'user actions - building'!
  1907 
  2153 
  1908 doNew
  2154 doNew
  2795 
  3041 
  2796 isRootItem
  3042 isRootItem
  2797     "returns true if the item is the root item
  3043     "returns true if the item is the root item
  2798     "
  3044     "
  2799     ^ false
  3045     ^ false
       
  3046 ! !
       
  3047 
       
  3048 !MenuEditor::Item methodsFor:'queries - editor'!
       
  3049 
       
  3050 actionSelectors
       
  3051     "returns my action selectors
       
  3052     "
       
  3053     |value|
       
  3054 
       
  3055     value := menuItem value.
       
  3056     value isSymbol ifTrue:[ ^ Array with:value ].
       
  3057   ^ #()
       
  3058 !
       
  3059 
       
  3060 aspectSelectors
       
  3061     "returns my aspect selectors
       
  3062     "
       
  3063     |aspects|
       
  3064 
       
  3065     aspects := OrderedCollection new.
       
  3066 
       
  3067     #( indication choice enabled isVisible ) do:[:aKey| |sel|
       
  3068         sel := menuItem perform:aKey.
       
  3069         sel isSymbol ifTrue:[ aspects add:sel ]
       
  3070     ].    
       
  3071     ^ aspects
  2800 ! !
  3072 ! !
  2801 
  3073 
  2802 !MenuEditor::Item methodsFor:'queries - operation'!
  3074 !MenuEditor::Item methodsFor:'queries - operation'!
  2803 
  3075 
  2804 canAddChildren
  3076 canAddChildren
  3953 
  4225 
  3954 isRootItem
  4226 isRootItem
  3955     ^ true
  4227     ^ true
  3956 ! !
  4228 ! !
  3957 
  4229 
       
  4230 !MenuEditor::ItemRoot methodsFor:'queries - editor'!
       
  4231 
       
  4232 actionSelectors
       
  4233     "returns my action selectors
       
  4234     "
       
  4235     ^ #()
       
  4236 !
       
  4237 
       
  4238 aspectSelectors
       
  4239     "returns my aspect selectors
       
  4240     "
       
  4241     ^ #()
       
  4242 ! !
       
  4243 
  3958 !MenuEditor::ItemRoot methodsFor:'queries - operation'!
  4244 !MenuEditor::ItemRoot methodsFor:'queries - operation'!
  3959 
  4245 
  3960 canMoveInAbove
  4246 canMoveInAbove
  3961     ^ false
  4247     ^ false
  3962 !
  4248 !