Page 1 of 1
Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 3:40 pm
by Mag
Hi all,
I have a Mac application that can open files. I would like to add a "recents" popup menu that list the name of the files user opened. When user choose a menu item the file is opened. Some suggestion in how is the best way to accomplish this with LC?
PS
Would be great to be able to add a Clear Recents menu item and a menuitem grey that appairs when there are not recents (No Recents).
Re: Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 7:01 pm
by Simon
Hi mag,
This sounds like a "Preferences" or "Data" file, lots of posts in the forums on that.
Pretty much just write the files names (url's) to an external file and save. Clearing the names I think you'll see is easy.
Write them to another stack seems popular, I like using a text file because they are easy to read.
Simon
Re: Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 8:12 pm
by Mag
Hi Simon, thank you so much for the message. Before to store data on disk, I would like to understand what is best to do when I have a file path, how to process it and local store name and path, what kind of container is better to use and hw to populate the menu. Any experience or suggestion on this will be welcome!
Re: Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 8:32 pm
by Simon
Hi Mag,
here:
http://forums.runrev.com/phpBB2/viewtop ... ile#p81542
I think the last posting gives you the right info. The only thing I'd change is the open/read/close thing. It's easier just to say "put url("file:"specialFolderPath("Documents") & "/prefs.txt"" into myVar" and read from that. Writing is the same.
Simon
Re: Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 8:39 pm
by Mag
Thank you Simon, and how do you usually handle the populating of menu items?
Re: Best way to populate a recent files popup menu button
Posted: Sat Jul 27, 2013 9:04 pm
by Simon
For a Open Recent File you'd have to either set a max number of items or build on the fly.
The items are just buttons all grouped together.
Code: Select all
set itemDel to "/"
set the label of button "3rdchoice" to the last item of line 3 of myVar --line 3 contains the url to file
and for the button
Code: Select all
put line 3 of myVar into tDoc
launch document tDoc
I guess you'd have to make myVar a global.
Simon
EDIT: I suppose it could just be a list and not actual buttons.
Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 4:03 pm
by Mag
Thank you for the post. Actually I don't need to store the info between sessions. Anyway thank you for the info.
I noticed that if I want to set a menuitems like these:
http://www.apple.com
http://www.apple.com/iphone
I get these:
http:/www.apple.com
http:/www.apple.comiphone
Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 4:16 pm
by Klaus
HI Mag,
since the SLASH is used as a delimiter for menu shortcuts, you have to ESCAPE (= replace

) the SLASHES like this:
...
http:\/\/
www.apple.com
http:\/\/www.apple.com\/iphone
...
Best
Klaus
Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 5:27 pm
by Mag
Thank you.
And how I populate the menu via code? Via inspector is easy, I just enter the text, but via code, I don't find the right way in docs.
Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 5:30 pm
by Klaus
...
set the text of btn "your menu here" to tVar
...

Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 5:57 pm
by Mag
Klaus wrote:...
set the text of btn "your menu here" to tVar
...

YEAH!
PS
No clickable emoticons yet

Re: Best way to populate a recent files popup menu button
Posted: Sun Jul 28, 2013 7:01 pm
by Mag
Thank you so much Simon and Klaus, with your help I done a great implementation of my recents button!