Page 1 of 1

find file dialog box

Posted: Wed Feb 18, 2015 11:25 pm
by david_fff
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

Re: find file dialog box

Posted: Wed Feb 18, 2015 11:41 pm
by FourthWorld
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.

Re: find file dialog box

Posted: Wed Feb 18, 2015 11:54 pm
by david_fff
Thanks, Richard. Funny how Hypercard begat Supercard, which begat Metacard, which begat Revolution, which begat LiveCode. :D

Re: find file dialog box

Posted: Thu Feb 19, 2015 12:01 am
by FourthWorld
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. :)