Force the script editor to update?

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Zax
Posts: 476
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Force the script editor to update?

Post by Zax » Tue Apr 23, 2024 12:38 pm

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

Code: Select all

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9403
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Force the script editor to update?

Post by richmond62 » Tue Apr 23, 2024 1:15 pm

Stop those messages from showing up in the Message Watcher.
Yup: that is all that suppressing message does, just tested it: what a shame.

-------

So, the next question has to be:

Is there a way to exclude certain messages from being passed?

Or, alternatively setting lockMessages in such a way that some messages are not locked?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Force the script editor to update?

Post by dunbarx » Tue Apr 23, 2024 3:38 pm

Is there a way to exclude certain messages from being passed?
You can always trap whatever messages you want in a backScript.

But is this really a problem?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7241
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Force the script editor to update?

Post by jacque » Tue Apr 23, 2024 7:21 pm

I'm not sure this is what you need, but you can close a stack and remove from memory with a single command:

Code: Select all

delete stack <stackName>
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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9403
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Force the script editor to update?

Post by richmond62 » 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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9843
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Force the script editor to update?

Post by FourthWorld » Tue Apr 23, 2024 8:06 pm

jacque wrote:
Tue Apr 23, 2024 7:21 pm
I'm not sure this is what you need, but you can close a stack and remove from memory with a single command:

Code: Select all

delete stack <stackName>
This does not delete the file, it only removes it from LC.
If memory serves, that's true only for mainstacks.

Be very careful not to use the delete command with substacks, as that command is how we delete those from the stack file.

It would be nice to have a purge command for purging from memory without deleting from storage.
https://quality.livecode.com/show_bug.cgi?id=3932
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9678
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Force the script editor to update?

Post by dunbarx » Tue Apr 23, 2024 8:50 pm

Craig or Stam bring up something slightly better...
Slightly?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7241
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Force the script editor to update?

Post by jacque » Wed Apr 24, 2024 12:55 am

FourthWorld wrote:
Tue Apr 23, 2024 8:06 pm
jacque wrote:
Tue Apr 23, 2024 7:21 pm
I'm not sure this is what you need, but you can close a stack and remove from memory with a single command:

Code: Select all

delete stack <stackName>
This does not delete the file, it only removes it from LC.
If memory serves, that's true only for mainstacks.

Be very careful not to use the delete command with substacks, as that command is how we delete those from the stack file.

It would be nice to have a purge command for purging from memory without deleting from storage.
https://quality.livecode.com/show_bug.cgi?id=3932
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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4007
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Force the script editor to update?

Post by bn » Wed Apr 24, 2024 11:34 am

Hi Zax,

here is a heavily commented script that does what I think is what you want: remove tabs from the script editor if the stack is closed.

Code: Select all

## 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.

Zax
Posts: 476
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Force the script editor to update?

Post by Zax » Wed Apr 24, 2024 2:48 pm

Thank you for all your answers :)
jacque wrote:
Wed Apr 24, 2024 12:55 am
It's unfortunate that MC chose such a confusing term for removing a stack from memory.
Right.
I guess it cames from "delete variable" that remove a variable from memory.
Anyhow, thanks, I didn't know this use of the "delete" command.

@Bernd: awesome script!
Though, don't you think this script would be better by modifying lines 39 to 44 with:

Code: Select all

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4007
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Force the script editor to update?

Post by bn » Wed Apr 24, 2024 3:14 pm

Zax wrote:
Wed Apr 24, 2024 2:48 pm
@Bernd: awesome script!
Though, don't you think this script would be better by modifying lines 39 to 44 with:

Code: Select all

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

Kind regards
Bernd

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7241
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Force the script editor to update?

Post by jacque » Wed Apr 24, 2024 8:59 pm

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

Zax
Posts: 476
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Force the script editor to update?

Post by Zax » Fri Apr 26, 2024 1:06 pm

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".

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7241
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Force the script editor to update?

Post by jacque » Fri Apr 26, 2024 6:05 pm

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

Zax
Posts: 476
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Force the script editor to update?

Post by Zax » Fri Apr 26, 2024 6:28 pm

jacque wrote:
Fri Apr 26, 2024 6:05 pm
Where is the handler that deletes the stack?
In another stack (a real other main stack).

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”