- enhancement: Set shortcuts for tools menu item.

This commit is contained in:
Roy Qu 2024-04-01 19:25:14 +08:00
parent 6339b44d5f
commit e10b5b1d39
5 changed files with 18 additions and 2 deletions

View File

@ -112,6 +112,7 @@ Red Panda C++ Version 2.27
- enhancement: Make colors in header suggestion popup consistent with the editor. - enhancement: Make colors in header suggestion popup consistent with the editor.
- fix: C++ source after ';' are treated as comments in cpu info window. - fix: C++ source after ';' are treated as comments in cpu info window.
- enhancement: Support "extern template" in code parser. - enhancement: Support "extern template" in code parser.
- enhancement: Set shortcuts for tools menu item.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -489,8 +489,8 @@ MainWindow::MainWindow(QWidget *parent)
updateEditorActions(); updateEditorActions();
updateCaretActions(); updateCaretActions();
updateEditorColorSchemes(); updateEditorColorSchemes();
updateShortcuts();
updateTools(); updateTools();
updateShortcuts();
updateEditorSettings(); updateEditorSettings();
//updateEditorBookmarks(); //updateEditorBookmarks();
} }
@ -3424,8 +3424,9 @@ void MainWindow::updateTools()
ui->menuTools->addAction(ui->actionOptions); ui->menuTools->addAction(ui->actionOptions);
if (!mToolsManager->tools().isEmpty()) { if (!mToolsManager->tools().isEmpty()) {
ui->menuTools->addSeparator(); ui->menuTools->addSeparator();
QList<QAction*> actions;
foreach (const PToolItem& item, mToolsManager->tools()) { 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, connect(action, &QAction::triggered,
[item] (){ [item] (){
QMap<QString, QString> macros = devCppMacroVariables(); QMap<QString, QString> macros = devCppMacroVariables();
@ -3482,7 +3483,11 @@ void MainWindow::updateTools()
}); });
ui->menuTools->addAction(action); ui->menuTools->addAction(action);
actions.append(action);
} }
ShortcutManager shortcutManager;
shortcutManager.load();
shortcutManager.applyTo(actions);
} }
} }

View File

@ -26,6 +26,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QUuid>
ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group, QWidget *parent) : ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group, QWidget *parent) :
SettingsWidget(name,group,parent), SettingsWidget(name,group,parent),
@ -197,6 +198,7 @@ void ToolsGeneralWidget::on_btnAdd_clicked()
{ {
ui->lstTools->setCurrentIndex(QModelIndex()); ui->lstTools->setCurrentIndex(QModelIndex());
PToolItem item = std::make_shared<ToolItem>(); PToolItem item = std::make_shared<ToolItem>();
item->id=QUuid::createUuid().toString();
item->title = tr("untitled"); item->title = tr("untitled");
item->pauseAfterExit = false; item->pauseAfterExit = false;
mToolsModel.addTool(item); mToolsModel.addTool(item);

View File

@ -36,6 +36,7 @@ void ToolsManager::load()
if (!fileExists(filename)) { if (!fileExists(filename)) {
mTools.clear(); mTools.clear();
PToolItem item = std::make_shared<ToolItem>(); PToolItem item = std::make_shared<ToolItem>();
item->id = QUuid::createUuid().toString();
item->title = tr("Remove Compiled"); item->title = tr("Remove Compiled");
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
item->program = "del"; item->program = "del";
@ -55,6 +56,7 @@ void ToolsManager::load()
// item->pauseAfterExit = false; // item->pauseAfterExit = false;
// mTools.append(item); // mTools.append(item);
//#endif //#endif
save();
return; return;
} }
//read config file //read config file
@ -82,6 +84,10 @@ void ToolsManager::load()
foreach (const QJsonValue& value,array) { foreach (const QJsonValue& value,array) {
QJsonObject object = value.toObject(); QJsonObject object = value.toObject();
PToolItem item = std::make_shared<ToolItem>(); PToolItem item = std::make_shared<ToolItem>();
if (!object.contains("id"))
item->id = QUuid::createUuid().toString();
else
item->id = object["id"].toString();
item->title = object["title"].toString(); item->title = object["title"].toString();
if (item->title.isEmpty()) if (item->title.isEmpty())
continue; continue;
@ -107,6 +113,7 @@ void ToolsManager::save()
QJsonArray array; QJsonArray array;
foreach (const PToolItem& tool,mTools) { foreach (const PToolItem& tool,mTools) {
QJsonObject object; QJsonObject object;
object["id"]=tool->id;
object["title"]=tool->title; object["title"]=tool->title;
object["program"]=tool->program; object["program"]=tool->program;
object["workingDirectory"] = tool->workingDirectory; object["workingDirectory"] = tool->workingDirectory;

View File

@ -21,6 +21,7 @@
#include <memory> #include <memory>
struct ToolItem { struct ToolItem {
QString id;
QString title; QString title;
QString program; QString program;
QString workingDirectory; QString workingDirectory;