From 2d0a06fef742b2b875612698883c715166044b33 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 5 Sep 2021 13:51:07 +0800 Subject: [PATCH] - feature: context menu for issue table - feature: copy current item's description in issue table --- RedPandaIDE/mainwindow.cpp | 82 +++++++++++++++++++++++++++-- RedPandaIDE/mainwindow.h | 12 ++++- RedPandaIDE/mainwindow.ui | 14 ++++- RedPandaIDE/widgets/issuestable.cpp | 15 ++++++ 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 0260341d..7e9c2578 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -10,7 +10,6 @@ #include "widgets/cpudialog.h" #include "widgets/filepropertiesdialog.h" - #include #include #include @@ -619,7 +618,6 @@ void MainWindow::checkSyntaxInBack(Editor *e) return; mCheckSyntaxInBack=true; - e->clearSyntaxIssues(); ui->tableIssues->clearIssues(); mCompilerManager->checkSyntax(e->filename(),e->lines()->text(), e->fileEncoding() == ENCODING_ASCII); @@ -639,7 +637,6 @@ bool MainWindow::compile(bool rebuild) { Editor * editor = mEditorList->getEditor(); if (editor != NULL ) { - editor->clearSyntaxIssues(); ui->tableIssues->clearIssues(); if (editor->modified()) { if (!editor->save(false,false)) @@ -1107,11 +1104,37 @@ void MainWindow::doAutoSave(Editor *e) e->saveFile(filename); } +//static void limitActionShortCutScope(QAction* action,QWidget* scopeWidget) { +// action->setParent(scopeWidget); +// action->setShortcutContext(Qt::WidgetWithChildrenShortcut); +//} + +QAction* MainWindow::createActionFor( + const QString& text, + QWidget* parent, + QKeySequence shortcut) { + QAction* action= new QAction(text,parent); + if (!shortcut.isEmpty()) + action->setShortcut(shortcut); + action->setPriority(QAction::HighPriority); + action->setShortcutContext(Qt::WidgetWithChildrenShortcut); + parent->addAction(action); + return action; +} void MainWindow::buildContextMenus() { + +// //prevent these action from active when editor not focused +// limitActionShortCutScope(ui->actionCopy,ui->EditorPanel); +// limitActionShortCutScope(ui->actionCut,ui->EditorPanel); +// limitActionShortCutScope(ui->actionSelectAll,ui->EditorPanel); +// limitActionShortCutScope(ui->actionPaste,ui->EditorPanel); +// limitActionShortCutScope(ui->actionSave,ui->EditorPanel); + ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->watchView,&QWidget::customContextMenuRequested, this, &MainWindow::onWatchViewContextMenu); + ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->EditorTabsLeft->tabBar(),&QWidget::customContextMenuRequested, this, &MainWindow::onEditorTabContextMenu); @@ -1119,6 +1142,47 @@ void MainWindow::buildContextMenus() connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested, this, &MainWindow::onEditorTabContextMenu); + ui->tableIssues->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->tableIssues,&QWidget::customContextMenuRequested, + this, &MainWindow::onTableIssuesContextMenu); + mTableIssuesCopyAction = createActionFor( + tr("Copy"), + ui->tableIssues, + QKeySequence("Ctrl+C")); + connect(mTableIssuesCopyAction,&QAction::triggered, + [this](){ + QModelIndex index = ui->tableIssues->selectionModel()->currentIndex(); + PCompileIssue issue = ui->tableIssues->issue(index); + if (issue) { + QClipboard* clipboard = QApplication::clipboard(); + clipboard->setText(issue->description); + } + }); + mTableIssuesCopyAllAction = createActionFor( + tr("Copy all"), + ui->tableIssues, + QKeySequence("Ctrl+Shift+C")); + connect(mTableIssuesCopyAllAction,&QAction::triggered, + [this](){ + qDebug()<<"copy all"; + }); + mTableIssuesSaveAction = createActionFor( + tr("Save"), + ui->tableIssues, + QKeySequence("Ctrl+S")); + connect(mTableIssuesSaveAction,&QAction::triggered, + [this](){ + qDebug()<<"Save"; + }); + mTableIssuesClearAction = createActionFor( + tr("Clear"), + ui->tableIssues); + connect(mTableIssuesClearAction,&QAction::triggered, + [this](){ + qDebug()<<"Clear"; + ui->tableIssues->clearIssues(); + }); + } void MainWindow::maximizeEditor() @@ -1201,6 +1265,18 @@ void MainWindow::onWatchViewContextMenu(const QPoint &pos) menu.exec(ui->watchView->mapToGlobal(pos)); } +void MainWindow::onTableIssuesContextMenu(const QPoint &pos) +{ + QMenu menu(this); + menu.addAction(mTableIssuesCopyAction); + menu.addAction(mTableIssuesCopyAllAction); + menu.addSeparator(); + menu.addAction(mTableIssuesSaveAction); + menu.addSeparator(); + menu.addAction(mTableIssuesClearAction); + menu.exec(ui->tableIssues->mapToGlobal(pos)); +} + void MainWindow::onEditorContextMenu(const QPoint &pos) { Editor * editor = mEditorList->getEditor(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 8496a744..e13af3b6 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -134,12 +134,17 @@ private: void buildContextMenus(); void maximizeEditor(); void openShell(const QString& folder, const QString& shellCommand); + QAction* createActionFor(const QString& text, + QWidget* parent, + QKeySequence shortcut=QKeySequence()); private slots: void onAutoSaveTimeout(); - void onWatchViewContextMenu(const QPoint& pos); void onFileChanged(const QString& path); + void onWatchViewContextMenu(const QPoint& pos); + void onTableIssuesContextMenu(const QPoint& pos); + void on_actionNew_triggered(); void on_EditorTabsLeft_tabCloseRequested(int index); @@ -329,6 +334,11 @@ private: bool mSystemTurnedOff; QPoint mEditorContextMenuPos; + QAction * mTableIssuesCopyAction; + QAction * mTableIssuesCopyAllAction; + QAction * mTableIssuesSaveAction; + QAction * mTableIssuesClearAction; + // QWidget interface protected: void closeEvent(QCloseEvent *event) override; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 48f65cff..e10e45b2 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -255,7 +255,7 @@ QTabWidget::South - 3 + 0 @@ -1104,6 +1104,9 @@ Ctrl+X + + Qt::WidgetWithChildrenShortcut + @@ -1117,6 +1120,9 @@ Ctrl+C + + Qt::WidgetWithChildrenShortcut + @@ -1130,6 +1136,9 @@ Ctrl+V + + Qt::WidgetWithChildrenShortcut + @@ -1138,6 +1147,9 @@ Ctrl+A + + Qt::WidgetWithChildrenShortcut + diff --git a/RedPandaIDE/widgets/issuestable.cpp b/RedPandaIDE/widgets/issuestable.cpp index 096d844e..8b302821 100644 --- a/RedPandaIDE/widgets/issuestable.cpp +++ b/RedPandaIDE/widgets/issuestable.cpp @@ -2,6 +2,9 @@ #include "../utils.h" #include #include "../settings.h" +#include "../mainwindow.h" +#include "../editor.h" +#include "../editorlist.h" IssuesTable::IssuesTable(QWidget *parent): @@ -44,11 +47,21 @@ void IssuesModel::addIssue(PCompileIssue issue) void IssuesModel::clearIssues() { + QSet issueFiles; + foreach(const PCompileIssue& issue, mIssues) { + if (!(issue->filename.isEmpty())){ + issueFiles.insert(issue->filename); + } + } if (mIssues.size()>0) { beginRemoveRows(QModelIndex(),0,mIssues.size()-1); mIssues.clear(); endRemoveRows(); } + foreach (const QString& filename, issueFiles) { + Editor *e=pMainWindow->editorList()->getOpenedEditorByFilename(filename); + e->clearSyntaxIssues(); + } } void IssuesModel::setErrorColor(QColor color) @@ -82,6 +95,8 @@ void IssuesTable::addIssue(PCompileIssue issue) PCompileIssue IssuesTable::issue(const QModelIndex &index) { + if (!index.isValid()) + return PCompileIssue(); return issue(index.row()); }