diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-06-05 19:47:49 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-06-05 19:47:49 +0000 |
| commit | 47181b8b9b0e3e914243a463ad02a2eceab61c6e (patch) | |
| tree | 11a75ac5d5d1a4e72a60284c7a4a1b74893568db /utils/themeeditor/skindocument.cpp | |
| parent | 45ab395c2fb42445382a377314bd63ae216f40c4 (diff) | |
| download | rockbox-47181b8b9b0e3e914243a463ad02a2eceab61c6e.zip rockbox-47181b8b9b0e3e914243a463ad02a2eceab61c6e.tar.gz rockbox-47181b8b9b0e3e914243a463ad02a2eceab61c6e.tar.bz2 rockbox-47181b8b9b0e3e914243a463ad02a2eceab61c6e.tar.xz | |
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
Diffstat (limited to '')
| -rw-r--r-- | utils/themeeditor/skindocument.cpp | 87 |
1 files changed, 72 insertions, 15 deletions
diff --git a/utils/themeeditor/skindocument.cpp b/utils/themeeditor/skindocument.cpp index 8617030..3fb7d48 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); + } |