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 <UndoBookmark.hxx>
21 
22 #include <strings.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 
35  const ::sw::mark::IMark& rBkmk )
36  : SwUndo( nUndoId, rBkmk.GetMarkPos().GetDoc() )
37  , m_pHistoryBookmark(new SwHistoryBookmark(rBkmk, true, rBkmk.IsExpanded()))
38 {
39 }
40 
42 {
43 }
44 
46 {
47  m_pHistoryBookmark->SetInDoc( pDoc, false );
48 }
49 
51 {
52  IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
53  for ( IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getAllMarksBegin();
54  ppBkmk != pMarkAccess->getAllMarksEnd();
55  ++ppBkmk )
56  {
57  if ( m_pHistoryBookmark->IsEqualBookmark( **ppBkmk ) )
58  {
59  pMarkAccess->deleteMark( ppBkmk );
60  break;
61  }
62  }
63 }
64 
66 {
67  SwRewriter aResult;
68 
69  aResult.AddRule(UndoArg1, m_pHistoryBookmark->GetName());
70 
71  return aResult;
72 }
73 
74 SwUndoInsBookmark::SwUndoInsBookmark( const ::sw::mark::IMark& rBkmk )
76 {
77 }
78 
80 {
81  ResetInDoc( &rContext.GetDoc() );
82 }
83 
85 {
86  SetInDoc( &rContext.GetDoc() );
87 }
88 
89 SwUndoDeleteBookmark::SwUndoDeleteBookmark( const ::sw::mark::IMark& rBkmk )
91 {
92 }
93 
95 {
96  SetInDoc( &rContext.GetDoc() );
97 }
98 
100 {
101  ResetInDoc( &rContext.GetDoc() );
102 }
103 
104 SwUndoRenameBookmark::SwUndoRenameBookmark( const OUString& rOldName, const OUString& rNewName, const SwDoc* pDoc )
105  : SwUndo( SwUndoId::BOOKMARK_RENAME, pDoc )
106  , m_sOldName( rOldName )
107  , m_sNewName( rNewName )
108 {
109 }
110 
112 {
113 }
114 
115 static OUString lcl_QuoteName(const OUString& rName)
116 {
117  static const OUString sStart = SwResId(STR_START_QUOTE);
118  static const OUString sEnd = SwResId(STR_END_QUOTE);
119  return sStart + rName + sEnd;
120 }
121 
123 {
124  SwRewriter aRewriter;
126  aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
128  return aRewriter;
129 }
130 
131 void SwUndoRenameBookmark::Rename(::sw::UndoRedoContext const & rContext, const OUString& sFrom, const OUString& sTo)
132 {
133  IDocumentMarkAccess* const pMarkAccess = rContext.GetDoc().getIDocumentMarkAccess();
134  IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findMark(sFrom);
135  if (ppBkmk != pMarkAccess->getAllMarksEnd())
136  {
137  pMarkAccess->renameMark( ppBkmk->get(), sTo );
138  }
139 }
140 
142 {
143  Rename(rContext, m_sNewName, m_sOldName);
144 }
145 
147 {
148  Rename(rContext, m_sOldName, m_sNewName);
149 }
150 
151 SwUndoInsNoTextFieldmark::SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
152  : SwUndo(SwUndoId::INSERT, rFieldmark.GetMarkPos().GetDoc())
153  , m_pHistoryNoTextFieldmark(new SwHistoryNoTextFieldmark(rFieldmark))
154 {
155 }
156 
158 {
159  m_pHistoryNoTextFieldmark->ResetInDoc(&rContext.GetDoc());
160 }
161 
163 {
164  m_pHistoryNoTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
165 }
166 
167 SwUndoInsTextFieldmark::SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark& rFieldmark)
168  : SwUndo(SwUndoId::INSERT, rFieldmark.GetMarkPos().GetDoc())
169  , m_pHistoryTextFieldmark(new SwHistoryTextFieldmark(rFieldmark))
170 {
171 }
172 
174 {
175  m_pHistoryTextFieldmark->ResetInDoc(&rContext.GetDoc());
176 }
177 
179 {
180  m_pHistoryTextFieldmark->SetInDoc(&rContext.GetDoc(), false);
181 }
182 
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
History object containing all information used during undo / redo of text form field insertion...
Definition: rolbck.hxx:281
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:178
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:146
SwUndoId
Definition: swundo.hxx:29
virtual ~SwUndoBookmark() override
Definition: unbkmk.cxx:41
static OUString lcl_QuoteName(const OUString &rName)
Definition: unbkmk.cxx:115
void SetInDoc(SwDoc *)
Definition: unbkmk.cxx:45
const std::unique_ptr< SwHistoryNoTextFieldmark > m_pHistoryNoTextFieldmark
Provides access to the marks of a document.
Definition: doc.hxx:185
SwUndoInsTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:167
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1348
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:157
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unbkmk.cxx:122
virtual ~SwUndoRenameBookmark() override
Definition: unbkmk.cxx:111
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:162
virtual const_iterator_t findMark(const OUString &rMark) const =0
Finds a mark by name.
SwUndoRenameBookmark(const OUString &rOldName, const OUString &rNewName, const SwDoc *pDoc)
Definition: unbkmk.cxx:104
void ResetInDoc(SwDoc *)
Definition: unbkmk.cxx:50
History object containing all information used during undo / redo of checkbox and drop-down form fiel...
Definition: rolbck.hxx:266
const std::unique_ptr< SwHistoryBookmark > m_pHistoryBookmark
SwUndoInsBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:74
static void Rename(::sw::UndoRedoContext const &, const OUString &sFrom, const OUString &sTo)
Definition: unbkmk.cxx:131
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
virtual const_iterator_t getAllMarksBegin() const =0
returns a STL-like random access iterator to the begin of the sequence of marks.
container_t::const_iterator const_iterator_t
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:65
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:141
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:173
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:84
SwUndoInsNoTextFieldmark(const ::sw::mark::IFieldmark &rFieldmark)
Definition: unbkmk.cxx:151
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:99
const std::unique_ptr< SwHistoryTextFieldmark > m_pHistoryTextFieldmark
SwUndoDeleteBookmark(const ::sw::mark::IMark &)
Definition: unbkmk.cxx:89
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unbkmk.cxx:94
const OUString m_sOldName
virtual std::shared_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark)=0
Deletes a mark.
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:79
SwUndoBookmark(SwUndoId nUndoId, const ::sw::mark::IMark &)
Definition: unbkmk.cxx:34
const OUString m_sNewName