Close the stack and don't ask me to save changes...

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: 402
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Close the stack and don't ask me to save changes...

Post by Zax » Wed Feb 07, 2024 11:13 am

Zax wrote:
Tue Feb 06, 2024 9:36 am
And thank you Stam: a modeless stack seems to be a good solution. :)
In fact this solution presents another problem: if a stack is modeless, the shutdownRequest message is received by the stack but I cannot block the process.

What I would like:
  • a stack that will only work with the LC 9.6.x IDE (not standalone)
  • NO automatic dialog "would you like to save..."
  • the ability to manually enter, or to paste, some text in a field
  • the possibility of asking the user if he wants to save this stack (or if he really wants to close/exit) when:
    • the user clicks on a "Close" button - "close this stack" by script
    • the user clicks on the standard closing box (the red MacOS circle)
    • the user quits LC - "Quit" article menu
CloseTest.livecode.zip
(1.13 KiB) Downloaded 14 times

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Wed Feb 07, 2024 11:11 pm

Zax wrote:
Wed Feb 07, 2024 11:13 am
What I would like:
  • a stack that will only work with the LC 9.6.x IDE (not standalone)
  • NO automatic dialog "would you like to save..."
  • the ability to manually enter, or to paste, some text in a field
These should be fine with modeless stack, either in IDE or standalone.

Zax wrote:
Wed Feb 07, 2024 11:13 am
[*]the possibility of asking the user if he wants to save this stack (or if he really wants to close/exit) when:
  • the user clicks on a "Close" button - "close this stack" by script
  • the user clicks on the standard closing box (the red MacOS circle)
  • the user quits LC - "Quit" article menu
[/list]
I'm pretty sure you can do this with closeStackReqeust, for example:

Code: Select all

on closeStackRequest
    answer "Close or Quit?" with "Quit" and "Close" and "Cancel"
    if it is "cancel" then
        // do nothing
    else if it is "Close" then
        pass closeStackRequest
    else
        quit
    end if
end closeStackRequest
seems to work fine on my end...

Stam

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Thu Feb 08, 2024 9:14 am

stam wrote:
Wed Feb 07, 2024 11:11 pm
I'm pretty sure you can do this with closeStackReqeust, for example:

Code: Select all

on closeStackRequest
    answer "Close or Quit?" with "Quit" and "Close" and "Cancel"
    if it is "cancel" then
        // do nothing
    else if it is "Close" then
        pass closeStackRequest
    else
        quit
    end if
end closeStackRequest
seems to work fine on my end...

Stam
Well, according to the Dictionnary, "The closeStackRequest message is only sent if the request to close a stack is initiated by the user (eg by clicking file -> close in the LiveCode menu [...]".
According to my tests, when a stack (with IDE) is modeless, closeStackRequest is only sent when the user clicks on the standard close icon.
Anyway, closeStackRequest is not sent on Quit.

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Thu Feb 08, 2024 11:36 am

Zax wrote:
Wed Feb 07, 2024 11:13 am
In fact this solution presents another problem: if a stack is modeless, the shutdownRequest message is received by the stack but I cannot block the process.
erm... you can't handle shutdownRequest in the IDE.

From dictionary on shutdownRequest:
Note: Applications will not receive this message when running in the IDE.
Nothing to do with modeless or topLevel style of a stack.
I think I saw somewhere that the IDE hijacks this message to check if stacks need saving, but don't quote me on that...

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Fri Feb 09, 2024 3:26 pm

Finally, I set my stack to cantModify (and toplevel style) and wrote a workaround script to allow paste text in fields, but it only works when using the keyboard shortcut (command-V).
At this time, it's the best solution I have found to solve my problem.

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Sun Feb 11, 2024 10:48 am

Just for my own curiosity:

Did you manage to work around the issue with quoting the IDE? (ie shutDownRequest)?
If not, in what way was this better than using a modeless stack?

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Sun Feb 11, 2024 11:31 am

stam wrote:
Sun Feb 11, 2024 10:48 am
Just for my own curiosity:

