Best way to populate a recent files popup menu button

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Best way to populate a recent files popup menu button

Post by Mag » Sat Jul 27, 2013 3:40 pm

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).

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Best way to populate a recent files popup menu button

Post by Simon » Sat Jul 27, 2013 7:01 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sat Jul 27, 2013 8:12 pm

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Best way to populate a recent files popup menu button

Post by Simon » Sat Jul 27, 2013 8:32 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sat Jul 27, 2013 8:39 pm

Thank you Simon, and how do you usually handle the populating of menu items?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Best way to populate a recent files popup menu button

Post by Simon » Sat Jul 27, 2013 9:04 pm

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.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sun Jul 28, 2013 4:03 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Best way to populate a recent files popup menu button

Post by Klaus » Sun Jul 28, 2013 4:16 pm

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

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sun Jul 28, 2013 5:27 pm

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.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Best way to populate a recent files popup menu button

Post by Klaus » Sun Jul 28, 2013 5:30 pm

...
set the text of btn "your menu here" to tVar
...
:-)

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sun Jul 28, 2013 5:57 pm

Klaus wrote:...
set the text of btn "your menu here" to tVar
...
:-)
YEAH!

PS
No clickable emoticons yet :(

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Best way to populate a recent files popup menu button

Post by Mag » Sun Jul 28, 2013 7:01 pm

Thank you so much Simon and Klaus, with your help I done a great implementation of my recents button!

Post Reply

Return to “Mac OS”