From 9e86a3626d792463dafdd142454c1295affffaae Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Mon, 7 Jul 2025 14:56:34 +1000 Subject: [PATCH] ux: format file sizes --- src/Converters/LongConverters.cs | 22 ++++++++++++++++++ src/Resources/Locales/de_DE.axaml | 1 - src/Resources/Locales/en_US.axaml | 1 - src/Resources/Locales/es_ES.axaml | 1 - src/Resources/Locales/fr_FR.axaml | 1 - src/Resources/Locales/it_IT.axaml | 1 - src/Resources/Locales/ja_JP.axaml | 1 - src/Resources/Locales/pt_BR.axaml | 1 - src/Resources/Locales/ru_RU.axaml | 1 - src/Resources/Locales/ta_IN.axaml | 1 - src/Resources/Locales/uk_UA.axaml | 1 - src/Resources/Locales/zh_CN.axaml | 1 - src/Resources/Locales/zh_TW.axaml | 1 - src/Views/DiffView.axaml | 16 +++++-------- src/Views/ImageDiffView.axaml | 28 +++++++++-------------- src/Views/RevisionFileContentViewer.axaml | 8 +++---- 16 files changed, 42 insertions(+), 44 deletions(-) create mode 100644 src/Converters/LongConverters.cs diff --git a/src/Converters/LongConverters.cs b/src/Converters/LongConverters.cs new file mode 100644 index 000000000..d7309363e --- /dev/null +++ b/src/Converters/LongConverters.cs @@ -0,0 +1,22 @@ +using Avalonia.Data.Converters; + +namespace SourceGit.Converters +{ + public static class LongConverters + { + public static readonly FuncValueConverter ToFileSize = new(bytes => + { + var suffixes = new[] { "", "ki", "Mi", "Gi", "Ti", "Pi", "Ei" }; + double dbl = bytes; + var i = 0; + + while (dbl > 1024 && i < suffixes.Length - 1) + { + dbl /= 1024; + i++; + } + + return $"{dbl:0.#} {suffixes[i]}B"; + }); + } +} diff --git a/src/Resources/Locales/de_DE.axaml b/src/Resources/Locales/de_DE.axaml index 99e5f12d0..a9ca4e421 100644 --- a/src/Resources/Locales/de_DE.axaml +++ b/src/Resources/Locales/de_DE.axaml @@ -75,7 +75,6 @@ Setze verfolgten Branch... Branch Vergleich Ungültiger Upstream! - Bytes ABBRECHEN Auf Vorgänger-Revision zurücksetzen Auf diese Revision zurücksetzen diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 65b02cb5e..452528488 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -71,7 +71,6 @@ Set Tracking Branch... Branch Compare Invalid upstream! - Bytes CANCEL Reset to Parent Revision Reset to This Revision diff --git a/src/Resources/Locales/es_ES.axaml b/src/Resources/Locales/es_ES.axaml index 8654e5ed4..bee433137 100644 --- a/src/Resources/Locales/es_ES.axaml +++ b/src/Resources/Locales/es_ES.axaml @@ -75,7 +75,6 @@ Establecer Rama de Seguimiento... Comparar Ramas ¡Upstream inválido! - Bytes CANCELAR Resetear a Revisión Padre Resetear a Esta Revisión diff --git a/src/Resources/Locales/fr_FR.axaml b/src/Resources/Locales/fr_FR.axaml index 55de07a27..131da866c 100644 --- a/src/Resources/Locales/fr_FR.axaml +++ b/src/Resources/Locales/fr_FR.axaml @@ -63,7 +63,6 @@ Définir la branche de suivi... Comparer les branches Branche en amont invalide! - Octets ANNULER Réinitialiser à la révision parente Réinitialiser à cette révision diff --git a/src/Resources/Locales/it_IT.axaml b/src/Resources/Locales/it_IT.axaml index 9b2102b6d..01983a425 100644 --- a/src/Resources/Locales/it_IT.axaml +++ b/src/Resources/Locales/it_IT.axaml @@ -70,7 +70,6 @@ Imposta Branch di Tracciamento... Confronto Branch Upstream non valido - Byte ANNULLA Ripristina la Revisione Padre Ripristina Questa Revisione diff --git a/src/Resources/Locales/ja_JP.axaml b/src/Resources/Locales/ja_JP.axaml index 3780ffdcd..bda1389da 100644 --- a/src/Resources/Locales/ja_JP.axaml +++ b/src/Resources/Locales/ja_JP.axaml @@ -62,7 +62,6 @@ トラッキングブランチを設定... ブランチの比較 無効な上流ブランチ! - バイト キャンセル 親リビジョンにリセット このリビジョンにリセット diff --git a/src/Resources/Locales/pt_BR.axaml b/src/Resources/Locales/pt_BR.axaml index 75da35522..a88124dac 100644 --- a/src/Resources/Locales/pt_BR.axaml +++ b/src/Resources/Locales/pt_BR.axaml @@ -54,7 +54,6 @@ Renomear ${0}$... Definir Branch de Rastreamento... Comparação de Branches - Bytes CANCELAR Resetar para Revisão Pai Resetar para Esta Revisão diff --git a/src/Resources/Locales/ru_RU.axaml b/src/Resources/Locales/ru_RU.axaml index 7d5b932b6..55b9f1457 100644 --- a/src/Resources/Locales/ru_RU.axaml +++ b/src/Resources/Locales/ru_RU.axaml @@ -75,7 +75,6 @@ Отслеживать ветку... Сравнение веток Недопустимая основная ветка! - Байты ОТМЕНА Сбросить родительскую ревизию Сбросить эту ревизию diff --git a/src/Resources/Locales/ta_IN.axaml b/src/Resources/Locales/ta_IN.axaml index d6f2ff444..2bf961b98 100644 --- a/src/Resources/Locales/ta_IN.axaml +++ b/src/Resources/Locales/ta_IN.axaml @@ -62,7 +62,6 @@ கண்காணிப்பு கிளையை அமை... கிளை ஒப்பிடு தவறான மேல்ஓடை! - எண்மங்கள் விடு பெற்றோர் திருத்தத்திற்கு மீட்டமை இந்த திருத்தத்திற்கு மீட்டமை diff --git a/src/Resources/Locales/uk_UA.axaml b/src/Resources/Locales/uk_UA.axaml index 393eea745..9ebd8d60d 100644 --- a/src/Resources/Locales/uk_UA.axaml +++ b/src/Resources/Locales/uk_UA.axaml @@ -63,7 +63,6 @@ Встановити відстежувану гілку... Порівняти гілки Недійсний upstream! - Байтів СКАСУВАТИ Скинути до батьківської ревізії Скинути до цієї ревізії diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 7fc028338..6c07bd7f2 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -75,7 +75,6 @@ 切换上游分支 ... 分支比较 跟踪的上游分支不存在或已删除! - 字节 取 消 重置文件到上一版本 重置文件到该版本 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 63273cb0e..957806674 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -75,7 +75,6 @@ 切換上游分支... 分支比較 追蹤上游分支不存在或已刪除! - 位元組 取 消 重設檔案到上一版本 重設檔案為此版本 diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index ad29b1a4c..6a2949149 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -232,20 +232,18 @@ Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/> - + - - + - - + @@ -259,20 +257,18 @@ Foreground="{DynamicResource Brush.FG2}" HorizontalAlignment="Center"/> - + - - + - - + diff --git a/src/Views/ImageDiffView.axaml b/src/Views/ImageDiffView.axaml index 54a20628d..59cd3e9a1 100644 --- a/src/Views/ImageDiffView.axaml +++ b/src/Views/ImageDiffView.axaml @@ -28,8 +28,7 @@ - - + @@ -48,8 +47,7 @@ - - + @@ -69,22 +67,20 @@ - + - - + - + - - - + + @@ -111,16 +107,14 @@ - - + - + - - - + + diff --git a/src/Views/RevisionFileContentViewer.axaml b/src/Views/RevisionFileContentViewer.axaml index 3e8362c9c..55bfb1cd8 100644 --- a/src/Views/RevisionFileContentViewer.axaml +++ b/src/Views/RevisionFileContentViewer.axaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="using:SourceGit.Models" xmlns:v="using:SourceGit.Views" + xmlns:c="using:SourceGit.Converters" xmlns:vm="using:SourceGit.ViewModels" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="SourceGit.Views.RevisionFileContentViewer"> @@ -14,7 +15,6 @@ - @@ -43,8 +43,7 @@ - - + @@ -55,8 +54,7 @@ - - +