Shortcut conflicts

This commit is contained in:
Roy Qu 2024-04-12 17:07:00 +08:00
parent 87586202dc
commit 75ef074601
4 changed files with 118 additions and 84 deletions

View File

@ -236,11 +236,8 @@ MainWindow::MainWindow(QWidget *parent)
e.reason()); e.reason());
} }
// ui->actionIndent->setShortcut(Qt::Key_Tab);
// ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier);
//mainmenu takes the owner //mainmenu takes the owner
mMenuNew = new QMenu(); mMenuNew = new QMenu(this);
mMenuNew->setTitle(tr("New")); mMenuNew->setTitle(tr("New"));
mMenuNew->addAction(ui->actionNew); mMenuNew->addAction(ui->actionNew);
mMenuNew->addAction(ui->actionNew_GAS_File); mMenuNew->addAction(ui->actionNew_GAS_File);
@ -254,7 +251,6 @@ MainWindow::MainWindow(QWidget *parent)
ui->menuFile->insertMenu(ui->actionOpen,mMenuNew); ui->menuFile->insertMenu(ui->actionOpen,mMenuNew);
mMenuExport = new QMenu(tr("Export")); mMenuExport = new QMenu(tr("Export"));
mMenuExport->addAction(ui->actionExport_As_RTF); mMenuExport->addAction(ui->actionExport_As_RTF);
mMenuExport->addAction(ui->actionExport_As_HTML); mMenuExport->addAction(ui->actionExport_As_HTML);
@ -475,10 +471,22 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->menuGit, &QMenu::aboutToShow, connect(ui->menuGit, &QMenu::aboutToShow,
this, &MainWindow::updateVCSActions); this, &MainWindow::updateVCSActions);
#endif #endif
initEditorActions(); //set action group name (show in the option / environment / shortcuts)
ui->actionNew->setData(mMenuNew->title());
ui->actionNew_GAS_File->setData(mMenuNew->title());
ui->actionNew_Text_File->setData(mMenuNew->title());
ui->actionNew_Project->setData(mMenuNew->title());
ui->actionRemove_Watch->setData(tr("Debug"));
ui->actionRemove_All_Watches->setData(tr("Debug"));
ui->actionModify_Watch->setData(tr("Debug"));
ui->actionRemove_All_Watches->setData(tr("Debug"));
ui->actionBreakpoint_property->setData(tr("Debug"));
initToolButtons(); initToolButtons();
buildContextMenus(); buildContextMenus();
updateAppTitle(); updateAppTitle();
initEditorActions();
//applySettings(); //applySettings();
applyUISettings(); applyUISettings();
initDocks(); initDocks();
@ -1578,6 +1586,8 @@ void MainWindow::updateShortcuts()
{ {
ShortcutManager manager; ShortcutManager manager;
manager.load(); manager.load();
// foreach(QAction* action, listShortCutableActions())
// qDebug()<<action->text()<<action->objectName();
manager.applyTo(listShortCutableActions()); manager.applyTo(listShortCutableActions());
} }
@ -2805,22 +2815,19 @@ void MainWindow::createCustomActions()
// action for problem set // action for problem set
mProblemSet_New = createAction( mProblemSet_New = createAction(
tr("New Problem Set"), tr("New Problem Set"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblemSet_New,&QAction::triggered, connect(mProblemSet_New,&QAction::triggered,
this, &MainWindow::onNewProblemSet); this, &MainWindow::onNewProblemSet);
mProblemSet_Rename = createAction( mProblemSet_Rename = createAction(
tr("Rename Problem Set"), tr("Rename Problem Set"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblemSet_Rename, &QAction::triggered, connect(mProblemSet_Rename, &QAction::triggered,
this, &MainWindow::onRenameProblemSet); this, &MainWindow::onRenameProblemSet);
mProblemSet_Save = createAction( mProblemSet_Save = createAction(
tr("Save Problem Set"), tr("Save Problem Set"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblemSet_Save,&QAction::triggered, connect(mProblemSet_Save,&QAction::triggered,
this, &MainWindow::onSaveProblemSet); this, &MainWindow::onSaveProblemSet);
@ -2854,26 +2861,22 @@ void MainWindow::createCustomActions()
connect(mProblemSet_RemoveProblem,&QAction::triggered, connect(mProblemSet_RemoveProblem,&QAction::triggered,
this, &MainWindow::onRemoveProblem); this, &MainWindow::onRemoveProblem);
//problem //problem
mProblem_OpenSource=createAction( mProblem_OpenSource=createAction(
tr("Open Source File"), tr("Open Source File"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblem_OpenSource, &QAction::triggered, this, connect(mProblem_OpenSource, &QAction::triggered, this,
&MainWindow::onProblemOpenSource); &MainWindow::onProblemOpenSource);
mProblem_Rename=createAction( mProblem_Rename=createAction(
tr("Rename Problem"), tr("Rename Problem"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblem_Rename, &QAction::triggered, this, connect(mProblem_Rename, &QAction::triggered, this,
&MainWindow::onProblemRename); &MainWindow::onProblemRename);
mProblem_GotoUrl=createAction( mProblem_GotoUrl=createAction(
tr("Goto Url"), tr("Goto Url"),
ui->tabProblemSet ui->tabProblemSet);
);
connect(mProblem_GotoUrl, &QAction::triggered, this, connect(mProblem_GotoUrl, &QAction::triggered, this,
&MainWindow::onProblemGotoUrl); &MainWindow::onProblemGotoUrl);
@ -2910,21 +2913,24 @@ void MainWindow::createCustomActions()
&MainWindow::onOpenCaseValidationOptions); &MainWindow::onOpenCaseValidationOptions);
// problem case run // problem case run
mProblem_RunAllCases = createShortcutCustomableAction( mProblem_RunAllCases = createGlobalAction(
tr("Run All Cases"), tr("Run All Cases"),
"Problem_RunAllCases"); "Problem_RunAllCases",
tr("Problem"));
connect(mProblem_RunAllCases, &QAction::triggered, this, connect(mProblem_RunAllCases, &QAction::triggered, this,
&MainWindow::onProblemRunAllCases); &MainWindow::onProblemRunAllCases);
mProblem_RunCurrentCase = createShortcutCustomableAction( mProblem_RunCurrentCase = createGlobalAction(
tr("Run Current Case"), tr("Run Current Case"),
"Problem_RunCurrentCases"); "Problem_RunCurrentCases",
tr("Problem"));
connect(mProblem_RunCurrentCase, &QAction::triggered, this, connect(mProblem_RunCurrentCase, &QAction::triggered, this,
&MainWindow::onProblemRunCurrentCase); &MainWindow::onProblemRunCurrentCase);
mProblem_batchSetCases = createShortcutCustomableAction( mProblem_batchSetCases = createGlobalAction(
tr("Batch Set Cases"), tr("Batch Set Cases"),
"Problem_BatchSetCases"); "Problem_BatchSetCases",
tr("Problem"));
connect(mProblem_batchSetCases, &QAction::triggered, this, connect(mProblem_batchSetCases, &QAction::triggered, this,
&MainWindow::onProblemBatchSetCases); &MainWindow::onProblemBatchSetCases);
@ -2971,7 +2977,8 @@ void MainWindow::createCustomActions()
mDebugConsole_SelectAll=createAction( mDebugConsole_SelectAll=createAction(
tr("Select All"), tr("Select All"),
ui->debugConsole); ui->debugConsole,
QKeySequence("Ctrl+A"));
connect(mDebugConsole_SelectAll, &QAction::triggered, connect(mDebugConsole_SelectAll, &QAction::triggered,
this, &MainWindow::onDebugConsoleSelectAll); this, &MainWindow::onDebugConsoleSelectAll);
@ -3184,13 +3191,14 @@ void MainWindow::createCustomActions()
this, &MainWindow::onToolsOutputClear); this, &MainWindow::onToolsOutputClear);
mToolsOutput_Copy = createAction( mToolsOutput_Copy = createAction(
tr("Copy"), tr("Copy"),
ui->txtToolsOutput); ui->txtToolsOutput,
mToolsOutput_Copy->setShortcut(QKeySequence("Ctrl+C")); QKeySequence("Ctrl+C"));
connect(mToolsOutput_Copy, &QAction::triggered, connect(mToolsOutput_Copy, &QAction::triggered,
this, &MainWindow::onToolsOutputCopy); this, &MainWindow::onToolsOutputCopy);
mToolsOutput_SelectAll = createAction( mToolsOutput_SelectAll = createAction(
tr("Select All"), tr("Select All"),
ui->txtToolsOutput); ui->txtToolsOutput,
QKeySequence("Ctrl+A"));
connect(mToolsOutput_SelectAll, &QAction::triggered, connect(mToolsOutput_SelectAll, &QAction::triggered,
this, &MainWindow::onToolsOutputSelectAll); this, &MainWindow::onToolsOutputSelectAll);
} }
@ -3296,10 +3304,12 @@ QAction* MainWindow::createAction(
return action; return action;
} }
QAction *MainWindow::createShortcutCustomableAction(const QString &text, const QString &objectName, QKeySequence shortcut) QAction *MainWindow::createGlobalAction(const QString &text, const QString &objectName, const QString &groupName, QKeySequence shortcut)
{ {
QAction* action = createAction(text,this,shortcut); QAction* action = createAction(text,this,shortcut);
action->setObjectName(objectName); action->setObjectName(objectName);
action->setShortcutContext(Qt::WindowShortcut);
action->setData(groupName);
return action; return action;
} }
@ -3517,7 +3527,7 @@ void MainWindow::updateTools()
ui->menuTools->addSeparator(); ui->menuTools->addSeparator();
QList<QAction*> actions; QList<QAction*> actions;
foreach (const PToolItem& item, mToolsManager->tools()) { foreach (const PToolItem& item, mToolsManager->tools()) {
QAction* action = createShortcutCustomableAction(item->title,"tool-"+item->id); QAction* action = createGlobalAction(item->title,"tool-"+item->id, tr("Tools"));
connect(action, &QAction::triggered, connect(action, &QAction::triggered,
[item,this] (){ [item,this] (){
executeTool(item); executeTool(item);
@ -7838,56 +7848,67 @@ void MainWindow::initEditorActions()
ui->menuSelection->menuAction()->setVisible(false); ui->menuSelection->menuAction()->setVisible(false);
ui->menuRefactor->menuAction()->setVisible(false); ui->menuRefactor->menuAction()->setVisible(false);
foreach (QAction* action, ui->menuEdit->actions()) { backupMenuForEditor(ui->menuEdit, mMenuEditBackup);
if (action->objectName().isEmpty()) backupMenuForEditor(ui->menuSelection, mMenuSelectionBackup);
continue; backupMenuForEditor(ui->menuCode, mMenuCodeBackup);
changeEditorActionParent(action); backupMenuForEditor(ui->menuRefactor, mMenuRefactorBackup);
} backupMenuForEditor(ui->menuMove_Caret, mMenuMoveCaretBackup);
foreach (QAction* action, ui->menuSelection->actions()) { backupMenuForEditor(mMenuEncoding, mMenuEncodingBackup);
if (action->objectName().isEmpty()) backupMenuForEditor(mMenuExport, mMenuExportBackup);
continue;
changeEditorActionParent(action);
}
foreach (QAction* action, ui->menuCode->actions()) {
if (action->objectName().isEmpty())
continue;
changeEditorActionParent(action);
}
foreach (QAction* action, ui->menuRefactor->actions()) {
if (action->objectName().isEmpty())
continue;
changeEditorActionParent(action);
}
foreach (QAction* action, mMenuEncoding->actions()) {
if (action->objectName().isEmpty())
continue;
changeEditorActionParent(action);
}
changeEditorActionParent(ui->actionPrint);
changeEditorActionParent(ui->actionExport_As_HTML);
changeEditorActionParent(ui->actionExport_As_RTF);
changeEditorActionParent(ui->actionSave);
changeEditorActionParent(ui->actionSaveAs);
changeEditorActionParent(ui->actionClose);
changeEditorActionParent(ui->actionFind); // changeEditorActionParent(ui->actionPrint, tr("File"));
changeEditorActionParent(ui->actionReplace); // changeEditorActionParent(ui->actionSave, tr("File"));
changeEditorActionParent(ui->actionFind_references); // changeEditorActionParent(ui->actionSaveAs, tr("File"));
changeEditorActionParent(ui->actionFind_Next); // changeEditorActionParent(ui->actionClose, tr("File"));
changeEditorActionParent(ui->actionFind_Previous);
changeEditorActionParent(ui->actionToggle_Breakpoint); // changeEditorActionParent(ui->actionFind, tr("Search"));
changeEditorActionParent(ui->actionGoto_Declaration); // changeEditorActionParent(ui->actionReplace, tr("Search"));
changeEditorActionParent(ui->actionGoto_Definition); changeEditorActionParent(ui->actionFind_references, tr("Search"));
changeEditorActionParent(ui->actionFile_Properties); // changeEditorActionParent(ui->actionFind_Next, tr("Search"));
changeEditorActionParent(ui->actionLocate_in_Files_View); // changeEditorActionParent(ui->actionFind_Previous, tr("Search"));
changeEditorActionParent(ui->actionSwitchHeaderSource); changeEditorActionParent(ui->actionToggle_Breakpoint, tr("Debug"));
changeEditorActionParent(ui->actionGoto_Declaration, tr("Code"));
changeEditorActionParent(ui->actionGoto_Definition, tr("Code"));
changeEditorActionParent(ui->actionFile_Properties, tr("Code"));
changeEditorActionParent(ui->actionLocate_in_Files_View, tr("Code"));
changeEditorActionParent(ui->actionSwitchHeaderSource, tr("Code"));
} }
void MainWindow::changeEditorActionParent(QAction *action) void MainWindow::changeEditorActionParent(QAction *action, const QString& groupName)
{ {
action->setParent(ui->splitterEditorPanel); removeAction(action);
ui->splitterEditorPanel->addAction(action); action->setParent(ui->EditorPanel);
ui->EditorPanel->addAction(action);
action->setShortcutContext(Qt::WidgetWithChildrenShortcut); action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
action->setData(groupName);
}
void MainWindow::backupMenuForEditor(QMenu *menu, QList<QAction *> &backup)
{
foreach (QAction* action, menu->actions()) {
if (!action->objectName().isEmpty())
changeEditorActionParent(action, menu->title());
if (action->isSeparator()) {
action = new QAction();
action->setSeparator(true);
}
backup.append(action);
}
menu->clear();
connect(menu,&QMenu::aboutToShow,
[menu, backup] {
foreach (QAction* action, backup) {
if (action->isSeparator()) {
menu->addSeparator();
} else {
menu->addAction(action);
}
}
});
connect(menu,&QMenu::aboutToHide,
[menu] {
menu->clear();
});
} }
void MainWindow::setupSlotsForProject() void MainWindow::setupSlotsForProject()
@ -8916,6 +8937,7 @@ bool MainWindow::openningFiles() const
QList<QAction *> MainWindow::listShortCutableActions() QList<QAction *> MainWindow::listShortCutableActions()
{ {
QList<QAction*> actions = findChildren<QAction *>(QString(), Qt::FindDirectChildrenOnly); QList<QAction*> actions = findChildren<QAction *>(QString(), Qt::FindDirectChildrenOnly);
actions += ui->EditorPanel->actions();
return actions; return actions;
} }

View File

@ -305,11 +305,11 @@ private:
QAction* createAction(const QString& text, QAction* createAction(const QString& text,
QWidget* parent, QWidget* parent,
QKeySequence shortcut=QKeySequence(), QKeySequence shortcut=QKeySequence(),
Qt::ShortcutContext shortcutContext = Qt::ShortcutContext::WidgetWithChildrenShortcut Qt::ShortcutContext shortcutContext = Qt::WidgetWithChildrenShortcut);
); QAction* createGlobalAction(
QAction* createShortcutCustomableAction( const QString &text,
const QString& text, const QString &objectName,
const QString& objectName, const QString &groupName,
QKeySequence shortcut=QKeySequence()); QKeySequence shortcut=QKeySequence());
void scanActiveProject(bool parse=false); void scanActiveProject(bool parse=false);
void showSearchReplacePanel(bool show); void showSearchReplacePanel(bool show);
@ -335,7 +335,8 @@ private:
void modifyBreakpointCondition(int index); void modifyBreakpointCondition(int index);
void initEditorActions(); void initEditorActions();
void changeEditorActionParent(QAction *action); void changeEditorActionParent(QAction *action, const QString& groupName);
void backupMenuForEditor(QMenu* menu, QList<QAction *> &backup);
private slots: private slots:
void setupSlotsForProject(); void setupSlotsForProject();
@ -874,6 +875,14 @@ private:
QMenu *mMenuRecentProjects; QMenu *mMenuRecentProjects;
QMenu *mMenuNew; QMenu *mMenuNew;
QMenu *mMenuInsertCodeSnippet; QMenu *mMenuInsertCodeSnippet;
QList<QAction *> mMenuEditBackup;
QList<QAction *> mMenuCodeBackup;
QList<QAction *> mMenuSelectionBackup;
QList<QAction *> mMenuRefactorBackup;
QList<QAction *> mMenuEncodingBackup;
QList<QAction *> mMenuExportBackup;
QList<QAction *> mMenuMoveCaretBackup;
QComboBox *mCompilerSet; QComboBox *mCompilerSet;
std::shared_ptr<CompilerManager> mCompilerManager; std::shared_ptr<CompilerManager> mCompilerManager;
std::shared_ptr<Debugger> mDebugger; std::shared_ptr<Debugger> mDebugger;

View File

@ -86,7 +86,6 @@ void EnvironmentAppearanceWidget::doSave()
pSettings->environment().setUseCustomIconSet(ui->chkUseCustomIconSet->isChecked()); pSettings->environment().setUseCustomIconSet(ui->chkUseCustomIconSet->isChecked());
pSettings->environment().setUseCustomTheme(ui->chkUseCustomTheme->isChecked()); pSettings->environment().setUseCustomTheme(ui->chkUseCustomTheme->isChecked());
pSettings->environment().save(); pSettings->environment().save();
pMainWindow->applySettings(); pMainWindow->applySettings();
} }

View File

@ -79,7 +79,11 @@ void EnvironmentShortcutModel::reload()
if (!action->text().isEmpty()) { if (!action->text().isEmpty()) {
PEnvironmentShortcut item = std::make_shared<EnvironmentShortcut>(); PEnvironmentShortcut item = std::make_shared<EnvironmentShortcut>();
item->name = action->objectName(); item->name = action->objectName();
item->fullPath = QString("%1 : %2").arg(tr("action"),action->text()); QString groupName = action->data().toString();
if (!groupName.isEmpty())
item->fullPath = QString("%1 > %2").arg(groupName,action->text());
else
item->fullPath = QString("%1 > %2").arg(tr("action"),action->text());
item->action = action; item->action = action;
item->shortcut = action->shortcut().toString().trimmed(); item->shortcut = action->shortcut().toString().trimmed();
item->isAction = true; item->isAction = true;