Implement freeze/thaw in Do/Undo to considerably speed up commands with a large number of actions (commit omitted part)

This commit is contained in:
JulianSmart
2015-11-14 18:47:33 +00:00
parent 1675e641e6
commit 6993b73042

View File

@@ -11645,11 +11645,13 @@ void wxRichTextModuleInit()
wxRichTextCommand::wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer, wxRichTextCommand::wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
wxRichTextParagraphLayoutBox* container, wxRichTextCtrl* ctrl, bool ignoreFirstTime): wxCommand(true, name) wxRichTextParagraphLayoutBox* container, wxRichTextCtrl* ctrl, bool ignoreFirstTime): wxCommand(true, name)
{ {
m_freeze = ctrl ? ctrl->IsFrozen() : false;
/* wxRichTextAction* action = */ new wxRichTextAction(this, name, id, buffer, container, ctrl, ignoreFirstTime); /* wxRichTextAction* action = */ new wxRichTextAction(this, name, id, buffer, container, ctrl, ignoreFirstTime);
} }
wxRichTextCommand::wxRichTextCommand(const wxString& name): wxCommand(true, name) wxRichTextCommand::wxRichTextCommand(const wxString& name): wxCommand(true, name)
{ {
m_freeze = false;
} }
wxRichTextCommand::~wxRichTextCommand() wxRichTextCommand::~wxRichTextCommand()
@@ -11661,6 +11663,9 @@ void wxRichTextCommand::AddAction(wxRichTextAction* action)
{ {
if (!m_actions.Member(action)) if (!m_actions.Member(action))
m_actions.Append(action); m_actions.Append(action);
if (!m_freeze && action->GetRichTextCtrl() && action->GetRichTextCtrl()->IsFrozen())
m_freeze = true;
} }
bool wxRichTextCommand::Do() bool wxRichTextCommand::Do()
@@ -11668,7 +11673,13 @@ bool wxRichTextCommand::Do()
for (wxList::compatibility_iterator node = m_actions.GetFirst(); node; node = node->GetNext()) for (wxList::compatibility_iterator node = m_actions.GetFirst(); node; node = node->GetNext())
{ {
wxRichTextAction* action = (wxRichTextAction*) node->GetData(); wxRichTextAction* action = (wxRichTextAction*) node->GetData();
if (GetFreeze() && node == m_actions.GetFirst() && action->GetRichTextCtrl())
action->GetRichTextCtrl()->Freeze();
action->Do(); action->Do();
if (GetFreeze() && node == m_actions.GetLast() && action->GetRichTextCtrl())
action->GetRichTextCtrl()->Thaw();
} }
return true; return true;
@@ -11679,7 +11690,13 @@ bool wxRichTextCommand::Undo()
for (wxList::compatibility_iterator node = m_actions.GetLast(); node; node = node->GetPrevious()) for (wxList::compatibility_iterator node = m_actions.GetLast(); node; node = node->GetPrevious())
{ {
wxRichTextAction* action = (wxRichTextAction*) node->GetData(); wxRichTextAction* action = (wxRichTextAction*) node->GetData();
if (GetFreeze() && node == m_actions.GetLast() && action->GetRichTextCtrl())
action->GetRichTextCtrl()->Freeze();
action->Undo(); action->Undo();
if (GetFreeze() && node == m_actions.GetFirst() && action->GetRichTextCtrl())
action->GetRichTextCtrl()->Thaw();
} }
return true; return true;