Applied #15226 wxRichTextCtrl: Implement setting properties with undo for objects e.g. wxRichTextTable (dghart)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3333,7 +3333,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
Sets with undo the properties for the given object.
|
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
|
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; }
|
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:
|
protected:
|
||||||
// Action name
|
// Action name
|
||||||
wxString m_name;
|
wxString m_name;
|
||||||
|
@@ -3213,7 +3213,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
Sets with undo the properties for the given object.
|
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
|
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; }
|
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:
|
protected:
|
||||||
// Action name
|
// Action name
|
||||||
wxString m_name;
|
wxString m_name;
|
||||||
|
@@ -7723,7 +7723,7 @@ wxRichTextField* wxRichTextParagraphLayoutBox::InsertFieldWithUndo(wxRichTextBuf
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties)
|
bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet)
|
||||||
{
|
{
|
||||||
wxRichTextBuffer* buffer = GetBuffer();
|
wxRichTextBuffer* buffer = GetBuffer();
|
||||||
wxCHECK_MSG(buffer, false, wxT("Invalid buffer"));
|
wxCHECK_MSG(buffer, false, wxT("Invalid buffer"));
|
||||||
@@ -7733,39 +7733,28 @@ bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject&
|
|||||||
wxRichTextAction* action = NULL;
|
wxRichTextAction* action = NULL;
|
||||||
wxRichTextObject* clone = NULL;
|
wxRichTextObject* clone = NULL;
|
||||||
|
|
||||||
#if 1
|
|
||||||
if (rtc->SuppressingUndo())
|
if (rtc->SuppressingUndo())
|
||||||
obj.SetProperties(properties);
|
obj.SetProperties(properties);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clone = obj.Clone();
|
clone = obj.Clone();
|
||||||
clone->SetProperties(obj.GetProperties());
|
if (objToSet)
|
||||||
action = new wxRichTextAction(NULL, _("Change Properties"), wxRICHTEXT_CHANGE_OBJECT, buffer, obj.GetParentContainer(), rtc);
|
{
|
||||||
|
// 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->SetOldAndNewObjects(& obj, clone);
|
||||||
action->SetPosition(obj.GetRange().GetStart());
|
action->SetPosition(obj.GetRange().GetStart());
|
||||||
action->SetRange(obj.GetRange());
|
action->SetRange(obj.GetRange());
|
||||||
buffer->SubmitAction(action);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -7926,11 +7915,14 @@ bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action)
|
|||||||
|
|
||||||
if (BatchingUndo() && m_batchedCommand && !SuppressingUndo())
|
if (BatchingUndo() && m_batchedCommand && !SuppressingUndo())
|
||||||
{
|
{
|
||||||
wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
|
if (!action->GetIgnoreFirstTime())
|
||||||
cmd->AddAction(action);
|
{
|
||||||
cmd->Do();
|
wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
|
||||||
cmd->GetActions().Clear();
|
cmd->AddAction(action);
|
||||||
delete cmd;
|
cmd->Do();
|
||||||
|
cmd->GetActions().Clear();
|
||||||
|
delete cmd;
|
||||||
|
}
|
||||||
|
|
||||||
m_batchedCommand->AddAction(action);
|
m_batchedCommand->AddAction(action);
|
||||||
}
|
}
|
||||||
@@ -7940,7 +7932,14 @@ bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action)
|
|||||||
cmd->AddAction(action);
|
cmd->AddAction(action);
|
||||||
|
|
||||||
// Only store it if we're not suppressing undo.
|
// 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;
|
return true;
|
||||||
|
Reference in New Issue
Block a user