diff options
author | Ken Moore <ken@ixsystems.com> | 2017-12-06 09:28:30 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2017-12-06 09:28:30 -0500 |
commit | eee843173b5f1f3d7e7d7fc1a822f0e735378d38 (patch) | |
tree | be35a325172c4656f617b5ea7941724b71ec4536 /src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp | |
parent | Make sure that on closing, it attempts to save *all* files with pending changes. (diff) | |
download | lumina-eee843173b5f1f3d7e7d7fc1a822f0e735378d38.tar.gz lumina-eee843173b5f1f3d7e7d7fc1a822f0e735378d38.tar.bz2 lumina-eee843173b5f1f3d7e7d7fc1a822f0e735378d38.zip |
Add better handling of read-only files in LTE.
Diffstat (limited to 'src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp')
-rw-r--r-- | src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
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 |