diff --git a/core/document.cpp b/core/document.cpp index 18787ac4a..cfad3b4d5 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2634,6 +2634,8 @@ void Document::closeDocument() if ( !d->m_generator ) return; + emit aboutToClose(); + delete d->m_pageController; d->m_pageController = nullptr; @@ -4079,6 +4081,10 @@ void Document::processAction( const Action * action ) if ( !action ) return; + // Don't execute next actions if the action itself caused the closing of the document + bool executeNextActions = true; + auto connectionId = connect( this, &Document::aboutToClose, [&executeNextActions] { executeNextActions = false; } ); + switch( action->actionType() ) { case Action::Goto: { @@ -4277,9 +4283,14 @@ void Document::processAction( const Action * action ) } - for ( const Action *a : action->nextActions() ) + disconnect( connectionId ); + + if ( executeNextActions ) { - processAction( a ); + for ( const Action *a : action->nextActions() ) + { + processAction( a ); + } } } diff --git a/core/document.h b/core/document.h index 3354e55ae..4e9f7ca30 100644 --- a/core/document.h +++ b/core/document.h @@ -1022,6 +1022,12 @@ class OKULARCORE_EXPORT Document : public QObject void reloadDocument() const; Q_SIGNALS: + /** + * This signal is emitted whenever the document is about to close. + * @since 1.5.3 + */ + void aboutToClose(); + /** * This signal is emitted whenever an action requests a * document close operation.