1
/* This file is part of the KDE project
2
Copyright (C) 2000, 2009 David Faure <faure@kde.org>
3
Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) version 3.
10
This program 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
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>
19
#include "commandhistory.h"
23
#include <kactioncollection.h>
24
#include <QUndoCommand>
26
CmdHistory* CmdHistory::s_self = 0;
28
CmdHistory::CmdHistory(KActionCollection *actionCollection)
32
s_self = this; // this is hacky
34
// TODO use QUndoView?
35
QAction* undoAction = m_commandHistory.createUndoAction(actionCollection);
36
connect(undoAction, SIGNAL(triggered()), this, SLOT(undo()));
37
QAction* redoAction = m_commandHistory.createRedoAction(actionCollection);
38
connect(redoAction, SIGNAL(triggered()), this, SLOT(redo()));
41
CmdHistory* CmdHistory::self()
47
void CmdHistory::undo()
49
const int idx = m_commandHistory.index();
50
const QUndoCommand* cmd = m_commandHistory.command(idx-1);
52
m_commandHistory.undo();
57
void CmdHistory::redo()
59
const int idx = m_commandHistory.index();
60
const QUndoCommand* cmd = m_commandHistory.command(idx);
62
m_commandHistory.redo();
67
void CmdHistory::commandExecuted(const QUndoCommand *k)
69
KEBApp::self()->notifyCommandExecuted();
71
const IKEBCommand * cmd = dynamic_cast<const IKEBCommand *>(k);
74
KBookmark bk = CurrentMgr::bookmarkAt(cmd->affectedBookmarks());
75
Q_ASSERT(bk.isGroup());
76
CurrentMgr::self()->notifyManagers(bk.toGroup());
79
void CmdHistory::notifyDocSaved()
81
m_commandHistory.setClean();
84
void CmdHistory::addCommand(QUndoCommand *cmd)
88
m_commandHistory.push(cmd); // calls cmd->redo()
89
CmdHistory::commandExecuted(cmd);
92
void CmdHistory::addInFlightCommand(QUndoCommand *cmd)
96
m_commandHistory.push(cmd); // TODO: HOW TO NOT CALL REDO?
99
void CmdHistory::clearHistory()
101
m_commandHistory.clear();
104
#include "commandhistory.moc"