create merged document and open a view for it (document is still empty at this point)

sceneinput
Marc Zinnschlag 10 years ago
parent d8655f2ff8
commit 1b663f01af

@ -35,14 +35,18 @@ opencs_hdrs_noqt (model/world
opencs_units (model/tools
tools reportmodel
tools reportmodel mergeoperation
)
opencs_units_noqt (model/tools
mandatoryid skillcheck classcheck factioncheck racecheck soundcheck regioncheck
birthsigncheck spellcheck referencecheck referenceablecheck scriptcheck bodypartcheck
startscriptcheck search searchoperation searchstage pathgridcheck soundgencheck
mergeoperation
mergestages
)
opencs_hdrs_noqt (model/tools
mergestate
)

@ -21,7 +21,8 @@
CS::Editor::Editor ()
: mUserSettings (mCfgMgr), mDocumentManager (mCfgMgr),
mViewManager (mDocumentManager), mPid(""),
mLock(), mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL)
mLock(), mMerge (mDocumentManager),
mIpcServerName ("org.openmw.OpenCS"), mServer(NULL), mClientSocket(NULL)
{
std::pair<Files::PathContainer, std::vector<std::string> > config = readConfig();

@ -2294,6 +2294,8 @@ CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationM
connect (&mTools, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
connect (&mTools, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool)));
connect (&mTools, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SIGNAL (mergeDone (CSMDoc::Document*)));
connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
connect (&mSaving, SIGNAL (done (int, bool)), this, SLOT (operationDone (int, bool)));
@ -2388,7 +2390,7 @@ void CSMDoc::Document::runSearch (const CSMWorld::UniversalId& searchId, const C
emit stateChanged (getState(), this);
}
void CSMDoc::Document::runMerge (const boost::filesystem::path& target)
void CSMDoc::Document::runMerge (std::auto_ptr<CSMDoc::Document> target)
{
mTools.runMerge (target);
emit stateChanged (getState(), this);

@ -130,7 +130,7 @@ namespace CSMDoc
void runSearch (const CSMWorld::UniversalId& searchId, const CSMTools::Search& search);
void runMerge (const boost::filesystem::path& target);
void runMerge (std::auto_ptr<CSMDoc::Document> target);
void abortOperation (int type);
@ -158,6 +158,10 @@ namespace CSMDoc
void progress (int current, int max, int type, int threads, CSMDoc::Document *document);
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
private slots:
void modificationStateChanged (bool clean);

@ -57,10 +57,24 @@ bool CSMDoc::DocumentManager::isEmpty()
void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
bool new_)
{
Document *document = new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts);
Document *document = makeDocument (files, savePath, new_);
insertDocument (document);
}
CSMDoc::Document *CSMDoc::DocumentManager::makeDocument (
const std::vector< boost::filesystem::path >& files,
const boost::filesystem::path& savePath, bool new_)
{
return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts);
}
void CSMDoc::DocumentManager::insertDocument (CSMDoc::Document *document)
{
mDocuments.push_back (document);
connect (document, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SLOT (insertDocument (CSMDoc::Document*)));
emit loadRequest (document);
mLoader.hasThingsToDo().wakeAll();

@ -56,6 +56,15 @@ namespace CSMDoc
///< \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way.
/// Create a new document. The ownership of the created document is transferred to
/// the calling function. The DocumentManager does not manage it. Loading has not
/// taken place at the point when the document is returned.
///
/// \param new_ Do not load the last content file in \a files and instead create in an
/// appropriate way.
Document *makeDocument (const std::vector< boost::filesystem::path >& files,
const boost::filesystem::path& savePath, bool new_);
void setResourceDir (const boost::filesystem::path& parResDir);
void setEncoding (ToUTF8::FromType encoding);
@ -84,6 +93,10 @@ namespace CSMDoc
void removeDocument (CSMDoc::Document *document);
///< Emits the lastDocumentDeleted signal, if applicable.
/// Hand over document to *this. The ownership is transferred. The DocumentManager
/// will initiate the load procedure, if necessary
void insertDocument (CSMDoc::Document *document);
signals:
void documentAdded (CSMDoc::Document *document);

@ -83,7 +83,9 @@ namespace CSMDoc
void executeStage();
void operationDone();
protected slots:
virtual void operationDone();
};
}

@ -2,14 +2,25 @@
#include "mergeoperation.hpp"
#include "../doc/state.hpp"
#include "../doc/document.hpp"
#include "mergestages.hpp"
CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document)
: CSMDoc::Operation (CSMDoc::State_Merging, true)
: CSMDoc::Operation (CSMDoc::State_Merging, true), mState (document)
{
appendStage (new FinishMergedDocumentStage (mState));
}
void CSMTools::MergeOperation::setTarget (std::auto_ptr<CSMDoc::Document> document)
{
mState.mTarget = document;
}
void CSMTools::MergeOperation::setTarget (const boost::filesystem::path& target)
void CSMTools::MergeOperation::operationDone()
{
CSMDoc::Operation::operationDone();
if (mState.mCompleted)
emit mergeDone (mState.mTarget.release());
}

