Skip to content

Commit 87c5b09

Browse files
committed
Allow specifying custom tab bar context menu
1 parent d876317 commit 87c5b09

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

src/NotepadNext/dialogs/MainWindow.cpp

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,29 +1980,57 @@ void MainWindow::tabBarRightClicked(ScintillaNext *editor)
19801980
// Focus on the correct tab
19811981
dockedEditor->switchToEditor(editor);
19821982

1983-
// Create the menu and show it
1983+
// Create the menu
19841984
QMenu *menu = new QMenu(this);
19851985
menu->setAttribute(Qt::WA_DeleteOnClose);
19861986

1987-
menu->addAction(ui->actionClose);
1988-
menu->addAction(ui->actionCloseAllExceptActive);
1989-
menu->addAction(ui->actionCloseAllToLeft);
1990-
menu->addAction(ui->actionCloseAllToRight);
1991-
menu->addSeparator();
1992-
menu->addAction(ui->actionSave);
1993-
menu->addAction(ui->actionSaveAs);
1994-
menu->addAction(ui->actionRename);
1995-
menu->addSeparator();
1996-
menu->addAction(ui->actionReload);
1997-
menu->addSeparator();
1987+
// Default actions
1988+
QStringList actionNames{
1989+
"actionClose",
1990+
"actionCloseAllExceptActive",
1991+
"actionCloseAllToLeft",
1992+
"actionCloseAllToRight",
1993+
"",
1994+
"actionSave",
1995+
"actionSaveAs",
1996+
"actionRename",
1997+
"",
1998+
"actionReload",
1999+
"",
19982000
#ifdef Q_OS_WIN
1999-
menu->addAction(ui->actionShowInExplorer);
2000-
menu->addAction(ui->actionOpenCommandPromptHere);
2001-
menu->addSeparator();
2001+
"actionShowInExplorer",
2002+
"actionOpenCommandPromptHere",
2003+
"",
20022004
#endif
2003-
menu->addAction(ui->actionCopyFullPath);
2004-
menu->addAction(ui->actionCopyFileName);
2005-
menu->addAction(ui->actionCopyFileDirectory);
2005+
"actionCopyFullPath",
2006+
"actionCopyFileName",
2007+
"actionCopyFileDirectory"
2008+
};
2009+
2010+
// If the entry exists in the settings, use that
2011+
ApplicationSettings *settings = app->getSettings();
2012+
if (settings->contains("Gui/TabBarContextMenu")) {
2013+
actionNames = settings->value("Gui/TabBarContextMenu").toStringList();
2014+
}
2015+
2016+
// Populate the menu
2017+
for (const QString &actionName : actionNames) {
2018+
if (actionName.isEmpty()) {
2019+
menu->addSeparator();
2020+
}
2021+
else {
2022+
QAction *a = findChild<QAction *>(actionName, Qt::FindDirectChildrenOnly);
2023+
2024+
if (a != Q_NULLPTR) {
2025+
menu->addAction(a);
2026+
}
2027+
else {
2028+
qWarning() << "Cannot locate menu named" << actionName;
2029+
}
2030+
}
2031+
}
2032+
2033+
// Show it
20062034
menu->popup(QCursor::pos());
20072035
}
20082036

0 commit comments

Comments
 (0)