LCOV - code coverage report
Current view: top level - chart2/source/controller/main - UndoCommandDispatch.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 47 89.4 %
Date: 2012-08-25 Functions: 7 8 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 71 125 56.8 %

           Branch data     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                 :            : using ::rtl::OUString;
      41                 :            : 
      42                 :            : namespace chart
      43                 :            : {
      44                 :            : 
      45                 :         34 : UndoCommandDispatch::UndoCommandDispatch(
      46                 :            :     const Reference< uno::XComponentContext > & xContext,
      47                 :            :     const Reference< frame::XModel > & xModel ) :
      48                 :            :         CommandDispatch( xContext ),
      49                 :         34 :         m_xModel( xModel )
      50                 :            : {
      51         [ +  - ]:         34 :     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
      52 [ +  - ][ +  - ]:         34 :     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
                 [ +  - ]
      53                 :         34 : }
      54                 :            : 
      55                 :         34 : UndoCommandDispatch::~UndoCommandDispatch()
      56         [ -  + ]:         68 : {}
      57                 :            : 
      58                 :         34 : void UndoCommandDispatch::initialize()
      59                 :            : {
      60         [ +  - ]:         34 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
      61         [ -  + ]:         68 :     ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
      62 [ +  - ][ +  - ]:         34 :     xBroadcaster->addModifyListener( this );
         [ +  - ][ +  - ]
      63                 :            : }
      64                 :            : 
      65                 :        306 : void UndoCommandDispatch::fireStatusEvent(
      66                 :            :     const OUString & rURL,
      67                 :            :     const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
      68                 :            : {
      69         [ +  - ]:        306 :     if( m_xUndoManager.is() )
      70                 :            :     {
      71                 :        306 :         bool bFireAll = rURL.isEmpty();
      72                 :        306 :         uno::Any aUndoState, aRedoState;
      73 [ +  - ][ +  + ]:        306 :         if( m_xUndoManager->isUndoPossible())
                 [ +  - ]
      74                 :            :         {
      75                 :            :             // using assignment for broken gcc 3.3
      76 [ +  - ][ +  - ]:        112 :             OUString aUndo = OUString( String( SvtResId( STR_UNDO )));
         [ +  - ][ +  - ]
      77 [ +  - ][ +  - ]:        112 :             aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
                 [ +  - ]
      78                 :            :         }
      79 [ +  - ][ +  - ]:        306 :         if( m_xUndoManager->isRedoPossible())
                 [ +  + ]
      80                 :            :         {
      81                 :            :             // using assignment for broken gcc 3.3
      82 [ +  - ][ +  - ]:         46 :             OUString aRedo = OUString( String( SvtResId( STR_REDO )));
         [ +  - ][ +  - ]
      83 [ +  - ][ +  - ]:         46 :             aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
                 [ +  - ]
      84                 :            :         }
      85                 :            : 
      86 [ +  + ][ +  + ]:        306 :         if( bFireAll || rURL == ".uno:Undo" )
                 [ +  + ]
      87 [ +  - ][ +  - ]:        272 :             fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
         [ +  - ][ +  - ]
      88 [ +  + ][ +  + ]:        306 :         if( bFireAll || rURL == ".uno:Redo" )
                 [ +  + ]
      89 [ +  - ][ +  - ]:        306 :             fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
         [ +  - ][ +  - ]
      90                 :            :     }
      91                 :        306 : }
      92                 :            : 
      93                 :            : // ____ XDispatch ____
      94                 :          8 : void SAL_CALL UndoCommandDispatch::dispatch(
      95                 :            :     const util::URL& URL,
      96                 :            :     const Sequence< beans::PropertyValue >& /* Arguments */ )
      97                 :            :     throw (uno::RuntimeException)
      98                 :            : {
      99         [ +  - ]:          8 :     if( m_xUndoManager.is() )
     100                 :            :     {
     101                 :            :         // why is it necessary to lock the solar mutex here?
     102         [ +  - ]:          8 :         SolarMutexGuard aSolarGuard;
     103                 :            :         try
     104                 :            :         {
     105         [ +  + ]:          8 :             if ( URL.Path == "Undo" )
     106 [ +  - ][ +  + ]:          6 :                 m_xUndoManager->undo();
     107                 :            :             else
     108 [ +  - ][ -  + ]:          2 :                 m_xUndoManager->redo();
     109                 :            :         }
     110         [ +  - ]:          4 :         catch( const document::UndoFailedException& )
     111                 :            :         {
     112                 :            :             // silently ignore
     113                 :            :         }
     114         [ #  # ]:          0 :         catch( const uno::Exception& )
     115                 :            :         {
     116                 :            :             DBG_UNHANDLED_EXCEPTION();
     117         [ +  - ]:          8 :         }
     118                 :            :         // \--
     119                 :            :     }
     120      [ -  +  - ]:         12 : }
     121                 :            : 
     122                 :            : // ____ WeakComponentImplHelperBase ____
     123                 :            : /// is called when this is disposed
     124                 :         34 : void SAL_CALL UndoCommandDispatch::disposing()
     125                 :            : {
     126         [ +  - ]:         34 :     Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
     127                 :            :     OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
     128         [ +  - ]:         34 :     if( xBroadcaster.is() )
     129                 :            :     {
     130 [ +  - ][ +  - ]:         34 :         xBroadcaster->removeModifyListener( this );
                 [ +  - ]
     131                 :            :     }
     132                 :            : 
     133                 :         34 :     m_xUndoManager.clear();
     134                 :         34 :     m_xModel.clear();
     135                 :         34 : }
     136                 :            : 
     137                 :            : // ____ XEventListener (base of XModifyListener) ____
     138                 :          0 : void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
     139                 :            :     throw (uno::RuntimeException)
     140                 :            : {
     141                 :          0 :     m_xUndoManager.clear();
     142                 :          0 :     m_xModel.clear();
     143                 :          0 : }
     144                 :            : 
     145                 :            : } //  namespace chart
     146                 :            : 
     147                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10