From d232cd85d3d8cbf2c4677231fde5098fd10acb3a Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 5 Sep 2021 05:01:31 +0800 Subject: [PATCH] - feature: editor title tabbar context menu --- RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/codetemplate.cpp | 6 +++ RedPandaIDE/codetemplate.h | 11 +++++ RedPandaIDE/mainwindow.cpp | 43 ++++++++++++++------ RedPandaIDE/mainwindow.h | 3 +- RedPandaIDE/widgets/filepropertiesdialog.cpp | 10 ++--- RedPandaIDE/widgets/filepropertiesdialog.h | 4 +- 7 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 RedPandaIDE/codetemplate.cpp create mode 100644 RedPandaIDE/codetemplate.h diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index d1b7446e..6550d33c 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -17,6 +17,7 @@ SOURCES += \ autolinkmanager.cpp \ caretlist.cpp \ codeformatter.cpp \ + codetemplate.cpp \ colorscheme.cpp \ compiler/compiler.cpp \ compiler/compilermanager.cpp \ @@ -94,6 +95,7 @@ HEADERS += \ autolinkmanager.h \ caretlist.h \ codeformatter.h \ + codetemplate.h \ colorscheme.h \ compiler/compiler.h \ compiler/compilermanager.h \ diff --git a/RedPandaIDE/codetemplate.cpp b/RedPandaIDE/codetemplate.cpp new file mode 100644 index 00000000..10ac53a3 --- /dev/null +++ b/RedPandaIDE/codetemplate.cpp @@ -0,0 +1,6 @@ +#include "codetemplate.h" + +CodeTemplate::CodeTemplate() +{ + +} diff --git a/RedPandaIDE/codetemplate.h b/RedPandaIDE/codetemplate.h new file mode 100644 index 00000000..48f85d36 --- /dev/null +++ b/RedPandaIDE/codetemplate.h @@ -0,0 +1,11 @@ +#ifndef CODETEMPLATE_H +#define CODETEMPLATE_H + + +class CodeTemplate +{ +public: + CodeTemplate(); +}; + +#endif // CODETEMPLATE_H diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index aabf7535..0260341d 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1112,11 +1112,11 @@ void MainWindow::buildContextMenus() ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->watchView,&QWidget::customContextMenuRequested, this, &MainWindow::onWatchViewContextMenu); - ui->EditorTabsLeft->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->EditorTabsLeft,&QWidget::customContextMenuRequested, + ui->EditorTabsLeft->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->EditorTabsLeft->tabBar(),&QWidget::customContextMenuRequested, this, &MainWindow::onEditorTabContextMenu); - ui->EditorTabsRight->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->EditorTabsRight,&QWidget::customContextMenuRequested, + ui->EditorTabsRight->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->EditorTabsRight->tabBar(),&QWidget::customContextMenuRequested, this, &MainWindow::onEditorTabContextMenu); } @@ -1208,7 +1208,7 @@ void MainWindow::onEditorContextMenu(const QPoint &pos) return; QMenu menu(this); BufferCoord p; - mContextMenuPos = pos; + mEditorContextMenuPos = pos; if (editor->GetPositionOfMouse(p)) { //mouse on editing area menu.addAction(ui->actionCompile_Run); @@ -1256,7 +1256,21 @@ void MainWindow::onEditorContextMenu(const QPoint &pos) void MainWindow::onEditorTabContextMenu(const QPoint &pos) { + int index = ui->EditorTabsLeft->tabBar()->tabAt(pos); + if (index<0) + return; + ui->EditorTabsLeft->setCurrentIndex(index); + QMenu menu(this); + QTabBar* tabBar = ui->EditorTabsLeft->tabBar(); + menu.addAction(ui->actionClose); + menu.addAction(ui->actionClose_All); + menu.addSeparator(); + menu.addAction(ui->actionOpen_Containing_Folder); + menu.addAction(ui->actionOpen_Terminal); + menu.addSeparator(); + menu.addAction(ui->actionFile_Properties); + menu.exec(tabBar->mapToGlobal(pos)); } void MainWindow::onFileChanged(const QString &path) @@ -2256,7 +2270,7 @@ void MainWindow::on_actionToggle_Breakpoint_triggered() { Editor * editor = mEditorList->getEditor(); int line; - if (editor && editor->PointToLine(mContextMenuPos,line)) + if (editor && editor->PointToLine(mEditorContextMenuPos,line)) editor->toggleBreakpoint(line); } @@ -2280,7 +2294,7 @@ void MainWindow::on_actionBreakpoint_property_triggered() { Editor * editor = mEditorList->getEditor(); int line; - if (editor && editor->PointToLine(mContextMenuPos,line)) { + if (editor && editor->PointToLine(mEditorContextMenuPos,line)) { if (editor->hasBreakpoint(line)) editor->modifyBreakpointProperty(line); } @@ -2292,7 +2306,7 @@ void MainWindow::on_actionGoto_Declaration_triggered() { Editor * editor = mEditorList->getEditor(); BufferCoord pos; - if (editor && editor->PointToCharLine(mContextMenuPos,pos)) { + if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) { editor->gotoDeclaration(pos); } } @@ -2302,7 +2316,7 @@ void MainWindow::on_actionGoto_Definition_triggered() { Editor * editor = mEditorList->getEditor(); BufferCoord pos; - if (editor && editor->PointToCharLine(mContextMenuPos,pos)) { + if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) { editor->gotoDefinition(pos); } } @@ -2312,7 +2326,7 @@ void MainWindow::on_actionFind_references_triggered() { Editor * editor = mEditorList->getEditor(); BufferCoord pos; - if (editor && editor->PointToCharLine(mContextMenuPos,pos)) { + if (editor && editor->PointToCharLine(mEditorContextMenuPos,pos)) { CppRefacter refactor; refactor.findOccurence(editor,pos); ui->tabMessages->setCurrentWidget(ui->tabSearch); @@ -2348,8 +2362,11 @@ void MainWindow::on_actionOpen_Terminal_triggered() void MainWindow::on_actionFile_Properties_triggered() { - FilePropertiesDialog dialog(this); - dialog.exec(); - dialog.setParent(nullptr); + Editor* editor = mEditorList->getEditor(); + if (editor) { + FilePropertiesDialog dialog(editor,this); + dialog.exec(); + dialog.setParent(nullptr); + } } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 59b8d878..8496a744 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -327,8 +327,7 @@ private: bool mClosing; bool mSystemTurnedOff; - QPoint mContextMenuPos; - + QPoint mEditorContextMenuPos; // QWidget interface protected: diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index 8a349ca8..e0c16cb1 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -7,8 +7,9 @@ #include -FilePropertiesDialog::FilePropertiesDialog(QWidget *parent) : +FilePropertiesDialog::FilePropertiesDialog(Editor* activeEditor,QWidget *parent) : QDialog(parent), + mActiveEditor(activeEditor), ui(new Ui::FilePropertiesDialog) { ui->setupUi(this); @@ -36,7 +37,7 @@ void FilePropertiesDialog::calcFile(Editor *editor, for (int i=0;ilines()->count();i++) { QString line = editor->lines()->getString(i); int j=0; - while (jeditorList()->getEditor(); for (int i=0;ieditorList()->pageCount();i++) { Editor * editor = (*(pMainWindow->editorList()))[i]; - if (editor == activeEditor) { + if (editor == mActiveEditor) { ui->cbFiles->setCurrentIndex(i); break; } @@ -120,7 +120,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index) } else { ui->txtFileSize->setText(QString("%1 ").arg(fileSize / 1024.0 / 1024.0 / 1024.0)+tr("GB")); } - ui->txtFileDate->setText( info.lastModified().toString(Qt::DateFormat::LocaleDate)); + ui->txtFileDate->setText( QLocale::system().toString(info.lastModified(), QLocale::LongFormat)); ui->txtProject->setText("-"); ui->txtPath->setText(editor->filename()); ui->txtRelativeToProject->setText("_"); diff --git a/RedPandaIDE/widgets/filepropertiesdialog.h b/RedPandaIDE/widgets/filepropertiesdialog.h index d5effca7..ed1edb79 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.h +++ b/RedPandaIDE/widgets/filepropertiesdialog.h @@ -24,8 +24,9 @@ class FilePropertiesDialog : public QDialog Q_OBJECT public: - explicit FilePropertiesDialog(QWidget *parent = nullptr); + explicit FilePropertiesDialog(Editor* activeEditor,QWidget *parent = nullptr); ~FilePropertiesDialog(); + private: void calcFile(Editor* editor, int& totalLines, @@ -35,6 +36,7 @@ private: int &includeLines); private: FilePropertiesModel mModel; + Editor * mActiveEditor; private: Ui::FilePropertiesDialog *ui;