1 /* This file is part of the KDE project
2    Copyright 2004 Ariya Hidayat <ariya@kde.org>
3    Copyright 2004 Laurent Montel <montel@kde.org>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public License
16    along with this library; see the file COPYING.LIB.  If not, write to
17    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19 */
20 
21 // Local
22 #include "LinkCommand.h"
23 
24 #include "Damages.h"
25 #include "Localization.h"
26 #include "Map.h"
27 #include "Sheet.h"
28 
29 using namespace Calligra::Sheets;
30 
LinkCommand(const Cell & c,const QString & text,const QString & link)31 LinkCommand::LinkCommand(const Cell& c, const QString& text, const QString& link)
32 {
33     cell = c;
34     oldText = cell.userInput();
35     oldLink = cell.link();
36     newText = text;
37     newLink = link;
38 
39     setText(newLink.isEmpty() ? kundo2_i18n("Remove Link") : kundo2_i18n("Set Link"));
40 }
41 
redo()42 void LinkCommand::redo()
43 {
44     if (!cell) return;
45 
46     if (!newText.isEmpty())
47         cell.parseUserInput(newText);
48     cell.setLink(newLink);
49 
50     cell.sheet()->map()->addDamage(new CellDamage(cell, CellDamage::Appearance));
51 }
52 
undo()53 void LinkCommand::undo()
54 {
55     if (!cell) return;
56 
57     cell.parseUserInput(oldText);
58     cell.setLink(oldLink);
59 
60     cell.sheet()->map()->addDamage(new CellDamage(cell, CellDamage::Appearance));
61 }
62