2024-06-27 06:43:15 -07:00
|
|
|
using System;
|
2024-08-13 03:24:28 -07:00
|
|
|
using System.Globalization;
|
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.Input;
|
|
|
|
using Avalonia.Interactivity;
|
2024-08-13 03:24:28 -07:00
|
|
|
using Avalonia.Media;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
2024-08-13 03:24:28 -07:00
|
|
|
public class CounterPresenter : Control
|
|
|
|
{
|
|
|
|
public static readonly StyledProperty<int> CountProperty =
|
|
|
|
AvaloniaProperty.Register<CounterPresenter, int>(nameof(Count), 0);
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
{
|
|
|
|
get => GetValue(CountProperty);
|
|
|
|
set => SetValue(CountProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
|
|
|
|
TextBlock.FontFamilyProperty.AddOwner<CounterPresenter>();
|
|
|
|
|
|
|
|
public FontFamily FontFamily
|
|
|
|
{
|
|
|
|
get => GetValue(FontFamilyProperty);
|
|
|
|
set => SetValue(FontFamilyProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<double> FontSizeProperty =
|
|
|
|
TextBlock.FontSizeProperty.AddOwner<CounterPresenter>();
|
|
|
|
|
|
|
|
public double FontSize
|
|
|
|
{
|
|
|
|
get => GetValue(FontSizeProperty);
|
|
|
|
set => SetValue(FontSizeProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<IBrush> ForegroundProperty =
|
|
|
|
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Foreground), Brushes.White);
|
|
|
|
|
|
|
|
public IBrush Foreground
|
|
|
|
{
|
|
|
|
get => GetValue(ForegroundProperty);
|
|
|
|
set => SetValue(ForegroundProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static readonly StyledProperty<IBrush> BackgroundProperty =
|
|
|
|
AvaloniaProperty.Register<CounterPresenter, IBrush>(nameof(Background), Brushes.White);
|
|
|
|
|
|
|
|
public IBrush Background
|
|
|
|
{
|
|
|
|
get => GetValue(BackgroundProperty);
|
|
|
|
set => SetValue(BackgroundProperty, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static CounterPresenter()
|
|
|
|
{
|
|
|
|
AffectsMeasure<CounterPresenter>(
|
|
|
|
FontSizeProperty,
|
|
|
|
FontFamilyProperty,
|
|
|
|
ForegroundProperty,
|
|
|
|
CountProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Render(DrawingContext context)
|
|
|
|
{
|
|
|
|
base.Render(context);
|
|
|
|
|
|
|
|
if (_label != null)
|
|
|
|
{
|
|
|
|
context.DrawRectangle(Background, null, new RoundedRect(new Rect(0, 0, _label.Width + 18, 18), new CornerRadius(9)));
|
|
|
|
context.DrawText(_label, new Point(9, 9 - _label.Height * 0.5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Size MeasureOverride(Size availableSize)
|
|
|
|
{
|
|
|
|
if (Count > 0)
|
|
|
|
{
|
|
|
|
_label = new FormattedText(
|
|
|
|
Count.ToString(),
|
|
|
|
CultureInfo.CurrentCulture,
|
|
|
|
FlowDirection.LeftToRight,
|
|
|
|
new Typeface(FontFamily),
|
|
|
|
FontSize,
|
|
|
|
Foreground);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_label = null;
|
|
|
|
}
|
|
|
|
|
2024-08-20 19:18:09 -07:00
|
|
|
InvalidateVisual();
|
2024-08-13 03:24:28 -07:00
|
|
|
return _label != null ? new Size(_label.Width + 18, 18) : new Size(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private FormattedText _label = null;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
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-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-07-14 00:55:15 -07:00
|
|
|
TxtSearchCommitsBox.Focus();
|
2024-03-07 00:18:51 -08:00
|
|
|
}
|
|
|
|
|
2024-07-06 05:46:26 -07:00
|
|
|
private void OnSearchKeyDown(object _, KeyEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-30 00:59:54 -07:00
|
|
|
var repo = DataContext as ViewModels.Repository;
|
2024-08-11 03:12:58 -07:00
|
|
|
if (repo == null)
|
|
|
|
return;
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (e.Key == Key.Enter)
|
|
|
|
{
|
2024-07-30 00:59:54 -07:00
|
|
|
if (!string.IsNullOrWhiteSpace(repo.SearchCommitFilter))
|
2024-02-05 23:08:37 -08:00
|
|
|
repo.StartSearchCommits();
|
2024-05-24 04:15:12 -07:00
|
|
|
|
2024-07-30 00:59:54 -07:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
else if (e.Key == Key.Down)
|
|
|
|
{
|
|
|
|
if (repo.IsSearchCommitSuggestionOpen)
|
|
|
|
{
|
|
|
|
SearchSuggestionBox.Focus(NavigationMethod.Tab);
|
|
|
|
SearchSuggestionBox.SelectedIndex = 0;
|
|
|
|
}
|
2024-07-31 01:26:58 -07:00
|
|
|
|
2024-07-30 00:59:54 -07:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
else if (e.Key == Key.Escape)
|
|
|
|
{
|
|
|
|
if (repo.IsSearchCommitSuggestionOpen)
|
|
|
|
{
|
|
|
|
repo.SearchCommitFilterSuggestion.Clear();
|
|
|
|
repo.IsSearchCommitSuggestionOpen = false;
|
|
|
|
}
|
|
|
|
|
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-14 00:55:15 -07:00
|
|
|
RemoteBranchTree.UnselectAll();
|
2024-08-11 03:12:58 -07:00
|
|
|
TagsList.UnselectAll();
|
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-14 00:55:15 -07:00
|
|
|
LocalBranchTree.UnselectAll();
|
2024-08-11 03:12:58 -07:00
|
|
|
TagsList.UnselectAll();
|
2024-05-29 01:42:47 -07:00
|
|
|
}
|
|
|
|
|
2024-08-11 03:12:58 -07:00
|
|
|
private void OnTagsRowsChanged(object _, RoutedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-11 03:12:58 -07:00
|
|
|
UpdateLeftSidebarLayout();
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-08-11 03:12:58 -07:00
|
|
|
private void OnTagsSelectionChanged(object _1, RoutedEventArgs _2)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-11 03:12:58 -07:00
|
|
|
LocalBranchTree.UnselectAll();
|
|
|
|
RemoteBranchTree.UnselectAll();
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-05-29 01:42:47 -07:00
|
|
|
private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArgs e)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-20 01:53:59 -07:00
|
|
|
if (sender is ListBox { SelectedItem: Models.Submodule submodule } grid && DataContext is ViewModels.Repository repo)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-08 06:11:10 -07:00
|
|
|
var menu = repo.CreateContextMenuForSubmodule(submodule.Path);
|
2024-07-14 00:55:15 -07:00
|
|
|
grid.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-08-20 01:53:59 -07:00
|
|
|
if (sender is ListBox { SelectedItem: Models.Submodule submodule } && DataContext is ViewModels.Repository repo)
|
2024-06-27 03:25:16 -07:00
|
|
|
{
|
2024-08-08 06:11:10 -07:00
|
|
|
repo.OpenSubmodule(submodule.Path);
|
2024-06-27 03:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnWorktreeContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-08-20 01:53:59 -07:00
|
|
|
if (sender is ListBox { SelectedItem: Models.Worktree worktree } grid && DataContext is ViewModels.Repository repo)
|
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-08-20 01:53:59 -07:00
|
|
|
if (sender is ListBox { SelectedItem: Models.Worktree worktree } && DataContext is ViewModels.Repository repo)
|
2024-06-27 03:25:16 -07:00
|
|
|
{
|
2024-07-06 02:17:41 -07:00
|
|
|
repo.OpenWorktree(worktree);
|
2024-06-27 03:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
|
2024-08-27 06:28:48 -07:00
|
|
|
private void OnLeftSidebarListBoxPropertyChanged(object _, AvaloniaPropertyChangedEventArgs e)
|
2024-07-04 04:12:22 -07:00
|
|
|
{
|
2024-08-20 01:53:59 -07:00
|
|
|
if (e.Property == ListBox.ItemsSourceProperty || e.Property == ListBox.IsVisibleProperty)
|
2024-07-04 04:41:38 -07:00
|
|
|
UpdateLeftSidebarLayout();
|
2024-07-26 01:32:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnLeftSidebarSizeChanged(object _, SizeChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.HeightChanged)
|
|
|
|
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;
|
|
|
|
|
2024-08-11 21:03:30 -07:00
|
|
|
var leftHeight = LeftSidebarGroups.Bounds.Height - 28.0 * 5 - 4;
|
2024-07-14 00:55:15 -07:00
|
|
|
var localBranchRows = vm.IsLocalBranchGroupExpanded ? LocalBranchTree.Rows.Count : 0;
|
|
|
|
var remoteBranchRows = vm.IsRemoteGroupExpanded ? RemoteBranchTree.Rows.Count : 0;
|
2024-07-06 08:50:54 -07:00
|
|
|
var desiredBranches = (localBranchRows + remoteBranchRows) * 24.0;
|
2024-08-11 03:12:58 -07:00
|
|
|
var desiredTag = vm.IsTagGroupExpanded ? 24.0 * TagsList.Rows : 0;
|
2024-09-05 18:57:22 -07:00
|
|
|
var desiredSubmodule = vm.IsSubmoduleGroupExpanded ? 24.0 * vm.VisibleSubmodules.Count : 0;
|
2024-08-20 01:53:59 -07:00
|
|
|
var desiredWorktree = vm.IsWorktreeGroupExpanded ? 24.0 * vm.Worktrees.Count : 0;
|
2024-07-06 08:50:54 -07:00
|
|
|
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;
|
2024-07-14 00:55:15 -07:00
|
|
|
TagsList.Height = height;
|
2024-07-06 08:50:54 -07:00
|
|
|
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;
|
2024-07-14 00:55:15 -07:00
|
|
|
SubmoduleList.Height = height;
|
2024-07-06 08:50:54 -07:00
|
|
|
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;
|
2024-07-14 00:55:15 -07:00
|
|
|
WorktreeList.Height = height;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
LocalBranchTree.Height = local;
|
|
|
|
RemoteBranchTree.Height = leftHeight - local;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
else if (remote < half)
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
RemoteBranchTree.Height = remote;
|
|
|
|
LocalBranchTree.Height = leftHeight - remote;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
LocalBranchTree.Height = half;
|
|
|
|
RemoteBranchTree.Height = half;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
LocalBranchTree.Height = leftHeight;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (vm.IsRemoteGroupExpanded)
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
RemoteBranchTree.Height = leftHeight;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (vm.IsLocalBranchGroupExpanded)
|
|
|
|
{
|
|
|
|
var height = localBranchRows * 24;
|
2024-07-14 00:55:15 -07:00
|
|
|
LocalBranchTree.Height = height;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vm.IsRemoteGroupExpanded)
|
|
|
|
{
|
|
|
|
var height = remoteBranchRows * 24;
|
2024-07-14 00:55:15 -07:00
|
|
|
RemoteBranchTree.Height = height;
|
2024-07-06 08:50:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-30 00:59:54 -07:00
|
|
|
|
2024-08-11 03:12:58 -07:00
|
|
|
private void OnSearchSuggestionBoxKeyDown(object _, KeyEventArgs e)
|
2024-07-30 00:59:54 -07:00
|
|
|
{
|
|
|
|
var repo = DataContext as ViewModels.Repository;
|
2024-08-11 03:12:58 -07:00
|
|
|
if (repo == null)
|
|
|
|
return;
|
|
|
|
|
2024-07-30 00:59:54 -07:00
|
|
|
if (e.Key == Key.Escape)
|
|
|
|
{
|
|
|
|
repo.IsSearchCommitSuggestionOpen = false;
|
|
|
|
repo.SearchCommitFilterSuggestion.Clear();
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
else if (e.Key == Key.Enter && SearchSuggestionBox.SelectedItem is string content)
|
|
|
|
{
|
|
|
|
repo.SearchCommitFilter = content;
|
|
|
|
TxtSearchCommitsBox.CaretIndex = content.Length;
|
|
|
|
repo.StartSearchCommits();
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 01:26:58 -07:00
|
|
|
private void OnSearchSuggestionDoubleTapped(object sender, TappedEventArgs e)
|
2024-07-30 00:59:54 -07:00
|
|
|
{
|
|
|
|
var repo = DataContext as ViewModels.Repository;
|
2024-08-11 03:12:58 -07:00
|
|
|
if (repo == null)
|
|
|
|
return;
|
|
|
|
|
2024-07-30 00:59:54 -07:00
|
|
|
var content = (sender as StackPanel)?.DataContext as string;
|
|
|
|
if (!string.IsNullOrEmpty(content))
|
|
|
|
{
|
|
|
|
repo.SearchCommitFilter = content;
|
|
|
|
TxtSearchCommitsBox.CaretIndex = content.Length;
|
|
|
|
repo.StartSearchCommits();
|
|
|
|
}
|
|
|
|
e.Handled = true;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|