Commit 97fb16af authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

auto hide tabs if we have just one document open

initial implementation, needs config UI
parent 98e83354
Pipeline #157988 passed with stage
in 6 minutes and 59 seconds
......@@ -23,6 +23,7 @@
#include <KAcceleratorManager>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <QApplication>
#include <QClipboard>
......@@ -161,12 +162,30 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
m_layout.tabBarLayout = hLayout;
m_layout.mainLayout = layout;
// init tab bar
tabBarToggled();
// apply config, will init tabbar
readConfig();
// handle config changes
connect(KateApp::self(), &KateApp::configurationChanged, this, &KateViewSpace::readConfig);
// ensure we show/hide tabbar if needed
connect(KateApp::self()->documentManager(), &KateDocManager::documentCreated, this, &KateViewSpace::documentCreatedOrDeleted);
connect(KateApp::self()->documentManager(), &KateDocManager::documentDeleted, this, &KateViewSpace::documentCreatedOrDeleted);
}
KateViewSpace::~KateViewSpace() = default;
void KateViewSpace::readConfig()
{
// get tab config
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup cgGeneral = KConfigGroup(config, "General");
m_autoHideTabBar = cgGeneral.readEntry("Auto Hide Tabs", true);
// init tab bar
tabBarToggled();
}
bool KateViewSpace::eventFilter(QObject *obj, QEvent *event)
{
QToolButton *button = qobject_cast<QToolButton *>(obj);
......@@ -203,11 +222,29 @@ bool KateViewSpace::eventFilter(QObject *obj, QEvent *event)
return false;
}
void KateViewSpace::documentCreatedOrDeleted(KTextEditor::Document *)
{
if (!m_autoHideTabBar || !m_viewManager->mainWindow()->showTabBar()) {
return;
}
// toggle hide/show if state changed
if ((KateApp::self()->documentManager()->documentList().size() > 1) != m_tabBar->isVisible()) {
tabBarToggled();
}
}
void KateViewSpace::tabBarToggled()
{
KateUpdateDisabler updatesDisabled(m_viewManager->mainWindow());
const bool show = m_viewManager->mainWindow()->showTabBar();
bool show = m_viewManager->mainWindow()->showTabBar();
// we might want to auto hide if just one document is open
if (show && m_autoHideTabBar) {
show = KateApp::self()->documentManager()->documentList().size() > 1;
}
const bool urlBarVisible = m_viewManager->showUrlNavBar();
bool showButtons = true;
......
......@@ -224,6 +224,16 @@ private Q_SLOTS:
*/
void createNewDocument();
/**
* Read and apply the config for this view space.
*/
void readConfig();
/**
* Document created or deleted, used to auto hide/show the tabs
*/
void documentCreatedOrDeleted(KTextEditor::Document *);
private:
bool acceptsDroppedTab(const class QMimeData *tabMimeData);
/**
......@@ -305,6 +315,9 @@ private:
} m_layout;
friend class LocationHistoryTest;
// should the tab bar be auto hidden if just one document is open?
bool m_autoHideTabBar = false;
};
#endif
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