diff --git a/gui/common.h b/gui/common.h index 116be8687..b50efeb93 100644 --- a/gui/common.h +++ b/gui/common.h @@ -84,6 +84,7 @@ ShowTypes; #define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths" #define SETTINGS_INLINE_SUPPRESSIONS "Inline suppressions" #define SETTINGS_INCONCLUSIVE_ERRORS "Inconclusive errors" +#define SETTINGS_MRU_PROJECTS "MRU Projects" /// @} #endif diff --git a/gui/main.ui b/gui/main.ui index c1456f70b..cfeeba6a5 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -66,7 +66,7 @@ 0 0 640 - 28 + 25 @@ -80,6 +80,7 @@ + @@ -540,6 +541,14 @@ Filter results + + + Project MRU placeholder + + + true + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 4ece1ffb5..7bbd793ec 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -137,6 +137,16 @@ MainWindow::MainWindow() : { HandleCLIParams(args); } + + for (int i = 0; i < MaxRecentProjects; ++i) + { + mRecentProjectActs[i] = new QAction(this); + mRecentProjectActs[i]->setVisible(false); + connect(mRecentProjectActs[i], SIGNAL(triggered()), + this, SLOT(OpenRecentProject())); + } + mUI.mActionProjectMRU->setVisible(false); + UpdateMRUMenuItems(); } MainWindow::~MainWindow() @@ -795,6 +805,7 @@ void MainWindow::LoadProjectFile(const QString &filePath) QFileInfo inf(filePath); const QString filename = inf.fileName(); FormatAndSetTitle(tr("Project: ") + QString(" ") + filename); + AddProjectMRU(filePath); mUI.mActionCloseProjectFile->setEnabled(true); mUI.mActionEditProjectFile->setEnabled(true); @@ -846,6 +857,7 @@ void MainWindow::NewProjectFile() mProject->Create(); mProject->Edit(); } + AddProjectMRU(filepath); } void MainWindow::CloseProjectFile() @@ -931,3 +943,46 @@ void MainWindow::EnableProjectOpenActions(bool enable) mUI.mActionNewProjectFile->setEnabled(enable); mUI.mActionOpenProjectFile->setEnabled(enable); } + +void MainWindow::OpenRecentProject() +{ + QAction *action = qobject_cast(sender()); + if (action) + LoadProjectFile(action->data().toString()); +} + +void MainWindow::UpdateMRUMenuItems() +{ + for (int i = 0; i < MaxRecentProjects; i++) + { + if (mRecentProjectActs[i] != NULL) + mUI.mMenuFile->removeAction(mRecentProjectActs[i]); + } + + QStringList projects = mSettings->value(SETTINGS_MRU_PROJECTS).toStringList(); + const int numRecentProjects = qMin(projects.size(), (int)MaxRecentProjects); + for (int i = 0; i < numRecentProjects; i++) + { + const QString filename = QFileInfo(projects[i]).fileName(); + const QString text = QString("&%1 %2").arg(i + 1).arg(filename); + mRecentProjectActs[i]->setText(text); + mRecentProjectActs[i]->setData(projects[i]); + mRecentProjectActs[i]->setVisible(true); + mUI.mMenuFile->insertAction(mUI.mActionProjectMRU, mRecentProjectActs[i]); + } + + if (numRecentProjects > 1) + mUI.mMenuFile->insertSeparator(mUI.mActionProjectMRU); +} + +void MainWindow::AddProjectMRU(const QString &project) +{ + QStringList files = mSettings->value(SETTINGS_MRU_PROJECTS).toStringList(); + files.removeAll(project); + files.prepend(project); + while (files.size() > MaxRecentProjects) + files.removeLast(); + + mSettings->setValue(SETTINGS_MRU_PROJECTS, files); + UpdateMRUMenuItems(); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index a4d88ec38..dc8dfdd5e 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -40,6 +40,7 @@ class HelpWindow; class Project; class ErrorItem; class StatsDialog; +class QAction; /// @addtogroup GUI /// @{ @@ -52,6 +53,12 @@ class MainWindow : public QMainWindow { Q_OBJECT public: + + /** + * @brief Maximum number of MRU project items in File-menu. + */ + enum { MaxRecentProjects = 5 }; + MainWindow(); virtual ~MainWindow(); @@ -268,6 +275,10 @@ protected slots: */ void FilterResults(); + /** + * @brief Opens recently opened project file. + */ + void OpenRecentProject(); protected: @@ -384,6 +395,17 @@ protected: */ void LoadProjectFile(const QString &filePath); + /** + * @brief Update project MRU items in File-menu. + */ + void UpdateMRUMenuItems(); + + /** + * @brief Add project file (path) to the MRU list. + * @param project Full path to the project file to add. + */ + void AddProjectMRU(const QString &project); + /** * @brief Program settings * @@ -448,6 +470,10 @@ private: */ bool mExiting; + /** + * @brief Project MRU menu actions. + */ + QAction *mRecentProjectActs[MaxRecentProjects]; }; /// @} #endif // MAINWINDOW_H