From 079daaa6933b54117a7963ea5d2cb8daf00caf90 Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 10:06:15 +0100 Subject: Don't close editor when user cancels save dialog. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 63 ++++++++++++++++++------ src-qt5/desktop-utils/lumina-textedit/MainUI.h | 1 + 2 files changed, 49 insertions(+), 15 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index 33f2d851..e584b8b1 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -189,6 +189,18 @@ QString MainUI::currentFileDir(){ return dir; } +QStringList MainUI::unsavedFiles(){ + QStringList unsaved; + for(int i=0; icount(); i++){ + PlainTextEditor *tmp = static_cast(tabWidget->widget(i)); + if(tmp->hasChange()){ + unsaved << tmp->currentFile(); + } + } + return unsaved; +} + + // ================= // PRIVATE SLOTS //================= @@ -240,6 +252,7 @@ void MainUI::CloseFile(){ } void MainUI::SaveFile(){ + qDebug() << "SaveFile"; PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } cur->SaveFile(); @@ -494,26 +507,46 @@ PlainTextEditor *cur = currentEditor(); } } + //============= // PROTECTED //============= void MainUI::closeEvent(QCloseEvent *ev){ //See if any of the open editors have unsaved changes first - QStringList unsaved; - for(int i=0; icount(); i++){ - PlainTextEditor *tmp = static_cast(tabWidget->widget(i)); - if(tmp->hasChange()){ - unsaved << tmp->currentFile(); - } + QStringList unsaved = unsavedFiles(); + if(unsaved.isEmpty()){ + QMainWindow::closeEvent(ev); + return; } - if(unsaved.isEmpty()){ QMainWindow::closeEvent(ev); return; } - bool savenow = false; - if(!savenow && !ui->actionShow_Popups->isChecked()){ savenow = true; } - if(!savenow){ - QMessageBox::StandardButton but = QMessageBox::question(this, tr("Save Changes before closing?"), QString(tr("There are unsaved changes.\nDo you want save them before you close the editor?\n\n%1")).arg(unsaved.join("\n")), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No); - savenow = (but == QMessageBox::Yes); - if(but == QMessageBox::Cancel){ ev->ignore(); return; } - } - if(savenow){ SaveFile(); } + + //If popups are disabled, give the user a chance by opening + //the save dialog automatically, then just close. + if(!ui->actionShow_Popups->isChecked()){ + SaveFile(); QMainWindow::closeEvent(ev); + return; + } + + //Otherwise, ask the user what to do. + QMessageBox::StandardButton but = QMessageBox::question( + this, + tr("Save Changes before closing?"), + QString(tr("There are unsaved changes.\nDo you want save them before you close the editor?\n\n%1")).arg(unsaved.join("\n")), + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No); + + if(but == QMessageBox::Cancel){ + ev->ignore(); + return; + } + else if(but == QMessageBox::Yes){ + SaveFile(); + //If there are still unsaved files, the user presumably + //cancelled the save dialog and we don't want to close. + unsaved = unsavedFiles(); + if (!unsaved.isEmpty()) { + ev->ignore(); + return; + } + } + QMainWindow::closeEvent(ev); } diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h index 148974a0..008859fa 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h @@ -44,6 +44,7 @@ private: //Simplification functions PlainTextEditor* currentEditor(); QString currentFileDir(); + QStringList unsavedFiles(); private slots: //Main Actions -- cgit From 58dc3bddcf5a1ed0d94feddf0a5f4f574853108f Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 10:12:59 +0100 Subject: Remove debug print. Fix indentation. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 1 - src-qt5/desktop-utils/lumina-textedit/MainUI.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index e584b8b1..c4981ff3 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -252,7 +252,6 @@ void MainUI::CloseFile(){ } void MainUI::SaveFile(){ - qDebug() << "SaveFile"; PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } cur->SaveFile(); diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h index 008859fa..6602830a 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h @@ -44,7 +44,7 @@ private: //Simplification functions PlainTextEditor* currentEditor(); QString currentFileDir(); - QStringList unsavedFiles(); + QStringList unsavedFiles(); private slots: //Main Actions -- cgit From 4e54b03821df58ca16b26f2c5faf39fe424a96cd Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 10:23:26 +0100 Subject: Fix indentation. --- src-qt5/desktop-utils/lumina-textedit/MainUI.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h index 6602830a..8a3812a1 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h @@ -44,7 +44,7 @@ private: //Simplification functions PlainTextEditor* currentEditor(); QString currentFileDir(); - QStringList unsavedFiles(); + QStringList unsavedFiles(); private slots: //Main Actions @@ -61,7 +61,7 @@ private slots: //Other Menu Actions void UpdateHighlighting(QAction *act = 0); - void showToolbar(bool); + void showToolbar(bool); void showLineNumbers(bool); void wrapLines(bool); void ModifyColors(); -- cgit From 7e998c5d28cad0ca2ac06667087cfc2845108b31 Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 10:28:19 +0100 Subject: Whitespace consistency. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index c4981ff3..41862be2 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -200,7 +200,6 @@ QStringList MainUI::unsavedFiles(){ return unsaved; } - // ================= // PRIVATE SLOTS //================= -- cgit From b5c72fc85c750940f1315f7d4676595363cd505d Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 10:29:26 +0100 Subject: Whitespace consistency. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index 41862be2..2fe54ac9 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -505,7 +505,6 @@ PlainTextEditor *cur = currentEditor(); } } - //============= // PROTECTED //============= -- cgit From 99b8089bd11baeb17030f1f0260a83b4f2d1fe0f Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Wed, 6 Dec 2017 11:23:44 +0100 Subject: Style consistency. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index 2fe54ac9..780483f7 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -529,7 +529,8 @@ void MainUI::closeEvent(QCloseEvent *ev){ this, tr("Save Changes before closing?"), QString(tr("There are unsaved changes.\nDo you want save them before you close the editor?\n\n%1")).arg(unsaved.join("\n")), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::No); + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, + QMessageBox::No); if(but == QMessageBox::Cancel){ ev->ignore(); -- cgit