/**
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
*/
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;
/**
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
*/
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;
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"));
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;
}
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);
}
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;