From a00b2a73d918c80645a51a57a1cb40c3ff3f09e1 Mon Sep 17 00:00:00 2001 From: Andreas Müller Date: Mon, 27 Nov 2017 17:18:29 +0100 Subject: manpages: fix out of tree install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes e.g: | gzip: lumina-info.1: No such file or directory Signed-off-by: Andreas Müller --- src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro b/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro index a9c16a0c..c5733ee7 100644 --- a/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro +++ b/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro @@ -103,7 +103,7 @@ syntax.path=$${L_SHAREDIR}/lumina-desktop/syntax_rules syntax.files=syntax_rules/* manpage.path=$${L_MANDIR}/man1/ -manpage.extra="$${MAN_ZIP} lumina-textedit.1 > $(INSTALL_ROOT)$${L_MANDIR}/man1/lumina-textedit.1.gz" +manpage.extra="$${MAN_ZIP} $$PWD/lumina-textedit.1 > $(INSTALL_ROOT)$${L_MANDIR}/man1/lumina-textedit.1.gz" INSTALLS += target desktop link syntax manpage -- cgit From d574947799c0a38b88a05387e04e1cf98c06fa89 Mon Sep 17 00:00:00 2001 From: Andreas Müller Date: Mon, 27 Nov 2017 17:37:59 +0100 Subject: i18n: fix out of tree build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes e.g: | /bin/sh: line 0: cd: i18n: No such file or directory | Makefile:955: recipe for target 'install_dotrans' failed | make[3]: *** [install_dotrans] Error 1 Signed-off-by: Andreas Müller --- src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro b/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro index c5733ee7..77cd8798 100644 --- a/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro +++ b/src-qt5/desktop-utils/lumina-textedit/lumina-textedit.pro @@ -91,7 +91,7 @@ TRANSLATIONS = i18n/l-te_af.ts \ i18n/l-te_zu.ts dotrans.path=$${L_SHAREDIR}/lumina-desktop/i18n/ -dotrans.extra=cd i18n && $${LRELEASE} -nounfinished *.ts && cp *.qm $(INSTALL_ROOT)$${L_SHAREDIR}/lumina-desktop/i18n/ +dotrans.extra=cd $$PWD/i18n && $${LRELEASE} -nounfinished *.ts && cp *.qm $(INSTALL_ROOT)$${L_SHAREDIR}/lumina-desktop/i18n/ desktop.files=lumina-textedit.desktop desktop.path=$${L_SHAREDIR}/applications/ -- cgit From 52d29fe416a3e41caf750889f7b9fcff637c2b94 Mon Sep 17 00:00:00 2001 From: Kjell Tore Ullavik Date: Thu, 30 Nov 2017 04:15:34 +0100 Subject: Add 'Show Toolbar' to textedit menu. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 10 ++++++++++ src-qt5/desktop-utils/lumina-textedit/MainUI.h | 1 + src-qt5/desktop-utils/lumina-textedit/MainUI.ui | 14 +++++++++++++- 3 files changed, 24 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 9e4ce499..33f2d851 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -72,6 +72,10 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ for(int i=0; imenuSyntax_Highlighting->addAction(smodes[i]); } + + bool toolbarVisible = settings->value("showToolbar",true).toBool(); + ui->toolBar->setHidden(!toolbarVisible); + ui->actionShow_Toolbar->setChecked(toolbarVisible); ui->actionLine_Numbers->setChecked( settings->value("showLineNumbers",true).toBool() ); ui->actionWrap_Lines->setChecked( settings->value("wrapLines",true).toBool() ); ui->actionShow_Popups->setChecked( settings->value("showPopupWarnings",true).toBool() ); @@ -96,6 +100,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(tabWidget->dndTabBar(), SIGNAL(DetachTab(int)), this, SLOT(tabDetached(int)) ); connect(tabWidget->dndTabBar(), SIGNAL(DroppedIn(QStringList)), this, SLOT(LoadArguments(QStringList)) ); connect(tabWidget->dndTabBar(), SIGNAL(DraggedOut(int, Qt::DropAction)), this, SLOT(tabDraggedOut(int, Qt::DropAction)) ); + connect(ui->actionShow_Toolbar, SIGNAL(toggled(bool)), this, SLOT(showToolbar(bool)) ); connect(ui->actionLine_Numbers, SIGNAL(toggled(bool)), this, SLOT(showLineNumbers(bool)) ); connect(ui->actionWrap_Lines, SIGNAL(toggled(bool)), this, SLOT(wrapLines(bool)) ); connect(ui->actionShow_Popups, SIGNAL(toggled(bool)), this, SLOT(showPopupWarnings(bool)) ); @@ -337,6 +342,11 @@ void MainUI::showPopupWarnings(bool show){ settings->setValue("showPopupWarnings",show); } +void MainUI::showToolbar(bool show){ + settings->setValue("showToolbar",show); + ui->toolBar->setHidden(!show); +} + void MainUI::updateTab(QString file){ PlainTextEditor *cur = 0; int index = -1; diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h index 6e5d2d23..148974a0 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h @@ -60,6 +60,7 @@ private slots: //Other Menu Actions void UpdateHighlighting(QAction *act = 0); + void showToolbar(bool); void showLineNumbers(bool); void wrapLines(bool); void ModifyColors(); diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.ui b/src-qt5/desktop-utils/lumina-textedit/MainUI.ui index 026521b3..f88f3976 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.ui +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.ui @@ -182,7 +182,7 @@ 0 0 505 - 28 + 24 @@ -224,6 +224,7 @@ + @@ -436,6 +437,17 @@ Ctrl+P + + + true + + + true + + + Show Toolbar + + line_find -- cgit 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 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 +++++++++++----------- src-qt5/desktop-utils/lumina-textedit/MainUI.h | 5 +-- .../lumina-textedit/PlainTextEditor.cpp | 10 ++++-- .../lumina-textedit/PlainTextEditor.h | 8 ++--- 4 files changed, 35 insertions(+), 28 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 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); } 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; -- cgit From eee843173b5f1f3d7e7d7fc1a822f0e735378d38 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Wed, 6 Dec 2017 09:28:30 -0500 Subject: Add better handling of read-only files in LTE. --- src-qt5/desktop-utils/lumina-textedit/MainUI.cpp | 22 ++++++++++++++++++---- src-qt5/desktop-utils/lumina-textedit/MainUI.h | 3 +++ .../lumina-textedit/PlainTextEditor.cpp | 17 +++++++++++++++-- .../lumina-textedit/PlainTextEditor.h | 8 +++++--- 4 files changed, 41 insertions(+), 9 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 e626023c..bdb9d29c 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp @@ -29,15 +29,26 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ fontbox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QWidget *spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + QWidget *spacer2 = new QWidget(this); + spacer2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + label_readonly = new QAction(tr("Read-Only File"), this); + label_readonly->setEnabled(false); //not an actual button + label_readonly->setToolTip(""); + QFont fnt = this->font(); + fnt.setItalic(true); + fnt.setBold(true); + label_readonly->setFont(fnt); fontSizes = new QSpinBox(this); fontSizes->setRange(5, 72); - fontSizes->setValue(9); + fontSizes->setValue(this->font().pointSize()); fontSizes->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); //For some reason, the FontComboBox is always 2 pixels taller than the SpinBox - manually fix that here - fontbox->setFixedHeight(30); - fontSizes->setFixedHeight(32); + fontbox->setFixedHeight(ui->toolBar->iconSize().height()-2); + fontSizes->setFixedHeight(ui->toolBar->iconSize().height()); ui->toolBar->addWidget(spacer); + ui->toolBar->addAction(label_readonly); + ui->toolBar->addWidget(spacer2); ui->toolBar->addWidget(fontbox); ui->toolBar->addWidget(fontSizes); //Load the special Drag and Drop QTabWidget @@ -264,12 +275,13 @@ bool MainUI::SaveFileAs(){ bool MainUI::SaveAllFiles(){ bool ok = true; - for(int i=0; icount(); i++){ + for(int i=0; icount() && ok; i++){ PlainTextEditor *tmp = static_cast(tabWidget->widget(i)); if(tmp->hasChange()){ ok = ok && tmp->SaveFile(); } } + return ok; } void MainUI::Print() { @@ -387,6 +399,7 @@ void MainUI::updateTab(QString file){ tabWidget->setTabWhatsThis(index, file); //needed for drag/drop functionality ui->actionSave_File->setEnabled(changes); this->setWindowTitle( (changes ? "*" : "") + file.section("/",-2) ); + label_readonly->setVisible( cur->readOnlyFile() ); } void MainUI::tabChanged(){ @@ -404,6 +417,7 @@ void MainUI::tabChanged(){ fontbox->setCurrentFont(font); fontSizes->setValue( font.pointSize() ); ui->actionWrap_Lines->setChecked( cur->lineWrapMode()==QPlainTextEdit::WidgetWidth ); + label_readonly->setVisible( cur->readOnlyFile() ); } void MainUI::tabClosed(int tab){ diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h index 5d10f21b..464e7a52 100644 --- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h +++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "PlainTextEditor.h" #include "ColorDialog.h" @@ -40,6 +42,7 @@ private: QSettings *settings; QShortcut *closeFindS; QSpinBox *fontSizes; + QAction *label_readonly; //Simplification functions PlainTextEditor* currentEditor(); diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 6e04d67b..8626b2b4 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -24,7 +24,7 @@ PlainTextEditor::PlainTextEditor(QSettings *set, QWidget *parent) : QPlainTextEd LNW = new LNWidget(this); showLNW = true; watcher = new QFileSystemWatcher(this); - hasChanges = false; + hasChanges = readonly = false; lastSaveContents.clear(); matchleft = matchright = -1; this->setTabStopWidth( 8 * this->fontMetrics().width(" ") ); //8 character spaces per tab (UNIX standard) @@ -99,7 +99,14 @@ void PlainTextEditor::LoadFile(QString filepath){ this->centerCursor(); //scroll until cursor is centered (if possible) } hasChanges = false; - if(QFile::exists(filepath)){ watcher->addPath(filepath); } + readonly = false; + if(QFile::exists(filepath)){ + readonly = !QFileInfo(filepath).isWritable(); + watcher->addPath(filepath); + }else if(filepath.startsWith("/")){ + //See if the containing directory is writable instead + readonly = !QFileInfo(filepath.section("/",0,-2)).isWritable(); + } emit FileLoaded(this->whatsThis()); } @@ -117,6 +124,7 @@ bool PlainTextEditor::SaveFile(bool newname){ this->setWhatsThis(file); SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); SYNTAX->rehighlight(); + readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag } if( !watcher->files().isEmpty() ){ watcher->removePaths(watcher->files()); } bool ok = LUtils::writeFile(this->whatsThis(), this->toPlainText().split("\n"), true); @@ -135,6 +143,11 @@ bool PlainTextEditor::hasChange(){ return hasChanges; } +bool PlainTextEditor::readOnlyFile(){ + //qDebug() << "Read Only File:" << readonly << this->whatsThis(); + return readonly; +} + //Functions for managing the line number widget int PlainTextEditor::LNWWidth(){ //Get the number of chars we need for line numbers diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h index ec6c6bf7..b0a6cbc7 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h @@ -33,6 +33,7 @@ public: QString currentFile(); bool hasChange(); + bool readOnlyFile(); //Functions for managing the line number widget (internal - do not need to run directly) int LNWWidth(); //replacing the LNW size hint detection @@ -55,8 +56,9 @@ private: void clearMatchData(); void highlightMatch(QChar ch, bool forward, int fromPos, QChar startch); - //Flags to keep track of changes - bool hasChanges; + //Flags to keep track of changes/status + bool hasChanges, readonly; + private slots: //Functions for managing the line number widget void LNW_updateWidth(); // Tied to the QPlainTextEdit::blockCountChanged() signal @@ -68,7 +70,7 @@ private slots: void textChanged(); void cursorMoved(); //Function for prompting the user if the file changed externally - void fileChanged(); + void fileChanged(); protected: void resizeEvent(QResizeEvent *ev); -- cgit From 16e6402abdc43b64467682c370237eb60f031af0 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 28 Dec 2017 10:17:02 -0500 Subject: Quick update to lumina-textedit: 1. Add a new syntax highlighting "meta" option for auto-selecting a ruleset based on the first line of text in the file, and add rules for shell, json, and python to support first-line matches. 2. Fix up the detection of "read-only" property on newly-saved files. --- .../desktop-utils/lumina-textedit/PlainTextEditor.cpp | 15 ++++++++++++--- src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp | 17 +++++++++++++++++ src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h | 8 +++++++- .../lumina-textedit/syntax_rules/README.md | 4 +++- .../lumina-textedit/syntax_rules/json.syntax | 3 ++- .../lumina-textedit/syntax_rules/python.syntax | 3 ++- .../lumina-textedit/syntax_rules/sh.syntax | 3 ++- 7 files changed, 45 insertions(+), 8 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-textedit') diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 8626b2b4..b1592cc3 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -76,17 +76,22 @@ void PlainTextEditor::LoadFile(QString filepath){ bool diffFile = (filepath != this->whatsThis()); this->setWhatsThis(filepath); this->clear(); - QList files = SyntaxFile::availableFiles(settings); + /*QList files = SyntaxFile::availableFiles(settings); for(int i=0; iloadRules(files[i]); break; } - } + }*/ //SYNTAX->loadRules( Custom_Syntax::ruleForFile(filepath.section("/",-1), settings) ); lastSaveContents = LUtils::readFile(filepath).join("\n"); if(diffFile){ + SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( lastSaveContents.section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); this->setPlainText( lastSaveContents ); }else{ //Try to keep the mouse cursor/scroll in the same position @@ -123,14 +128,18 @@ bool PlainTextEditor::SaveFile(bool newname){ if(file.isEmpty()){ return false; } //cancelled this->setWhatsThis(file); SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1), settings) ); + if(SYNTAX->loadedRules().isEmpty()){ + SYNTAX->loadRules( Custom_Syntax::ruleForFirstLine( this->toPlainText().section("\n",0,0,QString::SectionSkipEmpty) , settings) ); + } + SYNTAX->setupDocument(this); SYNTAX->rehighlight(); - readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag } if( !watcher->files().isEmpty() ){ watcher->removePaths(watcher->files()); } bool ok = LUtils::writeFile(this->whatsThis(), this->toPlainText().split("\n"), true); hasChanges = !ok; if(ok){ lastSaveContents = this->toPlainText(); emit FileLoaded(this->whatsThis()); } watcher->addPath(currentFile()); + readonly = !QFileInfo(this->whatsThis()).isWritable(); //update this flag return true; //qDebug() << " - Success:" << ok << hasChanges; } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 53f51f4e..a80d4149 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -83,6 +83,16 @@ bool SyntaxFile::supportsFile(QString file){ return false; } +bool SyntaxFile::supportsFirstLine(QString line){ + line = line.simplified(); + if(metaObj.contains("first_line_match")){ + return metaObj.value("first_line_match").toArray().contains(line); + }else if(metaObj.contains("first_line_regex")){ + return (QRegExp( metaObj.value("first_line_regex").toString() ).indexIn(line) >=0 ); + } + return false; +} + bool SyntaxFile::LoadFile(QString file, QSettings *settings){ QStringList contents = LUtils::readFile(file); //Now trim the extra non-JSON off the beginning of the file @@ -209,6 +219,13 @@ QString Custom_Syntax::ruleForFile(QString filename, QSettings *settings){ return ""; } +QString Custom_Syntax::ruleForFirstLine(QString line, QSettings *settings){ + QList files = SyntaxFile::availableFiles(settings); + for(int i=0; i files = SyntaxFile::availableFiles(settings); diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h index bffbfd1a..9949a90c 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.h @@ -46,6 +46,7 @@ public: void SetupDocument(QPlainTextEdit *editor); bool supportsFile(QString file); //does this syntax set support the file? + bool supportsFirstLine(QString line); //is the type of file defined by the first line of the file? ("#!/bin/" for instance) //Main Loading routine (run this before other functions) bool LoadFile(QString file, QSettings *settings); @@ -66,10 +67,13 @@ public: } ~Custom_Syntax(){} + QString loadedRules(){ return syntax.name(); } + static QStringList availableRules(QSettings *settings); static QStringList knownColors(); static void SetupDefaultColors(QSettings *settings); static QString ruleForFile(QString filename, QSettings *settings); + static QString ruleForFirstLine(QString line, QSettings *settings); void loadRules(QString type); void loadRules(SyntaxFile sfile); @@ -77,6 +81,8 @@ public: loadRules( syntax.name() ); } + void setupDocument(QPlainTextEdit *edit){ syntax.SetupDocument(edit); } //simple redirect for the function in the currently-loaded rules + protected: void highlightBlock(const QString &text){ //qDebug() << "Highlight Block:" << text; @@ -159,7 +165,7 @@ protected: int last = text.length()-1; while(last>=0 && (text[last]==' ' || text[last]=='\t' ) ){ last--; } if(last < text.length()-1){ - setFormat(last+1, text.length()-1-last, fmt); + setFormat(last+1, text.length()-1-last, fmt); } } } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md index fa00b557..04190672 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/README.md @@ -9,9 +9,11 @@ A small comment section may be placed at the top of the file where every line st # Requirements 1. A "meta" object containing the following variables (meta information about the rules): 1. "name" : The name that will be shown to the user for this set of syntax rules. - 2. If this syntax file is to be automatically applied to particular file type, then one of the following options must be set: + 2. If this syntax file is to be automatically applied to particular file type, then at least one of the following options must be set: 1. "file_suffix" : An array of file extensions which are supported by this syntax rule set (Example: temp.foo will be matched by "file_suffix"=["foo"] ) 2. "file_regex" : A regular expression which should be used to find if the filename matches this rule set. + 3. "first_line_match" : *(only used if no filename rules matched)* Exact match for the first line of text in the file (Example: "#!/bin/sh") + 4. "first_line_regex" : *(only used if no filename rules matched)* Regular expression to use when find a match for the first line of text in the file 2. A "format" object containing the following variables (file-wide formatting): 1. "columns_per_line" : (integer, optional) For file formats with line-length restrictions, this will automatically highlight/flag any "overage" of the designated limit. 2. "highlight_whitespace_eol" : (boolian, optional) Highlight any excess whitespace at the end of a line. diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax index ab67d384..1982e599 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/json.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "JSON", - "file_suffix": ["json", "syntax"] + "file_suffix": ["json", "syntax"], + "first_line_match":["{"] }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax index 6690d98c..2145beec 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/python.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Python", - "file_suffix": ["py", "pyc"] + "file_suffix": ["py", "pyc"], + "first_line_regex" : "(#!).+(python)" }, "format": { "line_wrap": false, diff --git a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax index 5f38cadc..f2256731 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax +++ b/src-qt5/desktop-utils/lumina-textedit/syntax_rules/sh.syntax @@ -8,7 +8,8 @@ { "meta": { "name": "Shell", - "file_suffix": ["sh"] + "file_suffix": ["sh"], + "first_line_match":["#!/bin/sh", "#!/sbin/openrc-run"] }, "format": { "line_wrap": false, -- cgit