flatten DocumentUndoGuard

which is a small object, and doesn't need a pimpl pattern

Change-Id: Ib76f6e5ad0347be61fe29b22f57e1211ce3337cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148172
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2023-03-03 13:15:24 +02:00
parent e55096a07a
commit 37a4d67d68
2 changed files with 29 additions and 55 deletions

View file

@ -44,8 +44,6 @@ namespace framework
typedef ::cppu::WeakImplHelper < XUndoManagerListener
> UndoManagerContextListener_Base;
namespace {
class UndoManagerContextListener : public UndoManagerContextListener_Base
{
public:
@ -100,8 +98,6 @@ namespace framework
bool m_documentDisposed;
};
}
void SAL_CALL UndoManagerContextListener::undoActionAdded( const UndoManagerEvent& )
{
// not interested in
@ -162,60 +158,37 @@ namespace framework
m_documentDisposed = true;
}
//= DocumentUndoGuard_Data
struct DocumentUndoGuard_Data
{
Reference< XUndoManager > xUndoManager;
::rtl::Reference< UndoManagerContextListener > pContextListener;
};
namespace
{
void lcl_init( DocumentUndoGuard_Data& i_data, const Reference< XInterface >& i_undoSupplierComponent )
{
try
{
Reference< XUndoManagerSupplier > xUndoSupplier( i_undoSupplierComponent, UNO_QUERY );
if ( xUndoSupplier.is() )
i_data.xUndoManager.set( xUndoSupplier->getUndoManager(), css::uno::UNO_SET_THROW );
if ( i_data.xUndoManager.is() )
i_data.pContextListener.set( new UndoManagerContextListener( i_data.xUndoManager ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("fwk");
}
}
void lcl_restore( DocumentUndoGuard_Data& i_data )
{
try
{
if ( i_data.pContextListener.is() )
i_data.pContextListener->finish();
i_data.pContextListener.clear();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("fwk");
}
}
}
//= DocumentUndoGuard
DocumentUndoGuard::DocumentUndoGuard( const Reference< XInterface >& i_undoSupplierComponent )
:m_xData( new DocumentUndoGuard_Data )
{
lcl_init( *m_xData, i_undoSupplierComponent );
try
{
Reference< XUndoManagerSupplier > xUndoSupplier( i_undoSupplierComponent, UNO_QUERY );
if ( xUndoSupplier.is() )
mxUndoManager.set( xUndoSupplier->getUndoManager(), css::uno::UNO_SET_THROW );
if ( mxUndoManager.is() )
mxContextListener.set( new UndoManagerContextListener( mxUndoManager ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("fwk");
}
}
DocumentUndoGuard::~DocumentUndoGuard()
{
lcl_restore( *m_xData );
try
{
if ( mxContextListener.is() )
mxContextListener->finish();
mxContextListener.clear();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("fwk");
}
}
} // namespace framework

View file

@ -21,18 +21,18 @@
#define INCLUDED_FRAMEWORK_DOCUMENTUNDOGUARD_HXX
#include <framework/fwkdllapi.h>
#include <com/sun/star/uno/Reference.hxx>
#include <memory>
#include <rtl/ref.hxx>
namespace com::sun::star::uno { class XInterface; }
namespace com::sun::star::document { class XUndoManager; }
namespace framework
{
class UndoManagerContextListener;
//= DocumentUndoGuard
struct DocumentUndoGuard_Data;
/** a helper class guarding the Undo manager of a document
This class guards, within a given scope, the Undo Manager of a document (or another component supporting
@ -49,7 +49,8 @@ namespace framework
~DocumentUndoGuard();
private:
std::unique_ptr< DocumentUndoGuard_Data > m_xData;
css::uno::Reference< css::document::XUndoManager > mxUndoManager;
::rtl::Reference< UndoManagerContextListener > mxContextListener;
};