android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / undo / unbkmk.cxx
blob8288453307a4f01e11a49a1fa3981826ced40644
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <string_view>
24 #include <UndoBookmark.hxx>
26 #include <strings.hrc>
27 #include <doc.hxx>
28 #include <swundo.hxx>
29 #include <pam.hxx>
31 #include <UndoCore.hxx>
32 #include <IMark.hxx>
33 #include <rolbck.hxx>
35 #include <SwRewriter.hxx>
36 #include <utility>
38 SwUndoBookmark::SwUndoBookmark( SwUndoId nUndoId,
39 const ::sw::mark::IMark& rBkmk )
40 : SwUndo( nUndoId, &rBkmk.GetMarkPos().GetDoc() )
41 , m_pHistoryBookmark(new SwHistoryBookmark(rBkmk, true, rBkmk.IsExpanded()))
45 SwUndoBookmark::~SwUndoBookmark()
49 void SwUndoBookmark::SetInDoc( SwDoc* pDoc )
51 m_pHistoryBookmark->SetInDoc( pDoc, false );
54 void SwUndoBookmark::ResetInDoc( SwDoc& rDoc )
56 IDocumentMarkAccess* const pMarkAccess = rDoc.getIDocumentMarkAccess();
57 for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
58 ppBkmk != pMarkAccess->getAllMarksEnd();
59 ++ppBkmk )
61 if ( m_pHistoryBookmark->IsEqualBookmark( **ppBkmk ) )
63 pMarkAccess->deleteMark(ppBkmk, false);
64 break;
69 SwRewriter SwUndoBookmark::GetRewriter() const
71 SwRewriter aResult;
73 aResult.AddRule(UndoArg1, m_pHistoryBookmark->GetName());
75 return aResult;
78 SwUndoInsBookmark::SwUndoInsBookmark( const ::sw::mark::IMark& rBkmk )
79 : SwUndoBookmark( SwUndoId::INSBOOKMARK, rBkmk )
83 void SwUndoInsBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
85 ResetInDoc( rContext.GetDoc() );
88 void SwUndoInsBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
90 SetInDoc( &rContext.GetDoc() );
93 SwUndoDeleteBookmark::SwUndoDeleteBookmark( const ::sw::mark::IMark& rBkmk )
94 : SwUndoBookmark( SwUndoId::DELBOOKMARK, rBkmk )
98 void SwUndoDeleteBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
100 SetInDoc( &rContext.GetDoc() );
103 void SwUndoDeleteBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
105 ResetInDoc( rContext.GetDoc() );
108 SwUndoRenameBookmark::SwUndoRenameBookmark( OUString aOldName, OUString aNewName, const SwDoc& rDoc )
109 : SwUndo( SwUndoId::BOOKMARK_RENAME, &rDoc )
110 , m_sOldName(std::move( aOldName ))
111 , m_sNewName(std::move( aNewName ))
115 SwUndoRenameBookmark::~SwUndoRenameBookmark()
119 static OUString lcl_QuoteName(std::u16string_view rName)
121 static const OUString sStart = SwResId(STR_START_QUOTE);
122 static const OUString sEnd = SwResId(STR_END_QUOTE);
123 return sStart + rName + sEnd;
126 SwRewriter SwUndoRenameBookmark::GetRewriter() const
128 SwRewriter aRewriter;
129 aRewriter.AddRule(UndoArg1, lcl_QuoteName(m_sOldName));
130 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
131 aRewriter.AddRule(UndoArg3, lcl_QuoteName(m_sNewName));
132 return aRewriter;
135 void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext const & rContext, const OUString& sFrom, const OUString& sTo)
137 IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
138 IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findMark(sFrom);
139 if (ppBkmk != pMarkAccess->getAllMarksEnd())
141 pMarkAccess->renameMark( *ppBkmk, sTo );
145 void SwUndoRenameBookmark::UndoImpl(::sw::UndoRedoContext & rContext)
147 Rename(rContext, m_sNewName, m_sOldName);
150 void SwUndoRenameBookmark::RedoImpl(::sw::UndoRedoContext & rContext)
152 Rename(rContext, m_sOldName, m_sNewName);
155 SwUndoInsNoTextFieldmark::SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
156 : SwUndo(SwUndoId::INSERT, &rFieldmark.GetMarkPos().GetDoc())
157 , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
161 void SwUndoInsNoTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
163 m_pHistoryNoTextFieldmark->ResetInDoc(rContext.GetDoc());
166 void SwUndoInsNoTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
168 m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
171 SwUndoDelNoTextFieldmark::SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
172 : SwUndo(SwUndoId::DELETE, &rFieldmark.GetMarkPos().GetDoc())
173 , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
177 SwUndoDelNoTextFieldmark::~SwUndoDelNoTextFieldmark() = default;
179 void SwUndoDelNoTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
181 m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
184 void SwUndoDelNoTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
186 m_pHistoryNoTextFieldmark->ResetInDoc(rContext.GetDoc());
189 SwUndoInsTextFieldmark::SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
190 : SwUndo(SwUndoId::INSERT, &rFieldmark.GetMarkPos().GetDoc())
191 , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
195 void SwUndoInsTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
197 m_pHistoryTextFieldmark->ResetInDoc(rContext.GetDoc());
200 void SwUndoInsTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
202 m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
205 SwUndoDelTextFieldmark::SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
206 : SwUndo(SwUndoId::DELETE, &rFieldmark.GetMarkPos().GetDoc())
207 , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
211 SwUndoDelTextFieldmark::~SwUndoDelTextFieldmark() = default;
213 void SwUndoDelTextFieldmark::UndoImpl(::sw::UndoRedoContext & rContext)
215 m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
218 void SwUndoDelTextFieldmark::RedoImpl(::sw::UndoRedoContext & rContext)
220 m_pHistoryTextFieldmark->ResetInDoc(rContext.GetDoc());
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */