ember/business/projectmanager.cpp

64 lines
1.4 KiB
C++

#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);
}
}