]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied #15226 wxRichTextCtrl: Implement setting properties with undo for objects...
authorJulian Smart <julian@anthemion.co.uk>
Tue, 1 Oct 2013 15:47:49 +0000 (15:47 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Tue, 1 Oct 2013 15:47:49 +0000 (15:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

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

index c4ad8d1a0aff1d7b07dc70210fea9ba19bcc07e6..14fa4d437ea915f90750e23f2c1ceb50c66c0042 100644 (file)
@@ -3333,7 +3333,7 @@ public:
     /**
         Sets with undo the properties for the given object.
     */
-    virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties);
+    virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet = NULL);
 
     /**
         Test if this whole range has character attributes of the specified kind. If any
@@ -6139,6 +6139,16 @@ public:
     */
     const wxString& GetName() const { return m_name; }
 
+    /**
+        Instructs the first Do() command should be skipped as it's already been applied.
+    */
+    void SetIgnoreFirstTime(bool b) { m_ignoreThis = b; }
+
+    /**
+        Returns true if the first Do() command should be skipped as it's already been applied.
+    */
+    bool GetIgnoreFirstTime() const { return m_ignoreThis; }
+
 protected:
     // Action name
     wxString                        m_name;
index d7118dd75e7dcd3162699b1f174731b5cc3e7ce7..7857043e989f595be4068e3663e35148d3185eec 100644 (file)
@@ -3213,7 +3213,7 @@ public:
     /**
         Sets with undo the properties for the given object.
     */
-    virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties);
+    virtual bool SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet = NULL);
 
     /**
         Test if this whole range has character attributes of the specified kind. If any
@@ -5997,6 +5997,16 @@ public:
     */
     const wxString& GetName() const { return m_name; }
 
+    /**
+        Instructs the first Do() command should be skipped as it's already been applied.
+    */
+    void SetIgnoreFirstTime(bool b);
+
+    /**
+        Returns true if the first Do() command should be skipped as it's already been applied.
+    */
+    bool GetIgnoreFirstTime() const;
+
 protected:
     // Action name
     wxString                        m_name;
index e00ff83983f07b9a80e7f4a47162a0ef77adb86c..33f257e6e46f6735eba28bc12142f8a43aecf6f2 100644 (file)
@@ -7723,7 +7723,7 @@ wxRichTextField* wxRichTextParagraphLayoutBox::InsertFieldWithUndo(wxRichTextBuf
     return obj;
 }
 
-bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties)
+bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet)
 {
     wxRichTextBuffer* buffer = GetBuffer();
     wxCHECK_MSG(buffer, false, wxT("Invalid buffer"));
@@ -7733,39 +7733,28 @@ bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject&
     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);
+        if (objToSet)
+        {
+            // Necessary e.g. if when setting a wxRichTextCell's properties, when obj will be the parent table
+            objToSet->SetProperties(properties);
+        }
+        else
+        {
+            obj.SetProperties(properties);
+        }
+
+        // The 'true' parameter in the next line says "Ignore first time"; otherwise the objects are prematurely switched
+        action = new wxRichTextAction(NULL, _("Change Properties"), wxRICHTEXT_CHANGE_OBJECT, buffer, obj.GetParentContainer(), rtc, true);
         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;
 }
@@ -7926,11 +7915,14 @@ bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action)
 
     if (BatchingUndo() && m_batchedCommand && !SuppressingUndo())
     {
-        wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
-        cmd->AddAction(action);
-        cmd->Do();
-        cmd->GetActions().Clear();
-        delete cmd;
+        if (!action->GetIgnoreFirstTime())
+        {
+            wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
+            cmd->AddAction(action);
+            cmd->Do();
+            cmd->GetActions().Clear();
+            delete cmd;
+        }
 
         m_batchedCommand->AddAction(action);
     }
@@ -7940,7 +7932,14 @@ bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action)
         cmd->AddAction(action);
 
         // Only store it if we're not suppressing undo.
-        return GetCommandProcessor()->Submit(cmd, !SuppressingUndo());
+        if (!action->GetIgnoreFirstTime())
+        {
+            return GetCommandProcessor()->Submit(cmd, !SuppressingUndo());
+        }
+        else if (!SuppressingUndo())
+        {
+            GetCommandProcessor()->Store(cmd); // Just store it, without Do()ing anything
+        }
     }
 
     return true;