diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index 08bf48ca..76a7f160 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -471,11 +471,7 @@ namespace SourceGit.Models public CustomAction AddNewCustomAction() { - var act = new CustomAction() - { - Name = "Unnamed Custom Action", - }; - + var act = new CustomAction() { Name = "Unnamed Action" }; CustomActions.Add(act); return act; } diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 48ce114d..301cbb3c 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -695,6 +695,11 @@ namespace SourceGit.ViewModels menu.Items.Add(new MenuItem() { Header = "-" }); var actions = new List(); + foreach (var action in Preferences.Instance.CustomActions) + { + if (action.Scope == Models.CustomActionScope.Commit) + actions.Add(action); + } foreach (var action in _repo.Settings.CustomActions) { if (action.Scope == Models.CustomActionScope.Commit) diff --git a/src/ViewModels/Preferences.cs b/src/ViewModels/Preferences.cs index 016fd4c4..dae90517 100644 --- a/src/ViewModels/Preferences.cs +++ b/src/ViewModels/Preferences.cs @@ -342,6 +342,12 @@ namespace SourceGit.ViewModels set; } = []; + public AvaloniaList CustomActions + { + get; + set; + } = []; + public AvaloniaList OpenAIServices { get; diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 2294fdde..5d2778c9 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1444,6 +1444,12 @@ namespace SourceGit.ViewModels public ContextMenu CreateContextMenuForCustomAction() { var actions = new List(); + foreach (var action in Preferences.Instance.CustomActions) + { + if (action.Scope == Models.CustomActionScope.Repository) + actions.Add(action); + } + foreach (var action in _settings.CustomActions) { if (action.Scope == Models.CustomActionScope.Repository) @@ -2350,6 +2356,12 @@ namespace SourceGit.ViewModels private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch) { var actions = new List(); + foreach (var action in Preferences.Instance.CustomActions) + { + if (action.Scope == Models.CustomActionScope.Branch) + actions.Add(action); + } + foreach (var action in Settings.CustomActions) { if (action.Scope == Models.CustomActionScope.Branch) diff --git a/src/Views/Preferences.axaml b/src/Views/Preferences.axaml index 12679e50..236deb1f 100644 --- a/src/Views/Preferences.axaml +++ b/src/Views/Preferences.axaml @@ -527,12 +527,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + diff --git a/src/Views/Preferences.axaml.cs b/src/Views/Preferences.axaml.cs index 8f9917be..324d2375 100644 --- a/src/Views/Preferences.axaml.cs +++ b/src/Views/Preferences.axaml.cs @@ -103,6 +103,15 @@ namespace SourceGit.Views set => SetValue(SelectedOpenAIServiceProperty, value); } + public static readonly StyledProperty SelectedCustomActionProperty = + AvaloniaProperty.Register(nameof(SelectedCustomAction)); + + public Models.CustomAction SelectedCustomAction + { + get => GetValue(SelectedCustomActionProperty); + set => SetValue(SelectedCustomActionProperty, value); + } + public Preferences() { var pref = ViewModels.Preferences.Instance; @@ -368,6 +377,40 @@ namespace SourceGit.Views e.Handled = true; } + private void OnAddCustomAction(object sender, RoutedEventArgs e) + { + var action = new Models.CustomAction() { Name = "Unnamed Action (Global)" }; + ViewModels.Preferences.Instance.CustomActions.Add(action); + SelectedCustomAction = action; + + e.Handled = true; + } + + private async void SelectExecutableForCustomAction(object sender, RoutedEventArgs e) + { + var options = new FilePickerOpenOptions() + { + FileTypeFilter = [new FilePickerFileType("Executable file(script)") { Patterns = ["*.*"] }], + AllowMultiple = false, + }; + + var selected = await StorageProvider.OpenFilePickerAsync(options); + if (selected.Count == 1 && sender is Button { DataContext: Models.CustomAction action }) + action.Executable = selected[0].Path.LocalPath; + + e.Handled = true; + } + + private void OnRemoveSelectedCustomAction(object sender, RoutedEventArgs e) + { + if (SelectedCustomAction == null) + return; + + ViewModels.Preferences.Instance.CustomActions.Remove(SelectedCustomAction); + SelectedCustomAction = null; + e.Handled = true; + } + private void UpdateGitVersion() { GitVersion = Native.OS.GitVersionString;