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

constructing documents from a file list instead of a single name

This commit is contained in:
Marc Zinnschlag 2013-02-04 13:46:54 +01:00
parent 3f0a49a2f6
commit 4c973a0f67
5 changed files with 66 additions and 10 deletions

View file

@ -22,13 +22,16 @@ void CS::Editor::createDocument()
mStartup.hide(); mStartup.hide();
/// \todo open the ESX picker instead /// \todo open the ESX picker instead
/// \todo remove the following code for creating initial records into the document manager /// \todo move the following code for creating initial records into the document manager
std::ostringstream stream; std::ostringstream stream;
stream << "NewDocument" << (++mNewDocumentIndex); stream << "NewDocument" << (++mNewDocumentIndex);
CSMDoc::Document *document = mDocumentManager.addDocument (stream.str()); std::vector<boost::filesystem::path> files;
files.push_back (stream.str());
CSMDoc::Document *document = mDocumentManager.addDocument (files, true);
static const char *sGlobals[] = static const char *sGlobals[] =
{ {
@ -60,7 +63,10 @@ void CS::Editor::loadDocument()
stream << "Document" << (++mNewDocumentIndex); stream << "Document" << (++mNewDocumentIndex);
CSMDoc::Document *document = mDocumentManager.addDocument (stream.str()); std::vector<boost::filesystem::path> files;
files.push_back (stream.str());
CSMDoc::Document *document = mDocumentManager.addDocument (files, false);
static const char *sGlobals[] = static const char *sGlobals[] =
{ {

View file

@ -1,10 +1,48 @@
#include "document.hpp" #include "document.hpp"
CSMDoc::Document::Document (const std::string& name) #include <iostream>
void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin,
const std::vector<boost::filesystem::path>::const_iterator& end)
{
for (std::vector<boost::filesystem::path>::const_iterator iter (begin); iter!=end; ++iter)
std::cout << "pretending to load " << iter->string() << std::endl;
/// \todo load content files
}
void CSMDoc::Document::createBase()
{
std::cout << "pretending to create base file records" << std::endl;
/// \todo create mandatory records for base content file
}
CSMDoc::Document::Document (const std::vector<boost::filesystem::path>& files, bool new_)
: mTools (mData) : mTools (mData)
{ {
mName = name; ///< \todo replace with ESX list if (files.empty())
throw std::runtime_error ("Empty content file sequence");
/// \todo adjust last file name:
/// \li make sure it is located in the data-local directory (adjust path if necessary)
/// \li make sure the extension matches the new scheme (change it if necesarry)
mName = files.back().filename().string();
if (files.size()>1 || !new_)
{
std::vector<boost::filesystem::path>::const_iterator end = files.end();
if (new_)
--end;
load (files.begin(), end);
}
if (new_ && files.size()==1)
createBase();
connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool))); connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool)));

View file

@ -3,6 +3,8 @@
#include <string> #include <string>
#include <boost/filesystem/path.hpp>
#include <QUndoStack> #include <QUndoStack>
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
@ -38,10 +40,14 @@ namespace CSMDoc
Document (const Document&); Document (const Document&);
Document& operator= (const Document&); Document& operator= (const Document&);
void load (const std::vector<boost::filesystem::path>::const_iterator& begin,
const std::vector<boost::filesystem::path>::const_iterator& end);
void createBase();
public: public:
Document (const std::string& name); Document (const std::vector<boost::filesystem::path>& files, bool new_);
///< \todo replace name with ESX list
QUndoStack& getUndoStack(); QUndoStack& getUndoStack();

View file

@ -14,9 +14,10 @@ CSMDoc::DocumentManager::~DocumentManager()
delete *iter; delete *iter;
} }
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::string& name) CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files,
bool new_)
{ {
Document *document = new Document (name); Document *document = new Document (files, new_);
mDocuments.push_back (document); mDocuments.push_back (document);

View file

@ -4,6 +4,8 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <boost/filesystem/path.hpp>
namespace CSMDoc namespace CSMDoc
{ {
class Document; class Document;
@ -21,8 +23,11 @@ namespace CSMDoc
~DocumentManager(); ~DocumentManager();
Document *addDocument (const std::string& name); Document *addDocument (const std::vector<boost::filesystem::path>& files, bool new_);
///< The ownership of the returned document is not transferred to the caller. ///< The ownership of the returned document is not transferred to the caller.
///
/// \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way.
bool removeDocument (Document *document); bool removeDocument (Document *document);
///< \return last document removed? ///< \return last document removed?