Skip to content

Commit 0460b0d

Browse files
committed
ux: layout of change collection view
Signed-off-by: leo <longshuang@msn.cn>
1 parent 0c37957 commit 0460b0d

File tree

2 files changed

+67
-53
lines changed

2 files changed

+67
-53
lines changed

src/Views/ChangeCollectionView.axaml

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,43 @@
3737
SelectionChanged="OnRowSelectionChanged">
3838
<ListBox.ItemTemplate>
3939
<DataTemplate DataType="vm:ChangeTreeNode">
40-
<Grid ColumnDefinitions="16,16,Auto,*"
41-
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
42-
Background="Transparent"
43-
DoubleTapped="OnRowDoubleTapped"
44-
DataContextChanged="OnRowDataContextChanged">
45-
<v:ChangeTreeNodeToggleButton Grid.Column="0"
46-
Classes="tree_expander"
47-
Focusable="False"
48-
HorizontalAlignment="Center"
49-
IsChecked="{Binding IsExpanded, Mode=OneWay}"
50-
IsVisible="{Binding IsFolder}"/>
51-
52-
<ToggleButton Grid.Column="1"
53-
Classes="folder"
40+
<StackPanel Orientation="Horizontal"
41+
Height="24"
42+
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
43+
Background="Transparent"
44+
DoubleTapped="OnRowDoubleTapped"
45+
DataContextChanged="OnRowDataContextChanged">
46+
<Border Width="16">
47+
<v:ChangeTreeNodeToggleButton Classes="tree_expander"
48+
Focusable="False"
49+
HorizontalAlignment="Center"
50+
IsChecked="{Binding IsExpanded, Mode=OneWay}"
51+
IsVisible="{Binding IsFolder}"/>
52+
</Border>
53+
54+
<ToggleButton Classes="folder"
5455
Focusable="False"
5556
Width="14" Height="14"
56-
Margin="0,1,0,0"
57+
Margin="1,1,1,0"
5758
Foreground="Goldenrod"
5859
IsChecked="{Binding IsExpanded}"
5960
IsVisible="{Binding IsFolder}"/>
6061

61-
<v:ChangeStatusIcon Grid.Column="1"
62-
Width="14" Height="14"
62+
<v:ChangeStatusIcon Width="14" Height="14"
63+
Margin="1,0"
6364
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
6465
Change="{Binding Change}"
6566
IsVisible="{Binding !IsFolder}"/>
6667

67-
<StackPanel Grid.Column="2" Orientation="Horizontal" Margin="4,0,0,0">
68-
<TextBlock Text="{Binding ConflictMarker, Mode=OneWay}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding ShowConflictMarker}"/>
69-
<TextBlock Text="{Binding DisplayName, Mode=OneWay}"/>
70-
</StackPanel>
71-
</Grid>
68+
<TextBlock Text="{Binding ConflictMarker, Mode=OneWay}"
69+
Foreground="DarkOrange"
70+
FontWeight="Bold"
71+
Margin="4,0,0,0"
72+
IsVisible="{Binding ShowConflictMarker}"/>
73+
74+
<TextBlock Text="{Binding DisplayName, Mode=OneWay}"
75+
Margin="4,0,0,0"/>
76+
</StackPanel>
7277
</DataTemplate>
7378
</ListBox.ItemTemplate>
7479
</v:ChangeCollectionContainer>
@@ -82,25 +87,28 @@
8287
SelectionChanged="OnRowSelectionChanged">
8388
<ListBox.ItemTemplate>
8489
<DataTemplate DataType="m:Change">
85-
<Grid ColumnDefinitions="Auto,Auto,Auto,*"
86-
Background="Transparent"
87-
DoubleTapped="OnRowDoubleTapped"
88-
DataContextChanged="OnRowDataContextChanged">
89-
<v:ChangeStatusIcon Grid.Column="0"
90-
Width="14" Height="14"
90+
<StackPanel Orientation="Horizontal"
91+
Height="24"
92+
Background="Transparent"
93+
DoubleTapped="OnRowDoubleTapped"
94+
DataContextChanged="OnRowDataContextChanged">
95+
<v:ChangeStatusIcon Width="14" Height="14"
9196
Margin="4,0,0,0"
9297
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
9398
Change="{Binding}" />
9499

