Applied #15226 with modifications: wxRichTextCtrl: Implement setting properties with undo for objects e.g. wxRichTextTable (dghart)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2013-09-29 16:08:03 +00:00
parent b7348ed0cf
commit d0b6c0c527
3 changed files with 57 additions and 0 deletions

View File

@ -3330,6 +3330,11 @@ public:
*/
virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO);
/**
Sets with undo the properties for the given object.
*/
virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties);
/**
Test if this whole range has character attributes of the specified kind. If any
of the attributes are different within the range, the test fails. You

View File

@ -3210,6 +3210,11 @@ public:
*/
virtual bool SetProperties(const wxRichTextRange& range, const wxRichTextProperties& properties, int flags = wxRICHTEXT_SETPROPERTIES_WITH_UNDO);
/**
Sets with undo the properties for the given object.
*/
virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties);
/**
Test if this whole range has character attributes of the specified kind. If any
of the attributes are different within the range, the test fails. You

View File

@ -7723,6 +7723,53 @@ wxRichTextField* wxRichTextParagraphLayoutBox::InsertFieldWithUndo(wxRichTextBuf
return obj;
}
bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties)
{
wxRichTextBuffer* buffer = GetBuffer();
wxCHECK_MSG(buffer, false, wxT("Invalid buffer"));
wxRichTextCtrl* rtc = buffer->GetRichTextCtrl();
wxCHECK_MSG(rtc, false, wxT("Invalid rtc"));
wxRichTextAction* action = NULL;
wxRichTextObject* clone = NULL;
#if 1
if (rtc->SuppressingUndo())
obj.SetProperties(properties);
else
{
clone = obj.Clone();
clone->SetProperties(obj.GetProperties());
action = new wxRichTextAction(NULL, _("Change Properties"), wxRICHTEXT_CHANGE_OBJECT, buffer, obj.GetParentContainer(), rtc);
action->SetOldAndNewObjects(& obj, clone);
action->SetPosition(obj.GetRange().GetStart());
action->SetRange(obj.GetRange());
buffer->SubmitAction(action);
}
#else
if (!rtc->SuppressingUndo())
{
// Create a clone containing the current state of the object. It will be used to Undo the action
clone = obj.Clone();
clone->SetParent(obj.GetParent());
action = new wxRichTextAction(NULL, _("Change Properties"), wxRICHTEXT_CHANGE_OBJECT, buffer, rtc->GetFocusObject(), rtc);
action->SetObject(&obj);
action->SetPosition(GetRange().GetStart());
}
obj.SetProperties(properties);
if (!rtc->SuppressingUndo())
{
buffer->SubmitAction(action);
// Finally store the original-state clone; doing so earlier would cause various failures
action->StoreObject(clone);
}
#endif
return true;
}
/// Get the style that is appropriate for a new paragraph at this position.
/// If the previous paragraph has a paragraph style name, look up the next-paragraph
/// style.