MenuEditor.st
changeset 2569 b55aeaecefda
parent 2448 eec01c02868e
child 2580 1ed737f4f840
--- a/MenuEditor.st	Thu Jul 09 20:07:21 2009 +0200
+++ b/MenuEditor.st	Thu Jul 09 20:07:35 2009 +0200
@@ -14,7 +14,7 @@
 ResourceSpecEditor subclass:#MenuEditor
 	instanceVariableNames:'selectionHolder tabHolder listOfItems listOfTabs
 		selectedSuperItems notifyDisabledCounter wizards listOfItemsView
-		dropOverLine'
+		dropOverLine savedSpec'
 	classVariableNames:'ImageRetrieverClasses'
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -448,6 +448,9 @@
 #fileSave
 'Save Menuspec as Method'
 
+#fileSaveSpec
+'Save Menuspec'
+
 #fileSaveAs
 'Save Menuspec as Method...'
 
@@ -945,21 +948,32 @@
             label: '-'
           )
          (MenuItem
+            isVisible: isNotEditingSpecOnly
             activeHelpKey: fileLoad
             label: 'Load...'
             itemValue: doLoad
             translateLabel: true
           )
          (MenuItem
+            isVisible: isNotEditingSpecOnly
             label: '-'
           )
          (MenuItem
+            isVisible: isEditingSpecOnly
+            activeHelpKey: fileSaveSpec
+            label: 'Save'
+            itemValue: doSave
+            translateLabel: true
+          )
+         (MenuItem
+            isVisible: isNotEditingSpecOnly
             activeHelpKey: fileSave
             label: 'Save'
             itemValue: doSave
             translateLabel: true
           )
          (MenuItem
+            isVisible: isNotEditingSpecOnly
             activeHelpKey: fileSaveAs
             label: 'Save As...'
             itemValue: doSaveAs
@@ -1145,6 +1159,7 @@
             ignoreShortcutKeys: true
           )
          (MenuItem
+            isVisible: isNotEditingSpecOnly
             label: 'Generate'
             translateLabel: true
             submenuChannel: generateMenu
@@ -1206,25 +1221,26 @@
 
     ^
      #(#Menu
-	#(
-	 #(#MenuItem
-	    #activeHelpKey: #settingsRedefineAspectMethods
-	    #enabled: #hasValidSpecClass
-	    #label: 'Redefine Aspect Methods'
-	    #translateLabel: true
-	    #hideMenuOnActivated: false
-	    #indication: #redefineAspectMethodsChannel
-	  )
-	 #(#MenuItem
-	    #activeHelpKey: #settingsRedefineAspectMethods
-	    #label: 'AutoAccept on Selection-Change'
-	    #translateLabel: true
-	    #hideMenuOnActivated: false
-	    #indication: #autoAcceptOnSelectionChange
-	  )
-	 )
-	nil
-	nil
+        #(
+         #(#MenuItem
+            isVisible: isNotEditingSpecOnly
+            #activeHelpKey: #settingsRedefineAspectMethods
+            #enabled: #hasValidSpecClass
+            #label: 'Redefine Aspect Methods'
+            #translateLabel: true
+            #hideMenuOnActivated: false
+            #indication: #redefineAspectMethodsChannel
+          )
+         #(#MenuItem
+            #activeHelpKey: #settingsRedefineAspectMethods
+            #label: 'AutoAccept on Selection-Change'
+            #translateLabel: true
+            #hideMenuOnActivated: false
+            #indication: #autoAcceptOnSelectionChange
+          )
+         )
+        nil
+        nil
       )
 !
 
@@ -1282,188 +1298,199 @@
 
     ^
      #(Menu
