Skip to content

Commit b0a80e4

Browse files
committed
ux: always show the scope target of custom action (#1466)
Signed-off-by: leo <[email protected]>
1 parent f36ab4a commit b0a80e4

File tree

6 files changed

+70
-25
lines changed

6 files changed

+70
-25
lines changed

src/Resources/Locales/de_DE.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@
318318
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">Ziel:</x:String>
319319
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">Ausgewählte Gruppe bearbeiten</x:String>
320320
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">Ausgewähltes Repository bearbeiten</x:String>
321-
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">Aktion wird durchgeführt, bitte warten...</x:String>
321+
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">Ziel:</x:String>
322322
<x:String x:Key="Text.Fetch" xml:space="preserve">Fetch</x:String>
323323
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Alle Remotes fetchen</x:String>
324324
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Aktiviere '--force' Option</x:String>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@
314314
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">Target:</x:String>
315315
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">Edit Selected Group</x:String>
316316
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">Edit Selected Repository</x:String>
317-
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">Action is running, please wait...</x:String>
317+
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">Target:</x:String>
318+
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">This repository</x:String>
318319
<x:String x:Key="Text.Fetch" xml:space="preserve">Fetch</x:String>
319320
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">Fetch all remotes</x:String>
320321
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">Force override local refs</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@
318318
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">目标 :</x:String>
319319
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">编辑分组</x:String>
320320
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">编辑仓库</x:String>
321-
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">操作正在进行中,请耐心等待...</x:String>
321+
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">目标:</x:String>
322+
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">本仓库</x:String>
322323
<x:String x:Key="Text.Fetch" xml:space="preserve">拉取(fetch)</x:String>
323324
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">拉取所有的远程仓库</x:String>
324325
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">强制覆盖本地REFs</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@
318318
<x:String x:Key="Text.EditRepositoryNode.Target" xml:space="preserve">目標:</x:String>
319319
<x:String x:Key="Text.EditRepositoryNode.TitleForGroup" xml:space="preserve">編輯群組</x:String>
320320
<x:String x:Key="Text.EditRepositoryNode.TitleForRepository" xml:space="preserve">編輯存放庫</x:String>
321-
<x:String x:Key="Text.ExecuteCustomAction.SimpleWait" xml:space="preserve">動作正在執行中,請稍候...</x:String>
321+
<x:String x:Key="Text.ExecuteCustomAction.Target" xml:space="preserve">目標:</x:String>
322+
<x:String x:Key="Text.ExecuteCustomAction.Repository" xml:space="preserve">本存放庫</x:String>
322323
<x:String x:Key="Text.Fetch" xml:space="preserve">提取 (fetch)</x:String>
323324
<x:String x:Key="Text.Fetch.AllRemotes" xml:space="preserve">提取所有的遠端存放庫</x:String>
324325
<x:String x:Key="Text.Fetch.Force" xml:space="preserve">強制覆寫本機 REFs</x:String>

src/ViewModels/ExecuteCustomAction.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class CustomActionControlTextBox : ICustomActionControlParameter
2121

2222
public CustomActionControlTextBox(string label, string placeholder, string defaultValue)
2323
{
24-
Label = label;
24+
Label = label + ":";
2525
Placeholder = placeholder;
2626
Text = defaultValue;
2727
}
@@ -43,7 +43,7 @@ public string Path
4343

4444
public CustomActionControlPathSelector(string label, string placeholder, bool isFolder, string defaultValue)
4545
{
46-
Label = label;
46+
Label = label + ":";
4747
Placeholder = placeholder;
4848
IsFolder = isFolder;
4949
_path = defaultValue;
@@ -79,45 +79,45 @@ public Models.CustomAction CustomAction
7979
get;
8080
}
8181

82-
public List<ICustomActionControlParameter> ControlParameters
82+
public object Target
8383
{
8484
get;
85-
} = [];
85+
}
8686

87-
public bool IsSimpleMode
87+
public List<ICustomActionControlParameter> ControlParameters
8888
{
89-
get => ControlParameters.Count == 0;
90-
}
89+
get;
90+
} = [];
9191

9292
public ExecuteCustomAction(Repository repo, Models.CustomAction action)
9393
{
9494
_repo = repo;
95-
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir());
9695
CustomAction = action;
96+
Target = new Models.Null();
9797
PrepareControlParameters();
9898
}
9999

100100
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
101101
{
102102
_repo = repo;
103-
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${BRANCH}", branch.FriendlyName);
104103
CustomAction = action;
104+
Target = branch;
105105
PrepareControlParameters();
106106
}
107107

108108
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
109109
{
110110
_repo = repo;
111-
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${SHA}", commit.SHA);
112111
CustomAction = action;
112+
Target = commit;
113113
PrepareControlParameters();
114114
}
115115

116116
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Tag tag)
117117
{
118118
_repo = repo;
119-
_commandline = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${TAG}", tag.Name);
120119
CustomAction = action;
120+
Target = tag;
121121
PrepareControlParameters();
122122
}
123123

@@ -126,7 +126,14 @@ public override Task<bool> Sure()
126126
_repo.SetWatcherEnabled(false);
127127
ProgressDescription = "Run custom action ...";
128128

