2024-06-27 06:43:15 -07:00
|
|
|
using System;
|
2024-05-24 04:15:12 -07:00
|
|
|
using System.Collections.Generic;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
2024-03-02 06:45:14 -08:00
|
|
|
using Avalonia;
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Controls.Primitives;
|
|
|
|
using Avalonia.Input;
|
|
|
|
using Avalonia.Interactivity;
|
2024-05-24 04:15:12 -07:00
|
|
|
using Avalonia.VisualTree;
|
2024-07-04 02:59:32 -07:00
|
|
|
using AvaloniaEdit.Utils;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
|
|
|
public partial class Repository : UserControl
|
|
|
|
{
|
|
|
|
public Repository()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2024-07-04 04:12:22 -07:00
|
|
|
protected override void OnLoaded(RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnLoaded(e);
|
|
|
|
|
|
|
|
if (DataContext is ViewModels.Repository repo && !repo.IsSearching)
|
|
|
|
{
|
|
|
|
UpdateLeftSidebarLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OpenWithExternalTools(object sender, RoutedEventArgs e)
|
2024-04-05 22:14:22 -07:00
|
|
|
{
|
|
|
|
if (sender is Button button && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
2024-04-08 02:39:52 -07:00
|
|
|
var menu = repo.CreateContextMenuForExternalTools();
|
2024-05-23 06:24:22 -07:00
|
|
|
button.OpenContextMenu(menu);
|
|
|
|
e.Handled = true;
|
2024-04-05 22:14:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OpenGitFlowMenu(object sender, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
if (DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var menu = repo.CreateContextMenuForGitFlow();
|
|
|
|
(sender as Control)?.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
e.Handled = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-06-17 03:25:57 -07:00
|
|
|
private void OpenGitLFSMenu(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
var menu = repo.CreateContextMenuForGitLFS();
|
|
|
|
(sender as Control)?.OpenContextMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private async void OpenStatistics(object sender, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
if (DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var dialog = new Statistics() { DataContext = new ViewModels.Statistics(repo.FullPath) };
|
|
|
|
await dialog.ShowDialog(TopLevel.GetTopLevel(this) as Window);
|
|
|
|
e.Handled = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
|
|
|
{
|
2024-03-07 00:18:51 -08:00
|
|
|
var grid = sender as Grid;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (e.Property == IsVisibleProperty && grid.IsVisible)
|
2024-03-07 00:18:51 -08:00
|
|
|
txtSearchCommitsBox.Focus();
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnSearchKeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.Repository repo)
|
2024-02-05 23:08:37 -08:00
|
|
|
repo.StartSearchCommits();
|
2024-05-24 04:15:12 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnSearchResultDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
|
|
|
{
|
|
|
|
if (DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var commit = datagrid.SelectedItem as Models.Commit;
|
|
|
|
repo.NavigateToCommit(commit.SHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnLocalBranchTreeSelectionChanged(object sender, SelectionChangedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
if (sender is TreeView tree && tree.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
remoteBranchTree.UnselectAll();
|
|
|
|
tagsList.SelectedItem = null;
|
|
|
|
|
|
|
|
ViewModels.BranchTreeNode prev = null;
|
|
|
|
foreach (var node in repo.LocalBranchTrees)
|
|
|
|
node.UpdateCornerRadius(ref prev);
|
2024-06-06 00:31:02 -07:00
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
if (tree.SelectedItems.Count == 1)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var node = tree.SelectedItem as ViewModels.BranchTreeNode;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (node.IsBranch)
|
2024-05-29 01:42:47 -07:00
|
|
|
repo.NavigateToCommit((node.Backend as Models.Branch).Head);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-05-29 01:42:47 -07:00
|
|
|
}
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnRemoteBranchTreeSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is TreeView tree && tree.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
localBranchTree.UnselectAll();
|
|
|
|
tagsList.SelectedItem = null;
|
|
|
|
|
|
|
|
ViewModels.BranchTreeNode prev = null;
|
|
|
|
foreach (var node in repo.RemoteBranchTrees)
|
|
|
|
node.UpdateCornerRadius(ref prev);
|
|
|
|
|
|
|
|
if (tree.SelectedItems.Count == 1)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var node = tree.SelectedItem as ViewModels.BranchTreeNode;
|
|
|
|
if (node.IsBranch)
|
|
|
|
repo.NavigateToCommit((node.Backend as Models.Branch).Head);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnLocalBranchContextMenuRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
remoteBranchTree.UnselectAll();
|
2024-05-24 04:15:12 -07:00
|
|
|
tagsList.SelectedItem = null;
|
|
|
|
|
|
|
|
var repo = DataContext as ViewModels.Repository;
|
|
|
|
var tree = sender as TreeView;
|
2024-05-24 20:15:07 -07:00
|
|
|
if (tree.SelectedItems.Count == 0)
|
|
|
|
{
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-05-29 01:42:47 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
var branches = new List<Models.Branch>();
|
|
|
|
foreach (var item in tree.SelectedItems)
|
|
|
|
CollectBranchesFromNode(branches, item as ViewModels.BranchTreeNode);
|
2024-05-29 01:42:47 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
if (branches.Count == 1)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-24 04:15:12 -07:00
|
|
|
var item = (e.Source as Control)?.FindAncestorOfType<TreeViewItem>(true);
|
|
|
|
if (item != null)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-24 04:15:12 -07:00
|
|
|
var menu = repo.CreateContextMenuForLocalBranch(branches[0]);
|
|
|
|
item.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
2024-05-24 04:15:12 -07:00
|
|
|
else if (branches.Count > 1 && branches.Find(x => x.IsCurrent) == null)
|
|
|
|
{
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
var deleteMulti = new MenuItem();
|
|
|
|
deleteMulti.Header = App.Text("BranchCM.DeleteMultiBranches", branches.Count);
|
|
|
|
deleteMulti.Icon = App.CreateMenuIcon("Icons.Clear");
|
|
|
|
deleteMulti.Click += (_, ev) =>
|
|
|
|
{
|
|
|
|
repo.DeleteMultipleBranches(branches, true);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
menu.Items.Add(deleteMulti);
|
|
|
|
tree.OpenContextMenu(menu);
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnRemoteBranchContextMenuRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
localBranchTree.UnselectAll();
|
2024-05-24 04:15:12 -07:00
|
|
|
tagsList.SelectedItem = null;
|
2024-05-29 01:42:47 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
var repo = DataContext as ViewModels.Repository;
|
|
|
|
var tree = sender as TreeView;
|
2024-05-24 20:15:07 -07:00
|
|
|
if (tree.SelectedItems.Count == 0)
|
|
|
|
{
|
|
|
|
e.Handled = true;
|
|
|
|
return;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
if (tree.SelectedItems.Count == 1)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-24 04:15:12 -07:00
|
|
|
var node = tree.SelectedItem as ViewModels.BranchTreeNode;
|
|
|
|
if (node != null && node.IsRemote)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-24 04:15:12 -07:00
|
|
|
var item = (e.Source as Control)?.FindAncestorOfType<TreeViewItem>(true);
|
|
|
|
if (item != null && item.DataContext == node)
|
|
|
|
{
|
|
|
|
var menu = repo.CreateContextMenuForRemote(node.Backend as Models.Remote);
|
|
|
|
item.OpenContextMenu(menu);
|
|
|
|
}
|
2024-05-29 01:42:47 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
e.Handled = true;
|
|
|
|
return;
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-05-24 04:15:12 -07:00
|
|
|
}
|
2024-05-29 01:42:47 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
var branches = new List<Models.Branch>();
|
|
|
|
foreach (var item in tree.SelectedItems)
|
|
|
|
CollectBranchesFromNode(branches, item as ViewModels.BranchTreeNode);
|
|
|
|
|
|
|
|
if (branches.Count == 1)
|
|
|
|
{
|
|
|
|
var item = (e.Source as Control)?.FindAncestorOfType<TreeViewItem>(true);
|
|
|
|
if (item != null)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-24 04:15:12 -07:00
|
|
|
var menu = repo.CreateContextMenuForRemoteBranch(branches[0]);
|
|
|
|
item.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
2024-05-24 10:36:08 -07:00
|
|
|
else if (branches.Count > 1)
|
2024-05-24 04:15:12 -07:00
|
|
|
{
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
var deleteMulti = new MenuItem();
|
|
|
|
deleteMulti.Header = App.Text("BranchCM.DeleteMultiBranches", branches.Count);
|
|
|
|
deleteMulti.Icon = App.CreateMenuIcon("Icons.Clear");
|
|
|
|
deleteMulti.Click += (_, ev) =>
|
|
|
|
{
|
|
|
|
repo.DeleteMultipleBranches(branches, false);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
menu.Items.Add(deleteMulti);
|
|
|
|
tree.OpenContextMenu(menu);
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs e)
|
|
|
|
{
|
|
|
|
if (!ViewModels.PopupHost.CanCreatePopup())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sender is Grid grid && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
var node = grid.DataContext as ViewModels.BranchTreeNode;
|
2024-07-04 04:12:22 -07:00
|
|
|
if (node == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (node.IsBranch)
|
2024-05-29 01:42:47 -07:00
|
|
|
{
|
|
|
|
var branch = node.Backend as Models.Branch;
|
|
|
|
if (branch.IsCurrent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
repo.CheckoutBranch(branch);
|
|
|
|
}
|
2024-07-04 04:12:22 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
node.IsExpanded = !node.IsExpanded;
|
|
|
|
UpdateLeftSidebarLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
2024-05-29 01:42:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null)
|
|
|
|
{
|
|
|
|
localBranchTree.UnselectAll();
|
|
|
|
remoteBranchTree.UnselectAll();
|
|
|
|
|
|
|
|
var tag = datagrid.SelectedItem as Models.Tag;
|
|
|
|
if (DataContext is ViewModels.Repository repo)
|
|
|
|
repo.NavigateToCommit(tag.SHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTagContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var tag = datagrid.SelectedItem as Models.Tag;
|
|
|
|
var menu = repo.CreateContextMenuForTag(tag);
|
2024-05-23 06:24:22 -07:00
|
|
|
datagrid.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnToggleFilter(object sender, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
if (sender is ToggleButton toggle)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var filter = string.Empty;
|
|
|
|
if (toggle.DataContext is ViewModels.BranchTreeNode node)
|
|
|
|
{
|
|
|
|
if (node.IsBranch)
|
|
|
|
filter = (node.Backend as Models.Branch).FullName;
|
|
|
|
}
|
|
|
|
else if (toggle.DataContext is Models.Tag tag)
|
|
|
|
{
|
|
|
|
filter = tag.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(filter) && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
repo.UpdateFilter(filter, toggle.IsChecked == true);
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-29 01:42:47 -07:00
|
|
|
var submodule = datagrid.SelectedItem as string;
|
|
|
|
var menu = repo.CreateContextMenuForSubmodule(submodule);
|
|
|
|
datagrid.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
2024-06-06 00:31:02 -07:00
|
|
|
|
2024-06-27 03:25:16 -07:00
|
|
|
private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
var submodule = datagrid.SelectedItem as string;
|
|
|
|
(DataContext as ViewModels.Repository).OpenSubmodule(submodule);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnWorktreeContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
var worktree = datagrid.SelectedItem as Models.Worktree;
|
|
|
|
var menu = repo.CreateContextMenuForWorktree(worktree);
|
|
|
|
datagrid.OpenContextMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDoubleTappedWorktree(object sender, TappedEventArgs e)
|
|
|
|
{
|
|
|
|
if (sender is DataGrid datagrid && datagrid.SelectedItem != null && DataContext is ViewModels.Repository repo)
|
|
|
|
{
|
|
|
|
var worktree = datagrid.SelectedItem as Models.Worktree;
|
|
|
|
(DataContext as ViewModels.Repository).OpenWorktree(worktree);
|
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
private void CollectBranchesFromNode(List<Models.Branch> outs, ViewModels.BranchTreeNode node)
|
|
|
|
{
|
|
|
|
if (node == null || node.IsRemote)
|
|
|
|
return;
|
2024-06-06 00:31:02 -07:00
|
|
|
|
2024-05-24 04:15:12 -07:00
|
|
|
if (node.IsFolder)
|
|
|
|
{
|
|
|
|
foreach (var child in node.Children)
|
|
|
|
CollectBranchesFromNode(outs, child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var b = node.Backend as Models.Branch;
|
|
|
|
if (b != null && !outs.Contains(b))
|
|
|
|
outs.Add(b);
|
|
|
|
}
|
|
|
|
}
|
2024-07-04 02:59:32 -07:00
|
|
|
|
2024-07-04 04:12:22 -07:00
|
|
|
private void OnLeftSidebarTreeViewPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.Property == TreeView.ItemsSourceProperty || e.Property == TreeView.IsVisibleProperty)
|
|
|
|
{
|
2024-07-04 04:41:38 -07:00
|
|
|
UpdateLeftSidebarLayout();
|
2024-07-04 04:12:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnLeftSidebarDataGridPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.Property == DataGrid.ItemsSourceProperty || e.Property == DataGrid.IsVisibleProperty)
|
|
|
|
{
|
2024-07-04 04:41:38 -07:00
|
|
|
UpdateLeftSidebarLayout();
|
2024-07-04 04:12:22 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UpdateLeftSidebarLayout()
|
2024-07-04 02:59:32 -07:00
|
|
|
{
|
|
|
|
var vm = DataContext as ViewModels.Repository;
|
|
|
|
if (vm == null || vm.Settings == null)
|
|
|
|
return;
|
|
|
|
|
2024-07-04 04:12:22 -07:00
|
|
|
if (!IsLoaded)
|
2024-07-04 02:59:32 -07:00
|
|
|
return;
|
|
|
|
|
2024-07-04 04:12:22 -07:00
|
|
|
var leftHeight = leftSidebarGroups.Bounds.Height - 28.0 * 5;
|
2024-07-04 19:46:00 -07:00
|
|
|
var localBranchRows = vm.IsLocalBranchGroupExpanded ? GetTreeRowsCount(vm.LocalBranchTrees) : 0;
|
|
|
|
var remoteBranchRows = vm.IsRemoteGroupExpanded ? GetTreeRowsCount(vm.RemoteBranchTrees) : 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);
|
|
|
|
|
2024-07-04 02:59:32 -07:00
|
|
|
if (vm.IsTagGroupExpanded)
|
|
|
|
{
|
2024-07-04 19:46:00 -07:00
|
|
|
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;
|
2024-07-04 02:59:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.IsSubmoduleGroupExpanded)
|
|
|
|
{
|
2024-07-04 19:46:00 -07:00
|
|
|
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;
|
2024-07-04 02:59:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.IsWorktreeGroupExpanded)
|
|
|
|
{
|
2024-07-04 19:46:00 -07:00
|
|
|
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;
|
2024-07-04 02:59:32 -07:00
|
|
|
}
|
|
|
|
|
2024-07-04 19:46:00 -07:00
|
|
|
if (desiredBranches > leftHeight)
|
2024-07-04 02:59:32 -07:00
|
|
|
{
|
2024-07-04 19:46:00 -07:00
|
|
|
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;
|
|
|
|
}
|
2024-07-04 02:59:32 -07:00
|
|
|
}
|
2024-07-04 19:46:00 -07:00
|
|
|
else
|
2024-07-04 03:11:10 -07:00
|
|
|
{
|
2024-07-04 19:46:00 -07:00
|
|
|
if (vm.IsLocalBranchGroupExpanded)
|
|
|
|
{
|
|
|
|
var height = localBranchRows * 24;
|
|
|
|
localBranchTree.Height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.IsRemoteGroupExpanded)
|
|
|
|
{
|
|
|
|
var height = remoteBranchRows * 24;
|
|
|
|
remoteBranchTree.Height = height;
|
|
|
|
}
|
2024-07-04 02:59:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetTreeRowsCount(List<ViewModels.BranchTreeNode> nodes)
|
|
|
|
{
|
|
|
|
int count = nodes.Count;
|
|
|
|
|
|
|
|
foreach (var node in nodes)
|
|
|
|
{
|
|
|
|
if (!node.IsBranch && node.IsExpanded)
|
|
|
|
count += GetTreeRowsCount(node.Children);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|