I am trying to change the #text: of a Menu (created in the VC as the only
item of a Shell's MenuBar). The text of the Menu is left empty and in the #onViewOpened method of the Shell to which the MenuBar containing the Menu belongs, I set the text of the menu to a string. The value of the Menu's variable named 'text' changes, but the text that is shown in the menu bar remains the same. How do I make the change appear in the menu bar of the shell? Best regards, Mikael Svane |
Mikael,
"Mikael Svane" <[hidden email]> wrote in message news:[hidden email]... > I am trying to change the #text: of a Menu (created in the VC as the only > item of a Shell's MenuBar). The text of the Menu is left empty and in the > #onViewOpened method of the Shell to which the MenuBar containing the Menu > belongs, I set the text of the menu to a string. The value of the Menu's > variable named 'text' changes, but the text that is shown in the menu bar > remains the same. How do I make the change appear in the menu bar of the > shell? Check the command query (which goes to #queryCommand:). I think there's a place to set the text there to change it everywhere that responds to that command. Be advised that I'm just going from memory, though. Just be aware that if you put a #halt in #queryCommand: you can get into a bit of trouble (it gets called a lot). Don > > Best regards, > Mikael Svane > > |
Mikael,
To Don's reply, I will add that IDE extensions can be a good source of examples. Just a hunch, but I suspect you are changing the text of a Smalltalk object after the menu is realized, and therefore not changing the Windows (queue throat-clearing wave file) object. I second Don's point about breakpoints with this type of coding. That's not to say that you should be afraid to use them, but you should recognize that things can get ugly. It's best to make an occaisional backup in case you (voice of experience) accidentally save the image after doing something risky. Also note that you can use a global variable to create a breakpoint that will fire only once. To the group at large, have any of you created a smart breakpoint class? It seems like one could have something like Breakpoint breakOnceIf:[ x < y ]. Breakpoint breakOnce. Is that asking too much? Back to watching Frances, and then Ivan :( Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
Don and Bill,
Thanks for your help. I was unable to change the text of the menu (as Bill suggested, I was only changing the text of the Smalltalk object). Instead, I created the entire menu programmatically which solved the problem. Best regards, Mikael Svane "Bill Schwab" <[hidden email]> skrev i meddelandet news:[hidden email]... > Mikael, > > To Don's reply, I will add that IDE extensions can be a good source of > examples. Just a hunch, but I suspect you are changing the text of a > Smalltalk object after the menu is realized, and therefore not changing the > Windows (queue throat-clearing wave file) object. > > I second Don's point about breakpoints with this type of coding. That's not > to say that you should be afraid to use them, but you should recognize that > things can get ugly. It's best to make an occaisional backup in case you > (voice of experience) accidentally save the image after doing something > risky. > > Also note that you can use a global variable to create a breakpoint that > will fire only once. > > To the group at large, have any of you created a smart breakpoint class? It > seems like one could have something like > > Breakpoint breakOnceIf:[ x < y ]. > Breakpoint breakOnce. > > Is that asking too much? > > Back to watching Frances, and then Ivan :( > > Have a good one, > > Bill > > -- > Wilhelm K. Schwab, Ph.D. > [hidden email] > > > |
In reply to this post by Bill Schwab-2
Bill Schwab wrote:
> To the group at large, have any of you created a smart breakpoint class? > It seems like one could have something like > > Breakpoint breakOnceIf:[ x < y ]. > Breakpoint breakOnce. I have an extremely trivial (four method) Once class which is intended to be used like: Once do: [self halt]. I've just added #do:if: to it (making it 25% bigger -- talk about code bloat). Thanks for the suggestion ! It seems too trivial to post, but I'll stick in onto the end of this message anyway... The problem with such things is that I use them so rarely that I have always forgotten how to use them by the next time I need them. I also have a simple little framework for halting/traceing conditionally on whether an object, its class, or the Shell it's part of, have been "marked" for debugging. I used to use that a bit, especially for putting breakpoints in core classes, but I don't think I've used it at all in years (maybe because I know my way around the system classes rather better these days). It's sort of sad how one creates these things then never uses them :-( It's a bit more elaborate than 'Once' but if anyone's interested, do drop me a line, or say here. -- chris "Filed out from Dolphin Smalltalk XP"! Object subclass: #Once instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' classInstanceVariableNames: 'times'! Once guid: (GUID fromString: '{3291FA17-64CB-11D5-B5CC-00B0D07894B1}')! Once comment: 'Simple class used to make things happen just once. Use as Once do: [..something]. All subsequent calls to #do: will then be ignored untill such time as Once class>>reset or Once class>>reset: n is called.'! !Once categoriesForClass!Unclassified! ! !Once class methodsFor! do: a0Block "if the we are not already saturated then answer the result of evaluating a0Block" ^ times > 0 ifTrue: [times := times-1. a0Block value] ifFalse: [nil].! do: a0Block if: another0Block "if the receiver is not already saturated, and another0Block answers true, then answer the result of evaluating a0Block" "NB: not coded as: ^ another0Block ifTrue: [self do: a0Block]. since that would evaluate a0Block even if we were saturated" ^ (times > 0 and: [another0Block value]) ifTrue: [times := times-1. a0Block value] ifFalse: [nil]. ! initialize "private -- class initialisation, called when we are loaded into the image self initialize. " self reset.! reset "reset the receiver so that it will fire just once. self reset. " self reset: 1.! reset: aNumber "reset the receiver so that it will fire aNumber of times" times := aNumber.! ! !Once class categoriesFor: #do:!operations!public! ! !Once class categoriesFor: #do:if:!operations!public! ! !Once class categoriesFor: #initialize!initializing!private! ! !Once class categoriesFor: #reset!operations!public! ! !Once class categoriesFor: #reset:!operations!public! ! |
In reply to this post by Mikael Svane
I didn't want to give up trying to change the menu text dynamically quite
yet. The reason for my interest in this is that it allows me to create a complex menu in the VC (rather than programmatically), giving each submenu and command a name. Then, by finding the item using the name rather than it's text, it is easy to change the language of the menu by changing the text. At first, I tried ShellView>>drawMenuBar but didn't get it to work, despite its' comment which says: "draw the receiver's menu bar, either when initially set or after it has been updated". After some more experimenting, I found the following code, which updates the menu: (in a Shell subclass, after having changed the text of the menus:) self view menuBar: self view menuBar copy Best regards, Mikael Svane "Mikael Svane" <[hidden email]> skrev i meddelandet news:[hidden email]... > Don and Bill, > > Thanks for your help. I was unable to change the text of the menu (as Bill > suggested, I was only changing the text of the Smalltalk object). Instead, I > created the entire menu programmatically which solved the problem. > > Best regards, > Mikael Svane > > "Bill Schwab" <[hidden email]> skrev i meddelandet > news:[hidden email]... > > Mikael, > > > > To Don's reply, I will add that IDE extensions can be a good source of > > examples. Just a hunch, but I suspect you are changing the text of a > > Smalltalk object after the menu is realized, and therefore not changing > the > > Windows (queue throat-clearing wave file) object. > > > > I second Don's point about breakpoints with this type of coding. That's > not > > to say that you should be afraid to use them, but you should recognize > that > > things can get ugly. It's best to make an occaisional backup in case > > (voice of experience) accidentally save the image after doing something > > risky. > > > > Also note that you can use a global variable to create a breakpoint that > > will fire only once. > > > > To the group at large, have any of you created a smart breakpoint class? > It > > seems like one could have something like > > > > Breakpoint breakOnceIf:[ x < y ]. > > Breakpoint breakOnce. > > > > Is that asking too much? > > > > Back to watching Frances, and then Ivan :( > > > > Have a good one, > > > > Bill > > > > -- > > Wilhelm K. Schwab, Ph.D. > > [hidden email] > > > > > > > > |
Free forum by Nabble | Edit this page |