Implemented project manager, app data, welcome window
This commit is contained in:
@ -1,11 +1,63 @@
|
||||
#include "projectmanager.h"
|
||||
#include <storage/appdatastorage.h>
|
||||
|
||||
namespace Ember
|
||||
{
|
||||
|
||||
ProjectManager::ProjectManager()
|
||||
: m_currentProject(nullptr),
|
||||
m_recentProjects(),
|
||||
m_recentProjectsLoaded(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const ProjectManager::RecentProjectMap &ProjectManager::recentProjects()
|
||||
{
|
||||
if (!m_recentProjectsLoaded)
|
||||
{
|
||||
std::vector<RecentProject> projects;
|
||||
AppDataStorage::readRecentProjects(projects);
|
||||
|
||||
for (RecentProject& project : projects)
|
||||
m_recentProjects.emplace(project.path, project);
|
||||
|
||||
m_recentProjectsLoaded = true;
|
||||
}
|
||||
|
||||
return m_recentProjects;
|
||||
}
|
||||
|
||||
void ProjectManager::pinRecentProject(boost::filesystem::path path, bool pinned)
|
||||
{
|
||||
auto it = m_recentProjects.find(path);
|
||||
if (it != m_recentProjects.end())
|
||||
{
|
||||
if (it->second.pinned != pinned)
|
||||
{
|
||||
it->second.pinned = pinned;
|
||||
saveRecentProjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectManager::deleteRecentProject(boost::filesystem::path path)
|
||||
{
|
||||
auto it = m_recentProjects.find(path);
|
||||
if (it != m_recentProjects.end())
|
||||
{
|
||||
m_recentProjects.erase(it);
|
||||
saveRecentProjects();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectManager::saveRecentProjects()
|
||||
{
|
||||
std::vector<RecentProject> projects;
|
||||
for (auto pair : m_recentProjects)
|
||||
projects.push_back(pair.second);
|
||||
|
||||
AppDataStorage::storeRecentProjects(projects);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,49 @@
|
||||
#ifndef PROJECTMANAGER_H
|
||||
#define PROJECTMANAGER_H
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <model/project.h>
|
||||
|
||||
namespace Ember
|
||||
{
|
||||
|
||||
class ProjectManager
|
||||
{
|
||||
public:
|
||||
typedef std::map<boost::filesystem::path, RecentProject> RecentProjectMap;
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
ProjectManager();
|
||||
|
||||
/**
|
||||
* @brief Gets a list of recent projects. First time reads from disk.
|
||||
* @return Map of recent projects.
|
||||
*/
|
||||
const RecentProjectMap& recentProjects();
|
||||
|
||||
/**
|
||||
* @brief Pins or unpins a recent project. Updates storage as well.
|
||||
* @param path Path
|
||||
* @param pinned True to pin, false to unpin
|
||||
*/
|
||||
void pinRecentProject(boost::filesystem::path path, bool pinned = true);
|
||||
|
||||
/**
|
||||
* @brief Deletes a recent project.
|
||||
* @param path
|
||||
*/
|
||||
void deleteRecentProject(boost::filesystem::path path);
|
||||
|
||||
private:
|
||||
void saveRecentProjects();
|
||||
|
||||
Project* m_currentProject;
|
||||
RecentProjectMap m_recentProjects;
|
||||
bool m_recentProjectsLoaded;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user