/src/libreoffice/sc/source/ui/undo/undorangename.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
10 | | #include <undorangename.hxx> |
11 | | #include <globstr.hrc> |
12 | | #include <scresid.hxx> |
13 | | |
14 | | #include <sfx2/app.hxx> |
15 | | |
16 | | #include <memory> |
17 | | #include <utility> |
18 | | |
19 | | ScUndoAllRangeNames::ScUndoAllRangeNames( |
20 | | ScDocShell& rDocSh, |
21 | | const std::map<OUString, ScRangeName*>& rOldNames, |
22 | | const std::map<OUString, ScRangeName>& rNewNames) |
23 | 0 | : ScSimpleUndo(rDocSh) |
24 | 0 | { |
25 | 0 | for (const auto& [rName, pRangeName] : rOldNames) |
26 | 0 | { |
27 | 0 | m_OldNames.insert(std::make_pair(rName, *pRangeName)); |
28 | 0 | } |
29 | |
|
30 | 0 | for (auto const& it : rNewNames) |
31 | 0 | { |
32 | 0 | m_NewNames.insert(std::make_pair(it.first, it.second)); |
33 | 0 | } |
34 | 0 | } |
35 | | |
36 | | ScUndoAllRangeNames::~ScUndoAllRangeNames() |
37 | 0 | { |
38 | 0 | } |
39 | | |
40 | | void ScUndoAllRangeNames::Undo() |
41 | 0 | { |
42 | 0 | DoChange(m_OldNames); |
43 | 0 | } |
44 | | |
45 | | void ScUndoAllRangeNames::Redo() |
46 | 0 | { |
47 | 0 | DoChange(m_NewNames); |
48 | 0 | } |
49 | | |
50 | | void ScUndoAllRangeNames::Repeat(SfxRepeatTarget& /*rTarget*/) |
51 | 0 | { |
52 | 0 | } |
53 | | |
54 | | bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget& /*rTarget*/) const |
55 | 0 | { |
56 | 0 | return false; |
57 | 0 | } |
58 | | |
59 | | OUString ScUndoAllRangeNames::GetComment() const |
60 | 0 | { |
61 | 0 | return ScResId(STR_UNDO_RANGENAMES); |
62 | 0 | } |
63 | | |
64 | | void ScUndoAllRangeNames::DoChange(const std::map<OUString, ScRangeName>& rNames) |
65 | 0 | { |
66 | 0 | ScDocument& rDoc = rDocShell.GetDocument(); |
67 | |
|
68 | 0 | rDoc.PreprocessAllRangeNamesUpdate(rNames); |
69 | 0 | rDoc.SetAllRangeNames(rNames); |
70 | 0 | rDoc.CompileHybridFormula(); |
71 | |
|
72 | 0 | SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScAreasChanged)); |
73 | 0 | } |
74 | | |
75 | | ScUndoAddRangeData::ScUndoAddRangeData(ScDocShell& rDocSh, const ScRangeData* pRangeData, SCTAB nTab) : |
76 | 0 | ScSimpleUndo(rDocSh), |
77 | 0 | mpRangeData(new ScRangeData(*pRangeData)), |
78 | 0 | mnTab(nTab) |
79 | 0 | { |
80 | |
|
81 | 0 | } |
82 | | |
83 | | ScUndoAddRangeData::~ScUndoAddRangeData() |
84 | 0 | { |
85 | 0 | } |
86 | | |
87 | | void ScUndoAddRangeData::Undo() |
88 | 0 | { |
89 | 0 | ScDocument& rDoc = rDocShell.GetDocument(); |
90 | 0 | ScRangeName* pRangeName = nullptr; |
91 | 0 | if (mnTab == -1) |
92 | 0 | { |
93 | 0 | pRangeName = rDoc.GetRangeName(); |
94 | 0 | } |
95 | 0 | else |
96 | 0 | { |
97 | 0 | pRangeName = rDoc.GetRangeName( mnTab ); |
98 | 0 | } |
99 | 0 | pRangeName->erase(*mpRangeData); |
100 | 0 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) ); |
101 | |
|
102 | 0 | } |
103 | | |
104 | | void ScUndoAddRangeData::Redo() |
105 | 0 | { |
106 | 0 | ScDocument& rDoc = rDocShell.GetDocument(); |
107 | 0 | ScRangeName* pRangeName = nullptr; |
108 | 0 | if (mnTab == -1) |
109 | 0 | { |
110 | 0 | pRangeName = rDoc.GetRangeName(); |
111 | 0 | } |
112 | 0 | else |
113 | 0 | { |
114 | 0 | pRangeName = rDoc.GetRangeName( mnTab ); |
115 | 0 | } |
116 | 0 | pRangeName->insert(new ScRangeData(*mpRangeData)); |
117 | 0 | SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) ); |
118 | 0 | } |
119 | | |
120 | | void ScUndoAddRangeData::Repeat(SfxRepeatTarget& /*rTarget*/) |
121 | 0 | { |
122 | 0 | } |
123 | | |
124 | | bool ScUndoAddRangeData::CanRepeat(SfxRepeatTarget& /*rTarget*/) const |
125 | 0 | { |
126 | 0 | return false; |
127 | 0 | } |
128 | | |
129 | | OUString ScUndoAddRangeData::GetComment() const |
130 | 0 | { |
131 | 0 | return ScResId(STR_UNDO_RANGENAMES); |
132 | 0 | } |
133 | | |
134 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |