Skip to content

Commit baaa402

Browse files
committed
ux: show tab status icon description in tooltip (#1767)
Signed-off-by: leo <[email protected]>
1 parent 2df1830 commit baaa402

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Avalonia.Data.Converters;
2+
using Avalonia.Media;
3+
4+
namespace SourceGit.Converters
5+
{
6+
public static class DirtyStateConverters
7+
{
8+
public static readonly FuncValueConverter<Models.DirtyState, IBrush> ToBrush =
9+
new FuncValueConverter<Models.DirtyState, IBrush>(v =>
10+
{
11+
if (v.HasFlag(Models.DirtyState.HasLocalChanges))
12+
return Brushes.Gray;
13+
if (v.HasFlag(Models.DirtyState.HasPendingPullOrPush))
14+
return Brushes.RoyalBlue;
15+
return Brushes.Transparent;
16+
});
17+
18+
public static readonly FuncValueConverter<Models.DirtyState, string> ToDesc =
19+
new FuncValueConverter<Models.DirtyState, string>(v =>
20+
{
21+
if (v.HasFlag(Models.DirtyState.HasLocalChanges))
22+
return " • " + App.Text("DirtyState.HasLocalChanges");
23+
if (v.HasFlag(Models.DirtyState.HasPendingPullOrPush))
24+
return " • " + App.Text("DirtyState.HasPendingPullOrPush");
25+
return " • " + App.Text("DirtyState.UpToDate");
26+
});
27+
}
28+
}

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@
335335
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">Increase Number of Visible Lines</x:String>
336336
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">SELECT FILE TO VIEW CHANGES</x:String>
337337
<x:String x:Key="Text.DirHistories" xml:space="preserve">Dir History</x:String>
338+
<x:String x:Key="Text.DirtyState.HasLocalChanges" xml:space="preserve">Has Local Changes</x:String>
339+
<x:String x:Key="Text.DirtyState.HasPendingPullOrPush" xml:space="preserve">Mismatched with Upstream</x:String>
340+
<x:String x:Key="Text.DirtyState.UpToDate" xml:space="preserve">Already Up-To-Date</x:String>
338341
<x:String x:Key="Text.Discard" xml:space="preserve">Discard Changes</x:String>
339342
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
340343
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@
339339
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">增加可见的行数</x:String>
340340
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">请选择需要对比的文件</x:String>
341341
<x:String x:Key="Text.DirHistories" xml:space="preserve">目录内容变更历史</x:String>
342+
<x:String x:Key="Text.DirtyState.HasLocalChanges" xml:space="preserve">未提交的本地变更</x:String>
343+
<x:String x:Key="Text.DirtyState.HasPendingPullOrPush" xml:space="preserve">当前分支HEAD与远端不一致</x:String>
344+
<x:String x:Key="Text.DirtyState.UpToDate" xml:space="preserve">已是最新</x:String>
342345
<x:String x:Key="Text.Discard" xml:space="preserve">放弃更改确认</x:String>
343346
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本仓库未提交的修改。</x:String>
344347
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">变更 :</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@
339339
<x:String x:Key="Text.Diff.VisualLines.Incr" xml:space="preserve">增加可見的行數</x:String>
340340
<x:String x:Key="Text.Diff.Welcome" xml:space="preserve">請選擇需要對比的檔案</x:String>
341341
<x:String x:Key="Text.DirHistories" xml:space="preserve">目錄内容變更歷史</x:String>
342+
<x:String x:Key="Text.DirtyState.HasLocalChanges" xml:space="preserve">未提交的本地變更</x:String>
343+
<x:String x:Key="Text.DirtyState.HasPendingPullOrPush" xml:space="preserve">當前分支的 HEAD 與上游不匹配</x:String>
344+
<x:String x:Key="Text.DirtyState.UpToDate" xml:space="preserve">已更新至最新</x:String>
342345
<x:String x:Key="Text.Discard" xml:space="preserve">捨棄變更</x:String>
343346
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本機未提交的變更。</x:String>
344347
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">變更:</x:String>

src/ViewModels/LauncherPage.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Threading.Tasks;
3+
34
using Avalonia.Collections;
45
using Avalonia.Media;
6+
57
using CommunityToolkit.Mvvm.ComponentModel;
68

79
namespace SourceGit.ViewModels
@@ -20,10 +22,10 @@ public object Data
2022
set => SetProperty(ref _data, value);
2123
}
2224

