aboutsummaryrefslogtreecommitdiff
path: root/desktop-utilities
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2016-04-15 21:53:05 -0400
committerKen Moore <moorekou@gmail.com>2016-04-15 21:53:05 -0400
commitaabc57d793c6709717b6adcbfd3923fdd2f63f2c (patch)
treec34dbd72fd3afc314fee18f3445e48b60f0af745 /desktop-utilities
parentAdd a bunch more work on the new lumina-textedit. Putting the tabbed-wrapper ... (diff)
downloadlumina-aabc57d793c6709717b6adcbfd3923fdd2f63f2c.tar.gz
lumina-aabc57d793c6709717b6adcbfd3923fdd2f63f2c.tar.bz2
lumina-aabc57d793c6709717b6adcbfd3923fdd2f63f2c.zip
Some more updates to lumina-textedit: Starting to get the buttons all hooked up and functional.
Diffstat (limited to 'desktop-utilities')
-rw-r--r--desktop-utilities/lumina-textedit/MainUI.cpp67
-rw-r--r--desktop-utilities/lumina-textedit/MainUI.h4
-rw-r--r--desktop-utilities/lumina-textedit/PlainTextEditor.cpp16
-rw-r--r--desktop-utilities/lumina-textedit/PlainTextEditor.h4
4 files changed, 75 insertions, 16 deletions
diff --git a/desktop-utilities/lumina-textedit/MainUI.cpp b/desktop-utilities/lumina-textedit/MainUI.cpp
index 71469030..eae57f6e 100644
--- a/desktop-utilities/lumina-textedit/MainUI.cpp
+++ b/desktop-utilities/lumina-textedit/MainUI.cpp
@@ -11,6 +11,9 @@
#include <LuminaXDG.h>
+#include <QFileDialog>
+#include <QDir>
+
MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
ui->setupUi(this);
this->setWindowTitle(tr("Text Editor"));
@@ -39,16 +42,21 @@ void MainUI::LoadArguments(QStringList args){ //CLI arguments
}
- if(ui->tabWidget->count()<1){
+ /*if(ui->tabWidget->count()<1){
NewFile();
- }
+ }*/
}
// =================
// PUBLIC SLOTS
//=================
void MainUI::updateIcons(){
- ui->actionClose->setIcon(LXDG::findIcon("action-close") );
+ ui->actionClose->setIcon(LXDG::findIcon("application-exit") );
+ ui->actionNew_File->setIcon(LXDG::findIcon("document-new") );
+ ui->actionOpen_File->setIcon(LXDG::findIcon("document-open") );
+ ui->actionSave_File->setIcon(LXDG::findIcon("document-save") );
+ ui->actionSave_File_As->setIcon(LXDG::findIcon("document-save-as") );
+ ui->menuSyntax_Highlighting->setIcon( LXDG::findIcon("format-text-color") );
}
@@ -60,6 +68,17 @@ PlainTextEditor* MainUI::currentEditor(){
return static_cast<PlainTextEditor*>( ui->tabWidget->currentWidget() );
}
+QString MainUI::currentFileDir(){
+ PlainTextEditor* cur = currentEditor();
+ QString dir;
+ if(cur!=0){
+ if(cur->currentFile().startsWith("/")){
+ dir = cur->currentFile().section("/",0,-2);
+ }
+ }
+ return dir;
+}
+
// =================
// PRIVATE SLOTS
//=================
@@ -69,24 +88,37 @@ void MainUI::NewFile(){
}
void MainUI::OpenFile(QString file){
+ QStringList files;
if(file.isEmpty()){
//Prompt for a file to open
-
+ files = QFileDialog::getOpenFileNames(this, tr("Open File(s)"), currentFileDir(), tr("Text Files (*)") );
+ if(files.isEmpty()){ return; } //cancelled
+ }else{
+ files << file;
+ }
+ for(int i=0; i<files.length(); i++){
+ PlainTextEditor *edit = new PlainTextEditor(this);
+ connect(edit, SIGNAL(FileLoaded(QString)), this, SLOT(updateTab(QString)) );
+ connect(edit, SIGNAL(UnsavedChanges(QString)), this, SLOT(updateTab(QString)) );
+ ui->tabWidget->addTab(edit, files[i].section("/",-1));
+ edit->showLineNumbers(ui->actionLine_Numbers->isChecked());
+ ui->tabWidget->setCurrentWidget(edit);
+ edit->LoadFile(files[i]);
+ edit->setFocus();
+ QApplication::processEvents(); //to catch the fileLoaded() signal
}
- if(file.isEmpty()){ return; }
- PlainTextEditor *edit = new PlainTextEditor(this);
- ui->tabWidget->addTab(edit, file.section("/",-1));
- edit->showLineNumbers(ui->actionLine_Numbers->isChecked());
- edit->LoadFile(file);
- ui->tabWidget->setCurrentWidget(edit);
}
void MainUI::SaveFile(){
-
+ PlainTextEditor *cur = currentEditor();
+ if(cur==0){ return; }
+ cur->SaveFile();
}
void MainUI::SaveFileAs(){
-
+ PlainTextEditor *cur = currentEditor();
+ if(cur==0){ return; }
+ cur->SaveFile(true);
}
void MainUI::UpdateHighlighting(QAction *act){
@@ -94,3 +126,14 @@ void MainUI::UpdateHighlighting(QAction *act){
if(cur==0){ return; }
cur->LoadSyntaxRule(act->text());
}
+
+void MainUI::updateTab(QString file){
+ PlainTextEditor *cur = currentEditor();
+ if(cur==0){ return; } //should never happen
+ int index = ui->tabWidget->currentIndex();
+ if(index<0){ index = 0; } //FALLBACK - use the first tab
+ bool changes = cur->hasChange();
+ ui->tabWidget->setTabText(index,(changes ? "*" : "") + file.section("/",-1));
+ ui->actionSave_File->setEnabled(changes);
+ ui->actionSave_File_As->setEnabled(changes);
+} \ No newline at end of file
diff --git a/desktop-utilities/lumina-textedit/MainUI.h b/desktop-utilities/lumina-textedit/MainUI.h
index 6ded613b..7db77433 100644
--- a/desktop-utilities/lumina-textedit/MainUI.h
+++ b/desktop-utilities/lumina-textedit/MainUI.h
@@ -29,8 +29,10 @@ public slots:
private:
Ui::MainUI *ui;
+
//Simplification functions
PlainTextEditor* currentEditor();
+ QString currentFileDir();
private slots:
//Main Actions
@@ -39,6 +41,8 @@ private slots:
void SaveFile();
void SaveFileAs();
void UpdateHighlighting(QAction*);
+ //Tab Interactions
+ void updateTab(QString);
};
#endif \ No newline at end of file
diff --git a/desktop-utilities/lumina-textedit/PlainTextEditor.cpp b/desktop-utilities/lumina-textedit/PlainTextEditor.cpp
index 92e42cf7..51bb2ed5 100644
--- a/desktop-utilities/lumina-textedit/PlainTextEditor.cpp
+++ b/desktop-utilities/lumina-textedit/PlainTextEditor.cpp
@@ -9,6 +9,7 @@
#include <QColor>
#include <QPainter>
#include <QTextBlock>
+#include <QFileDialog>
#include <LuminaUtils.h>
@@ -52,21 +53,30 @@ void PlainTextEditor::LoadFile(QString filepath){
SYNTAX->loadRules( Custom_Syntax::ruleForFile(filepath.section("/",-1)) );
this->setPlainText( LUtils::readFile(filepath).join("\n") );
hasChanges = false;
+ emit FileLoaded(this->whatsThis());
}
-void PlainTextEditor::SaveFile(){
- if( !this->whatsThis().startsWith("/") ){
+void PlainTextEditor::SaveFile(bool newname){
+ 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; }
+ else{ this->setWhatsThis(file); }
}
bool ok = LUtils::writeFile(this->whatsThis(), this->toPlainText().split("\n"), true);
if(ok){ emit FileLoaded(this->whatsThis()); }
+ SYNTAX->loadRules( Custom_Syntax::ruleForFile(this->whatsThis().section("/",-1)) );
+ SYNTAX->rehighlight();
}
QString PlainTextEditor::currentFile(){
return this->whatsThis();
}
+bool PlainTextEditor::hasChange(){
+ return hasChanges;
+}
+
//Functions for managing the line number widget
int PlainTextEditor::LNWWidth(){
//Get the number of chars we need for line numbers
diff --git a/desktop-utilities/lumina-textedit/PlainTextEditor.h b/desktop-utilities/lumina-textedit/PlainTextEditor.h
index 291f09aa..e90243dd 100644
--- a/desktop-utilities/lumina-textedit/PlainTextEditor.h
+++ b/desktop-utilities/lumina-textedit/PlainTextEditor.h
@@ -27,9 +27,11 @@ public:
//File loading/setting options
void LoadFile(QString filepath);
- void SaveFile();
+ void SaveFile(bool newname = false);
QString currentFile();
+ bool hasChange();
+
//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
bgstack15