@ -1,10 +1,12 @@
#ifndef CSM_TOOLS_MERGEOPERATION_H
#define CSM_TOOLS_MERGEOPERATION_H
#include <boost/filesystem/path.hpp>
#include <memory>
#include "../doc/operation.hpp"
#include "mergestate.hpp"
namespace CSMDoc
{
class Document;
@ -14,14 +16,27 @@ namespace CSMTools
{
class MergeOperation : public CSMDoc::Operation
{
Q_OBJECT
MergeState mState;
public:
MergeOperation (CSMDoc::Document& document);
/// \attention Do not call this function while a merge is running.
void setTarget (const boost::filesystem::path& target);
void setTarget (std::auto_ptr<CSMDoc::Document> document);
protected slots:
virtual void operationDone();
signals:
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
};
}

@ -0,0 +1,18 @@
#include "mergestages.hpp"
#include "mergestate.hpp"
CSMTools::FinishMergedDocumentStage::FinishMergedDocumentStage (MergeState& state)
: mState (state)
{}
int CSMTools::FinishMergedDocumentStage::setup()
{
return 1;
}
void CSMTools::FinishMergedDocumentStage::perform (int stage, CSMDoc::Messages& messages)
{
mState.mCompleted = true;
}

@ -0,0 +1,26 @@
#ifndef CSM_TOOLS_MERGESTAGES_H
#define CSM_TOOLS_MERGESTAGES_H
#include "../doc/stage.hpp"
namespace CSMTools
{
struct MergeState;
class FinishMergedDocumentStage : public CSMDoc::Stage
{
MergeState& mState;
public:
FinishMergedDocumentStage (MergeState& state);
virtual int setup();
///< \return number of steps
virtual void perform (int stage, CSMDoc::Messages& messages);
///< Messages resulting from this stage will be appended to \a messages.
};
}
#endif

@ -0,0 +1,20 @@
#ifndef CSM_TOOLS_MERGESTATE_H
#define CSM_TOOLS_MERGESTATE_H
#include <memory>
#include "../doc/document.hpp"
namespace CSMTools
{
struct MergeState
{
std::auto_ptr<CSMDoc::Document> mTarget;
CSMDoc::Document& mSource;
bool mCompleted;
MergeState (CSMDoc::Document& source) : mSource (source), mCompleted (false) {}
};
}
#endif

@ -195,7 +195,7 @@ void CSMTools::Tools::runSearch (const CSMWorld::UniversalId& searchId, const Se
mSearch.start();
}
void CSMTools::Tools::runMerge (const boost::filesystem::path& target)
void CSMTools::Tools::runMerge (std::auto_ptr<CSMDoc::Document> target)
{
// not setting an active report, because merge does not produce messages
@ -203,6 +203,8 @@ void CSMTools::Tools::runMerge (const boost::filesystem::path& target)
{
mMergeOperation = new MergeOperation (mDocument);
mMerge.setOperation (mMergeOperation);
connect (mMergeOperation, SIGNAL (mergeDone (CSMDoc::Document*)),
this, SIGNAL (mergeDone (CSMDoc::Document*)));
}
mMergeOperation->setTarget (target);

@ -1,6 +1,7 @@
#ifndef CSM_TOOLS_TOOLS_H
#define CSM_TOOLS_TOOLS_H
#include <memory>
#include <map>
#include <QObject>
@ -73,7 +74,7 @@ namespace CSMTools
void runSearch (const CSMWorld::UniversalId& searchId, const Search& search);
void runMerge (const boost::filesystem::path& target);
void runMerge (std::auto_ptr<CSMDoc::Document> target);
void abortOperation (int type);
///< \attention The operation is not aborted immediately.
@ -92,6 +93,10 @@ namespace CSMTools
void progress (int current, int max, int type);
void done (int type, bool failed);
/// \attention When this signal is emitted, *this hands over the ownership of the
/// document. This signal must be handled to avoid a leak.
void mergeDone (CSMDoc::Document *document);
};
}

@ -10,6 +10,7 @@
#include <QKeyEvent>
#include "../../model/doc/document.hpp"
#include "../../model/doc/documentmanager.hpp"
#include "../doc/filewidget.hpp"
#include "../doc/adjusterwidget.hpp"
@ -25,8 +26,8 @@ void CSVTools::Merge::keyPressEvent (QKeyEvent *event)
QWidget::keyPressEvent (event);
}
CSVTools::Merge::Merge (QWidget *parent)
: QWidget (parent), mDocument (0)
CSVTools::Merge::Merge (CSMDoc::DocumentManager& documentManager, QWidget *parent)
: QWidget (parent), mDocument (0), mDocumentManager (documentManager)
{
setWindowTitle ("Merge Content Files into a new Game File");
@ -124,7 +125,13 @@ void CSVTools::Merge::accept()
{
if ((mDocument->getState() & CSMDoc::State_Merging)==0)
{
mDocument->runMerge (mAdjuster->getPath());
std::vector< boost::filesystem::path > files (1, mAdjuster->getPath());
std::auto_ptr<CSMDoc::Document> target (
mDocumentManager.makeDocument (files, files[0], true));
mDocument->runMerge (target);
hide();
}
}

@ -11,6 +11,7 @@ class QListWidget;
namespace CSMDoc
{
class Document;
class DocumentManager;
}
namespace CSVDoc
@ -30,12 +31,13 @@ namespace CSVTools
QListWidget *mFiles;
CSVDoc::FileWidget *mNewFile;
CSVDoc::AdjusterWidget *mAdjuster;
CSMDoc::DocumentManager& mDocumentManager;
void keyPressEvent (QKeyEvent *event);
public:
Merge (QWidget *parent = 0);
Merge (CSMDoc::DocumentManager& documentManager, QWidget *parent = 0);
/// Configure dialogue for a new merge
void configure (CSMDoc::Document *document);

Loading…
Cancel
Save