-	(
-	 (MenuItem
-	    activeHelpKey: fileNew
-	    label: 'New'
-	    itemValue: doNew
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever ToolbarIconLibrary newMenuIcon)
-	  )
-	 (MenuItem
-	    label: '-'
-	  )
-	 (MenuItem
-	    activeHelpKey: fileLoad
-	    label: 'Load'
-	    itemValue: doLoad
-	    translateLabel: true
-	    isButton: true
-	    submenuChannel: menuHistory
-	    labelImage: (ResourceRetriever ToolbarIconLibrary loadFromMethodIcon)
-	    keepLinkedMenu: true
-	  )
-	 (MenuItem
-	    activeHelpKey: fileSave
-	    label: 'Save'
-	    itemValue: doSave
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever ToolbarIconLibrary saveAsMethodIcon)
-	  )
-	 (MenuItem
-	    label: '-'
-	  )
-	 (MenuItem
-	    activeHelpKey: editCut
-	    enabled: hasSelectionChannel
-	    label: 'Cut'
-	    itemValue: doCut
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever ToolbarIconLibrary cutMenuItemIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editCopy
-	    enabled: hasSelectionChannel
-	    label: 'Copy'
-	    itemValue: doCopy
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever ToolbarIconLibrary copyMenuItemIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editPaste
-	    enabled: canPasteHolder
-	    label: 'Paste'
-	    itemValue: doPaste
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever ToolbarIconLibrary pasteMenuItemIcon)
-	  )
-	 (MenuItem
-	    label: '-'
-	  )
-	 (MenuItem
-	    activeHelpKey: addMenuItem
-	    enabled: hasSingleSelectionChannel
-	    label: 'Add Item'
-	    itemValue: doCreateItem
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconItem)
-	  )
-	 (MenuItem
-	    activeHelpKey: addMenuSeparator
-	    enabled: hasSingleSelectionChannel
-	    label: 'Add Separator'
-	    itemValue: doCreateSep
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconSeparator)
-	  )
-	 (MenuItem
-	    activeHelpKey: addMenuSlice
-	    enabled: hasSingleSelectionChannel
-	    label: 'Menu Slice'
-	    itemValue: doCreateMenuSliceItem
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconSliceMenu)
-	  )
-	 (MenuItem
-	    activeHelpKey: addSubMenu
-	    enabled: hasSingleSelectionChannel
-	    label: 'Add Menu'
-	    itemValue: doCreateMenu
-	    translateLabel: true
-	    isButton: true
-	    submenuChannel: standardMenus
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconMenu)
-	    keepLinkedMenu: true
-	  )
-	 (MenuItem
-	    activeHelpKey: addSubMenuLink
-	    enabled: hasSingleSelectionChannel
-	    label: 'Add Linked Menu'
-	    itemValue: doCreateLinkedMenu
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconLinkedMenu)
-	  )
-	 (MenuItem
-	    activeHelpKey: addDelayedMenu
-	    enabled: canCreateDelayedMenuChannel
-	    label: 'Add Delayed Menu'
-	    itemValue: doCreateDelayedMenu:
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconDelayedMenu)
-	    argument: menu
-	  )
-	 (MenuItem
-	    activeHelpKey: addDelayedSubMenuLink
-	    enabled: canCreateDelayedMenuChannel
-	    label: 'Add Delayed Linked Menu'
-	    itemValue: doCreateDelayedMenu:
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever #'MenuEditor::Item' iconDelayedLinkedMenu)
-	    argument: linkedMenu
-	  )
-	 (MenuItem
-	    label: ''
-	  )
-	 (MenuItem
-	    activeHelpKey: editMoveUp
-	    enabled: enableMovingUpOrDownHolder
-	    label: 'Move Up'
-	    itemValue: doMoveUp
-	    translateLabel: true
-	    isButton: true
-	    startGroup: right
-	    labelImage: (ResourceRetriever Icon upIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editMoveDown
-	    enabled: enableMovingUpOrDownHolder
-	    label: 'Move Down'
-	    itemValue: doMoveDown
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever Icon downIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editMoveIn
-	    enabled: enableMovingInHolder
-	    label: 'Move Into Next'
-	    itemValue: doMoveInNext
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever Icon downRightIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editMoveInAbove
-	    enabled: enableMovingInAboveHolder
-	    label: 'Move Into Previous'
-	    itemValue: doMoveInPrevious
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever Icon upRightIcon)
-	  )
-	 (MenuItem
-	    activeHelpKey: editMoveOut
-	    enabled: enableMovingOutHolder
-	    label: 'Move Out'
-	    itemValue: doMoveOut
-	    translateLabel: true
-	    isButton: true
-	    labelImage: (ResourceRetriever Icon leftDownIcon)
-	  )
-	 )
-	nil
-	nil
+        (
+         (MenuItem
+            activeHelpKey: fileNew
+            label: 'New'
+            itemValue: doNew
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever ToolbarIconLibrary newMenuIcon)
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
+            isVisible: isNotEditingSpecOnly
+            activeHelpKey: fileLoad
+            label: 'Load'
+            itemValue: doLoad
+            translateLabel: true
+            isButton: true
+            submenuChannel: menuHistory
+            labelImage: (ResourceRetriever ToolbarIconLibrary loadFromMethodIcon)
+            keepLinkedMenu: true
+          )
+         (MenuItem
+            isVisible: isNotEditingSpecOnly
+            activeHelpKey: fileSave
+            label: 'Save'
+            itemValue: doSave
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever ToolbarIconLibrary saveAsMethodIcon)
+          )
+         (MenuItem  
+            isVisible: isEditingSpecOnly
+            activeHelpKey: fileSaveSpec
+            label: 'Save'
+            itemValue: doSave
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever XPToolbarIconLibrary saveImageIcon)
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
+            activeHelpKey: editCut
+            enabled: hasSelectionChannel
+            label: 'Cut'
+            itemValue: doCut
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever ToolbarIconLibrary cutMenuItemIcon)
+          )
+         (MenuItem
+            activeHelpKey: editCopy
+            enabled: hasSelectionChannel
+            label: 'Copy'
+            itemValue: doCopy
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever ToolbarIconLibrary copyMenuItemIcon)
+          )
+         (MenuItem
+            activeHelpKey: editPaste
+            enabled: canPasteHolder
+            label: 'Paste'
+            itemValue: doPaste
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever ToolbarIconLibrary pasteMenuItemIcon)
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
+            activeHelpKey: addMenuItem
+            enabled: hasSingleSelectionChannel
+            label: 'Add Item'
+            itemValue: doCreateItem
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconItem)
+          )
+         (MenuItem
+            activeHelpKey: addMenuSeparator
+            enabled: hasSingleSelectionChannel
+            label: 'Add Separator'
+            itemValue: doCreateSep
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconSeparator)
+          )
+         (MenuItem
+            activeHelpKey: addMenuSlice
+            enabled: hasSingleSelectionChannel
+            label: 'Menu Slice'
+            itemValue: doCreateMenuSliceItem
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconSliceMenu)
+          )
+         (MenuItem
+            activeHelpKey: addSubMenu
+            enabled: hasSingleSelectionChannel
+            label: 'Add Menu'
+            itemValue: doCreateMenu
+            translateLabel: true
+            isButton: true
+            submenuChannel: standardMenus
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconMenu)
+            keepLinkedMenu: true
+          )
+         (MenuItem
+            activeHelpKey: addSubMenuLink
+            enabled: hasSingleSelectionChannel
+            label: 'Add Linked Menu'
+            itemValue: doCreateLinkedMenu
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconLinkedMenu)
+          )
+         (MenuItem
+            activeHelpKey: addDelayedMenu
+            enabled: canCreateDelayedMenuChannel
+            label: 'Add Delayed Menu'
+            itemValue: doCreateDelayedMenu:
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconDelayedMenu)
+            argument: menu
+          )
+         (MenuItem
+            activeHelpKey: addDelayedSubMenuLink
+            enabled: canCreateDelayedMenuChannel
+            label: 'Add Delayed Linked Menu'
+            itemValue: doCreateDelayedMenu:
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever #'MenuEditor::Item' iconDelayedLinkedMenu)
+            argument: linkedMenu
+          )
+         (MenuItem
+            label: ''
+          )
+         (MenuItem
+            activeHelpKey: editMoveUp
+            enabled: enableMovingUpOrDownHolder
+            label: 'Move Up'
+            itemValue: doMoveUp
+            translateLabel: true
+            isButton: true
+            startGroup: right
+            labelImage: (ResourceRetriever Icon upIcon)
+          )
+         (MenuItem
+            activeHelpKey: editMoveDown
+            enabled: enableMovingUpOrDownHolder
+            label: 'Move Down'
+            itemValue: doMoveDown
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever Icon downIcon)
+          )
+         (MenuItem
+            activeHelpKey: editMoveIn
+            enabled: enableMovingInHolder
+            label: 'Move Into Next'
+            itemValue: doMoveInNext
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever Icon downRightIcon)
+          )
+         (MenuItem
+            activeHelpKey: editMoveInAbove
+            enabled: enableMovingInAboveHolder
+            label: 'Move Into Previous'
+            itemValue: doMoveInPrevious
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever Icon upRightIcon)
+          )
+         (MenuItem
+            activeHelpKey: editMoveOut
+            enabled: enableMovingOutHolder
+            label: 'Move Out'
+            itemValue: doMoveOut
+            translateLabel: true
+            isButton: true
+            labelImage: (ResourceRetriever Icon leftDownIcon)
+          )
+         )
+        nil
+        nil
       )
 ! !
 
