Menu command question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Menu command question

Dan Antion
I have an application where the user has to select a folder to work in.
I want to provide a menu for "Recent Folders" Thanks to several previous
posts, I think I have the hang of modifying a menu, my problem is having
  the menu options linked to a command that takes a parameter.  I have
an OrderedCollection of recently selected folders.  From that I can
build a menu, showing the path strings as options.  I'd also like to
pass the path as an argument to setWorkingFolder: aFolder, but I can't
figure out how to structure a menu command (I'm building the menu using
fromStrings: ) so that I can append an index or string as a parameter.

I also realize that I might be suffering from stubbornness, and perhaps
I'm just trying to implement this the wrong way.

Any suggestions would be appreciated.

thanks
-Dan
Dan Antion
American Nuclear Insurers


Reply | Threaded
Open this post in threaded view
|

Re: Menu command question

Christopher J. Demers
"Dan Antion" <[hidden email]> wrote in message
news:[hidden email]...
> I have an application where the user has to select a folder to work in.
> I want to provide a menu for "Recent Folders" Thanks to several previous
...
> build a menu, showing the path strings as options.  I'd also like to
> pass the path as an argument to setWorkingFolder: aFolder, but I can't
> figure out how to structure a menu command (I'm building the menu using
> fromStrings: ) so that I can append an index or string as a parameter.

This is what I do for a recent files menu (the formatting won't make the
Usenet voyage so well):

======
populateRecentFilesMenu: aMenu
| fileNames count |
"fileNames := #('c:\blah\fileName.ext' 'c:\blah\fileName2.ext'
'c:\blah\fileName5.ext')."
fileNames := self getMRUFiles.
aMenu clear.
count := 1.
fileNames do: [:each |
aMenu addCommand: (MessageSend
receiver: self
selector: #cmdOpenRecentFile:
argument: each)
description: count displayString , ') ', each.
count := count + 1].
aMenu addCommand: (MessageSend
receiver: self
selector: #cmdClearRecentFiles)
description: 'Clear List'.
================

Hope this helps,
Chris


Reply | Threaded
Open this post in threaded view
|

Re: Menu command question

Blair McGlashan
In reply to this post by Dan Antion
"Dan Antion" <[hidden email]> wrote in message
news:[hidden email]...

> I have an application where the user has to select a folder to work in.
> I want to provide a menu for "Recent Folders" Thanks to several previous
> posts, I think I have the hang of modifying a menu, my problem is having
>   the menu options linked to a command that takes a parameter.  I have
> an OrderedCollection of recently selected folders.  From that I can
> build a menu, showing the path strings as options.  I'd also like to
> pass the path as an argument to setWorkingFolder: aFolder, but I can't
> figure out how to structure a menu command (I'm building the menu using
> fromStrings: ) so that I can append an index or string as a parameter.
>
> I also realize that I might be suffering from stubbornness, and perhaps
> I'm just trying to implement this the wrong way.
> ...

Yes, #fromStrings: won't do what you want. Try browsing references to
#addCommand:description: in the image, which shows many examples of how
dynamic menus are built up in the system. You'll see that in some cases a
fully closed MessageSend is used (i.e. the receiver, selector, and arguments
are all predetermined), and in others a Message is used (i.e. just selector
and arguments predetermined, with the receiver dynamically determined by
normal command routing).

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: Menu command question

Dan Antion
In reply to this post by Christopher J. Demers
Christopher J. Demers wrote:

> "Dan Antion" <[hidden email]> wrote in message
> news:[hidden email]...
>
>>I have an application where the user has to select a folder to work in.
>>I want to provide a menu for "Recent Folders" Thanks to several previous
>
> ...
>
>>build a menu, showing the path strings as options.  I'd also like to
>>pass the path as an argument to setWorkingFolder: aFolder, but I can't
>>figure out how to structure a menu command (I'm building the menu using
>>fromStrings: ) so that I can append an index or string as a parameter.
>
>
> This is what I do for a recent files menu (the formatting won't make the
> Usenet voyage so well):
>
> ======
> populateRecentFilesMenu: aMenu
> | fileNames count |
> "fileNames := #('c:\blah\fileName.ext' 'c:\blah\fileName2.ext'
> 'c:\blah\fileName5.ext')."
> fileNames := self getMRUFiles.
> aMenu clear.
> count := 1.
> fileNames do: [:each |
> aMenu addCommand: (MessageSend
> receiver: self
> selector: #cmdOpenRecentFile:
> argument: each)
> description: count displayString , ') ', each.
> count := count + 1].
> aMenu addCommand: (MessageSend
> receiver: self
> selector: #cmdClearRecentFiles)
> description: 'Clear List'.
> ================
>
> Hope this helps,
> Chris
>
>

Thanks Chris!  This will work nicely.

-Dan