~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/wxSmith/wxwidgets/wxsitemundobuffer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of wxSmith plugin for Code::Blocks Studio
 
3
* Copyright (C) 2006-2007  Bartlomiej Swiecki
 
4
*
 
5
* wxSmith is free software; you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License as published by
 
7
* the Free Software Foundation; either version 3 of the License, or
 
8
* (at your option) any later version.
 
9
*
 
10
* wxSmith 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 wxSmith. If not, see <http://www.gnu.org/licenses/>.
 
17
*
 
18
* $Revision: 4850 $
 
19
* $Id: wxsitemundobuffer.cpp 4850 2008-01-29 21:45:49Z byo $
 
20
* $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/wxSmith/wxwidgets/wxsitemundobuffer.cpp $
 
21
*/
 
22
 
 
23
#include "wxsitemundobuffer.h"
 
24
 
 
25
namespace
 
26
{
 
27
    wxString Empty = wxEmptyString;
 
28
}
 
29
 
 
30
wxsItemUndoBuffer::wxsItemUndoBuffer(int MaxEnteries):
 
31
    m_CurrentPos(0),
 
32
    m_SavedPos(0),
 
33
    m_MaxEnteries(MaxEnteries)
 
34
{
 
35
}
 
36
 
 
37
wxsItemUndoBuffer::~wxsItemUndoBuffer()
 
38
{
 
39
}
 
40
 
 
41
void wxsItemUndoBuffer::StoreChange(const wxString& XmlData)
 
42
{
 
43
    // Removing all undo points after current one
 
44
    if ( m_CurrentPos < GetCount()-1 )
 
45
    {
 
46
        m_Enteries.RemoveAt(m_CurrentPos+1,GetCount()-m_CurrentPos-1);
 
47
    }
 
48
 
 
49
    // Removing all outdated undos
 
50
    if ( m_MaxEnteries > 0 )
 
51
    {
 
52
        int ToRemove = GetCount()-m_MaxEnteries;
 
53
        if ( ToRemove > 0 )
 
54
        {
 
55
            m_Enteries.RemoveAt(0,ToRemove);
 
56
            m_CurrentPos -= ToRemove;
 
57
            m_SavedPos -= ToRemove;
 
58
        }
 
59
    }
 
60
 
 
61
    m_Enteries.Add(XmlData);
 
62
    m_CurrentPos = GetCount()-1;
 
63
}
 
64
 
 
65
const wxString& wxsItemUndoBuffer::Undo()
 
66
{
 
67
    if ( m_CurrentPos == 0 ) return Empty;
 
68
    return m_Enteries[--m_CurrentPos];
 
69
}
 
70
 
 
71
const wxString& wxsItemUndoBuffer::Redo()
 
72
{
 
73
    if ( m_CurrentPos >= GetCount() - 1 ) return Empty;
 
74
    return m_Enteries[++m_CurrentPos];
 
75
}