diff --git a/src/Models/CustomAction.cs b/src/Models/CustomAction.cs
index bd56d6ae..a614961a 100644
--- a/src/Models/CustomAction.cs
+++ b/src/Models/CustomAction.cs
@@ -6,6 +6,7 @@ namespace SourceGit.Models
{
Repository,
Commit,
+ Branch,
}
public class CustomAction : ObservableObject
diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml
index 70da2973..f8a06f08 100644
--- a/src/Resources/Locales/en_US.axaml
+++ b/src/Resources/Locales/en_US.axaml
@@ -56,6 +56,7 @@
Compare with HEAD
Compare with Worktree
Copy Branch Name
+ Custom Action
Delete ${0}$...
Delete selected {0} branches
Discard all changes
@@ -152,10 +153,11 @@
Template Content:
CUSTOM ACTION
Arguments:
- ${REPO} - Repository's path; ${SHA} - Selected commit's SHA
+ ${REPO} - Repository's path; ${BRANCH} - Selected branch; ${SHA} - Selected commit's SHA
Executable File:
Name:
Scope:
+ Branch
Commit
Repository
Wait for action exit
diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml
index 005ef3a2..4db909c9 100644
--- a/src/Resources/Locales/zh_CN.axaml
+++ b/src/Resources/Locales/zh_CN.axaml
@@ -59,6 +59,7 @@
与当前HEAD比较
与本地工作树比较
复制分支名
+ 自定义操作
删除 ${0}$...
删除选中的 {0} 个分支
放弃所有更改
@@ -155,10 +156,11 @@
模板内容 :
自定义操作
命令行参数 :
- 请使用${REPO}代替仓库路径,${SHA}代替提交哈希
+ 请使用${REPO}代替仓库路径,${BRANCH}代替选中的分支,${SHA}代替提交哈希
可执行文件路径 :
名称 :
作用目标 :
+ 选中的分支
选中的提交
仓库
等待操作执行完成
diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml
index fe0e4bac..167565cf 100644
--- a/src/Resources/Locales/zh_TW.axaml
+++ b/src/Resources/Locales/zh_TW.axaml
@@ -59,6 +59,7 @@
與目前 HEAD 比較
與本機工作區比較
複製分支名稱
+ 自訂動作
刪除 ${0}$...
刪除所選的 {0} 個分支
捨棄所有變更
@@ -155,10 +156,11 @@
範本內容:
自訂動作
指令參數:
- 使用 ${REPO} 表示存放庫路徑、${SHA} 表示所選的提交編號
+ 使用 ${REPO} 表示存放庫路徑、${BRANCH} 表示所選的分支、${SHA} 表示所選的提交編號
可執行檔案路徑:
名稱:
執行範圍:
+ 選取的分支
選取的提交
存放庫
等待自訂操作退出
diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs
index 848faaaf..8e34379f 100644
--- a/src/ViewModels/ExecuteCustomAction.cs
+++ b/src/ViewModels/ExecuteCustomAction.cs
@@ -10,13 +10,26 @@ namespace SourceGit.ViewModels
private set;
}
- public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
+ public ExecuteCustomAction(Repository repo, Models.CustomAction action)
{
_repo = repo;
_args = action.Arguments.Replace("${REPO}", _repo.FullPath);
- if (commit != null)
- _args = _args.Replace("${SHA}", commit.SHA);
+ CustomAction = action;
+ View = new Views.ExecuteCustomAction() { DataContext = this };
+ }
+ public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch)
+ {
+ _repo = repo;
+ _args = action.Arguments.Replace("${REPO}", _repo.FullPath).Replace("${BRANCH}", branch.FriendlyName);
+ CustomAction = action;
+ View = new Views.ExecuteCustomAction() { DataContext = this };
+ }
+
+ public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit)
+ {
+ _repo = repo;
+ _args = action.Arguments.Replace("${REPO}", _repo.FullPath).Replace("${SHA}", commit.SHA);
CustomAction = action;
View = new Views.ExecuteCustomAction() { DataContext = this };
}
diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs
index 44de8c35..6b96255f 100644
--- a/src/ViewModels/Repository.cs
+++ b/src/ViewModels/Repository.cs
@@ -1439,7 +1439,7 @@ namespace SourceGit.ViewModels
item.Click += (_, e) =>
{
if (CanCreatePopup())
- ShowAndStartPopup(new ExecuteCustomAction(this, dup, null));
+ ShowAndStartPopup(new ExecuteCustomAction(this, dup));
e.Handled = true;
};
@@ -1698,6 +1698,7 @@ namespace SourceGit.ViewModels
menu.Items.Add(createBranch);
menu.Items.Add(createTag);
menu.Items.Add(new MenuItem() { Header = "-" });
+ TryToAddCustomActionsToBranchContextMenu(menu, branch);
if (!IsBare)
{
@@ -1968,7 +1969,9 @@ namespace SourceGit.ViewModels
menu.Items.Add(new MenuItem() { Header = "-" });
menu.Items.Add(archive);
menu.Items.Add(new MenuItem() { Header = "-" });
+ TryToAddCustomActionsToBranchContextMenu(menu, branch);
menu.Items.Add(copy);
+
return menu;
}
@@ -2319,6 +2322,43 @@ namespace SourceGit.ViewModels
return null;
}
+ private void TryToAddCustomActionsToBranchContextMenu(ContextMenu menu, Models.Branch branch)
+ {
+ var actions = new List();
+ foreach (var action in Settings.CustomActions)
+ {
+ if (action.Scope == Models.CustomActionScope.Branch)
+ actions.Add(action);
+ }
+
+ if (actions.Count == 0)
+ return;
+
+ var custom = new MenuItem();
+ custom.Header = App.Text("BranchCM.CustomAction");
+ custom.Icon = App.CreateMenuIcon("Icons.Action");
+
+ foreach (var action in actions)
+ {
+ var dup = action;
+ var item = new MenuItem();
+ item.Icon = App.CreateMenuIcon("Icons.Action");
+ item.Header = dup.Name;
+ item.Click += (_, e) =>
+ {
+ if (CanCreatePopup())
+ ShowAndStartPopup(new ExecuteCustomAction(this, dup, branch));
+
+ e.Handled = true;
+ };
+
+ custom.Items.Add(item);
+ }
+
+ menu.Items.Add(custom);
+ menu.Items.Add(new MenuItem() { Header = "-" });
+ }
+
private void UpdateCurrentRevisionFilesForSearchSuggestion()
{
_revisionFiles.Clear();
diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml
index d9383743..6b7cdc12 100644
--- a/src/Views/RepositoryConfigure.axaml
+++ b/src/Views/RepositoryConfigure.axaml
@@ -5,7 +5,6 @@
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
- xmlns:ac="using:Avalonia.Controls.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.RepositoryConfigure"
x:DataType="vm:RepositoryConfigure"
@@ -412,20 +411,12 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+