LCOV - code coverage report
Current view: top level - chart2/source/controller/main - UndoCommandDispatch.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 47 89.4 %
Date: 2015-06-13 12:38:46 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "UndoCommandDispatch.hxx"
      21             : #include "ResId.hxx"
      22             : #include "macros.hxx"
      23             : 
      24             : #include <com/sun/star/util/XModifyBroadcaster.hpp>
      25             : #include <com/sun/star/document/XUndoManagerSupplier.hpp>
      26             : 
      27             : #include <osl/mutex.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <tools/diagnose_ex.h>
      30             : 
      31             : #include <svtools/svtools.hrc>
      32             : #include <svtools/svtresid.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : using ::com::sun::star::uno::Reference;
      37             : using ::com::sun::star::uno::Sequence;
      38             : 
      39             : namespace chart
      40             : {
      41             : 
      42          17 : UndoCommandDispatch::UndoCommandDispatch(
      43             :     const Reference< uno::XComponentContext > & xContext,
      44             :     const Reference< frame::XModel > & xModel ) :
      45             :         CommandDispatch( xContext ),
      46          17 :         m_xModel( xModel )
      47             : {
      48          17 :     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
      49          17 :     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
      50          17 : }
      51             : 
      52          34 : UndoCommandDispatch::~UndoCommandDispatch()
      53          34 : {}
      54             : 
      55          17 : void UndoCommandDispatch::initialize()
      56             : {
      57          17 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
      58          34 :     ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
      59          17 :     xBroadcaster->addModifyListener( this );
      60             : }
      61             : 
      62         153 : void UndoCommandDispatch::fireStatusEvent(
      63             :     const OUString & rURL,
      64             :     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
      65             : {
      66         153 :     if( m_xUndoManager.is() )
      67             :     {
      68         153 :         const bool bFireAll = rURL.isEmpty();
      69         306 :         uno::Any aUndoState, aRedoState;
      70         153 :         if( m_xUndoManager->isUndoPossible())
      71             :         {
      72             :             // using assignment for broken gcc 3.3
      73          56 :             OUString aUndo = SvtResId( STR_UNDO ).toString();
      74          56 :             aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
      75             :         }
      76         153 :         if( m_xUndoManager->isRedoPossible())
      77             :         {
      78             :             // using assignment for broken gcc 3.3
      79          23 :             OUString aRedo = SvtResId( STR_REDO ).toString();
      80          23 :             aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
      81             :         }
      82             : 
      83         153 :         if( bFireAll || rURL == ".uno:Undo" )
      84         136 :             fireStatusEventForURL( ".uno:Undo", aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
      85         153 :         if( bFireAll || rURL == ".uno:Redo" )
      86         289 :             fireStatusEventForURL( ".uno:Redo", aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
      87             :     }
      88         153 : }
      89             : 
      90             : // ____ XDispatch ____
      91           4 : void SAL_CALL UndoCommandDispatch::dispatch(
      92             :     const util::URL& URL,
      93             :     const Sequence< beans::PropertyValue >& /* Arguments */ )
      94             :     throw (uno::RuntimeException, std::exception)
      95             : {
      96           4 :     if( m_xUndoManager.is() )
      97             :     {
      98             :         // why is it necessary to lock the solar mutex here?
      99           4 :         SolarMutexGuard aSolarGuard;
     100             :         try
     101             :         {
     102           4 :             if ( URL.Path == "Undo" )
     103           3 :                 m_xUndoManager->undo();
     104             :             else
     105           1 :                 m_xUndoManager->redo();
     106             :         }
     107           2 :         catch( const document::UndoFailedException& )
     108             :         {
     109             :             // silently ignore
     110             :         }
     111           0 :         catch( const uno::Exception& )
     112             :         {
     113             :             DBG_UNHANDLED_EXCEPTION();
     114           4 :         }
     115             :         // \--
     116             :     }
     117           4 : }
     118             : 
     119             : // ____ WeakComponentImplHelperBase ____
     120             : /// is called when this is disposed
     121          17 : void SAL_CALL UndoCommandDispatch::disposing()
     122             : {
     123          17 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
     124             :     OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
     125          17 :     if( xBroadcaster.is() )
     126             :     {
     127          17 :         xBroadcaster->removeModifyListener( this );
     128             :     }
     129             : 
     130          17 :     m_xUndoManager.clear();
     131          17 :     m_xModel.clear();
     132          17 : }
     133             : 
     134             : // ____ XEventListener (base of XModifyListener) ____
     135           0 : void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
     136             :     throw (uno::RuntimeException, std::exception)
     137             : {
     138           0 :     m_xUndoManager.clear();
     139           0 :     m_xModel.clear();
     140           0 : }
     141             : 
     142             : } //  namespace chart
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11