LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
richmond62 wrote: Tue Apr 23, 2024 12:31 pm
2. Stop those messages from shiwing up in the Message Watcher.
I bet on this.
After digging in the IDE scripts, I wrote this script but I don't like it.
1 - I'm not sure it performs all the actions that should be
2 - I don't really like calling commands from the IDE scripts because they are of course subject to change in future LC versions
on myStacksCloseAndRemove closedShortNameStack // closedShortNameStack : short name of the stack to close
if (there is a stack closedShortNameStack) then
put the long id of stack closedShortNameStack into tStackID
else exit dpal_stackCloseAndRemove
try
----------- Update Script Editor (with stack "...app/Contents/Tools/Toolset/libraries/revbackscriptlibrary.livecodescript")
revIDEHandleObjectDeleted tStackID
----------- Close the stack and its substacks
put the subStacks of stack tStackID into tSubstacks
put the lockMessages into savedLockMessages
lock messages // prevent user stack saving during the close, erasing substacks
repeat for each line tSubStack in tSubstacks
close stack tSubStack
end repeat
delete stack tStackID // main stack
set the lockMessages to savedLockMessages
----------- Update Project Browser
if ("revIDEProjectBrowser" is among the lines of the openStacks) then dispatch "deleteStackFromProjectBrowser" to \
stack "revIDEProjectBrowser" with the long name of stack closedShortNameStack // openStacks : short names
catch errMsg
answer error "Unable to close and remove from memory stack '" & closedShortNameStack & "':" & cr & cr & \
errMsg with "Cancel"
end try
end myStacksCloseAndRemove
This does not delete the file, it only removes it from LC. There is no save dialog or other interference. Since it doesn't need messages to be locked, the script editor should respond as expected.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
You're right and thanks for bringing that up. If the mainstack isn't saved the substack will still be there, but it's dangerous if you forget and save the mainstack.
It's unfortunate that MC chose such a confusing term for removing a stack from memory.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
## the script editor tabs are named using the rugged id of the objects
## Menu Window of LC lists the available stacks as the short names of the stacks
## a closed stack is not listed in Menu Window of LC
## this is used as reference for script tabs that point to not available (closed) stacks
on mouseUp
## get list of available stacks from Menu Window of LC
put revIDEWindowList() into tWindowList
## convert the stack names to rugged IDs of the stacks
repeat for each line aStack in tWindowList
put revruggedID (aStack) & cr after tRuggedList
end repeat
put tRuggedList into tWindowList
## remove editors and LC stuff
filter tWindowList without "*rev*"
## get all open Script Editors
put revListScriptEditors() into tAllEditors
## get the tab names of all open editors
repeat for each line anEditor in tAllEditors
send "listTabs" to group "Script Tabs" of anEditor
put the result & cr after tTabList
end repeat
delete char -1 of tTabList
## extract the stack names from the tab names
## we only need to know the stack names
## this is immune against funny names of stacks
## e.g. "my collection of stack xyz"
## since only the first occurence of " of stack " it tested
## which is always before the short name of the stack
set the itemDelimiter to " of stack "
repeat for each line anEntry in tTabList
if first word of anEntry is "stack" then
put anEntry & cr after tCleanStackList
else
put "stack " & item 2 to -1 of anEntry & cr after tCleanStackList
end if
end repeat
set the itemDelimiter to comma
## test for stacks not listed in the Menu Window hence probably closed
repeat for each line aStack in tCleanStackList
if aStack is not among the lines of tWindowList then
put aStack & cr after tMissing
end if
end repeat
delete char -1 of tMissing
if tMissing is empty then exit to top
-- remove duplicates
split tMissing by return as set
put the keys of tMissing into tMissing
repeat for each line aMissingStack in tMissing
try
## convert rugged id to long id since "revSEObjectDeleted" expects a long id
put the long id of stack aMissingStack into tObject
send "revSEObjectDeleted tObject" to revScriptEditorMain()
catch e
put e & cr & anEditor
beep
end try
end repeat
end mouseUp
Kind regards
Bernd
EDIT: I updated the script according to Zax´s correction from below
Last edited by bn on Wed Apr 24, 2024 3:49 pm, edited 1 time in total.
repeat for each line anEntry in tTabList
if first word of anEntry is "stack" then
put anEntry & cr after tCleanStackList
else
put "stack " & item 2 to -1 of anEntry & cr after tCleanStackList
end if
end repeat
repeat for each line anEntry in tTabList
if first word of anEntry is "stack" then
put anEntry & cr after tCleanStackList
else
put "stack " & item 2 to -1 of anEntry & cr after tCleanStackList
end if
end repeat
Oops, that was a cleanup mistake. I had a "next repeat" at the end of the conditional.
But your solution is more elegant.
Thanks
richmond62 wrote: Tue Apr 23, 2024 7:27 pm
And that stereotypical discussion behaviour I described elsewhere continues:
1. Richmond suggests stuff with 'spades' and other crude ways.
2. Craig or Stam bring up something slightly better (as in cotton underpants rather than hessian 'passion killers').
3. The 'Queen of the Night' comes along and puts us all in our place.
I'm not that devious. I only get the digest once a day and when I see something I might answer I click over to the forum. If someone else has answered already I say nothing, otherwise I post. Often Bernd comes in later with an even better expanded answer.
It's all in the timing.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
I wrote a new script based on delete stack. The "delete stack" command works very cleanly: the main stack and its substacks are closed, the script editor is updated but, in some cases, I get the following error:
execution error at line n/a (Object: stack locked, or object's script is executing) near "stack "/... myStackPath"
I can't figure out where this error is coming from.
It seems that this happens when the main stack to be closed has placed some of its substacks in the message path (with start using, or insert). However, before executing "delete stack", I remove these substacks from the message path and they no longer appear in the stacksInuse, nor in the frontScripts, nor in the backScripts.
I don't understand what is blocking the execution of "delete stack".
Where is the handler that deletes the stack? If it's in stack you're deleting, the problem might be the handler itself, which can't delete itself while its own handler is running.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com