Skip to content

Commit 380b885

Browse files
committed
feature: supports to copy author/committer time from context menu of selected commit (#2366)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 7779b91 commit 380b885

7 files changed

Lines changed: 53 additions & 2 deletions

File tree

src/Resources/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<StreamGeometry x:Key="Icons.Copy">M896 811l-128 0c-23 0-43-19-43-43 0-23 19-43 43-43l107 0c13 0 21-9 21-21L896 107c0-13-9-21-21-21L448 85c-13 0-21 9-21 21l0 21c0 23-19 43-43 43-23 0-43-19-43-43L341 85c0-47 38-85 85-85l469 0c47 0 85 38 85 85l0 640C981 772 943 811 896 811zM683 299l0 640c0 47-38 85-85 85L128 1024c-47 0-85-38-85-85L43 299c0-47 38-85 85-85l469 0C644 213 683 252 683 299zM576 299 149 299c-13 0-21 9-21 21l0 597c0 13 9 21 21 21l427 0c13 0 21-9 21-21L597 320C597 307 589 299 576 299z</StreamGeometry>
3535
<StreamGeometry x:Key="Icons.CreatePR">M339 297c17-23 25-51 25-83 2-42-12-79-43-108S255 62 215 65c-32 0-60 8-84 25s-42 39-54 67-15 56-10 86 19 55 40 76c21 21 47 35 76 41v303c-30 6-55 20-76 41-21 21-35 47-40 76-5 30-2 58 10 86s30 50 54 67 52 25 83 25 59-8 84-25c25-17 45-39 57-67 6-19 10-39 10-61 0-30-8-57-25-83-21-34-52-55-92-64v-299l25-6c28-13 50-32 67-57zm-45 471c8 15 12 30 11 46-1 16-6 31-16 46-10 15-23 25-40 32s-34 8-51 5-32-11-46-24-22-28-24-45c-6-28-1-53 18-75s41-33 68-33c17 0 32 4 46 13 14 8 25 20 33 35zM167 288c-15-11-26-24-33-41-7-17-10-34-6-51 3-17 11-32 24-45s28-21 46-25 36-3 53 5c17 7 30 18 40 32 10 14 15 29 16 46 1 17-3 33-11 48-8 15-20 27-33 35-14 8-29 13-46 13s-33-5-48-16zm615 45c2-19-1-38-10-57-11-28-29-50-54-67s-53-25-83-25h-111l76-76-45-41-127 127v41l127 127 45-41-76-76h111c23 0 44 8 62 25 18 17 27 38 27 64v89h57V332zm0 449H960v-61H782V542h-61v178H543v61h178v178h61V781z</StreamGeometry>
3636
<StreamGeometry x:Key="Icons.Cut">M280 145l243 341 0-0 45 63-0 0 79 110a143 143 0 11-36 75l-88-123-92 126c1 4 1 9 1 13l0 5a143 143 0 11-36-95l82-113L221 188l60-43zm473 541a70 70 0 100 140 70 70 0 000-140zm-463 0a70 70 0 100 140 70 70 0 000-140zM772 145l59 43-232 319-45-63L772 145z</StreamGeometry>
37+
<StreamGeometry x:Key="Icons.DateTime">M853 137h-102V102h-68v34H341V102h-68v34h-102C133 137 102 167 102 205v68h819V205c0-38-31-68-68-68zM102 341v512C102 891 133 922 171 922h683C891 922 922 891 922 853v-512H102zM444 819h-68V512H307v-68h137V819zm273-273a102 102 0 01-30 72l-97 97 0 0a34 34 0 00-10 24v12H717V819H512v-80a102 102 0 0130-72l97-97a34 34 0 0010-24h0C649 527 633 512 614 512s-34 15-34 34H512c0-57 46-102 102-102s102 46 102 102h-0 0z</StreamGeometry>
3738
<StreamGeometry x:Key="Icons.Detached">M128 183C128 154 154 128 183 128h521c30 0 55 26 55 55v38c0 17-17 34-34 34s-34-17-34-34v-26H196v495h26c17 0 34 17 34 34s-17 34-34 34h-38c-30 0-55-26-55-55V183zM380 896h-34c-26 0-47-21-47-47v-90h68V828h64V896H380c4 0 0 0 0 0zM759 828V896h90c26 0 47-21 47-47v-90h-68V828h-68zM828 435H896V346c0-26-21-47-47-47h-90v68H828v68zM435 299v68H367V439H299V346C299 320 320 299 346 299h90zM367 649H299v-107h68v107zM546 367V299h107v68h-107zM828 546H896v107h-68v-107zM649 828V896h-107v-68h107zM730 508v188c0 17-17 34-34 34h-188c-17 0-34-17-34-34s17-34 34-34h102l-124-124c-13-13-13-34 0-47 13-13 34-13 47 0l124 124V512c0-17 17-34 34-34 21-4 38 9 38 30z</StreamGeometry>
3839
<StreamGeometry x:Key="Icons.Detail">M889 0H135c-32 0-59 26-59 59v906c0 32 26 59 59 59h753c32 0 59-26 59-59v-906c1-33-26-59-58-59zm-165 177c31 0 56 25 56 56s-25 56-56 56-56-25-56-56 25-56 56-56zm-212 0c31 0 56 25 56 56S543 288 512 288s-56-25-56-56S481 177 512 177zm-212 0c31 0 56 25 56 56s-25 56-56 56-56-25-56-56 25-56 56-56zm209 606H285c-25 0-44-20-44-44 0-25 20-44 44-44h224c25 0 44 20 44 44 0 24-20 44-44 44zm230-212H285c-25 0-44-20-44-44 0-25 20-44 44-44h453c25 0 44 20 44 44 1 24-20 44-44 44z</StreamGeometry>
3940
<StreamGeometry x:Key="Icons.Diff">M854 307 611 73c-6-6-14-9-22-9H296c-4 0-8 4-8 8v56c0 4 4 8 8 8h277l219 211V824c0 4 4 8 8 8h56c4 0 8-4 8-8V330c0-9-4-17-10-23zM553 201c-6-6-14-9-23-9H192c-18 0-32 14-32 32v704c0 18 14 32 32 32h512c18 0 32-14 32-32V397c0-9-3-17-9-23L553 201zM568 753c0 4-3 7-8 7h-225c-4 0-8-3-8-7v-42c0-4 3-7 8-7h225c4 0 8 3 8 7v42zm0-220c0 4-3 7-8 7H476v85c0 4-3 7-7 7h-42c-4 0-7-3-7-7V540h-85c-4 0-8-3-8-7v-42c0-4 3-7 8-7H420v-85c0-4 3-7 7-7h42c4 0 7 3 7 7V484h85c4 0 8 3 8 7v42z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@
151151
<x:String x:Key="Text.CommitCM.CompareWithHead" xml:space="preserve">Compare with HEAD</x:String>
152152
<x:String x:Key="Text.CommitCM.CompareWithWorktree" xml:space="preserve">Compare with Worktree</x:String>
153153
<x:String x:Key="Text.CommitCM.CopyAuthor" xml:space="preserve">Author</x:String>
154+
<x:String x:Key="Text.CommitCM.CopyAuthorTime" xml:space="preserve">Author Time</x:String>
154155
<x:String x:Key="Text.CommitCM.CopyCommitMessage" xml:space="preserve">Message</x:String>
155156
<x:String x:Key="Text.CommitCM.CopyCommitter" xml:space="preserve">Committer</x:String>
157+
<x:String x:Key="Text.CommitCM.CopyCommitterTime" xml:space="preserve">Committer Time</x:String>
156158
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">SHA</x:String>
157159
<x:String x:Key="Text.CommitCM.CopySubject" xml:space="preserve">Subject</x:String>
158160
<x:String x:Key="Text.CommitCM.CustomAction" xml:space="preserve">Custom Action</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@
155155
<x:String x:Key="Text.CommitCM.CompareWithHead" xml:space="preserve">与当前HEAD比较</x:String>
156156
<x:String x:Key="Text.CommitCM.CompareWithWorktree" xml:space="preserve">与本地工作树比较</x:String>
157157
<x:String x:Key="Text.CommitCM.CopyAuthor" xml:space="preserve">作者</x:String>
158+
<x:String x:Key="Text.CommitCM.CopyAuthorTime" xml:space="preserve">修改时间</x:String>
158159
<x:String x:Key="Text.CommitCM.CopyCommitMessage" xml:space="preserve">提交信息</x:String>
159160
<x:String x:Key="Text.CommitCM.CopyCommitter" xml:space="preserve">提交者</x:String>
161+
<x:String x:Key="Text.CommitCM.CopyCommitterTime" xml:space="preserve">提交时间</x:String>
160162
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">提交指纹</x:String>
161163
<x:String x:Key="Text.CommitCM.CopySubject" xml:space="preserve">主题</x:String>
162164
<x:String x:Key="Text.CommitCM.CustomAction" xml:space="preserve">自定义操作</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@
155155
<x:String x:Key="Text.CommitCM.CompareWithHead" xml:space="preserve">與目前 HEAD 比較</x:String>
156156
<x:String x:Key="Text.CommitCM.CompareWithWorktree" xml:space="preserve">與本機工作區比較</x:String>
157157
<x:String x:Key="Text.CommitCM.CopyAuthor" xml:space="preserve">作者</x:String>
158+
<x:String x:Key="Text.CommitCM.CopyAuthorTime" xml:space="preserve">修改時間</x:String>
158159
<x:String x:Key="Text.CommitCM.CopyCommitMessage" xml:space="preserve">提交訊息</x:String>
159160
<x:String x:Key="Text.CommitCM.CopyCommitter" xml:space="preserve">提交者</x:String>
161+
<x:String x:Key="Text.CommitCM.CopyCommitterTime" xml:space="preserve">提交時間</x:String>
160162
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">提交編號</x:String>
161163
<x:String x:Key="Text.CommitCM.CopySubject" xml:space="preserve">標題</x:String>
162164
<x:String x:Key="Text.CommitCM.CustomAction" xml:space="preserve">自訂動作</x:String>

src/Views/CommitBaseInfo.axaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
<v:DateTimePresenter Margin="2,0,0,0"
2929
Timestamp="{Binding AuthorTime}"
3030
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
31-
Foreground="{DynamicResource Brush.FG2}"/>
31+
Foreground="{DynamicResource Brush.FG2}"
32+
Background="Transparent"
33+
ContextRequested="OnDateTimeContextMenuRequested"/>
3234
</StackPanel>
3335
</Grid>
3436

@@ -46,7 +48,9 @@
4648
<v:DateTimePresenter Margin="2,0,0,0"
4749
Timestamp="{Binding CommitterTime}"
4850
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
49-
Foreground="{DynamicResource Brush.FG2}"/>
51+
Foreground="{DynamicResource Brush.FG2}"
52+
Background="Transparent"
53+
ContextRequested="OnDateTimeContextMenuRequested"/>
5054
</StackPanel>
5155
</Grid>
5256
</UniformGrid>

src/Views/CommitBaseInfo.axaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ protected override void OnUnloaded(RoutedEventArgs e)
8787
_iconResetTimer?.Dispose();
8888
}
8989

