diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-07-25 21:16:37 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-07-25 21:16:37 +0000 |
commit | e1e51f99949f2a2967210342fcea6e8ae8495e0b (patch) | |
tree | bb2d62c6bea3e379e301d9b6b3592e1156274a54 | |
parent | e024198305623674d372aff71463e904905485b0 (diff) |
Theme Editor: Added recent docs/projects menus. Modified buildtargetdb.php to add a do-not-modify warning to the top of its output, and generated a new targetdb file with the warning in place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27564 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-x | utils/themeeditor/buildtargetdb.php | 12 | ||||
-rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 121 | ||||
-rw-r--r-- | utils/themeeditor/gui/editorwindow.h | 14 | ||||
-rw-r--r-- | utils/themeeditor/gui/editorwindow.ui | 36 | ||||
-rw-r--r-- | utils/themeeditor/resources/targetdb | 11 |
5 files changed, 193 insertions, 1 deletions
diff --git a/utils/themeeditor/buildtargetdb.php b/utils/themeeditor/buildtargetdb.php index 694b1668b6..26b6f119c2 100755 --- a/utils/themeeditor/buildtargetdb.php +++ b/utils/themeeditor/buildtargetdb.php @@ -21,6 +21,18 @@ * ****************************************************************************/ +// Printing the do-not-modify warning +echo "# ----------------------------------------------------------- #\n"; +echo "# ----------------------------------------------------------- #\n"; +echo "# --- This file automatically generated, do not modify! --- #\n"; +echo "# --- To add a target to the targetdb, add it to the --- #\n"; +echo "# --- \$targets array in buildtargetdb.php and run that --- #\n"; +echo "# --- script, ensuring that your current directory is --- #\n"; +echo "# --- utils/themeeditor, and pipe the output into --- #\n"; +echo "# --- utils/themeeditor/resources/targetdb --- #\n"; +echo "# ----------------------------------------------------------- #\n"; +echo "# ----------------------------------------------------------- #\n\n"; + // This is the array of targets, with the target id as the key and the // plaintext name of the target as the value $targets = array( 'archosfmrecorder' => 'Archos FM Recorder', diff --git a/utils/themeeditor/gui/editorwindow.cpp b/utils/themeeditor/gui/editorwindow.cpp index f919224a2f..f76fd8e88b 100644 --- a/utils/themeeditor/gui/editorwindow.cpp +++ b/utils/themeeditor/gui/editorwindow.cpp @@ -36,6 +36,8 @@ #include <QDir> #include <QFile> +const int EditorWindow::numRecent = 5; + EditorWindow::EditorWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) { @@ -56,6 +58,8 @@ EditorWindow::~EditorWindow() delete project; delete deviceConfig; delete deviceDock; + delete timer; + delete timerDock; RBFontCache::clearCache(); RBTextCache::clearCache(); @@ -63,6 +67,8 @@ EditorWindow::~EditorWindow() void EditorWindow::loadTabFromSkinFile(QString fileName) { + docToTop(fileName); + /* Checking to see if the file is already open */ for(int i = 0; i < ui->editorTabs->count(); i++) { @@ -114,6 +120,12 @@ void EditorWindow::loadSettings() QSize size = settings.value("size").toSize(); QPoint pos = settings.value("position").toPoint(); QByteArray state = settings.value("state").toByteArray(); + + /* Recent docs/projects */ + recentDocs = settings.value("recentDocs", QStringList()).toStringList(); + recentProjects = settings.value("recentProjects", + QStringList()).toStringList(); + settings.endGroup(); if(!(size.isNull() || pos.isNull() || state.isNull())) @@ -135,6 +147,11 @@ void EditorWindow::saveSettings() settings.setValue("position", pos()); settings.setValue("size", size()); settings.setValue("state", saveState()); + + /* Saving recent docs/projects */ + settings.setValue("recentDocs", recentDocs); + settings.setValue("recentProjects", recentProjects); + settings.endGroup(); } @@ -245,6 +262,30 @@ void EditorWindow::setupMenus() this, SLOT(paste())); QObject::connect(ui->actionFind_Replace, SIGNAL(triggered()), this, SLOT(findReplace())); + + /* Adding the recent docs/projects menus */ + for(int i = 0; i < numRecent; i++) + { + recentDocsMenu.append(new QAction(tr("Recent Doc"), + ui->menuRecent_Files)); + recentDocsMenu.last() + ->setShortcut(QKeySequence(tr("CTRL+") + + QString::number(i + 1))); + QObject::connect(recentDocsMenu.last(), SIGNAL(triggered()), + this, SLOT(openRecentFile())); + ui->menuRecent_Files->addAction(recentDocsMenu.last()); + + + recentProjectsMenu.append(new QAction(tr("Recent Project"), + ui->menuRecent_Projects)); + recentProjectsMenu.last() + ->setShortcut(QKeySequence(tr("CTRL+SHIFT+") + + QString::number(i + 1))); + QObject::connect(recentProjectsMenu.last(), SIGNAL(triggered()), + this, SLOT(openRecentProject())); + ui->menuRecent_Projects->addAction(recentProjectsMenu.last()); + } + refreshRecentMenus(); } void EditorWindow::addTab(TabContent *doc) @@ -546,6 +587,16 @@ void EditorWindow::openProject() } +void EditorWindow::openRecentFile() +{ + loadTabFromSkinFile(dynamic_cast<QAction*>(QObject::sender())->text()); +} + +void EditorWindow::openRecentProject() +{ + loadProjectFile(dynamic_cast<QAction*>(QObject::sender())->text()); +} + void EditorWindow::configFileChanged(QString configFile) { @@ -743,6 +794,8 @@ void EditorWindow::loadProjectFile(QString fileName) if(QFile::exists(fileName)) { + projectToTop(fileName); + if(project) project->deleteLater(); @@ -816,3 +869,71 @@ void EditorWindow::createFile(QString filename, QString contents) fout.close(); } + +void EditorWindow::docToTop(QString file) +{ + if(!QFile::exists(file)) + return; + + int index = recentDocs.indexOf(file); + if(index == -1) + { + /* Bumping off the last file */ + if(recentDocs.count() >= numRecent) + recentDocs.removeLast(); + recentDocs.prepend(file); + } + else + { + /* Shuffling file to the top of the list */ + recentDocs.removeAt(index); + recentDocs.prepend(file); + } + + refreshRecentMenus(); +} + +void EditorWindow::projectToTop(QString file) +{ + if(!QFile::exists(file)) + return; + + int index = recentProjects.indexOf(file); + if(index == -1) + { + /* Bumping off the last project */ + if(recentProjects.count() >= numRecent) + recentProjects.removeLast(); + recentProjects.prepend(file); + } + else + { + /* Shuffling file to the top of the list */ + recentProjects.removeAt(index); + recentProjects.prepend(file); + } + + refreshRecentMenus(); +} + +void EditorWindow::refreshRecentMenus() +{ + /* First hiding all the menu items */ + for(int i = 0; i < recentDocsMenu.count(); i++) + recentDocsMenu[i]->setVisible(false); + for(int i = 0; i < recentProjectsMenu.count(); i++) + recentProjectsMenu[i]->setVisible(false); + + /* Then setting the text of and showing any available */ + for(int i = 0; i < recentDocs.count(); i++) + { + recentDocsMenu[i]->setText(recentDocs[i]); + recentDocsMenu[i]->setVisible(true); + } + + for(int i = 0; i < recentProjects.count(); i++) + { + recentProjectsMenu[i]->setText(recentProjects[i]); + recentProjectsMenu[i]->setVisible(true); + } +} diff --git a/utils/themeeditor/gui/editorwindow.h b/utils/themeeditor/gui/editorwindow.h index 996ddcd40e..bd71c9a5dc 100644 --- a/utils/themeeditor/gui/editorwindow.h +++ b/utils/themeeditor/gui/editorwindow.h @@ -49,6 +49,8 @@ class EditorWindow : public QMainWindow { Q_OBJECT public: + static const int numRecent; + EditorWindow(QWidget *parent = 0); virtual ~EditorWindow(); @@ -75,6 +77,8 @@ private slots: void exportProject(); void openFile(); void openProject(); + void openRecentFile(); + void openRecentProject(); void tabTitleChanged(QString title); void updateCurrent(); /* Generates code in the current tab */ void lineChanged(int line); /* Used for auto-expand */ @@ -100,6 +104,11 @@ private: void loadProjectFile(QString fileName); static void createFile(QString filename, QString contents); + /* Functions to manipulate the recent projects/documents menus */ + void docToTop(QString file); + void projectToTop(QString file); + void refreshRecentMenus(); + Ui::EditorWindow *ui; PreferencesDialog* prefs; QLabel* parseStatus; @@ -110,6 +119,11 @@ private: QDockWidget* deviceDock; SkinTimer* timer; QDockWidget* timerDock; + + QStringList recentDocs; + QStringList recentProjects; + QList<QAction*> recentDocsMenu; + QList<QAction*> recentProjectsMenu; }; #endif // EDITORWINDOW_H diff --git a/utils/themeeditor/gui/editorwindow.ui b/utils/themeeditor/gui/editorwindow.ui index edfdfe3d84..bd74e1369e 100644 --- a/utils/themeeditor/gui/editorwindow.ui +++ b/utils/themeeditor/gui/editorwindow.ui @@ -40,17 +40,29 @@ <x>0</x> <y>0</y> <width>628</width> - <height>25</height> + <height>27</height> </rect> </property> <widget class="QMenu" name="menuFile"> <property name="title"> <string>&File</string> </property> + <widget class="QMenu" name="menuRecent_Files"> + <property name="title"> + <string>Recent Files</string> + </property> + </widget> + <widget class="QMenu" name="menuRecent_Projects"> + <property name="title"> + <string>Recent Projects</string> + </property> + </widget> <addaction name="actionNew_Document"/> <addaction name="actionNew_Project"/> <addaction name="actionOpen_Document"/> <addaction name="actionOpen_Project"/> + <addaction name="menuRecent_Files"/> + <addaction name="menuRecent_Projects"/> <addaction name="separator"/> <addaction name="actionClose_Document"/> <addaction name="actionClose_Project"/> @@ -407,6 +419,28 @@ <string>Ctrl+Shift+X</string> </property> </action> + <action name="actionFiles"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Files</string> + </property> + <property name="visible"> + <bool>true</bool> + </property> + </action> + <action name="actionProjects"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Projects</string> + </property> + <property name="visible"> + <bool>true</bool> + </property> + </action> </widget> <tabstops> <tabstop>projectTree</tabstop> diff --git a/utils/themeeditor/resources/targetdb b/utils/themeeditor/resources/targetdb index 114937a863..e466747b88 100644 --- a/utils/themeeditor/resources/targetdb +++ b/utils/themeeditor/resources/targetdb @@ -1,3 +1,14 @@ +# ----------------------------------------------------------- # +# ----------------------------------------------------------- # +# --- This file automatically generated, do not modify! --- # +# --- To add a target to the targetdb, add it to the --- # +# --- $targets array in buildtargetdb.php and run that --- # +# --- script, ensuring that your current directory is --- # +# --- utils/themeeditor, and pipe the output into --- # +# --- utils/themeeditor/resources/targetdb --- # +# ----------------------------------------------------------- # +# ----------------------------------------------------------- # + archosfmrecorder { name : Archos FM Recorder |