From 47181b8b9b0e3e914243a463ad02a2eceab61c6e Mon Sep 17 00:00:00 2001 From: Robert Bieber Date: Sat, 5 Jun 2010 19:47:49 +0000 Subject: [PATCH] Theme Editor: Got save/save-as functionality working and added Tango icons to the toolbar git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26593 a1c6a512-1295-4272-9138-f99709370657 --- utils/themeeditor/editorwindow.cpp | 61 +++++++++++- utils/themeeditor/editorwindow.h | 5 +- utils/themeeditor/editorwindow.ui | 89 ++++++++++++++++- utils/themeeditor/resources.qrc | 3 + utils/themeeditor/resources/COPYING | 6 ++ utils/themeeditor/resources/document-new.png | Bin 0 -> 1008 bytes utils/themeeditor/resources/document-open.png | Bin 0 -> 1550 bytes utils/themeeditor/resources/document-save.png | Bin 0 -> 1971 bytes utils/themeeditor/skindocument.cpp | 91 ++++++++++++++---- utils/themeeditor/skindocument.h | 12 ++- utils/themeeditor/themeeditor.pro | 6 +- 11 files changed, 242 insertions(+), 31 deletions(-) create mode 100644 utils/themeeditor/resources/COPYING create mode 100644 utils/themeeditor/resources/document-new.png create mode 100644 utils/themeeditor/resources/document-open.png create mode 100644 utils/themeeditor/resources/document-save.png diff --git a/utils/themeeditor/editorwindow.cpp b/utils/themeeditor/editorwindow.cpp index cadc6313a9..4d2ed87169 100644 --- a/utils/themeeditor/editorwindow.cpp +++ b/utils/themeeditor/editorwindow.cpp @@ -96,9 +96,22 @@ void EditorWindow::setupMenus() QObject::connect(ui->actionPreview_Panel, SIGNAL(triggered()), this, SLOT(showPanel())); - /* Connecting the document opening/closing actions */ + /* Connecting the document management actions */ QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), this, SLOT(newTab())); + QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()), + this, SLOT(newTab())); + + QObject::connect(ui->actionClose_Document, SIGNAL(triggered()), + this, SLOT(closeCurrent())); + + QObject::connect(ui->actionSave_Document, SIGNAL(triggered()), + this, SLOT(saveCurrent())); + QObject::connect(ui->actionSave_Document_As, SIGNAL(triggered()), + this, SLOT(saveCurrentAs())); + QObject::connect(ui->actionToolbarSave, SIGNAL(triggered()), + this, SLOT(saveCurrent())); + } @@ -115,13 +128,23 @@ void EditorWindow::newTab() void EditorWindow::shiftTab(int index) { if(index < 0) + { ui->parseTree->setModel(0); + ui->actionSave_Document->setEnabled(false); + ui->actionSave_Document_As->setEnabled(false); + ui->actionClose_Document->setEnabled(false); + } else + { ui->parseTree->setModel(dynamic_cast (ui->editorTabs->currentWidget())->getModel()); + ui->actionSave_Document->setEnabled(true); + ui->actionSave_Document_As->setEnabled(true); + ui->actionClose_Document->setEnabled(true); + } } -void EditorWindow::closeTab(int index) +bool EditorWindow::closeTab(int index) { SkinDocument* widget = dynamic_cast (ui->editorTabs->widget(index)); @@ -129,9 +152,30 @@ void EditorWindow::closeTab(int index) { ui->editorTabs->removeTab(index); widget->deleteLater(); + return true; } + + return false; } +void EditorWindow::closeCurrent() +{ + closeTab(ui->editorTabs->currentIndex()); +} + +void EditorWindow::saveCurrent() +{ + if(ui->editorTabs->currentIndex() >= 0) + dynamic_cast(ui->editorTabs->currentWidget())->save(); +} + +void EditorWindow::saveCurrentAs() +{ + if(ui->editorTabs->currentIndex() >= 0) + dynamic_cast(ui->editorTabs->currentWidget())->saveAs(); +} + + void EditorWindow::tabTitleChanged(QString title) { SkinDocument* sender = dynamic_cast(QObject::sender()); @@ -150,7 +194,20 @@ void EditorWindow::showPanel() void EditorWindow::closeEvent(QCloseEvent* event) { + saveSettings(); + + /* Closing all the tabs */ + for(int i = 0; i < ui->editorTabs->count(); i++) + { + if(!dynamic_cast + (ui->editorTabs->widget(i))->requestClose()) + { + event->ignore(); + return; + } + } + event->accept(); } diff --git a/utils/themeeditor/editorwindow.h b/utils/themeeditor/editorwindow.h index 52076b61a2..0febe54021 100644 --- a/utils/themeeditor/editorwindow.h +++ b/utils/themeeditor/editorwindow.h @@ -45,7 +45,10 @@ private slots: void showPanel(); void newTab(); void shiftTab(int index); - void closeTab(int index); + bool closeTab(int index); + void closeCurrent(); + void saveCurrent(); + void saveCurrentAs(); void tabTitleChanged(QString title); private: diff --git a/utils/themeeditor/editorwindow.ui b/utils/themeeditor/editorwindow.ui index b990f6eabd..21152dad75 100644 --- a/utils/themeeditor/editorwindow.ui +++ b/utils/themeeditor/editorwindow.ui @@ -14,7 +14,7 @@ Rockbox Theme Editor - + :/resources/resources/windowicon.png:/resources/resources/windowicon.png @@ -50,6 +50,11 @@ + + + + + @@ -91,6 +96,9 @@ false + + + @@ -147,14 +155,14 @@ Parse &Tree Panel - - Ctrl+D - &Preferences + + Ctrl+P + @@ -194,8 +202,79 @@ Ctrl+O + + + false + + + &Save Document + + + Ctrl+S + + + + + false + + + &Close Document + + + Ctrl+W + + + + + false + + + Save Document &As + + + Ctrl+Shift+S + + + + + + :/resources/resources/document-new.png:/resources/resources/document-new.png + + + ToolbarNew + + + New + + + + + + :/resources/resources/document-open.png:/resources/resources/document-open.png + + + ToolbarOpen + + + Open + + + + + + :/resources/resources/document-save.png:/resources/resources/document-save.png + + + ToolbarSave + + + Save + + - + + + actionQuit diff --git a/utils/themeeditor/resources.qrc b/utils/themeeditor/resources.qrc index fbe5cfbb01..b882e23a1d 100644 --- a/utils/themeeditor/resources.qrc +++ b/utils/themeeditor/resources.qrc @@ -1,5 +1,8 @@ resources/windowicon.png + resources/document-new.png + resources/document-open.png + resources/document-save.png diff --git a/utils/themeeditor/resources/COPYING b/utils/themeeditor/resources/COPYING new file mode 100644 index 0000000000..02389762b0 --- /dev/null +++ b/utils/themeeditor/resources/COPYING @@ -0,0 +1,6 @@ +The files appicon.xcf and windowicon.png are authored by Robert Bieber, and +made available in the public domain. + +The files document-new.png, document-open.png, and document-save.png came from +the Tango Desktop Project (http://www.tango.freedesktop.org) and are also in +the public domain. diff --git a/utils/themeeditor/resources/document-new.png b/utils/themeeditor/resources/document-new.png new file mode 100644 index 0000000000000000000000000000000000000000..e6d64bb90b32dfec83232de6478afc1a6b335b8f GIT binary patch literal 1008 zcmV9&7>1-t%; zZoBM??ke>U^dD4er7kL=hDJeZLn7jm5(v08gqI)OnbXC!k+JW?xKusTXl69mbH4MM z@xcEq@?UJK$`~hw1@dkN7mNd7!v<|zXR5g`LOT&)eSQ72TrT&mh?I;m7-R6>>yxk%nY!jFra=|`UYN$jJFw$o6!Q~hf9-+XQxm0cZ zJOI$ON<^+(?>q^>$`OG*B(MkM>^|0nAkF)!0Ktc~6Mw%ewATx-0 z2=>Fy#)6oaAmto-RYqh2Z%eTNabbvae=k5%Xre;9nY`Cxo3Q|K&2t~+0bbw5`9+*Bg4+i7q|>%JJZgfrw$XMK(PuKxMWP1) zmY0{W>pwdb1w8NJv=RMSizu_;qj``kQ{8>c()+Ea(0)p>xdkyNp>qyZjjXz5Nh%eb zJ_06CKaG(SAOf&5#fzQa`ScU_6UFA1NR%C^9_W{0asp;?Orsp*IYRUtB#$=>{POGf z$mGS7-aUt|f-L1XOD{mFpjwHh3d#hRje(RK4xrbrCP4qK*Ol9z4QaP$ zB0w01u}ZUm;sE+(Xb;3G&N>H11xP%I05&!@FlI1uh6OanWah@e?qL{S$7*F|CG}!T zQk>+WI7tmb|J9u4iTE=iTT(+XjMA*NEST6TNGiioz`DnJl8oemyOdkq1z9qR=SBkP zt&A)XRZRu!2Phk3PF1yBE|(FB-UUGr{Oh~`$mjECz&vmawE6)`KxJ=l@5|NI)h|Rk zFN(X9=I-w9SHJ>bfdjzz`fv=G1MUG+ow>a$ literal 0 HcmV?d00001 diff --git a/utils/themeeditor/resources/document-open.png b/utils/themeeditor/resources/document-open.png new file mode 100644 index 0000000000000000000000000000000000000000..f35f2583540678b7a544d9175245096082f302af GIT binary patch literal 1550 zcmV+p2J!icP)x2@7Ze~uNfga3vbZE9GEM?G2QWwx$l|aG!6EBtvokxp zvoq5l)m6n|XM1OQW{kx~$|IHPv)|{b_kF9YL=;7Qme9AeD9aOny9T9{E~r#qPhztg z1VQi60-DXH_~GhP{O0)=sMqT=*LlCEvE6RV7hihev3LLe?mJnMeJ2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{!;dz%bNu9K2D3TV-ZGQk_s@~b4)b7VGoI(+ z`#!$!69fTLN|aJ)t#MtK#fukXS=N>b0PEJRtF5lCUe(ahfa5qQrO4;=0F;-Phs8)K zg;I*ja>)I7TwnnTagQ*8Z8 z8&j(iM59sS@i@t3l4LT8=Xp4egOm~}C6P!3r4$PnF0{4Q_rrxcAcVNPy}cdRb*Zhb zC7aDMGBSb?f*=UOwq;o)lSyFg{NJ2T^ShrkP*H9pr9^9u)_N>ov<}~qQj$ugsIIQ2 zzrUZ3jt=(j-Fpx4<5D5|Ofs2dWMqW1XV0RwM#{1Duq-PysI?CBq12Dr;QRgr&&6Uf zg!s=rXN)1A&*L}_T5G0EnS$2(hR_2*%=0{K+YVnGe*u-AC8*2IkDn{)__!Lx;nJhw6?b5c^)k-Effj`nwy((9EYZ+ zCUUtPsZ^?T)QKKi3?iBCBB+Ir34qW0OT(K@o!k3U4Q?i+IRo}002ovPDHLk FV1jL*$BzI2 literal 0 HcmV?d00001 diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index 8617030180..3fb7d4871b 100644 --- a/utils/themeeditor/skindocument.cpp +++ b/utils/themeeditor/skindocument.cpp @@ -28,13 +28,18 @@ #include SkinDocument::SkinDocument(QWidget *parent) : - QWidget(parent) + QWidget(parent), fileFilter(tr("WPS Files (*.wps *.rwps);;" + "SBS Files (*.sbs *.rsbs);;" + "FMS Files (*.fms *.rfms);;" + "All Skin Files (*.wps *.rwps *.sbs " + "*.rsbs *.fms *.rfms);;" + "All Files (*.*)")) { setupUI(); title = "Untitled"; fileName = ""; - saved = true; + saved = ""; } SkinDocument::~SkinDocument() @@ -45,7 +50,35 @@ SkinDocument::~SkinDocument() bool SkinDocument::requestClose() { - saveAs(); + if(editor->document()->toPlainText() != saved) + { + /* Spawning the "Are you sure?" dialog */ + QMessageBox confirm(this); + confirm.setText(title + tr(" has been modified.")); + confirm.setInformativeText(tr("Do you want to save your changes?")); + confirm.setStandardButtons(QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + confirm.setDefaultButton(QMessageBox::Save); + int confirmation = confirm.exec(); + + switch(confirmation) + { + case QMessageBox::Save: + save(); + /* After calling save, make sure the user actually went through */ + if(editor->document()->toPlainText() != saved) + return false; + else + return true; + + case QMessageBox::Discard: + return true; + + case QMessageBox::Cancel: + return false; + } + } + return true; } @@ -74,11 +107,22 @@ void SkinDocument::setupUI() void SkinDocument::codeChanged() { model->changeTree(editor->document()->toPlainText().toAscii()); - if(saved == true) + + if(editor->document()->toPlainText() != saved) { - saved = false; - title.append(tr("*")); - emit titleChanged(title); + if(title.length() > 0 && title[title.length() - 1] != '*') + { + title.append('*'); + emit titleChanged(title); + } + } + else + { + if(title.length() > 0 && title[title.length() - 1] == '*') + { + title.chop(1); + emit titleChanged(title); + } } } @@ -88,7 +132,7 @@ void SkinDocument::save() if(!fout.exists()) { - QTimer::singleShot(0, this, SLOT(saveAs())); + saveAs(); return; } @@ -96,22 +140,31 @@ void SkinDocument::save() fout.write(editor->document()->toPlainText().toAscii()); fout.close(); - saved = true; + saved = editor->document()->toPlainText(); + QStringList decompose = fileName.split('/'); + title = decompose[decompose.count() - 1]; + emit titleChanged(title); + } void SkinDocument::saveAs() { /* Determining the directory to open */ - QSettings settings; - - settings.beginGroup("SkinDocument"); - QString openDir = settings.value("defaultDirectory", "").toString(); - - fileName = QFileDialog::getSaveFileName(this, tr("Save File"), openDir,""); QString directory = fileName; + + QSettings settings; + settings.beginGroup("SkinDocument"); + if(directory == "") + directory = settings.value("defaultDirectory", "").toString(); + + fileName = QFileDialog::getSaveFileName(this, tr("Save Document"), + directory, fileFilter); + directory = fileName; + if(fileName == "") + return; + directory.chop(fileName.length() - fileName.lastIndexOf('/') - 1); settings.setValue("defaultDirectory", directory); - settings.endGroup(); QFile fout(fileName); @@ -119,5 +172,9 @@ void SkinDocument::saveAs() fout.write(editor->document()->toPlainText().toAscii()); fout.close(); - saved = true; + saved = editor->document()->toPlainText(); + QStringList decompose = fileName.split('/'); + title = decompose[decompose.count() - 1]; + emit titleChanged(title); + } diff --git a/utils/themeeditor/skindocument.h b/utils/themeeditor/skindocument.h index 37f1443ece..d00c81f36b 100644 --- a/utils/themeeditor/skindocument.h +++ b/utils/themeeditor/skindocument.h @@ -33,21 +33,23 @@ class SkinDocument : public QWidget { Q_OBJECT public: + const QString fileFilter; + + SkinDocument(QWidget *parent = 0); virtual ~SkinDocument(); ParseTreeModel* getModel(){ return model; } QString getTitle(){ return title; } + void save(); + void saveAs(); + bool requestClose(); signals: void titleChanged(QString); -public slots: - void save(); - void saveAs(); - private slots: void codeChanged(); @@ -56,7 +58,7 @@ private: QString title; QString fileName; - bool saved; + QString saved; QLayout* layout; QPlainTextEdit* editor; diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro index 19d9205d7b..ef32a3e56e 100644 --- a/utils/themeeditor/themeeditor.pro +++ b/utils/themeeditor/themeeditor.pro @@ -26,6 +26,10 @@ SOURCES += tag_table.c \ skindocument.cpp OTHER_FILES += README \ resources/windowicon.png \ - resources/appicon.xcf + resources/appicon.xcf \ + resources/COPYING \ + resources/document-save.png \ + resources/document-open.png \ + resources/document-new.png FORMS += editorwindow.ui RESOURCES += resources.qrc