summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-06-05 19:47:49 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-06-05 19:47:49 +0000
commit47181b8b9b0e3e914243a463ad02a2eceab61c6e (patch)
tree11a75ac5d5d1a4e72a60284c7a4a1b74893568db
parent45ab395c2fb42445382a377314bd63ae216f40c4 (diff)
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
-rw-r--r--utils/themeeditor/editorwindow.cpp61
-rw-r--r--utils/themeeditor/editorwindow.h5
-rw-r--r--utils/themeeditor/editorwindow.ui89
-rw-r--r--utils/themeeditor/resources.qrc3
-rw-r--r--utils/themeeditor/resources/COPYING6
-rw-r--r--utils/themeeditor/resources/document-new.pngbin0 -> 1008 bytes
-rw-r--r--utils/themeeditor/resources/document-open.pngbin0 -> 1550 bytes
-rw-r--r--utils/themeeditor/resources/document-save.pngbin0 -> 1971 bytes
-rw-r--r--utils/themeeditor/skindocument.cpp87
-rw-r--r--utils/themeeditor/skindocument.h12
-rw-r--r--utils/themeeditor/themeeditor.pro6
11 files changed, 240 insertions, 29 deletions
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<SkinDocument*>
(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<SkinDocument*>
(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<SkinDocument*>(ui->editorTabs->currentWidget())->save();
+}
+
+void EditorWindow::saveCurrentAs()
+{
+ if(ui->editorTabs->currentIndex() >= 0)
+ dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->saveAs();
+}
+
+
void EditorWindow::tabTitleChanged(QString title)
{
SkinDocument* sender = dynamic_cast<SkinDocument*>(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<SkinDocument*>
+ (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 @@
<string>Rockbox Theme Editor</string>
</property>
<property name="windowIcon">
- <iconset>
+ <iconset resource="resources.qrc">
<normaloff>:/resources/resources/windowicon.png</normaloff>:/resources/resources/windowicon.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
@@ -50,6 +50,11 @@
<addaction name="actionNew_Document"/>
<addaction name="actionOpen_Document"/>
<addaction name="separator"/>
+ <addaction name="actionClose_Document"/>
+ <addaction name="separator"/>
+ <addaction name="actionSave_Document"/>
+ <addaction name="actionSave_Document_As"/>
+ <addaction name="separator"/>
<addaction name="actionPreferences"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
@@ -91,6 +96,9 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
+ <addaction name="actionToolbarNew"/>
+ <addaction name="actionToolbarOpen"/>
+ <addaction name="actionToolbarSave"/>
</widget>
<widget class="QDockWidget" name="fileDock">
<property name="windowTitle">
@@ -147,14 +155,14 @@
<property name="text">
<string>Parse &amp;Tree Panel</string>
</property>
- <property name="shortcut">
- <string>Ctrl+D</string>
- </property>
</action>
<action name="actionPreferences">
<property name="text">
<string>&amp;Preferences</string>
</property>
+ <property name="shortcut">
+ <string>Ctrl+P</string>
+ </property>
</action>
<action name="actionFile_Panel">
<property name="checkable">
@@ -194,8 +202,79 @@
<string>Ctrl+O</string>
</property>
</action>
+ <action name="actionSave_Document">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Save Document</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
+ </property>
+ </action>
+ <action name="actionClose_Document">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Close Document</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+W</string>
+ </property>
+ </action>
+ <action name="actionSave_Document_As">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Save Document &amp;As</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+S</string>
+ </property>
+ </action>
+ <action name="actionToolbarNew">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/resources/resources/document-new.png</normaloff>:/resources/resources/document-new.png</iconset>
+ </property>
+ <property name="text">
+ <string>ToolbarNew</string>
+ </property>
+ <property name="toolTip">
+ <string>New</string>
+ </property>
+ </action>
+ <action name="actionToolbarOpen">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/resources/resources/document-open.png</normaloff>:/resources/resources/document-open.png</iconset>
+ </property>
+ <property name="text">
+ <string>ToolbarOpen</string>
+ </property>
+ <property name="toolTip">
+ <string>Open</string>
+ </property>
+ </action>
+ <action name="actionToolbarSave">
+ <property name="icon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/resources/resources/document-save.png</normaloff>:/resources/resources/document-save.png</iconset>
+ </property>
+ <property name="text">
+ <string>ToolbarSave</string>
+ </property>
+ <property name="toolTip">
+ <string>Save</string>
+ </property>
+ </action>
</widget>
- <resources/>
+ <resources>
+ <include location="resources.qrc"/>
+ </resources>
<connections>
<connection>
<sender>actionQuit</sender>
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 @@
<RCC>
<qresource prefix="/resources">
<file>resources/windowicon.png</file>
+ <file>resources/document-new.png</file>
+ <file>resources/document-open.png</file>
+ <file>resources/document-save.png</file>
</qresource>
</RCC>
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 0000000000..e6d64bb90b
--- /dev/null
+++ b/utils/themeeditor/resources/document-new.png
Binary files differ
diff --git a/utils/themeeditor/resources/document-open.png b/utils/themeeditor/resources/document-open.png
new file mode 100644
index 0000000000..f35f258354
--- /dev/null
+++ b/utils/themeeditor/resources/document-open.png
Binary files differ
diff --git a/utils/themeeditor/resources/document-save.png b/utils/themeeditor/resources/document-save.png
new file mode 100644
index 0000000000..db5c52b769
--- /dev/null
+++ b/utils/themeeditor/resources/document-save.png
Binary files differ
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 <QFileDialog>
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;
+ QString directory = fileName;
+ QSettings settings;
settings.beginGroup("SkinDocument");
- QString openDir = settings.value("defaultDirectory", "").toString();
+ if(directory == "")
+ directory = settings.value("defaultDirectory", "").toString();
+
+ fileName = QFileDialog::getSaveFileName(this, tr("Save Document"),
+ directory, fileFilter);
+ directory = fileName;
+ if(fileName == "")
+ return;
- fileName = QFileDialog::getSaveFileName(this, tr("Save File"), openDir,"");
- QString directory = fileName;
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