2024-06-27 06:43:15 -07:00
|
|
|
using System;
|
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-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);
|
2024-07-06 08:50:54 -07:00
|
|
|
UpdateLeftSidebarLayout();
|
2024-07-04 04:12:22 -07:00
|
|
|
}
|
|
|
|
|
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-07-06 05:46:26 -07:00
|
|
|
private async void OpenStatistics(object _, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
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) };
|
2024-07-06 02:17:41 -07:00
|
|
|
await dialog.ShowDialog(owner);
|
2024-05-29 01:42:47 -07:00
|
|
|
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-07-09 21:11:51 -07:00
|
|
|
if (e.Property == IsVisibleProperty && sender is Grid { IsVisible: true })
|
2024-03-07 00:18:51 -08:00
|
|
|
txtSearchCommitsBox.Focus();
|
|
|
|
}
|
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnSearchKeyDown(object _, KeyEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
if (sender is DataGrid { SelectedItem: Models.Commit commit } && DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
repo.NavigateToCommit(commit.SHA);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-07-09 21:11:51 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
2024-07-06 08:50:54 -07:00
|
|
|
|
|
|
|
private void OnBranchTreeRowsChanged(object _, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
UpdateLeftSidebarLayout();
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnLocalBranchTreeSelectionChanged(object _1, RoutedEventArgs _2)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
remoteBranchTree.UnselectAll();
|
|
|
|
tagsList.SelectedItem = null;
|
2024-05-29 01:42:47 -07:00
|
|
|
}
|
2024-07-09 21:11:51 -07:00
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnRemoteBranchTreeSelectionChanged(object _1, RoutedEventArgs _2)
|
2024-05-29 01:42:47 -07:00
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
localBranchTree.UnselectAll();
|
|
|
|
tagsList.SelectedItem = null;
|
2024-05-29 01:42:47 -07:00
|
|
|
}
|
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs _)
|
2024-05-29 01:42:47 -07:00
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
if (sender is DataGrid { SelectedItem: Models.Tag tag })
|
2024-05-29 01:42:47 -07:00
|
|
|
{
|
|
|
|
localBranchTree.UnselectAll();
|
|
|
|
remoteBranchTree.UnselectAll();
|
|
|
|
|
|
|
|
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-07-06 02:17:41 -07:00
|
|
|
private void OnToggleTagFilter(object sender, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
if (sender is ToggleButton { DataContext: Models.Tag tag } toggle && DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-06 05:46:26 -07:00
|
|
|
repo.UpdateFilter(tag.Name, 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)
|
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
if (sender is DataGrid { SelectedItem: not null } grid && DataContext is ViewModels.Repository repo)
|
2024-06-27 03:25:16 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
var submodule = grid.SelectedItem as string;
|
|
|
|
repo.OpenSubmodule(submodule);
|
2024-06-27 03:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnWorktreeContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
if (sender is DataGrid { SelectedItem: not null } grid && DataContext is ViewModels.Repository repo)
|
2024-06-27 03:25:16 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
var worktree = grid.SelectedItem as Models.Worktree;
|
2024-06-27 03:25:16 -07:00
|
|
|
var menu = repo.CreateContextMenuForWorktree(worktree);
|
2024-07-06 02:17:41 -07:00
|
|
|
grid.OpenContextMenu(menu);
|
2024-06-27 03:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDoubleTappedWorktree(object sender, TappedEventArgs e)
|
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
if (sender is DataGrid { SelectedItem: not null } grid && DataContext is ViewModels.Repository repo)
|
2024-06-27 03:25:16 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
var worktree = grid.SelectedItem as Models.Worktree;
|
|
|
|
repo.OpenWorktree(worktree);
|
2024-06-27 03:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnLeftSidebarDataGridPropertyChanged(object _, AvaloniaPropertyChangedEventArgs e)
|
2024-07-04 04:12:22 -07:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2024-07-06 08:50:54 -07:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|