LCOV - code coverage report
Current view: top level - chart2/source/controller/main - UndoCommandDispatch.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 43 48 89.6 %
Date: 2014-11-03 Functions: 9 10 90.0 %
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          27 : UndoCommandDispatch::UndoCommandDispatch(
      43             :     const Reference< uno::XComponentContext > & xContext,
      44             :     const Reference< frame::XModel > & xModel ) :
      45             :         CommandDispatch( xContext ),
      46          27 :         m_xModel( xModel )
      47             : {
      48          27 :     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
      49          27 :     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
      50          27 : }
      51             : 
      52          54 : UndoCommandDispatch::~UndoCommandDispatch()
      53          54 : {}
      54             : 
      55          27 : void UndoCommandDispatch::initialize()
      56             : {
      57          27 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
      58          54 :     ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
      59          27 :     xBroadcaster->addModifyListener( this );
      60             : }
      61             : 
      62         292 : void UndoCommandDispatch::fireStatusEvent(
      63             :     const OUString & rURL,
      64             :     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
      65             : {
      66         292 :     if( m_xUndoManager.is() )
      67             :     {
      68         292 :         const bool bFireAll = rURL.isEmpty();
      69         584 :         uno::Any aUndoState, aRedoState;
      70         292 :         if( m_xUndoManager->isUndoPossible())
      71             :         {
      72             :             // using assignment for broken gcc 3.3
      73         112 :             OUString aUndo = SvtResId( STR_UNDO ).toString();
      74         112 :             aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
      75             :         }
      76         292 :         if( m_xUndoManager->isRedoPossible())
      77             :         {
      78             :             // using assignment for broken gcc 3.3
      79          46 :             OUString aRedo = SvtResId( STR_REDO ).toString();
      80          46 :             aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
      81             :         }
      82             : 
      83         292 :         if( bFireAll || rURL == ".uno:Undo" )
      84         265 :             fireStatusEventForURL( ".uno:Undo", aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
      85         292 :         if( bFireAll || rURL == ".uno:Redo" )
      86         557 :             fireStatusEventForURL( ".uno:Redo", aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
      87             :     }
      88         292 : }
      89             : 
      90             : // ____ XDispatch ____
      91           8 : void SAL_CALL UndoCommandDispatch::dispatch(
      92             :     const util::URL& URL,
      93             :     const Sequence< beans::PropertyValue >& /* Arguments */ )
      94             :     throw (uno::RuntimeException, std::exception)
      95             : {
      96           8 :     if( m_xUndoManager.is() )
      97             :     {
      98             :         // why is it necessary to lock the solar mutex here?
      99           8 :         SolarMutexGuard aSolarGuard;
     100             :         try
     101             :         {
     102           8 :             if ( URL.Path == "Undo" )
     103           6 :                 m_xUndoManager->undo();
     104             :             else
     105           2 :                 m_xUndoManager->redo();
     106             :         }
     107           4 :         catch( const document::UndoFailedException& )
     108             :         {
     109             :             // silently ignore
     110             :         }
     111           0 :         catch( const uno::Exception& )
     112             :         {
     113             :             DBG_UNHANDLED_EXCEPTION();
     114           8 :         }
     115             :         // \--
     116             :     }
     117           8 : }
     118             : 
     119             : // ____ WeakComponentImplHelperBase ____
     120             : /// is called when this is disposed
     121          27 : void SAL_CALL UndoCommandDispatch::disposing()
     122             : {
     123          27 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
     124             :     OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
     125          27 :     if( xBroadcaster.is() )
     126             :     {
     127          27 :         xBroadcaster->removeModifyListener( this );
     128             :     }
     129             : 
     130          27 :     m_xUndoManager.clear();
     131          27 :     m_xModel.clear();
     132          27 : }
     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         102 : } //  namespace chart
     143             : 
     144             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10