1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
21 #include <ChartModel.hxx>
23 #include <com/sun/star/util/XModifyBroadcaster.hpp>
24 #include <com/sun/star/document/UndoFailedException.hpp>
27 #include <vcl/svapp.hxx>
28 #include <comphelper/diagnose_ex.hxx>
30 #include <svtools/strings.hrc>
31 #include <svtools/svtresid.hxx>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
41 UndoCommandDispatch::UndoCommandDispatch(
42 const Reference
< uno::XComponentContext
> & xContext
,
43 rtl::Reference
<::chart::ChartModel
> xModel
) :
44 CommandDispatch( xContext
),
45 m_xModel(std::move( xModel
))
47 m_xUndoManager
.set( m_xModel
->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() )
67 const bool bFireAll
= rURL
.isEmpty();
68 uno::Any aUndoState
, aRedoState
, aUndoStrings
, aRedoStrings
;
69 if( m_xUndoManager
->isUndoPossible())
70 aUndoState
<<= SvtResId( STR_UNDO
) + m_xUndoManager
->getCurrentUndoActionTitle();
71 if( m_xUndoManager
->isRedoPossible())
72 aRedoState
<<= SvtResId( STR_REDO
) + m_xUndoManager
->getCurrentRedoActionTitle();
74 aUndoStrings
<<= m_xUndoManager
->getAllUndoActionTitles();
75 aRedoStrings
<<= m_xUndoManager
->getAllRedoActionTitles();
77 if( bFireAll
|| rURL
== ".uno:Undo" )
78 fireStatusEventForURL( u
".uno:Undo"_ustr
, aUndoState
, m_xUndoManager
->isUndoPossible(), xSingleListener
);
79 if( bFireAll
|| rURL
== ".uno:Redo" )
80 fireStatusEventForURL( u
".uno:Redo"_ustr
, aRedoState
, m_xUndoManager
->isRedoPossible(), xSingleListener
);
81 if( bFireAll
|| rURL
== ".uno:GetUndoStrings" )
82 fireStatusEventForURL( u
".uno:GetUndoStrings"_ustr
, aUndoStrings
, true, xSingleListener
);
83 if( bFireAll
|| rURL
== ".uno:GetRedoStrings" )
84 fireStatusEventForURL( u
".uno:GetRedoStrings"_ustr
, aRedoStrings
, true, xSingleListener
);
87 // ____ XDispatch ____
88 void SAL_CALL
UndoCommandDispatch::dispatch(
90 const Sequence
< beans::PropertyValue
>& Arguments
)
92 if( !m_xUndoManager
.is() )
95 // why is it necessary to lock the solar mutex here?
96 SolarMutexGuard aSolarGuard
;
99 sal_Int16
nCount( 1 );
100 if ( Arguments
.hasElements() && Arguments
[0].Name
== URL
.Path
)
101 Arguments
[0].Value
>>= nCount
;
105 if ( URL
.Path
== "Undo" )
106 m_xUndoManager
->undo();
108 m_xUndoManager
->redo();
111 catch( const document::UndoFailedException
& )
115 catch( const uno::Exception
& )
117 DBG_UNHANDLED_EXCEPTION("chart2");
122 // ____ WeakComponentImplHelperBase ____
123 /// is called when this is disposed
124 void UndoCommandDispatch::disposing(std::unique_lock
<std::mutex
>& /*rGuard*/)
126 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xUndoManager
, uno::UNO_QUERY
);
127 OSL_ENSURE( xBroadcaster
.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
128 if( xBroadcaster
.is() )
130 xBroadcaster
->removeModifyListener( this );
133 m_xUndoManager
.clear();
137 // ____ XEventListener (base of XModifyListener) ____
138 void SAL_CALL
UndoCommandDispatch::disposing( const lang::EventObject
& /* Source */ )
140 m_xUndoManager
.clear();
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */