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