From baaa40257943c6a13667231c7a5f41bd80b0e57f Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 27 Aug 2025 12:05:41 +0800 Subject: [PATCH] ux: show tab status icon description in tooltip (#1767) Signed-off-by: leo --- src/Converters/DirtyStateConverters.cs | 28 ++++++++++++++++++++++++++ src/Resources/Locales/en_US.axaml | 3 +++ src/Resources/Locales/zh_CN.axaml | 3 +++ src/Resources/Locales/zh_TW.axaml | 3 +++ src/ViewModels/LauncherPage.cs | 23 +++++++++------------ src/Views/LauncherTabBar.axaml | 11 +++++++--- 6 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 src/Converters/DirtyStateConverters.cs diff --git a/src/Converters/DirtyStateConverters.cs b/src/Converters/DirtyStateConverters.cs new file mode 100644 index 00000000..f140f7d3 --- /dev/null +++ b/src/Converters/DirtyStateConverters.cs @@ -0,0 +1,28 @@ +using Avalonia.Data.Converters; +using Avalonia.Media; + +namespace SourceGit.Converters +{ + public static class DirtyStateConverters + { + public static readonly FuncValueConverter ToBrush = + new FuncValueConverter(v => + { + if (v.HasFlag(Models.DirtyState.HasLocalChanges)) + return Brushes.Gray; + if (v.HasFlag(Models.DirtyState.HasPendingPullOrPush)) + return Brushes.RoyalBlue; + return Brushes.Transparent; + }); + + public static readonly FuncValueConverter ToDesc = + new FuncValueConverter(v => + { + if (v.HasFlag(Models.DirtyState.HasLocalChanges)) + return " • " + App.Text("DirtyState.HasLocalChanges"); + if (v.HasFlag(Models.DirtyState.HasPendingPullOrPush)) + return " • " + App.Text("DirtyState.HasPendingPullOrPush"); + return " • " + App.Text("DirtyState.UpToDate"); + }); + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 97dca077..f12fb542 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -335,6 +335,9 @@ Increase Number of Visible Lines SELECT FILE TO VIEW CHANGES Dir History + Has Local Changes + Mismatched with Upstream + Already Up-To-Date Discard Changes All local changes in working copy. Changes: diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 2866a8d4..f8d7a42d 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -339,6 +339,9 @@ 增加可见的行数 请选择需要对比的文件 目录内容变更历史 + 未提交的本地变更 + 当前分支HEAD与远端不一致 + 已是最新 放弃更改确认 所有本仓库未提交的修改。 变更 : diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 7edb94a4..b42301b5 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -339,6 +339,9 @@ 增加可見的行數 請選擇需要對比的檔案 目錄内容變更歷史 + 未提交的本地變更 + 當前分支的 HEAD 與上游不匹配 + 已更新至最新 捨棄變更 所有本機未提交的變更。 變更: diff --git a/src/ViewModels/LauncherPage.cs b/src/ViewModels/LauncherPage.cs index 906f9e8a..88d6ee99 100644 --- a/src/ViewModels/LauncherPage.cs +++ b/src/ViewModels/LauncherPage.cs @@ -1,7 +1,9 @@ using System; using System.Threading.Tasks; + using Avalonia.Collections; using Avalonia.Media; + using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.ViewModels @@ -20,10 +22,10 @@ namespace SourceGit.ViewModels set => SetProperty(ref _data, value); } - public IBrush DirtyBrush + public Models.DirtyState DirtyState { - get => _dirtyBrush; - private set => SetProperty(ref _dirtyBrush, value); + get => _dirtyState; + private set => SetProperty(ref _dirtyState, value); } public Popup Popup @@ -66,22 +68,18 @@ namespace SourceGit.ViewModels public void ChangeDirtyState(Models.DirtyState flag, bool remove) { + var state = _dirtyState; if (remove) { - if (_dirtyState.HasFlag(flag)) - _dirtyState -= flag; + if (state.HasFlag(flag)) + state -= flag; } else { - _dirtyState |= flag; + state |= flag; } - if (_dirtyState.HasFlag(Models.DirtyState.HasLocalChanges)) - DirtyBrush = Brushes.Gray; - else if (_dirtyState.HasFlag(Models.DirtyState.HasPendingPullOrPush)) - DirtyBrush = Brushes.RoyalBlue; - else - DirtyBrush = null; + DirtyState = state; } public bool CanCreatePopup() @@ -127,7 +125,6 @@ namespace SourceGit.ViewModels private RepositoryNode _node = null; private object _data = null; - private IBrush _dirtyBrush = null; private Models.DirtyState _dirtyState = Models.DirtyState.None; private Popup _popup = null; } diff --git a/src/Views/LauncherTabBar.axaml b/src/Views/LauncherTabBar.axaml index ce35697f..a2273428 100644 --- a/src/Views/LauncherTabBar.axaml +++ b/src/Views/LauncherTabBar.axaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:m="using:SourceGit.Models" xmlns:vm="using:SourceGit.ViewModels" xmlns:c="using:SourceGit.Converters" xmlns:v="using:SourceGit.Views" @@ -51,7 +52,11 @@ - + + + + @@ -78,8 +83,8 @@ Width="8" Height="8" Margin="0,0,6,0" VerticalAlignment="Center" - IsVisible="{Binding DirtyBrush, Converter={x:Static ObjectConverters.IsNotNull}}" - Fill="{Binding DirtyBrush}"/> + IsVisible="{Binding DirtyState, Converter={x:Static ObjectConverters.IsNotNull}, ConverterParameter={x:Static m:DirtyState.None}}" + Fill="{Binding DirtyState, Converter={x:Static c:DirtyStateConverters.ToBrush}}"/>