129-
var cmdline = _commandline;
129+
var cmdline = CustomAction.Arguments.Replace("${REPO}", GetWorkdir());
130+
if (Target is Models.Branch b)
131+
cmdline = cmdline.Replace("${BRANCH}", b.FriendlyName);
132+
else if (Target is Models.Commit c)
133+
cmdline = cmdline.Replace("${SHA}", c.SHA);
134+
else if (Target is Models.Tag t)
135+
cmdline = cmdline.Replace("${TAG}", t.Name);
136+
130137
for (var i = ControlParameters.Count - 1; i >= 0; i--)
131138
{
132139
var param = ControlParameters[i];
@@ -249,6 +256,5 @@ private void RunAndWait(string args, Models.ICommandLog log)
249256
}
250257

251258
private readonly Repository _repo = null;
252-
private readonly string _commandline = string.Empty;
253259
}
254260
}

src/Views/ExecuteCustomAction.axaml

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:m="using:SourceGit.Models"
56
xmlns:vm="using:SourceGit.ViewModels"
7+
xmlns:c="using:SourceGit.Converters"
68
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
79
x:Class="SourceGit.Views.ExecuteCustomAction"
810
x:DataType="vm:ExecuteCustomAction">
@@ -11,13 +13,47 @@
1113
Classes="bold"
1214
Text="{Binding CustomAction.Name}"/>
1315

14-
<Grid Margin="0,16,0,0" IsVisible="{Binding IsSimpleMode}">
15-
<TextBlock Text="{DynamicResource Text.ExecuteCustomAction.SimpleWait}"
16-
HorizontalAlignment="Center"/>
16+
<Grid Margin="0,16,0,0" Height="32" ColumnDefinitions="150,*">
17+
<TextBlock Grid.Column="0"
18+
Text="{DynamicResource Text.ExecuteCustomAction.Target}"
19+
HorizontalAlignment="Right" VerticalAlignment="Center"
20+
Margin="0,0,8,0"/>
21+
22+
<ContentControl Grid.Column="1" Content="{Binding Target}">
23+
<ContentControl.DataTemplates>
24+
<DataTemplate DataType="m:Null">
25+
<StackPanel Orientation="Horizontal">
26+
<Path Width="14" Height="14" Data="{StaticResource Icons.Repositories}"/>
27+
<SelectableTextBlock VerticalAlignment="Center" Text="{DynamicResource Text.ExecuteCustomAction.Repository}" Margin="8,0,0,0"/>
28+
</StackPanel>
29+
</DataTemplate>
30+
31+
<DataTemplate DataType="m:Branch">
32+
<StackPanel Orientation="Horizontal">
33+
<Path Width="14" Height="14" Data="{StaticResource Icons.Branch}"/>
34+
<SelectableTextBlock VerticalAlignment="Center" Text="{Binding FriendlyName}" Margin="8,0,0,0"/>
35+
</StackPanel>
36+
</DataTemplate>
37+
38+
<DataTemplate DataType="m:Commit">
39+
<Grid ColumnDefinitions="Auto,Auto,*">
40+
<Path Grid.Column="0" Width="14" Height="14" Data="{StaticResource Icons.Commit}"/>
41+
<TextBlock Grid.Column="1" Classes="primary" VerticalAlignment="Center" Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" Foreground="DarkOrange" Margin="8,0,0,0"/>
42+
<TextBlock Grid.Column="2" VerticalAlignment="Center" Text="{Binding Subject}" Margin="4,0,0,0" TextTrimming="CharacterEllipsis"/>
43+
</Grid>
44+
</DataTemplate>
45+
46+
<DataTemplate DataType="m:Tag">
47+
<StackPanel Orientation="Horizontal">
48+
<Path Width="14" Height="14" Data="{StaticResource Icons.Tag}"/>
49+
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" Margin="8,0,0,0"/>
50+
</StackPanel>
51+
</DataTemplate>
52+
</ContentControl.DataTemplates>
53+
</ContentControl>
1754
</Grid>
1855

19-
<ListBox Margin="0,16,0,0"
20-
IsVisible="{Binding !IsSimpleMode}"
56+
<ListBox IsVisible="{Binding ControlParameters, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
2157
ItemsSource="{Binding ControlParameters, Mode=OneWay}">
2258
<ListBox.Styles>
2359
<Style Selector="ListBoxItem">
@@ -39,7 +75,7 @@
3975

4076
<ListBox.DataTemplates>
4177
<DataTemplate DataType="vm:CustomActionControlTextBox">
42-
<Grid ColumnDefinitions="120,*">
78+
<Grid ColumnDefinitions="150,*">
4379
<TextBlock Grid.Column="0"
4480
Text="{Binding Label}"
4581
HorizontalAlignment="Right" VerticalAlignment="Center"
@@ -55,7 +91,7 @@
5591
</DataTemplate>
5692

5793
<DataTemplate DataType="vm:CustomActionControlCheckBox">
58-
<Grid ColumnDefinitions="120,*">
94+
<Grid ColumnDefinitions="150,*">
5995
<CheckBox Grid.Column="1"
6096
Content="{Binding Label}"
6197
ToolTip.Tip="{Binding ToolTip, Mode=OneWay}"
@@ -64,7 +100,7 @@
64100
</DataTemplate>
65101

66102
<DataTemplate DataType="vm:CustomActionControlPathSelector">
67-
<Grid ColumnDefinitions="120,*">
103+
<Grid ColumnDefinitions="150,*">
68104
<TextBlock Grid.Column="0"
69105
Text="{Binding Label}"
70106
HorizontalAlignment="Right" VerticalAlignment="Center"

0 commit comments

Comments
 (0)