Skip to content

Commit f904b3b

Browse files
committed
enhance: improve performance
1 parent c03cc85 commit f904b3b

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

src/Views/Repository.axaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
</TextBox.InnerRightContent>
232232
</TextBox>
233233

234-
<Grid Grid.Row="2" RowDefinitions="28,Auto,28,Auto,28,Auto,28,Auto,28,Auto" LayoutUpdated="OnDashboardLayoutUpdated">
234+
<Grid Grid.Row="2" x:Name="leftSidebarGroups" RowDefinitions="28,Auto,28,Auto,28,Auto,28,Auto,28,Auto">
235235
<!-- Local Branches -->
236236
<ToggleButton Grid.Row="0" Classes="group_expander" IsChecked="{Binding IsLocalBranchGroupExpanded, Mode=TwoWay}">
237237
<TextBlock Classes="group_header_label" Margin="0" Text="{DynamicResource Text.Repository.LocalBranches}"/>
@@ -245,7 +245,8 @@
245245
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
246246
ScrollViewer.VerticalScrollBarVisibility="Auto"
247247
ContextRequested="OnLocalBranchContextMenuRequested"
248-
SelectionChanged="OnLocalBranchTreeSelectionChanged">
248+
SelectionChanged="OnLocalBranchTreeSelectionChanged"
249+
PropertyChanged="OnLeftSidebarTreeViewPropertyChanged">
249250
<TreeView.Styles>
250251
<Style Selector="TreeViewItem" x:DataType="vm:BranchTreeNode">
251252
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
@@ -325,7 +326,8 @@
325326
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
326327
ScrollViewer.VerticalScrollBarVisibility="Auto"
327328
ContextRequested="OnRemoteBranchContextMenuRequested"
328-
SelectionChanged="OnRemoteBranchTreeSelectionChanged">
329+
SelectionChanged="OnRemoteBranchTreeSelectionChanged"
330+
PropertyChanged="OnLeftSidebarTreeViewPropertyChanged">
329331
<TreeView.Styles>
330332
<Style Selector="TreeViewItem" x:DataType="vm:BranchTreeNode">
331333
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
@@ -401,7 +403,8 @@
401403
VerticalScrollBarVisibility="Auto"
402404
IsVisible="{Binding IsTagGroupExpanded, Mode=OneWay}"
403405
SelectionChanged="OnTagDataGridSelectionChanged"
404-
ContextRequested="OnTagContextRequested">
406+
ContextRequested="OnTagContextRequested"
407+
PropertyChanged="OnLeftSidebarDataGridPropertyChanged">
405408
<DataGrid.Styles>
406409
<Style Selector="DataGridRow">
407410
<Setter Property="CornerRadius" Value="4" />
@@ -504,6 +507,7 @@
504507
VerticalScrollBarVisibility="Auto"
505508
ContextRequested="OnSubmoduleContextRequested"
506509
DoubleTapped="OnDoubleTappedSubmodule"
510+
PropertyChanged="OnLeftSidebarDataGridPropertyChanged"
507511
IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}">
508512
<DataGrid.Styles>
509513
<Style Selector="DataGridRow">
@@ -585,6 +589,7 @@
585589
VerticalScrollBarVisibility="Auto"
586590
ContextRequested="OnWorktreeContextRequested"
587591
DoubleTapped="OnDoubleTappedWorktree"
592+
PropertyChanged="OnLeftSidebarDataGridPropertyChanged"
588593
IsVisible="{Binding IsWorktreeGroupExpanded, Mode=OneWay}">
589594
<DataGrid.Styles>
590595
<Style Selector="DataGridRow">

src/Views/Repository.axaml.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ public Repository()
1818
InitializeComponent();
1919
}
2020

21+
protected override void OnLoaded(RoutedEventArgs e)
22+
{
23+
base.OnLoaded(e);
24+
25+
if (DataContext is ViewModels.Repository repo && !repo.IsSearching)
26+
{
27+
UpdateLeftSidebarLayout();
28+
}
29+
}
30+
2131
private void OpenWithExternalTools(object sender, RoutedEventArgs e)
2232
{
2333
if (sender is Button button && DataContext is ViewModels.Repository repo)
@@ -244,15 +254,24 @@ private void OnDoubleTappedBranchNode(object sender, TappedEventArgs e)
244254
if (sender is Grid grid && DataContext is ViewModels.Repository repo)
245255
{
246256
var node = grid.DataContext as ViewModels.BranchTreeNode;
247-
if (node != null && node.IsBranch)
257+
if (node == null)
258+
return;
259+
260+
if (node.IsBranch)
248261
{
249262
var branch = node.Backend as Models.Branch;
250263
if (branch.IsCurrent)
251264
return;
252265

253266
repo.CheckoutBranch(branch);
254-
e.Handled = true;
255267
}
268+
else
269+
{
270+
node.IsExpanded = !node.IsExpanded;
271+
UpdateLeftSidebarLayout();
272+
}
273+
274+
e.Handled = true;
256275
}
257276
}
258277

@@ -369,17 +388,34 @@ private void CollectBranchesFromNode(List<Models.Branch> outs, ViewModels.Branch
369388
}
370389
}
371390

372-
private void OnDashboardLayoutUpdated(object sender, EventArgs e)
391+
private void OnLeftSidebarTreeViewPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
392+
{
393+
if (e.Property == TreeView.ItemsSourceProperty || e.Property == TreeView.IsVisibleProperty)
394+
{
395+
if (sender is TreeView tree && tree.IsVisible)
396+
UpdateLeftSidebarLayout();
397+
}
398+
}
399+
400+
private void OnLeftSidebarDataGridPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
401+
{
402+
if (e.Property == DataGrid.ItemsSourceProperty || e.Property == DataGrid.IsVisibleProperty)
403+
{
404+
if (sender is DataGrid datagrid && datagrid.IsVisible)
405+
UpdateLeftSidebarLayout();
406+
}
407+
}
408+
409+
private void UpdateLeftSidebarLayout()
373410
{
374411
var vm = DataContext as ViewModels.Repository;
375412
if (vm == null || vm.Settings == null)
376413
return;
377414

378-
var grid = sender as Grid;
379-
if (grid == null || !grid.IsAttachedToVisualTree())
415+
if (!IsLoaded)
380416
return;
381417

382-
var leftHeight = grid.Bounds.Height - 28.0 * 5;
418+
var leftHeight = leftSidebarGroups.Bounds.Height - 28.0 * 5;
383419
if (vm.IsTagGroupExpanded)
384420
{
385421
var desiredHeight = Math.Min(200.0, tagsList.RowHeight * vm.VisibleTags.Count);

0 commit comments

Comments
 (0)