LiveCode 开发人员如何从标准模板模拟多个打开的文档?
How do LiveCode developers simulate multiple open documents from a standard template?
我们需要创建一个文本编辑器类型的应用程序,它可以同时打开多个文本windows。
windows 应该都使用相同的堆栈布局。
是否可以多次打开一个堆栈,就好像堆栈是一个模板或"stationery"?
如果是这样,那么我们可以将 empty
文本注入 openStack 上的文本字段,以使用堆栈作为模板创建一个新的空白文本编辑器文档。
如果用户想要打开现有的文本文件,那么我们可以 put URL "file://xyz.txt" into field "Text Editor" of stack "the new text editor window"
这在概念上类似于旧的 Mac "Stationery" 文档的经典想法,这些文档是不可更改的,但是当用户在 Finder 中双击文档时,它将在新的 window,并被称为 "Untitled #1".
我们好像记得LiveCode里曾经有一个设置,把一个子栈保存为一个"template",这样就可以用来显示几个相同的windows.
在通过 LiveCode UI 和字典进行谷歌搜索后,我们唯一找到的是
templateStack
如果我们要使用 templateStack
那么我们将不得不以编程方式构建整个堆栈,这破坏了 LiveCode 编程范例的简单性。
我们是不是处理错了?
LiveCode 开发者如何从标准模板模拟多个打开的文档?
我们唯一的解决方法是创建一个子堆栈作为模板,隐藏模板,然后当我们需要一个新的文本编辑器时 window 我们需要:
- 创建一个新的完全空的堆栈
- 对于模板堆栈中的每一项...
- 在新文本编辑器中创建一个重复项window。
我们走错路了吗?
您可以按如下方式使用 "clone"。
(这不是 'simulation',而是使用模板堆栈的一种方法。)
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
我们需要创建一个文本编辑器类型的应用程序,它可以同时打开多个文本windows。
windows 应该都使用相同的堆栈布局。
是否可以多次打开一个堆栈,就好像堆栈是一个模板或"stationery"?
如果是这样,那么我们可以将 empty
文本注入 openStack 上的文本字段,以使用堆栈作为模板创建一个新的空白文本编辑器文档。
如果用户想要打开现有的文本文件,那么我们可以 put URL "file://xyz.txt" into field "Text Editor" of stack "the new text editor window"
这在概念上类似于旧的 Mac "Stationery" 文档的经典想法,这些文档是不可更改的,但是当用户在 Finder 中双击文档时,它将在新的 window,并被称为 "Untitled #1".
我们好像记得LiveCode里曾经有一个设置,把一个子栈保存为一个"template",这样就可以用来显示几个相同的windows.
在通过 LiveCode UI 和字典进行谷歌搜索后,我们唯一找到的是
templateStack
如果我们要使用 templateStack
那么我们将不得不以编程方式构建整个堆栈,这破坏了 LiveCode 编程范例的简单性。
我们是不是处理错了?
LiveCode 开发者如何从标准模板模拟多个打开的文档?
我们唯一的解决方法是创建一个子堆栈作为模板,隐藏模板,然后当我们需要一个新的文本编辑器时 window 我们需要:
- 创建一个新的完全空的堆栈
- 对于模板堆栈中的每一项...
- 在新文本编辑器中创建一个重复项window。
我们走错路了吗?
您可以按如下方式使用 "clone"。 (这不是 'simulation',而是使用模板堆栈的一种方法。)
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