1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 11:09:43 +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();
/// \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;
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[] =
{
@ -60,7 +63,10 @@ void CS::Editor::loadDocument()
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[] =
{

View file

@ -1,10 +1,48 @@
#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)
{
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)));

View file

@ -3,6 +3,8 @@
#include <string>
#include <boost/filesystem/path.hpp>
#include <QUndoStack>
#include <QObject>
#include <QTimer>
@ -38,10 +40,14 @@ namespace CSMDoc
Document (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:
Document (const std::string& name);
///< \todo replace name with ESX list
Document (const std::vector<boost::filesystem::path>& files, bool new_);
QUndoStack& getUndoStack();

View file

@ -14,9 +14,10 @@ CSMDoc::DocumentManager::~DocumentManager()
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);

View file

@ -4,6 +4,8 @@
#include <vector>
#include <string>
#include <boost/filesystem/path.hpp>
namespace CSMDoc
{
class Document;
@ -21,8 +23,11 @@ namespace CSMDoc
~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.
///
/// \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way.
bool removeDocument (Document *document);
///< \return last document removed?