90+
private void OnDateTimeContextMenuRequested(object sender, ContextRequestedEventArgs e)
91+
{
92+
if (sender is DateTimePresenter presenter)
93+
{
94+
var copy = new MenuItem();
95+
copy.Header = App.Text("Copy");
96+
copy.Icon = this.CreateMenuIcon("Icons.Copy");
97+
copy.Click += async (_, ev) =>
98+
{
99+
await this.CopyTextAsync(presenter.Text);
100+
ev.Handled = true;
101+
};
102+
103+
var menu = new ContextMenu();
104+
menu.Items.Add(copy);
105+
menu.Open(presenter);
106+
e.Handled = true;
107+
}
108+
}
109+
90110
private async void OnCopyCommitSHA(object sender, RoutedEventArgs e)
91111
{
92112
if (sender is Button { DataContext: Models.Commit commit })

src/Views/Histories.axaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,24 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
12461246
e.Handled = true;
12471247
};
12481248

1249+
var copyAuthorTime = new MenuItem();
1250+
copyAuthorTime.Header = App.Text("CommitCM.CopyAuthorTime");
1251+
copyAuthorTime.Icon = this.CreateMenuIcon("Icons.DateTime");
1252+
copyAuthorTime.Click += async (_, e) =>
1253+
{
1254+
await this.CopyTextAsync(Models.DateTimeFormat.Format(commit.AuthorTime));
1255+
e.Handled = true;
1256+
};
1257+
1258+
var copyCommitterTime = new MenuItem();
1259+
copyCommitterTime.Header = App.Text("CommitCM.CopyCommitterTime");
1260+
copyCommitterTime.Icon = this.CreateMenuIcon("Icons.DateTime");
1261+
copyCommitterTime.Click += async (_, e) =>
1262+
{
1263+
await this.CopyTextAsync(Models.DateTimeFormat.Format(commit.CommitterTime));
1264+
e.Handled = true;
1265+
};
1266+
12491267
var copy = new MenuItem();
12501268
copy.Header = App.Text("Copy");
12511269
copy.Icon = this.CreateMenuIcon("Icons.Copy");
@@ -1256,6 +1274,8 @@ private ContextMenu CreateContextMenuForSingleCommit(ViewModels.Repository repo,
12561274
copy.Items.Add(copyMessage);
12571275
copy.Items.Add(copyAuthor);
12581276
copy.Items.Add(copyCommitter);
1277+
copy.Items.Add(copyAuthorTime);
1278+
copy.Items.Add(copyCommitterTime);
12591279
menu.Items.Add(copy);
12601280

12611281
return menu;

0 commit comments

Comments
 (0)