Did you manage to work around the issue with quoting the IDE? (ie shutDownRequest)?
If not, in what way was this better than using a modeless stack?
As I have done numerous tests, I am unable to post an accurate comparison of the different solutions.
The following solution (stack's script) seems to best meet my needs.

Code: Select all

on preOpenStack
   choose browse tool
   set the cantModify of me to true
   // do preferences stuff here
end preOpenStack

on closeStackRequest // built-in close box
   closeProcess true
end closeStackRequest

on closeProcess askSaveBoolean // things to do before closing
   // save preferences here
   closeCleaningProcess askSaveBoolean
   close me
end closeProcess

on closeCleaningProcess askSaveBoolean
   if (askSaveBoolean) then
      answer "Save data?" with "No" or "Save"
   else get "No"
   if (it = "No") then ... do cleaning
   save me
end closeCleaningProcess

================================ PASTE IN LOCKED STACK =================================
on commandKeyDown tKey
   if (tKey = "V") then
      pasteTextInField the selectedChunk, the id of this card
   else pass commandKeyDown
end commandKeyDown

on pasteTextInField tSelChunk, tCardId
   if (tSelChunk <> "") then
      if (the clipboardData["text"] <> "") then
         put last word of tSelChunk into fldNumber
         if (not the lockText of fld fldNumber of card id tCardId) then
            put word 2 of tSelChunk into charStart
            put word 4 of tSelChunk into charEnd
            put the clipboardData["text"] into char charStart to charEnd of fld fldNumber of card id tCardId
            select after char (charStart + the length of the clipboardData["text"] - 1) of fld fldNumber of card id tCardId
         end if
      end if
   end if
end pasteTextInField

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Sun Feb 11, 2024 5:17 pm

As far as I can see reading your code, it does the following:
- Set the cantModify of the stack to true
- On close stack: ask user to save or not
- if save then you just save the stack
- If it is not save then reset the stack to it's default
- And finally: implement a complicated method for pasting into a stack with cantModify = true.

If it works for you it works for you, and no question.
But I have to ask, what added benefit there is to all of this instead of just:

Code: Select all

on preOpenStack
   set the style of this stack to "modeless"
   // do preferences stuff here
end preOpenStack

on closeStackRequest // built-in close box
   answer "Save data?" with "No" and "Save"
   if it is "Save" then 
     save me
     // maybe do some preferences stuff here, no cleanup needed
   end if
   pass closeStackRequest
end closeStackRequest
Yes, the code above doesn't cater for quitting the IDE, but neither does yours as far as I can see?

With modeless you can close without the save stack dialog and you can both type and paste in any way (not just command/ctrl-V), and no need to introduce an extra 20 lines of code?

I'll admit I don't see the point in complicating things more than needed.

For an excellent example in how a modeless stack works, checkout the LiveCode Error Lookup stack jointly created by Richard and Jaqueline (it's available in Sample Stacks, or it's web-facing site liveCodeShare (terribly, painfully sloooowwww..., but then so is Sample Stacks) at https://livecodeshare.runrev.com/stack/ ... ror-Lookup

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Mon Feb 12, 2024 9:47 am

OK Stam, you convinced me :)
If we add the management of a closing a stack by script, it could look like this:

Code: Select all

on preOpenStack
   set the style of me to "modeless"
   // do preferences stuff here
end preOpenStack

on closeStackRequest // built-in close box
   askTosave
end closeStackRequest

on closeStack // close by script
   askTosave
end closeStack

on askToSave
   answer "Save data?" with "No" and "Save"
   if it is "Save" then 
      save me
      // maybe do some preferences stuff here, no cleanup needed
   end if
   lock messages
   close me
end askToSave

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Mon Feb 12, 2024 1:17 pm

heh - I hadn't realised closing the stack via code would not trigger closeStackReqeust...
Although like most things 'I hadn't realised', it's a 1-liner in the Dictionary that I hadn't noticed. Live and learn...

But with code above the closeStackReqeust is superfluous as closeStack automatically follows closeStackRequest.
closeStackRequest is only really helpful in this context if you want to give the user an opportunity to abort closing the stack or perhaps quit the app/IDE after clicking the window's close box.

Your code above works identically if the closeStackRequest is removed.

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Mon Feb 12, 2024 2:35 pm

stam wrote:
Mon Feb 12, 2024 1:17 pm
Your code above works identically if the closeStackRequest is removed.
Oh yes, indeed :)
Furthermore "lock messages" is an error on my part because it prevents other stacks in the IDE from possibly reacting.
New version :

