ux: always show the scope target of custom action (#1466)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-27 15:37:20 +08:00
parent f36ab4a189
commit b0a80e41ee
No known key found for this signature in database
6 changed files with 70 additions and 25 deletions

View file

@ -318,7 +318,7 @@
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">Ziel:</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">Ausgewählte Gruppe bearbeiten</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">Ausgewähltes Repository bearbeiten</x:String>
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">Aktion wird durchgeführt, bitte warten...</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">Ziel:</x:String>
<x:String x:Key="Text.Fetch" xml:space="preserve">Fetch</x:String>
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Alle Remotes fetchen</x:String>
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Aktiviere '--force' Option</x:String>

View file

@ -314,7 +314,8 @@
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">Target:</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">Edit Selected Group</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">Edit Selected Repository</x:String>
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">Action is running, please wait...</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">Target:</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">This repository</x:String>
<x:String x:Key="Text.Fetch" xml:space="preserve">Fetch</x:String>
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Fetch all remotes</x:String>
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Force override local refs</x:String>

View file

@ -318,7 +318,8 @@
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">目标 </x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">编辑分组</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">编辑仓库</x:String>
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">操作正在进行中,请耐心等待...</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">目标:</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">本仓库</x:String>
<x:String x:Key="Text.Fetch" xml:space="preserve">拉取(fetch)</x:String>
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">拉取所有的远程仓库</x:String>
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">强制覆盖本地REFs</x:String>

View file

@ -318,7 +318,8 @@
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">目標:</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">編輯群組</x:String>
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">編輯存放庫</x:String>
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">動作正在執行中,請稍候...</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">目標:</x:String>
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">本存放庫</x:String>
<x:String x:Key="Text.Fetch" xml:space="preserve">提取 (fetch)</x:String>
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">提取所有的遠端存放庫</x:String>
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">強制覆寫本機 REFs</x:String>

View file

@ -21,7 +21,7 @@ namespace SourceGit.ViewModels
public CustomActionControlTextBox(string label, string placeholder, string defaultValue)
{
Label = label;
Label = label + ":";
Placeholder = placeholder;
Text = defaultValue;
}
@ -43,7 +43,7 @@ namespace SourceGit.ViewModels
public CustomActionControlPathSelector(string label, string placeholder, bool isFolder, string defaultValue)
{
Label = label;
Label = label + ":";
Placeholder = placeholder;
IsFolder = isFolder;
_path = defaultValue;
@ -79,45 +79,45 @@ namespace SourceGit.ViewModels
get;
}
public object Target
{
get;
}
public List<ICustomActionControlParameter> ControlParameters
{
get;
} = [];
public bool IsSimpleMode
{
get => ControlParameters.Count == 0;
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action)
{
_repo = repo;
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir());
CustomAction = action;
Target = new Models.Null();
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
{
_repo = repo;
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${BRANCH}", branch.FriendlyName);
CustomAction = action;
Target = branch;
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
{
_repo = repo;
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${SHA}", commit.SHA);
CustomAction = action;
Target = commit;
PrepareControlParameters();
}
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Tag tag)
{
_repo = repo;
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${TAG}", tag.Name);
CustomAction = action;
Target = tag;
PrepareControlParameters();
}
@ -126,7 +126,14 @@ namespace SourceGit.ViewModels
_repo.SetWatcherEnabled(false);
ProgressDescription = "Run custom action ...";
var cmdline = _commandline;
var cmdline = CustomAction.Arguments.Replace("${REPO}", GetWorkdir());
if (Target is Models.Branch b)
cmdline = cmdline.Replace("${BRANCH}", b.FriendlyName);
else if (Target is Models.Commit c)
cmdline = cmdline.Replace("${SHA}", c.SHA);
else if (Target is Models.Tag t)
cmdline = cmdline.Replace("${TAG}", t.Name);
for (var i = ControlParameters.Count - 1; i >= 0; i--)
{
var param = ControlParameters[i];
@ -249,6 +256,5 @@ namespace SourceGit.ViewModels
}
private readonly Repository _repo = null;
private readonly string _commandline = string.Empty;
}
}

View file

@ -2,7 +2,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="SourceGit.Views.ExecuteCustomAction"
x:DataType="vm:ExecuteCustomAction">
@ -11,13 +13,47 @@
Classes="bold"
Text="{Binding CustomAction.Name}"/>
<Grid Margin="0,16,0,0" IsVisible="{Binding IsSimpleMode}">
<TextBlock Text="{DynamicResource Text.ExecuteCustomAction.SimpleWait}"
HorizontalAlignment="Center"/>
<Grid Margin="0,16,0,0" Height="32" ColumnDefinitions="150,*">
<TextBlock Grid.Column="0"
Text="{DynamicResource Text.ExecuteCustomAction.Target}"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"/>
<ContentControl Grid.Column="1" Content="{Binding Target}">
<ContentControl.DataTemplates>
<DataTemplate DataType="m:Null">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Repositories}"/>
<SelectableTextBlock VerticalAlignment="Center" Text="{DynamicResource Text.ExecuteCustomAction.Repository}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="m:Branch">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
<SelectableTextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="m:Commit">
<Grid ColumnDefinitions="Auto,Auto,*">
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Commit}"/>
<TextBlock Grid.Column="1" Classes="primary" VerticalAlignment="Center" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0"/>
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Subject}" Margin="4,0,0,0" TextTrimming="CharacterEllipsis"/>
</Grid>
</DataTemplate>
<DataTemplate DataType="m:Tag">
<StackPanel Orientation="Horizontal">
<Path Width="14" Height="14" Data="{StaticResource Icons.Tag}"/>
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" Margin="8,0,0,0"/>
</StackPanel>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</Grid>
<ListBox Margin="0,16,0,0"
IsVisible="{Binding !IsSimpleMode}"
<ListBox IsVisible="{Binding ControlParameters, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
ItemsSource="{Binding ControlParameters, Mode=OneWay}">
<ListBox.Styles>
<Style Selector="ListBoxItem">
@ -39,7 +75,7 @@
<ListBox.DataTemplates>
<DataTemplate DataType="vm:CustomActionControlTextBox">
<Grid ColumnDefinitions="120,*">
<Grid ColumnDefinitions="150,*">
<TextBlock Grid.Column="0"
Text="{Binding Label}"
HorizontalAlignment="Right" VerticalAlignment="Center"
@ -55,7 +91,7 @@
</DataTemplate>
<DataTemplate DataType="vm:CustomActionControlCheckBox">
<Grid ColumnDefinitions="120,*">
<Grid ColumnDefinitions="150,*">
<CheckBox Grid.Column="1"
Content="{Binding Label}"
ToolTip.Tip="{Binding ToolTip, Mode=OneWay}"
@ -64,7 +100,7 @@
</DataTemplate>
<DataTemplate DataType="vm:CustomActionControlPathSelector">
<Grid ColumnDefinitions="120,*">
<Grid ColumnDefinitions="150,*">
<TextBlock Grid.Column="0"
Text="{Binding Label}"
HorizontalAlignment="Right" VerticalAlignment="Center"