From db95cce299bf73518f29fcff61322b97387cce1b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 4 Mar 2024 20:40:13 +0800 Subject: [PATCH] - enhancement: Shortcuts for the tree view in files panel. --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 43 ++++++++++++++++++++++++++++---------- RedPandaIDE/mainwindow.h | 6 ++++-- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 048b0b34..9c06ee59 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,7 @@ Red Panda C++ Version 2.27 - enhancement: Better look&feel for the wave underline shown for syntax errors. - fix: "float" in #include "float.h" is wrong syntax colored. - enhancement: Unify syntax color for #include header name + - enhancement: Shortcuts for the tree view in files panel. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 16c504d2..719c570a 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2984,48 +2984,68 @@ void MainWindow::createCustomActions() //Files view mFilesView_CreateFolder = createAction( tr("New Folder"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_F, + Qt::WidgetShortcut); connect(mFilesView_CreateFolder, &QAction::triggered, this, &MainWindow::onFilesViewCreateFolder); mFilesView_CreateFile = createAction( tr("New File"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_N, + Qt::WidgetShortcut); connect(mFilesView_CreateFile, &QAction::triggered, this, &MainWindow::onFilesViewCreateFile); mFilesView_Rename = createAction( tr("Rename"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_R, + Qt::WidgetShortcut); connect(mFilesView_Rename, &QAction::triggered, this, &MainWindow::onFilesViewRename); mFilesView_RemoveFile = createAction( tr("Delete"), - ui->treeFiles); - mFilesView_RemoveFile->setShortcut(Qt::Key_Delete); + ui->treeFiles, + Qt::Key_Delete, + Qt::WidgetShortcut); connect(mFilesView_RemoveFile, &QAction::triggered, this, &MainWindow::onFilesViewRemoveFiles); + mFilesView_Open = createAction( tr("Open in Editor"), - ui->treeFiles); + ui->treeFiles, + Qt::Key_Return, + Qt::WidgetShortcut); + mFilesView_Open->setShortcuts( + {Qt::Key_Return, Qt::Key_Enter}); connect(mFilesView_Open, &QAction::triggered, this, &MainWindow::onFilesViewOpen); mFilesView_OpenWithExternal = createAction( tr("Open in External Program"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_O, + Qt::WidgetShortcut); connect(mFilesView_OpenWithExternal, &QAction::triggered, this, &MainWindow::onFilesViewOpenWithExternal); + mFilesView_OpenInTerminal = createAction( tr("Open in Terminal"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_T, + Qt::WidgetShortcut); mFilesView_OpenInTerminal->setIcon(ui->actionOpen_Terminal->icon()); connect(mFilesView_OpenInTerminal, &QAction::triggered, this, &MainWindow::onFilesViewOpenInTerminal); + mFilesView_OpenInExplorer = createAction( tr("Open in Windows Explorer"), - ui->treeFiles); + ui->treeFiles, + Qt::CTRL + Qt::Key_E, + Qt::WidgetShortcut); mFilesView_OpenInExplorer->setIcon(ui->actionOpen_Containing_Folder->icon()); connect(mFilesView_OpenInExplorer, &QAction::triggered, this, &MainWindow::onFilesViewOpenInExplorer); @@ -3139,12 +3159,13 @@ void MainWindow::initToolButtons() QAction* MainWindow::createAction( const QString& text, QWidget* parent, - QKeySequence shortcut) { + QKeySequence shortcut, + Qt::ShortcutContext shortcutContext) { QAction* action= new QAction(text,parent); if (!shortcut.isEmpty()) action->setShortcut(shortcut); action->setPriority(QAction::HighPriority); - action->setShortcutContext(Qt::WidgetWithChildrenShortcut); + action->setShortcutContext(shortcutContext); parent->addAction(action); return action; } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index fe5ce1ee..126f756e 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -301,8 +301,10 @@ private: QStringList getDefaultCompilerSetBinDirs(); void openShell(const QString& folder, const QString& shellCommand, const QStringList& binDirs); QAction* createAction(const QString& text, - QWidget* parent, - QKeySequence shortcut=QKeySequence()); + QWidget* parent, + QKeySequence shortcut=QKeySequence(), + Qt::ShortcutContext shortcutContext = Qt::ShortcutContext::WidgetWithChildrenShortcut + ); QAction* createShortcutCustomableAction( const QString& text, const QString& objectName,