Skip to content

Commit

Permalink
Add reconfirm when closing the floating window
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Sep 19, 2024
1 parent bba1aa5 commit af836c4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en-US:
- Add record script feature
- Add recently loaded script feature
- Add disable plugin command line option
- Add reconfirm when closing the floating window
- Improve the default path of recording logs, etc. to the last saved path
- Improve the appearance of the session tabs
- Fix the small probability memory leak problem
Expand All @@ -22,6 +23,7 @@ zh-CN:
- 增加记录脚本功能
- 增加最近加载的脚本功能
- 增加禁用插件命令行选项
- 增加浮动窗口关闭时二次确认
- 改进记录日志等默认路径为上次保存路径
- 改进会话标签外观
- 修复可能存在的小概率内存泄漏问题
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add record script feature
- Add recently loaded script feature
- Add disable plugin command line option
- Add reconfirm when closing the floating window
- Improve the default path of recording logs, etc. to the last saved path
- Improve the appearance of the session tabs
- Fix the small probability memory leak problem
Expand Down
9 changes: 3 additions & 6 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,7 @@ void CentralWidget::terminalWidgetContextMenuBase(QMenu *menu,SessionsWindow *te
}

void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
QDialog *dialog = new QDialog(this);
dialog->setWindowFlags(Qt::Window);
dialog->resize(800,480);
dialog->setLayout(new QVBoxLayout);
FloatingTab *dialog = new FloatingTab(this);
MainWidgetGroup *group = new MainWidgetGroup(MainWidgetGroup::FLOATING,dialog);
mainWidgetGroupList.append(group);
int newGroup = mainWidgetGroupList.count()-1;
Expand All @@ -1402,7 +1399,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
menu->addAction(floatBackAction);
connect(floatBackAction,&QAction::triggered,this,[=](){
moveToAnotherTab(newGroup,0,1);
dialog->close();
dialog->forceClose();
});
if(menu->isEmpty()) {
delete menu;
Expand All @@ -1423,7 +1420,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) {
SessionsWindow *sessionsWindow = widget->property("session").value<SessionsWindow *>();
sessionsWindow->proxySendData(data);
});
connect(dialog, &QDialog::finished, this, [=](int result){
connect(dialog, &FloatingTab::finished, this, [=](int result){
MainWidgetGroup *group = mainWidgetGroupList.at(newGroup);
stopSession(group,1,true);
mainWidgetGroupList.removeAt(newGroup);
Expand Down
29 changes: 29 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ extern QString HASH_TAG;
extern QString SHORT_HASH_TAG;
extern QDateTime START_TIME;

class FloatingTab : public QDialog {
Q_OBJECT
public:
explicit FloatingTab(QWidget *parent = nullptr) : QDialog(parent) {
setWindowFlags(Qt::Window);
resize(800,480);
setLayout(new QVBoxLayout);
}
void forceClose(void) {
doNotAskClose = true;
close();
}
protected:
void closeEvent(QCloseEvent *event) override {
if(doNotAskClose) {
QDialog::closeEvent(event);
} else {
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Close"),tr("Do you want to close this window?"),QMessageBox::Yes|QMessageBox::No);
if(ret == QMessageBox::Yes) {
event->accept();
} else {
event->ignore();
}
}
}
private:
bool doNotAskClose = false;
};

QT_BEGIN_NAMESPACE
namespace Ui { class CentralWidget; }
QT_END_NAMESPACE
Expand Down

0 comments on commit af836c4

Please sign in to comment.