1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

giving Documents direct access to ConfigurationManager

This commit is contained in:
Marc Zinnschlag 2013-09-27 15:24:58 +02:00
parent e7c48cbe58
commit 6143ec33e0
5 changed files with 41 additions and 24 deletions

View file

@ -11,7 +11,7 @@
CS::Editor::Editor()
: mDocumentManager (mCfgMgr.getUserPath() / "projects"), mViewManager (mDocumentManager)
: mDocumentManager (mCfgMgr), mViewManager (mDocumentManager)
{
mIpcServerName = "org.openmw.OpenCS";

View file

@ -4,6 +4,10 @@
#include <boost/filesystem.hpp>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin,
const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified)
{
@ -2142,10 +2146,13 @@ void CSMDoc::Document::createBase()
}
}
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
const boost::filesystem::path& savePath, bool new_,
const boost::filesystem::path& projectPath)
: mSavePath (savePath), mContentFiles (files), mTools (mData), mSaving (*this, projectPath)
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
const std::vector<boost::filesystem::path>& files,
const boost::filesystem::path& savePath, bool new_)
: mSavePath (savePath), mContentFiles (files), mTools (mData),
mProjectPath ((configuration.getUserPath() / "projects") /
(savePath.filename().string() + ".project")),
mSaving (*this, mProjectPath)
{
if (files.empty())
throw std::runtime_error ("Empty content file sequence");
@ -2170,9 +2177,9 @@ CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files,
/// \todo un-outcomment the else, once loading an existing content file works properly again.
// else
{
if (boost::filesystem::exists (projectPath))
if (boost::filesystem::exists (mProjectPath))
{
getData().loadFile (projectPath, false, true);
getData().loadFile (mProjectPath, false, true);
}
else
{

View file

@ -24,6 +24,11 @@ namespace ESM
struct Global;
}
namespace Files
{
class ConfigurationManager;
}
namespace CSMDoc
{
class Document : public QObject
@ -36,6 +41,7 @@ namespace CSMDoc
std::vector<boost::filesystem::path> mContentFiles;
CSMWorld::Data mData;
CSMTools::Tools mTools;
boost::filesystem::path mProjectPath;
Saving mSaving;
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
@ -64,11 +70,9 @@ namespace CSMDoc
public:
Document (const std::vector<boost::filesystem::path>& files,
const boost::filesystem::path& savePath, bool new_,
const boost::filesystem::path& projectPath);
///< \param projectPath Location of file that can be used to store additional data for
/// this project.
Document (const Files::ConfigurationManager& configuration,
const std::vector<boost::filesystem::path>& files,
const boost::filesystem::path& savePath, bool new_);
~Document();

View file

@ -6,13 +6,19 @@
#include <boost/filesystem.hpp>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
#include "document.hpp"
CSMDoc::DocumentManager::DocumentManager (const boost::filesystem::path& projectPath)
: mProjectPath (projectPath)
CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& configuration)
: mConfiguration (configuration)
{
if (!boost::filesystem::is_directory (mProjectPath))
boost::filesystem::create_directories (mProjectPath);
boost::filesystem::path projectPath = configuration.getUserPath() / "projects";
if (!boost::filesystem::is_directory (projectPath))
boost::filesystem::create_directories (projectPath);
}
CSMDoc::DocumentManager::~DocumentManager()
@ -24,11 +30,7 @@ CSMDoc::DocumentManager::~DocumentManager()
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
bool new_)
{
boost::filesystem::path projectFile (mProjectPath);
projectFile /= savePath.filename().string() + ".project";
Document *document = new Document (files, savePath, new_, projectFile);
Document *document = new Document (mConfiguration, files, savePath, new_);
mDocuments.push_back (document);

View file

@ -6,6 +6,11 @@
#include <boost/filesystem/path.hpp>
namespace Files
{
class ConfigurationManager;
}
namespace CSMDoc
{
class Document;
@ -13,15 +18,14 @@ namespace CSMDoc
class DocumentManager
{
std::vector<Document *> mDocuments;
boost::filesystem::path mProjectPath;
const Files::ConfigurationManager& mConfiguration;
DocumentManager (const DocumentManager&);
DocumentManager& operator= (const DocumentManager&);
public:
DocumentManager (const boost::filesystem::path& projectPath);
///< \param projectPath Directory where additional per-project data will be stored.
DocumentManager (const Files::ConfigurationManager& configuration);
~DocumentManager();