I think it could be extended on other widgets :) They are only implemented here because the need was for menus in list and text I guess :)
Ben On Nov 29, 2012, at 4:36 PM, Goubier Thierry wrote: > Le 29/11/2012 16:11, Benjamin a écrit : >> Thank you for your explanation, I didn't have time to reply (sorry :( ) >> >> The mechanism describe is still working (or at least should), but I thought >> that the second argument was a boolean to know is shift was pressed or not. >> I may be wrong :) > > Oups :-( You're right, it's the shift status. So it should be : > > textModel menu: [:aMenu :shifted | self buildMenu: aMenu shifted: shifted ] > > And: > > buildMenu: aMenu shifted: shifted > > self isActive ifTrue: [ > (aMenu add: self label target: self selector: #execute) > enablementSelector: #isEnabled; > icon: (self icon notNil > ifTrue: [ UITheme current perform: self icon ] > ifFalse: [ nil ]); > keyText: self keyString ] > > Oh, and I notice that now : #menu: only exists for ListComposableModel and > TreeModel in Spec, so this method will only work for them. But as this is > where you usually needs it, it should be Ok :). > > Thierry > >> Thanks again, > > Thanks for correcting my example. > > Thierry > >> Ben >> >> On Nov 29, 2012, at 4:05 PM, Goubier Thierry wrote: >> >>> Le 28/11/2012 10:03, Torsten Bergmann a écrit : >>>> Can anyone point me to a spec example >>>> with a (context) menu with icons and >>>> where we can enable/disable specific >>>> menue items depending on state? >>>> >>> >>> I'm not sure there is anything Spec specific in menus doing that but... >>> >>> A source for doing what you want is available in the OmniBrowser (Pharo >>> 1.4). I reused a simplified version of that code in the Alt Browser in >>> Pharo 2.0; if you browse around version 40, it is linked to a Spec-built >>> interface. >>> >>> The example goes like that : >>> >>> A menu command object answer the following methods: >>>>> isActive (in the menu or not in the menu) >>>>> isEnabled (greyed out in the menu) >>>>> execute (the command to execute when selected) >>>>> icon (the icon symbol name) >>>>> label (the text of the menu item) >>>>> keyString (if you want to add a keymapping shortcut as well, it lists >>>>> itself in the menu). >>> >>> Building a menu item is then the following, once you get the menu given to >>> you by the widget : >>> >>> buildTreeMenu: aMenu on: aTarget >>> >>> ... >>> self isActive ifTrue: [ >>> (aMenu add: self label target: self selector: #execute) >>> enablementSelector: #isEnabled; >>> icon: (self icon notNil >>> ifTrue: [ UITheme current perform: self icon ] >>> ifFalse: [ nil ]); >>> keyText: self keyString ] >>> ... >>> >>> When you create your Spec GUI, you ask the widget model to give you the >>> menu before showing it to the user (this is in initializePresenter) >>> >>> textModel menu: [:aMenu :aTarget | self buildMenu: aMenu on: aTarget ] >>> >>> The resulting menu will look like the picture in attachment. >>> >>> Note: This is with a fairly old version of Spec. Newer versions may have >>> changed the way to get the menu from the widget model. >>> >>> Note 2: Since the menu is built each time the user asks for it then its >>> easy to have a menu which depends on the state of the application (the type >>> of selected item, etc...) >>> >>> Thierry >>> -- >>> Thierry Goubier >>> CEA list >>> Laboratoire des Fondations des Systèmes Temps Réel Embarqués >>> 91191 Gif sur Yvette Cedex >>> France >>> Phone/Fax: +33 (0) 1 69 08 32 92 / 83 95 >>> <Capture du 2012-11-29 15:45:34.png> >> >> >> >> > > > -- > Thierry Goubier > CEA list > Laboratoire des Fondations des Systèmes Temps Réel Embarqués > 91191 Gif sur Yvette Cedex > France > Phone/Fax: +33 (0) 1 69 08 32 92 / 83 95 >
