mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
feature: add global configuration for custom action (#1077)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
0f9087fac6
commit
5c279b4b56
6 changed files with 182 additions and 6 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue