Page 2 of 3
Re: Close the stack and don't ask me to save changes...
Posted: Wed Feb 07, 2024 11:13 am
by Zax
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
Re: Close the stack and don't ask me to save changes...
Posted: Wed Feb 07, 2024 11:11 pm
by stam
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
Re: Close the stack and don't ask me to save changes...
Posted: Thu Feb 08, 2024 9:14 am
by Zax
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.
Re: Close the stack and don't ask me to save changes...
Posted: Thu Feb 08, 2024 11:36 am
by stam
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...
Re: Close the stack and don't ask me to save changes...
Posted: Fri Feb 09, 2024 3:26 pm
by Zax
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.
Re: Close the stack and don't ask me to save changes...
Posted: Sun Feb 11, 2024 10:48 am
by stam
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?
Re: Close the stack and don't ask me to save changes...
Posted: Sun Feb 11, 2024 11:31 am
by Zax
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
Re: Close the stack and don't ask me to save changes...
Posted: Sun Feb 11, 2024 5:17 pm
by stam
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
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 9:47 am
by Zax
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
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 1:17 pm
by stam
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.
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 2:35 pm
by Zax
stam wrote: Mon Feb 12, 2024 1:17 pmYour 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
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 3:03 pm
by stam
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
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 3:22 pm
by Zax
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.
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 7:11 pm
by FourthWorld
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.
Re: Close the stack and don't ask me to save changes...
Posted: Mon Feb 12, 2024 8:06 pm
by stam
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...