23-
public IBrush DirtyBrush
25+
public Models.DirtyState DirtyState
2426
{
25-
get => _dirtyBrush;
26-
private set => SetProperty(ref _dirtyBrush, value);
27+
get => _dirtyState;
28+
private set => SetProperty(ref _dirtyState, value);
2729
}
2830

2931
public Popup Popup
@@ -66,22 +68,18 @@ public async Task CopyPathAsync()
6668

6769
public void ChangeDirtyState(Models.DirtyState flag, bool remove)
6870
{
71+
var state = _dirtyState;
6972
if (remove)
7073
{
71-
if (_dirtyState.HasFlag(flag))
72-
_dirtyState -= flag;
74+
if (state.HasFlag(flag))
75+
state -= flag;
7376
}
7477
else
7578
{
76-
_dirtyState |= flag;
79+
state |= flag;
7780
}
7881

79-
if (_dirtyState.HasFlag(Models.DirtyState.HasLocalChanges))
80-
DirtyBrush = Brushes.Gray;
81-
else if (_dirtyState.HasFlag(Models.DirtyState.HasPendingPullOrPush))
82-
DirtyBrush = Brushes.RoyalBlue;
83-
else
84-
DirtyBrush = null;
82+
DirtyState = state;
8583
}
8684

8785
public bool CanCreatePopup()
@@ -127,7 +125,6 @@ public void CancelPopup()
127125

128126
private RepositoryNode _node = null;
129127
private object _data = null;
130-
private IBrush _dirtyBrush = null;
131128
private Models.DirtyState _dirtyState = Models.DirtyState.None;
132129
private Popup _popup = null;
133130
}

src/Views/LauncherTabBar.axaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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"
67
xmlns:c="using:SourceGit.Converters"
78
xmlns:v="using:SourceGit.Views"
@@ -51,7 +52,11 @@
5152
<ToolTip.Tip>
5253
<Grid>
5354
<TextBlock Text="{DynamicResource Text.Welcome}" IsVisible="{Binding !Node.IsRepository}"/>
54-
<TextBlock Text="{Binding Node.Id}" IsVisible="{Binding Node.IsRepository}"/>
55+
<StackPanel Orientation="Horizontal" IsVisible="{Binding Node.IsRepository}">
56+
<TextBlock Text="{Binding Node.Id}"/>
57+
<TextBlock Text="{Binding DirtyState, Converter={x:Static c:DirtyStateConverters.ToDesc}}"
58+
Foreground="{DynamicResource Brush.FG2}"/>
59+
</StackPanel>
5560
</Grid>
5661
</ToolTip.Tip>
5762

@@ -78,8 +83,8 @@
7883
Width="8" Height="8"
7984
Margin="0,0,6,0"
8085
VerticalAlignment="Center"
81-
IsVisible="{Binding DirtyBrush, Converter={x:Static ObjectConverters.IsNotNull}}"
82-
Fill="{Binding DirtyBrush}"/>
86+
IsVisible="{Binding DirtyState, Converter={x:Static ObjectConverters.IsNotNull}, ConverterParameter={x:Static m:DirtyState.None}}"
87+
Fill="{Binding DirtyState, Converter={x:Static c:DirtyStateConverters.ToBrush}}"/>
8388

8489
<TextBlock Grid.Column="1"
8590
Classes="primary"

0 commit comments

Comments
 (0)