1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <undorangename.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
14 #include <sfx2/app.hxx>
19 ScUndoAllRangeNames::ScUndoAllRangeNames(
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()
45 void ScUndoAllRangeNames::Redo()
50 void ScUndoAllRangeNames::Repeat(SfxRepeatTarget
& /*rTarget*/)
54 bool ScUndoAllRangeNames::CanRepeat(SfxRepeatTarget
& /*rTarget*/) const
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
) :
77 mpRangeData(new ScRangeData(*pRangeData
)),
83 ScUndoAddRangeData::~ScUndoAddRangeData()
87 void ScUndoAddRangeData::Undo()
89 ScDocument
& rDoc
= pDocShell
->GetDocument();
90 ScRangeName
* pRangeName
= nullptr;
93 pRangeName
= rDoc
.GetRangeName();
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;
110 pRangeName
= rDoc
.GetRangeName();
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
129 OUString
ScUndoAddRangeData::GetComment() const
131 return ScResId(STR_UNDO_RANGENAMES
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */