diff --git a/NEWS.md b/NEWS.md index 61e860fe..4703a440 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,6 +19,7 @@ Red Panda C++ Version 1.0.0 - fix: when no selection, copy/cut should auto select whole line with the line break - fix: redo cut with no selection while make whole line selected - fix: correctly reset caret when redo cut with no selection + - enhancement: close editor when middle button clicked on it's title tab Red Panda C++ Version 0.14.5 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 00743edd..2d7a6f6f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -335,6 +335,12 @@ MainWindow::MainWindow(QWidget *parent) ui->actionEGE_Manual->setVisible(pSettings->environment().language()=="zh_CN"); + connect(ui->EditorTabsLeft, &EditorsTabWidget::middleButtonClicked, + this, &MainWindow::on_EditorTabsLeft_tabCloseRequested); + + connect(ui->EditorTabsRight, &EditorsTabWidget::middleButtonClicked, + this, &MainWindow::on_EditorTabsRight_tabCloseRequested); + //git menu connect(ui->menuGit, &QMenu::aboutToShow, this, &MainWindow::updateVCSActions); diff --git a/RedPandaIDE/widgets/editorstabwidget.cpp b/RedPandaIDE/widgets/editorstabwidget.cpp index 05add55c..f1aed1fd 100644 --- a/RedPandaIDE/widgets/editorstabwidget.cpp +++ b/RedPandaIDE/widgets/editorstabwidget.cpp @@ -55,3 +55,13 @@ void EditorsTabWidget::dragEnterEvent(QDragEnterEvent *event) event->acceptProposedAction(); } } + +void EditorsTabWidget::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() == Qt::MiddleButton) { + int idx = this->tabBar()->tabAt(event->pos()); + if (idx>=0) + emit middleButtonClicked(idx); + } + QTabWidget::mousePressEvent(event); +} diff --git a/RedPandaIDE/widgets/editorstabwidget.h b/RedPandaIDE/widgets/editorstabwidget.h index 0ec74eaa..463af9ad 100644 --- a/RedPandaIDE/widgets/editorstabwidget.h +++ b/RedPandaIDE/widgets/editorstabwidget.h @@ -28,10 +28,16 @@ class EditorsTabWidget : public QTabWidget public: explicit EditorsTabWidget(QWidget* parent=nullptr); +signals: + void middleButtonClicked(int index); // QWidget interface protected: void dropEvent(QDropEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override; + + // QWidget interface +protected: + void mousePressEvent(QMouseEvent *event) override; }; #endif // EDITORSTABWIDGET_H