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.cpp22
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.h3
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp17
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.h8
4 files changed, 41 insertions, 9 deletions
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; i<tabWidget->count(); i++){
+ for(int i=0; i<tabWidget->count() && ok; i++){
PlainTextEditor *tmp = static_cast<PlainTextEditor*>(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 <QShortcut>
#include <QFontComboBox>
#include <QSpinBox>
+#include <QAction>
+#include <QApplication>
#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);
bgstack15