Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » CanClose? Mechanism to prompt user to save edits
CanClose? Mechanism to prompt user to save edits [message #31938] Sun, 10 April 2011 04:57 Go to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
In windows or certain language on Win32, before a window/container is closed, it query whether the window can be closed thus give a chance for the program to determine whether there are unsaved work, and check if the end user wants to save his/her work, discard it, or even cancel the close action (might be by accident).


What's the equivalence in U++?


I did some test in U++. I open some files (some are the essential libary files), and make some changes and click the little square on the tab. It silently decides to save the possibly unintentional changes and closes the current tab. I am afraid this is too bold; the traditional Windows' way, user consent before action, is more reasonable IMHO.

Thanks,
Lance
Re: CanClose? Mechanism to prompt user to save edits [message #31939 is a reply to message #31938] Sun, 10 April 2011 05:26 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Then I find this code snippet in UWord

UWord::UWord()
{
.....
	WhenClose = THISBACK(Destroy);
.....
}
void UWord::Destroy()
{
	if(editor.IsModified()) {
		switch(PromptYesNoCancel("Do you want to save the changes to the document?")) {
		case 1:
			Save();
			break;
		case -1:
			return;
		}
	}
	delete this;
}



WhenClose is a TopWindow callback, so I know how to guard it when the main window is to be closed. Now, like TheIDE, many files(slave ctrls) are in TabCtrl pages, what events should I hook to when a tab page is to be closed?

Re: CanClose? Mechanism to prompt user to save edits [message #34761 is a reply to message #31939] Sun, 11 December 2011 18:28 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
OK. (one of?) The right way is to override the Accept virtual method of Ctrl-derivated class.

In my case, I use TabCtrl to host different pages that are derivated from ParentCtrl, in the overrided Accept, do something like:

bool MyPage::Accept()
{
    bool ok=true;

    if( DataIsChanged() )
    {
        switch(PromptYesNoCancel("Data Changed, do you want to save?"))
        {
        case -1: // Cancel;
            ok=false;
            break;
        case 1: // Yes
            if(!SuccessfullySaveD())
                ok=false;
        }
    }
    return ok;
}

[Updated on: Sun, 11 December 2011 18:30]

Report message to a moderator

Re: CanClose? Mechanism to prompt user to save edits [message #34762 is a reply to message #34761] Sun, 11 December 2011 18:37 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Sad

Sorry, misinformation. Above only works when the application is closed. It failed to detect when the hosting tab page is closed.

Re: CanClose? Mechanism to prompt user to save edits [message #34763 is a reply to message #34762] Sun, 11 December 2011 18:48 Go to previous messageGo to next message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
Do you want to let your app ask if he want to save his changes then your tab changes?
Re: CanClose? Mechanism to prompt user to save edits [message #34768 is a reply to message #34763] Sun, 11 December 2011 23:57 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Thank you, Wolfgang!

If that's the only way. I would prefer not though. For example, I may be editing something in one tab page and occasionally switch to another tab page to consult some other information. Say I am doing an order, in the process I may become interested in a particular inventory item, e.g. its flow and current count, etc, I will double click the item to bring out a new tab page displaying the inventory activities information. It may not hurt that much to save partial edits but it's preferable not to commit until I (the end user) ask to, e.g. I may subsequently decide to cancel changes made in this session, it will be necessary to remember the edit/undo history if partial changes and saved in the editing process.

[Updated on: Sun, 11 December 2011 23:57]

Report message to a moderator

Re: CanClose? Mechanism to prompt user to save edits [message #34769 is a reply to message #31938] Mon, 12 December 2011 00:14 Go to previous messageGo to next message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
I dont see your problem... if you change the active tab, you don't have to destroy the old one. This way you just have to show / hide the tab with the user changed information. And if you want to save them, you can use the destroy event of the mainwindows to check if something have changed - if yes, ask the user if you should save the changes.
Re: CanClose? Mechanism to prompt user to save edits [message #34770 is a reply to message #31938] Mon, 12 December 2011 09:38 Go to previous messageGo to next message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
I dont know if I understand you the right way but I uploaded an example for you how I would handle the "saving" problematic..

A simple example project with 3 tabs, one for settings which is monitored for changes!
Hope it helps!
  • Attachment: lance.zip
    (Size: 2.24KB, Downloaded 192 times)

[Updated on: Mon, 12 December 2011 09:38]

Report message to a moderator

Re: CanClose? Mechanism to prompt user to save edits [message #34784 is a reply to message #34768] Mon, 12 December 2011 13:14 Go to previous messageGo to next message
Sender Ghost is currently online  Sender Ghost
Messages: 299
Registered: November 2008
Experienced Member
Hello, Lance.

Lance wrote on Sun, 10 April 2011 04:57


I did some test in U++. I open some files (some are the essential libary files), and make some changes and click the little square on the tab. It silently decides to save the possibly unintentional changes and closes the current tab. I am afraid this is too bold; the traditional Windows' way, user consent before action, is more reasonable IMHO..


Lance wrote on Sun, 10 April 2011 05:26


WhenClose is a TopWindow callback, so I know how to guard it when the main window is to be closed. Now, like TheIDE, many files(slave ctrls) are in TabCtrl pages, what events should I hook to when a tab page is to be closed?


In my opinion, TheIDE behaviour with TabBar is normal if you use some kind of source code management system (svn, git, etc.) to be able revert changes when needed.

Lance wrote on Sun, 11 December 2011 18:28


In my case, I use TabCtrl to host different pages that are derivated from ParentCtrl


Lance wrote on Sun, 11 December 2011 23:57


For example, I may be editing something in one tab page and occasionally switch to another tab page to consult some other information. Say I am doing an order, in the process I may become interested in a particular inventory item, e.g. its flow and current count, etc, I will double click the item to bring out a new tab page displaying the inventory activities information. It may not hurt that much to save partial edits but it's preferable not to commit until I (the end user) ask to, e.g. I may subsequently decide to cancel changes made in this session, it will be necessary to remember the edit/undo history if partial changes and saved in the editing process.



In the attachment you could find another example how to save/cancel, revert to default changes of TabCtrl, while using Serialize and storage data structure(s).

Also, take a look for CtrlRetriever example.
Re: CanClose? Mechanism to prompt user to save edits [message #34793 is a reply to message #34784] Mon, 12 December 2011 16:52 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Hi Wolfgang & Sender Ghost:

Thanks for the help! I will try your codes in a while.
Re: CanClose? Mechanism to prompt user to save edits [message #34801 is a reply to message #34793] Tue, 13 December 2011 01:15 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member

I am sorry. The post was from long ago, I actually changed TabCtrl to TabBarCtrl to allow closing individual TabPages. Your samples are very interesting; the serialization part in particular is something I knew was useful but never have a chance to study.

Anyways, I figured out the thing I was looking for should be CancelClose gate of TabBar (parent of TabBarCtrl), hook up the following code fixed my problem, quite decently IMHO Smile


bool MyMain::TabCancelClose(Value key)
{
     return !myTabBarCtrlInstance.FindCtrl(key)->Accept();
} 




Each Complex Ctrl that's to be hosted in a Tab page can individually decide its Accept() logic. For example, my example code above will query user to see if he/she wants to save/discard/cancel when there are modifications, and takes action accordingly.


My only remaining question was, for the TabBar libary developers, should the above logic be built in, as it should the very purpose of Accept() in Ctrl's designers intention? Sorry I don't know enough to judge, just raising a question.


TabBar has CancelCloseSome and similar gates, I am not sure if they are of any interests. For my purpose, the above is exactly what I wanted.

Thanks again to Wolfgang and Sender Ghost.
Re: CanClose? Mechanism to prompt user to save edits [message #34804 is a reply to message #34801] Tue, 13 December 2011 04:29 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Above solution still has a flaw.


If the Ctrl (the outmost container) in a page is modified and the containing page is crossed(to initiate a close request), the user will be prompted whether he/she wants to save, discard edit or cancel the close action when overrided Accept() is called from within CancelClose gate. If user selects "no" to discard change (close without saving) and no action was taken to unset the modified flag, the Accept() gets called again before the Ctrl is destructed. A simple fix would be to always reset modified flag when the user chooses to discard edit. This way when Accept() is called at the moment of destruction, it always returns true so that it is silently disposed of as wished.

[Updated on: Tue, 13 December 2011 04:33]

Report message to a moderator

Re: CanClose? Mechanism to prompt user to save edits [message #34910 is a reply to message #34804] Fri, 16 December 2011 21:09 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1264
Registered: September 2007
Senior Contributor
If I have did understand your problem, there's TabBarCtrl in Bazaar to which I added some time ago a couple of callbacks
named CancelCloseSome and WhenCloseSome just for that purpose.

First is called BEFORE a tab or also many tabs are being closed, giving the ability to prompt for a file/list of files to be saved; the latter happens AFTER the tabs are closed and allows the application to finish closing / do some cleanup.

It was refactored by original maintainer, but those callbacks are still there, IIRC.
I'm using a modified version of this control in my app and works quite good.

Max

Edit : I've read now one of your posts about CancelCloseSome and WhenCloseSome.... the purpose is the one I've explained above; you can close multiple tabs at once and those allows you to group the closing prompts.

[Updated on: Fri, 16 December 2011 21:11]

Report message to a moderator

Re: CanClose? Mechanism to prompt user to save edits [message #34920 is a reply to message #34910] Sat, 17 December 2011 04:31 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Hi Max:

Thanks for the reply!


Are you the current maintainer of TabBarCtrl? If yes, I would like to request a feature. Basically, let's say EditInt1 on Tab Page 1 is currently focused, then I switch to Tab Page2, I would expect some control in Tab Page2 to receive the key board focus. But EditInt1 will continue hold the key board focus until I, say, click EditString2 on Tab Page2. Then I switch back to Tab Page1, and of course, EditString2 will not release key board focus to EditInt1 as would be desirable in most cases.

The current implementation requires library users to write callbacks to remember and restore keyboard focus upon Tab changes. Not that it's hard to do, but it should not be necessary.

It's not only a problem with TabBarCtrl. In general, a container Ctrl should remember its focused child and restore focus to it when it receives focus. In the current implementation, if a window receives focus because of another window who had the focus was closed, its first focusable child will receive the focus instead of the previously focused child in that window. Having container Ctrl to remember and restore its focused child is too often requested by library users to leave it out.
Re: CanClose? Mechanism to prompt user to save edits [message #34923 is a reply to message #34920] Sat, 17 December 2011 10:54 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1264
Registered: September 2007
Senior Contributor
No, sorry... I'm not the maintainer of TabBarCtrl.
I'm using a custom version since long.

Max
Re: CanClose? Mechanism to prompt user to save edits [message #34934 is a reply to message #34923] Sun, 18 December 2011 16:28 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 351
Registered: March 2007
Senior Member
Interesting. To maintain a customized version, what do you need to do when there are updates for upp? Simply overwrite with your own version or do you need to check line by line every time? Or is there a tool for that purpose?
Re: CanClose? Mechanism to prompt user to save edits [message #34935 is a reply to message #34934] Sun, 18 December 2011 16:35 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1264
Registered: September 2007
Senior Contributor
I do nothing because my customized version is all what I need Smile
Normally I avoid this, but the original maintainer made some changes that were incompatible with my app so, having no time to modify my code, I had to gather my previous mods and stay with it.

If you have to start from scratch, I suggest you to use bazaar code. Mine is not polished and has no great advantages.

About keeping in sync with upp.... there are no special tools, we're using svn. Usually each piece of bazaar has its own maintainer (not everywhere, but usually....) so when we need some mods we ask him if it's ok to add OR we do ourselves, but taking care that they'll not break anything.

The case with TabBarCtrl was peculiar because I needed it, it was not there, so I added to original code, but the "owner" took it in charge later on and rewrote it to its taste. The only things that were kept are the CanCloseSome() and WhenCloseSome() callbacks I added.

BTW, the mod you're requesting for makes sense and should be almost trivial.... I don't know if original maintainer is still working on it, but you can ask here.

Max

[Updated on: Sun, 18 December 2011 16:36]

Report message to a moderator

Previous Topic: TheIDE refactoring and multiple packages build support?
Next Topic: mySql - how to use - what is needed?
Goto Forum:
  


Current Time: Wed May 27 22:58:40 CEST 2020

Total time taken to generate the page: 0.02068 seconds