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>
|
|
|
|
|
2013-09-27 13:24:58 +00:00
|
|
|
#ifndef Q_MOC_RUN
|
|
|
|
#include <components/files/configurationmanager.hpp>
|
|
|
|
#endif
|
|
|
|
|
2012-11-21 16:31:18 +00:00
|
|
|
#include "document.hpp"
|
|
|
|
|
2013-09-27 13:24:58 +00:00
|
|
|
CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& configuration)
|
|
|
|
: mConfiguration (configuration)
|
2013-09-27 09:36:06 +00:00
|
|
|
{
|
2013-09-27 13:24:58 +00:00
|
|
|
boost::filesystem::path projectPath = configuration.getUserPath() / "projects";
|
|
|
|
|
|
|
|
if (!boost::filesystem::is_directory (projectPath))
|
|
|
|
boost::filesystem::create_directories (projectPath);
|
2013-09-27 09:36:06 +00:00
|
|
|
}
|
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-10-17 16:21:41 +00:00
|
|
|
Document *document = new Document (mConfiguration, files, savePath, mResDir, new_);
|
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();
|
2013-10-17 16:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSMDoc::DocumentManager::setResourceDir (const boost::filesystem::path& parResDir)
|
|
|
|
{
|
|
|
|
mResDir = boost::filesystem::system_complete(parResDir);
|
2012-11-21 16:31:18 +00:00
|
|
|
}
|