find file dialog box

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
david_fff
Posts: 29
Joined: Wed Nov 12, 2014 5:29 pm

find file dialog box

Post by david_fff » Wed Feb 18, 2015 11:25 pm

In Supercard all you need to to is type Open proj "xxx" and a dialog box opens so you can locate the project, but how is this done in Livecode?
Thanks,
David

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: find file dialog box

Post by FourthWorld » Wed Feb 18, 2015 11:41 pm

Hello David - good to see another SuperCard fan here.

SC's behavior there is less of a feature per se than a graceful way to handle an error - the error being that there is no project file at "xxx".

In LiveCode, file open operations, whether stack files or any other file, are handled by reporting errors in the result, which you can check immediately after attempting to open a file to determine what to do next, e.g.:

Code: Select all

open stack "xxxx"
if the result is not empty then
    --- error handling here
end if
If you want a generic handler you can call to achieve something similar to the way SC handles project files it can't find you could use:

Code: Select all

on mouseUp
   OpenStackFile "SomeFile"
end mouseUp

on OpenStackFile pFile
   if there is not a stack pFile then
      answer file "Where is the stack file "& quote& pFile& quote&"?" \
            with type "LiveCode Stack|livecode,rev,mc|RSTK" or type "All Files|*|*"
      if it is empty then exit to top
      if there is not a stack it then
         answer "Not a stack file: "& it
         exit to top
      end if
      put it into pFile
   end if
   open stack pFile
end OpenStackFile
Note that the "answer file" statement seems kinda long - that's by design: in LC it's a very flexible command allowing you to list multiple file types for the GetFile dialog filter. See the Dictionary entry for the "answer file" command for details on that.

Also, the "is a stack" function is pretty nifty. LC also include "is a file" and "is a folder", but when you use "is a stack" it not only checks to see if the file exists, but ensures that it's also a valid LiveCode stack file.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

david_fff
Posts: 29
Joined: Wed Nov 12, 2014 5:29 pm

Re: find file dialog box

Post by david_fff » Wed Feb 18, 2015 11:54 pm

Thanks, Richard. Funny how Hypercard begat Supercard, which begat Metacard, which begat Revolution, which begat LiveCode. :D

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: find file dialog box

Post by FourthWorld » Thu Feb 19, 2015 12:01 am

Yeah, I'm just glad there are two left. In the past I've shipped projects with Oracle Media Objects, Gain Momentum, and Asymetrix Toolbook, and while I guess TB is still around I haven't seen other xTalks around in a long time.

Too bad you're jumping on board here only now: a few years ago at the LiveCode Conference in San Jose we had a special guest presentation by Bill Atkinson himself. It was great to finally meet him in person, and I think he had a good time too - after all, there are few places you can go with 200 people in one room who all think you're a god. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply