GUI: Add most recently used projects to menu.
Add MRU items for project files to File-menu. When user creates a new project file or opens existing project file it is added to the list of recently used projects. Last 5 projects are remembered and available for quick acess in the File-menu.
This commit is contained in:
parent
be9e66efff
commit
04652e75df
|
@ -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
|
||||
|
|
11
gui/main.ui
11
gui/main.ui
|
@ -66,7 +66,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>28</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="mMenuFile">
|
||||
|
@ -80,6 +80,7 @@
|
|||
<addaction name="mActionEditProjectFile"/>
|
||||
<addaction name="mActionCloseProjectFile"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="mActionProjectMRU"/>
|
||||
<addaction name="mActionSave"/>
|
||||
<addaction name="mActionQuit"/>
|
||||
</widget>
|
||||
|
@ -540,6 +541,14 @@
|
|||
<string>Filter results</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="mActionProjectMRU">
|
||||
<property name="text">
|
||||
<string>Project MRU placeholder</string>
|
||||
</property>
|
||||
<property name="visible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -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<QAction *>(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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue