From 0731b3a309f48ec0202e50d8d034b0723a20f8eb Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 6 Dec 2017 08:50:50 -0500 Subject: Make sure that on closing, it attempts to save *all* files with pending changes. If popup warnings are disabled just close the app (never automatically change the underlying file(s) - this can be disastrous) Add status reporting to all the "Save" functions so that it returns false if the user cancelled it. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 40 ++++++++++++------------ 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit/MainUI.cpp') diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp index 780483f7..e626023c 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -250,16 +250,26 @@ void MainUI::CloseFile(){ if(index>=0){ tabClosed(index); } } -void MainUI::SaveFile(){ +bool MainUI::SaveFile(){ PlainTextEditor *cur = currentEditor(); - if(cur==0){ return; } - cur->SaveFile(); + if(cur==0){ return true; } //nothing to do + return cur->SaveFile(); } -void MainUI::SaveFileAs(){ +bool MainUI::SaveFileAs(){ PlainTextEditor *cur = currentEditor(); - if(cur==0){ return; } - cur->SaveFile(true); + if(cur==0){ return true; } //nothing to do + return cur->SaveFile(true); +} + +bool MainUI::SaveAllFiles(){ + bool ok = true; + for(int i=0; icount(); i++){ + PlainTextEditor *tmp = static_cast(tabWidget->widget(i)); + if(tmp->hasChange()){ + ok = ok && tmp->SaveFile(); + } + } } void MainUI::Print() { @@ -511,15 +521,7 @@ PlainTextEditor *cur = currentEditor(); void MainUI::closeEvent(QCloseEvent *ev){ //See if any of the open editors have unsaved changes first QStringList unsaved = unsavedFiles(); - if(unsaved.isEmpty()){ - QMainWindow::closeEvent(ev); - return; - } - - //If popups are disabled, give the user a chance by opening - //the save dialog automatically, then just close. - if(!ui->actionShow_Popups->isChecked()){ - SaveFile(); + if(unsaved.isEmpty() || !ui->actionShow_Popups->isChecked()){ QMainWindow::closeEvent(ev); return; } @@ -537,14 +539,12 @@ void MainUI::closeEvent(QCloseEvent *ev){ 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()) { + if( !SaveAllFiles() ){ + //cancelled by user ev->ignore(); return; } + } QMainWindow::closeEvent(ev); } -- cgit