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 » U++ Library support » TabCtrl » How to use TabBar CancelClose/WhenClose?
How to use TabBar CancelClose/WhenClose? [message #46501] Tue, 17 May 2016 10:46 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
I have a TabBar and when you close a tab it unceremoniously closes the tab. I would like to prompt the user to save if needed with a Yes/No/Cancel dialog like in the rest of the application and the handle the saving and cleanup.

Looking over the source code I think that I need to handle the prompt and the actual saving in CancelClose and the cleanup in WhenClose? How do you CancelClose? I have never used a gate before. I can't even get it to compile with callbacks.

And what is up with CancelCloseSome/WhenCloseSome? What is the difference between the Some variants and the normal ones and which one should I handle?

Thank you!
Re: How to use TabBar CancelClose/WhenClose? [message #46503 is a reply to message #46501] Tue, 17 May 2016 17:21 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 536
Registered: March 2007
Contributor
I manage to extract this minimal example to get my idea across.

You will need to rewrite many parts to suit your needs.


HTH,

Lance
--------------------
[edit] removed incorrect/misleading info

[Updated on: Tue, 17 May 2016 19:35]

Report message to a moderator

Re: How to use TabBar CancelClose/WhenClose? [message #46504 is a reply to message #46503] Tue, 17 May 2016 17:24 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 536
Registered: March 2007
Contributor
Sorry, forget to attach the test package.

If you are still using non-C++11 compiler, add a
#define nullptr NULL


somewhere. Hopefully there is no other non-compliance.
  • Attachment: MultiTab.zip
    (Size: 2.91KB, Downloaded 257 times)
Re: How to use TabBar CancelClose/WhenClose? [message #46506 is a reply to message #46504] Wed, 18 May 2016 10:29 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
Hi Lance,

Thank you for the help. Unfortunately, I can't get your sample to link.

But it did help me to find out why my gates wouldn't compile: I had it take a const Value& parameter instead of a Value.

So now it works.

But I found a bug on TabBar. The closing mechanism is based on the current highlighted tab under mouse. Which is fine, until you Prompt in CancelClose, like I do:

bool EditorManager::OnCancelClose(Value val) {
	int i = tabFiles.GetCursor();
	if (i == -1)
		return true;
	
	if (IsChanged(i)) {
		BeepQuestion();
		String fn = DeQtf(tabFiles[i].key.ToString());
		DUMP(tabFiles.GetHighlight());
		int save = PromptSaveDontSaveCancel("[ph The following file was changed since last save:&-|[* " + fn + "]&Would you like to save it?]");
		DUMP(tabFiles.GetHighlight());
		if (save == 1)
			Save(i);
		else if (save == -1)
			return true;
	}
		
	return false;
}


Between the two DUMPs, the highlight changes to -1. I tried this simple fix in TabBar.cpp:

void TabBar::MiddleDown(Point p, dword keyflags)
{
	if (highlight >= 0)
	{
		Value v = tabs[highlight].key;
		ValueArray vv;
		vv.Add(v);
		int highlightBack = highlight;
		if (!CancelClose(v) && ! CancelCloseSome(vv)) {
			Value v = tabs[highlightBack].key;
			// 2014/03/06 - FIRST the callbacks, THEN remove the tab
			// otherwise keys in WhenCloseSome() are invalid
			WhenClose(v);
			WhenCloseSome(vv);
			TabClosed(v);
			Close(highlightBack);
		}
	}
}
Re: How to use TabBar CancelClose/WhenClose? [message #46508 is a reply to message #46506] Wed, 18 May 2016 14:25 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 536
Registered: March 2007
Contributor
Glad you fixed it.

Why did you use get GetHighlight() instead of GetCurrentCtrl()? I didn't use GetHighlight() so I don't really know its intention. Could it be the opening of your prompt dialog shift the highlight such that no tab is thought as highlighted (hench change to -1), ie., it's intended behaviour instead of a bug? Just my thought.

It's a pity you cannot link my package, btw, what's the failure message?
Re: How to use TabBar CancelClose/WhenClose? [message #46510 is a reply to message #46508] Wed, 18 May 2016 15:15 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
It is not me using the highlight. TabBar is the one using it, when it handles the middle mouse click for tab closing. Which reminded me about the close box, so I tested using the box and it did not work for me because I had an index based API and TabBar is key based. I fixed it now...

You method with GetCurrentCtrl, pointers and memory management is a bit not U++ enough for me.

Which reminds me, I need to replace the box icon with a close icon that has an "x" inside. Closing a tab with a box is not intuitive. I learned from you how you can easily change the boxes. Thank you!

I solved the linking errors. Your package does not use the TabBar package. You need to add it and it works!

Thanks!
Re: How to use TabBar CancelClose/WhenClose? [message #46512 is a reply to message #46510] Wed, 18 May 2016 15:51 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 536
Registered: March 2007
Contributor
You method with GetCurrentCtrl, pointers and memory management is a bit not U++ enough for me.


Sad

A few years ago, I proposed to add a bit in Ctrl to allow a child Ctrl to be owned, which was rejected by Mirek. Then I found he used PtrBit or something like that (pointer as int, add 1 to signal an owned ctrl) in his ArrayCtrl to allow a child to be owned. If a Ctrl can be owned, we can rely on TabCtrl to delete it when needed, which will save some code and some 'ugly' delete. Otherwise it's an inevitable choice, unless you want to put up with the extra cost of an redundant Array just to hold the new'd Ctrls.

Anyway, it's a matter of taste/faith. Good thing is you make things work as you wish and the way you wish.
Re: How to use TabBar CancelClose/WhenClose? [message #46800 is a reply to message #46512] Thu, 11 August 2016 15:38 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
BUMP BUMP!

The bug I spoke about is actually a bug and not yet fixed in the latest version.

I was just about to report not a new bug, but a proposed functionality improvement for TabBar and I remembered to check the status of this one.

Should I start using Redmine?
Re: How to use TabBar CancelClose/WhenClose? [message #47349 is a reply to message #46800] Fri, 06 January 2017 12:59 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1406
Registered: September 2007
Ultimate Contributor
Redmine issue for the BUG: http://ultimatepp.org/redmine/issues/1598
Previous Topic: Coloring tab
Next Topic: How to plot image in one tab based on TabCtrl
Goto Forum:
  


Current Time: Thu Jun 20 02:31:24 CEST 2024

Total time taken to generate the page: 0.02065 seconds