]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied #15226 with modifications: wxRichTextCtrl: Implement setting properties with...
authorJulian Smart <julian@anthemion.co.uk>
Sun, 29 Sep 2013 16:08:03 +0000 (16:08 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sun, 29 Sep 2013 16:08:03 +0000 (16:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/richtext/richtextbuffer.h
interface/wx/richtext/richtextbuffer.h
src/richtext/richtextbuffer.cpp

index 4892f944dd20f684f6045c665d56b3ae22eab0c7..c4ad8d1a0aff1d7b07dc70210fea9ba19bcc07e6 100644 (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
index 325b5ca8145a84af963f1b45fe1d629cfd5ddcee..d7118dd75e7dcd3162699b1f174731b5cc3e7ce7 100644 (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
index 98c2e3979ee19a10d4b7067fbc7f7d1b4065626e..e00ff83983f07b9a80e7f4a47162a0ef77adb86c 100644 (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.