fix<CommitChanges>: fix row selection in Grid/List view mode

This commit is contained in:
leo 2021-04-30 10:19:37 +08:00
parent 262c7afe9e
commit 75006db94f
2 changed files with 27 additions and 4 deletions

View file

@ -70,7 +70,7 @@
BorderBrush="{StaticResource Brush.Border2}"
BorderThickness="1"
Background="{StaticResource Brush.Contents}">
<Grid>
<Grid x:Name="layerChanges">
<controls:Tree
x:Name="modeTree"
FontFamily="Consolas"
@ -128,6 +128,7 @@
SelectionMode="Single"
SelectionUnit="FullRow"
SelectionChanged="OnListSelectionChanged"
SizeChanged="OnListSizeChanged"
RowStyle="{StaticResource Style.DataGridRow.Changes}">
<DataGrid.Columns>
<DataGridTemplateColumn Width="22" IsReadOnly="True">
@ -153,6 +154,7 @@
SelectionMode="Single"
SelectionUnit="FullRow"
SelectionChanged="OnGridSelectionChanged"
SizeChanged="OnGridSizeChanged"
RowStyle="{StaticResource Style.DataGridRow.Changes}">
<DataGrid.Columns>
<DataGridTemplateColumn Width="22" IsReadOnly="True">

View file

@ -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();
}
}
}