aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.cpp40
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.h5
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp10
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h8
4 files changed, 35 insertions, 28 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);
}
diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h
index 8a3812a1..5d10f21b 100644
--- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h
+++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h
@@ -51,8 +51,9 @@ private slots:
void NewFile();
void OpenFile(QString file = "");
void CloseFile(); //current file only
- void SaveFile();
- void SaveFileAs();
+ bool SaveFile();
+ bool SaveFileAs();
+ bool SaveAllFiles();
void Print();
void fontChanged(const QFont &font);
void updateStatusTip();
diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp
index 653bd0e8..6e04d67b 100644
--- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp
+++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp
@@ -103,12 +103,17 @@ void PlainTextEditor::LoadFile(QString filepath){
emit FileLoaded(this->whatsThis());
}
-void PlainTextEditor::SaveFile(bool newname){
+bool PlainTextEditor::SaveFile(bool newname){
+ //NOTE: This returns true for proper behaviour, and false for a user-cancelled process
//qDebug() << "Save File:" << this->whatsThis();
+ //Quick check for a non-editable file
+ if(!newname && this->whatsThis().startsWith("/")){
+ if(!QFileInfo(this->whatsThis()).isWritable()){ newname = true; } //cannot save the current file name/location
+ }
if( !this->whatsThis().startsWith("/") || newname ){
//prompt for a filename/path
QString file = QFileDialog::getSaveFileName(this, tr("Save File"), this->whatsThis(), tr("Text File (*)"));
- if(file.isEmpty()){ return; }
+ if(file.isEmpty()){ return false; } //cancelled
this->setWhatsThis(file);
SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) );
SYNTAX->rehighlight();
@@ -118,6 +123,7 @@ void PlainTextEditor::SaveFile(bool newname){
hasChanges = !ok;
if(ok){ lastSaveContents = this->toPlainText(); emit FileLoaded(this->whatsThis()); }
watcher->addPath(currentFile());
+ return true;
//qDebug() << " - Success:" << ok << hasChanges;
}
diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h
index 0c83b7ce..ec6c6bf7 100644
--- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h
+++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h
@@ -21,7 +21,7 @@ class PlainTextEditor : public QPlainTextEdit{
public:
PlainTextEditor(QSettings *set, QWidget *parent = 0);
~PlainTextEditor();
-
+
//Functions for setting up the editor
void showLineNumbers(bool show = true);
void LoadSyntaxRule(QString type);
@@ -29,7 +29,7 @@ public:
//File loading/setting options
void LoadFile(QString filepath);
- void SaveFile(bool newname = false);
+ bool SaveFile(bool newname = false);
QString currentFile();
bool hasChange();
@@ -37,10 +37,10 @@ public:
//Functions for managing the line number widget (internal - do not need to run directly)
int LNWWidth(); //replacing the LNW size hint detection
void paintLNW(QPaintEvent *ev); //forwarded from the LNW paint event
- void updateLNW();
+ void updateLNW();
QFontMetrics *metrics;
-
+
private:
QWidget *LNW; //Line Number Widget
bool showLNW;
bgstack15