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