mirror of
https://github.com/leozide/leocad.git
synced 2026-07-27 19:56:49 +00:00
Fixed empty undo action added when canceling a property widget edit.
This commit is contained in:
@@ -2020,6 +2020,21 @@ void lcModel::SetSaved()
|
||||
mSavedHistory = GetFirstUndoChange();
|
||||
}
|
||||
|
||||
void lcModel::RemoveFirstUndoIfUnchanged()
|
||||
{
|
||||
if (mUndoHistory.empty())
|
||||
return;
|
||||
|
||||
for (const std::unique_ptr<lcModelAction>& ModelAction : mUndoHistory.front()->ModelActions)
|
||||
if (ModelAction->StateChanged())
|
||||
return;
|
||||
|
||||
mUndoHistory.erase(mUndoHistory.begin());
|
||||
|
||||
gMainWindow->UpdateModified(IsModified());
|
||||
gMainWindow->UpdateUndoRedo(!mUndoHistory.empty() ? mUndoHistory.front()->Description : nullptr, !mRedoHistory.empty() ? mRedoHistory.front()->Description : nullptr);
|
||||
}
|
||||
|
||||
const lcModelHistoryEntry* lcModel::GetFirstUndoChange() const
|
||||
{
|
||||
for (const std::unique_ptr<lcModelHistoryEntry>& UndoEntry : mUndoHistory)
|
||||
@@ -3492,6 +3507,8 @@ void lcModel::MoveSelectedObjects(const lcVector3& PieceDistance, const lcVector
|
||||
{
|
||||
EndObjectEditAction();
|
||||
EndActionSequence(tr("Move"));
|
||||
|
||||
RemoveFirstUndoIfUnchanged();
|
||||
}
|
||||
|
||||
UpdateAllViews();
|
||||
@@ -3676,6 +3693,8 @@ void lcModel::RotateSelectedObjects(const lcVector3& Angles, bool Relative, bool
|
||||
{
|
||||
EndObjectEditAction();
|
||||
EndActionSequence(tr("Rotate"));
|
||||
|
||||
RemoveFirstUndoIfUnchanged();
|
||||
}
|
||||
|
||||
UpdateAllViews();
|
||||
@@ -3904,6 +3923,8 @@ void lcModel::SetObjectsProperty(const std::vector<lcObject*>& Objects, lcObject
|
||||
EndObjectEditAction();
|
||||
EndActionSequence(lcObject::GetCheckpointString(PropertyId));
|
||||
|
||||
RemoveFirstUndoIfUnchanged();
|
||||
|
||||
gMainWindow->UpdateSelectedObjects(false);
|
||||
|
||||
// todo: fix hacky timeline update
|
||||
@@ -3921,6 +3942,8 @@ void lcModel::SetObjectsProperty(const std::vector<lcObject*>& Objects, lcObject
|
||||
|
||||
void lcModel::EndPropertyEdit(lcObjectPropertyId PropertyId, bool Accept)
|
||||
{
|
||||
// todo: right clicking or pressing esc while dragging the spinbox doesn't cancel
|
||||
|
||||
if (!Accept)
|
||||
{
|
||||
RevertActionSequence();
|
||||
|
||||
@@ -410,6 +410,7 @@ protected:
|
||||
void EndActionSequence(const QString& Description);
|
||||
void DiscardActionSequence();
|
||||
void RevertActionSequence();
|
||||
void RemoveFirstUndoIfUnchanged();
|
||||
const lcModelHistoryEntry* GetFirstUndoChange() const;
|
||||
|
||||
void SaveCheckpoint(const QString& Description);
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
virtual void SaveEndState(const lcModel* Model) = 0;
|
||||
virtual void LoadStartState(lcModel* Model) const = 0;
|
||||
virtual void LoadEndState(lcModel* Model) const = 0;
|
||||
virtual bool StateChanged() const = 0;
|
||||
|
||||
virtual bool CanMergeWith(const lcModelAction* Other) const
|
||||
{
|
||||
@@ -55,8 +56,7 @@ public:
|
||||
void SaveEndState(const lcModel* Model) override;
|
||||
void LoadStartState(lcModel* Model) const override;
|
||||
void LoadEndState(lcModel* Model) const override;
|
||||
|
||||
bool StateChanged() const;
|
||||
bool StateChanged() const override;
|
||||
|
||||
protected:
|
||||
static void SaveState(lcModelActionSelectionState& State, const lcModel* Model);
|
||||
@@ -101,8 +101,8 @@ public:
|
||||
void SaveEndState(const lcModel* Model) override;
|
||||
void LoadStartState(lcModel* Model) const override;
|
||||
void LoadEndState(lcModel* Model) const override;
|
||||
|
||||
bool StateChanged() const;
|
||||
bool StateChanged() const override;
|
||||
|
||||
bool CanMergeWith(const lcModelAction* Other) const override;
|
||||
void MergeWith(lcModelAction* Other) override;
|
||||
|
||||
@@ -125,8 +125,7 @@ public:
|
||||
void SaveEndState(const lcModel* Model) override;
|
||||
void LoadStartState(lcModel* Model) const override;
|
||||
void LoadEndState(lcModel* Model) const override;
|
||||
|
||||
bool StateChanged() const;
|
||||
bool StateChanged() const override;
|
||||
|
||||
protected:
|
||||
static void SaveState(lcModelProperties& State, const lcModel* Model);
|
||||
|
||||
Reference in New Issue
Block a user