cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / undo / undorangename.cxx
blob7dceff763f20aade2019a40ede1ee57ddda60df4
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/.
8 */
10 #include <undorangename.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
14 #include <sfx2/app.hxx>
16 #include <memory>
17 #include <utility>
19 ScUndoAllRangeNames::ScUndoAllRangeNames(
20 ScDocShell* pDocSh,
21 const std::map<OUString, ScRangeName*>& rOldNames,
22 const std::map<OUString, ScRangeName>& rNewNames)
23 : ScSimpleUndo(pDocSh)
25 for (const auto& [rName, pRangeName] : rOldNames)
27 m_OldNames.insert(std::make_pair(rName, *pRangeName));
30 for (auto const& it : rNewNames)
32 m_NewNames.insert(std::make_pair(it.first, it.second));
36 ScUndoAllRangeNames::~ScUndoAllRangeNames()
40 void ScUndoAllRangeNames::Undo()
42 DoChange(m_OldNames);
45 void ScUndoAllRangeNames::Redo()
47 DoChange(m_NewNames);
50 void ScUndoAllRangeNames::Repeat(SfxRepeatTarget& /*rTarget*/)
54 bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
56 return false;
59 OUString ScUndoAllRangeNames::GetComment() const
61 return ScResId(STR_UNDO_RANGENAMES);
64 void ScUndoAllRangeNames::DoChange(const std::map<OUString, ScRangeName>& rNames)
66 ScDocument& rDoc = pDocShell->GetDocument();
68 rDoc.PreprocessAllRangeNamesUpdate(rNames);
69 rDoc.SetAllRangeNames(rNames);
70 rDoc.CompileHybridFormula();
72 SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScAreasChanged));
75 ScUndoAddRangeData::ScUndoAddRangeData(ScDocShell* pDocSh, const ScRangeData* pRangeData, SCTAB nTab) :
76 ScSimpleUndo(pDocSh),
77 mpRangeData(new ScRangeData(*pRangeData)),
78 mnTab(nTab)
83 ScUndoAddRangeData::~ScUndoAddRangeData()
87 void ScUndoAddRangeData::Undo()
89 ScDocument& rDoc = pDocShell->GetDocument();
90 ScRangeName* pRangeName = nullptr;
91 if (mnTab == -1)
93 pRangeName = rDoc.GetRangeName();
95 else
97 pRangeName = rDoc.GetRangeName( mnTab );
99 pRangeName->erase(*mpRangeData);
100 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
104 void ScUndoAddRangeData::Redo()
106 ScDocument& rDoc = pDocShell->GetDocument();
107 ScRangeName* pRangeName = nullptr;
108 if (mnTab == -1)
110 pRangeName = rDoc.GetRangeName();
112 else
114 pRangeName = rDoc.GetRangeName( mnTab );
116 pRangeName->insert(new ScRangeData(*mpRangeData));
117 SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
120 void ScUndoAddRangeData::Repeat(SfxRepeatTarget& /*rTarget*/)
124 bool ScUndoAddRangeData::CanRepeat(SfxRepeatTarget& /*rTarget*/) const
126 return false;
129 OUString ScUndoAddRangeData::GetComment() const
131 return ScResId(STR_UNDO_RANGENAMES);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */