Reputation: 23
We need to create a text-editor type app that can open multiple text windows at the same time.
The windows should all use the same stack layout.
Is it possible to open one stack several times as if the stack were a template or "stationery"?
If so, then we could inject empty
text into the text field on openStack to create a new blank text editor document using the stack as a template.
If the user wanted to open an existing text file, then we could put URL "file://xyz.txt" into field "Text Editor" of stack "the new text editor window"
This would be conceptually like the old Mac Classic idea of "Stationery" documents which were unchangeable, but when a user double-clicked on the document in the Finder it would open in a new window, and be called "Untitled #1".
We seem to remember there was once a setting in LiveCode to save a sub-stack as a "template" so that it could be used to display several identical windows.
After googling and searching through the LiveCode UI and Dictionary the only thing we found was
templateStack
If we were to use templateStack
then we would have to build an entire stack programmatically, which defeats the simplicity of the LiveCode programming paradigm.
Are we approaching this wrong?
How do LiveCode developers simulate multiple open documents from a standard template?
The only workaroud which we had was to create a substack as a template, keep the template hidden, and then when we need a new text editor window we would need to:
Are we on the wrong track?
Upvotes: 2
Views: 246
Reputation: 46
You could use "clone" as follows. (This is not a 'simulation' but one way to use template stacks.)
local templatePath="/Users/admin/myTemplates"
on mouseUp
lock screen
-- clone from file
put templatePath & "/mytemplate.livecode" into longPath
clone stack longPath
-- # or clone from an open stack:
-- clone stack "mytemplate"
put 1 into J
repeat while there is a stack ("copy_"&J)
add 1 to J
end repeat
put ("copy_"&J) into newName
set name of it to newName -- named but not yet saved!
set title of stack newName to (newName & " (not yet saved)")
go stack newName
put URL ("file:" & templatePath & "/myNew.txt") into fld "mainEdit"
unlock screen
end mouseUp
Upvotes: 3