summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-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()
96 QObject::connect(ui->actionPreview_Panel, SIGNAL(triggered()), 96 QObject::connect(ui->actionPreview_Panel, SIGNAL(triggered()),
97 this, SLOT(showPanel())); 97 this, SLOT(showPanel()));
98 98
99 /* Connecting the document opening/closing actions */ 99 /* Connecting the document management actions */
100 QObject::connect(ui->actionNew_Document, SIGNAL(triggered()), 100 QObject::connect(ui->actionNew_Document, SIGNAL(triggered()),
101 this, SLOT(newTab())); 101 this, SLOT(newTab()));
102 QObject::connect(ui->actionToolbarNew, SIGNAL(triggered()),
103 this, SLOT(newTab()));
104
105 QObject::connect(ui->actionClose_Document, SIGNAL(triggered()),
106 this, SLOT(closeCurrent()));
107
108 QObject::connect(ui->actionSave_Document, SIGNAL(triggered()),
109 this, SLOT(saveCurrent()));
110 QObject::connect(ui->actionSave_Document_As, SIGNAL(triggered()),
111 this, SLOT(saveCurrentAs()));
112 QObject::connect(ui->actionToolbarSave, SIGNAL(triggered()),
113 this, SLOT(saveCurrent()));
114
102} 115}
103 116
104 117
@@ -115,13 +128,23 @@ void EditorWindow::newTab()
115void EditorWindow::shiftTab(int index) 128void EditorWindow::shiftTab(int index)
116{ 129{
117 if(index < 0) 130 if(index < 0)
131 {
118 ui->parseTree->setModel(0); 132 ui->parseTree->setModel(0);
133 ui->actionSave_Document->setEnabled(false);
134 ui->actionSave_Document_As->setEnabled(false);
135 ui->actionClose_Document->setEnabled(false);
136 }
119 else 137 else
138 {
120 ui->parseTree->setModel(dynamic_cast<SkinDocument*> 139 ui->parseTree->setModel(dynamic_cast<SkinDocument*>
121 (ui->editorTabs->currentWidget())->getModel()); 140 (ui->editorTabs->currentWidget())->getModel());
141 ui->actionSave_Document->setEnabled(true);
142 ui->actionSave_Document_As->setEnabled(true);
143 ui->actionClose_Document->setEnabled(true);
144 }
122} 145}
123 146
124void EditorWindow::closeTab(int index) 147bool EditorWindow::closeTab(int index)
125{ 148{
126 SkinDocument* widget = dynamic_cast<SkinDocument*> 149 SkinDocument* widget = dynamic_cast<SkinDocument*>
127 (ui->editorTabs->widget(index)); 150 (ui->editorTabs->widget(index));
@@ -129,9 +152,30 @@ void EditorWindow::closeTab(int index)
129 { 152 {
130 ui->editorTabs->removeTab(index); 153 ui->editorTabs->removeTab(index);
131 widget->deleteLater(); 154 widget->deleteLater();
155 return true;
132 } 156 }
157
158 return false;
159}
160
161void EditorWindow::closeCurrent()
162{
163 closeTab(ui->editorTabs->currentIndex());
133} 164}
134 165
166void EditorWindow::saveCurrent()
167{
168 if(ui->editorTabs->currentIndex() >= 0)
169 dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->save();
170}
171
172void EditorWindow::saveCurrentAs()
173{
174 if(ui->editorTabs->currentIndex() >= 0)
175 dynamic_cast<SkinDocument*>(ui->editorTabs->currentWidget())->saveAs();
176}
177
178
135void EditorWindow::tabTitleChanged(QString title) 179void EditorWindow::tabTitleChanged(QString title)
136{ 180{
137 SkinDocument* sender = dynamic_cast<SkinDocument*>(QObject::sender()); 181 SkinDocument* sender = dynamic_cast<SkinDocument*>(QObject::sender());
@@ -150,7 +194,20 @@ void EditorWindow::showPanel()
150 194
151void EditorWindow::closeEvent(QCloseEvent* event) 195void EditorWindow::closeEvent(QCloseEvent* event)
152{ 196{
197
153 saveSettings(); 198 saveSettings();
199
200 /* Closing all the tabs */
201 for(int i = 0; i < ui->editorTabs->count(); i++)
202 {
203 if(!dynamic_cast<SkinDocument*>
204 (ui->editorTabs->widget(i))->requestClose())
205 {
206 event->ignore();
207 return;
208 }
209 }
210
154 event->accept(); 211 event->accept();
155} 212}
156 213
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:
45 void showPanel(); 45 void showPanel();
46 void newTab(); 46 void newTab();
47 void shiftTab(int index); 47 void shiftTab(int index);
48 void closeTab(int index); 48 bool closeTab(int index);
49 void closeCurrent();
50 void saveCurrent();
51 void saveCurrentAs();
49 void tabTitleChanged(QString title); 52 void tabTitleChanged(QString title);
50 53
51private: 54private:
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 @@
14 <string>Rockbox Theme Editor</string> 14 <string>Rockbox Theme Editor</string>
15 </property> 15 </property>
16 <property name="windowIcon"> 16 <property name="windowIcon">
17 <iconset> 17 <iconset resource="resources.qrc">
18 <normaloff>:/resources/resources/windowicon.png</normaloff>:/resources/resources/windowicon.png</iconset> 18 <normaloff>:/resources/resources/windowicon.png</normaloff>:/resources/resources/windowicon.png</iconset>
19 </property> 19 </property>
20 <widget class="QWidget" name="centralwidget"> 20 <widget class="QWidget" name="centralwidget">
@@ -50,6 +50,11 @@
50 <addaction name="actionNew_Document"/> 50 <addaction name="actionNew_Document"/>
51 <addaction name="actionOpen_Document"/> 51 <addaction name="actionOpen_Document"/>
52 <addaction name="separator"/> 52 <addaction name="separator"/>
53 <addaction name="actionClose_Document"/>
54 <addaction name="separator"/>
55 <addaction name="actionSave_Document"/>
56 <addaction name="actionSave_Document_As"/>
57 <addaction name="separator"/>
53 <addaction name="actionPreferences"/> 58 <addaction name="actionPreferences"/>
54 <addaction name="separator"/> 59 <addaction name="separator"/>
55 <addaction name="actionQuit"/> 60 <addaction name="actionQuit"/>
@@ -91,6 +96,9 @@
91 <attribute name="toolBarBreak"> 96 <attribute name="toolBarBreak">
92 <bool>false</bool> 97 <bool>false</bool>
93 </attribute> 98 </attribute>
99 <addaction name="actionToolbarNew"/>
100 <addaction name="actionToolbarOpen"/>
101 <addaction name="actionToolbarSave"/>
94 </widget> 102 </widget>
95 <widget class="QDockWidget" name="fileDock"> 103 <widget class="QDockWidget" name="fileDock">
96 <property name="windowTitle"> 104 <property name="windowTitle">
@@ -147,14 +155,14 @@
147 <property name="text"> 155 <property name="text">
148 <string>Parse &amp;Tree Panel</string> 156 <string>Parse &amp;Tree Panel</string>
149 </property> 157 </property>
150 <property name="shortcut">
151 <string>Ctrl+D</string>
152 </property>
153 </action> 158 </action>
154 <action name="actionPreferences"> 159 <action name="actionPreferences">
155 <property name="text"> 160 <property name="text">
156 <string>&amp;Preferences</string> 161 <string>&amp;Preferences</string>
157 </property> 162 </property>
163 <property name="shortcut">
164 <string>Ctrl+P</string>
165 </property>
158 </action> 166 </action>
159 <action name="actionFile_Panel"> 167 <action name="actionFile_Panel">
160 <property name="checkable"> 168 <property name="checkable">
@@ -194,8 +202,79 @@
194 <string>Ctrl+O</string> 202 <string>Ctrl+O</string>
195 </property> 203 </property>
196 </action> 204 </action>
205 <action name="actionSave_Document">
206 <property name="enabled">
207 <bool>false</bool>
208 </property>
209 <property name="text">
210 <string>&amp;Save Document</string>
211 </property>
212 <property name="shortcut">
213 <string>Ctrl+S</string>
214 </property>
215 </action>
216 <action name="actionClose_Document">
217 <property name="enabled">
218 <bool>false</bool>
219 </property>
220 <property name="text">
221 <string>&amp;Close Document</string>
222 </property>
223 <property name="shortcut">
224 <string>Ctrl+W</string>
225 </property>
226 </action>
227 <action name="actionSave_Document_As">
228 <property name="enabled">
229 <bool>false</bool>
230 </property>
231 <property name="text">
232 <string>Save Document &amp;As</string>
233 </property>
234 <property name="shortcut">
235 <string>Ctrl+Shift+S</string>
236 </property>
237 </action>
238 <action name="actionToolbarNew">
239 <property name="icon">
240 <iconset resource="resources.qrc">
241 <normaloff>:/resources/resources/document-new.png</normaloff>:/resources/resources/document-new.png</iconset>
242 </property>
243 <property name="text">
244 <string>ToolbarNew</string>
245 </property>
246 <property name="toolTip">
247 <string>New</string>
248 </property>
249 </action>
250 <action name="actionToolbarOpen">
251 <property name="icon">
252 <iconset resource="resources.qrc">
253 <normaloff>:/resources/resources/document-open.png</normaloff>:/resources/resources/document-open.png</iconset>
254 </property>
255 <property name="text">
256 <string>ToolbarOpen</string>
257 </property>
258 <property name="toolTip">
259 <string>Open</string>
260 </property>
261 </action>
262 <action name="actionToolbarSave">
263 <property name="icon">
264 <iconset resource="resources.qrc">
265 <normaloff>:/resources/resources/document-save.png</normaloff>:/resources/resources/document-save.png</iconset>
266 </property>
267 <property name="text">
268 <string>ToolbarSave</string>
269 </property>
270 <property name="toolTip">
271 <string>Save</string>
272 </property>
273 </action>
197 </widget> 274 </widget>
198 <resources/> 275 <resources>
276 <include location="resources.qrc"/>
277 </resources>
199 <connections> 278 <connections>
200 <connection> 279 <connection>
201 <sender>actionQuit</sender> 280 <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 @@
1<RCC> 1<RCC>
2 <qresource prefix="/resources"> 2 <qresource prefix="/resources">
3 <file>resources/windowicon.png</file> 3 <file>resources/windowicon.png</file>
4 <file>resources/document-new.png</file>
5 <file>resources/document-open.png</file>
6 <file>resources/document-save.png</file>
4 </qresource> 7 </qresource>
5</RCC> 8</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 @@
1The files appicon.xcf and windowicon.png are authored by Robert Bieber, and
2made available in the public domain.
3
4The files document-new.png, document-open.png, and document-save.png came from
5the Tango Desktop Project (http://www.tango.freedesktop.org) and are also in
6the 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 @@
28#include <QFileDialog> 28#include <QFileDialog>
29 29
30SkinDocument::SkinDocument(QWidget *parent) : 30SkinDocument::SkinDocument(QWidget *parent) :
31 QWidget(parent) 31 QWidget(parent), fileFilter(tr("WPS Files (*.wps *.rwps);;"
32 "SBS Files (*.sbs *.rsbs);;"
33 "FMS Files (*.fms *.rfms);;"
34 "All Skin Files (*.wps *.rwps *.sbs "
35 "*.rsbs *.fms *.rfms);;"
36 "All Files (*.*)"))
32{ 37{
33 setupUI(); 38 setupUI();
34 39
35 title = "Untitled"; 40 title = "Untitled";
36 fileName = ""; 41 fileName = "";
37 saved = true; 42 saved = "";
38} 43}
39 44
40SkinDocument::~SkinDocument() 45SkinDocument::~SkinDocument()
@@ -45,7 +50,35 @@ SkinDocument::~SkinDocument()
45 50
46bool SkinDocument::requestClose() 51bool SkinDocument::requestClose()
47{ 52{
48 saveAs(); 53 if(editor->document()->toPlainText() != saved)
54 {
55 /* Spawning the "Are you sure?" dialog */
56 QMessageBox confirm(this);
57 confirm.setText(title + tr(" has been modified."));
58 confirm.setInformativeText(tr("Do you want to save your changes?"));
59 confirm.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
60 | QMessageBox::Cancel);
61 confirm.setDefaultButton(QMessageBox::Save);
62 int confirmation = confirm.exec();
63
64 switch(confirmation)
65 {
66 case QMessageBox::Save:
67 save();
68 /* After calling save, make sure the user actually went through */
69 if(editor->document()->toPlainText() != saved)
70 return false;
71 else
72 return true;
73
74 case QMessageBox::Discard:
75 return true;
76
77 case QMessageBox::Cancel:
78 return false;
79 }
80 }
81
49 return true; 82 return true;
50} 83}
51 84
@@ -74,11 +107,22 @@ void SkinDocument::setupUI()
74void SkinDocument::codeChanged() 107void SkinDocument::codeChanged()
75{ 108{
76 model->changeTree(editor->document()->toPlainText().toAscii()); 109 model->changeTree(editor->document()->toPlainText().toAscii());
77 if(saved == true) 110
111 if(editor->document()->toPlainText() != saved)
78 { 112 {
79 saved = false; 113 if(title.length() > 0 && title[title.length() - 1] != '*')
80 title.append(tr("*")); 114 {
81 emit titleChanged(title); 115 title.append('*');
116 emit titleChanged(title);
117 }
118 }
119 else
120 {
121 if(title.length() > 0 && title[title.length() - 1] == '*')
122 {
123 title.chop(1);
124 emit titleChanged(title);
125 }
82 } 126 }
83} 127}
84 128
@@ -88,7 +132,7 @@ void SkinDocument::save()
88 132
89 if(!fout.exists()) 133 if(!fout.exists())
90 { 134 {
91 QTimer::singleShot(0, this, SLOT(saveAs())); 135 saveAs();
92 return; 136 return;
93 } 137 }
94 138
@@ -96,22 +140,31 @@ void SkinDocument::save()
96 fout.write(editor->document()->toPlainText().toAscii()); 140 fout.write(editor->document()->toPlainText().toAscii());
97 fout.close(); 141 fout.close();
98 142
99 saved = true; 143 saved = editor->document()->toPlainText();
144 QStringList decompose = fileName.split('/');
145 title = decompose[decompose.count() - 1];
146 emit titleChanged(title);
147
100} 148}
101 149
102void SkinDocument::saveAs() 150void SkinDocument::saveAs()
103{ 151{
104 /* Determining the directory to open */ 152 /* Determining the directory to open */
105 QSettings settings; 153 QString directory = fileName;
106 154
155 QSettings settings;
107 settings.beginGroup("SkinDocument"); 156 settings.beginGroup("SkinDocument");
108 QString openDir = settings.value("defaultDirectory", "").toString(); 157 if(directory == "")
158 directory = settings.value("defaultDirectory", "").toString();
159
160 fileName = QFileDialog::getSaveFileName(this, tr("Save Document"),
161 directory, fileFilter);
162 directory = fileName;
163 if(fileName == "")
164 return;
109 165
110 fileName = QFileDialog::getSaveFileName(this, tr("Save File"), openDir,"");
111 QString directory = fileName;
112 directory.chop(fileName.length() - fileName.lastIndexOf('/') - 1); 166 directory.chop(fileName.length() - fileName.lastIndexOf('/') - 1);
113 settings.setValue("defaultDirectory", directory); 167 settings.setValue("defaultDirectory", directory);
114
115 settings.endGroup(); 168 settings.endGroup();
116 169
117 QFile fout(fileName); 170 QFile fout(fileName);
@@ -119,5 +172,9 @@ void SkinDocument::saveAs()
119 fout.write(editor->document()->toPlainText().toAscii()); 172 fout.write(editor->document()->toPlainText().toAscii());
120 fout.close(); 173 fout.close();
121 174
122 saved = true; 175 saved = editor->document()->toPlainText();
176 QStringList decompose = fileName.split('/');
177 title = decompose[decompose.count() - 1];
178 emit titleChanged(title);
179
123} 180}
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
33{ 33{
34Q_OBJECT 34Q_OBJECT
35public: 35public:
36 const QString fileFilter;
37
38
36 SkinDocument(QWidget *parent = 0); 39 SkinDocument(QWidget *parent = 0);
37 virtual ~SkinDocument(); 40 virtual ~SkinDocument();
38 41
39 ParseTreeModel* getModel(){ return model; } 42 ParseTreeModel* getModel(){ return model; }
40 QString getTitle(){ return title; } 43 QString getTitle(){ return title; }
41 44
45 void save();
46 void saveAs();
47
42 bool requestClose(); 48 bool requestClose();
43 49
44signals: 50signals:
45 void titleChanged(QString); 51 void titleChanged(QString);
46 52
47public slots:
48 void save();
49 void saveAs();
50
51private slots: 53private slots:
52 void codeChanged(); 54 void codeChanged();
53 55
@@ -56,7 +58,7 @@ private:
56 58
57 QString title; 59 QString title;
58 QString fileName; 60 QString fileName;
59 bool saved; 61 QString saved;
60 62
61 QLayout* layout; 63 QLayout* layout;
62 QPlainTextEdit* editor; 64 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 \
26 skindocument.cpp 26 skindocument.cpp
27OTHER_FILES += README \ 27OTHER_FILES += README \
28 resources/windowicon.png \ 28 resources/windowicon.png \
29 resources/appicon.xcf 29 resources/appicon.xcf \
30 resources/COPYING \
31 resources/document-save.png \
32 resources/document-open.png \
33 resources/document-new.png
30FORMS += editorwindow.ui 34FORMS += editorwindow.ui
31RESOURCES += resources.qrc 35RESOURCES += resources.qrc