ux: use DataGrid instead of ChangeCollectionView for changes in INFORMATION page

This commit is contained in:
leo 2024-06-03 10:06:23 +08:00
parent 49ce07443e
commit 0e6a08860a
2 changed files with 51 additions and 37 deletions

View file

@ -25,28 +25,40 @@
<Rectangle Grid.Row="1" Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}" VerticalAlignment="Center"/> <Rectangle Grid.Row="1" Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}" VerticalAlignment="Center"/>
<!-- Change List --> <!-- Change List -->
<Grid Grid.Row="2" ColumnDefinitions="96,*" Margin="0,0,8,16"> <DataGrid Grid.Row="2"
<TextBlock Grid.Column="0" Background="Transparent"
Classes="group_header_label" ItemsSource="{Binding Changes}"
Margin="0" SelectionMode="Single"
HorizontalAlignment="Right" CanUserReorderColumns="False"
VerticalAlignment="Top" CanUserResizeColumns="False"
Text="{DynamicResource Text.CommitDetail.Changes}"/> CanUserSortColumns="False"
IsReadOnly="True"
<v:ChangeCollectionView Grid.Column="1" HeadersVisibility="None"
IsWorkingCopyChange="False" Focusable="False"
Margin="8,0,0,0" RowHeight="26"
ViewMode="List" Margin="80,0,8,16"
Changes="{Binding Changes}" HorizontalScrollBarVisibility="Disabled"
ContextRequested="OnChangeListContextRequested" VerticalScrollBarVisibility="Auto"
ChangeDoubleTapped="OnChangeDoubleTapped"> ContextRequested="OnChangeListContextRequested"
<v:ChangeCollectionView.Styles> DoubleTapped="OnChangeListDoubleTapped">
<Style Selector="TreeDataGrid"> <DataGrid.Columns>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/> <DataGridTemplateColumn Header="ICON">
</Style> <DataGridTemplateColumn.CellTemplate>
</v:ChangeCollectionView.Styles> <DataTemplate>
</v:ChangeCollectionView> <v:ChangeStatusIcon Width="14" Height="14" IsWorkingCopyChange="False" Change="{Binding}"/>
</Grid> </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" Header="PATH">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Classes="monospace" Text="{Binding Path}" Margin="8,0,0,0"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid> </Grid>
</TabItem> </TabItem>

View file

@ -1,5 +1,5 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Input;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -10,31 +10,33 @@ namespace SourceGit.Views
InitializeComponent(); InitializeComponent();
} }
private void OnChangeListContextRequested(object sender, ContextRequestedEventArgs e) private void OnChangeListDoubleTapped(object sender, TappedEventArgs e)
{ {
if (DataContext is ViewModels.CommitDetail vm && sender is ChangeCollectionView view) if (DataContext is ViewModels.CommitDetail detail)
{ {
var selected = view.SelectedChanges; var datagrid = sender as DataGrid;
if (selected != null && selected.Count == 1) detail.ActivePageIndex = 1;
{ detail.SelectedChanges = new () { datagrid.SelectedItem as Models.Change };
var menu = vm.CreateChangeContextMenu(selected[0]);
view.OpenContextMenu(menu);
}
} }
e.Handled = true; e.Handled = true;
} }
private void OnChangeDoubleTapped(object sender, RoutedEventArgs e) private void OnChangeListContextRequested(object sender, ContextRequestedEventArgs e)
{ {
if (DataContext is ViewModels.CommitDetail vm && sender is ChangeCollectionView view) if (DataContext is ViewModels.CommitDetail detail)
{ {
var selected = view.SelectedChanges; var datagrid = sender as DataGrid;
if (selected != null && selected.Count == 1) if (datagrid.SelectedItem == null)
{ {
vm.ActivePageIndex = 1; e.Handled = true;
vm.SelectedChanges = new() { selected[0] }; return;
} }
var menu = detail.CreateChangeContextMenu(datagrid.SelectedItem as Models.Change);
datagrid.OpenContextMenu(menu);
} }
e.Handled = true; e.Handled = true;
} }
} }