mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
feature: add Wait for action done
option to control whether or not to wait for the custom action execution to complete (#951)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
10fba08e43
commit
af20ab2448
7 changed files with 49 additions and 3 deletions
|
@ -8,7 +8,37 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public static class ExecuteCustomAction
|
||||
{
|
||||
public static void Run(string repo, string file, string args, Action<string> outputHandler)
|
||||
public static void Run(string repo, string file, string args)
|
||||
{
|
||||
var start = new ProcessStartInfo();
|
||||
start.FileName = file;
|
||||
start.Arguments = args;
|
||||
start.UseShellExecute = false;
|
||||
start.CreateNoWindow = true;
|
||||
start.WorkingDirectory = repo;
|
||||
|
||||
// Force using en_US.UTF-8 locale to avoid GCM crash
|
||||
if (OperatingSystem.IsLinux())
|
||||
start.Environment.Add("LANG", "en_US.UTF-8");
|
||||
|
||||
// Fix macOS `PATH` env
|
||||
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
|
||||
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(start);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
App.RaiseException(repo, e.Message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void RunAndWait(string repo, string file, string args, Action<string> outputHandler)
|
||||
{
|
||||
var start = new ProcessStartInfo();
|
||||
start.FileName = file;
|
||||
|
|
|
@ -34,9 +34,16 @@ namespace SourceGit.Models
|
|||
set => SetProperty(ref _arguments, value);
|
||||
}
|
||||
|
||||
public bool WaitForExit
|
||||
{
|
||||
get => _waitForExit;
|
||||
set => SetProperty(ref _waitForExit, value);
|
||||
}
|
||||
|
||||
private string _name = string.Empty;
|
||||
private CustomActionScope _scope = CustomActionScope.Repository;
|
||||
private string _executable = string.Empty;
|
||||
private string _arguments = string.Empty;
|
||||
private bool _waitForExit = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,6 +158,7 @@
|
|||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">Scope:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">Commit</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">Repository</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">Wait for action done</x:String>
|
||||
<x:String x:Key="Text.Configure.Email" xml:space="preserve">Email Address</x:String>
|
||||
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">Email address</x:String>
|
||||
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT</x:String>
|
||||
|
|
|
@ -161,6 +161,7 @@
|
|||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">作用目标 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">选中的提交</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">仓库</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待操作执行完成</x:String>
|
||||
<x:String x:Key="Text.Configure.Email" xml:space="preserve">电子邮箱</x:String>
|
||||
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">邮箱地址</x:String>
|
||||
<x:String x:Key="Text.Configure.Git" xml:space="preserve">GIT配置</x:String>
|
||||
|
|
|
@ -161,6 +161,7 @@
|
|||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">執行範圍:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Commit" xml:space="preserve">選取的提交</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">存放庫</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待自訂操作退出</x:String>
|
||||
<x:String x:Key="Text.Configure.Email" xml:space="preserve">電子郵件</x:String>
|
||||
<x:String x:Key="Text.Configure.Email.Placeholder" xml:space="preserve">電子郵件地址</x:String>
|
||||
<x:String x:Key="Text.Configure.Git" xml:space="preserve">Git 設定</x:String>
|
||||
|
|
|
@ -28,7 +28,11 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription);
|
||||
if (CustomAction.WaitForExit)
|
||||
Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, _args, SetProgressDescription);
|
||||
else
|
||||
Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args);
|
||||
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -341,7 +341,7 @@
|
|||
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Configure.CustomAction}"/>
|
||||
</TabItem.Header>
|
||||
|
||||
<Grid ColumnDefinitions="200,*" Height="250" Margin="0,8,0,16">
|
||||
<Grid ColumnDefinitions="200,*" Height="300" Margin="0,8,0,16">
|
||||
<Border Grid.Column="0"
|
||||
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border2}"
|
||||
Background="{DynamicResource Brush.Contents}">
|
||||
|
@ -439,6 +439,8 @@
|
|||
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Arguments}"/>
|
||||
<TextBox Margin="0,4,0,0" CornerRadius="3" Height="28" Text="{Binding Arguments, Mode=TwoWay}"/>
|
||||
<TextBlock Margin="0,2,0,0" TextWrapping="Wrap" Text="{DynamicResource Text.Configure.CustomAction.Arguments.Tip}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
|
||||
<CheckBox Margin="0,8,0,0" Content="{DynamicResource Text.Configure.CustomAction.WaitForExit}" IsChecked="{Binding WaitForExit, Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue