sourcegit/src/Views/RepositoryConfigure.axaml.cs
leo 676785f8b1
feature: support to use input control in custom action
Signed-off-by: leo <longshuang@msn.cn>
2025-06-25 16:28:54 +08:00

60 lines
1.8 KiB
C#

using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
namespace SourceGit.Views
{
public partial class RepositoryConfigure : ChromelessWindow
{
public RepositoryConfigure()
{
InitializeComponent();
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (!e.Handled && e.Key == Key.Escape)
Close();
}
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
if (!Design.IsDesignMode && DataContext is ViewModels.RepositoryConfigure configure)
configure.Save();
}
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 async void EditCustomActionControls(object sender, RoutedEventArgs e)
{
if (sender is not Button { DataContext: Models.CustomAction act })
return;
var dialog = new ConfigureCustomActionControls()
{
DataContext = new ViewModels.ConfigureCustomActionControls(act.Controls)
};
await dialog.ShowDialog(this);
e.Handled = true;
}
}
}