tdf#141136 NBB SetContext: try to stay on the same tab
The user was forced on the HOME page at almost any
context change.
Instead, this should only happen if:
-there is a special context tab
-there is no special tab, and some "random" tab is needed.
This helps in a lot of cases, but there are still plenty
of cases where TWO context changes are emitted for one logical event.
For example, in Calc a new comment switches to special DRAW tab,
and then immediately to DrawText which has no tab -> home tab.
So further fixes are needed to prevent machine-gun fire context events.
Change-Id: Ibaf18fa823c613b4d11d33284842e439d3689542
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153476
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx
index c384cb0..d44554b 100644
--- a/vcl/source/control/tabctrl.cxx
+++ b/vcl/source/control/tabctrl.cxx
@@ -2285,17 +2285,27 @@ void NotebookbarTabControlBase::SetContext( vcl::EnumContext::Context eContext )
bool bHandled = false;
TabPage* pPage = GetTabPage(mnCurPageId);
// Try to stay on the current tab (unless the new context has a special tab)
if (pPage && eLastContext != vcl::EnumContext::Context::Any
&& pPage->HasContext(vcl::EnumContext::Context::Any) && pPage->IsEnabled())
{
bHandled = true;
}
for (int nChild = 0; nChild < GetPageCount(); ++nChild)
{
sal_uInt16 nPageId = TabControl::GetPageId(nChild);
TabPage* pPage = GetTabPage(nPageId);
pPage = GetTabPage(nPageId);
if (!pPage)
continue;
SetPageVisible(nPageId, pPage->HasContext(eContext) || pPage->HasContext(vcl::EnumContext::Context::Any));
if (pPage->HasContext(eContext) && eContext != vcl::EnumContext::Context::Any)
if (eContext != vcl::EnumContext::Context::Any
&& (!bHandled || !pPage->HasContext(vcl::EnumContext::Context::Any))
&& pPage->HasContext(eContext))
{
SetCurPageId(nPageId);
bHandled = true;