From: Julian Smart Date: Sun, 29 Sep 2013 16:08:03 +0000 (+0000) Subject: Applied #15226 with modifications: wxRichTextCtrl: Implement setting properties with... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/d0b6c0c52729e737a8d69a61a2f47c24abf18a8c 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 --- diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 4892f944dd..c4ad8d1a0a 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -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 diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index 325b5ca814..d7118dd75e 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -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 diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 98c2e3979e..e00ff83983 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -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.