wxCommandProcessor::MarkAsSaved() and IsDirty() added (modified patch 1062556)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32192 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2005-02-19 16:52:08 +00:00
parent 8348e2cbf3
commit f260c476e4
4 changed files with 68 additions and 4 deletions

View File

@ -52,6 +52,7 @@ All:
mouse clicks and left mouse click for starting a drag operation. mouse clicks and left mouse click for starting a drag operation.
- "Alt" key (VK_MENU) now results in WXK_ALT keyboard event, not WXK_MENU - "Alt" key (VK_MENU) now results in WXK_ALT keyboard event, not WXK_MENU
- wxFFile::ReadAll() now takes an optional wxMBConv parameter - wxFFile::ReadAll() now takes an optional wxMBConv parameter
- wxCommandProcessor::MarkAsSaved() and IsDirty() added (Angela Wrobel)
All (GUI): All (GUI):

View File

@ -18,6 +18,7 @@ if you want different behaviour.
\latexignore{\rtfignore{\wxheading{Members}}} \latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxCommandProcessor::wxCommandProcessor}\label{wxcommandprocessorctor} \membersection{wxCommandProcessor::wxCommandProcessor}\label{wxcommandprocessorctor}
\func{}{wxCommandProcessor}{\param{int}{ maxCommands = $-1$}} \func{}{wxCommandProcessor}{\param{int}{ maxCommands = $-1$}}
@ -28,72 +29,84 @@ Constructor.
commands stored to it, otherwise (and by default) the list of commands can grow commands stored to it, otherwise (and by default) the list of commands can grow
arbitrarily. arbitrarily.
\membersection{wxCommandProcessor::\destruct{wxCommandProcessor}}\label{wxcommandprocessordtor} \membersection{wxCommandProcessor::\destruct{wxCommandProcessor}}\label{wxcommandprocessordtor}
\func{}{\destruct{wxCommandProcessor}}{\void} \func{}{\destruct{wxCommandProcessor}}{\void}
Destructor. Destructor.
\membersection{wxCommandProcessor::CanUndo}\label{wxcommandprocessorcanundo} \membersection{wxCommandProcessor::CanUndo}\label{wxcommandprocessorcanundo}
\func{virtual bool}{CanUndo}{\void} \func{virtual bool}{CanUndo}{\void}
Returns true if the currently-active command can be undone, false otherwise. Returns true if the currently-active command can be undone, false otherwise.
\membersection{wxCommandProcessor::ClearCommands}\label{wxcommandprocessorclearcommands} \membersection{wxCommandProcessor::ClearCommands}\label{wxcommandprocessorclearcommands}
\func{virtual void}{ClearCommands}{\void} \func{virtual void}{ClearCommands}{\void}
Deletes all the commands in the list and sets the current command pointer to NULL. Deletes all the commands in the list and sets the current command pointer to NULL.
\membersection{wxCommandProcessor::Redo}\label{wxcommandprocessorredo} \membersection{wxCommandProcessor::Redo}\label{wxcommandprocessorredo}
\func{virtual bool}{Redo}{\void} \func{virtual bool}{Redo}{\void}
Executes (redoes) the current command (the command that has just been undone if any). Executes (redoes) the current command (the command that has just been undone if any).
\membersection{wxCommandProcessor::GetCommands}\label{wxcommandprocessorgetcommands} \membersection{wxCommandProcessor::GetCommands}\label{wxcommandprocessorgetcommands}
\constfunc{wxList\&}{GetCommands}{\void} \constfunc{wxList\&}{GetCommands}{\void}
Returns the list of commands. Returns the list of commands.
\membersection{wxCommandProcessor::GetMaxCommands}\label{wxcommandprocessorgetmaxcommands} \membersection{wxCommandProcessor::GetMaxCommands}\label{wxcommandprocessorgetmaxcommands}
\constfunc{int}{GetMaxCommands}{\void} \constfunc{int}{GetMaxCommands}{\void}
Returns the maximum number of commands that the command processor stores. Returns the maximum number of commands that the command processor stores.
\membersection{wxCommandProcessor::GetEditMenu}\label{wxcommandprocessorgeteditmenu} \membersection{wxCommandProcessor::GetEditMenu}\label{wxcommandprocessorgeteditmenu}
\constfunc{wxMenu*}{GetEditMenu}{\void} \constfunc{wxMenu*}{GetEditMenu}{\void}
Returns the edit menu associated with the command processor. Returns the edit menu associated with the command processor.
\membersection{wxCommandProcessor::GetRedoAccelerator}\label{wxcommandprocessorgetredoaccelerator} \membersection{wxCommandProcessor::GetRedoAccelerator}\label{wxcommandprocessorgetredoaccelerator}
\constfunc{const wxString\&}{GetRedoAccelerator}{\void} \constfunc{const wxString\&}{GetRedoAccelerator}{\void}
Returns the string that will be appended to the Redo menu item. Returns the string that will be appended to the Redo menu item.
\membersection{wxCommandProcessor::GetRedoMenuLabel}\label{wxcommandprocessorgetredomenulabel} \membersection{wxCommandProcessor::GetRedoMenuLabel}\label{wxcommandprocessorgetredomenulabel}
\constfunc{wxString}{GetRedoMenuLabel}{\void} \constfunc{wxString}{GetRedoMenuLabel}{\void}
Returns the string that will be shown for the redo menu item. Returns the string that will be shown for the redo menu item.
\membersection{wxCommandProcessor::GetUndoAccelerator}\label{wxcommandprocessorgetundoaccelerator} \membersection{wxCommandProcessor::GetUndoAccelerator}\label{wxcommandprocessorgetundoaccelerator}
\constfunc{const wxString\&}{GetUndoAccelerator}{\void} \constfunc{const wxString\&}{GetUndoAccelerator}{\void}
Returns the string that will be appended to the Undo menu item. Returns the string that will be appended to the Undo menu item.
\membersection{wxCommandProcessor::GetUndoMenuLabel}\label{wxcommandprocessorgetundomenulabel} \membersection{wxCommandProcessor::GetUndoMenuLabel}\label{wxcommandprocessorgetundomenulabel}
\constfunc{wxString}{GetUndoMenuLabel}{\void} \constfunc{wxString}{GetUndoMenuLabel}{\void}
Returns the string that will be shown for the undo menu item. Returns the string that will be shown for the undo menu item.
\membersection{wxCommandProcessor::Initialize}\label{wxcommandprocessorinitialize} \membersection{wxCommandProcessor::Initialize}\label{wxcommandprocessorinitialize}
\func{virtual void}{Initialize}{\void} \func{virtual void}{Initialize}{\void}
@ -102,6 +115,25 @@ Initializes the command processor, setting the current command to the
last in the list (if any), and updating the edit menu (if one has been last in the list (if any), and updating the edit menu (if one has been
specified). specified).
\membersection{wxCommandProcessor::IsDirty}\label{wxcommandprocessorisdirty}
\func{virtual bool}{IsDirty}{\void}
Returns a boolean value that indicates if changes have been made since
the last save operation. This only works if
\helpref{wxCommandProcessor::MarkAsSaved}{wxcommandprocessormarkassaved}
is called whenever the project is saved.
\membersection{wxCommandProcessor::MarkAsSaved}\label{wxcommandprocessormarkassaved}
\func{virtual void}{MarkAsSaved}{\void}
You must call this method whenever the project is saved if you plan to use
\helpref{wxCommandProcessor::IsDirty}{wxcommandprocessorisdirty}.
\membersection{wxCommandProcessor::SetEditMenu}\label{wxcommandprocessorseteditmenu} \membersection{wxCommandProcessor::SetEditMenu}\label{wxcommandprocessorseteditmenu}
\func{void}{SetEditMenu}{\param{wxMenu* }{menu}} \func{void}{SetEditMenu}{\param{wxMenu* }{menu}}
@ -111,6 +143,7 @@ menu as appropriate. Set this to NULL if the menu is about to be
destroyed and command operations may still be performed, or the command destroyed and command operations may still be performed, or the command
processor may try to access an invalid pointer. processor may try to access an invalid pointer.
\membersection{wxCommandProcessor::SetMenuStrings}\label{wxcommandprocessorsetmenustrings} \membersection{wxCommandProcessor::SetMenuStrings}\label{wxcommandprocessorsetmenustrings}
\func{void}{SetMenuStrings}{\void} \func{void}{SetMenuStrings}{\void}
@ -118,18 +151,21 @@ processor may try to access an invalid pointer.
Sets the menu labels according to the currently set menu and the current Sets the menu labels according to the currently set menu and the current
command state. command state.
\membersection{wxCommandProcessor::SetRedoAccelerator}\label{wxcommandprocessorsetredoaccelerator} \membersection{wxCommandProcessor::SetRedoAccelerator}\label{wxcommandprocessorsetredoaccelerator}
\func{void}{SetRedoAccelerator}{\param{const wxString\&}{accel}} \func{void}{SetRedoAccelerator}{\param{const wxString\&}{accel}}
Sets the string that will be appended to the Redo menu item. Sets the string that will be appended to the Redo menu item.
\membersection{wxCommandProcessor::SetUndoAccelerator}\label{wxcommandprocessorsetundoaccelerator} \membersection{wxCommandProcessor::SetUndoAccelerator}\label{wxcommandprocessorsetundoaccelerator}
\func{void}{SetUndoAccelerator}{\param{const wxString\&}{accel}} \func{void}{SetUndoAccelerator}{\param{const wxString\&}{accel}}
Sets the string that will be appended to the Undo menu item. Sets the string that will be appended to the Undo menu item.
\membersection{wxCommandProcessor::Submit}\label{wxcommandprocessorsubmit} \membersection{wxCommandProcessor::Submit}\label{wxcommandprocessorsubmit}
\func{virtual bool}{Submit}{\param{wxCommand *}{command}, \param{bool}{ storeIt = true}} \func{virtual bool}{Submit}{\param{wxCommand *}{command}, \param{bool}{ storeIt = true}}
@ -144,6 +180,7 @@ be deleted directly by the application.
{\it storeIt} indicates whether the successful command should be stored {\it storeIt} indicates whether the successful command should be stored
in the history list. in the history list.
\membersection{wxCommandProcessor::Undo}\label{wxcommandprocessorundo} \membersection{wxCommandProcessor::Undo}\label{wxcommandprocessorundo}
\func{virtual bool}{Undo}{\void} \func{virtual bool}{Undo}{\void}

