Page 1 of 2

launching livecode files in Windows in one instance of LiveCode

Posted: Wed Oct 02, 2024 6:13 pm
by golife
In Windows 11 double clicking a .livecode file (application extension:.livecode, .rev) opens that file in a new instance of LiveCode.exe which I want to prevent. I want to open the file in the IDE of the currently executing LiveCode instance as if opening from the IDE. Maybe I have overseen a solution to this, or I cannot find a solution despite searching. I can prevent LiveCode from starting another process using system tools, but that does not help since the LIveCode file shall still open which is not possible stopping a new process.
Any suggestions? Roland

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Wed Oct 02, 2024 6:32 pm
by Klaus
Hi Roland,

check "relaunch" in the dictionary, sounds like that is what you need. :-)

Best

Klaus

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Wed Oct 02, 2024 10:56 pm
by golife
Klaus, thank you for your reply. I had checked that. It does not work in the IDE, only for standalones.

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 8:59 am
by Klaus
Hi Roland,

hm, if I remember correctly, this is the official way to do so.

Sorry, was in a hurry yesterday. Did you add a handler like this to your stack
that should be opened after the IDE had started:

Code: Select all

##Stackskript or script of first card:
on relaunch
  ### NADA
end relaunch
Best

Klaus

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 8:12 pm
by golife
Klaus:

Code: Select all

on relaunch
-- quit ---- :-)
end relaunch
is not recognized in the IDE. It does not fire.

I cannot think of any solution that is simply scriptable. When opening a file from anywhere except from inside a running instance, a new instance is started. In some cases, this may be desired. In most cases, I do not want it.

What I could do is check with a command line program if an instance of LiveCode.exe is running, and if YES, then intercepting every call to LiveCode.exe on the system level (redirecting to a message sending app using regedit) and using sockets in a library stack that would receive the path of the file to be opened as the message.

The running LiveCode.exe process would then be opening the file processing the message received. But it is no-standard, and it requires Admin rights to install -- at least I think so. I must check it. Possibly, an external C-program hooked into LiveCode could also do this directly inside of LiveCode.exe. I am not sure and not knowledgeable enough to work on this. And I also doubt that LiveCode builder could help here. But what do I really know? :P

I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 8:50 pm
by FourthWorld
golife wrote:
Thu Oct 03, 2024 8:12 pm
I am still hoping that an easier solution exists to prevent a relaunch in the IDE and opens double-clicked files in the running process.
A unique application would need a unique file extension to distinguish its document type.

Once you do that, Klaus did not lead you astray: the relaunch message is indeed the way to prevent documents from launching a new instance, instead opening in the running instance.

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 8:54 pm
by Klaus
I just made a test and it works as I told you!

1. I created a new stack "test1" with this "dummy" handler in the script of its first cd:

Code: Select all

on relaunch
  ##
end relaunch
2. I closed it and created another stack.
3. I double-clicked the stack "test1" and it was opended in the already running instance of Livecode.
Did you try exactly this?
relaunch.png

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 10:24 pm
by golife
Yes, I tried exactly this. Even before writing of course. You are on Windows?
That is interesting. Are there any settings that may be different?

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 11:07 pm
by FourthWorld
What file extension are you using for your LiveCode stackfile documents?

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Thu Oct 03, 2024 11:11 pm
by golife
Just to make sure that I am not mistake, I tested it with three different stacks.

The script is in the stack script. The stack is not dependent on any other stack or resources.

Code: Select all

on relaunch
   ##
end relaunch
Now, for example, saving a copy of the stack to the same folder the running stack is located, and double-clicking that file, opens the file in another window and launches LiveCode as a new instance. Having done this twice, there are now two menu bars, to tools-palettes, etc.

The handler for such an event is never triggered and does not receive such message even though it should (or not)?

The dictionary finally states:
"Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
What does it mean? What is double clicking in a file in the Windows shell? I am running latest version of Windows 11 and the latest LiveCode 9.6.13. But whatever the configuration -- I also tested on other machines -- the result is the same.

The dictionary also says:
If there are no existing instances, the new instance will run.
The relaunch message is passed a variable number of arguments depending on the command-line the new instance is started up with. The processing is the same that is performed for the $n global variables before application startup. i.e. the command-line string is split into words, each word has any leading and trailing quotes stripped and '\' is replaced by '/'.
Maybe there is some hint in here? The $n global?

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Fri Oct 04, 2024 1:15 pm
by Klaus
Hi Roland
golife wrote:
Thu Oct 03, 2024 10:24 pm
You are on Windows?
I started a VM machine (via Paralells on my Mac) with Win11 for testing.
golife wrote:
Thu Oct 03, 2024 10:24 pm
Are there any settings that may be different?
No, this is a fresh installation, did not set anything in Windows so far.

Best

Klaus

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Fri Oct 04, 2024 1:19 pm
by Klaus
golife wrote:
Thu Oct 03, 2024 11:11 pm
The dictionary finally states:
"Note: This feature is only available in the standalone engine, as the IDE engine uses the relaunch facitily to suport loading of stack files into an existing instance of the IDE by double clicking on a file in the Windows shell." --
What does it mean? What is double clicking in a file in the Windows shell?
this just means double-clicking a LC file on the desktop or any open folder.

I also means that the "dummy" handler is not even neccessary, the IDE takes care of this.
So if this is not the case for you, then there is something else going on on your machine!

Try to de-install and re-install LC, maybe that will help

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Sat Oct 05, 2024 5:42 pm
by golife
Yes, as I said from the beginning, the relaunch handler only seems to work in a standalone, as the dictionary states. Yes, I am using Windows 11 latest version. Klaus made another observation, but I cannot reproduce. I am uskng .livecodei or .rev as the file extensions.

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Sat Oct 05, 2024 6:43 pm
by FourthWorld
golife wrote:
Sat Oct 05, 2024 5:42 pm
I am uskng .livecodei or .rev as the file extensions.
Those file extensions are associated with the LiveCode application. That's the missing piece here, file associations.

There really should be a more complete Lesson on document handing, but this tutorial from Ken Ray will point you in the right direction:
http://sonsothunder.com/devres/livecode ... ile004.htm

In short, OSes need some way to know which file types are associated with which apps. On macOS this is done in the plist file included inside the application bundle. On Windows this is handled in the Windows Registry.

That tutorial shows how LiveCode can be used to read and write the appropriate Registry entries to associate your unique file type with your application.

Please note it will need to be a unique file type. File type extensions matter to the OS, but not to the LC engine. The engine can open any valid LC stack file regardless of its file extension.

When opening from within LC this is simple and automatic; scripting "open stack <file path> just works.

It's the part involving the Windows File Explorer, either dragging your document file icon to the app or double clicking it, where the appropriate Registry entry is needed.

Re: launching livecode files in Windows in one instance of LiveCode

Posted: Sat Oct 05, 2024 8:02 pm
by SparkOut
Unless I am misreading, I think the file association is fine.
Double-clicking a file with (eg) extension of .rev will open that file in the IDE.
The problem for the OP is that once opened in the IDE, then double-clicking the same file will also open it, in a new instance of the IDE.
What should normally happen, I believe, is that the original instance of the IDE would attempt to open the file, but halt with a prompt to the user advising a stack with that name is already open, and to choose whether to close, or purge the original.
I don't know why two IDE instances would be initiated.