diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 65a3b493..816dbe15 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -1397,72 +1397,6 @@ - - - - - - - - + + - + - - - + + + + + + + + + + + + + + + + + + - + + - - - + - - - + + + + typeof(ToggleButton); + + protected override void OnPointerPressed(PointerPressedEventArgs e) + { + if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && + DataContext is ViewModels.RepositoryNode { IsRepository: false } node) + { + ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node); + } + + e.Handled = true; + } + } + public partial class Welcome : UserControl { public Welcome() @@ -15,9 +33,30 @@ namespace SourceGit.Views InitializeComponent(); } + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (!e.Handled) + { + if (e.Key == Key.Down && ViewModels.Welcome.Instance.Rows.Count > 0) + { + TreeContainer.SelectedIndex = 0; + TreeContainer.Focus(NavigationMethod.Directional); + e.Handled = true; + } + else if (e.Key == Key.F && + ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Meta)) || + (!OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Control)))) + { + SearchBox.Focus(); + } + } + } + private void SetupTreeViewDragAndDrop(object sender, RoutedEventArgs _) { - if (sender is TreeView view) + if (sender is ListBox view) { DragDrop.SetAllowDrop(view, true); view.AddHandler(DragDrop.DragOverEvent, DragOverTreeView); @@ -35,67 +74,25 @@ namespace SourceGit.Views } } - private void OnSearchBoxKeyDown(object sender, KeyEventArgs e) + private void OnTreeViewKeyDown(object sender, KeyEventArgs e) { - if (e.Key == Key.Down || e.Key == Key.FnDownArrow) + if (TreeContainer.SelectedItem is ViewModels.RepositoryNode node && e.Key == Key.Enter) { - var containers = ReposTree.GetRealizedContainers(); - if (containers == null) - return; - - foreach (var c in containers) + if (node.IsRepository) { - if (c is TreeViewItem { IsVisible: true } item) - { - ReposTree.SelectedItem = item.DataContext; - break; - } + var parent = this.FindAncestorOfType(); + if (parent is { DataContext: ViewModels.Launcher launcher }) + launcher.OpenRepositoryInTab(node, null); + } + else + { + ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node); } e.Handled = true; } } - private void OnTreeViewKeyDown(object sender, KeyEventArgs e) - { - if (ReposTree.SelectedItem is ViewModels.RepositoryNode node) - { - if (e.Key == Key.Space && node.IsRepository) - { - var parent = this.FindAncestorOfType(); - if (parent?.DataContext is ViewModels.Launcher launcher) - launcher.OpenRepositoryInTab(node, null); - - e.Handled = true; - } - else if (e.Key == Key.Down) - { - var next = ViewModels.Welcome.Instance.GetNextVisible(node); - if (next != null) - ReposTree.SelectedItem = next; - - e.Handled = true; - } - else if (e.Key == Key.Up) - { - var prev = ViewModels.Welcome.Instance.GetPrevVisible(node); - if (prev != null) - ReposTree.SelectedItem = prev; - - e.Handled = true; - } - } - } - - private void OnTreeViewSelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (ReposTree.SelectedItem is ViewModels.RepositoryNode node) - { - var item = FindTreeViewItemByNode(node, ReposTree); - item?.Focus(NavigationMethod.Directional); - } - } - private void OnTreeNodeContextRequested(object sender, ContextRequestedEventArgs e) { if (sender is Grid grid) @@ -256,16 +253,21 @@ namespace SourceGit.Views private void OnDoubleTappedTreeNode(object sender, TappedEventArgs e) { - var grid = sender as Grid; - var to = grid?.DataContext as ViewModels.RepositoryNode; - if (to is not { IsRepository: true }) - return; + if (sender is Grid { DataContext: ViewModels.RepositoryNode node }) + { + if (node.IsRepository) + { + var parent = this.FindAncestorOfType(); + if (parent is { DataContext: ViewModels.Launcher launcher }) + launcher.OpenRepositoryInTab(node, null); + } + else + { + ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node); + } - var parent = this.FindAncestorOfType(); - if (parent?.DataContext is ViewModels.Launcher launcher) - launcher.OpenRepositoryInTab(to, null); - - e.Handled = true; + e.Handled = true; + } } private void OpenOrInitRepository(string path, ViewModels.RepositoryNode parent = null) @@ -287,30 +289,12 @@ namespace SourceGit.Views var normalizedPath = root.Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, true); + ViewModels.Welcome.Instance.Refresh(); + var launcher = this.FindAncestorOfType()?.DataContext as ViewModels.Launcher; launcher?.OpenRepositoryInTab(node, launcher.ActivePage); } - private TreeViewItem FindTreeViewItemByNode(ViewModels.RepositoryNode node, ItemsControl container) - { - var items = container.GetRealizedContainers(); - - foreach (var item in items) - { - if (item is TreeViewItem { DataContext: ViewModels.RepositoryNode test } treeViewItem) - { - if (test == node) - return treeViewItem; - - var child = FindTreeViewItemByNode(node, treeViewItem); - if (child != null) - return child; - } - } - - return null; - } - private bool _pressedTreeNode = false; private Point _pressedTreeNodePosition = new Point(); private bool _startDragTreeNode = false; diff --git a/src/Views/WelcomeToolbar.axaml.cs b/src/Views/WelcomeToolbar.axaml.cs index 2f8de643..6c5e21d0 100644 --- a/src/Views/WelcomeToolbar.axaml.cs +++ b/src/Views/WelcomeToolbar.axaml.cs @@ -56,6 +56,8 @@ namespace SourceGit.Views var normalizedPath = root.Replace("\\", "/"); var node = ViewModels.Preference.Instance.FindOrAddNodeByRepositoryPath(normalizedPath, parent, false); + ViewModels.Welcome.Instance.Refresh(); + var launcher = this.FindAncestorOfType()?.DataContext as ViewModels.Launcher; launcher?.OpenRepositoryInTab(node, launcher.ActivePage); }