Skip to content

Commit af836c4

Browse files
committed
Add reconfirm when closing the floating window
Signed-off-by: xiaoming <[email protected]>
1 parent bba1aa5 commit af836c4

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ en-US:
1010
- Add record script feature
1111
- Add recently loaded script feature
1212
- Add disable plugin command line option
13+
- Add reconfirm when closing the floating window
1314
- Improve the default path of recording logs, etc. to the last saved path
1415
- Improve the appearance of the session tabs
1516
- Fix the small probability memory leak problem
@@ -22,6 +23,7 @@ zh-CN:
2223
- 增加记录脚本功能
2324
- 增加最近加载的脚本功能
2425
- 增加禁用插件命令行选项
26+
- 增加浮动窗口关闭时二次确认
2527
- 改进记录日志等默认路径为上次保存路径
2628
- 改进会话标签外观
2729
- 修复可能存在的小概率内存泄漏问题

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Add record script feature
1111
- Add recently loaded script feature
1212
- Add disable plugin command line option
13+
- Add reconfirm when closing the floating window
1314
- Improve the default path of recording logs, etc. to the last saved path
1415
- Improve the appearance of the session tabs
1516
- Fix the small probability memory leak problem

src/mainwindow.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,7 @@ void CentralWidget::terminalWidgetContextMenuBase(QMenu *menu,SessionsWindow *te
13751375
}
13761376

13771377
void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
1378-
QDialog *dialog = new QDialog(this);
1379-
dialog->setWindowFlags(Qt::Window);
1380-
dialog->resize(800,480);
1381-
dialog->setLayout(new QVBoxLayout);
1378+
FloatingTab *dialog = new FloatingTab(this);
13821379
MainWidgetGroup *group = new MainWidgetGroup(MainWidgetGroup::FLOATING,dialog);
13831380
mainWidgetGroupList.append(group);
13841381
int newGroup = mainWidgetGroupList.count()-1;
@@ -1402,7 +1399,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
14021399
menu->addAction(floatBackAction);
14031400
connect(floatBackAction,&QAction::triggered,this,[=](){
14041401
moveToAnotherTab(newGroup,0,1);
1405-
dialog->close();
1402+
dialog->forceClose();
14061403
});
14071404
if(menu->isEmpty()) {
14081405
delete menu;
@@ -1423,7 +1420,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
14231420
SessionsWindow *sessionsWindow = widget->property("session").value<SessionsWindow *>();
14241421
sessionsWindow->proxySendData(data);
14251422
});
1426-
connect(dialog, &QDialog::finished, this, [=](int result){
1423+
connect(dialog, &FloatingTab::finished, this, [=](int result){
14271424
MainWidgetGroup *group = mainWidgetGroupList.at(newGroup);
14281425
stopSession(group,1,true);
14291426
mainWidgetGroupList.removeAt(newGroup);

src/mainwindow.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ extern QString HASH_TAG;
7474
extern QString SHORT_HASH_TAG;
7575
extern QDateTime START_TIME;
7676

77+
class FloatingTab : public QDialog {
78+
Q_OBJECT
79+
public:
80+
explicit FloatingTab(QWidget *parent = nullptr) : QDialog(parent) {
81+
setWindowFlags(Qt::Window);
82+
resize(800,480);
83+
setLayout(new QVBoxLayout);
84+
}
85+
void forceClose(void) {
86+
doNotAskClose = true;
87+
close();
88+
}
89+
protected:
90+
void closeEvent(QCloseEvent *event) override {
91+
if(doNotAskClose) {
92+
QDialog::closeEvent(event);
93+
} else {
94+
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Close"),tr("Do you want to close this window?"),QMessageBox::Yes|QMessageBox::No);
95+
if(ret == QMessageBox::Yes) {
96+
event->accept();
97+
} else {
98+
event->ignore();
99+
}
100+
}
101+
}
102+
private:
103+
bool doNotAskClose = false;
104+
};
105+
77106
QT_BEGIN_NAMESPACE
78107
namespace Ui { class CentralWidget; }
79108
QT_END_NAMESPACE

0 commit comments

Comments
 (0)