fix: sidebar dock tabs get functional close buttons when tabified

When Project and Modules docks are tabified together, Qt creates a
tab bar with close buttons via setupDockTabBars(). The dock lookup
only searched m_docDocks, so sidebar dock close buttons were installed
but never connected — clicking × did nothing.

Now the lookup also checks m_workspaceDock, m_scannerDock, and
m_symbolsDock. Middle-click close and right-click context menu also
work for sidebar tabs. Sidebar tabs get a minimal context menu
(Close + Float/Dock) while doc tabs keep the full menu.
This commit is contained in:
IChooseYou
2026-03-15 15:19:08 -06:00
committed by IChooseYou
parent b2a81ea687
commit bc94a595c7

View File

@@ -2112,6 +2112,15 @@ void MainWindow::setupDockTabBars() {
tabBar->setTabVisible(i, false); tabBar->setTabVisible(i, false);
} }
// Helper: find any dock widget by title (doc tabs + sidebar docks)
auto findDockByTitle = [this](const QString& title) -> QDockWidget* {
for (auto* d : m_docDocks)
if (d->windowTitle() == title) return d;
for (auto* d : {m_workspaceDock, m_scannerDock, m_symbolsDock})
if (d && d->windowTitle() == title) return d;
return nullptr;
};
// Install tab buttons for any tab that doesn't have them yet // Install tab buttons for any tab that doesn't have them yet
for (int i = 0; i < tabBar->count(); ++i) { for (int i = 0; i < tabBar->count(); ++i) {
if (tabBar->tabText(i) == sentinelTitle) if (tabBar->tabText(i) == sentinelTitle)
@@ -2123,12 +2132,8 @@ void MainWindow::setupDockTabBars() {
auto* btns = new DockTabButtons(tabBar); auto* btns = new DockTabButtons(tabBar);
btns->applyTheme(theme.hover); btns->applyTheme(theme.hover);
// Find dock by matching tab title // Find dock by matching tab title (doc tabs + sidebar docks)
QString title = tabBar->tabText(i); QDockWidget* target = findDockByTitle(tabBar->tabText(i));
QDockWidget* target = nullptr;
for (auto* d : m_docDocks) {
if (d->windowTitle() == title) { target = d; break; }
}
if (target) { if (target) {
connect(btns->closeBtn, &QToolButton::clicked, connect(btns->closeBtn, &QToolButton::clicked,
target, &QDockWidget::close); target, &QDockWidget::close);
@@ -2145,22 +2150,29 @@ void MainWindow::setupDockTabBars() {
int idx = tabBar->tabAt(pos); int idx = tabBar->tabAt(pos);
if (idx < 0) return; if (idx < 0) return;
// Find target dock // Find target dock (doc tabs + sidebar docks)
QString tabTitle = tabBar->tabText(idx); QString tabTitle = tabBar->tabText(idx);
QDockWidget* target = nullptr; QDockWidget* target = nullptr;
for (auto* d : m_docDocks) for (auto* d : m_docDocks)
if (d->windowTitle() == tabTitle) { target = d; break; } if (d->windowTitle() == tabTitle) { target = d; break; }
if (!target) {
for (auto* d : {m_workspaceDock, m_scannerDock, m_symbolsDock})
if (d && d->windowTitle() == tabTitle) { target = d; break; }
}
if (!target) return; if (!target) return;
auto tabIt = m_tabs.find(target); bool isDocDock = m_docDocks.contains(target);
QMenu menu; QMenu menu;
// Close // Close
menu.addAction(makeIcon(":/vsicons/close.svg"), "Close", menu.addAction(makeIcon(":/vsicons/close.svg"), "Close",
QKeySequence(Qt::CTRL | Qt::Key_W),
[target]() { target->close(); }); [target]() { target->close(); });
// Doc-only actions
if (isDocDock) {
auto tabIt = m_tabs.find(target);
menu.addSeparator(); menu.addSeparator();
// Close All Tabs // Close All Tabs
@@ -2189,17 +2201,19 @@ void MainWindow::setupDockTabBars() {
QUrl::fromLocalFile(QFileInfo(path).absolutePath())); QUrl::fromLocalFile(QFileInfo(path).absolutePath()));
}); });
} }
}
menu.addSeparator();
// Float / Dock // Float / Dock
menu.addAction(target->isFloating() ? "Dock" : "Float", [target]() { menu.addAction(target->isFloating() ? "Dock" : "Float", [target]() {
target->setFloating(!target->isFloating()); target->setFloating(!target->isFloating());
}); });
// New Document Groups (doc tabs only, >1 visible tab)
if (isDocDock) {
menu.addSeparator(); menu.addSeparator();
menu.addSeparator();
// New Document Groups (only if >1 visible tab — excludes sentinels)
int visibleTabs = 0; int visibleTabs = 0;
for (int i = 0; i < tabBar->count(); ++i) for (int i = 0; i < tabBar->count(); ++i)
if (tabBar->isTabVisible(i)) ++visibleTabs; if (tabBar->isTabVisible(i)) ++visibleTabs;
@@ -2255,6 +2269,7 @@ void MainWindow::setupDockTabBars() {
}); });
}); });
} }
}
menu.exec(tabBar->mapToGlobal(pos)); menu.exec(tabBar->mapToGlobal(pos));
}); });
@@ -2270,7 +2285,10 @@ bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
if (idx >= 0) { if (idx >= 0) {
QString title = tabBar->tabText(idx); QString title = tabBar->tabText(idx);
for (auto* d : m_docDocks) { for (auto* d : m_docDocks) {
if (d->windowTitle() == title) { d->close(); break; } if (d->windowTitle() == title) { d->close(); return true; }
}
for (auto* d : {m_workspaceDock, m_scannerDock, m_symbolsDock}) {
if (d && d->windowTitle() == title) { d->close(); return true; }
} }
return true; return true;
} }