1
////////////////////////////////////////////////////////////////////////////
2
// NoteCase notes manager project <http://notecase.sf.net>
4
// This code is licensed under BSD license.See "license.txt" for more details.
6
// File: Object that manages document changes history list (Undo/Redo framework)
7
////////////////////////////////////////////////////////////////////////////
9
#include "DocActionManager.h"
11
DocActionManager::DocActionManager(int nMaxListSize)
13
m_nMaxListSize = nMaxListSize;
17
DocActionManager::~DocActionManager()
22
void DocActionManager::Clear()
24
//delete all action objects
25
for(unsigned int i=0; i<m_lstHistory.size(); i++)
26
delete m_lstHistory[i];
27
m_lstHistory.clear(); //clear pointer list
31
bool DocActionManager::CanUndo()
33
return (m_lstHistory.size() > 0) && (m_nPos > 0);
36
bool DocActionManager::CanRedo()
38
return (m_lstHistory.size() > 0) && ((m_lstHistory.size() - m_nPos) > 0);
41
void DocActionManager::AddAction(DocActionBase *pAction)
43
//each new action destroys redo part of the list
46
//push new undo action into the list
47
m_lstHistory.push_back(pAction);
50
//check if we overgrown allowed list size
51
if(m_lstHistory.size() > m_nMaxListSize)
54
delete m_lstHistory[0];
55
m_lstHistory.erase(m_lstHistory.begin(), m_lstHistory.begin()+1);
60
void DocActionManager::Undo()
65
m_lstHistory[m_nPos]->Undo();
69
void DocActionManager::Redo()
73
m_lstHistory[m_nPos]->Redo();
78
void DocActionManager::ClearRedoList()
80
// clear redo part of the list
82
for(unsigned int i=m_nPos; i<m_lstHistory.size(); i++)
83
delete m_lstHistory[i];
84
m_lstHistory.erase(m_lstHistory.begin()+m_nPos, m_lstHistory.end());
88
// returns a pointer to the specified action.
89
DocActionBase* DocActionManager::GetAction(unsigned int nPos) const
91
// make sure that index is valid
92
if(nPos < 0 || nPos > m_lstHistory.size()) return NULL;
94
return m_lstHistory[nPos];
97
// returns a pointer to the current action.
98
DocActionBase* DocActionManager::GetCurrentAction() const
100
// make sure that current undo action exists
101
if(m_nPos < 1 || m_nPos > m_lstHistory.size()) return NULL;
103
return m_lstHistory[m_nPos - 1];
1
////////////////////////////////////////////////////////////////////////////
2
// NoteCase notes manager project <http://notecase.sf.net>
4
// This code is licensed under BSD license.See "license.txt" for more details.
6
// File: Object that manages document changes history list (Undo/Redo framework)
7
////////////////////////////////////////////////////////////////////////////
9
#include "DocActionManager.h"
11
DocActionManager::DocActionManager(int nMaxListSize)
13
m_nMaxListSize = nMaxListSize;
17
DocActionManager::~DocActionManager()
22
void DocActionManager::Clear()
24
//delete all action objects
25
for(unsigned int i=0; i<m_lstHistory.size(); i++)
26
delete m_lstHistory[i];
27
m_lstHistory.clear(); //clear pointer list
31
bool DocActionManager::CanUndo()
33
return (m_lstHistory.size() > 0) && (m_nPos > 0);
36
bool DocActionManager::CanRedo()
38
return (m_lstHistory.size() > 0) && ((m_lstHistory.size() - m_nPos) > 0);
41
void DocActionManager::AddAction(DocActionBase *pAction)
43
//each new action destroys redo part of the list
46
//push new undo action into the list
47
m_lstHistory.push_back(pAction);
50
//check if we overgrown allowed list size
51
if(m_lstHistory.size() > m_nMaxListSize)
54
delete m_lstHistory[0];
55
m_lstHistory.erase(m_lstHistory.begin(), m_lstHistory.begin()+1);
60
void DocActionManager::Undo()
65
m_lstHistory[m_nPos]->Undo();
69
void DocActionManager::Redo()
73
m_lstHistory[m_nPos]->Exec();
78
void DocActionManager::ClearRedoList()
80
// clear redo part of the list
82
for(unsigned int i=m_nPos; i<m_lstHistory.size(); i++)
83
delete m_lstHistory[i];
84
m_lstHistory.erase(m_lstHistory.begin()+m_nPos, m_lstHistory.end());
88
// returns a pointer to the specified action.
89
DocActionBase* DocActionManager::GetAction(unsigned int nPos) const
91
// make sure that index is valid
92
if(nPos < 0 || nPos > m_lstHistory.size()) return NULL;
94
return m_lstHistory[nPos];
97
// returns a pointer to the current action.
98
DocActionBase* DocActionManager::GetCurrentAction() const
100
// make sure that current undo action exists
101
if(m_nPos < 1 || m_nPos > m_lstHistory.size()) return NULL;
103
return m_lstHistory[m_nPos - 1];