aboutsummaryrefslogtreecommitdiff
path: root/src-qt5
diff options
context:
space:
mode:
authorKen Moore <ken@ixsystems.com>2017-12-06 08:30:33 -0500
committerGitHub <noreply@github.com>2017-12-06 08:30:33 -0500
commit665e10420ffb17caf003a852bc96a09f186440a1 (patch)
tree8633a6a2b2abf9d02bb7880fa0ded5a3d714babe /src-qt5
parentRename the OSInterface files according to the new format ("framework-*") (diff)
parentStyle consistency. (diff)
downloadlumina-665e10420ffb17caf003a852bc96a09f186440a1.tar.gz
lumina-665e10420ffb17caf003a852bc96a09f186440a1.tar.bz2
lumina-665e10420ffb17caf003a852bc96a09f186440a1.zip
Merge pull request #521 from ktullavik/lumina-textedit-ui
Don't close editor when user cancels save dialog.
Diffstat (limited to 'src-qt5')
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.cpp61
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.h3
2 files changed, 48 insertions, 16 deletions
diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
index 33f2d851..780483f7 100644
--- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
@@ -189,6 +189,17 @@ QString MainUI::currentFileDir(){
return dir;
}
+QStringList MainUI::unsavedFiles(){
+ QStringList unsaved;
+ for(int i=0; i<tabWidget->count(); i++){
+ PlainTextEditor *tmp = static_cast<PlainTextEditor*>(tabWidget->widget(i));
+ if(tmp->hasChange()){
+ unsaved << tmp->currentFile();
+ }
+ }
+ return unsaved;
+}
+
// =================
// PRIVATE SLOTS
//=================
@@ -499,21 +510,41 @@ PlainTextEditor *cur = currentEditor();
//=============
void MainUI::closeEvent(QCloseEvent *ev){
//See if any of the open editors have unsaved changes first
- QStringList unsaved;
- for(int i=0; i<tabWidget->count(); i++){
- PlainTextEditor *tmp = static_cast<PlainTextEditor*>(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..8a3812a1 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
@@ -60,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();
bgstack15