View File

@ -99,6 +99,19 @@ public:
int GetMaxCommands() const { return m_maxNoCommands; } int GetMaxCommands() const { return m_maxNoCommands; }
virtual void ClearCommands(); virtual void ClearCommands();
// Has the current project been changed?
virtual bool IsDirty() const
{
return m_currentCommand && (m_lastSavedCommand != m_currentCommand);
}
// Mark the current command as the one where the last save took place
void MarkAsSaved()
{
m_lastSavedCommand = m_currentCommand;
}
// By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y" // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y"
const wxString& GetUndoAccelerator() const { return m_undoAccelerator; } const wxString& GetUndoAccelerator() const { return m_undoAccelerator; }
const wxString& GetRedoAccelerator() const { return m_redoAccelerator; } const wxString& GetRedoAccelerator() const { return m_redoAccelerator; }
@ -115,7 +128,8 @@ protected:
int m_maxNoCommands; int m_maxNoCommands;
wxList m_commands; wxList m_commands;
wxList::compatibility_iterator m_currentCommand; wxList::compatibility_iterator m_currentCommand,
m_lastSavedCommand;
#if wxUSE_MENUS #if wxUSE_MENUS
wxMenu* m_commandEditMenu; wxMenu* m_commandEditMenu;
@ -130,3 +144,4 @@ private:
}; };
#endif // _WX_CMDPROC_H_ #endif // _WX_CMDPROC_H_

