feature: add global configuration for custom action (#1077)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-10 21:19:38 +08:00
parent 0f9087fac6
commit 5c279b4b56
No known key found for this signature in database
6 changed files with 182 additions and 6 deletions

View file

@ -103,6 +103,15 @@ namespace SourceGit.Views
set => SetValue(SelectedOpenAIServiceProperty, value);
}
public static readonly StyledProperty<Models.CustomAction> SelectedCustomActionProperty =
AvaloniaProperty.Register<Preferences, Models.CustomAction>(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;