@@ -1651,6 +1678,10 @@
     ]
 !
 
+savedSpec
+    ^ savedSpec
+!
+
 useHelpTool:aHelpTool
     "take the help dictionaries from aHelpTool into my helpTool
     "
@@ -1850,21 +1881,29 @@
     specSelector := aSelector.
 
     aSelector notNil ifTrue:[
-	aClass notNil ifTrue:[
-	    cls := aClass isBehavior ifTrue:[ aClass ] ifFalse:[ self resolveName:aClass].
-
-	    (cls respondsTo:aSelector) ifTrue:[
-		menu := cls perform: aSelector.
-	    ].
-
-	    menu notNil ifTrue:[
-		(menu isCollection) ifTrue:[
-		    menu := Menu decodeFromLiteralArray:menu
-		].
-	    ]
-	].
+        aClass notNil ifTrue:[
+            cls := aClass isBehavior ifTrue:[ aClass ] ifFalse:[ self resolveName:aClass].
+
+            (cls respondsTo:aSelector) ifTrue:[
+                menu := cls perform: aSelector.
+            ].
+        ].
     ].
-    self buildFromMenu:menu selector:aSelector.
+    self loadFromMenu:menu selector:aSelector.
+!
+
+loadFromMenu:menuArg selector:selectorOrNil
+    "rebuild menu"
+
+    |menu|
+
+    menu := menuArg.
+    menu notNil ifTrue:[
+        (menu isCollection) ifTrue:[
+            menu := Menu decodeFromLiteralArray:menu
+        ].
+    ].
+    self buildFromMenu:menu selector:selectorOrNil.
     self clearModified.
 
     "Modified: / 27-03-2007 / 11:16:47 / cg"