95-
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
96-
<TextBlock Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
97-
<TextBlock Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"/>
98-
</StackPanel>
100+
<TextBlock Text="{Binding ConflictMarker}"
101+
Foreground="DarkOrange"
102+
FontWeight="Bold"
103+
Margin="4,0,0,0" IsVisible="{Binding IsConflicted}"/>
104+
105+
<TextBlock Text="{Binding Path, Converter={x:Static c:PathConverters.PureFileName}}"
106+
Margin="4,0,0,0"/>
99107

100-
<TextBlock Grid.Column="2"
101-
Text="{Binding Path, Converter={x:Static c:PathConverters.PureDirectoryName}}"
102-
Foreground="{DynamicResource Brush.FG2}"/>
103-
</Grid>
108+
<TextBlock Text="{Binding Path, Converter={x:Static c:PathConverters.PureDirectoryName}}"
109+
Foreground="{DynamicResource Brush.FG2}"
110+
Margin="4,0,0,0"/>
111+
</StackPanel>
104112
</DataTemplate>
105113
</ListBox.ItemTemplate>
106114
</v:ChangeCollectionContainer>
@@ -114,21 +122,25 @@
114122
SelectionChanged="OnRowSelectionChanged">
115123
<ListBox.ItemTemplate>
116124
<DataTemplate DataType="m:Change">
117-
<Grid ColumnDefinitions="Auto,Auto,*"
118-
Background="Transparent"
119-
DoubleTapped="OnRowDoubleTapped"
120-
DataContextChanged="OnRowDataContextChanged">
121-
<v:ChangeStatusIcon Grid.Column="0"
122-
Width="14" Height="14"
125+
<StackPanel Orientation="Horizontal"
126+
Height="24"
127+
Background="Transparent"
128+
DoubleTapped="OnRowDoubleTapped"
129+
DataContextChanged="OnRowDataContextChanged">
130+
<v:ChangeStatusIcon Width="14" Height="14"
123131
Margin="4,0,0,0"
124132
IsUnstagedChange="{Binding #ThisControl.IsUnstagedChange}"
125133
Change="{Binding}" />
126134

127-
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="4,0">
128-
<TextBlock Text="{Binding ConflictMarker}" Foreground="DarkOrange" FontWeight="Bold" Margin="0,0,4,0" IsVisible="{Binding IsConflicted}"/>
129-
<TextBlock Text="{Binding Path}"/>
130-
</StackPanel>
131-
</Grid>
135+
<TextBlock Text="{Binding ConflictMarker}"
136+
Foreground="DarkOrange"
137+
FontWeight="Bold"
138+
Margin="4,0,0,0"
139+
IsVisible="{Binding IsConflicted}"/>
140+
141+
<TextBlock Margin="4,0,0,0"
142+
Text="{Binding Path}"/>
143+
</StackPanel>
132144
</DataTemplate>
133145
</ListBox.ItemTemplate>
134146
</v:ChangeCollectionContainer>

src/Views/ChangeCollectionView.axaml.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
231231

232232
private void OnRowDataContextChanged(object sender, EventArgs e)
233233
{
234-
if (sender is not Control control)
234+
if (sender is not Control { DataContext: { } ctx } control)
235235
return;
236236

237-
if (control.DataContext is ViewModels.ChangeTreeNode node)
237+
if (ctx is ViewModels.ChangeTreeNode node)
238238
{
239239
if (node.Change is { } c)
240240
UpdateRowTips(control, c);
241241
else
242242
ToolTip.SetTip(control, node.FullPath);
243243
}
244-
else if (control.DataContext is Models.Change change)
244+
else if (ctx is Models.Change change)
245245
{
246246
UpdateRowTips(control, change);
247247
}
@@ -253,8 +253,10 @@ private void OnRowDataContextChanged(object sender, EventArgs e)
253253

254254
private void OnRowDoubleTapped(object sender, TappedEventArgs e)
255255
{
256-
var grid = sender as Grid;
257-
if (grid?.DataContext is ViewModels.ChangeTreeNode node)
256+
if (sender is not Control { DataContext: { } ctx })
257+
return;
258+
259+
if (ctx is ViewModels.ChangeTreeNode node)
258260
{
259261
if (node.IsFolder)
260262
{
@@ -269,7 +271,7 @@ private void OnRowDoubleTapped(object sender, TappedEventArgs e)
269271
RaiseEvent(new RoutedEventArgs(ChangeDoubleTappedEvent));
270272
}
271273
}
272-
else if (grid?.DataContext is Models.Change)
274+
else if (ctx is Models.Change)
273275
{
274276
RaiseEvent(new RoutedEventArgs(ChangeDoubleTappedEvent));
275277
}

0 commit comments

Comments
 (0)