diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index ead4d2a98..a43059795 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -11,7 +11,7 @@ CS::Editor::Editor() -: mDocumentManager (mCfgMgr.getUserPath() / "projects"), mViewManager (mDocumentManager) +: mDocumentManager (mCfgMgr), mViewManager (mDocumentManager) { mIpcServerName = "org.openmw.OpenCS"; diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 7f609f9f7..5c29d9f61 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -4,6 +4,10 @@ #include +#ifndef Q_MOC_RUN +#include +#endif + void CSMDoc::Document::load (const std::vector::const_iterator& begin, const std::vector::const_iterator& end, bool lastAsModified) { @@ -2142,10 +2146,13 @@ void CSMDoc::Document::createBase() } } -CSMDoc::Document::Document (const std::vector& 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& 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& 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 { diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 7843cfbfe..d171dacae 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -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 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& 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& files, + const boost::filesystem::path& savePath, bool new_); ~Document(); diff --git a/apps/opencs/model/doc/documentmanager.cpp b/apps/opencs/model/doc/documentmanager.cpp index 1978c0e53..1d6c88dcc 100644 --- a/apps/opencs/model/doc/documentmanager.cpp +++ b/apps/opencs/model/doc/documentmanager.cpp @@ -6,13 +6,19 @@ #include +#ifndef Q_MOC_RUN +#include +#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& 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); diff --git a/apps/opencs/model/doc/documentmanager.hpp b/apps/opencs/model/doc/documentmanager.hpp index 622a135a5..28a21216a 100644 --- a/apps/opencs/model/doc/documentmanager.hpp +++ b/apps/opencs/model/doc/documentmanager.hpp @@ -6,6 +6,11 @@ #include +namespace Files +{ + class ConfigurationManager; +} + namespace CSMDoc { class Document; @@ -13,15 +18,14 @@ namespace CSMDoc class DocumentManager { std::vector 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();