LCOV - code coverage report
Current view: top level - sw/source/core/undo - unbkmk.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 65 65 100.0 %
Date: 2015-06-13 12:38:46 Functions: 21 22 95.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 <UndoBookmark.hxx>
      21             : 
      22             : #include <comcore.hrc>
      23             : #include "doc.hxx"
      24             : #include "docary.hxx"
      25             : #include "swundo.hxx"
      26             : #include "pam.hxx"
      27             : 
      28             : #include <UndoCore.hxx>
      29             : #include "IMark.hxx"
      30             : #include "rolbck.hxx"
      31             : 
      32             : #include "SwRewriter.hxx"
      33             : 
      34        1043 : SwUndoBookmark::SwUndoBookmark( SwUndoId nUndoId,
      35             :             const ::sw::mark::IMark& rBkmk )
      36             :     : SwUndo( nUndoId )
      37        1043 :     , m_pHistoryBookmark(new SwHistoryBookmark(rBkmk, true, rBkmk.IsExpanded()))
      38             : {
      39        1043 : }
      40             : 
      41        1041 : SwUndoBookmark::~SwUndoBookmark()
      42             : {
      43        1041 : }
      44             : 
      45           2 : void SwUndoBookmark::SetInDoc( SwDoc* pDoc )
      46             : {
      47           2 :     m_pHistoryBookmark->SetInDoc( pDoc, false );
      48           2 : }
      49             : 
      50           2 : void SwUndoBookmark::ResetInDoc( SwDoc* pDoc )
      51             : {
      52           2 :     IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
      53           6 :     for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
      54           4 :           ppBkmk != pMarkAccess->getAllMarksEnd();
      55             :           ++ppBkmk )
      56             :     {
      57           2 :         if ( m_pHistoryBookmark->IsEqualBookmark( **ppBkmk ) )
      58             :         {
      59           2 :             pMarkAccess->deleteMark( ppBkmk );
      60           2 :             break;
      61             :         }
      62             :     }
      63           2 : }
      64             : 
      65        1043 : SwRewriter SwUndoBookmark::GetRewriter() const
      66             : {
      67        1043 :     SwRewriter aResult;
      68             : 
      69        1043 :     aResult.AddRule(UndoArg1, m_pHistoryBookmark->GetName());
      70             : 
      71        1043 :     return aResult;
      72             : }
      73             : 
      74        1041 : SwUndoInsBookmark::SwUndoInsBookmark( const ::sw::mark::IMark& rBkmk )
      75        1041 :     : SwUndoBookmark( UNDO_INSBOOKMARK, rBkmk )
      76             : {
      77        1041 : }
      78             : 
      79           1 : void SwUndoInsBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
      80             : {
      81           1 :     ResetInDoc( &rContext.GetDoc() );
      82           1 : }
      83             : 
      84           1 : void SwUndoInsBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
      85             : {
      86           1 :     SetInDoc( &rContext.GetDoc() );
      87           1 : }
      88             : 
      89           2 : SwUndoDeleteBookmark::SwUndoDeleteBookmark( const ::sw::mark::IMark& rBkmk )
      90           2 :     : SwUndoBookmark( UNDO_DELBOOKMARK, rBkmk )
      91             : {
      92           2 : }
      93             : 
      94           1 : void SwUndoDeleteBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
      95             : {
      96           1 :     SetInDoc( &rContext.GetDoc() );
      97           1 : }
      98             : 
      99           1 : void SwUndoDeleteBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
     100             : {
     101           1 :     ResetInDoc( &rContext.GetDoc() );
     102           1 : }
     103             : 
     104           3 : SwUndoRenameBookmark::SwUndoRenameBookmark( const OUString& rOldName, const OUString& rNewName )
     105             :     : SwUndo( UNDO_BOOKMARK_RENAME )
     106             :     , m_sOldName( rOldName )
     107           3 :     , m_sNewName( rNewName )
     108             : {
     109           3 : }
     110             : 
     111           6 : SwUndoRenameBookmark::~SwUndoRenameBookmark()
     112             : {
     113           6 : }
     114             : 
     115           6 : static OUString lcl_QuoteName(const OUString& rName)
     116             : {
     117           6 :     static const OUString sStart = SW_RES(STR_START_QUOTE);
     118           6 :     static const OUString sEnd = SW_RES(STR_END_QUOTE);
     119           6 :     return sStart + rName + sEnd;
     120             : }
     121             : 
     122           3 : SwRewriter SwUndoRenameBookmark::GetRewriter() const
     123             : {
     124           3 :     SwRewriter aRewriter;
     125           3 :     aRewriter.AddRule(UndoArg1, lcl_QuoteName(m_sOldName));
     126           3 :     aRewriter.AddRule(UndoArg2, SW_RES(STR_YIELDS));
     127           3 :     aRewriter.AddRule(UndoArg3, lcl_QuoteName(m_sNewName));
     128           3 :     return aRewriter;
     129             : }
     130             : 
     131           2 : void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext & rContext, const OUString& sFrom, const OUString& sTo)
     132             : {
     133           2 :     IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
     134           2 :     IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findMark(sFrom);
     135           2 :     if (ppBkmk != pMarkAccess->getAllMarksEnd())
     136             :     {
     137           2 :         pMarkAccess->renameMark( ppBkmk->get(), sTo );
     138             :     }
     139           2 : }
     140             : 
     141           1 : void SwUndoRenameBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
     142             : {
     143           1 :     Rename(rContext, m_sNewName, m_sOldName);
     144           1 : }
     145             : 
     146           1 : void SwUndoRenameBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
     147             : {
     148           1 :     Rename(rContext, m_sOldName, m_sNewName);
     149         178 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11