diff --git a/NEWS.md b/NEWS.md index c4b5f250..ab131309 100644 --- a/NEWS.md +++ b/NEWS.md @@ -112,6 +112,7 @@ Red Panda C++ Version 2.27 - enhancement: Make colors in header suggestion popup consistent with the editor. - fix: C++ source after ';' are treated as comments in cpu info window. - enhancement: Support "extern template" in code parser. + - enhancement: Set shortcuts for tools menu item. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index c6eaea93..81a43426 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -489,8 +489,8 @@ MainWindow::MainWindow(QWidget *parent) updateEditorActions(); updateCaretActions(); updateEditorColorSchemes(); - updateShortcuts(); updateTools(); + updateShortcuts(); updateEditorSettings(); //updateEditorBookmarks(); } @@ -3424,8 +3424,9 @@ void MainWindow::updateTools() ui->menuTools->addAction(ui->actionOptions); if (!mToolsManager->tools().isEmpty()) { ui->menuTools->addSeparator(); + QList actions; foreach (const PToolItem& item, mToolsManager->tools()) { - QAction* action = new QAction(item->title,ui->menuTools); + QAction* action = createShortcutCustomableAction(item->title,"tool-"+item->id); connect(action, &QAction::triggered, [item] (){ QMap macros = devCppMacroVariables(); @@ -3482,7 +3483,11 @@ void MainWindow::updateTools() }); ui->menuTools->addAction(action); + actions.append(action); } + ShortcutManager shortcutManager; + shortcutManager.load(); + shortcutManager.applyTo(actions); } } diff --git a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp index 4aa16754..6bfbf940 100644 --- a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp @@ -26,6 +26,7 @@ #include #include +#include ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group, QWidget *parent) : SettingsWidget(name,group,parent), @@ -197,6 +198,7 @@ void ToolsGeneralWidget::on_btnAdd_clicked() { ui->lstTools->setCurrentIndex(QModelIndex()); PToolItem item = std::make_shared(); + item->id=QUuid::createUuid().toString(); item->title = tr("untitled"); item->pauseAfterExit = false; mToolsModel.addTool(item); diff --git a/RedPandaIDE/toolsmanager.cpp b/RedPandaIDE/toolsmanager.cpp index 603a526b..7421dfd1 100644 --- a/RedPandaIDE/toolsmanager.cpp +++ b/RedPandaIDE/toolsmanager.cpp @@ -36,6 +36,7 @@ void ToolsManager::load() if (!fileExists(filename)) { mTools.clear(); PToolItem item = std::make_shared(); + item->id = QUuid::createUuid().toString(); item->title = tr("Remove Compiled"); #ifdef Q_OS_WIN item->program = "del"; @@ -55,6 +56,7 @@ void ToolsManager::load() // item->pauseAfterExit = false; // mTools.append(item); //#endif + save(); return; } //read config file @@ -82,6 +84,10 @@ void ToolsManager::load() foreach (const QJsonValue& value,array) { QJsonObject object = value.toObject(); PToolItem item = std::make_shared(); + if (!object.contains("id")) + item->id = QUuid::createUuid().toString(); + else + item->id = object["id"].toString(); item->title = object["title"].toString(); if (item->title.isEmpty()) continue; @@ -107,6 +113,7 @@ void ToolsManager::save() QJsonArray array; foreach (const PToolItem& tool,mTools) { QJsonObject object; + object["id"]=tool->id; object["title"]=tool->title; object["program"]=tool->program; object["workingDirectory"] = tool->workingDirectory; diff --git a/RedPandaIDE/toolsmanager.h b/RedPandaIDE/toolsmanager.h index 53864940..6e7c0a21 100644 --- a/RedPandaIDE/toolsmanager.h +++ b/RedPandaIDE/toolsmanager.h @@ -21,6 +21,7 @@ #include struct ToolItem { + QString id; QString title; QString program; QString workingDirectory;