From a8690339257b65849e48222e7c4a84b7188037c4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 18 Feb 2015 21:36:47 +0100 Subject: [PATCH] + add slots for undo/redo to Python document observer --- src/App/DocumentObserverPython.cpp | 40 ++++++++++++++++++++++++++++++ src/App/DocumentObserverPython.h | 6 +++++ 2 files changed, 46 insertions(+) diff --git a/src/App/DocumentObserverPython.cpp b/src/App/DocumentObserverPython.cpp index ba94b55b1..0bfe02807 100644 --- a/src/App/DocumentObserverPython.cpp +++ b/src/App/DocumentObserverPython.cpp @@ -67,6 +67,10 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj (&DocumentObserverPython::slotRelabelDocument, this, _1)); this->connectApplicationActivateDocument = App::GetApplication().signalActiveDocument.connect(boost::bind (&DocumentObserverPython::slotActivateDocument, this, _1)); + this->connectApplicationUndoDocument = App::GetApplication().signalUndoDocument.connect(boost::bind + (&DocumentObserverPython::slotUndoDocument, this, _1)); + this->connectApplicationRedoDocument = App::GetApplication().signalRedoDocument.connect(boost::bind + (&DocumentObserverPython::slotRedoDocument, this, _1)); this->connectDocumentCreatedObject = App::GetApplication().signalNewObject.connect(boost::bind (&DocumentObserverPython::slotCreatedObject, this, _1)); @@ -82,6 +86,8 @@ DocumentObserverPython::~DocumentObserverPython() this->connectApplicationDeletedDocument.disconnect(); this->connectApplicationRelabelDocument.disconnect(); this->connectApplicationActivateDocument.disconnect(); + this->connectApplicationUndoDocument.disconnect(); + this->connectApplicationRedoDocument.disconnect(); this->connectDocumentCreatedObject.disconnect(); this->connectDocumentDeletedObject.disconnect(); @@ -156,6 +162,40 @@ void DocumentObserverPython::slotActivateDocument(const App::Document& Doc) } } +void DocumentObserverPython::slotUndoDocument(const App::Document& Doc) +{ + Base::PyGILStateLocker lock; + try { + if (this->inst.hasAttr(std::string("slotUndoDocument"))) { + Py::Callable method(this->inst.getAttr(std::string("slotUndoDocument"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(const_cast(Doc).getPyObject(), true)); + method.apply(args); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + +void DocumentObserverPython::slotRedoDocument(const App::Document& Doc) +{ + Base::PyGILStateLocker lock; + try { + if (this->inst.hasAttr(std::string("slotRedoDocument"))) { + Py::Callable method(this->inst.getAttr(std::string("slotRedoDocument"))); + Py::Tuple args(1); + args.setItem(0, Py::Object(const_cast(Doc).getPyObject(), true)); + method.apply(args); + } + } + catch (Py::Exception&) { + Base::PyException e; // extract the Python error text + e.ReportException(); + } +} + void DocumentObserverPython::slotCreatedObject(const App::DocumentObject& Obj) { Base::PyGILStateLocker lock; diff --git a/src/App/DocumentObserverPython.h b/src/App/DocumentObserverPython.h index b3289fc6d..e83c220c2 100644 --- a/src/App/DocumentObserverPython.h +++ b/src/App/DocumentObserverPython.h @@ -65,6 +65,10 @@ private: void slotDeletedObject(const App::DocumentObject& Obj); /** The property of an observed object has changed */ void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop); + /** Undoes the last transaction of the document */ + void slotUndoDocument(const App::Document& Doc); + /** Redoes the last undone transaction of the document */ + void slotRedoDocument(const App::Document& Doc); private: Py::Object inst; @@ -75,6 +79,8 @@ private: Connection connectApplicationDeletedDocument; Connection connectApplicationRelabelDocument; Connection connectApplicationActivateDocument; + Connection connectApplicationUndoDocument; + Connection connectApplicationRedoDocument; Connection connectDocumentCreatedObject; Connection connectDocumentDeletedObject; Connection connectDocumentChangedObject;