MenuEditor.st
changeset 2151 5427bb64d15e
parent 2137 70f859d89841
child 2156 215e8d8f965e
equal deleted inserted replaced
2150:72029523c30a 2151:5427bb64d15e
  1656     "
  1656     "
  1657     |holder|
  1657     |holder|
  1658 
  1658 
  1659     holder := builder bindingAt:#wizardHolder.
  1659     holder := builder bindingAt:#wizardHolder.
  1660 
  1660 
  1661     holder ifNil:[
  1661     holder isNil ifTrue:[
  1662 	holder := nil asValue.
  1662         holder := nil asValue.
  1663 	builder aspectAt:#wizardHolder put:holder.
  1663         builder aspectAt:#wizardHolder put:holder.
  1664     ].
  1664     ].
  1665     ^ holder
  1665     ^ holder
  1666 ! !
  1666 ! !
  1667 
  1667 
  1668 !MenuEditor methodsFor:'building'!
  1668 !MenuEditor methodsFor:'building'!
  1786     "
  1786     "
  1787     |tab selector item canvas wizardHolder|
  1787     |tab selector item canvas wizardHolder|
  1788 
  1788 
  1789     wizardHolder := self wizardHolder.
  1789     wizardHolder := self wizardHolder.
  1790     item := self selectedItem.
  1790     item := self selectedItem.
  1791     item ifNil:[ ^ wizardHolder value:nil ].
  1791     item isNil ifTrue:[ ^ wizardHolder value:nil ].
  1792 
  1792 
  1793     tab := tabHolder value.
  1793     tab := tabHolder value.
  1794 
  1794 
  1795     tab notNil ifTrue:[
  1795     tab notNil ifTrue:[
  1796         tab := item slices detect:[:el| el first = tab ] ifNone:nil.
  1796         tab := item slices detect:[:el| el first = tab ] ifNone:nil.
  2023 doDrop:aDropContext
  2023 doDrop:aDropContext
  2024     "drop the dropContext into the hierachical list of items
  2024     "drop the dropContext into the hierachical list of items
  2025     "
  2025     "
  2026     |done item|
  2026     |done item|
  2027 
  2027 
  2028     dropOverLine ifNil:[^ false ].      "/ context not valid to me ...
  2028     dropOverLine isNil ifTrue:[^ false ].      "/ context not valid to me ...
  2029 
  2029 
  2030     item := listOfItems at:dropOverLine ifAbsent:nil.
  2030     item := listOfItems at:dropOverLine ifAbsent:nil.
  2031     self dropLeave:aDropContext.
  2031     self dropLeave:aDropContext.
  2032     item ifNil:[^ false].
  2032     item isNil ifTrue:[^ false].
  2033 
  2033 
  2034     selectionHolder setValue:(Array with:item).
  2034     selectionHolder setValue:(Array with:item).
  2035 
  2035 
  2036     done := false.
  2036     done := false.
  2037 
  2037 
  2095 dropOver:aDropContext
  2095 dropOver:aDropContext
  2096     "called during drag & drop while moving over the widget."
  2096     "called during drag & drop while moving over the widget."
  2097 
  2097 
  2098     |lnNr item|
  2098     |lnNr item|
  2099 
  2099 
  2100     dropOverLine ifNil:[^ self ].       "/ context not valid to me ...
  2100     dropOverLine isNil ifTrue:[^ self ].       "/ context not valid to me ...
  2101 
  2101 
  2102     lnNr := listOfItemsView yVisibleToLineNr:(aDropContext targetPoint y).
  2102     lnNr := listOfItemsView yVisibleToLineNr:(aDropContext targetPoint y).
  2103     item := nil.
  2103     item := nil.
  2104 
  2104 
  2105     lnNr ifNotNil:[
  2105     lnNr ifNotNil:[
  2108             (item isAction and:[item hasDelayedMenu]) ifTrue:[
  2108             (item isAction and:[item hasDelayedMenu]) ifTrue:[
  2109                 item := nil
  2109                 item := nil
  2110             ]
  2110             ]
  2111         ]
  2111         ]
  2112     ].
  2112     ].
  2113     item ifNil:[ lnNr := 0 ].   "/ not dropable for item
  2113     item isNil ifTrue:[ lnNr := 0 ].   "/ not dropable for item
  2114 
  2114 
  2115     "/ redraw drop indication
  2115     "/ redraw drop indication
  2116     self changeDropLineTo:lnNr in:aDropContext.
  2116     self changeDropLineTo:lnNr in:aDropContext.
  2117 
  2117 
  2118     "Modified: / 13-10-2006 / 16:04:05 / cg"
  2118     "Modified: / 13-10-2006 / 16:04:05 / cg"
  2127     |evView inView rawKey key|
  2127     |evView inView rawKey key|
  2128 
  2128 
  2129     anEvent isKeyPressEvent ifFalse:[ ^ false].
  2129     anEvent isKeyPressEvent ifFalse:[ ^ false].
  2130 
  2130 
  2131     evView := anEvent targetView.
  2131     evView := anEvent targetView.
  2132     evView ifNil:[ ^ false ].
  2132     evView isNil ifTrue:[ ^ false ].
  2133 
  2133 
  2134     inView := evView isSameOrComponentOf:listOfItemsView.
  2134     inView := evView isSameOrComponentOf:listOfItemsView.
  2135     inView ifFalse:[^ false].
  2135     inView ifFalse:[^ false].
  2136 
  2136 
  2137     key    := anEvent key.
  2137     key    := anEvent key.
  2252      is enabled. On success the new item(s) are returned otherwise nil.
  2252      is enabled. On success the new item(s) are returned otherwise nil.
  2253     "
  2253     "
  2254     |intoItem index newItem|
  2254     |intoItem index newItem|
  2255 
  2255 
  2256     intoItem := self selectedItem.
  2256     intoItem := self selectedItem.
  2257     intoItem ifNil:[ ^ nil].
  2257     intoItem isNil ifTrue:[ ^ nil].
  2258 
  2258 
  2259     self askForItemModification ifFalse:[ ^ nil ].
  2259     self askForItemModification ifFalse:[ ^ nil ].
  2260 
  2260 
  2261     index := 1.
  2261     index := 1.
  2262 
  2262 
  2300     "generate and returns the current menu spec or nil
  2300     "generate and returns the current menu spec or nil
  2301     "
  2301     "
  2302     |menu spec|
  2302     |menu spec|
  2303 
  2303 
  2304     menu := listOfItems root submenu.
  2304     menu := listOfItems root submenu.
  2305     menu ifNil:[^ nil].
  2305     menu isNil ifTrue:[^ nil].
  2306     menu := menu literalArrayEncoding.
  2306     menu := menu literalArrayEncoding.
  2307     spec := WriteStream on:String new.
  2307     spec := WriteStream on:String new.
  2308     UISpecification prettyPrintSpecArray:menu on:spec indent:5.
  2308     UISpecification prettyPrintSpecArray:menu on:spec indent:5.
  2309   ^ spec contents.
  2309     ^ spec contents.
  2310 !
  2310 !
  2311 
  2311 
  2312 submenuTest
  2312 submenuTest
  2313     "returns a menu on the current editing menu
  2313     "returns a menu on the current editing menu
  2314     "
  2314     "
  2315     |menu indication choice submenu retriever|
  2315     |menu indication choice submenu retriever|
  2316 
  2316 
  2317     menu := listOfItems root submenu.
  2317     menu := listOfItems root submenu.
  2318     menu ifNil:[^ nil ].
  2318     menu isNil ifTrue:[^ nil ].
  2319 
  2319 
  2320     menu allItemsDo:[:anItem|
  2320     menu allItemsDo:[:anItem|
  2321         anItem isVisible:true.
  2321         anItem isVisible:true.
  2322         anItem   enabled:true.
  2322         anItem   enabled:true.
  2323         anItem translateLabel:false.
  2323         anItem translateLabel:false.
  2376 hasValidSpecClass
  2376 hasValidSpecClass
  2377     "returns true if a valid specClass exists
  2377     "returns true if a valid specClass exists
  2378     "
  2378     "
  2379     |cls|
  2379     |cls|
  2380 
  2380 
  2381     specClass ifNil:[^ false].
  2381     specClass isNil ifTrue:[^ false].
  2382     cls := self resolveName:specClass.
  2382     cls := self resolveName:specClass.
  2383   ^ cls notNil
  2383     ^ cls notNil
  2384 ! !
  2384 ! !
  2385 
  2385 
  2386 !MenuEditor methodsFor:'selection'!
  2386 !MenuEditor methodsFor:'selection'!
  2387 
  2387 
  2388 canSelect:anIndex
  2388 canSelect:anIndex
  2393 
  2393 
  2394     self enablingCommitButtonsHolder value ifFalse:[
  2394     self enablingCommitButtonsHolder value ifFalse:[
  2395         ^ true
  2395         ^ true
  2396     ].
  2396     ].
  2397     oldSelectedItem := self selectedItem.
  2397     oldSelectedItem := self selectedItem.
  2398     oldSelectedItem ifNil:[^ true].
  2398     oldSelectedItem isNil ifTrue:[^ true].
  2399 
  2399 
  2400     newSelectedItem := listOfItems at:anIndex ifAbsent:nil.
  2400     newSelectedItem := listOfItems at:anIndex ifAbsent:nil.
  2401     oldSelectedItem == newSelectedItem ifTrue:[
  2401     oldSelectedItem == newSelectedItem ifTrue:[
  2402         ^ true
  2402         ^ true
  2403     ].
  2403     ].
  2467 doGenerateAspectMethods
  2467 doGenerateAspectMethods
  2468     "compile aspect and action methods"
  2468     "compile aspect and action methods"
  2469 
  2469 
  2470     |cls redefineAspectMethods category|
  2470     |cls redefineAspectMethods category|
  2471 
  2471 
  2472     specClass ifNil:[
  2472     specClass isNil ifTrue:[
  2473         self warn:'Define the class first !!'.
  2473         self warn:'Define the class first !!'.
  2474         ^ self
  2474         ^ self
  2475     ].
  2475     ].
  2476     redefineAspectMethods := self redefineAspectMethodsChannel value.
  2476     redefineAspectMethods := self redefineAspectMethodsChannel value.
  2477 
  2477 
  2478     cls := self resolveName:specClass.
  2478     cls := self resolveName:specClass.
  2479     cls ifNil:[
  2479     cls isNil ifTrue:[
  2480         self warn:'Class ', specClass asString, ' does not exist!!'.
  2480         self warn:'Class ', specClass asString, ' does not exist!!'.
  2481         ^ self  
  2481         ^ self  
  2482     ].
  2482     ].
  2483 
  2483 
  2484     category := UserPreferences current categoryForMenuActionsMethods.
  2484     category := UserPreferences current categoryForMenuActionsMethods.
  2530     "
  2530     "
  2531     |cls spec mthd category code excla|
  2531     |cls spec mthd category code excla|
  2532 
  2532 
  2533     super doSave ifFalse: [^nil].
  2533     super doSave ifFalse: [^nil].
  2534     spec := self generateMenuSpec.
  2534     spec := self generateMenuSpec.
  2535     spec ifNil:[^ nil].
  2535     spec isNil ifTrue:[^ nil].
  2536 
  2536 
  2537     cls  := self resolveName:specClass.
  2537     cls  := self resolveName:specClass.
  2538 
  2538 
  2539     "/ if that method already exists, do not overwrite the category
  2539     "/ if that method already exists, do not overwrite the category
  2540 
  2540 
  2605 
  2605 
  2606 doCreateDelayedMenu:what
  2606 doCreateDelayedMenu:what
  2607     |selectedItem delayedItem|
  2607     |selectedItem delayedItem|
  2608 
  2608 
  2609     selectedItem := self selectedItem.
  2609     selectedItem := self selectedItem.
  2610     selectedItem ifNil:[^ self].
  2610     selectedItem isNil ifTrue:[^ self].
  2611 
  2611 
  2612     selectedItem canAddDelayedMenu      ifFalse:[ ^ self ].
  2612     selectedItem canAddDelayedMenu      ifFalse:[ ^ self ].
  2613     self askForItemModification ifFalse:[ ^ self ].
  2613     self askForItemModification ifFalse:[ ^ self ].
  2614 
  2614 
  2615     what == #menu ifTrue:[ delayedItem := RegularMenuItem new ]
  2615     what == #menu ifTrue:[ delayedItem := RegularMenuItem new ]
  2765     |item loMenuItems|
  2765     |item loMenuItems|
  2766 
  2766 
  2767     aCollection size == 0 ifTrue:[ ^ self ].
  2767     aCollection size == 0 ifTrue:[ ^ self ].
  2768 
  2768 
  2769     item := self selectedItem.
  2769     item := self selectedItem.
  2770     item ifNil:[ ^ self ].
  2770     item isNil ifTrue:[ ^ self ].
  2771 
  2771 
  2772     loMenuItems := OrderedCollection new.
  2772     loMenuItems := OrderedCollection new.
  2773     aCollection do:[:el|
  2773     aCollection do:[:el|
  2774         (el askFor:#isMenuItem) ifTrue:[ loMenuItems add:el ].
  2774         (el askFor:#isMenuItem) ifTrue:[ loMenuItems add:el ].
  2775     ].
  2775     ].
  2792     "move selected item into the next (#inNext) or previous (#inPrev) item
  2792     "move selected item into the next (#inNext) or previous (#inPrev) item
  2793     "
  2793     "
  2794     |item idx parent toParent|
  2794     |item idx parent toParent|
  2795 
  2795 
  2796     item := self selectedItem.
  2796     item := self selectedItem.
  2797     item ifNil:[^ self].
  2797     item isNil ifTrue:[^ self].
  2798 
  2798 
  2799     aDirection == #inNext ifTrue:[ item canMoveInNext  ifFalse:[^ self] ]
  2799     aDirection == #inNext ifTrue:[ item canMoveInNext  ifFalse:[^ self] ]
  2800                          ifFalse:[ item canMoveInAbove ifFalse:[^ self] ].
  2800                          ifFalse:[ item canMoveInAbove ifFalse:[^ self] ].
  2801 
  2801 
  2802     self askForItemModification ifFalse:[ ^ self ].
  2802     self askForItemModification ifFalse:[ ^ self ].
  2835     "move selected item out of current item
  2835     "move selected item out of current item
  2836     "
  2836     "
  2837     |item parent grandParent index|
  2837     |item parent grandParent index|
  2838 
  2838 
  2839     item := self selectedItem.
  2839     item := self selectedItem.
  2840     item ifNil:[^ self].
  2840     item isNil ifTrue:[^ self].
  2841     item canMoveOut ifFalse:[^ self].
  2841     item canMoveOut ifFalse:[^ self].
  2842 
  2842 
  2843     self askForItemModification ifFalse:[ ^ self ].
  2843     self askForItemModification ifFalse:[ ^ self ].
  2844 
  2844 
  2845     parent      := item parent.
  2845     parent      := item parent.
  2866     "move selected item up (#up) or down (#down)
  2866     "move selected item up (#up) or down (#down)
  2867     "
  2867     "
  2868     |item index parent children|
  2868     |item index parent children|
  2869 
  2869 
  2870     item := self selectedItem.
  2870     item := self selectedItem.
  2871     item ifNil:[^ self].
  2871     item isNil ifTrue:[^ self].
  2872     item canMoveUpOrDown ifFalse:[^ self].
  2872     item canMoveUpOrDown ifFalse:[^ self].
  2873 
  2873 
  2874     self askForItemModification ifFalse:[ ^ self ].
  2874     self askForItemModification ifFalse:[ ^ self ].
  2875 
  2875 
  2876     self withoutNotifyDo:[
  2876     self withoutNotifyDo:[
  3066 
  3066 
  3067 menuItem:aMenuItem
  3067 menuItem:aMenuItem
  3068     |item cls|
  3068     |item cls|
  3069 
  3069 
  3070     cls := self classFor:aMenuItem.
  3070     cls := self classFor:aMenuItem.
  3071     cls ifNil:[^ nil].
  3071     cls isNil ifTrue:[^ nil].
  3072 
  3072 
  3073     item := cls new.
  3073     item := cls new.
  3074     item menuItem:aMenuItem.
  3074     item menuItem:aMenuItem.
  3075   ^ item
  3075     ^ item
  3076 ! !
  3076 ! !
  3077 
  3077 
  3078 !MenuEditor::Item class methodsFor:'interface specs'!
  3078 !MenuEditor::Item class methodsFor:'interface specs'!
  3079 
  3079 
  3080 detailsEditSpec
  3080 detailsEditSpec
  3448 !
  3448 !
  3449 
  3449 
  3450 heightOn:aGC
  3450 heightOn:aGC
  3451     "returns the height of the label on a GC
  3451     "returns the height of the label on a GC
  3452     "
  3452     "
  3453     height ifNil:[ height := parent heightOn:aGC ].
  3453     height isNil ifTrue:[ height := parent heightOn:aGC ].
  3454   ^ height
  3454     ^ height
  3455 !
  3455 !
  3456 
  3456 
  3457 label
  3457 label
  3458     "get the rawLabel assigned to the item
  3458     "get the rawLabel assigned to the item
  3459     "
  3459     "
  3467 !
  3467 !
  3468 
  3468 
  3469 widthOn:aGC
  3469 widthOn:aGC
  3470     "returns the height of the displayLabel on a GC
  3470     "returns the height of the displayLabel on a GC
  3471     "
  3471     "
  3472     width ifNil:[ width := self widthOf:(self displayLabel) on:aGC ].
  3472     width isNil ifTrue:[ width := self widthOf:(self displayLabel) on:aGC ].
  3473   ^ width
  3473     ^ width
  3474 ! !
  3474 ! !
  3475 
  3475 
  3476 !MenuEditor::Item methodsFor:'initialization'!
  3476 !MenuEditor::Item methodsFor:'initialization'!
  3477 
  3477 
  3478 initialize
  3478 initialize
  3573     siblings size > 1 ifFalse:[ ^ false ].
  3573     siblings size > 1 ifFalse:[ ^ false ].
  3574 
  3574 
  3575     index    := siblings identityIndexOf:self.
  3575     index    := siblings identityIndexOf:self.
  3576     nextItem := siblings at:(index - 1)  ifAbsent:nil.
  3576     nextItem := siblings at:(index - 1)  ifAbsent:nil.
  3577 
  3577 
  3578     nextItem ifNil:[^ false].
  3578     nextItem isNil ifTrue:[^ false].
  3579   ^ nextItem canAddChildren
  3579     ^ nextItem canAddChildren
  3580 !
  3580 !
  3581 
  3581 
  3582 canMoveInNext
  3582 canMoveInNext
  3583     "returns true if the item can become a child of its next sibling
  3583     "returns true if the item can become a child of its next sibling
  3584     "
  3584     "
  3588     siblings size > 1 ifFalse:[ ^ false ].
  3588     siblings size > 1 ifFalse:[ ^ false ].
  3589 
  3589 
  3590     index    := siblings identityIndexOf:self.
  3590     index    := siblings identityIndexOf:self.
  3591     nextItem := siblings at:(index + 1)  ifAbsent:nil.
  3591     nextItem := siblings at:(index + 1)  ifAbsent:nil.
  3592 
  3592 
  3593     nextItem ifNil:[^ false].
  3593     nextItem isNil ifTrue:[^ false].
  3594   ^ nextItem canAddChildren
  3594     ^ nextItem canAddChildren
  3595 !
  3595 !
  3596 
  3596 
  3597 canMoveOut
  3597 canMoveOut
  3598     "returns true if the item can be moved out from its current parent
  3598     "returns true if the item can be moved out from its current parent
  3599     "
  3599     "
  3911 
  3911 
  3912     item := super menuItem.
  3912     item := super menuItem.
  3913     self hasDelayedMenu ifTrue:[
  3913     self hasDelayedMenu ifTrue:[
  3914         children first setDelayedAttributesTo:item.
  3914         children first setDelayedAttributesTo:item.
  3915 
  3915 
  3916         menuItem value ifNil:[
  3916         menuItem value isNil ifTrue:[
  3917             menuItem value:#unspecified
  3917             menuItem value:#unspecified
  3918         ]
  3918         ]
  3919     ].
  3919     ].
  3920     ^ item
  3920     ^ item
  3921 !
  3921 !
  5077 retrieverList
  5077 retrieverList
  5078     |list|
  5078     |list|
  5079 
  5079 
  5080     list := builder bindingAt:#retrieverList.
  5080     list := builder bindingAt:#retrieverList.
  5081 
  5081 
  5082     list ifNil:[
  5082     list isNil ifTrue:[
  5083 	list := MenuEditor imageRetrieverClasses asList.
  5083         list := MenuEditor imageRetrieverClasses asList.
  5084 	builder aspectAt:#retrieverList put:list.
  5084         builder aspectAt:#retrieverList put:list.
  5085     ].
  5085     ].
  5086     ^ list
  5086     ^ list
  5087 !
  5087 !
  5088 
  5088 
  5089 selectorHolder
  5089 selectorHolder
  5148         sel := anItem selector.
  5148         sel := anItem selector.
  5149         selector == sel ifTrue:[
  5149         selector == sel ifTrue:[
  5150             imageHolder value:anItem.
  5150             imageHolder value:anItem.
  5151             ^ self
  5151             ^ self
  5152         ].
  5152         ].
  5153         item ifNil:[
  5153         item isNil ifTrue:[
  5154             (sel startsWith:selector) ifTrue:[ item := anItem ]
  5154             (sel startsWith:selector) ifTrue:[ item := anItem ]
  5155         ]
  5155         ]
  5156     ].
  5156     ].
  5157     imageHolder value:nil.
  5157     imageHolder value:nil.
  5158 
  5158 
  5411 ! !
  5411 ! !
  5412 
  5412 
  5413 !MenuEditor::RootItem methodsFor:'displaying'!
  5413 !MenuEditor::RootItem methodsFor:'displaying'!
  5414 
  5414 
  5415 heightOn:aGC
  5415 heightOn:aGC
  5416     height ifNil:[ height := aGC font heightOn:aGC device ].
  5416     height isNil ifTrue:[ height := aGC font heightOn:aGC device ].
  5417   ^ height
  5417     ^ height
  5418 ! !
  5418 ! !
  5419 
  5419 
  5420 !MenuEditor::RootItem methodsFor:'initialization'!
  5420 !MenuEditor::RootItem methodsFor:'initialization'!
  5421 
  5421 
  5422 initialize
  5422 initialize
  5682     ].
  5682     ].
  5683     aGC displayLineFromX:x y:y0 toX:x1 y:y0
  5683     aGC displayLineFromX:x y:y0 toX:x1 y:y0
  5684 !
  5684 !
  5685 
  5685 
  5686 widthOn:aGC
  5686 widthOn:aGC
  5687     width ifNil:[ width := 60 ].
  5687     width isNil ifTrue:[ width := 60 ].
  5688   ^ width
  5688     ^ width
  5689 ! !
  5689 ! !
  5690 
  5690 
  5691 !MenuEditor class methodsFor:'documentation'!
  5691 !MenuEditor class methodsFor:'documentation'!
  5692 
  5692 
  5693 version
  5693 version