LibreOffice Module sw (master) 1
unbkmk.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <string_view>
23
24#include <UndoBookmark.hxx>
25
26#include <strings.hrc>
27#include <doc.hxx>
28#include <swundo.hxx>
29#include <pam.hxx>
30
31#include <UndoCore.hxx>
32#include <IMark.hxx>
33#include <rolbck.hxx>
34
35#include <SwRewriter.hxx>
36#include <utility>
37
39 const ::sw::mark::IMark& rBkmk )
40 : SwUndo( nUndoId, &rBkmk.GetMarkPos().GetDoc() )
41 , m_pHistoryBookmark(new SwHistoryBookmark(rBkmk, true, rBkmk.IsExpanded()))
42{
43}
44
46{
47}
48
50{
51 m_pHistoryBookmark->SetInDoc( pDoc, false );
52}
53
55{
56 IDocumentMarkAccess* const pMarkAccess = rDoc.getIDocumentMarkAccess();
57 for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
58 ppBkmk != pMarkAccess->getAllMarksEnd();
59 ++ppBkmk )
60 {
61 if ( m_pHistoryBookmark->IsEqualBookmark( **ppBkmk ) )
62 {
63 pMarkAccess->deleteMark(ppBkmk, false);
64 break;
65 }
66 }
67}
68
70{
71 SwRewriter aResult;
72
73 aResult.AddRule(UndoArg1, m_pHistoryBookmark->GetName());
74
75 return aResult;
76}
77
78SwUndoInsBookmark::SwUndoInsBookmark( const ::sw::mark::IMark& rBkmk )
80{
81}
82
84{
85 ResetInDoc( rContext.GetDoc() );
86}
87
89{
90 SetInDoc( &rContext.GetDoc() );
91}
92
93SwUndoDeleteBookmark::SwUndoDeleteBookmark( const ::sw::mark::IMark& rBkmk )
95{
96}
97
99{
100 SetInDoc( &rContext.GetDoc() );
101}
102
104{
105 ResetInDoc( rContext.GetDoc() );
106}
107
108SwUndoRenameBookmark::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 ))
112{
113}
114
116{
117}
118
119static OUString lcl_QuoteName(std::u16string_view rName)
120{
121 static const OUString sStart = SwResId(STR_START_QUOTE);
122 static const OUString sEnd = SwResId(STR_END_QUOTE);
123 return sStart + rName + sEnd;
124}
125
127{
128 SwRewriter aRewriter;
130 aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
132 return aRewriter;
133}
134
135void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext const & rContext, const OUString& sFrom, const OUString& sTo)
136{
137 IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
138 IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findMark(sFrom);
139 if (ppBkmk != pMarkAccess->getAllMarksEnd())
140 {
141 pMarkAccess->renameMark( *ppBkmk, sTo );
142 }
143}
144
146{
147 Rename(rContext, m_sNewName, m_sOldName);
148}
149
151{
152 Rename(rContext, m_sOldName, m_sNewName);
153}
154
155SwUndoInsNoTextFieldmark::SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
156 : SwUndo(SwUndoId::INSERT, &rFieldmark.GetMarkPos().GetDoc())
157 , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
158{
159}
160
162{
163 m_pHistoryNoTextFieldmark->ResetInDoc(rContext.GetDoc());
164}
165
167{
168 m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
169}
170
171SwUndoDelNoTextFieldmark::SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
172 : SwUndo(SwUndoId::DELETE, &rFieldmark.GetMarkPos().GetDoc())
173 , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
174{
175}
176
178
180{
181 m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
182}
183
185{
186 m_pHistoryNoTextFieldmark->ResetInDoc(rContext.GetDoc());
187}
188
189SwUndoInsTextFieldmark::SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
190 : SwUndo(SwUndoId::INSERT, &rFieldmark.GetMarkPos().GetDoc())
191 , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
192{
193}
194
196{
197 m_pHistoryTextFieldmark->ResetInDoc(rContext.GetDoc());
198}
199
201{
202 m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
203}
204
205SwUndoDelTextFieldmark::SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
206 : SwUndo(SwUndoId::DELETE, &rFieldmark.GetMarkPos().GetDoc())
207 , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
208{
209}
210
212
214{
215 m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
216}
217
219{
220 m_pHistoryTextFieldmark->ResetInDoc(rContext.GetDoc());
221}
222
223/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ UndoArg1
Definition: SwRewriter.hxx:29
@ UndoArg3
Definition: SwRewriter.hxx:31
@ UndoArg2
Definition: SwRewriter.hxx:30
wrapper iterator: wraps iterator of implementation while hiding MarkBase class; only IMark instances ...
Provides access to the marks of a document.
virtual bool renameMark(::sw::mark::IMark *io_pMark, const OUString &rNewName)=0
Renames an existing Mark, if possible.
virtual const_iterator_t getAllMarksEnd() const =0
returns a STL-like random access iterator to the end of the sequence of marks.
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
virtual std::unique_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark, bool isMoveNodes)=0
Deletes a mark.
virtual const_iterator_t getAllMarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence of marks.
Definition: doc.hxx:197
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1890
History object containing all information used during undo / redo of checkbox and drop-down form fiel...
Definition: rolbck.hxx:276
History object containing all information used during undo / redo of text form field insertion.
Definition: rolbck.hxx:291
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
const std::unique_ptr< SwHistoryBookmark > m_pHistoryBookmark
SwUndoBookmark(SwUndoId nUndoId, const ::sw::mark::IMark &)
Definition: unbkmk.cxx:38
void SetInDoc(SwDoc *)
Definition: unbkmk.cxx:49
virtual ~SwUndoBookmark() override
Definition: unbkmk.cxx:45
void ResetInDoc(SwDoc &)
Definition: unbkmk.cxx:54
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this undo object.
Definition: unbkmk.cxx:69
SwUndoDelNoTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:171
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:179
const std::unique_ptr< SwHistoryNoTextFieldmark > m_pHistoryNoTextFieldmark
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:184
const std::unique_ptr< SwHistoryTextFieldmark > m_pHistoryTextFieldmark
SwUndoDelTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:205
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:213
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:218
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:98
SwUndoDeleteBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:93
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:103
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:83
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:88
SwUndoInsBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:78
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:161
const std::unique_ptr< SwHistoryNoTextFieldmark > m_pHistoryNoTextFieldmark
SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:155
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:166
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:200
SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:189
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:195
const std::unique_ptr< SwHistoryTextFieldmark > m_pHistoryTextFieldmark
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:145
virtual ~SwUndoRenameBookmark() override
Definition: unbkmk.cxx:115
static void Rename(::sw::UndoRedoContext const &, const OUString &sFrom, const OUString &sTo)
Definition: unbkmk.cxx:135
const OUString m_sOldName
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unbkmk.cxx:126
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:150
const OUString m_sNewName
SwUndoRenameBookmark(OUString aOldName, OUString aNewName, const SwDoc &rDoc)
Definition: unbkmk.cxx:108
SwDoc & GetDoc() const
Definition: UndoCore.hxx:95
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SwUndoId
Definition: swundo.hxx:30
@ BOOKMARK_RENAME
static OUString lcl_QuoteName(std::u16string_view rName)
Definition: unbkmk.cxx:119