mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
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:
44
src/main.cpp
44
src/main.cpp
@@ -2112,6 +2112,15 @@ void MainWindow::setupDockTabBars() {
|
||||
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
|
||||
for (int i = 0; i < tabBar->count(); ++i) {
|
||||
if (tabBar->tabText(i) == sentinelTitle)
|
||||
@@ -2123,12 +2132,8 @@ void MainWindow::setupDockTabBars() {
|
||||
auto* btns = new DockTabButtons(tabBar);
|
||||
btns->applyTheme(theme.hover);
|
||||
|
||||
// Find dock by matching tab title
|
||||
QString title = tabBar->tabText(i);
|
||||
QDockWidget* target = nullptr;
|
||||
for (auto* d : m_docDocks) {
|
||||
if (d->windowTitle() == title) { target = d; break; }
|
||||
}
|
||||
// Find dock by matching tab title (doc tabs + sidebar docks)
|
||||
QDockWidget* target = findDockByTitle(tabBar->tabText(i));
|
||||
if (target) {
|
||||
connect(btns->closeBtn, &QToolButton::clicked,
|
||||
target, &QDockWidget::close);
|
||||
@@ -2145,22 +2150,29 @@ void MainWindow::setupDockTabBars() {
|
||||
int idx = tabBar->tabAt(pos);
|
||||
if (idx < 0) return;
|
||||
|
||||
// Find target dock
|
||||
// Find target dock (doc tabs + sidebar docks)
|
||||
QString tabTitle = tabBar->tabText(idx);
|
||||
QDockWidget* target = nullptr;
|
||||
for (auto* d : m_docDocks)
|
||||
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;
|
||||
|
||||
auto tabIt = m_tabs.find(target);
|
||||
bool isDocDock = m_docDocks.contains(target);
|
||||
|
||||
QMenu menu;
|
||||
|
||||
// Close
|
||||
menu.addAction(makeIcon(":/vsicons/close.svg"), "Close",
|
||||
QKeySequence(Qt::CTRL | Qt::Key_W),
|
||||
[target]() { target->close(); });
|
||||
|
||||
// Doc-only actions
|
||||
if (isDocDock) {
|
||||
auto tabIt = m_tabs.find(target);
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// Close All Tabs
|
||||
@@ -2189,17 +2201,19 @@ void MainWindow::setupDockTabBars() {
|
||||
QUrl::fromLocalFile(QFileInfo(path).absolutePath()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// Float / Dock
|
||||
menu.addAction(target->isFloating() ? "Dock" : "Float", [target]() {
|
||||
target->setFloating(!target->isFloating());
|
||||
});
|
||||
|
||||
// New Document Groups (doc tabs only, >1 visible tab)
|
||||
if (isDocDock) {
|
||||
menu.addSeparator();
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// New Document Groups (only if >1 visible tab — excludes sentinels)
|
||||
int visibleTabs = 0;
|
||||
for (int i = 0; i < tabBar->count(); ++i)
|
||||
if (tabBar->isTabVisible(i)) ++visibleTabs;
|
||||
@@ -2255,6 +2269,7 @@ void MainWindow::setupDockTabBars() {
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menu.exec(tabBar->mapToGlobal(pos));
|
||||
});
|
||||
@@ -2270,7 +2285,10 @@ bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
|
||||
if (idx >= 0) {
|
||||
QString title = tabBar->tabText(idx);
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user