Skip to content

Commit

Permalink
Gui New Feature: Gui::Document support for App::Document undo and red…
Browse files Browse the repository at this point in the history
…o signals

==========================================================================

It defines new slots connected to App::Document's signalUndo/signalRedo, which
triggers Gui::Document's signalUndoDocument and signalRedoDocument signals.

setModified is not executed upon redo/undo, as this is already done on modification of the properties if
properties were modified, and if there were not, no setModified is needed anyway.
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jun 15, 2015
1 parent eb7a3c7 commit da52701
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Gui/Document.cpp
Expand Up @@ -96,6 +96,8 @@ struct DocumentP
Connection connectFinishLoadDocument;
Connection connectExportObjects;
Connection connectImportObjects;
Connection connectUndoDocument;
Connection connectRedoDocument;
};

} // namespace Gui
Expand Down Expand Up @@ -142,6 +144,11 @@ Document::Document(App::Document* pcDocument,Application * app)
(boost::bind(&Gui::Document::exportObjects, this, _1, _2));
d->connectImportObjects = pcDocument->signalImportViewObjects.connect
(boost::bind(&Gui::Document::importObjects, this, _1, _2, _3));

d->connectUndoDocument = pcDocument->signalUndo.connect
(boost::bind(&Gui::Document::slotUndoDocument, this, _1));
d->connectRedoDocument = pcDocument->signalRedo.connect
(boost::bind(&Gui::Document::slotRedoDocument, this, _1));

// pointer to the python class
// NOTE: As this Python object doesn't get returned to the interpreter we
Expand Down Expand Up @@ -171,6 +178,8 @@ Document::~Document()
d->connectFinishLoadDocument.disconnect();
d->connectExportObjects.disconnect();
d->connectImportObjects.disconnect();
d->connectUndoDocument.disconnect();
d->connectRedoDocument.disconnect();

// e.g. if document gets closed from within a Python command
d->_isClosing = true;
Expand Down Expand Up @@ -535,6 +544,22 @@ void Document::slotActivatedObject(const App::DocumentObject& Obj)
}
}

void Document::slotUndoDocument(const App::Document& doc)
{
if (d->_pcDocument != &doc)
return;

signalUndoDocument(*this);
}

void Document::slotRedoDocument(const App::Document& doc)
{
if (d->_pcDocument != &doc)
return;

signalRedoDocument(*this);
}

void Document::setModified(bool b)
{
d->_isModified = b;
Expand Down
7 changes: 6 additions & 1 deletion src/Gui/Document.h
Expand Up @@ -77,6 +77,8 @@ class GuiExport Document : public Base::Persistence
void slotActivatedObject(const App::DocumentObject&);
void slotStartRestoreDocument(const App::Document&);
void slotFinishRestoreDocument(const App::Document&);
void slotUndoDocument(const App::Document&);
void slotRedoDocument(const App::Document&);
//@}

public:
Expand Down Expand Up @@ -105,7 +107,10 @@ class GuiExport Document : public Base::Persistence
/// signal on changed Object, the 2nd argument is the highlite mode to use
mutable boost::signal<void (const Gui::ViewProviderDocumentObject&,
const Gui::TreeItemMode&)> signalExpandObject;

/// signal on undo Document
mutable boost::signal<void (const Gui::Document& doc)> signalUndoDocument;
/// signal on redo Document
mutable boost::signal<void (const Gui::Document& doc)> signalRedoDocument;
//@}

/** @name I/O of the document */
Expand Down

0 comments on commit da52701

Please sign in to comment.