mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-22 05:40:43 +08:00
feature: support creating custom action for selected remote (#1726)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -9,6 +9,7 @@ namespace SourceGit.Models
|
||||
Commit,
|
||||
Branch,
|
||||
Tag,
|
||||
Remote,
|
||||
}
|
||||
|
||||
public enum CustomActionControlType
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">Template Name:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">CUSTOM ACTION</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">Arguments:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters: ${REPO} - repository's path; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">Built-in parameters: ${REPO} - repository's path; ${REMOTE} - selected remote or selected branch's remote; ${BRANCH} - selected branch; ${SHA} - selected commit's hash; ${TAG} - selected tag</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">Executable File:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">Input Controls:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">Edit</x:String>
|
||||
@@ -182,6 +182,7 @@
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">Scope:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" xml:space="preserve">Branch</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.Remote" xml:space="preserve">Remote</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Repository" xml:space="preserve">Repository</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Tag" xml:space="preserve">Tag</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">Wait for action exit</x:String>
|
||||
@@ -616,6 +617,7 @@
|
||||
<x:String x:Key="Text.Remote.URL" xml:space="preserve">Repository URL:</x:String>
|
||||
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">Remote git repository URL</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">Copy URL</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">Custom Action</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">Delete...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">Edit...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">Fetch</x:String>
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">模板名 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自定义操作</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">命令行参数 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:${REPO} 仓库路径、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">内置变量:${REPO} 仓库路径、${REMOTE} 选中的远程仓库或选中分支所属的远程仓库、${BRANCH} 选中的分支、${SHA} 选中的提交哈希,${TAG} 选中的标签</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可执行文件路径 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">输入控件 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">编辑</x:String>
|
||||
@@ -186,6 +186,7 @@
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">作用目标 :</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" 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.Remote" 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.Scope.Tag" xml:space="preserve">选中的标签</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待操作执行完成</x:String>
|
||||
@@ -620,6 +621,7 @@
|
||||
<x:String x:Key="Text.Remote.URL" xml:space="preserve">仓库地址 :</x:String>
|
||||
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">远程仓库的地址</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">复制远程地址</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">自定义操作</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">删除 ...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">编辑 ...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">拉取(fetch)更新</x:String>
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
<x:String x:Key="Text.Configure.CommitMessageTemplate.Name" xml:space="preserve">範本名稱:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction" xml:space="preserve">自訂動作</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments" xml:space="preserve">指令參數:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">內建參數: ${REPO} 存放庫路徑、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Arguments.Tip" xml:space="preserve">內建參數: ${REPO} 存放庫路徑、${REMOTE} 所選的遠端存放庫或所選分支的遠端、${BRANCH} 所選的分支、${SHA} 所選的提交編號、${TAG} 所選的標籤</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Executable" xml:space="preserve">可執行檔案路徑:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls" xml:space="preserve">輸入控制項:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.InputControls.Edit" xml:space="preserve">編輯</x:String>
|
||||
@@ -186,6 +186,7 @@
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope" xml:space="preserve">執行範圍:</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.Scope.Branch" 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.Remote" 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.Scope.Tag" xml:space="preserve">選取的標籤</x:String>
|
||||
<x:String x:Key="Text.Configure.CustomAction.WaitForExit" xml:space="preserve">等待自訂動作執行結束</x:String>
|
||||
@@ -620,6 +621,7 @@
|
||||
<x:String x:Key="Text.Remote.URL" xml:space="preserve">存放庫網址:</x:String>
|
||||
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">遠端存放庫的網址</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">複製遠端網址</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">自訂動作</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">刪除...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">編輯...</x:String>
|
||||
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">提取 (fetch) 更新</x:String>
|
||||
|
||||
@@ -119,35 +119,11 @@ namespace SourceGit.ViewModels
|
||||
get;
|
||||
} = [];
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action)
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, object scopeTarget)
|
||||
{
|
||||
_repo = repo;
|
||||
CustomAction = action;
|
||||
Target = new Models.Null();
|
||||
PrepareControlParameters();
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
|
||||
{
|
||||
_repo = repo;
|
||||
CustomAction = action;
|
||||
Target = branch;
|
||||
PrepareControlParameters();
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
|
||||
{
|
||||
_repo = repo;
|
||||
CustomAction = action;
|
||||
Target = commit;
|
||||
PrepareControlParameters();
|
||||
}
|
||||
|
||||
public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Tag tag)
|
||||
{
|
||||
_repo = repo;
|
||||
CustomAction = action;
|
||||
Target = tag;
|
||||
Target = scopeTarget ?? new Models.Null();
|
||||
PrepareControlParameters();
|
||||
}
|
||||
|
||||
@@ -206,9 +182,10 @@ namespace SourceGit.ViewModels
|
||||
|
||||
return Target switch
|
||||
{
|
||||
Models.Branch b => org.Replace("${BRANCH}", b.FriendlyName),
|
||||
Models.Branch b => org.Replace("${BRANCH}", b.FriendlyName).Replace("${REMOTE}", b.Remote),
|
||||
Models.Commit c => org.Replace("${SHA}", c.SHA),
|
||||
Models.Tag t => org.Replace("${TAG}", t.Name),
|
||||
Models.Remote r => org.Replace("${REMOTE}", r.Name),
|
||||
_ => org
|
||||
};
|
||||
}
|
||||
|
||||
@@ -876,19 +876,12 @@ namespace SourceGit.ViewModels
|
||||
ShowPopup(new Apply(this));
|
||||
}
|
||||
|
||||
public async Task ExecCustomActionAsync(Models.CustomAction action, object scope)
|
||||
public async Task ExecCustomActionAsync(Models.CustomAction action, object scopeTarget)
|
||||
{
|
||||
if (!CanCreatePopup())
|
||||
return;
|
||||
|
||||
var popup = scope switch
|
||||
{
|
||||
Models.Branch b => new ExecuteCustomAction(this, action, b),
|
||||
Models.Commit c => new ExecuteCustomAction(this, action, c),
|
||||
Models.Tag t => new ExecuteCustomAction(this, action, t),
|
||||
_ => new ExecuteCustomAction(this, action)
|
||||
};
|
||||
|
||||
var popup = new ExecuteCustomAction(this, action, scopeTarget);
|
||||
if (action.Controls.Count == 0)
|
||||
await ShowAndStartPopupAsync(popup);
|
||||
else
|
||||
|
||||
@@ -940,6 +940,7 @@ namespace SourceGit.Views
|
||||
menu.Items.Add(edit);
|
||||
menu.Items.Add(delete);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
TryToAddCustomActionsToRemoteContextMenu(repo, menu, remote);
|
||||
menu.Items.Add(copy);
|
||||
return menu;
|
||||
}
|
||||
@@ -1112,6 +1113,35 @@ namespace SourceGit.Views
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
private void TryToAddCustomActionsToRemoteContextMenu(ViewModels.Repository repo, ContextMenu menu, Models.Remote remote)
|
||||
{
|
||||
var actions = repo.GetCustomActions(Models.CustomActionScope.Remote);
|
||||
if (actions.Count == 0)
|
||||
return;
|
||||
|
||||
var custom = new MenuItem();
|
||||
custom.Header = App.Text("RemoteCM.CustomAction");
|
||||
custom.Icon = App.CreateMenuIcon("Icons.Action");
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
var (dup, label) = action;
|
||||
var item = new MenuItem();
|
||||
item.Icon = App.CreateMenuIcon("Icons.Action");
|
||||
item.Header = label;
|
||||
item.Click += async (_, e) =>
|
||||
{
|
||||
await repo.ExecCustomActionAsync(dup, remote);
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
custom.Items.Add(item);
|
||||
}
|
||||
|
||||
menu.Items.Add(custom);
|
||||
menu.Items.Add(new MenuItem() { Header = "-" });
|
||||
}
|
||||
|
||||
private bool _disableSelectionChangingEvent = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,13 @@
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:DataType="m:Remote">
|
||||
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||
<Path Width="14" Height="14" Data="{StaticResource Icons.Remote}"/>
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding Name}" Margin="8,0,0,0"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
|
||||
@@ -656,6 +656,7 @@
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Commit}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Branch}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Tag}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Remote}"/>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Executable}"/>
|
||||
|
||||
@@ -480,6 +480,7 @@
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Commit}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Branch}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Tag}"/>
|
||||
<ComboBoxItem Content="{DynamicResource Text.Configure.CustomAction.Scope.Remote}"/>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CustomAction.Executable}"/>
|
||||
|
||||
Reference in New Issue
Block a user