Commit ea400057 authored by Ludovic Fauvet's avatar Ludovic Fauvet
Browse files

ProjectManager: keep a list of recently opened projects

parent 505d69ce
......@@ -22,6 +22,7 @@
#include <QFileDialog>
#include <QtDebug>
#include <QSettings>
#include "ProjectManager.h"
#include "Library.h"
......@@ -30,11 +31,16 @@
ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
{
QSettings s;
m_recentsProjects = s.value( "RecentsProjects" ).toStringList();
}
ProjectManager::~ProjectManager()
{
// Write uncommited change to the disk
QSettings s;
s.sync();
if ( m_projectFile != NULL )
delete m_projectFile;
}
......@@ -44,6 +50,11 @@ bool ProjectManager::needSave() const
return m_needSave;
}
QStringList ProjectManager::recentsProjects() const
{
return m_recentsProjects;
}
void ProjectManager::cleanChanged( bool val )
{
m_needSave = !val;
......@@ -70,6 +81,16 @@ void ProjectManager::loadProject( const QString& fileName )
if ( fileName.length() == 0 )
return;
// Append the item to the recents list
m_recentsProjects.removeAll( fileName );
m_recentsProjects.prepend( fileName );
while ( m_recentsProjects.count() > 15 )
m_recentsProjects.removeLast();
QSettings s;
s.setValue( "RecentsProjects", m_recentsProjects );
if ( !m_projectFile )
delete m_projectFile;
m_projectFile = new QFile( fileName );
......
......@@ -26,6 +26,7 @@
#include <QFile>
#include <QObject>
#include <QDomDocument>
#include <QStringList>
#include "Singleton.hpp"
......@@ -38,6 +39,7 @@ public:
QString loadProjectFile();
void saveProject( bool saveAs = true );
bool needSave() const;
QStringList recentsProjects() const;
private:
ProjectManager();
......@@ -49,6 +51,7 @@ private:
QFile* m_projectFile;
QDomDocument* m_domDocument;
bool m_needSave;
QStringList m_recentsProjects;
friend class Singleton<ProjectManager>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment