Allow undoing overwriting designs.

This commit is contained in:
Ottermandias 2023-11-10 19:00:33 +01:00
parent 36f6c48f7a
commit 859c738080
2 changed files with 45 additions and 7 deletions

View file

@ -84,6 +84,16 @@ public class DesignPanel
Disabled = _selector.Selected?.WriteProtected() ?? true,
};
private HeaderDrawer.Button UndoButton()
=> new()
{
Description = "Undo the last change if you accidentally overwrote your design with a different one.",
Icon = FontAwesomeIcon.Undo,
OnClick = UndoOverwrite,
Visible = _selector.Selected != null,
Disabled = !_manager.CanUndo(_selector.Selected),
};
private HeaderDrawer.Button ExportToClipboardButton()
=> new()
{
@ -95,7 +105,7 @@ public class DesignPanel
private void DrawHeader()
=> HeaderDrawer.Draw(SelectionName, 0, ImGui.GetColorU32(ImGuiCol.FrameBg),
2, SetFromClipboardButton(), ExportToClipboardButton(), LockButton(),
3, SetFromClipboardButton(), UndoButton(), ExportToClipboardButton(), LockButton(),
HeaderDrawer.Button.IncognitoButton(_selector.IncognitoMode, v => _selector.IncognitoMode = v));
private string SelectionName
@ -411,6 +421,18 @@ public class DesignPanel
}
}
private void UndoOverwrite()
{
try
{
_manager.UndoDesignChange(_selector.Selected!);
}
catch (Exception ex)
{
Glamourer.Messager.NotificationMessage(ex, $"Could not undo last changes to {_selector.Selected!.Name}.", NotificationType.Error, false);
}
}
private void ExportToClipboard()
{
try