How do LiveCode developers simulate multiple open documents from a standard template? - livecode

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:
Create a new totally empty stack
For each item in the template stack...
Create a duplicate item in the new text editor window.
Are we on the wrong track?

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

Related

What are the requirements of a NETSuite PDF Template that will allow it to accept a page break?

Currently trying to write my first NETSuite PDF template, and am struggling with so many aspects of it.
I am unable to add an "End Of Page" to my template.
When I click the button, nothing happens.
I have tried...
Examining default templates in which I can add pages, and identifying the code change associated with the change. I could not find any change.
Creating a brand new template, and trying to add a new page. I was not able to.
"End of Page" just inserts a page break - <pbr />.
You can switch to Source Code view to see exactly where it's inserted, and usually it's not where you want if you're using the WYSIWYG editor. So you can move or manually enter the <pbr /> in the correct place in the Source Code editor instead.

How to get the text of a menu item with its ID

I have an old visual prolog project in which I have to change the text of a menu during runtime.
This is what I've done to change the text:
menu_setText(Win, id_menu, NewMenuText)
This works fine, however, when I want to enable/disable this menu, the following does not work (meaning the menu item doesn't change its state):
menu_Enable(Win, id_menu, b_true)
After some search, I found that:
Under MS-Windows, submenus can not be referred to by a resource identifier. If the menu entry for a submenu, needs to enabled, disabled, checked or have the text changed. it is necessary to use a special versions of the menu_Enable, menu_Check and menu_SetText predicates, which specify the text of the menu entry instead of the constant.
menu_Enable(WinHandle, String, BOOLEAN)
menu_Check(WinHandle, String, BOOLEAN)
menu_SetText(WinHandle, String, NewString)
The weird thing is that in my case, menu_setText works just fine with the constant where menu_Enable requires the text itself. (yes I tested menu_Enable with the initial text of the menu item, but when the text changes then everything breaks)
Here comes my question:
How can I enable/disable a menu when I know its ID but not its name ?
If not possible directly, how can I get the current name of a menu when I know its ID ?
In case this helps, this project is opened and compiled with VIP52 (since before the year 2001).
I finally found a workaround that solves my problem, but I'm still not really satisfied, so if anyone comes up with a better answer, I'll take it !
I declared:
txt_menu(menu_tag,string)
And then called:
txt_menu(id_menu, MenuText),
menu_setText(Win, MenuText, NewText),
retractAll(txt_menu(id_menu,_)),
assert(txt_menu(id_menu,NewText)),
menu_Update(Win)
whenever I have to change the text of a menu item, and this can easily be transformed into a menu_setTextById predicate as such:
menu_setTextById(Win, MenuId, NewText):-
txt_menu(MenuId, MenuText),
menu_setText(Win, MenuText, NewText),
retractAll(txt_menu(MenuId,_)),
assert(txt_menu(MenuId, NewText)),
menu_Update(Win).
with the usage:
menu_setTextById(Win, id_menu, "My new text menu").
Noted that if I ever have the need to have several windows with menus, I'll have to add the Window Id to my txt_menu clause.
The main problem with this workaround is that I can't use & in the new text menu because if my menu has "&Menu" as text (meaning that M will be underlined), then trying to use menu_setText(Win,"&Menu","New Menu") will break because "&Menu" is not found.
So I'd need to remove any ampersand from the string before trying to use it in such predicates.

How to create button to another stack - Livecode

I want to create button to another stack with code
I have two stack.And Stacks name is "AA" and "BB"
I want to create button in stack "BB" from stack "AA" with my code
on createDigits
create button "test" of stack "BB"
end createDigits
Results: It's create in stack name "AA" and this error message:
Here's one way to do what you want:
on createDigits
set the defaultStack to "BB"
create button "test"
end createDigits
What Mark said.
The "create" command only works on the current card. You therefore have to navigate to that card in order to use the command. Mark used the "defaultStack" command to navigate to the target stack. You could also:
lock screen.
go stack "BB".
create button "test".
go back
That sort of thing.
Craig Newman

How to create custom expandable dialog using ControlsFX

I want to create the same dialog as the one created when using Dialogs.showException(), but instead of showing the stacktrace, I want to show my custom pre-formatted text. The functionality that I want is the Details button behavior.
What I want is this:
But not with the printed stacktrace.
What I have tried is to create my own Throwable, populate it with StackTraceElement objects(filled with the the text that I need) and overwrite the getStackTrace() method to return the populated array. The problem is that the stack trace is displayed from the point where the exception is thrown so the text that I need is shown at the bottom of the expanded pane.
ControlsFX is an open source project.
The source of the Exception Dialog is available here. I'm a ControlsFX committer, so ping me if you need more information.

Custom theming Drupal 6 Menus

Is there a hook or preprocess function that I can access to write my own theming function for a drupal menu (in this case, primary links)?
I have a rather complex menu structure that requires a little extra markup than I'm currently getting by just rendering the menu items in a block (involving sub-menus with a little custom markup) and really need to get access to build the menu's content variable myself, ideally from an array that has all the primary links and their children in scope.
While it may not be the best solution, it is one that worked quite quickly and painlessly:
Drupal keeps a cached version of all your menus in the cache_menu table, I ran a this query to retreive a serialized string containing all the contents of the menu:
SELECT data FROM menu_cache WHERE serialized = 1 AND cid LIKE 'links:primary_links:%';
Substitute primary_links for whatever the name of your menu is and call unserialize on $row->data to get a structured array of everything you should need to build a custom menu.
I call a function in hook_preprocess_block that swaps the content of the menu block with my own and everything seems to be working fine.

Resources