View File

@ -65,9 +65,9 @@ wxCommandProcessor::wxCommandProcessor(int maxCommands)
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
m_undoAccelerator = wxT("\tCtrl+Z"); m_undoAccelerator = wxT("\tCtrl+Z");
m_redoAccelerator = wxT("\tCtrl+Y"); m_redoAccelerator = wxT("\tCtrl+Y");
#if !wxUSE_STL
m_currentCommand = NULL; m_lastSavedCommand =
#endif m_currentCommand = wxList::compatibility_iterator();
} }
wxCommandProcessor::~wxCommandProcessor() wxCommandProcessor::~wxCommandProcessor()
@ -118,6 +118,10 @@ void wxCommandProcessor::Store(wxCommand *command)
wxCommand *firstCommand = (wxCommand *)firstNode->GetData(); wxCommand *firstCommand = (wxCommand *)firstNode->GetData();
delete firstCommand; delete firstCommand;
m_commands.Erase(firstNode); m_commands.Erase(firstNode);
// Make sure m_lastSavedCommand won't point to freed memory
if ( m_lastSavedCommand == firstNode )
m_lastSavedCommand = wxList::compatibility_iterator();
} }
// Correct a bug: we must chop off the current 'branch' // Correct a bug: we must chop off the current 'branch'
@ -132,6 +136,11 @@ void wxCommandProcessor::Store(wxCommand *command)
wxList::compatibility_iterator next = node->GetNext(); wxList::compatibility_iterator next = node->GetNext();
delete (wxCommand *)node->GetData(); delete (wxCommand *)node->GetData();
m_commands.Erase(node); m_commands.Erase(node);
// Make sure m_lastSavedCommand won't point to freed memory
if ( m_lastSavedCommand == node )
m_lastSavedCommand = wxList::compatibility_iterator();
node = next; node = next;
} }
} }
@ -312,7 +321,9 @@ void wxCommandProcessor::ClearCommands()
m_commands.Erase(node); m_commands.Erase(node);
node = m_commands.GetFirst(); node = m_commands.GetFirst();
} }
m_currentCommand = wxList::compatibility_iterator(); m_currentCommand = wxList::compatibility_iterator();
m_lastSavedCommand = wxList::compatibility_iterator();
} }