~ubuntu-branches/ubuntu/maverick/kdebase/maverick-updates

« back to all changes in this revision

Viewing changes to apps/keditbookmarks/commandhistory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers, Martin Alfke, Modestas Vainius
  • Date: 2010-05-01 23:37:50 UTC
  • mfrom: (0.7.4 upstream) (0.4.4 experimental)
  • mto: This revision was merged to the branch mainline in revision 285.
  • Revision ID: james.westby@ubuntu.com-20100501233750-maq4i4sh8ymjbneb
Tags: 4:4.4.3-1
* New upstream release:
  - Konsole does not crash when closing a broken restored session.
    (Closes: #555831)
  - Konqueror does not crash when closing fast a tab. (Closes: #441298)

[Martin Alfke]
* Update of debian/copyright for kde 4.4

[ Modestas Vainius ]
* Bump kde-sc-dev-latest build dependency to 4.4.3.
* Confirm symbol files for 4.4.2 on hurd-i386 i386 ia64 kfreebsd-amd64
  kfreebsd-i386 mips powerpc s390 sparc.
* Release KDE SC 4.4.3 to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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/>
 
17
*/
 
18
 
 
19
#include "commandhistory.h"
 
20
#include <kdebug.h>
 
21
#include "commands.h"
 
22
#include "toplevel.h"
 
23
#include <kactioncollection.h>
 
24
#include <QUndoCommand>
 
25
 
 
26
CmdHistory* CmdHistory::s_self = 0;
 
27
 
 
28
CmdHistory::CmdHistory(KActionCollection *actionCollection)
 
29
    : m_commandHistory()
 
30
{
 
31
    Q_ASSERT(!s_self);
 
32
    s_self = this; // this is hacky
 
33
 
 
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()));
 
39
}
 
40
 
 
41
CmdHistory* CmdHistory::self()
 
42
{
 
43
    Q_ASSERT(s_self);
 
44
    return s_self;
 
45
}
 
46
 
 
47
void CmdHistory::undo()
 
48
{
 
49
    const int idx = m_commandHistory.index();
 
50
    const QUndoCommand* cmd = m_commandHistory.command(idx-1);
 
51
    if (cmd) {
 
52
        m_commandHistory.undo();
 
53
        commandExecuted(cmd);
 
54
    }
 
55
}
 
56
 
 
57
void CmdHistory::redo()
 
58
{
 
59
    const int idx = m_commandHistory.index();
 
60
    const QUndoCommand* cmd = m_commandHistory.command(idx);
 
61
    if (cmd) {
 
62
        m_commandHistory.redo();
 
63
        commandExecuted(cmd);
 
64
    }
 
65
}
 
66
 
 
67
void CmdHistory::commandExecuted(const QUndoCommand *k)
 
68
{
 
69
    KEBApp::self()->notifyCommandExecuted();
 
70
 
 
71
    const IKEBCommand * cmd = dynamic_cast<const IKEBCommand *>(k);
 
72
    Q_ASSERT(cmd);
 
73
 
 
74
    KBookmark bk = CurrentMgr::bookmarkAt(cmd->affectedBookmarks());
 
75
    Q_ASSERT(bk.isGroup());
 
76
    CurrentMgr::self()->notifyManagers(bk.toGroup());
 
77
}
 
78
 
 
79
void CmdHistory::notifyDocSaved()
 
80
{
 
81
    m_commandHistory.setClean();
 
82
}
 
83
 
 
84
void CmdHistory::addCommand(QUndoCommand *cmd)
 
85
{
 
86
    if (!cmd)
 
87
        return;
 
88
    m_commandHistory.push(cmd); // calls cmd->redo()
 
89
    CmdHistory::commandExecuted(cmd);
 
90
}
 
91
 
 
92
void CmdHistory::addInFlightCommand(QUndoCommand *cmd)
 
93
{
 
94
    if(!cmd)
 
95
        return;
 
96
    m_commandHistory.push(cmd); // TODO: HOW TO NOT CALL REDO?
 
97
}
 
98
 
 
99
void CmdHistory::clearHistory()
 
100
{
 
101
    m_commandHistory.clear();
 
102
}
 
103
 
 
104
#include "commandhistory.moc"