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

Generated by: LCOV version 1.10