From 75006db94f002f6e01a9f45a21ba6f82eb984933 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 30 Apr 2021 10:19:37 +0800 Subject: [PATCH] fix: fix row selection in Grid/List view mode --- src/Views/Widgets/CommitChanges.xaml | 4 +++- src/Views/Widgets/CommitChanges.xaml.cs | 27 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Views/Widgets/CommitChanges.xaml b/src/Views/Widgets/CommitChanges.xaml index 8ad89663..1b1043cb 100644 --- a/src/Views/Widgets/CommitChanges.xaml +++ b/src/Views/Widgets/CommitChanges.xaml @@ -70,7 +70,7 @@ BorderBrush="{StaticResource Brush.Border2}" BorderThickness="1" Background="{StaticResource Brush.Contents}"> - + @@ -153,6 +154,7 @@ SelectionMode="Single" SelectionUnit="FullRow" SelectionChanged="OnGridSelectionChanged" + SizeChanged="OnGridSizeChanged" RowStyle="{StaticResource Style.DataGridRow.Changes}"> diff --git a/src/Views/Widgets/CommitChanges.xaml.cs b/src/Views/Widgets/CommitChanges.xaml.cs index de340646..1fb82de1 100644 --- a/src/Views/Widgets/CommitChanges.xaml.cs +++ b/src/Views/Widgets/CommitChanges.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -252,7 +253,7 @@ namespace SourceGit.Views.Widgets { } private void OnTreeSelectionChanged(object sender, RoutedEventArgs e) { - if (Models.Preference.Instance.Window.ChangeInCommitInfo != Models.Change.DisplayMode.Tree) return; + if (modeSwitcher.Mode != Models.Change.DisplayMode.Tree) return; diffViewer.Reset(); if (modeTree.Selected.Count == 0) return; @@ -264,7 +265,7 @@ namespace SourceGit.Views.Widgets { } private void OnListSelectionChanged(object sender, SelectionChangedEventArgs e) { - if (Models.Preference.Instance.Window.ChangeInCommitInfo != Models.Change.DisplayMode.List) return; + if (modeSwitcher.Mode != Models.Change.DisplayMode.List) return; diffViewer.Reset(); @@ -275,7 +276,7 @@ namespace SourceGit.Views.Widgets { } private void OnGridSelectionChanged(object sender, SelectionChangedEventArgs e) { - if (Models.Preference.Instance.Window.ChangeInCommitInfo != Models.Change.DisplayMode.Grid) return; + if (modeSwitcher.Mode != Models.Change.DisplayMode.Grid) return; diffViewer.Reset(); @@ -306,5 +307,25 @@ namespace SourceGit.Views.Widgets { OpenChangeContextMenu(change); e.Handled = true; } + + private void OnListSizeChanged(object sender, SizeChangedEventArgs e) { + if (modeSwitcher.Mode != Models.Change.DisplayMode.List) return; + + int last = modeList.Columns.Count - 1; + double offset = 0; + for (int i = 0; i < last; i++) offset += modeList.Columns[i].ActualWidth; + modeList.Columns[last].MinWidth = Math.Max(layerChanges.ActualWidth - offset, 10); + modeList.UpdateLayout(); + } + + private void OnGridSizeChanged(object sender, SizeChangedEventArgs e) { + if (modeSwitcher.Mode != Models.Change.DisplayMode.Grid) return; + + int last = modeGrid.Columns.Count - 1; + double offset = 0; + for (int i = 0; i < last; i++) offset += modeGrid.Columns[i].ActualWidth; + modeGrid.Columns[last].MinWidth = Math.Max(layerChanges.ActualWidth - offset, 10); + modeGrid.UpdateLayout(); + } } }