Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / main / UndoCommandDispatch.cxx
blob677ab8fb77ad8a52a360e6c61fa48e20bb27a2bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "UndoCommandDispatch.hxx"
22 #include <com/sun/star/util/XModifyBroadcaster.hpp>
23 #include <com/sun/star/document/UndoFailedException.hpp>
24 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
26 #include <vcl/svapp.hxx>
27 #include <tools/diagnose_ex.h>
29 #include <svtools/strings.hrc>
30 #include <svtools/svtresid.hxx>
32 using namespace ::com::sun::star;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Sequence;
37 namespace chart
40 UndoCommandDispatch::UndoCommandDispatch(
41 const Reference< uno::XComponentContext > & xContext,
42 const Reference< frame::XModel > & xModel ) :
43 CommandDispatch( xContext ),
44 m_xModel( xModel )
46 uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
47 m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_SET_THROW );
50 UndoCommandDispatch::~UndoCommandDispatch()
53 void UndoCommandDispatch::initialize()
55 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
56 ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
57 xBroadcaster->addModifyListener( this );
60 void UndoCommandDispatch::fireStatusEvent(
61 const OUString & rURL,
62 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
64 if( m_xUndoManager.is() )
66 const bool bFireAll = rURL.isEmpty();
67 uno::Any aUndoState, aRedoState;
68 if( m_xUndoManager->isUndoPossible())
69 aUndoState <<= SvtResId( STR_UNDO ) + m_xUndoManager->getCurrentUndoActionTitle();
70 if( m_xUndoManager->isRedoPossible())
71 aRedoState <<= SvtResId( STR_REDO ) + m_xUndoManager->getCurrentRedoActionTitle();
73 if( bFireAll || rURL == ".uno:Undo" )
74 fireStatusEventForURL( ".uno:Undo", aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
75 if( bFireAll || rURL == ".uno:Redo" )
76 fireStatusEventForURL( ".uno:Redo", aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
80 // ____ XDispatch ____
81 void SAL_CALL UndoCommandDispatch::dispatch(
82 const util::URL& URL,
83 const Sequence< beans::PropertyValue >& /* Arguments */ )
85 if( m_xUndoManager.is() )
87 // why is it necessary to lock the solar mutex here?
88 SolarMutexGuard aSolarGuard;
89 try
91 if ( URL.Path == "Undo" )
92 m_xUndoManager->undo();
93 else
94 m_xUndoManager->redo();
96 catch( const document::UndoFailedException& )
98 // silently ignore
100 catch( const uno::Exception& )
102 DBG_UNHANDLED_EXCEPTION("chart2");
104 // \--
108 // ____ WeakComponentImplHelperBase ____
109 /// is called when this is disposed
110 void SAL_CALL UndoCommandDispatch::disposing()
112 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
113 OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
114 if( xBroadcaster.is() )
116 xBroadcaster->removeModifyListener( this );
119 m_xUndoManager.clear();
120 m_xModel.clear();
123 // ____ XEventListener (base of XModifyListener) ____
124 void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
126 m_xUndoManager.clear();
127 m_xModel.clear();
130 } // namespace chart
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */