diff --git a/src/ViewModels/InteractiveRebase.cs b/src/ViewModels/InteractiveRebase.cs index a8fe1c2b..1c4d4480 100644 --- a/src/ViewModels/InteractiveRebase.cs +++ b/src/ViewModels/InteractiveRebase.cs @@ -35,7 +35,7 @@ namespace SourceGit.ViewModels public Models.InteractiveRebaseAction Action { get => _action; - private set => SetProperty(ref _action, value); + set => SetProperty(ref _action, value); } public string Subject @@ -68,11 +68,6 @@ namespace SourceGit.ViewModels CanSquashOrFixup = canSquashOrFixup; } - public void SetAction(object param) - { - Action = (Models.InteractiveRebaseAction)param; - } - private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick; private string _subject; private string _fullMessage; @@ -158,10 +153,8 @@ namespace SourceGit.ViewModels var prev = Items[idx - 1]; Items.RemoveAt(idx - 1); Items.Insert(idx, prev); - - item.CanSquashOrFixup = true; - prev.CanSquashOrFixup = idx < Items.Count - 1; SelectedItem = item; + UpdateItems(); } } @@ -173,13 +166,23 @@ namespace SourceGit.ViewModels var next = Items[idx + 1]; Items.RemoveAt(idx + 1); Items.Insert(idx, next); - - item.CanSquashOrFixup = idx < Items.Count - 2; - next.CanSquashOrFixup = true; SelectedItem = item; + UpdateItems(); } } + public void ChangeAction(InteractiveRebaseItem item, Models.InteractiveRebaseAction action) + { + if (!item.CanSquashOrFixup) + { + if (action == Models.InteractiveRebaseAction.Squash || action == Models.InteractiveRebaseAction.Fixup) + return; + } + + item.Action = action; + UpdateItems(); + } + public Task Start() { _repo.SetWatcherEnabled(false); @@ -210,6 +213,27 @@ namespace SourceGit.ViewModels }); } + private void UpdateItems() + { + if (Items.Count == 0) + return; + + var hasValidParent = false; + for (var i = Items.Count - 1; i >= 0; i--) + { + var item = Items[i]; + if (hasValidParent) + { + item.CanSquashOrFixup = true; + } + else + { + item.CanSquashOrFixup = false; + hasValidParent = item.Action != Models.InteractiveRebaseAction.Drop; + } + } + } + private Repository _repo = null; private bool _isLoading = false; private InteractiveRebaseItem _selectedItem = null; diff --git a/src/Views/InteractiveRebase.axaml b/src/Views/InteractiveRebase.axaml index 7307eb84..f9f69e88 100644 --- a/src/Views/InteractiveRebase.axaml +++ b/src/Views/InteractiveRebase.axaml @@ -107,7 +107,7 @@