Code: Select all

on preOpenStack
   set the style of this stack to "modeless"
   // read preferences here
end preOpenStack

on closeStack // closed by script or with built-in close box
   askTosave
   pass closeStack
end closeStack

on askToSave
   answer "Save data?" with "No" and "Save"
   if it is "Save" then 
      save me
      // update and save preferences here, no cleanup needed
   end if
end askToSave

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Mon Feb 12, 2024 3:03 pm

Looks good :)

PS: In the interest of minimising code, there is no point in passing closeStack, since you can't abort closing the stack at that stage (that's why we have closeStackRequest ;) ).

so really the askToSave handler can be removed and the closeStack handler could be:

Code: Select all

on closeStack
   answer "Save data?" with "No" and "Save"
   if it is "Save" then save me
   // update and save preferences here, no cleanup needed
end closeStack

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

Re: Close the stack and don't ask me to save changes...

Post by Zax » Mon Feb 12, 2024 3:22 pm

Something is happening that I don't understand: if you quit, the stack is automatically saved (which doesn't suit me) whereas in the LiveCode-Error-Lookup.rev stack, the modifications are not saved.

I tried looking at the scripts for LiveCode-Error-Lookup.rev but couldn't find anything conclusive.

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

Re: Close the stack and don't ask me to save changes...

Post by FourthWorld » Mon Feb 12, 2024 7:11 pm

Zax wrote:
Mon Feb 12, 2024 3:22 pm
Something is happening that I don't understand: if you quit, the stack is automatically saved (which doesn't suit me) whereas in the LiveCode-Error-Lookup.rev stack, the modifications are not saved.

I tried looking at the scripts for LiveCode-Error-Lookup.rev but couldn't find anything conclusive.
What would one want to save in that static reference tool?

It may be helpful to think about windows as falling into two categories: documents, and tooling that works on documents. In broad terms, documents are usually where the user does their work, be it data entry, diagramming, etc. Tooling can be anything else, from object creation tools to property inspectors to reference guides.

Document data of course need to be saved, and tooling (once implemented) would generally not (with the exception of Prefs or other things that save state).

Of course LC lets us make all standard window types, so the key to making tooling windows (eg modeless, palette) is to build them in toplevel mode, then when you're testing set their style back to whatever is needed for use (modeless or palette).

It's also worth keeping in mind the difference between why and how we save changes during development, and what gets saved for our users at runtime. That seems to be separate from this thread, but worth keeping in mind early on since windows physically attached to the standalone cannot be saved at all (OSes generally prevent app modification at runtime). User data is often best handled as a separate file and often in a format other than a stackfile. We can cover those options as the question raises; for now just keep in mind that these questions of saving are specific to developing in the IDE, and you have total control over how all of this is done in the user experience you deliver in your app.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2550
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Close the stack and don't ask me to save changes...

Post by stam » Mon Feb 12, 2024 8:06 pm

Zax wrote:
Mon Feb 12, 2024 3:22 pm
Something is happening that I don't understand: if you quit, the stack is automatically saved (which doesn't suit me) whereas in the LiveCode-Error-Lookup.rev stack, the modifications are not saved.

I tried looking at the scripts for LiveCode-Error-Lookup.rev but couldn't find anything conclusive.
Must be something in your code that is saving this.
I tested on a modeless stack with

Code: Select all

on closeStack
    answer "Save?" with "Save" and "No"
    if it is "No" then
        // do nothing
    else if it is "Save" then
        save this stack
    end if
end closeStack
no changes to text fields were saved on Quit. If I close the stack I am shown the save dialog and only clicking 'save' saves the changed data.
FourthWorld wrote:
Mon Feb 12, 2024 7:11 pm
It's also worth keeping in mind the difference between why and how we save changes during development, and what gets saved for our users at runtime. That seems to be separate from this thread, but worth keeping in mind early on since windows physically attached to the standalone cannot be saved at all (OSes generally prevent app modification at runtime). User data is often best handled as a separate file and often in a format other than a stackfile. We can cover those options as the question raises; for now just keep in mind that these questions of saving are specific to developing in the IDE, and you have total control over how all of this is done in the user experience you deliver in your app.
@Richard - Zax is designing a stack for the IDE as I understand it...

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”