LCOV - code coverage report
Current view: top level - chart2/source/controller/main - UndoCommandDispatch.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 42 47 89.4 %
Date: 2014-04-11 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             : // for resource strings STR_UNDO and STR_REDO
      32             : #include <svtools/svtools.hrc>
      33             : #include <svtools/svtresid.hxx>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : 
      37             : using ::com::sun::star::uno::Reference;
      38             : using ::com::sun::star::uno::Sequence;
      39             : 
      40             : namespace chart
      41             : {
      42             : 
      43          17 : UndoCommandDispatch::UndoCommandDispatch(
      44             :     const Reference< uno::XComponentContext > & xContext,
      45             :     const Reference< frame::XModel > & xModel ) :
      46             :         CommandDispatch( xContext ),
      47          17 :         m_xModel( xModel )
      48             : {
      49          17 :     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
      50          17 :     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
      51          17 : }
      52             : 
      53          34 : UndoCommandDispatch::~UndoCommandDispatch()
      54          34 : {}
      55             : 
      56          17 : void UndoCommandDispatch::initialize()
      57             : {
      58          17 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
      59          34 :     ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
      60          17 :     xBroadcaster->addModifyListener( this );
      61             : }
      62             : 
      63         153 : void UndoCommandDispatch::fireStatusEvent(
      64             :     const OUString & rURL,
      65             :     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
      66             : {
      67         153 :     if( m_xUndoManager.is() )
      68             :     {
      69         153 :         const bool bFireAll = rURL.isEmpty();
      70         306 :         uno::Any aUndoState, aRedoState;
      71         153 :         if( m_xUndoManager->isUndoPossible())
      72             :         {
      73             :             // using assignment for broken gcc 3.3
      74          56 :             OUString aUndo = SvtResId( STR_UNDO ).toString();
      75          56 :             aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
      76             :         }
      77         153 :         if( m_xUndoManager->isRedoPossible())
      78             :         {
      79             :             // using assignment for broken gcc 3.3
      80          23 :             OUString aRedo = SvtResId( STR_REDO ).toString();
      81          23 :             aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
      82             :         }
      83             : 
      84         153 :         if( bFireAll || rURL == ".uno:Undo" )
      85         136 :             fireStatusEventForURL( ".uno:Undo", aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
      86         153 :         if( bFireAll || rURL == ".uno:Redo" )
      87         289 :             fireStatusEventForURL( ".uno:Redo", aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
      88             :     }
      89         153 : }
      90             : 
      91             : // ____ XDispatch ____
      92           4 : void SAL_CALL UndoCommandDispatch::dispatch(
      93             :     const util::URL& URL,
      94             :     const Sequence< beans::PropertyValue >& /* Arguments */ )
      95             :     throw (uno::RuntimeException, std::exception)
      96             : {
      97           4 :     if( m_xUndoManager.is() )
      98             :     {
      99             :         // why is it necessary to lock the solar mutex here?
     100           4 :         SolarMutexGuard aSolarGuard;
     101             :         try
     102             :         {
     103           4 :             if ( URL.Path == "Undo" )
     104           3 :                 m_xUndoManager->undo();
     105             :             else
     106           1 :                 m_xUndoManager->redo();
     107             :         }
     108           2 :         catch( const document::UndoFailedException& )
     109             :         {
     110             :             // silently ignore
     111             :         }
     112           0 :         catch( const uno::Exception& )
     113             :         {
     114             :             DBG_UNHANDLED_EXCEPTION();
     115           4 :         }
     116             :         // \--
     117             :     }
     118           4 : }
     119             : 
     120             : // ____ WeakComponentImplHelperBase ____
     121             : /// is called when this is disposed
     122          17 : void SAL_CALL UndoCommandDispatch::disposing()
     123             : {
     124          17 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
     125             :     OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
     126          17 :     if( xBroadcaster.is() )
     127             :     {
     128          17 :         xBroadcaster->removeModifyListener( this );
     129             :     }
     130             : 
     131          17 :     m_xUndoManager.clear();
     132          17 :     m_xModel.clear();
     133          17 : }
     134             : 
     135             : // ____ XEventListener (base of XModifyListener) ____
     136           0 : void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
     137             :     throw (uno::RuntimeException, std::exception)
     138             : {
     139           0 :     m_xUndoManager.clear();
     140           0 :     m_xModel.clear();
     141           0 : }
     142             : 
     143             : } //  namespace chart
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10