diff options
Diffstat (limited to 'utils/themeeditor/gui/editorwindow.cpp')
-rw-r--r-- | utils/themeeditor/gui/editorwindow.cpp | 121 |
1 files changed, 121 insertions, 0 deletions
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 @@ | |||
36 | #include <QDir> | 36 | #include <QDir> |
37 | #include <QFile> | 37 | #include <QFile> |
38 | 38 | ||
39 | const int EditorWindow::numRecent = 5; | ||
40 | |||
39 | EditorWindow::EditorWindow(QWidget *parent) : | 41 | EditorWindow::EditorWindow(QWidget *parent) : |
40 | QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) | 42 | QMainWindow(parent), ui(new Ui::EditorWindow), parseTreeSelection(0) |
41 | { | 43 | { |
@@ -56,6 +58,8 @@ EditorWindow::~EditorWindow() | |||
56 | delete project; | 58 | delete project; |
57 | delete deviceConfig; | 59 | delete deviceConfig; |
58 | delete deviceDock; | 60 | delete deviceDock; |
61 | delete timer; | ||
62 | delete timerDock; | ||
59 | 63 | ||
60 | RBFontCache::clearCache(); | 64 | RBFontCache::clearCache(); |
61 | RBTextCache::clearCache(); | 65 | RBTextCache::clearCache(); |
@@ -63,6 +67,8 @@ EditorWindow::~EditorWindow() | |||
63 | 67 | ||
64 | void EditorWindow::loadTabFromSkinFile(QString fileName) | 68 | void EditorWindow::loadTabFromSkinFile(QString fileName) |
65 | { | 69 | { |
70 | docToTop(fileName); | ||
71 | |||
66 | /* Checking to see if the file is already open */ | 72 | /* Checking to see if the file is already open */ |
67 | for(int i = 0; i < ui->editorTabs->count(); i++) | 73 | for(int i = 0; i < ui->editorTabs->count(); i++) |
68 | { | 74 | { |
@@ -114,6 +120,12 @@ void EditorWindow::loadSettings() | |||
114 | QSize size = settings.value("size").toSize(); | 120 | QSize size = settings.value("size").toSize(); |
115 | QPoint pos = settings.value("position").toPoint(); | 121 | QPoint pos = settings.value("position").toPoint(); |
116 | QByteArray state = settings.value("state").toByteArray(); | 122 | QByteArray state = settings.value("state").toByteArray(); |
123 | |||
124 | /* Recent docs/projects */ | ||
125 | recentDocs = settings.value("recentDocs", QStringList()).toStringList(); | ||
126 | recentProjects = settings.value("recentProjects", | ||
127 | QStringList()).toStringList(); | ||
128 | |||
117 | settings.endGroup(); | 129 | settings.endGroup(); |
118 | 130 | ||
119 | if(!(size.isNull() || pos.isNull() || state.isNull())) | 131 | if(!(size.isNull() || pos.isNull() || state.isNull())) |
@@ -135,6 +147,11 @@ void EditorWindow::saveSettings() | |||
135 | settings.setValue("position", pos()); | 147 | settings.setValue("position", pos()); |
136 | settings.setValue("size", size()); | 148 | settings.setValue("size", size()); |
137 | settings.setValue("state", saveState()); | 149 | settings.setValue("state", saveState()); |
150 | |||
151 | /* Saving recent docs/projects */ | ||
152 | settings.setValue("recentDocs", recentDocs); | ||
153 | settings.setValue("recentProjects", recentProjects); | ||
154 | |||
138 | settings.endGroup(); | 155 | settings.endGroup(); |
139 | } | 156 | } |
140 | 157 | ||
@@ -245,6 +262,30 @@ void EditorWindow::setupMenus() | |||
245 | this, SLOT(paste())); | 262 | this, SLOT(paste())); |
246 | QObject::connect(ui->actionFind_Replace, SIGNAL(triggered()), | 263 | QObject::connect(ui->actionFind_Replace, SIGNAL(triggered()), |
247 | this, SLOT(findReplace())); | 264 | this, SLOT(findReplace())); |
265 | |||
266 | /* Adding the recent docs/projects menus */ | ||
267 | for(int i = 0; i < numRecent; i++) | ||
268 | { | ||
269 | recentDocsMenu.append(new QAction(tr("Recent Doc"), | ||
270 | ui->menuRecent_Files)); | ||
271 | recentDocsMenu.last() | ||
272 | ->setShortcut(QKeySequence(tr("CTRL+") | ||
273 | + QString::number(i + 1))); | ||
274 | QObject::connect(recentDocsMenu.last(), SIGNAL(triggered()), | ||
275 | this, SLOT(openRecentFile())); | ||
276 | ui->menuRecent_Files->addAction(recentDocsMenu.last()); | ||
277 | |||
278 | |||
279 | recentProjectsMenu.append(new QAction(tr("Recent Project"), | ||
280 | ui->menuRecent_Projects)); | ||
281 | recentProjectsMenu.last() | ||
282 | ->setShortcut(QKeySequence(tr("CTRL+SHIFT+") + | ||
283 | QString::number(i + 1))); | ||
284 | QObject::connect(recentProjectsMenu.last(), SIGNAL(triggered()), | ||
285 | this, SLOT(openRecentProject())); | ||
286 | ui->menuRecent_Projects->addAction(recentProjectsMenu.last()); | ||
287 | } | ||
288 | refreshRecentMenus(); | ||
248 | } | 289 | } |
249 | 290 | ||
250 | void EditorWindow::addTab(TabContent *doc) | 291 | void EditorWindow::addTab(TabContent *doc) |
@@ -546,6 +587,16 @@ void EditorWindow::openProject() | |||
546 | 587 | ||
547 | } | 588 | } |
548 | 589 | ||
590 | void EditorWindow::openRecentFile() | ||
591 | { | ||
592 | loadTabFromSkinFile(dynamic_cast<QAction*>(QObject::sender())->text()); | ||
593 | } | ||
594 | |||
595 | void EditorWindow::openRecentProject() | ||
596 | { | ||
597 | loadProjectFile(dynamic_cast<QAction*>(QObject::sender())->text()); | ||
598 | } | ||
599 | |||
549 | void EditorWindow::configFileChanged(QString configFile) | 600 | void EditorWindow::configFileChanged(QString configFile) |
550 | { | 601 | { |
551 | 602 | ||
@@ -743,6 +794,8 @@ void EditorWindow::loadProjectFile(QString fileName) | |||
743 | 794 | ||
744 | if(QFile::exists(fileName)) | 795 | if(QFile::exists(fileName)) |
745 | { | 796 | { |
797 | projectToTop(fileName); | ||
798 | |||
746 | if(project) | 799 | if(project) |
747 | project->deleteLater(); | 800 | project->deleteLater(); |
748 | 801 | ||
@@ -816,3 +869,71 @@ void EditorWindow::createFile(QString filename, QString contents) | |||
816 | 869 | ||
817 | fout.close(); | 870 | fout.close(); |
818 | } | 871 | } |
872 | |||
873 | void EditorWindow::docToTop(QString file) | ||
874 | { | ||
875 | if(!QFile::exists(file)) | ||
876 | return; | ||
877 | |||
878 | int index = recentDocs.indexOf(file); | ||
879 | if(index == -1) | ||
880 | { | ||
881 | /* Bumping off the last file */ | ||
882 | if(recentDocs.count() >= numRecent) | ||
883 | recentDocs.removeLast(); | ||
884 | recentDocs.prepend(file); | ||
885 | } | ||
886 | else | ||
887 | { | ||
888 | /* Shuffling file to the top of the list */ | ||
889 | recentDocs.removeAt(index); | ||
890 | recentDocs.prepend(file); | ||
891 | } | ||
892 | |||
893 | refreshRecentMenus(); | ||
894 | } | ||
895 | |||
896 | void EditorWindow::projectToTop(QString file) | ||
897 | { | ||
898 | if(!QFile::exists(file)) | ||
899 | return; | ||
900 | |||
901 | int index = recentProjects.indexOf(file); | ||
902 | if(index == -1) | ||
903 | { | ||
904 | /* Bumping off the last project */ | ||
905 | if(recentProjects.count() >= numRecent) | ||
906 | recentProjects.removeLast(); | ||
907 | recentProjects.prepend(file); | ||
908 | } | ||
909 | else | ||
910 | { | ||
911 | /* Shuffling file to the top of the list */ | ||
912 | recentProjects.removeAt(index); | ||
913 | recentProjects.prepend(file); | ||
914 | } | ||
915 | |||
916 | refreshRecentMenus(); | ||
917 | } | ||
918 | |||
919 | void EditorWindow::refreshRecentMenus() | ||
920 | { | ||
921 | /* First hiding all the menu items */ | ||
922 | for(int i = 0; i < recentDocsMenu.count(); i++) | ||
923 | recentDocsMenu[i]->setVisible(false); | ||
924 | for(int i = 0; i < recentProjectsMenu.count(); i++) | ||
925 | recentProjectsMenu[i]->setVisible(false); | ||
926 | |||
927 | /* Then setting the text of and showing any available */ | ||
928 | for(int i = 0; i < recentDocs.count(); i++) | ||
929 | { | ||
930 | recentDocsMenu[i]->setText(recentDocs[i]); | ||
931 | recentDocsMenu[i]->setVisible(true); | ||
932 | } | ||
933 | |||
934 | for(int i = 0; i < recentProjects.count(); i++) | ||
935 | { | ||
936 | recentProjectsMenu[i]->setText(recentProjects[i]); | ||
937 | recentProjectsMenu[i]->setVisible(true); | ||
938 | } | ||
939 | } | ||