From ad1263b0a8eb54d61277270034e4fb3b6a0c6dea Mon Sep 17 00:00:00 2001 From: goran-w Date: Sat, 16 Nov 2024 13:33:10 +0100 Subject: [PATCH] Added indicator of current/total change-blocks in DiffView toolbar --- src/ViewModels/DiffContext.cs | 25 ++++++++++++++++++++++++- src/Views/DiffView.axaml | 7 +++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 51418baf..9d3486a1 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -51,6 +51,12 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _unifiedLines, value); } + public string ChangeBlockIndicator + { + get => _changeBlockIndicator; + private set => SetProperty(ref _changeBlockIndicator, value); + } + public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { _repo = repo; @@ -88,6 +94,7 @@ namespace SourceGit.ViewModels textDiff.CurrentChangeBlockIdx = 0; } } + RefreshChangeBlockIndicator(); } public void NextChange() @@ -104,9 +111,22 @@ namespace SourceGit.ViewModels textDiff.CurrentChangeBlockIdx = -1; textDiff.CurrentChangeBlockIdx = textDiff.ChangeBlocks.Count - 1; } + RefreshChangeBlockIndicator(); } } + public void RefreshChangeBlockIndicator() + { + string curr = "-", tot = "-"; + if (_content is Models.TextDiff textDiff) + { + if (textDiff.CurrentChangeBlockIdx >= 0) + curr = (textDiff.CurrentChangeBlockIdx + 1).ToString(); + tot = (textDiff.ChangeBlocks.Count).ToString(); + } + ChangeBlockIndicator = curr + "/" + tot; + } + public void ToggleFullTextDiff() { Preference.Instance.UseFullTextDiff = !Preference.Instance.UseFullTextDiff; @@ -251,7 +271,9 @@ namespace SourceGit.ViewModels FileModeChange = latest.FileModeChange; Content = rs; IsTextDiff = rs is Models.TextDiff; - }); + + RefreshChangeBlockIndicator(); + }); }); } @@ -315,6 +337,7 @@ namespace SourceGit.ViewModels private string _title; private string _fileModeChange = string.Empty; private int _unifiedLines = 4; + private string _changeBlockIndicator = "-/-"; private bool _isTextDiff = false; private bool _ignoreWhitespace = false; private object _content = null; diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 360ac8fc..e904f4a4 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -42,6 +42,13 @@ + +