@@ -2267,10 +2306,14 @@
     wizards    := IdentityDictionary new.
 !
 
-openModalOnMenu:aMenu
-    "build a tree from aMenu and open it modal
-    "
-    self openModalOnResourceSpec:aMenu
+loadFromResourceSpec:aResourceSpec
+    self loadFromMenu:aResourceSpec selector:nil
+!
+
+openModalOnMenu:aMenuOrNil
+    "build a tree from aMenu and open it modal"
+
+    self openModalOnResourceSpec:aMenuOrNil
 !
 
 postBuildListOfItemsView:aSrollableView
@@ -2391,16 +2434,27 @@
 !
 
 generateMenuSpec
-    "generate and returns the current menu spec or nil
-    "
-    |menu spec|
+    "generate and returns the current menu spec or nil"
+
+    |menu|
 
     menu := listOfItems root submenu.
     menu isNil ifTrue:[^ nil].
-    menu := menu literalArrayEncoding.
-    spec := WriteStream on:String new.
-    UISpecification prettyPrintSpecArray:menu on:spec indent:5.
-    ^ spec contents.
+
+    ^ menu literalArrayEncoding.
+!
+
+generateMenuSpecString
+    "generate and returns the current menu spec as string or nil"
+
+    |menu specStream|
+
+    menu := self generateMenuSpec.
+    menu isNil ifTrue:[^ nil].
+
+    specStream := WriteStream on:String new.
+    UISpecification prettyPrintSpecArray:menu on:specStream indent:5.
+    ^ specStream contents.
 !
 
 withoutNotifyDo:aBlock
