mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
fix: bounds not updated after left side bar layout updated
This commit is contained in:
parent
b03ee19e54
commit
294f856150
4 changed files with 174 additions and 153 deletions
|
@ -10,13 +10,11 @@
|
|||
x:Name="ThisControl">
|
||||
<DataGrid x:Name="BranchesPresenter"
|
||||
ItemsSource="{Binding #ThisControl.Rows}"
|
||||
Height="{Binding #ThisControl.Height}"
|
||||
Background="Transparent"
|
||||
RowHeight="24"
|
||||
CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False"
|
||||
CanUserSortColumns="False"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto"
|
||||
HeadersVisibility="None"
|
||||
|
@ -48,27 +46,27 @@
|
|||
<Setter Property="Opacity" Value=".8"/>
|
||||
</Style>
|
||||
</DataGrid.Styles>
|
||||
|
||||
|
||||
<DataGrid.Columns>
|
||||
<DataGridTemplateColumn Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate x:DataType="vm:BranchTreeNode">
|
||||
<Grid Height="24"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
ColumnDefinitions="16,20,*,Auto,Auto"
|
||||
Background="Transparent"
|
||||
DoubleTapped="OnDoubleTappedBranchNode"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
ColumnDefinitions="16,20,*,Auto,Auto"
|
||||
Background="Transparent"
|
||||
DoubleTapped="OnDoubleTappedBranchNode"
|
||||
ToolTip.Tip="{Binding Tooltip}">
|
||||
|
||||
|
||||
<!-- Tree Expander -->
|
||||
<ToggleButton Grid.Column="0"
|
||||
<ToggleButton Grid.Column="0"
|
||||
Classes="tree_expander"
|
||||
Focusable="False"
|
||||
HorizontalAlignment="Center"
|
||||
IsChecked="{Binding IsExpanded}"
|
||||
IsHitTestVisible="False"
|
||||
IsVisible="{Binding !IsBranch}"/>
|
||||
|
||||
|
||||
<!-- Icon -->
|
||||
<v:BranchTreeNodeIcon Grid.Column="1"
|
||||
Node="{Binding}"
|
||||
|
@ -79,14 +77,14 @@
|
|||
Text="{Binding Name}"
|
||||
Classes="monospace"
|
||||
FontWeight="{Binding NameFontWeight}"/>
|
||||
|
||||
|
||||
<!-- Tracking status -->
|
||||
<Border Grid.Column="3"
|
||||
Margin="8,0"
|
||||
Height="18"
|
||||
CornerRadius="9"
|
||||
VerticalAlignment="Center"
|
||||
Background="{DynamicResource Brush.Badge}"
|
||||
<Border Grid.Column="3"
|
||||
Margin="8,0"
|
||||
Height="18"
|
||||
CornerRadius="9"
|
||||
VerticalAlignment="Center"
|
||||
Background="{DynamicResource Brush.Badge}"
|
||||
IsVisible="{Binding IsUpstreamTrackStatusVisible}">
|
||||
<TextBlock Classes="monospace" FontSize="10" HorizontalAlignment="Center" Margin="9,0" Text="{Binding UpstreamTrackStatus}" Foreground="{DynamicResource Brush.BadgeFG}"/>
|
||||
</Border>
|
||||
|
|
|
@ -113,6 +113,15 @@ namespace SourceGit.Views
|
|||
remove { RemoveHandler(SelectionChangedEvent, value); }
|
||||
}
|
||||
|
||||
public static readonly RoutedEvent<RoutedEventArgs> RowsChangedEvent =
|
||||
RoutedEvent.Register<BranchTree, RoutedEventArgs>(nameof(RowsChanged), RoutingStrategies.Tunnel | RoutingStrategies.Bubble);
|
||||
|
||||
public event EventHandler<RoutedEventArgs> RowsChanged
|
||||
{
|
||||
add { AddHandler(RowsChangedEvent, value); }
|
||||
remove { RemoveHandler(RowsChangedEvent, value); }
|
||||
}
|
||||
|
||||
public BranchTree()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -123,6 +132,14 @@ namespace SourceGit.Views
|
|||
BranchesPresenter.SelectedItem = null;
|
||||
}
|
||||
|
||||
protected override void OnSizeChanged(SizeChangedEventArgs e)
|
||||
{
|
||||
base.OnSizeChanged(e);
|
||||
|
||||
if (Bounds.Height >= 23.0)
|
||||
BranchesPresenter.Height = Bounds.Height;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
@ -138,18 +155,20 @@ namespace SourceGit.Views
|
|||
Rows.AddRange(rows);
|
||||
}
|
||||
|
||||
var repo = this.FindAncestorOfType<Repository>();
|
||||
repo?.UpdateLeftSidebarLayout();
|
||||
RaiseEvent(new RoutedEventArgs(RowsChangedEvent));
|
||||
}
|
||||
else if (change.Property == IsVisibleProperty)
|
||||
{
|
||||
var repo = this.FindAncestorOfType<Repository>();
|
||||
repo?.UpdateLeftSidebarLayout();
|
||||
RaiseEvent(new RoutedEventArgs(RowsChangedEvent));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNodesSelectionChanged(object _, SelectionChangedEventArgs e)
|
||||
{
|
||||
var repo = DataContext as ViewModels.Repository;
|
||||
if (repo?.Settings == null)
|
||||
return;
|
||||
|
||||
foreach (var item in e.AddedItems)
|
||||
{
|
||||
if (item is ViewModels.BranchTreeNode node)
|
||||
|
@ -167,10 +186,7 @@ namespace SourceGit.Views
|
|||
return;
|
||||
|
||||
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
||||
{
|
||||
var repo = DataContext as ViewModels.Repository;
|
||||
repo?.NavigateToCommit(branch.Head);
|
||||
}
|
||||
repo.NavigateToCommit(branch.Head);
|
||||
|
||||
var prev = null as ViewModels.BranchTreeNode;
|
||||
foreach (var row in Rows)
|
||||
|
@ -285,8 +301,7 @@ namespace SourceGit.Views
|
|||
rows.RemoveRange(idx + 1, removeCount);
|
||||
}
|
||||
|
||||
var repo = this.FindAncestorOfType<Repository>();
|
||||
repo?.UpdateLeftSidebarLayout();
|
||||
RaiseEvent(new RoutedEventArgs(RowsChangedEvent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,8 @@
|
|||
Margin="8,0,4,0"
|
||||
Nodes="{Binding LocalBranchTrees}"
|
||||
IsVisible="{Binding IsLocalBranchGroupExpanded}"
|
||||
SelectionChanged="OnLocalBranchTreeSelectionChanged"/>
|
||||
SelectionChanged="OnLocalBranchTreeSelectionChanged"
|
||||
RowsChanged="OnBranchTreeRowsChanged"/>
|
||||
|
||||
<!-- Remotes -->
|
||||
<ToggleButton Grid.Row="2" Classes="group_expander" IsChecked="{Binding IsRemoteGroupExpanded, Mode=TwoWay}">
|
||||
|
@ -257,7 +258,8 @@
|
|||
Margin="8,0,4,0"
|
||||
Nodes="{Binding RemoteBranchTrees}"
|
||||
IsVisible="{Binding IsRemoteGroupExpanded}"
|
||||
SelectionChanged="OnRemoteBranchTreeSelectionChanged"/>
|
||||
SelectionChanged="OnRemoteBranchTreeSelectionChanged"
|
||||
RowsChanged="OnBranchTreeRowsChanged"/>
|
||||
|
||||
<!-- Tags -->
|
||||
<ToggleButton Grid.Row="4" Classes="group_expander" IsChecked="{Binding IsTagGroupExpanded, Mode=TwoWay}">
|
||||
|
|
|
@ -15,132 +15,10 @@ namespace SourceGit.Views
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void UpdateLeftSidebarLayout()
|
||||
{
|
||||
var vm = DataContext as ViewModels.Repository;
|
||||
if (vm == null || vm.Settings == null)
|
||||
return;
|
||||
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
var leftHeight = leftSidebarGroups.Bounds.Height - 28.0 * 5;
|
||||
var localBranchRows = vm.IsLocalBranchGroupExpanded ? localBranchTree.Rows.Count : 0;
|
||||
var remoteBranchRows = vm.IsRemoteGroupExpanded ? remoteBranchTree.Rows.Count : 0;
|
||||
var desiredBranches = (localBranchRows + remoteBranchRows) * 24.0;
|
||||
var desiredTag = vm.IsTagGroupExpanded ? tagsList.RowHeight * vm.VisibleTags.Count : 0;
|
||||
var desiredSubmodule = vm.IsSubmoduleGroupExpanded ? submoduleList.RowHeight * vm.Submodules.Count : 0;
|
||||
var desiredWorktree = vm.IsWorktreeGroupExpanded ? worktreeList.RowHeight * vm.Worktrees.Count : 0;
|
||||
var desiredOthers = desiredTag + desiredSubmodule + desiredWorktree;
|
||||
var hasOverflow = (desiredBranches + desiredOthers > leftHeight);
|
||||
|
||||
if (vm.IsTagGroupExpanded)
|
||||
{
|
||||
var height = desiredTag;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches - desiredSubmodule - desiredWorktree;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
tagsList.Height = height;
|
||||
hasOverflow = (desiredBranches + desiredSubmodule + desiredWorktree) > leftHeight;
|
||||
}
|
||||
|
||||
if (vm.IsSubmoduleGroupExpanded)
|
||||
{
|
||||
var height = desiredSubmodule;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches - desiredWorktree;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
submoduleList.Height = height;
|
||||
hasOverflow = (desiredBranches + desiredWorktree) > leftHeight;
|
||||
}
|
||||
|
||||
if (vm.IsWorktreeGroupExpanded)
|
||||
{
|
||||
var height = desiredWorktree;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
worktreeList.Height = height;
|
||||
}
|
||||
|
||||
if (desiredBranches > leftHeight)
|
||||
{
|
||||
var local = localBranchRows * 24.0;
|
||||
var remote = remoteBranchRows * 24.0;
|
||||
var half = leftHeight / 2;
|
||||
if (vm.IsLocalBranchGroupExpanded)
|
||||
{
|
||||
if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
if (local < half)
|
||||
{
|
||||
localBranchTree.Height = local;
|
||||
remoteBranchTree.Height = leftHeight - local;
|
||||
}
|
||||
else if (remote < half)
|
||||
{
|
||||
remoteBranchTree.Height = remote;
|
||||
localBranchTree.Height = leftHeight - remote;
|
||||
}
|
||||
else
|
||||
{
|
||||
localBranchTree.Height = half;
|
||||
remoteBranchTree.Height = half;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
localBranchTree.Height = leftHeight;
|
||||
}
|
||||
}
|
||||
else if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
remoteBranchTree.Height = leftHeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vm.IsLocalBranchGroupExpanded)
|
||||
{
|
||||
var height = localBranchRows * 24;
|
||||
localBranchTree.Height = height;
|
||||
}
|
||||
|
||||
if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
var height = remoteBranchRows * 24;
|
||||
remoteBranchTree.Height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
if (DataContext is ViewModels.Repository { IsSearching: false })
|
||||
UpdateLeftSidebarLayout();
|
||||
UpdateLeftSidebarLayout();
|
||||
}
|
||||
|
||||
private void OpenWithExternalTools(object sender, RoutedEventArgs e)
|
||||
|
@ -211,7 +89,13 @@ namespace SourceGit.Views
|
|||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
private void OnBranchTreeRowsChanged(object _, RoutedEventArgs e)
|
||||
{
|
||||
UpdateLeftSidebarLayout();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnLocalBranchTreeSelectionChanged(object _1, RoutedEventArgs _2)
|
||||
{
|
||||
remoteBranchTree.UnselectAll();
|
||||
|
@ -311,5 +195,127 @@ namespace SourceGit.Views
|
|||
UpdateLeftSidebarLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLeftSidebarLayout()
|
||||
{
|
||||
var vm = DataContext as ViewModels.Repository;
|
||||
if (vm == null || vm.Settings == null)
|
||||
return;
|
||||
|
||||
if (!IsLoaded)
|
||||
return;
|
||||
|
||||
var leftHeight = leftSidebarGroups.Bounds.Height - 28.0 * 5;
|
||||
var localBranchRows = vm.IsLocalBranchGroupExpanded ? localBranchTree.Rows.Count : 0;
|
||||
var remoteBranchRows = vm.IsRemoteGroupExpanded ? remoteBranchTree.Rows.Count : 0;
|
||||
var desiredBranches = (localBranchRows + remoteBranchRows) * 24.0;
|
||||
var desiredTag = vm.IsTagGroupExpanded ? tagsList.RowHeight * vm.VisibleTags.Count : 0;
|
||||
var desiredSubmodule = vm.IsSubmoduleGroupExpanded ? submoduleList.RowHeight * vm.Submodules.Count : 0;
|
||||
var desiredWorktree = vm.IsWorktreeGroupExpanded ? worktreeList.RowHeight * vm.Worktrees.Count : 0;
|
||||
var desiredOthers = desiredTag + desiredSubmodule + desiredWorktree;
|
||||
var hasOverflow = (desiredBranches + desiredOthers > leftHeight);
|
||||
|
||||
if (vm.IsTagGroupExpanded)
|
||||
{
|
||||
var height = desiredTag;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches - desiredSubmodule - desiredWorktree;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
tagsList.Height = height;
|
||||
hasOverflow = (desiredBranches + desiredSubmodule + desiredWorktree) > leftHeight;
|
||||
}
|
||||
|
||||
if (vm.IsSubmoduleGroupExpanded)
|
||||
{
|
||||
var height = desiredSubmodule;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches - desiredWorktree;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
submoduleList.Height = height;
|
||||
hasOverflow = (desiredBranches + desiredWorktree) > leftHeight;
|
||||
}
|
||||
|
||||
if (vm.IsWorktreeGroupExpanded)
|
||||
{
|
||||
var height = desiredWorktree;
|
||||
if (hasOverflow)
|
||||
{
|
||||
var test = leftHeight - desiredBranches;
|
||||
if (test < 0)
|
||||
height = Math.Min(200, height);
|
||||
else
|
||||
height = Math.Max(200, test);
|
||||
}
|
||||
|
||||
leftHeight -= height;
|
||||
worktreeList.Height = height;
|
||||
}
|
||||
|
||||
if (desiredBranches > leftHeight)
|
||||
{
|
||||
var local = localBranchRows * 24.0;
|
||||
var remote = remoteBranchRows * 24.0;
|
||||
var half = leftHeight / 2;
|
||||
if (vm.IsLocalBranchGroupExpanded)
|
||||
{
|
||||
if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
if (local < half)
|
||||
{
|
||||
localBranchTree.Height = local;
|
||||
remoteBranchTree.Height = leftHeight - local;
|
||||
}
|
||||
else if (remote < half)
|
||||
{
|
||||
remoteBranchTree.Height = remote;
|
||||
localBranchTree.Height = leftHeight - remote;
|
||||
}
|
||||
else
|
||||
{
|
||||
localBranchTree.Height = half;
|
||||
remoteBranchTree.Height = half;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
localBranchTree.Height = leftHeight;
|
||||
}
|
||||
}
|
||||
else if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
remoteBranchTree.Height = leftHeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vm.IsLocalBranchGroupExpanded)
|
||||
{
|
||||
var height = localBranchRows * 24;
|
||||
localBranchTree.Height = height;
|
||||
}
|
||||
|
||||
if (vm.IsRemoteGroupExpanded)
|
||||
{
|
||||
var height = remoteBranchRows * 24;
|
||||
remoteBranchTree.Height = height;
|
||||
}
|
||||
}
|
||||
|
||||
leftSidebarGroups.InvalidateMeasure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue