2012-11-21 16:31:18 +00:00
|
|
|
|
|
|
|
#include "documentmanager.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2013-09-27 09:36:06 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
2012-11-21 16:31:18 +00:00
|
|
|
#include "document.hpp"
|
|
|
|
|
2013-09-27 09:36:06 +00:00
|
|
|
CSMDoc::DocumentManager::DocumentManager (const boost::filesystem::path& projectPath)
|
|
|
|
: mProjectPath (projectPath)
|
|
|
|
{
|
|
|
|
if (!boost::filesystem::is_directory (mProjectPath))
|
|
|
|
boost::filesystem::create_directories (mProjectPath);
|
|
|
|
}
|
2012-11-21 16:31:18 +00:00
|
|
|
|
|
|
|
CSMDoc::DocumentManager::~DocumentManager()
|
|
|
|
{
|
|
|
|
for (std::vector<Document *>::iterator iter (mDocuments.begin()); iter!=mDocuments.end(); ++iter)
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
|
2013-09-10 14:45:01 +00:00
|
|
|
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
|
2013-02-04 12:46:54 +00:00
|
|
|
bool new_)
|
2012-11-21 16:31:18 +00:00
|
|
|
{
|
2013-09-27 09:36:06 +00:00
|
|
|
boost::filesystem::path projectFile (mProjectPath);
|
|
|
|
|
|
|
|
projectFile /= savePath.filename().string() + ".project";
|
|
|
|
|
|
|
|
Document *document = new Document (files, savePath, new_, projectFile);
|
2012-11-21 16:31:18 +00:00
|
|
|
|
|
|
|
mDocuments.push_back (document);
|
|
|
|
|
|
|
|
return document;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSMDoc::DocumentManager::removeDocument (Document *document)
|
|
|
|
{
|
|
|
|
std::vector<Document *>::iterator iter = std::find (mDocuments.begin(), mDocuments.end(), document);
|
|
|
|
|
|
|
|
if (iter==mDocuments.end())
|
|
|
|
throw std::runtime_error ("removing invalid document");
|
|
|
|
|
|
|
|
mDocuments.erase (iter);
|
|
|
|
delete document;
|
|
|
|
|
|
|
|
return mDocuments.empty();
|
|
|
|
}
|