From 14001788d0197110e61dbb5eb6f21a73b384b7a5 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:26:47 +0900 Subject: [PATCH 1/5] Sidebar -> SideBar --- .../Data/Items/INavigationControlItem.cs | 4 +- .../UserControls/SideBar/ISideBarViewModel.cs | 10 ++-- .../UserControls/SideBar/ISidebarItemModel.cs | 4 +- .../UserControls/SideBar/SideBarControls.xaml | 12 ++-- .../SideBar/SideBarDisplayMode.cs | 10 ++-- .../UserControls/SideBar/SideBarItem.cs | 60 +++++++++---------- .../SideBar/SideBarItem.properties.cs | 40 ++++++------- .../UserControls/SideBar/SideBarResources.cs | 14 ----- .../SideBar/SideBarView.properties.cs | 34 +++++------ .../UserControls/SideBar/SideBarView.xaml | 2 +- .../UserControls/SideBar/SideBarView.xaml.cs | 46 +++++++------- .../SideBar/SidebarItemAutomationPeer.cs | 10 ++-- .../SideBar/SidebarItemDropPosition.cs | 6 +- .../SideBar/SidebarViewAutomationPeer.cs | 8 +-- .../UserControls/SidebarViewModel.cs | 18 +++--- src/Files.App/Views/MainPage.xaml | 6 +- src/Files.App/Views/MainPage.xaml.cs | 4 +- 17 files changed, 139 insertions(+), 149 deletions(-) delete mode 100644 src/Files.App/UserControls/SideBar/SideBarResources.cs diff --git a/src/Files.App/Data/Items/INavigationControlItem.cs b/src/Files.App/Data/Items/INavigationControlItem.cs index 6d3802161eb1..180fc01952f6 100644 --- a/src/Files.App/Data/Items/INavigationControlItem.cs +++ b/src/Files.App/Data/Items/INavigationControlItem.cs @@ -1,13 +1,13 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -using Files.App.UserControls.Sidebar; +using Files.App.UserControls.SideBar; using Microsoft.UI.Xaml.Controls; namespace Files.App.Data.Items { - public interface INavigationControlItem : IComparable, INotifyPropertyChanged, ISidebarItemModel + public interface INavigationControlItem : IComparable, INotifyPropertyChanged, ISideBarItemModel { public new string Text { get; } diff --git a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs index 45f56570ea0a..624f20ec0a5a 100644 --- a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs +++ b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs @@ -5,13 +5,13 @@ using Windows.ApplicationModel.DataTransfer; using Windows.Foundation; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public record ItemDroppedEventArgs(object DropTarget, DataPackageView DroppedItem, SidebarItemDropPosition dropPosition, DragEventArgs RawEvent) { } - public record ItemDragOverEventArgs(object DropTarget, DataPackageView DroppedItem, SidebarItemDropPosition dropPosition, DragEventArgs RawEvent) { } + public record ItemDroppedEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) { } + public record ItemDragOverEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) { } public record ItemContextInvokedArgs(object? Item, Point Position) { } - public interface ISidebarViewModel + public interface ISideBarViewModel { /// /// The source/list of items that will be rendered in the sidebar @@ -20,7 +20,7 @@ public interface ISidebarViewModel /// /// Gets invoked when the context was requested for an item in the sidebar. - /// Also applies when context was requested for the pane itsself. + /// Also applies when context was requested for the pane itself. /// /// The sender of this event /// The for this event. diff --git a/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs b/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs index 412df855803f..479626b0d74b 100644 --- a/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs +++ b/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs @@ -4,9 +4,9 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public interface ISidebarItemModel : INotifyPropertyChanged + public interface ISideBarItemModel : INotifyPropertyChanged { /// /// The children of this item that will be rendered as child elements of the SidebarItem diff --git a/src/Files.App/UserControls/SideBar/SideBarControls.xaml b/src/Files.App/UserControls/SideBar/SideBarControls.xaml index fb90cba3f753..8fc5b4e8933a 100644 --- a/src/Files.App/UserControls/SideBar/SideBarControls.xaml +++ b/src/Files.App/UserControls/SideBar/SideBarControls.xaml @@ -2,11 +2,10 @@ 300 @@ -40,17 +39,17 @@ - - + diff --git a/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs b/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs index 3ce0c62b1b71..f0dd2068911d 100644 --- a/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs +++ b/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs @@ -1,21 +1,23 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { /// - /// The display mode of the + /// The display mode of the /// - public enum SidebarDisplayMode + public enum SideBarDisplayMode { /// - /// The sidebar is hidden and moves in from the side when the is set to true. + /// The sidebar is hidden and moves in from the side when the is set to true. /// Minimal, + /// /// Only the icons of the top most sections are visible. /// Compact, + /// /// The sidebar is expanded and items can also be expanded. /// diff --git a/src/Files.App/UserControls/SideBar/SideBarItem.cs b/src/Files.App/UserControls/SideBar/SideBarItem.cs index e55f6e82c824..a2c3ef14048a 100644 --- a/src/Files.App/UserControls/SideBar/SideBarItem.cs +++ b/src/Files.App/UserControls/SideBar/SideBarItem.cs @@ -11,26 +11,26 @@ using System.Collections.Specialized; using Windows.ApplicationModel.DataTransfer; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public sealed partial class SidebarItem : Control + public sealed partial class SideBarItem : Control { private const double DROP_REPOSITION_THRESHOLD = 0.2; // Percentage of top/bottom at which we consider a drop to be a reposition/insertion public bool HasChildren => Item?.Children is IList enumerable && enumerable.Count > 0; public bool IsGroupHeader => Item?.Children is not null; - public bool CollapseEnabled => DisplayMode != SidebarDisplayMode.Compact; + public bool CollapseEnabled => DisplayMode != SideBarDisplayMode.Compact; private bool hasChildSelection => selectedChildItem != null; private bool isPointerOver = false; private bool isClicking = false; private object? selectedChildItem = null; private ItemsRepeater? childrenRepeater; - private ISidebarItemModel? lastSubscriber; + private ISideBarItemModel? lastSubscriber; - public SidebarItem() + public SideBarItem() { - DefaultStyleKey = typeof(SidebarItem); + DefaultStyleKey = typeof(SideBarItem); PointerReleased += Item_PointerReleased; KeyDown += (sender, args) => @@ -48,7 +48,7 @@ public SidebarItem() protected override AutomationPeer OnCreateAutomationPeer() { - return new SidebarItemAutomationPeer(this); + return new SideBarItemAutomationPeer(this); } internal void Select() @@ -114,22 +114,22 @@ private void HookupOwners() { resolvingTarget = element; } - Owner = resolvingTarget.FindAscendant()!; + Owner = resolvingTarget.FindAscendant()!; - Owner.RegisterPropertyChangedCallback(SidebarView.DisplayModeProperty, (sender, args) => + Owner.RegisterPropertyChangedCallback(SideBarView.DisplayModeProperty, (sender, args) => { DisplayMode = Owner.DisplayMode; }); DisplayMode = Owner.DisplayMode; - Owner.RegisterPropertyChangedCallback(SidebarView.SelectedItemProperty, (sender, args) => + Owner.RegisterPropertyChangedCallback(SideBarView.SelectedItemProperty, (sender, args) => { ReevaluateSelection(); }); ReevaluateSelection(); } - private void HookupItemChangeListener(ISidebarItemModel? oldItem, ISidebarItemModel? newItem) + private void HookupItemChangeListener(ISideBarItemModel? oldItem, ISideBarItemModel? newItem) { if (lastSubscriber != null) { @@ -178,7 +178,7 @@ private void ChildItems_CollectionChanged(object? sender, System.Collections.Spe { ReevaluateSelection(); UpdateExpansionState(); - if (DisplayMode == SidebarDisplayMode.Compact && !HasChildren) + if (DisplayMode == SideBarDisplayMode.Compact && !HasChildren) { SetFlyoutOpen(false); } @@ -186,7 +186,7 @@ private void ChildItems_CollectionChanged(object? sender, System.Collections.Spe void ItemPropertyChangedHandler(object? sender, PropertyChangedEventArgs args) { - if (args.PropertyName == nameof(ISidebarItemModel.IconSource)) + if (args.PropertyName == nameof(ISideBarItemModel.IconSource)) { UpdateIcon(); } @@ -219,18 +219,18 @@ private void ReevaluateSelection() private void ChildrenPresenter_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { - if (args.Element is SidebarItem item) + if (args.Element is SideBarItem item) { if (Item?.Children is IList enumerable) { var newElement = enumerable[args.Index]; if (newElement == selectedChildItem) { - (args.Element as SidebarItem)!.IsSelected = true; + (args.Element as SideBarItem)!.IsSelected = true; } else { - (args.Element as SidebarItem)!.IsSelected = false; + (args.Element as SideBarItem)!.IsSelected = false; } item.HandleItemChange(); } @@ -258,28 +258,28 @@ internal void RaiseItemInvoked() Owner?.RaiseItemInvoked(this); } - private void SidebarDisplayModeChanged(SidebarDisplayMode oldValue) + private void SidebarDisplayModeChanged(SideBarDisplayMode oldValue) { - var useAnimations = oldValue != SidebarDisplayMode.Minimal; + var useAnimations = oldValue != SideBarDisplayMode.Minimal; switch (DisplayMode) { - case SidebarDisplayMode.Expanded: + case SideBarDisplayMode.Expanded: UpdateExpansionState(useAnimations); UpdateSelectionState(); SetFlyoutOpen(false); break; - case SidebarDisplayMode.Minimal: + case SideBarDisplayMode.Minimal: UpdateExpansionState(useAnimations); SetFlyoutOpen(false); break; - case SidebarDisplayMode.Compact: + case SideBarDisplayMode.Compact: UpdateExpansionState(useAnimations); UpdateSelectionState(); break; } if (!IsInFlyout) { - VisualStateManager.GoToState(this, DisplayMode == SidebarDisplayMode.Compact ? "Compact" : "NonCompact", true); + VisualStateManager.GoToState(this, DisplayMode == SideBarDisplayMode.Compact ? "Compact" : "NonCompact", true); } } @@ -401,15 +401,15 @@ private void ItemGrid_DragOver(object sender, DragEventArgs e) } var insertsAbove = DetermineDropTargetPosition(e); - if (insertsAbove == SidebarItemDropPosition.Center) + if (insertsAbove == SideBarItemDropPosition.Center) { VisualStateManager.GoToState(this, "DragOnTop", true); } - else if (insertsAbove == SidebarItemDropPosition.Top) + else if (insertsAbove == SideBarItemDropPosition.Top) { VisualStateManager.GoToState(this, "DragInsertAbove", true); } - else if (insertsAbove == SidebarItemDropPosition.Bottom) + else if (insertsAbove == SideBarItemDropPosition.Bottom) { VisualStateManager.GoToState(this, "DragInsertBelow", true); } @@ -434,7 +434,7 @@ private void ItemGrid_Drop(object sender, DragEventArgs e) Owner?.RaiseItemDropped(this, DetermineDropTargetPosition(e), e); } - private SidebarItemDropPosition DetermineDropTargetPosition(DragEventArgs args) + private SideBarItemDropPosition DetermineDropTargetPosition(DragEventArgs args) { if (UseReorderDrop) { @@ -443,16 +443,16 @@ private SidebarItemDropPosition DetermineDropTargetPosition(DragEventArgs args) var position = args.GetPosition(grid); if (position.Y < grid.ActualHeight * DROP_REPOSITION_THRESHOLD) { - return SidebarItemDropPosition.Top; + return SideBarItemDropPosition.Top; } if (position.Y > grid.ActualHeight * (1 - DROP_REPOSITION_THRESHOLD)) { - return SidebarItemDropPosition.Bottom; + return SideBarItemDropPosition.Bottom; } - return SidebarItemDropPosition.Center; + return SideBarItemDropPosition.Center; } } - return SidebarItemDropPosition.Center; + return SideBarItemDropPosition.Center; } } } diff --git a/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs b/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs index ebf990107ff3..f3e0ab667df5 100644 --- a/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs +++ b/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs @@ -4,17 +4,17 @@ using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public sealed partial class SidebarItem : Control + public sealed partial class SideBarItem : Control { - public SidebarView? Owner + public SideBarView? Owner { - get { return (SidebarView?)GetValue(OwnerProperty); } + get { return (SideBarView?)GetValue(OwnerProperty); } set { SetValue(OwnerProperty, value); } } public static readonly DependencyProperty OwnerProperty = - DependencyProperty.Register(nameof(Owner), typeof(SidebarView), typeof(SidebarItem), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Owner), typeof(SideBarView), typeof(SideBarItem), new PropertyMetadata(null)); public bool IsSelected { @@ -22,7 +22,7 @@ public bool IsSelected set { SetValue(IsSelectedProperty, value); } } public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged)); + DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false, OnPropertyChanged)); public bool IsExpanded { @@ -30,7 +30,7 @@ public bool IsExpanded set { SetValue(IsExpandedProperty, value); } } public static readonly DependencyProperty IsExpandedProperty = - DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged)); + DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SideBarItem), new PropertyMetadata(true, OnPropertyChanged)); public bool IsInFlyout { @@ -38,7 +38,7 @@ public bool IsInFlyout set { SetValue(IsInFlyoutProperty, value); } } public static readonly DependencyProperty IsInFlyoutProperty = - DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false)); + DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false)); public double ChildrenPresenterHeight { @@ -47,15 +47,15 @@ public double ChildrenPresenterHeight } // Using 30 as a default in case something goes wrong public static readonly DependencyProperty ChildrenPresenterHeightProperty = - DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SidebarItem), new PropertyMetadata(30d)); + DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SideBarItem), new PropertyMetadata(30d)); - public ISidebarItemModel? Item + public ISideBarItemModel? Item { - get { return (ISidebarItemModel)GetValue(ItemProperty); } + get { return (ISideBarItemModel)GetValue(ItemProperty); } set { SetValue(ItemProperty, value); } } public static readonly DependencyProperty ItemProperty = - DependencyProperty.Register(nameof(Item), typeof(ISidebarItemModel), typeof(SidebarItem), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Item), typeof(ISideBarItemModel), typeof(SideBarItem), new PropertyMetadata(null)); public bool UseReorderDrop { @@ -63,7 +63,7 @@ public bool UseReorderDrop set { SetValue(UseReorderDropProperty, value); } } public static readonly DependencyProperty UseReorderDropProperty = - DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false)); + DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false)); public FrameworkElement? Icon { @@ -71,7 +71,7 @@ public FrameworkElement? Icon set { SetValue(IconProperty, value); } } public static readonly DependencyProperty IconProperty = - DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SideBarItem), new PropertyMetadata(null)); public FrameworkElement? Decorator { @@ -79,15 +79,15 @@ public FrameworkElement? Decorator set { SetValue(DecoratorProperty, value); } } public static readonly DependencyProperty DecoratorProperty = - DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SideBarItem), new PropertyMetadata(null)); - public SidebarDisplayMode DisplayMode + public SideBarDisplayMode DisplayMode { - get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); } + get { return (SideBarDisplayMode)GetValue(DisplayModeProperty); } set { SetValue(DisplayModeProperty, value); } } public static readonly DependencyProperty DisplayModeProperty = - DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarItem), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged)); + DependencyProperty.Register(nameof(DisplayMode), typeof(SideBarDisplayMode), typeof(SideBarItem), new PropertyMetadata(SideBarDisplayMode.Expanded, OnPropertyChanged)); public static void SetTemplateRoot(DependencyObject target, FrameworkElement value) { @@ -102,10 +102,10 @@ public static FrameworkElement GetTemplateRoot(DependencyObject target) public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { - if (sender is not SidebarItem item) return; + if (sender is not SideBarItem item) return; if (e.Property == DisplayModeProperty) { - item.SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue); + item.SidebarDisplayModeChanged((SideBarDisplayMode)e.OldValue); } else if (e.Property == IsSelectedProperty) { diff --git a/src/Files.App/UserControls/SideBar/SideBarResources.cs b/src/Files.App/UserControls/SideBar/SideBarResources.cs deleted file mode 100644 index 95851b0168d6..000000000000 --- a/src/Files.App/UserControls/SideBar/SideBarResources.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2023 Files Community -// Licensed under the MIT License. See the LICENSE. - -using Microsoft.UI.Xaml; - -namespace Files.App.UserControls.Sidebar -{ - /// - /// Backing dictionary for Sidebar Resources to support x:Bind - /// - partial class SidebarResources : ResourceDictionary - { - } -} diff --git a/src/Files.App/UserControls/SideBar/SideBarView.properties.cs b/src/Files.App/UserControls/SideBar/SideBarView.properties.cs index 9693af74871f..28a00ca2a48c 100644 --- a/src/Files.App/UserControls/SideBar/SideBarView.properties.cs +++ b/src/Files.App/UserControls/SideBar/SideBarView.properties.cs @@ -3,17 +3,17 @@ using Microsoft.UI.Xaml; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public sealed partial class SidebarView + public sealed partial class SideBarView { - public SidebarDisplayMode DisplayMode + public SideBarDisplayMode DisplayMode { - get { return (SidebarDisplayMode)GetValue(DisplayModeProperty); } + get { return (SideBarDisplayMode)GetValue(DisplayModeProperty); } set { SetValue(DisplayModeProperty, value); } } public static readonly DependencyProperty DisplayModeProperty = - DependencyProperty.Register(nameof(DisplayMode), typeof(SidebarDisplayMode), typeof(SidebarView), new PropertyMetadata(SidebarDisplayMode.Expanded, OnPropertyChanged)); + DependencyProperty.Register(nameof(DisplayMode), typeof(SideBarDisplayMode), typeof(SideBarView), new PropertyMetadata(SideBarDisplayMode.Expanded, OnPropertyChanged)); public UIElement InnerContent { @@ -21,7 +21,7 @@ public UIElement InnerContent set { SetValue(InnerContentProperty, value); } } public static readonly DependencyProperty InnerContentProperty = - DependencyProperty.Register(nameof(InnerContent), typeof(UIElement), typeof(SidebarView), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(InnerContent), typeof(UIElement), typeof(SideBarView), new PropertyMetadata(null)); public UIElement Footer { @@ -29,7 +29,7 @@ public UIElement Footer set { SetValue(FooterProperty, value); } } public static readonly DependencyProperty FooterProperty = - DependencyProperty.Register("Footer", typeof(UIElement), typeof(SidebarView), new PropertyMetadata(null)); + DependencyProperty.Register("Footer", typeof(UIElement), typeof(SideBarView), new PropertyMetadata(null)); public bool IsPaneOpen { @@ -37,7 +37,7 @@ public bool IsPaneOpen set { SetValue(IsPaneOpenProperty, value); } } public static readonly DependencyProperty IsPaneOpenProperty = - DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(SidebarView), new PropertyMetadata(false, OnPropertyChanged)); + DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(SideBarView), new PropertyMetadata(false, OnPropertyChanged)); public double OpenPaneLength { @@ -49,7 +49,7 @@ public double OpenPaneLength } } public static readonly DependencyProperty OpenPaneLengthProperty = - DependencyProperty.Register(nameof(OpenPaneLength), typeof(double), typeof(SidebarView), new PropertyMetadata(240d, OnPropertyChanged)); + DependencyProperty.Register(nameof(OpenPaneLength), typeof(double), typeof(SideBarView), new PropertyMetadata(240d, OnPropertyChanged)); public double NegativeOpenPaneLength { @@ -57,30 +57,30 @@ public double NegativeOpenPaneLength set { SetValue(NegativeOpenPaneLengthProperty, value); } } public static readonly DependencyProperty NegativeOpenPaneLengthProperty = - DependencyProperty.Register(nameof(NegativeOpenPaneLength), typeof(double), typeof(SidebarView), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(NegativeOpenPaneLength), typeof(double), typeof(SideBarView), new PropertyMetadata(null)); - public ISidebarViewModel ViewModel + public ISideBarViewModel ViewModel { - get => (ISidebarViewModel)GetValue(ViewModelProperty); + get => (ISideBarViewModel)GetValue(ViewModelProperty); set => SetValue(ViewModelProperty, value); } public static readonly DependencyProperty ViewModelProperty = - DependencyProperty.Register(nameof(ViewModel), typeof(ISidebarViewModel), typeof(SidebarView), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(ViewModel), typeof(ISideBarViewModel), typeof(SideBarView), new PropertyMetadata(null)); - public ISidebarItemModel SelectedItem + public ISideBarItemModel SelectedItem { - get => (ISidebarItemModel)GetValue(SelectedItemProperty); + get => (ISideBarItemModel)GetValue(SelectedItemProperty); set { SetValue(SelectedItemProperty, value); } } public static readonly DependencyProperty SelectedItemProperty = - DependencyProperty.Register(nameof(SelectedItem), typeof(ISidebarItemModel), typeof(SidebarView), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(SelectedItem), typeof(ISideBarItemModel), typeof(SideBarView), new PropertyMetadata(null)); public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { - if (sender is not SidebarView control) return; + if (sender is not SideBarView control) return; if (e.Property == OpenPaneLengthProperty) { diff --git a/src/Files.App/UserControls/SideBar/SideBarView.xaml b/src/Files.App/UserControls/SideBar/SideBarView.xaml index 7f9cc8d5c8ce..57d8c4c1f366 100644 --- a/src/Files.App/UserControls/SideBar/SideBarView.xaml +++ b/src/Files.App/UserControls/SideBar/SideBarView.xaml @@ -1,6 +1,6 @@  ? ItemContextInvoked; public event PropertyChangedEventHandler? PropertyChanged; - internal SidebarItem? SelectedItemContainer = null; + internal SideBarItem? SelectedItemContainer = null; private bool draggingSidebarResizer; private double preManipulationSidebarWidth = 0; - public SidebarView() + public SideBarView() { InitializeComponent(); } - internal void UpdateSelectedItemContainer(SidebarItem container) + internal void UpdateSelectedItemContainer(SideBarItem container) { SelectedItemContainer = container; } - internal void RaiseItemInvoked(SidebarItem item) + internal void RaiseItemInvoked(SideBarItem item) { // Only leaves can be selected if (item.Item is null || item.IsGroupHeader) return; @@ -49,20 +49,20 @@ internal void RaiseItemInvoked(SidebarItem item) ViewModel.HandleItemInvoked(item.Item); } - internal void RaiseContextRequested(SidebarItem item, Point e) + internal void RaiseContextRequested(SideBarItem item, Point e) { ItemContextInvoked?.Invoke(item, new ItemContextInvokedArgs(item.Item, e)); ViewModel.HandleItemContextInvoked(item, new ItemContextInvokedArgs(item.Item, e)); } - internal void RaiseItemDropped(SidebarItem sideBarItem, SidebarItemDropPosition dropPosition, DragEventArgs rawEvent) + internal void RaiseItemDropped(SideBarItem sideBarItem, SideBarItemDropPosition dropPosition, DragEventArgs rawEvent) { if (sideBarItem.Item is null) return; ItemDropped?.Invoke(sideBarItem, new ItemDroppedEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); ViewModel.HandleItemDropped(new ItemDroppedEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); } - internal void RaiseItemDragOver(SidebarItem sideBarItem, SidebarItemDropPosition dropPosition, DragEventArgs rawEvent) + internal void RaiseItemDragOver(SideBarItem sideBarItem, SideBarItemDropPosition dropPosition, DragEventArgs rawEvent) { if (sideBarItem.Item is null) return; ItemDragOver?.Invoke(sideBarItem, new ItemDragOverEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); @@ -71,7 +71,7 @@ internal void RaiseItemDragOver(SidebarItem sideBarItem, SidebarItemDropPosition private void UpdateMinimalMode() { - if (DisplayMode != SidebarDisplayMode.Minimal) return; + if (DisplayMode != SideBarDisplayMode.Minimal) return; if (IsPaneOpen) { @@ -87,13 +87,13 @@ private void UpdateDisplayMode() { switch (DisplayMode) { - case SidebarDisplayMode.Compact: + case SideBarDisplayMode.Compact: VisualStateManager.GoToState(this, "Compact", true); return; - case SidebarDisplayMode.Expanded: + case SideBarDisplayMode.Expanded: VisualStateManager.GoToState(this, "Expanded", true); return; - case SidebarDisplayMode.Minimal: + case SideBarDisplayMode.Minimal: IsPaneOpen = false; UpdateMinimalMode(); return; @@ -104,11 +104,11 @@ private void UpdateDisplayModeForPaneWidth(double newPaneWidth) { if (newPaneWidth < COMPACT_MAX_WIDTH) { - DisplayMode = SidebarDisplayMode.Compact; + DisplayMode = SideBarDisplayMode.Compact; } else if (newPaneWidth > COMPACT_MAX_WIDTH) { - DisplayMode = SidebarDisplayMode.Expanded; + DisplayMode = SideBarDisplayMode.Expanded; OpenPaneLength = newPaneWidth; } } @@ -143,11 +143,11 @@ private void SidebarResizer_ManipulationDelta(object sender, ManipulationDeltaRo private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e) { var primaryInvocation = e.Key == VirtualKey.Space || e.Key == VirtualKey.Enter; - if (DisplayMode == SidebarDisplayMode.Expanded) + if (DisplayMode == SideBarDisplayMode.Expanded) { if (primaryInvocation) { - DisplayMode = SidebarDisplayMode.Compact; + DisplayMode = SideBarDisplayMode.Compact; return; } @@ -164,11 +164,11 @@ private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e) e.Handled = true; return; } - else if (DisplayMode == SidebarDisplayMode.Compact) + else if (DisplayMode == SideBarDisplayMode.Compact) { if (primaryInvocation || e.Key == VirtualKey.Right) { - DisplayMode = SidebarDisplayMode.Expanded; + DisplayMode = SideBarDisplayMode.Expanded; e.Handled = true; } } @@ -188,14 +188,14 @@ private void PaneLightDismissLayer_Tapped(object sender, TappedRoutedEventArgs e private void SidebarResizer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { - if (DisplayMode == SidebarDisplayMode.Expanded) + if (DisplayMode == SideBarDisplayMode.Expanded) { - DisplayMode = SidebarDisplayMode.Compact; + DisplayMode = SideBarDisplayMode.Compact; e.Handled = true; } else { - DisplayMode = SidebarDisplayMode.Expanded; + DisplayMode = SideBarDisplayMode.Expanded; e.Handled = true; } } @@ -235,7 +235,7 @@ private void PaneColumnGrid_ContextRequested(UIElement sender, ContextRequestedE private void MenuItemsHost_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { - if(args.Element is SidebarItem sidebarItem) + if(args.Element is SideBarItem sidebarItem) { sidebarItem.HandleItemChange(); } diff --git a/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs b/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs index 4a981d0ea8b1..6acca5b71764 100644 --- a/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs +++ b/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs @@ -6,9 +6,9 @@ using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - public class SidebarItemAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IExpandCollapseProvider, ISelectionItemProvider + public class SideBarItemAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IExpandCollapseProvider, ISelectionItemProvider { public ExpandCollapseState ExpandCollapseState { @@ -22,9 +22,9 @@ public ExpandCollapseState ExpandCollapseState public bool IsSelected => Owner.IsSelected; public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner)); - private new SidebarItem Owner { get; init; } + private new SideBarItem Owner { get; init; } - public SidebarItemAutomationPeer(SidebarItem owner) : base(owner) + public SideBarItemAutomationPeer(SideBarItem owner) : base(owner) { this.Owner = owner; } @@ -104,7 +104,7 @@ protected override int GetPositionInSetCore() private IList GetOwnerCollection() { - if (Owner.FindAscendant() is SidebarItem parent && parent.Item?.Children is IList list) + if (Owner.FindAscendant() is SideBarItem parent && parent.Item?.Children is IList list) { return list; } diff --git a/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs b/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs index d9fc1d760def..6507fa26bfc6 100644 --- a/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs +++ b/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs @@ -1,21 +1,23 @@ // Copyright (c) 2023 Files Community // Licensed under the MIT License. See the LICENSE. -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { /// /// The position of the item that was dropped on the sidebar item. /// - public enum SidebarItemDropPosition + public enum SideBarItemDropPosition { /// /// The item was dropped on the top of the sidebar item indicating it should be moved/inserted above this item. /// Top, + /// /// The item was dropped on the bottom of the sidebar item indicating it should be moved/inserted below this item. /// Bottom, + /// /// The item was dropped on the center of the sidebar item indicating it should be moved/inserted as a child of this item. /// diff --git a/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs b/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs index 279782dc62cd..f0ac435787b0 100644 --- a/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs +++ b/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs @@ -4,16 +4,16 @@ using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; -namespace Files.App.UserControls.Sidebar +namespace Files.App.UserControls.SideBar { - class SidebarViewAutomationPeer : FrameworkElementAutomationPeer, ISelectionProvider + class SideBarViewAutomationPeer : FrameworkElementAutomationPeer, ISelectionProvider { public bool CanSelectMultiple => false; public bool IsSelectionRequired => true; - private new SidebarView Owner { get; init; } + private new SideBarView Owner { get; init; } - public SidebarViewAutomationPeer(SidebarView owner) : base(owner) + public SideBarViewAutomationPeer(SideBarView owner) : base(owner) { Owner = owner; } diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index dd2315384b3d..b69d93a57b56 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -2,7 +2,7 @@ // Licensed under the MIT License. See the LICENSE. using Files.App.Helpers.ContextFlyouts; -using Files.App.UserControls.Sidebar; +using Files.App.UserControls.SideBar; using Files.App.ViewModels.Dialogs; using Microsoft.UI.Input; using Microsoft.UI.Xaml; @@ -22,7 +22,7 @@ namespace Files.App.ViewModels.UserControls { - public class SidebarViewModel : ObservableObject, IDisposable, ISidebarViewModel + public class SidebarViewModel : ObservableObject, IDisposable, ISideBarViewModel { private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); private ICommandManager Commands { get; } = Ioc.Default.GetRequiredService(); @@ -51,18 +51,18 @@ public IFilesystemHelpers FilesystemHelpers public SidebarPinnedModel SidebarPinnedModel => App.QuickAccessManager.Model; public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService(); - private SidebarDisplayMode sidebarDisplayMode; - public SidebarDisplayMode SidebarDisplayMode + private SideBarDisplayMode sidebarDisplayMode; + public SideBarDisplayMode SidebarDisplayMode { get => sidebarDisplayMode; set { // We only want to track non minimal mode - if (value == SidebarDisplayMode.Minimal) return; + if (value == SideBarDisplayMode.Minimal) return; if (SetProperty(ref sidebarDisplayMode, value)) { OnPropertyChanged(nameof(IsSidebarCompactSize)); - IsSidebarOpen = sidebarDisplayMode == SidebarDisplayMode.Expanded; + IsSidebarOpen = sidebarDisplayMode == SideBarDisplayMode.Expanded; UpdateTabControlMargin(); } } @@ -86,7 +86,7 @@ public SidebarDisplayMode SidebarDisplayMode }; public bool IsSidebarCompactSize - => SidebarDisplayMode == SidebarDisplayMode.Compact || SidebarDisplayMode == SidebarDisplayMode.Minimal; + => SidebarDisplayMode == SideBarDisplayMode.Compact || SidebarDisplayMode == SideBarDisplayMode.Minimal; public void NotifyInstanceRelatedPropertiesChanged(string arg) { @@ -254,7 +254,7 @@ public SidebarViewModel() networkDrivesViewModel.Drives.CollectionChanged += (x, args) => Manager_DataChanged(SectionType.Network, args); App.WSLDistroManager.DataChanged += Manager_DataChanged; App.FileTagsManager.DataChanged += Manager_DataChanged; - SidebarDisplayMode = UserSettingsService.AppearanceSettingsService.IsSidebarOpen ? SidebarDisplayMode.Expanded : SidebarDisplayMode.Compact; + SidebarDisplayMode = UserSettingsService.AppearanceSettingsService.IsSidebarOpen ? SideBarDisplayMode.Expanded : SideBarDisplayMode.Compact; HideSectionCommand = new RelayCommand(HideSection); UnpinItemCommand = new RelayCommand(UnpinItem); @@ -656,7 +656,7 @@ public void UpdateTabControlMargin() TabControlMargin = SidebarDisplayMode switch { // This prevents the pane toggle button from overlapping the tab control in minimal mode - SidebarDisplayMode.Minimal => new GridLength(44, GridUnitType.Pixel), + SideBarDisplayMode.Minimal => new GridLength(44, GridUnitType.Pixel), _ => new GridLength(0, GridUnitType.Pixel), }; } diff --git a/src/Files.App/Views/MainPage.xaml b/src/Files.App/Views/MainPage.xaml index 77b851b26a13..bba018563bb8 100644 --- a/src/Files.App/Views/MainPage.xaml +++ b/src/Files.App/Views/MainPage.xaml @@ -8,7 +8,7 @@ xmlns:i="using:Microsoft.Xaml.Interactivity" xmlns:icore="using:Microsoft.Xaml.Interactions.Core" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:sidebar="using:Files.App.UserControls.Sidebar" + xmlns:sidebar="using:Files.App.UserControls.SideBar" xmlns:tabbar="using:Files.App.UserControls.TabBar" xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls" xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers" @@ -198,7 +198,7 @@ - - + diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index 4546a5f78837..d1db24e15e7a 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -4,7 +4,7 @@ using CommunityToolkit.WinUI.Helpers; using CommunityToolkit.WinUI.UI; using CommunityToolkit.WinUI.UI.Controls; -using Files.App.UserControls.Sidebar; +using Files.App.UserControls.SideBar; using Microsoft.Extensions.Logging; using Microsoft.UI.Dispatching; using Microsoft.UI.Input; @@ -489,7 +489,7 @@ private void PaneSplitter_ManipulationStarted(object sender, ManipulationStarted private void TogglePaneButton_Click(object sender, RoutedEventArgs e) { - if (SidebarControl.DisplayMode == SidebarDisplayMode.Minimal) + if (SidebarControl.DisplayMode == SideBarDisplayMode.Minimal) { SidebarControl.IsPaneOpen = !SidebarControl.IsPaneOpen; } From a01a3795a17202aa4fee31441f2d9c0e9a52df03 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:31:28 +0900 Subject: [PATCH 2/5] Corrected license header --- src/Files.App/App.xaml | 2 +- src/Files.App/UserControls/SideBar/SideBarItem.cs | 4 ++-- .../SideBar/{SideBarControls.xaml => SideBarStyles.xaml} | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) rename src/Files.App/UserControls/SideBar/{SideBarControls.xaml => SideBarStyles.xaml} (98%) diff --git a/src/Files.App/App.xaml b/src/Files.App/App.xaml index 51f0b13ff276..0ee92a313b65 100644 --- a/src/Files.App/App.xaml +++ b/src/Files.App/App.xaml @@ -31,7 +31,7 @@ - + diff --git a/src/Files.App/UserControls/SideBar/SideBarItem.cs b/src/Files.App/UserControls/SideBar/SideBarItem.cs index a2c3ef14048a..ff78207654d6 100644 --- a/src/Files.App/UserControls/SideBar/SideBarItem.cs +++ b/src/Files.App/UserControls/SideBar/SideBarItem.cs @@ -1,5 +1,5 @@ -// Copyright (c) Microsoft Corporation and Contributors. -// Licensed under the MIT License. +// Copyright (c) 2023 Files Community +// Licensed under the MIT License. See the LICENSE. using CommunityToolkit.WinUI.UI; using Microsoft.UI.Input; diff --git a/src/Files.App/UserControls/SideBar/SideBarControls.xaml b/src/Files.App/UserControls/SideBar/SideBarStyles.xaml similarity index 98% rename from src/Files.App/UserControls/SideBar/SideBarControls.xaml rename to src/Files.App/UserControls/SideBar/SideBarStyles.xaml index 8fc5b4e8933a..eb3b4670c641 100644 --- a/src/Files.App/UserControls/SideBar/SideBarControls.xaml +++ b/src/Files.App/UserControls/SideBar/SideBarStyles.xaml @@ -1,6 +1,4 @@ - - - + @@ -199,7 +197,7 @@ x:Name="ChildrenPresenter" Grid.Row="2" HorizontalAlignment="Stretch" - local:SidebarItem.TemplateRoot="{Binding ElementName=RootPanel}" + local:SideBarItem.TemplateRoot="{Binding ElementName=RootPanel}" AutomationProperties.AccessibilityView="Content" ItemTemplate="{StaticResource DefaultSidebarItemTemplate}" ItemsSource="{Binding Children, Mode=OneWay}" From 9c618712e34c0babecf702248eec0c7d771049f2 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:54:24 +0900 Subject: [PATCH 3/5] Chore: Refactored --- .../UserControls/SideBar/ISideBarViewModel.cs | 19 ++- .../UserControls/SideBar/ISidebarItemModel.cs | 14 +- .../SideBar/SideBarDisplayMode.cs | 26 ---- .../UserControls/SideBar/SideBarItem.cs | 124 +++++++++------- .../SideBar/SideBarItem.properties.cs | 133 ++++++++++++------ .../SideBar/SideBarPaneDisplayMode.cs | 28 ++++ .../SideBar/SideBarView.properties.cs | 91 ++++++++---- .../UserControls/SideBar/SideBarView.xaml | 8 +- .../UserControls/SideBar/SideBarView.xaml.cs | 72 ++++++---- .../SideBar/SidebarItemAutomationPeer.cs | 23 ++- .../SideBar/SidebarItemDropPosition.cs | 8 +- .../SideBar/SidebarViewAutomationPeer.cs | 19 ++- .../UserControls/SidebarViewModel.cs | 14 +- src/Files.App/Views/MainPage.xaml.cs | 2 +- 14 files changed, 360 insertions(+), 221 deletions(-) delete mode 100644 src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs create mode 100644 src/Files.App/UserControls/SideBar/SideBarPaneDisplayMode.cs diff --git a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs index 624f20ec0a5a..8fdc525da9e8 100644 --- a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs +++ b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs @@ -7,14 +7,25 @@ namespace Files.App.UserControls.SideBar { - public record ItemDroppedEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) { } - public record ItemDragOverEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) { } - public record ItemContextInvokedArgs(object? Item, Point Position) { } + public record ItemDroppedEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) + { + } + + public record ItemDragOverEventArgs(object DropTarget, DataPackageView DroppedItem, SideBarItemDropPosition dropPosition, DragEventArgs RawEvent) + { + } + + public record ItemContextInvokedArgs(object? Item, Point Position) + { + } + /// + /// Represents interface for . + /// public interface ISideBarViewModel { /// - /// The source/list of items that will be rendered in the sidebar + /// Gets the source/list of items that will be rendered in the sidebar /// object SidebarItems { get; } diff --git a/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs b/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs index 479626b0d74b..7b1e17fb533b 100644 --- a/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs +++ b/src/Files.App/UserControls/SideBar/ISidebarItemModel.cs @@ -9,33 +9,33 @@ namespace Files.App.UserControls.SideBar public interface ISideBarItemModel : INotifyPropertyChanged { /// - /// The children of this item that will be rendered as child elements of the SidebarItem + /// Gets the children of this item that will be rendered as child elements of the /// object? Children { get; } /// - /// The icon source used to generate the icon for the SidebarItem + /// Gets the icon source used to generate the icon for the /// IconSource? IconSource { get; } /// - /// Item decorator for the given item. + /// Gets the item decorator for the given item. /// FrameworkElement? ItemDecorator { get => null; } /// - /// Determines whether the SidebarItem is expanded and the children are visible - /// or if it is collapsed and children are not visible. + /// Gets or sets a value that indicates whether the is expanded + /// and the children are visible, or if it is collapsed and children are not visible. /// bool IsExpanded { get; set; } /// - /// The text of this item that will be rendered as the label of the SidebarItem + /// Gets the text of this item that will be rendered as the label of the SidebarItem. /// string Text { get; } /// - /// The tooltip used when hovering over this item in the sidebar + /// Gets the tooltip used when hovering over this item in the sidebar. /// object ToolTip { get; } } diff --git a/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs b/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs deleted file mode 100644 index f0dd2068911d..000000000000 --- a/src/Files.App/UserControls/SideBar/SideBarDisplayMode.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2023 Files Community -// Licensed under the MIT License. See the LICENSE. - -namespace Files.App.UserControls.SideBar -{ - /// - /// The display mode of the - /// - public enum SideBarDisplayMode - { - /// - /// The sidebar is hidden and moves in from the side when the is set to true. - /// - Minimal, - - /// - /// Only the icons of the top most sections are visible. - /// - Compact, - - /// - /// The sidebar is expanded and items can also be expanded. - /// - Expanded - } -} diff --git a/src/Files.App/UserControls/SideBar/SideBarItem.cs b/src/Files.App/UserControls/SideBar/SideBarItem.cs index ff78207654d6..fa3d72632f10 100644 --- a/src/Files.App/UserControls/SideBar/SideBarItem.cs +++ b/src/Files.App/UserControls/SideBar/SideBarItem.cs @@ -13,19 +13,34 @@ namespace Files.App.UserControls.SideBar { + /// + /// Represents for item. + /// public sealed partial class SideBarItem : Control { - private const double DROP_REPOSITION_THRESHOLD = 0.2; // Percentage of top/bottom at which we consider a drop to be a reposition/insertion + // Percentage of top/bottom at which we consider a drop to be a reposition/insertion + private const double DROP_REPOSITION_THRESHOLD = 0.2; - public bool HasChildren => Item?.Children is IList enumerable && enumerable.Count > 0; - public bool IsGroupHeader => Item?.Children is not null; - public bool CollapseEnabled => DisplayMode != SideBarDisplayMode.Compact; + public bool HasChildren + => Item?.Children is IList enumerable && enumerable.Count > 0; + + public bool IsGroupHeader + => Item?.Children is not null; + + public bool CollapseEnabled + => DisplayMode != SideBarPaneDisplayMode.Compact; + + private bool hasChildSelection + => selectedChildItem != null; - private bool hasChildSelection => selectedChildItem != null; private bool isPointerOver = false; + private bool isClicking = false; + private object? selectedChildItem = null; + private ItemsRepeater? childrenRepeater; + private ISideBarItemModel? lastSubscriber; public SideBarItem() @@ -33,6 +48,7 @@ public SideBarItem() DefaultStyleKey = typeof(SideBarItem); PointerReleased += Item_PointerReleased; + KeyDown += (sender, args) => { if (args.Key == Windows.System.VirtualKey.Enter) @@ -41,6 +57,7 @@ public SideBarItem() args.Handled = true; } }; + DragStarting += SidebarItem_DragStarting; Loaded += SidebarItem_Loaded; @@ -81,6 +98,7 @@ private void SidebarItem_Loaded(object sender, RoutedEventArgs e) repeater.ElementPrepared += ChildrenPresenter_ElementPrepared; repeater.SizeChanged += ChildrenPresenter_SizeChanged; } + if (GetTemplateChild("FlyoutChildrenPresenter") is ItemsRepeater flyoutRepeater) { flyoutRepeater.ElementPrepared += ChildrenPresenter_ElementPrepared; @@ -110,22 +128,26 @@ private void ChildrenPresenter_SizeChanged(object sender, SizeChangedEventArgs e private void HookupOwners() { FrameworkElement resolvingTarget = this; + if (GetTemplateRoot(Parent) is FrameworkElement element) { resolvingTarget = element; } + Owner = resolvingTarget.FindAscendant()!; Owner.RegisterPropertyChangedCallback(SideBarView.DisplayModeProperty, (sender, args) => { DisplayMode = Owner.DisplayMode; }); + DisplayMode = Owner.DisplayMode; Owner.RegisterPropertyChangedCallback(SideBarView.SelectedItemProperty, (sender, args) => { ReevaluateSelection(); }); + ReevaluateSelection(); } @@ -134,6 +156,7 @@ private void HookupItemChangeListener(ISideBarItemModel? oldItem, ISideBarItemMo if (lastSubscriber != null) { lastSubscriber.PropertyChanged -= ItemPropertyChangedHandler; + if (lastSubscriber.Children is INotifyCollectionChanged observableCollection) observableCollection.CollectionChanged -= ChildItems_CollectionChanged; } @@ -141,6 +164,7 @@ private void HookupItemChangeListener(ISideBarItemModel? oldItem, ISideBarItemMo if (oldItem != null) { oldItem.PropertyChanged -= ItemPropertyChangedHandler; + if (oldItem.Children is INotifyCollectionChanged observableCollection) observableCollection.CollectionChanged -= ChildItems_CollectionChanged; } @@ -148,9 +172,11 @@ private void HookupItemChangeListener(ISideBarItemModel? oldItem, ISideBarItemMo { newItem.PropertyChanged += ItemPropertyChangedHandler; lastSubscriber = newItem; + if (newItem.Children is INotifyCollectionChanged observableCollection) observableCollection.CollectionChanged += ChildItems_CollectionChanged; } + UpdateIcon(); } @@ -161,9 +187,11 @@ private void SidebarItem_DragStarting(UIElement sender, DragStartingEventArgs ar private void SetFlyoutOpen(bool isOpen = true) { - if (Item?.Children is null) return; + if (Item?.Children is null) + return; var flyoutOwner = (GetTemplateChild("ElementGrid") as FrameworkElement)!; + if (isOpen) { FlyoutBase.ShowAttachedFlyout(flyoutOwner); @@ -178,18 +206,15 @@ private void ChildItems_CollectionChanged(object? sender, System.Collections.Spe { ReevaluateSelection(); UpdateExpansionState(); - if (DisplayMode == SideBarDisplayMode.Compact && !HasChildren) - { + + if (DisplayMode == SideBarPaneDisplayMode.Compact && !HasChildren) SetFlyoutOpen(false); - } } void ItemPropertyChangedHandler(object? sender, PropertyChangedEventArgs args) { if (args.PropertyName == nameof(ISideBarItemModel.IconSource)) - { UpdateIcon(); - } } private void ReevaluateSelection() @@ -198,9 +223,7 @@ private void ReevaluateSelection() { IsSelected = Item == Owner?.SelectedItem; if (IsSelected) - { Owner?.UpdateSelectedItemContainer(this); - } } else if (Item?.Children is IList list) { @@ -213,6 +236,7 @@ private void ReevaluateSelection() { selectedChildItem = null; } + UpdateSelectionState(); } } @@ -224,14 +248,12 @@ private void ChildrenPresenter_ElementPrepared(ItemsRepeater sender, ItemsRepeat if (Item?.Children is IList enumerable) { var newElement = enumerable[args.Index]; + if (newElement == selectedChildItem) - { (args.Element as SideBarItem)!.IsSelected = true; - } else - { (args.Element as SideBarItem)!.IsSelected = false; - } + item.HandleItemChange(); } } @@ -242,14 +264,11 @@ internal void Clicked() if (IsGroupHeader) { if (CollapseEnabled) - { IsExpanded = !IsExpanded; - } else if (HasChildren) - { SetFlyoutOpen(true); - } } + RaiseItemInvoked(); } @@ -258,34 +277,42 @@ internal void RaiseItemInvoked() Owner?.RaiseItemInvoked(this); } - private void SidebarDisplayModeChanged(SideBarDisplayMode oldValue) + private void SidebarDisplayModeChanged(SideBarPaneDisplayMode oldValue) { - var useAnimations = oldValue != SideBarDisplayMode.Minimal; + var useAnimations = oldValue != SideBarPaneDisplayMode.Minimal; + switch (DisplayMode) { - case SideBarDisplayMode.Expanded: + case SideBarPaneDisplayMode.Expanded: UpdateExpansionState(useAnimations); UpdateSelectionState(); SetFlyoutOpen(false); break; - case SideBarDisplayMode.Minimal: + case SideBarPaneDisplayMode.Minimal: UpdateExpansionState(useAnimations); SetFlyoutOpen(false); break; - case SideBarDisplayMode.Compact: + case SideBarPaneDisplayMode.Compact: UpdateExpansionState(useAnimations); UpdateSelectionState(); break; } + if (!IsInFlyout) { - VisualStateManager.GoToState(this, DisplayMode == SideBarDisplayMode.Compact ? "Compact" : "NonCompact", true); + VisualStateManager.GoToState( + this, + DisplayMode == SideBarPaneDisplayMode.Compact + ? "Compact" + : "NonCompact", + true); } } private void UpdateSelectionState() { VisualStateManager.GoToState(this, ShouldShowSelectionIndicator() ? "Selected" : "Unselected", true); + UpdatePointerState(); } @@ -299,30 +326,21 @@ private void UpdateIcon() private bool ShouldShowSelectionIndicator() { if (IsExpanded && CollapseEnabled) - { return IsSelected; - } else - { return IsSelected || hasChildSelection; - } } private void UpdatePointerState(bool isPointerDown = false) { var useSelectedState = ShouldShowSelectionIndicator(); + if (isPointerDown) - { VisualStateManager.GoToState(this, useSelectedState ? "PressedSelected" : "Pressed", true); - } else if (isPointerOver) - { VisualStateManager.GoToState(this, useSelectedState ? "PointerOverSelected" : "PointerOver", true); - } else - { VisualStateManager.GoToState(this, useSelectedState ? "NormalSelected" : "Normal", true); - } } private void UpdateExpansionState(bool useAnimations = true) @@ -340,19 +358,20 @@ private void UpdateExpansionState(bool useAnimations = true) if (childrenRepeater != null) { if (childrenRepeater.ActualHeight > ChildrenPresenterHeight) - { ChildrenPresenterHeight = childrenRepeater.ActualHeight; - } } + VisualStateManager.GoToState(this, IsExpanded ? "Expanded" : "Collapsed", useAnimations); VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", useAnimations); } + UpdateSelectionState(); } private void ItemGrid_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { isPointerOver = true; + UpdatePointerState(); } @@ -360,19 +379,23 @@ private void ItemGrid_PointerExited(object sender, Microsoft.UI.Xaml.Input.Point { isPointerOver = false; isClicking = false; + UpdatePointerState(); } private void ItemGrid_PointerCanceled(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { isClicking = false; + UpdatePointerState(); } private void ItemGrid_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) { isClicking = true; + UpdatePointerState(true); + VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconPressed" : "CollapsedIconPressed", true); } @@ -383,36 +406,29 @@ private void Item_PointerReleased(object sender, Microsoft.UI.Xaml.Input.Pointer isClicking = false; e.Handled = true; + UpdatePointerState(); VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", true); + var updateKind = e.GetCurrentPoint(null).Properties.PointerUpdateKind; if (updateKind == PointerUpdateKind.LeftButtonReleased) - { Clicked(); - } } private void ItemGrid_DragOver(object sender, DragEventArgs e) { if (HasChildren) - { IsExpanded = true; - } var insertsAbove = DetermineDropTargetPosition(e); + if (insertsAbove == SideBarItemDropPosition.Center) - { VisualStateManager.GoToState(this, "DragOnTop", true); - } else if (insertsAbove == SideBarItemDropPosition.Top) - { VisualStateManager.GoToState(this, "DragInsertAbove", true); - } else if (insertsAbove == SideBarItemDropPosition.Bottom) - { VisualStateManager.GoToState(this, "DragInsertBelow", true); - } Owner?.RaiseItemDragOver(this, insertsAbove, e); } @@ -420,6 +436,7 @@ private void ItemGrid_DragOver(object sender, DragEventArgs e) private void ItemGrid_ContextRequested(UIElement sender, Microsoft.UI.Xaml.Input.ContextRequestedEventArgs args) { Owner?.RaiseContextRequested(this, args.TryGetPosition(this, out var point) ? point : default); + args.Handled = true; } @@ -431,6 +448,7 @@ private void ItemGrid_DragLeave(object sender, DragEventArgs e) private void ItemGrid_Drop(object sender, DragEventArgs e) { UpdatePointerState(); + Owner?.RaiseItemDropped(this, DetermineDropTargetPosition(e), e); } @@ -441,17 +459,17 @@ private SideBarItemDropPosition DetermineDropTargetPosition(DragEventArgs args) if (GetTemplateChild("ElementGrid") is Grid grid) { var position = args.GetPosition(grid); + if (position.Y < grid.ActualHeight * DROP_REPOSITION_THRESHOLD) - { return SideBarItemDropPosition.Top; - } + if (position.Y > grid.ActualHeight * (1 - DROP_REPOSITION_THRESHOLD)) - { return SideBarItemDropPosition.Bottom; - } + return SideBarItemDropPosition.Center; } } + return SideBarItemDropPosition.Center; } } diff --git a/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs b/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs index f3e0ab667df5..6c791a8135be 100644 --- a/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs +++ b/src/Files.App/UserControls/SideBar/SideBarItem.properties.cs @@ -10,119 +10,166 @@ public sealed partial class SideBarItem : Control { public SideBarView? Owner { - get { return (SideBarView?)GetValue(OwnerProperty); } - set { SetValue(OwnerProperty, value); } + get => (SideBarView?)GetValue(OwnerProperty); + set => SetValue(OwnerProperty, value); } + public static readonly DependencyProperty OwnerProperty = - DependencyProperty.Register(nameof(Owner), typeof(SideBarView), typeof(SideBarItem), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(Owner), + typeof(SideBarView), + typeof(SideBarItem), + new PropertyMetadata(null)); public bool IsSelected { - get { return (bool)GetValue(IsSelectedProperty); } - set { SetValue(IsSelectedProperty, value); } + get => (bool)GetValue(IsSelectedProperty); + set => SetValue(IsSelectedProperty, value); } + public static readonly DependencyProperty IsSelectedProperty = - DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false, OnPropertyChanged)); + DependencyProperty.Register( + nameof(IsSelected), + typeof(bool), + typeof(SideBarItem), + new PropertyMetadata(false, OnPropertyChanged)); public bool IsExpanded { - get { return (bool)GetValue(IsExpandedProperty); } - set { SetValue(IsExpandedProperty, value); } + get => (bool)GetValue(IsExpandedProperty); + set => SetValue(IsExpandedProperty, value); } + public static readonly DependencyProperty IsExpandedProperty = - DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SideBarItem), new PropertyMetadata(true, OnPropertyChanged)); + DependencyProperty.Register( + nameof(IsExpanded), + typeof(bool), + typeof(SideBarItem), + new PropertyMetadata(true, OnPropertyChanged)); public bool IsInFlyout { - get { return (bool)GetValue(IsInFlyoutProperty); } - set { SetValue(IsInFlyoutProperty, value); } + get => (bool)GetValue(IsInFlyoutProperty); + set => SetValue(IsInFlyoutProperty, value); } + public static readonly DependencyProperty IsInFlyoutProperty = - DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false)); + DependencyProperty.Register( + nameof(IsInFlyout), + typeof(bool), + typeof(SideBarItem), + new PropertyMetadata(false)); public double ChildrenPresenterHeight { - get { return (double)GetValue(ChildrenPresenterHeightProperty); } - set { SetValue(ChildrenPresenterHeightProperty, value); } + get => (double)GetValue(ChildrenPresenterHeightProperty); + set => SetValue(ChildrenPresenterHeightProperty, value); } + // Using 30 as a default in case something goes wrong public static readonly DependencyProperty ChildrenPresenterHeightProperty = - DependencyProperty.Register(nameof(ChildrenPresenterHeight), typeof(double), typeof(SideBarItem), new PropertyMetadata(30d)); + DependencyProperty.Register( + nameof(ChildrenPresenterHeight), + typeof(double), + typeof(SideBarItem), + new PropertyMetadata(30d)); public ISideBarItemModel? Item { - get { return (ISideBarItemModel)GetValue(ItemProperty); } - set { SetValue(ItemProperty, value); } + get => (ISideBarItemModel)GetValue(ItemProperty); + set => SetValue(ItemProperty, value); } + public static readonly DependencyProperty ItemProperty = - DependencyProperty.Register(nameof(Item), typeof(ISideBarItemModel), typeof(SideBarItem), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(Item), + typeof(ISideBarItemModel), + typeof(SideBarItem), + new PropertyMetadata(null)); public bool UseReorderDrop { - get { return (bool)GetValue(UseReorderDropProperty); } - set { SetValue(UseReorderDropProperty, value); } + get => (bool)GetValue(UseReorderDropProperty); + set => SetValue(UseReorderDropProperty, value); } + public static readonly DependencyProperty UseReorderDropProperty = - DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SideBarItem), new PropertyMetadata(false)); + DependencyProperty.Register( + nameof(UseReorderDrop), + typeof(bool), + typeof(SideBarItem), + new PropertyMetadata(false)); public FrameworkElement? Icon { - get { return (FrameworkElement?)GetValue(IconProperty); } - set { SetValue(IconProperty, value); } + get => (FrameworkElement?)GetValue(IconProperty); + set => SetValue(IconProperty, value); } + public static readonly DependencyProperty IconProperty = - DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SideBarItem), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(Icon), + typeof(FrameworkElement), + typeof(SideBarItem), + new PropertyMetadata(null)); public FrameworkElement? Decorator { - get { return (FrameworkElement?)GetValue(DecoratorProperty); } - set { SetValue(DecoratorProperty, value); } + get => (FrameworkElement?)GetValue(DecoratorProperty); + set => SetValue(DecoratorProperty, value); } + public static readonly DependencyProperty DecoratorProperty = - DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SideBarItem), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(Decorator), + typeof(FrameworkElement), + typeof(SideBarItem), + new PropertyMetadata(null)); - public SideBarDisplayMode DisplayMode + public SideBarPaneDisplayMode DisplayMode { - get { return (SideBarDisplayMode)GetValue(DisplayModeProperty); } - set { SetValue(DisplayModeProperty, value); } + get => (SideBarPaneDisplayMode)GetValue(DisplayModeProperty); + set => SetValue(DisplayModeProperty, value); } + public static readonly DependencyProperty DisplayModeProperty = - DependencyProperty.Register(nameof(DisplayMode), typeof(SideBarDisplayMode), typeof(SideBarItem), new PropertyMetadata(SideBarDisplayMode.Expanded, OnPropertyChanged)); + DependencyProperty.Register( + nameof(DisplayMode), + typeof(SideBarPaneDisplayMode), + typeof(SideBarItem), + new PropertyMetadata(SideBarPaneDisplayMode.Expanded, OnPropertyChanged)); public static void SetTemplateRoot(DependencyObject target, FrameworkElement value) { target.SetValue(TemplateRootProperty, value); } + public static FrameworkElement GetTemplateRoot(DependencyObject target) { return (FrameworkElement)target.GetValue(TemplateRootProperty); } + public static readonly DependencyProperty TemplateRootProperty = - DependencyProperty.Register("TemplateRoot", typeof(FrameworkElement), typeof(FrameworkElement), new PropertyMetadata(null)); + DependencyProperty.Register( + "TemplateRoot", + typeof(FrameworkElement), + typeof(FrameworkElement), + new PropertyMetadata(null)); public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if (sender is not SideBarItem item) return; + if (e.Property == DisplayModeProperty) - { - item.SidebarDisplayModeChanged((SideBarDisplayMode)e.OldValue); - } + item.SidebarDisplayModeChanged((SideBarPaneDisplayMode)e.OldValue); else if (e.Property == IsSelectedProperty) - { item.UpdateSelectionState(); - } else if (e.Property == IsExpandedProperty) - { item.UpdateExpansionState(); - } else if(e.Property == ItemProperty) - { item.HandleItemChange(); - } else - { Debug.Write(e.Property.ToString()); - } } } } diff --git a/src/Files.App/UserControls/SideBar/SideBarPaneDisplayMode.cs b/src/Files.App/UserControls/SideBar/SideBarPaneDisplayMode.cs new file mode 100644 index 000000000000..14c6e31dfc72 --- /dev/null +++ b/src/Files.App/UserControls/SideBar/SideBarPaneDisplayMode.cs @@ -0,0 +1,28 @@ +// Copyright (c) 2023 Files Community +// Licensed under the MIT License. See the LICENSE. + +namespace Files.App.UserControls.SideBar +{ + /// + /// Defines constants that specify how the pane is shown. + /// + public enum SideBarPaneDisplayMode + { + /// + /// The pane is shown on the left side of the control. + /// Only the pane menu button is shown by default. + /// + Minimal, + + /// + /// The pane is shown on the left side of the control. + /// Only the pane icons are shown by default. + /// + Compact, + + /// + /// The pane is shown on the left side of the control in its fully open state. + /// + Expanded + } +} diff --git a/src/Files.App/UserControls/SideBar/SideBarView.properties.cs b/src/Files.App/UserControls/SideBar/SideBarView.properties.cs index 28a00ca2a48c..5a2fec28e710 100644 --- a/src/Files.App/UserControls/SideBar/SideBarView.properties.cs +++ b/src/Files.App/UserControls/SideBar/SideBarView.properties.cs @@ -7,93 +7,124 @@ namespace Files.App.UserControls.SideBar { public sealed partial class SideBarView { - public SideBarDisplayMode DisplayMode + public SideBarPaneDisplayMode DisplayMode { - get { return (SideBarDisplayMode)GetValue(DisplayModeProperty); } - set { SetValue(DisplayModeProperty, value); } + get => (SideBarPaneDisplayMode)GetValue(DisplayModeProperty); + set => SetValue(DisplayModeProperty, value); } + public static readonly DependencyProperty DisplayModeProperty = - DependencyProperty.Register(nameof(DisplayMode), typeof(SideBarDisplayMode), typeof(SideBarView), new PropertyMetadata(SideBarDisplayMode.Expanded, OnPropertyChanged)); + DependencyProperty.Register( + nameof(DisplayMode), + typeof(SideBarPaneDisplayMode), + typeof(SideBarView), + new PropertyMetadata(SideBarPaneDisplayMode.Expanded, OnPropertyChanged)); public UIElement InnerContent { - get { return (UIElement)GetValue(InnerContentProperty); } - set { SetValue(InnerContentProperty, value); } + get => (UIElement)GetValue(InnerContentProperty); + set => SetValue(InnerContentProperty, value); } + public static readonly DependencyProperty InnerContentProperty = - DependencyProperty.Register(nameof(InnerContent), typeof(UIElement), typeof(SideBarView), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(InnerContent), + typeof(UIElement), + typeof(SideBarView), + new PropertyMetadata(null)); public UIElement Footer { - get { return (UIElement)GetValue(FooterProperty); } - set { SetValue(FooterProperty, value); } + get => (UIElement)GetValue(FooterProperty); + set => SetValue(FooterProperty, value); } + public static readonly DependencyProperty FooterProperty = - DependencyProperty.Register("Footer", typeof(UIElement), typeof(SideBarView), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(Footer), + typeof(UIElement), + typeof(SideBarView), + new PropertyMetadata(null)); public bool IsPaneOpen { - get { return (bool)GetValue(IsPaneOpenProperty); } - set { SetValue(IsPaneOpenProperty, value); } + get => (bool)GetValue(IsPaneOpenProperty); + set => SetValue(IsPaneOpenProperty, value); } + public static readonly DependencyProperty IsPaneOpenProperty = - DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(SideBarView), new PropertyMetadata(false, OnPropertyChanged)); + DependencyProperty.Register( + nameof(IsPaneOpen), + typeof(bool), + typeof(SideBarView), + new PropertyMetadata(false, OnPropertyChanged)); public double OpenPaneLength { - get { return (double)GetValue(OpenPaneLengthProperty); } + get => (double)GetValue(OpenPaneLengthProperty); set { SetValue(OpenPaneLengthProperty, value); NegativeOpenPaneLength = -value; } } + public static readonly DependencyProperty OpenPaneLengthProperty = - DependencyProperty.Register(nameof(OpenPaneLength), typeof(double), typeof(SideBarView), new PropertyMetadata(240d, OnPropertyChanged)); + DependencyProperty.Register( + nameof(OpenPaneLength), + typeof(double), + typeof(SideBarView), + new PropertyMetadata(240d, OnPropertyChanged)); public double NegativeOpenPaneLength { - get { return (double)GetValue(NegativeOpenPaneLengthProperty); } - set { SetValue(NegativeOpenPaneLengthProperty, value); } + get => (double)GetValue(NegativeOpenPaneLengthProperty); + set => SetValue(NegativeOpenPaneLengthProperty, value); } + public static readonly DependencyProperty NegativeOpenPaneLengthProperty = - DependencyProperty.Register(nameof(NegativeOpenPaneLength), typeof(double), typeof(SideBarView), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(NegativeOpenPaneLength), + typeof(double), + typeof(SideBarView), + new PropertyMetadata(null)); public ISideBarViewModel ViewModel { get => (ISideBarViewModel)GetValue(ViewModelProperty); set => SetValue(ViewModelProperty, value); } + public static readonly DependencyProperty ViewModelProperty = - DependencyProperty.Register(nameof(ViewModel), typeof(ISideBarViewModel), typeof(SideBarView), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(ViewModel), + typeof(ISideBarViewModel), + typeof(SideBarView), + new PropertyMetadata(null)); public ISideBarItemModel SelectedItem { get => (ISideBarItemModel)GetValue(SelectedItemProperty); - set - { - SetValue(SelectedItemProperty, value); - } + set => SetValue(SelectedItemProperty, value); } + public static readonly DependencyProperty SelectedItemProperty = - DependencyProperty.Register(nameof(SelectedItem), typeof(ISideBarItemModel), typeof(SideBarView), new PropertyMetadata(null)); + DependencyProperty.Register( + nameof(SelectedItem), + typeof(ISideBarItemModel), + typeof(SideBarView), + new PropertyMetadata(null)); public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if (sender is not SideBarView control) return; if (e.Property == OpenPaneLengthProperty) - { control.UpdateOpenPaneLengthColumn(); - } else if (e.Property == DisplayModeProperty) - { control.UpdateDisplayMode(); - } else if (e.Property == IsPaneOpenProperty) - { control.UpdateMinimalMode(); - } } } } diff --git a/src/Files.App/UserControls/SideBar/SideBarView.xaml b/src/Files.App/UserControls/SideBar/SideBarView.xaml index 57d8c4c1f366..e7362e4cae9a 100644 --- a/src/Files.App/UserControls/SideBar/SideBarView.xaml +++ b/src/Files.App/UserControls/SideBar/SideBarView.xaml @@ -21,13 +21,14 @@ - + + + + + + @@ -360,4 +365,5 @@ + diff --git a/src/Files.App/UserControls/SideBar/SideBarView.xaml.cs b/src/Files.App/UserControls/SideBar/SideBarView.xaml.cs index 1a8c2bbbe808..68372f2d3287 100644 --- a/src/Files.App/UserControls/SideBar/SideBarView.xaml.cs +++ b/src/Files.App/UserControls/SideBar/SideBarView.xaml.cs @@ -15,7 +15,6 @@ namespace Files.App.UserControls.SideBar [ContentProperty(Name = "InnerContent")] public sealed partial class SideBarView : UserControl, INotifyPropertyChanged { - private const double COMPACT_MAX_WIDTH = 200; public event EventHandler? ItemDropped; @@ -27,6 +26,7 @@ public sealed partial class SideBarView : UserControl, INotifyPropertyChanged internal SideBarItem? SelectedItemContainer = null; private bool draggingSidebarResizer; + private double preManipulationSidebarWidth = 0; public SideBarView() @@ -42,7 +42,8 @@ internal void UpdateSelectedItemContainer(SideBarItem container) internal void RaiseItemInvoked(SideBarItem item) { // Only leaves can be selected - if (item.Item is null || item.IsGroupHeader) return; + if (item.Item is null || item.IsGroupHeader) + return; SelectedItem = item.Item; ItemInvoked?.Invoke(item, item.Item); @@ -52,48 +53,51 @@ internal void RaiseItemInvoked(SideBarItem item) internal void RaiseContextRequested(SideBarItem item, Point e) { ItemContextInvoked?.Invoke(item, new ItemContextInvokedArgs(item.Item, e)); + ViewModel.HandleItemContextInvoked(item, new ItemContextInvokedArgs(item.Item, e)); } internal void RaiseItemDropped(SideBarItem sideBarItem, SideBarItemDropPosition dropPosition, DragEventArgs rawEvent) { - if (sideBarItem.Item is null) return; + if (sideBarItem.Item is null) + return; + ItemDropped?.Invoke(sideBarItem, new ItemDroppedEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); + ViewModel.HandleItemDropped(new ItemDroppedEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); } internal void RaiseItemDragOver(SideBarItem sideBarItem, SideBarItemDropPosition dropPosition, DragEventArgs rawEvent) { - if (sideBarItem.Item is null) return; + if (sideBarItem.Item is null) + return; + ItemDragOver?.Invoke(sideBarItem, new ItemDragOverEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); + ViewModel.HandleItemDragOver(new ItemDragOverEventArgs(sideBarItem.Item, rawEvent.DataView, dropPosition, rawEvent)); } private void UpdateMinimalMode() { - if (DisplayMode != SideBarDisplayMode.Minimal) return; + if (DisplayMode != SideBarPaneDisplayMode.Minimal) return; if (IsPaneOpen) - { VisualStateManager.GoToState(this, "MinimalExpanded", true); - } else - { VisualStateManager.GoToState(this, "MinimalCollapsed", true); - } } private void UpdateDisplayMode() { switch (DisplayMode) { - case SideBarDisplayMode.Compact: + case SideBarPaneDisplayMode.Compact: VisualStateManager.GoToState(this, "Compact", true); return; - case SideBarDisplayMode.Expanded: + case SideBarPaneDisplayMode.Expanded: VisualStateManager.GoToState(this, "Expanded", true); return; - case SideBarDisplayMode.Minimal: + case SideBarPaneDisplayMode.Minimal: IsPaneOpen = false; UpdateMinimalMode(); return; @@ -104,11 +108,11 @@ private void UpdateDisplayModeForPaneWidth(double newPaneWidth) { if (newPaneWidth < COMPACT_MAX_WIDTH) { - DisplayMode = SideBarDisplayMode.Compact; + DisplayMode = SideBarPaneDisplayMode.Compact; } else if (newPaneWidth > COMPACT_MAX_WIDTH) { - DisplayMode = SideBarDisplayMode.Expanded; + DisplayMode = SideBarPaneDisplayMode.Expanded; OpenPaneLength = newPaneWidth; } } @@ -122,6 +126,7 @@ private void SidebarView_Loaded(object sender, RoutedEventArgs e) { UpdateDisplayMode(); UpdateOpenPaneLengthColumn(); + PaneColumnGrid.Translation = new System.Numerics.Vector3(0, 0, 32); } @@ -129,7 +134,9 @@ private void SidebarResizer_ManipulationStarted(object sender, ManipulationStart { draggingSidebarResizer = true; preManipulationSidebarWidth = PaneColumnGrid.ActualWidth; + VisualStateManager.GoToState(this, "ResizerPressed", true); + e.Handled = true; } @@ -137,17 +144,20 @@ private void SidebarResizer_ManipulationDelta(object sender, ManipulationDeltaRo { var newWidth = preManipulationSidebarWidth + e.Cumulative.Translation.X; UpdateDisplayModeForPaneWidth(newWidth); + e.Handled = true; } private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e) { var primaryInvocation = e.Key == VirtualKey.Space || e.Key == VirtualKey.Enter; - if (DisplayMode == SideBarDisplayMode.Expanded) + + if (DisplayMode == SideBarPaneDisplayMode.Expanded) { if (primaryInvocation) { - DisplayMode = SideBarDisplayMode.Compact; + DisplayMode = SideBarPaneDisplayMode.Compact; + return; } @@ -156,19 +166,21 @@ private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e) // Left makes the pane smaller so we invert the increment if (e.Key == VirtualKey.Left) - { increment = -increment; - } + var newWidth = OpenPaneLength + increment; UpdateDisplayModeForPaneWidth(newWidth); + e.Handled = true; + return; } - else if (DisplayMode == SideBarDisplayMode.Compact) + else if (DisplayMode == SideBarPaneDisplayMode.Compact) { if (primaryInvocation || e.Key == VirtualKey.Right) { - DisplayMode = SideBarDisplayMode.Expanded; + DisplayMode = SideBarPaneDisplayMode.Expanded; + e.Handled = true; } } @@ -177,25 +189,29 @@ private void SidebarResizerControl_KeyDown(object sender, KeyRoutedEventArgs e) private void PaneLightDismissLayer_PointerPressed(object sender, PointerRoutedEventArgs e) { IsPaneOpen = false; + e.Handled = true; } private void PaneLightDismissLayer_Tapped(object sender, TappedRoutedEventArgs e) { IsPaneOpen = false; + e.Handled = true; } private void SidebarResizer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { - if (DisplayMode == SideBarDisplayMode.Expanded) + if (DisplayMode == SideBarPaneDisplayMode.Expanded) { - DisplayMode = SideBarDisplayMode.Compact; + DisplayMode = SideBarPaneDisplayMode.Compact; + e.Handled = true; } else { - DisplayMode = SideBarDisplayMode.Expanded; + DisplayMode = SideBarPaneDisplayMode.Expanded; + e.Handled = true; } } @@ -204,7 +220,9 @@ private void SidebarResizer_PointerEntered(object sender, PointerRoutedEventArgs { var sidebarResizer = (FrameworkElement)sender; sidebarResizer.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast)); + VisualStateManager.GoToState(this, "ResizerPointerOver", true); + e.Handled = true; } @@ -215,30 +233,34 @@ private void SidebarResizer_PointerExited(object sender, PointerRoutedEventArgs var sidebarResizer = (FrameworkElement)sender; sidebarResizer.ChangeCursor(InputSystemCursor.Create(InputSystemCursorShape.Arrow)); + VisualStateManager.GoToState(this, "ResizerNormal", true); + e.Handled = true; } private void SidebarResizer_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { draggingSidebarResizer = false; + VisualStateManager.GoToState(this, "ResizerNormal", true); + e.Handled = true; } private void PaneColumnGrid_ContextRequested(UIElement sender, ContextRequestedEventArgs e) { var newArgs = new ItemContextInvokedArgs(null, e.TryGetPosition(this, out var point) ? point : default); + ViewModel.HandleItemContextInvoked(this, newArgs); + e.Handled = true; } private void MenuItemsHost_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { if(args.Element is SideBarItem sidebarItem) - { sidebarItem.HandleItemChange(); - } } } } diff --git a/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs b/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs index 6acca5b71764..9aacc24331d0 100644 --- a/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs +++ b/src/Files.App/UserControls/SideBar/SidebarItemAutomationPeer.cs @@ -16,11 +16,16 @@ public ExpandCollapseState ExpandCollapseState { if (Owner.HasChildren) return Owner.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed; + return ExpandCollapseState.LeafNode; } } - public bool IsSelected => Owner.IsSelected; - public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner)); + + public bool IsSelected + => Owner.IsSelected; + + public IRawElementProviderSimple SelectionContainer + => ProviderFromPeer(CreatePeerForElement(Owner.Owner)); private new SideBarItem Owner { get; init; } @@ -48,28 +53,22 @@ protected override object GetPatternCore(PatternInterface patternInterface) else if (patternInterface == PatternInterface.ExpandCollapse) { if (Owner.CollapseEnabled) - { return this; - } } + return base.GetPatternCore(patternInterface); } public void Collapse() { if (Owner.CollapseEnabled) - { Owner.IsExpanded = false; - } } public void Expand() { - if (Owner.CollapseEnabled) - { Owner.IsExpanded = true; - } } public void Invoke() @@ -105,13 +104,11 @@ protected override int GetPositionInSetCore() private IList GetOwnerCollection() { if (Owner.FindAscendant() is SideBarItem parent && parent.Item?.Children is IList list) - { return list; - } + if (Owner?.Owner is not null && Owner.Owner.ViewModel.SidebarItems is IList items) - { return items; - } + return new List(); } } diff --git a/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs b/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs index 6507fa26bfc6..7c212357af7e 100644 --- a/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs +++ b/src/Files.App/UserControls/SideBar/SidebarItemDropPosition.cs @@ -4,22 +4,22 @@ namespace Files.App.UserControls.SideBar { /// - /// The position of the item that was dropped on the sidebar item. + /// Defines constants that specify the position of the item that was dropped on the . /// public enum SideBarItemDropPosition { /// - /// The item was dropped on the top of the sidebar item indicating it should be moved/inserted above this item. + /// The item was dropped on the top of the indicating it should be moved/inserted above this . /// Top, /// - /// The item was dropped on the bottom of the sidebar item indicating it should be moved/inserted below this item. + /// The item was dropped on the bottom of the indicating it should be moved/inserted below this . /// Bottom, /// - /// The item was dropped on the center of the sidebar item indicating it should be moved/inserted as a child of this item. + /// The item was dropped on the center of the indicating it should be moved/inserted as a child of this . /// Center } diff --git a/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs b/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs index f0ac435787b0..c35b3c1d991a 100644 --- a/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs +++ b/src/Files.App/UserControls/SideBar/SidebarViewAutomationPeer.cs @@ -8,8 +8,11 @@ namespace Files.App.UserControls.SideBar { class SideBarViewAutomationPeer : FrameworkElementAutomationPeer, ISelectionProvider { - public bool CanSelectMultiple => false; - public bool IsSelectionRequired => true; + public bool CanSelectMultiple + => false; + + public bool IsSelectionRequired + => true; private new SideBarView Owner { get; init; } @@ -21,19 +24,21 @@ public SideBarViewAutomationPeer(SideBarView owner) : base(owner) protected override object GetPatternCore(PatternInterface patternInterface) { if (patternInterface == PatternInterface.Selection) - { return this; - } + return base.GetPatternCore(patternInterface); } public IRawElementProviderSimple[] GetSelection() { if (Owner.SelectedItemContainer != null) + { return new IRawElementProviderSimple[] - { - ProviderFromPeer(CreatePeerForElement(Owner.SelectedItemContainer)) - }; + { + ProviderFromPeer(CreatePeerForElement(Owner.SelectedItemContainer)) + }; + } + return Array.Empty(); } } diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index b69d93a57b56..d0e911d767f1 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -51,18 +51,18 @@ public IFilesystemHelpers FilesystemHelpers public SidebarPinnedModel SidebarPinnedModel => App.QuickAccessManager.Model; public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService(); - private SideBarDisplayMode sidebarDisplayMode; - public SideBarDisplayMode SidebarDisplayMode + private SideBarPaneDisplayMode sidebarDisplayMode; + public SideBarPaneDisplayMode SidebarDisplayMode { get => sidebarDisplayMode; set { // We only want to track non minimal mode - if (value == SideBarDisplayMode.Minimal) return; + if (value == SideBarPaneDisplayMode.Minimal) return; if (SetProperty(ref sidebarDisplayMode, value)) { OnPropertyChanged(nameof(IsSidebarCompactSize)); - IsSidebarOpen = sidebarDisplayMode == SideBarDisplayMode.Expanded; + IsSidebarOpen = sidebarDisplayMode == SideBarPaneDisplayMode.Expanded; UpdateTabControlMargin(); } } @@ -86,7 +86,7 @@ public SideBarDisplayMode SidebarDisplayMode }; public bool IsSidebarCompactSize - => SidebarDisplayMode == SideBarDisplayMode.Compact || SidebarDisplayMode == SideBarDisplayMode.Minimal; + => SidebarDisplayMode == SideBarPaneDisplayMode.Compact || SidebarDisplayMode == SideBarPaneDisplayMode.Minimal; public void NotifyInstanceRelatedPropertiesChanged(string arg) { @@ -254,7 +254,7 @@ public SidebarViewModel() networkDrivesViewModel.Drives.CollectionChanged += (x, args) => Manager_DataChanged(SectionType.Network, args); App.WSLDistroManager.DataChanged += Manager_DataChanged; App.FileTagsManager.DataChanged += Manager_DataChanged; - SidebarDisplayMode = UserSettingsService.AppearanceSettingsService.IsSidebarOpen ? SideBarDisplayMode.Expanded : SideBarDisplayMode.Compact; + SidebarDisplayMode = UserSettingsService.AppearanceSettingsService.IsSidebarOpen ? SideBarPaneDisplayMode.Expanded : SideBarPaneDisplayMode.Compact; HideSectionCommand = new RelayCommand(HideSection); UnpinItemCommand = new RelayCommand(UnpinItem); @@ -656,7 +656,7 @@ public void UpdateTabControlMargin() TabControlMargin = SidebarDisplayMode switch { // This prevents the pane toggle button from overlapping the tab control in minimal mode - SideBarDisplayMode.Minimal => new GridLength(44, GridUnitType.Pixel), + SideBarPaneDisplayMode.Minimal => new GridLength(44, GridUnitType.Pixel), _ => new GridLength(0, GridUnitType.Pixel), }; } diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index d1db24e15e7a..c16d795a63f2 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -489,7 +489,7 @@ private void PaneSplitter_ManipulationStarted(object sender, ManipulationStarted private void TogglePaneButton_Click(object sender, RoutedEventArgs e) { - if (SidebarControl.DisplayMode == SideBarDisplayMode.Minimal) + if (SidebarControl.DisplayMode == SideBarPaneDisplayMode.Minimal) { SidebarControl.IsPaneOpen = !SidebarControl.IsPaneOpen; } From 64993b27d26b7ca4879c75ee10f2bb36654e23a8 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:06:24 +0900 Subject: [PATCH 4/5] SidebarViewModel to SideBarViewModel --- src/Files.App/App.xaml.cs | 2 +- src/Files.App/Data/Contexts/Tags/TagsContext.cs | 2 +- .../UserControls/SideBar/ISideBarViewModel.cs | 2 +- .../ViewModels/UserControls/SidebarViewModel.cs | 14 ++++++++------ src/Files.App/Views/MainPage.xaml.cs | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Files.App/App.xaml.cs b/src/Files.App/App.xaml.cs index 1ea38214f59a..6443d979ce5e 100644 --- a/src/Files.App/App.xaml.cs +++ b/src/Files.App/App.xaml.cs @@ -144,7 +144,7 @@ private IHost ConfigureHost() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() diff --git a/src/Files.App/Data/Contexts/Tags/TagsContext.cs b/src/Files.App/Data/Contexts/Tags/TagsContext.cs index 6564e22a4e16..21d2535aa34e 100644 --- a/src/Files.App/Data/Contexts/Tags/TagsContext.cs +++ b/src/Files.App/Data/Contexts/Tags/TagsContext.cs @@ -30,7 +30,7 @@ sealed class TagsContext : ITagsContext public TagsContext() { FileTagsContainerViewModel.SelectedTagChanged += SelectedTagsChanged; - SidebarViewModel.SelectedTagChanged += SelectedTagsChanged; + SideBarViewModel.SelectedTagChanged += SelectedTagsChanged; } private void SelectedTagsChanged(object _, SelectedTagChangedEventArgs e) diff --git a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs index 8fdc525da9e8..fa1640831571 100644 --- a/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs +++ b/src/Files.App/UserControls/SideBar/ISideBarViewModel.cs @@ -20,7 +20,7 @@ public record ItemContextInvokedArgs(object? Item, Point Position) } /// - /// Represents interface for . + /// Represents interface for . /// public interface ISideBarViewModel { diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index d0e911d767f1..b64822b38e47 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -22,15 +22,18 @@ namespace Files.App.ViewModels.UserControls { - public class SidebarViewModel : ObservableObject, IDisposable, ISideBarViewModel + public class SideBarViewModel : ObservableObject, IDisposable, ISideBarViewModel { - private IUserSettingsService UserSettingsService { get; } = Ioc.Default.GetRequiredService(); - private ICommandManager Commands { get; } = Ioc.Default.GetRequiredService(); + private IUserSettingsService UserSettingsService = Ioc.Default.GetRequiredService(); + private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService(); - private readonly IFileTagsService fileTagsService; + + private readonly IFileTagsService fileTagsService = Ioc.Default.GetRequiredService(); private readonly NetworkDrivesViewModel networkDrivesViewModel = Ioc.Default.GetRequiredService(); + private ICommandManager Commands = Ioc.Default.GetRequiredService(); + private IPaneHolder paneHolder; public IPaneHolder PaneHolder { @@ -230,10 +233,9 @@ public INavigationControlItem SidebarSelectedItem set => SetProperty(ref selectedSidebarItem, value); } - public SidebarViewModel() + public SideBarViewModel() { dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread(); - fileTagsService = Ioc.Default.GetRequiredService(); sidebarItems = new BulkConcurrentObservableCollection(); UserSettingsService.OnSettingChangedEvent += UserSettingsService_OnSettingChangedEvent; diff --git a/src/Files.App/Views/MainPage.xaml.cs b/src/Files.App/Views/MainPage.xaml.cs index c16d795a63f2..4d32c96682d8 100644 --- a/src/Files.App/Views/MainPage.xaml.cs +++ b/src/Files.App/Views/MainPage.xaml.cs @@ -29,7 +29,7 @@ public sealed partial class MainPage : Page, INotifyPropertyChanged public IWindowContext WindowContext { get; } - public SidebarViewModel SidebarAdaptiveViewModel { get; } + public SideBarViewModel SidebarAdaptiveViewModel { get; } public MainPageViewModel ViewModel { get; } @@ -53,7 +53,7 @@ public MainPage() ApplicationService = Ioc.Default.GetRequiredService(); Commands = Ioc.Default.GetRequiredService(); WindowContext = Ioc.Default.GetRequiredService(); - SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService(); + SidebarAdaptiveViewModel = Ioc.Default.GetRequiredService(); SidebarAdaptiveViewModel.PaneFlyout = (MenuFlyout)Resources["SidebarContextMenu"]; ViewModel = Ioc.Default.GetRequiredService(); OngoingTasksViewModel = Ioc.Default.GetRequiredService(); From d13366fa707e076cd384225390977f7ac478dd44 Mon Sep 17 00:00:00 2001 From: 0x5BFA <62196528+0x5bfa@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:11:45 +0900 Subject: [PATCH 5/5] Update ViewModel --- .../ViewModels/UserControls/SidebarViewModel.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs index b64822b38e47..bbc8799d3c22 100644 --- a/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/SidebarViewModel.cs @@ -32,6 +32,8 @@ public class SideBarViewModel : ObservableObject, IDisposable, ISideBarViewModel private readonly NetworkDrivesViewModel networkDrivesViewModel = Ioc.Default.GetRequiredService(); + public IQuickAccessService QuickAccessService = Ioc.Default.GetRequiredService(); + private ICommandManager Commands = Ioc.Default.GetRequiredService(); private IPaneHolder paneHolder; @@ -47,12 +49,15 @@ public IFilesystemHelpers FilesystemHelpers => PaneHolder?.FilesystemHelpers; private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue; + private INavigationControlItem rightClickedItem; - public object SidebarItems => sidebarItems; + public object SidebarItems + => sidebarItems; + public BulkConcurrentObservableCollection sidebarItems { get; init; } + public SidebarPinnedModel SidebarPinnedModel => App.QuickAccessManager.Model; - public IQuickAccessService QuickAccessService { get; } = Ioc.Default.GetRequiredService(); private SideBarPaneDisplayMode sidebarDisplayMode; public SideBarPaneDisplayMode SidebarDisplayMode @@ -226,7 +231,6 @@ public bool ShowFileTagsSection } private INavigationControlItem selectedSidebarItem; - public INavigationControlItem SidebarSelectedItem { get => selectedSidebarItem;