From 98041c803e0c3cfae6b5b300e0385d7482f487fc Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 3 Jun 2025 20:24:30 +0800 Subject: [PATCH] feature: supports re-order custom actions (#1346) Signed-off-by: leo --- src/Models/RepositorySettings.cs | 14 ++++++++++++ src/ViewModels/RepositoryConfigure.cs | 12 ++++++++++ src/Views/Preferences.axaml | 33 +++++++++++++++++++-------- src/Views/Preferences.axaml.cs | 24 +++++++++++++++++++ src/Views/RepositoryConfigure.axaml | 33 +++++++++++++++++++-------- 5 files changed, 98 insertions(+), 18 deletions(-) diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 34189073..306ba189 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -453,5 +453,19 @@ namespace SourceGit.Models if (act != null) CustomActions.Remove(act); } + + public void MoveCustomActionUp(CustomAction act) + { + var idx = CustomActions.IndexOf(act); + if (idx > 0) + CustomActions.Move(idx - 1, idx); + } + + public void MoveCustomActionDown(CustomAction act) + { + var idx = CustomActions.IndexOf(act); + if (idx < CustomActions.Count - 1) + CustomActions.Move(idx + 1, idx); + } } } diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 9a3bc9c4..d8a62a48 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -304,6 +304,18 @@ namespace SourceGit.ViewModels SelectedCustomAction = null; } + public void MoveSelectedCustomActionUp() + { + if (_selectedCustomAction != null) + _repo.Settings.MoveCustomActionUp(_selectedCustomAction); + } + + public void MoveSelectedCustomActionDown() + { + if (_selectedCustomAction != null) + _repo.Settings.MoveCustomActionDown(_selectedCustomAction); + } + public void Save() { SetIfChanged("user.name", UserName, ""); diff --git a/src/Views/Preferences.axaml b/src/Views/Preferences.axaml index b5826d11..beb228b6 100644 --- a/src/Views/Preferences.axaml +++ b/src/Views/Preferences.axaml @@ -583,19 +583,34 @@ - - - - - - - - - + + + diff --git a/src/Views/Preferences.axaml.cs b/src/Views/Preferences.axaml.cs index 5c8fb7aa..85de6a14 100644 --- a/src/Views/Preferences.axaml.cs +++ b/src/Views/Preferences.axaml.cs @@ -415,6 +415,30 @@ namespace SourceGit.Views e.Handled = true; } + private void OnMoveSelectedCustomActionUp(object sender, RoutedEventArgs e) + { + if (SelectedCustomAction == null) + return; + + var idx = ViewModels.Preferences.Instance.CustomActions.IndexOf(SelectedCustomAction); + if (idx > 0) + ViewModels.Preferences.Instance.CustomActions.Move(idx - 1, idx); + + e.Handled = true; + } + + private void OnMoveSelectedCustomActionDown(object sender, RoutedEventArgs e) + { + if (SelectedCustomAction == null) + return; + + var idx = ViewModels.Preferences.Instance.CustomActions.IndexOf(SelectedCustomAction); + if (idx < ViewModels.Preferences.Instance.CustomActions.Count - 1) + ViewModels.Preferences.Instance.CustomActions.Move(idx + 1, idx); + + e.Handled = true; + } + private void UpdateGitVersion() { GitVersion = Native.OS.GitVersionString; diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index ee1d6fa8..509adcd8 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -417,19 +417,34 @@ - - - - - - - - - + + +