- feature: context menu for issue table
- feature: copy current item's description in issue table
This commit is contained in:
parent
d232cd85d3
commit
2d0a06fef7
|
@ -10,7 +10,6 @@
|
|||
#include "widgets/cpudialog.h"
|
||||
#include "widgets/filepropertiesdialog.h"
|
||||
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QComboBox>
|
||||
#include <QDesktopServices>
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -255,7 +255,7 @@
|
|||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>3</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabIssues">
|
||||
<attribute name="icon">
|
||||
|
@ -1104,6 +1104,9 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+X</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
<property name="icon">
|
||||
|
@ -1117,6 +1120,9 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+C</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPaste">
|
||||
<property name="icon">
|
||||
|
@ -1130,6 +1136,9 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+V</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSelectAll">
|
||||
<property name="text">
|
||||
|
@ -1138,6 +1147,9 @@
|
|||
<property name="shortcut">
|
||||
<string>Ctrl+A</string>
|
||||
</property>
|
||||
<property name="shortcutContext">
|
||||
<enum>Qt::WidgetWithChildrenShortcut</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionIndent">
|
||||
<property name="icon">
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#include "../utils.h"
|
||||
#include <QHeaderView>
|
||||
#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<QString> 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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue