Commit 8c252cac authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Fix tabbar auto hide

Restores the behaviour that tabbar is visible for all viewspaces if
only one has enough tabs.

Also fix the tests
parent 1d0f576f
Pipeline #261429 failed with stage
in 11 minutes and 43 seconds
......@@ -189,7 +189,7 @@ void KateViewManagementTests::testTwoMainWindowsCloseInitialDocument1()
QVERIFY(first);
// create a second one
KateMainWindow *second = app->newMainWindow();
std::unique_ptr<KateMainWindow> second(app->newMainWindow());
QVERIFY(second);
// close the initial document
......@@ -209,7 +209,7 @@ void KateViewManagementTests::testTwoMainWindowsCloseInitialDocument2()
QVERIFY(first);
// create a second one
KateMainWindow *second = app->newMainWindow();
std::unique_ptr<KateMainWindow> second(app->newMainWindow());
QVERIFY(second);
// close the initial document tab in second window
......@@ -229,7 +229,7 @@ void KateViewManagementTests::testTwoMainWindowsCloseInitialDocument3()
QVERIFY(first);
// create a second one
KateMainWindow *second = app->newMainWindow();
std::unique_ptr<KateMainWindow> second(app->newMainWindow());
QVERIFY(second);
// close the initial document tab in second window
......@@ -402,33 +402,55 @@ void KateViewManagementTests::testTabBarHidesShows()
app->sessionManager()->sessionNew();
KateMainWindow *mw = app->activeKateMainWindow();
auto vm = mw->viewManager();
vm->slotCloseOtherViews();
auto vs = vm->activeViewSpace();
// close everything
for (int i = 0; i < vs->numberOfRegisteredDocuments(); ++i) {
vm->slotDocumentClose();
}
QTabBar *tabs = vs->m_tabBar;
vs->m_autoHideTabBar = true;
vs->tabBarToggled();
QVERIFY(!vs->m_tabBar->isVisible());
vm->slotDocumentClose();
app->activeKateMainWindow()->viewManager()->slotDocumentNew();
QCOMPARE(vm->views().size(), 1);
QVERIFY(vs->m_tabBar->isHidden());
QCOMPARE(tabs->count(), 1);
QVERIFY(tabs->isHidden()); // only 1 => hide
app->activeKateMainWindow()->viewManager()->slotDocumentNew();
QCOMPARE(vm->views().size(), 2);
qApp->processEvents();
QVERIFY(vs->m_tabBar->isVisible());
QCOMPARE(tabs->count(), 2);
QVERIFY(!tabs->isHidden()); // 2 => show
vm->slotDocumentClose();
QCOMPARE(vm->views().size(), 1);
qApp->processEvents();
QVERIFY(!vs->m_tabBar->isVisible());
QCOMPARE(tabs->count(), 1);
QVERIFY(!vs->m_tabBar->isVisible()); // 1 -> hide
Utils::addWidget(new QWidget, app->activeMainWindow());
qApp->processEvents();
QVERIFY(vs->m_tabBar->isVisible());
QVERIFY(vs->m_tabBar->isVisible()); // 1 + widget => show
vm->slotDocumentClose();
qApp->processEvents();
QVERIFY(!vs->m_tabBar->isVisible());
// m_autoHideTabBar
QVERIFY(!vs->m_tabBar->isVisible()); // 1 -> hide
vm->splitViewSpace();
auto *secondVS = vm->activeViewSpace();
QVERIFY(secondVS != vs);
// if one viewspace has more than 1 tab and its
// tabbar is visible, all other viewspaces shall
// also have visible tabbars
// make first vs active and create a doc in it
// Expect: both viewspaces have tabbar visible
vm->setActiveSpace(vs);
vm->slotDocumentNew();
QCOMPARE(vs->m_tabBar->count(), 2);
QVERIFY(!vs->m_tabBar->isHidden());
QCOMPARE(secondVS->m_tabBar->count(), 1);
QVERIFY(!secondVS->m_tabBar->isHidden());
// Expect both have tabbar hidden
vm->slotDocumentClose();
QVERIFY(vs->m_tabBar->isHidden());
QVERIFY(secondVS->m_tabBar->isHidden());
}
......@@ -1171,6 +1171,13 @@ int KateViewManager::viewspaceCountForDoc(KTextEditor::Document *doc) const
});
}
bool KateViewManager::tabsVisible() const
{
return std::count_if(m_viewSpaceList.begin(), m_viewSpaceList.end(), [](KateViewSpace *vs) {
return vs->tabCount() > 1;
});
}
bool KateViewManager::docOnlyInOneViewspace(KTextEditor::Document *doc) const
{
return (viewspaceCountForDoc(doc) == 1) && !KateApp::self()->documentVisibleInOtherWindows(doc, m_mainWindow);
......
......@@ -317,6 +317,8 @@ public Q_SLOTS:
int viewspaceCountForDoc(KTextEditor::Document *doc) const;
// returns true if @p doc exists only in one viewspace
bool docOnlyInOneViewspace(KTextEditor::Document *doc) const;
// returns true if any viewspace in this viewmanager has its tabbar visible
bool tabsVisible() const;
void setShowUrlNavBar(bool show);
bool showUrlNavBar() const;
......
......@@ -171,9 +171,10 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
connect(KateApp::self(), &KateApp::configurationChanged, this, &KateViewSpace::readConfig);
// ensure we show/hide tabbar if needed
// Queued so tabbar etc handle it first
connect(KateApp::self()->documentManager(), &KateDocManager::documentCreated, this, &KateViewSpace::documentCreatedOrDeleted, Qt::QueuedConnection);
connect(KateApp::self()->documentManager(), &KateDocManager::documentDeleted, this, &KateViewSpace::documentCreatedOrDeleted, Qt::QueuedConnection);
connect(m_viewManager, &KateViewManager::viewCreated, this, &KateViewSpace::updateTabBar);
connect(KateApp::self()->documentManager(), &KateDocManager::documentsDeleted, this, &KateViewSpace::updateTabBar);
connect(m_viewManager->mainWindow(), &KateMainWindow::widgetAdded, this, &KateViewSpace::updateTabBar);
connect(m_viewManager->mainWindow(), &KateMainWindow::widgetRemoved, this, &KateViewSpace::updateTabBar);
}
KateViewSpace::~KateViewSpace() = default;
......@@ -225,14 +226,14 @@ bool KateViewSpace::eventFilter(QObject *obj, QEvent *event)
return false;
}
void KateViewSpace::documentCreatedOrDeleted(KTextEditor::Document *)
void KateViewSpace::updateTabBar()
{
if (!m_autoHideTabBar || !m_viewManager->mainWindow()->showTabBar()) {
return;
}
// toggle hide/show if state changed
if ((documentList().size() > 1) != m_tabBar->isVisible()) {
if (m_viewManager->tabsVisible() != m_tabBar->isVisible()) {
tabBarToggled();
}
}
......@@ -245,7 +246,7 @@ void KateViewSpace::tabBarToggled()
// we might want to auto hide if just one document is open
if (show && m_autoHideTabBar) {
show = documentList().size() > 1;
show = tabCount() > 1 || m_viewManager->tabsVisible();
}
const bool urlBarVisible = m_viewManager->showUrlNavBar();
......@@ -663,8 +664,6 @@ QWidget *KateViewSpace::takeView(DocOrWidget docOrWidget)
Qt::QueuedConnection);
}
documentCreatedOrDeleted(nullptr);
return ret;
}
......@@ -768,8 +767,6 @@ void KateViewSpace::closeTabRequest(int idx)
// if this was the last doc, let viewManager know we are empty
if (m_registeredDocuments.isEmpty() && m_tabBar->count() == 0) {
Q_EMIT viewSpaceEmptied(this);
} else {
documentCreatedOrDeleted(nullptr);
}
}
return;
......@@ -818,7 +815,7 @@ void KateViewSpace::addWidgetAsTab(QWidget *widget)
connect(m_tabBar, &KateTabBar::currentChanged, this, &KateViewSpace::changeView);
stack->setCurrentWidget(widget);
m_registeredDocuments.append(widget);
documentCreatedOrDeleted(nullptr);
updateTabBar();
}
bool KateViewSpace::hasWidgets() const
......
......@@ -85,6 +85,11 @@ public:
return m_tabBar->documentList();
}
int tabCount() const
{
return m_tabBar->count();
}
/**
* How many documents are registered here?
*/
......@@ -255,7 +260,7 @@ private Q_SLOTS:
/**
* Document created or deleted, used to auto hide/show the tabs
*/
void documentCreatedOrDeleted(KTextEditor::Document *);
void updateTabBar();
private:
bool acceptsDroppedTab(const class QMimeData *tabMimeData);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment