From ec2fc59fde61b1eea65de2bd870b390b2c47d9a0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 29 Jan 2022 18:33:39 +0100 Subject: [PATCH] App: add a function to document observer to be notified if the active document changes --- src/App/DocumentObserver.cpp | 13 ++++++++----- src/App/DocumentObserver.h | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/App/DocumentObserver.cpp b/src/App/DocumentObserver.cpp index 2aa04a1aa1..927f7d7c8d 100644 --- a/src/App/DocumentObserver.cpp +++ b/src/App/DocumentObserver.cpp @@ -656,15 +656,13 @@ DocumentObserver::DocumentObserver() : _document(nullptr) (&DocumentObserver::slotCreatedDocument, this, sp::_1)); this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(std::bind (&DocumentObserver::slotDeletedDocument, this, sp::_1)); + this->connectApplicationActivateDocument = App::GetApplication().signalActiveDocument.connect(std::bind + (&DocumentObserver::slotActivateDocument, this, sp::_1)); } -DocumentObserver::DocumentObserver(Document* doc) : _document(nullptr) +DocumentObserver::DocumentObserver(Document* doc) : DocumentObserver() { // Connect to application and given document - this->connectApplicationCreatedDocument = App::GetApplication().signalNewDocument.connect(std::bind - (&DocumentObserver::slotCreatedDocument, this, sp::_1)); - this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(std::bind - (&DocumentObserver::slotDeletedDocument, this, sp::_1)); attachDocument(doc); } @@ -673,6 +671,7 @@ DocumentObserver::~DocumentObserver() // disconnect from application and document this->connectApplicationCreatedDocument.disconnect(); this->connectApplicationDeletedDocument.disconnect(); + this->connectApplicationActivateDocument.disconnect(); detachDocument(); } @@ -720,6 +719,10 @@ void DocumentObserver::slotDeletedDocument(const App::Document& /*Doc*/) { } +void DocumentObserver::slotActivateDocument(const App::Document& /*Doc*/) +{ +} + void DocumentObserver::slotCreatedObject(const App::DocumentObject& /*Obj*/) { } diff --git a/src/App/DocumentObserver.h b/src/App/DocumentObserver.h index 1cde5f51d5..4f1a47958f 100644 --- a/src/App/DocumentObserver.h +++ b/src/App/DocumentObserver.h @@ -437,10 +437,12 @@ public: void detachDocument(); private: - /** Checks if a new document was created */ + /** Called when a new document was created */ virtual void slotCreatedDocument(const App::Document& Doc); - /** Checks if the given document is about to be closed */ + /** Called when a document is about to be closed */ virtual void slotDeletedDocument(const App::Document& Doc); + /** Called when a document is activated */ + virtual void slotActivateDocument(const App::Document& Doc); /** Checks if a new object was added. */ virtual void slotCreatedObject(const App::DocumentObject& Obj); /** Checks if the given object is about to be removed. */ @@ -460,6 +462,7 @@ private: typedef boost::signals2::connection Connection; Connection connectApplicationCreatedDocument; Connection connectApplicationDeletedDocument; + Connection connectApplicationActivateDocument; Connection connectDocumentCreatedObject; Connection connectDocumentDeletedObject; Connection connectDocumentChangedObject;