diff options
author | Ken Moore <ken@ixsystems.com> | 2017-12-06 08:50:50 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-12-06 08:50:50 -0500 |
commit | 0731b3a309f48ec0202e50d8d034b0723a20f8eb (patch) | |
tree | 19785e7eff64d3a85d9f792a00699e301820ae16 /src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | |
parent | Merge pull request #521 from ktullavik/lumina-textedit-ui (diff) | |
download | lumina-0731b3a309f48ec0202e50d8d034b0723a20f8eb.tar.gz lumina-0731b3a309f48ec0202e50d8d034b0723a20f8eb.tar.bz2 lumina-0731b3a309f48ec0202e50d8d034b0723a20f8eb.zip |
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.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-textedit/MainUI.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
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; i<tabWidget->count(); i++){ + PlainTextEditor *tmp = static_cast<PlainTextEditor*>(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); } |