@@ -2428,6 +2482,14 @@
     specClass isNil ifTrue:[^ false].
     cls := self resolveName:specClass.
     ^ cls notNil
+!
+
+isEditingSpecOnly
+    ^ masterApplication notNil and:[ masterApplication isEditingSpecOnly ]
+!
+
+isNotEditingSpecOnly
+    ^ self isEditingSpecOnly not
 ! !
 
 !MenuEditor methodsFor:'selection'!
@@ -2665,14 +2727,21 @@
 
 doSave
     "save current editing menu to
-	   class: specClass
-	selector: specSelector
-    "
-    |cls spec mthd category code excla|
+           class: specClass
+        selector: specSelector
+    "
+    |cls specCode mthd category code excla|
+
+    self isEditingSpecOnly ifTrue:[
+        savedSpec := self generateMenuSpec.
+        hasSaved := true.
+        self clearModified.
+        ^ self
+    ].
 
     super doSave ifFalse: [^nil].
-    spec := self generateMenuSpec.
-    spec isNil ifTrue:[^ nil].
+    specCode := self generateMenuSpecString.
+    specCode isNil ifTrue:[^ nil].
 
     cls  := self resolveName:specClass.
 
@@ -2680,35 +2749,35 @@
 
     category := 'menu specs'.
     (mthd := cls class compiledMethodAt:specSelector) notNil ifTrue:[
-	category := mthd category.
+        category := mthd category.
     ].
 
     excla := Character excla asString.
 
     code := excla
-	    , (cls name , ' class methodsFor:' , category storeString)
-	    , excla , '\\'
-
-	    , specSelector , '\'
-	    , (self class codeGenerationComment replChar:$!! withString:'!!!!')
-	    , '\\    "\'
-	    , ('     MenuEditor new openOnClass:' , cls name , ' andSelector:#' , specSelector , '\')
-	    , ('     (Menu new fromLiteralArrayEncoding:(' , cls name , ' ' , specSelector , ')) startUp\')
-	    , '    "\'.
+            , (cls name , ' class methodsFor:' , category storeString)
+            , excla , '\\'
+
+            , specSelector , '\'
+            , (self class codeGenerationComment replChar:$!! withString:'!!!!')
+            , '\\    "\'
+            , ('     MenuEditor new openOnClass:' , cls name , ' andSelector:#' , specSelector , '\')
+            , ('     (Menu new fromLiteralArrayEncoding:(' , cls name , ' ' , specSelector , ')) startUp\')
+            , '    "\'.
 
     code := code
-	    , '\'
-	    , '    <resource: #menu>\\'
-	    , '    ^ ' , spec
-	    , '\'
-	    , (excla , ' ' , excla)
-	    , '\\'.
+            , '\'
+            , '    <resource: #menu>\\'
+            , '    ^ ' , specCode
+            , '\'
+            , (excla , ' ' , excla)
+            , '\\'.
 
     code := code withCRs.
     (ReadStream on:code) fileIn.
 
     self isStandAlone ifTrue:[
-	self helpTool doSave
+        self helpTool doSave
     ].
 
     self updateHistory.
@@ -2726,14 +2795,14 @@
 !
 
 doShowMenuSpec
-    "opens a code view with the contents of the menu spec
-    "
-    |spec|
-
-    spec := self generateMenuSpec.
-
-    spec ifNotNil:[
-	CodeView openWith:spec title: 'Menu Spec'
+    "opens a code view with the contents of the menu spec"
+
+    |code|
+
+    code := self generateMenuSpecString.
+
+    code ifNotNil:[
+        CodeView openWith:code title: 'Menu Spec'
     ].
 !