From 71725f4d7b526160387cdef487f2aa3725b0a592 Mon Sep 17 00:00:00 2001 From: bieber Date: Sat, 5 Jun 2010 08:22:30 +0000 Subject: [PATCH] Theme Editor: Got document title change signal working, beginning work on save function git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26567 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 10 ++++++++++ utils/themeeditor/editorwindow.h | 1 + utils/themeeditor/skindocument.cpp | 35 +++++++++++++++++++++++++++++++++++ utils/themeeditor/skindocument.h | 7 +++++++ 4 files changed, 53 insertions(+) diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index a2fc11afd..cadc6313a 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -106,6 +106,10 @@ void EditorWindow::newTab() { SkinDocument* doc = new SkinDocument; ui->editorTabs->addTab(doc, doc->getTitle()); + + /* Connecting to title change events */ + QObject::connect(doc, SIGNAL(titleChanged(QString)), + this, SLOT(tabTitleChanged(QString))); } void EditorWindow::shiftTab(int index) @@ -128,6 +132,12 @@ void EditorWindow::closeTab(int index) } } +void EditorWindow::tabTitleChanged(QString title) +{ + SkinDocument* sender = dynamic_cast(QObject::sender()); + ui->editorTabs->setTabText(ui->editorTabs->indexOf(sender), title); +} + void EditorWindow::showPanel() { if(sender() == ui->actionFile_Panel) diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index 1c02bb378..52076b61a 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -46,6 +46,7 @@ private slots: void newTab(); void shiftTab(int index); void closeTab(int index); + void tabTitleChanged(QString title); private: /* Setup functions */ diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index 5391f9155..2e4f6f464 100644 --- a/utils/themeeditor/skindocument.cpp +++ b/utils/themeeditor/skindocument.cpp @@ -21,12 +21,18 @@ #include "skindocument.h" +#include +#include +#include + SkinDocument::SkinDocument(QWidget *parent) : QWidget(parent) { setupUI(); title = "Untitled"; + fileName = ""; + saved = true; } SkinDocument::~SkinDocument() @@ -65,4 +71,33 @@ void SkinDocument::setupUI() void SkinDocument::codeChanged() { model->changeTree(editor->document()->toPlainText().toAscii()); + if(saved == true) + { + saved = false; + title.append(tr("*")); + emit titleChanged(title); + } +} + +void SkinDocument::save() +{ + QFile fout(fileName); + + if(!fout.exists()) + { + QTimer::singleShot(0, this, SLOT(saveAs())); + return; + } + + fout.open(QFile::WriteOnly); + fout.write(editor->document()->toPlainText().toAscii()); + fout.close(); + + saved = true; +} + +void SkinDocument::saveAs() +{ + /* Determining the directory to open */ + } diff --git a/utils/themeeditor/skindocument.h b/utils/themeeditor/skindocument.h index e15dd613f..37f1443ec 100644 --- a/utils/themeeditor/skindocument.h +++ b/utils/themeeditor/skindocument.h @@ -42,6 +42,11 @@ public: bool requestClose(); signals: + void titleChanged(QString); + +public slots: + void save(); + void saveAs(); private slots: void codeChanged(); @@ -50,6 +55,8 @@ private: void setupUI(); QString title; + QString fileName; + bool saved; QLayout* layout; QPlainTextEdit* editor; -- 2.11.4.GIT