mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
refactor: trigger nagivation in BranchTree
This commit is contained in:
parent
36b8472d02
commit
b03ee19e54
2 changed files with 33 additions and 58 deletions
|
@ -17,7 +17,7 @@ namespace SourceGit.Views
|
||||||
public class BranchTreeNodeIcon : UserControl
|
public class BranchTreeNodeIcon : UserControl
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<ViewModels.BranchTreeNode> NodeProperty =
|
public static readonly StyledProperty<ViewModels.BranchTreeNode> NodeProperty =
|
||||||
AvaloniaProperty.Register<BranchTreeNodeIcon, ViewModels.BranchTreeNode>(nameof(Node), null);
|
AvaloniaProperty.Register<BranchTreeNodeIcon, ViewModels.BranchTreeNode>(nameof(Node));
|
||||||
|
|
||||||
public ViewModels.BranchTreeNode Node
|
public ViewModels.BranchTreeNode Node
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,7 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<bool> IsExpandedProperty =
|
public static readonly StyledProperty<bool> IsExpandedProperty =
|
||||||
AvaloniaProperty.Register<BranchTreeNodeIcon, bool>(nameof(IsExpanded), false);
|
AvaloniaProperty.Register<BranchTreeNodeIcon, bool>(nameof(IsExpanded));
|
||||||
|
|
||||||
public bool IsExpanded
|
public bool IsExpanded
|
||||||
{
|
{
|
||||||
|
@ -36,8 +36,8 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
static BranchTreeNodeIcon()
|
static BranchTreeNodeIcon()
|
||||||
{
|
{
|
||||||
NodeProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, e) => icon.UpdateContent());
|
NodeProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, _) => icon.UpdateContent());
|
||||||
IsExpandedProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, e) => icon.UpdateContent());
|
IsExpandedProperty.Changed.AddClassHandler<BranchTreeNodeIcon>((icon, _) => icon.UpdateContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateContent()
|
private void UpdateContent()
|
||||||
|
@ -90,7 +90,7 @@ namespace SourceGit.Views
|
||||||
public partial class BranchTree : UserControl
|
public partial class BranchTree : UserControl
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<List<ViewModels.BranchTreeNode>> NodesProperty =
|
public static readonly StyledProperty<List<ViewModels.BranchTreeNode>> NodesProperty =
|
||||||
AvaloniaProperty.Register<BranchTree, List<ViewModels.BranchTreeNode>>(nameof(Nodes), null);
|
AvaloniaProperty.Register<BranchTree, List<ViewModels.BranchTreeNode>>(nameof(Nodes));
|
||||||
|
|
||||||
public List<ViewModels.BranchTreeNode> Nodes
|
public List<ViewModels.BranchTreeNode> Nodes
|
||||||
{
|
{
|
||||||
|
@ -148,12 +148,8 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNodesSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void OnNodesSelectionChanged(object _, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var selected = BranchesPresenter.SelectedItems;
|
|
||||||
if (selected == null || selected.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var item in e.AddedItems)
|
foreach (var item in e.AddedItems)
|
||||||
{
|
{
|
||||||
if (item is ViewModels.BranchTreeNode node)
|
if (item is ViewModels.BranchTreeNode node)
|
||||||
|
@ -165,6 +161,16 @@ namespace SourceGit.Views
|
||||||
if (item is ViewModels.BranchTreeNode node)
|
if (item is ViewModels.BranchTreeNode node)
|
||||||
node.IsSelected = false;
|
node.IsSelected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var selected = BranchesPresenter.SelectedItems;
|
||||||
|
if (selected == null || selected.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
||||||
|
{
|
||||||
|
var repo = DataContext as ViewModels.Repository;
|
||||||
|
repo?.NavigateToCommit(branch.Head);
|
||||||
|
}
|
||||||
|
|
||||||
var prev = null as ViewModels.BranchTreeNode;
|
var prev = null as ViewModels.BranchTreeNode;
|
||||||
foreach (var row in Rows)
|
foreach (var row in Rows)
|
||||||
|
@ -189,7 +195,7 @@ namespace SourceGit.Views
|
||||||
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeContextRequested(object sender, ContextRequestedEventArgs e)
|
private void OnTreeContextRequested(object _1, ContextRequestedEventArgs _2)
|
||||||
{
|
{
|
||||||
var repo = DataContext as ViewModels.Repository;
|
var repo = DataContext as ViewModels.Repository;
|
||||||
if (repo?.Settings == null)
|
if (repo?.Settings == null)
|
||||||
|
@ -237,7 +243,7 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs e)
|
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
|
||||||
{
|
{
|
||||||
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
|
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,7 +175,7 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OpenStatistics(object sender, RoutedEventArgs e)
|
private async void OpenStatistics(object _, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
if (DataContext is ViewModels.Repository repo && TopLevel.GetTopLevel(this) is Window owner)
|
||||||
{
|
{
|
||||||
|
@ -187,11 +187,11 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
private void OnSearchCommitPanelPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Property == IsVisibleProperty && sender is Grid { IsVisible: true} grid)
|
if (e.Property == IsVisibleProperty && sender is Grid { IsVisible: true})
|
||||||
txtSearchCommitsBox.Focus();
|
txtSearchCommitsBox.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSearchKeyDown(object sender, KeyEventArgs e)
|
private void OnSearchKeyDown(object _, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Key == Key.Enter)
|
if (e.Key == Key.Enter)
|
||||||
{
|
{
|
||||||
|
@ -204,55 +204,33 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnSearchResultDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void OnSearchResultDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is DataGrid { SelectedItem: not null } grid && DataContext is ViewModels.Repository repo)
|
if (sender is DataGrid { SelectedItem: Models.Commit commit } && DataContext is ViewModels.Repository repo)
|
||||||
{
|
{
|
||||||
var commit = grid.SelectedItem as Models.Commit;
|
|
||||||
repo.NavigateToCommit(commit.SHA);
|
repo.NavigateToCommit(commit.SHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLocalBranchTreeSelectionChanged(object sender, RoutedEventArgs e)
|
private void OnLocalBranchTreeSelectionChanged(object _1, RoutedEventArgs _2)
|
||||||
{
|
{
|
||||||
if (sender is BranchTree tree && DataContext is ViewModels.Repository repo)
|
remoteBranchTree.UnselectAll();
|
||||||
{
|
tagsList.SelectedItem = null;
|
||||||
var selected = tree.BranchesPresenter.SelectedItems;
|
|
||||||
if (selected == null || selected.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
remoteBranchTree.UnselectAll();
|
|
||||||
tagsList.SelectedItem = null;
|
|
||||||
|
|
||||||
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
|
||||||
repo.NavigateToCommit(branch.Head);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRemoteBranchTreeSelectionChanged(object sender, RoutedEventArgs e)
|
private void OnRemoteBranchTreeSelectionChanged(object _1, RoutedEventArgs _2)
|
||||||
{
|
{
|
||||||
if (sender is BranchTree tree && DataContext is ViewModels.Repository repo)
|
localBranchTree.UnselectAll();
|
||||||
{
|
tagsList.SelectedItem = null;
|
||||||
var selected = tree.BranchesPresenter.SelectedItems;
|
|
||||||
if (selected == null || selected.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
localBranchTree.UnselectAll();
|
|
||||||
tagsList.SelectedItem = null;
|
|
||||||
|
|
||||||
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
|
||||||
repo.NavigateToCommit(branch.Head);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
|
private void OnTagDataGridSelectionChanged(object sender, SelectionChangedEventArgs _)
|
||||||
{
|
{
|
||||||
if (sender is DataGrid { SelectedItem: not null } grid)
|
if (sender is DataGrid { SelectedItem: Models.Tag tag })
|
||||||
{
|
{
|
||||||
localBranchTree.UnselectAll();
|
localBranchTree.UnselectAll();
|
||||||
remoteBranchTree.UnselectAll();
|
remoteBranchTree.UnselectAll();
|
||||||
|
|
||||||
var tag = grid.SelectedItem as Models.Tag;
|
|
||||||
if (DataContext is ViewModels.Repository repo)
|
if (DataContext is ViewModels.Repository repo)
|
||||||
repo.NavigateToCommit(tag.SHA);
|
repo.NavigateToCommit(tag.SHA);
|
||||||
}
|
}
|
||||||
|
@ -272,18 +250,9 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnToggleTagFilter(object sender, RoutedEventArgs e)
|
private void OnToggleTagFilter(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is ToggleButton toggle)
|
if (sender is ToggleButton { DataContext: Models.Tag tag } toggle && DataContext is ViewModels.Repository repo)
|
||||||
{
|
{
|
||||||
var filter = string.Empty;
|
repo.UpdateFilter(tag.Name, toggle.IsChecked == true);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
@ -335,7 +304,7 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLeftSidebarDataGridPropertyChanged(object sender, AvaloniaPropertyChangedEventArgs e)
|
private void OnLeftSidebarDataGridPropertyChanged(object _, AvaloniaPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Property == DataGrid.ItemsSourceProperty || e.Property == DataGrid.IsVisibleProperty)
|
if (e.Property == DataGrid.ItemsSourceProperty || e.Property == DataGrid.IsVisibleProperty)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue