Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Files.App.Controls/Sidebar/SidebarDisplayMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public enum SidebarDisplayMode
/// The sidebar is hidden and moves in from the side when the <see cref="SidebarView.IsPaneOpen"/> is set to <code>true</code>.
/// </summary>
Minimal,

/// <summary>
/// Only the icons of the top most sections are visible.
/// </summary>
Compact,

/// <summary>
/// The sidebar is expanded and items can also be expanded.
/// </summary>
Expand Down
136 changes: 42 additions & 94 deletions src/Files.App.Controls/Sidebar/SidebarItem.Properties.cs
Original file line number Diff line number Diff line change
@@ -1,125 +1,73 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using CommunityToolkit.WinUI;

namespace Files.App.Controls
{
public sealed partial class SidebarItem : Control
public sealed partial class SidebarItem
{
public SidebarView? Owner
{
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));
[GeneratedDependencyProperty]
public partial SidebarView? Owner { get; set; }

public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
public static readonly DependencyProperty IsSelectedProperty =
DependencyProperty.Register(nameof(IsSelected), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false, OnPropertyChanged));
[GeneratedDependencyProperty]
public partial bool IsSelected { get; set; }

public bool IsExpanded
{
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public static readonly DependencyProperty IsExpandedProperty =
DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(SidebarItem), new PropertyMetadata(true, OnPropertyChanged));
[GeneratedDependencyProperty(DefaultValue = true)]
public partial bool IsExpanded { get; set; }

public bool IsInFlyout
{
get { return (bool)GetValue(IsInFlyoutProperty); }
set { SetValue(IsInFlyoutProperty, value); }
}
public static readonly DependencyProperty IsInFlyoutProperty =
DependencyProperty.Register(nameof(IsInFlyout), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
[GeneratedDependencyProperty]
public partial bool IsInFlyout { get; set; }

public double ChildrenPresenterHeight
{
get { return (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));
[GeneratedDependencyProperty(DefaultValue = 30d)]
public partial double ChildrenPresenterHeight { get; set; }

public ISidebarItemModel? Item
{
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));
[GeneratedDependencyProperty]
public partial ISidebarItemModel? Item { get; set; }

public bool UseReorderDrop
{
get { return (bool)GetValue(UseReorderDropProperty); }
set { SetValue(UseReorderDropProperty, value); }
}
public static readonly DependencyProperty UseReorderDropProperty =
DependencyProperty.Register(nameof(UseReorderDrop), typeof(bool), typeof(SidebarItem), new PropertyMetadata(false));
[GeneratedDependencyProperty]
public partial bool UseReorderDrop { get; set; }

public FrameworkElement? Icon
{
get { return (FrameworkElement?)GetValue(IconProperty); }
set { SetValue(IconProperty, value); }
}
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(nameof(Icon), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
[GeneratedDependencyProperty]
public partial FrameworkElement? Icon { get; set; }

public FrameworkElement? Decorator
{
get { return (FrameworkElement?)GetValue(DecoratorProperty); }
set { SetValue(DecoratorProperty, value); }
}
public static readonly DependencyProperty DecoratorProperty =
DependencyProperty.Register(nameof(Decorator), typeof(FrameworkElement), typeof(SidebarItem), new PropertyMetadata(null));
[GeneratedDependencyProperty]
public partial FrameworkElement? Decorator { get; set; }

public SidebarDisplayMode DisplayMode
{
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));
[GeneratedDependencyProperty(DefaultValue = SidebarDisplayMode.Expanded)]
public partial SidebarDisplayMode DisplayMode { get; set; }

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));

public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
partial void OnDisplayModePropertyChanged(DependencyPropertyChangedEventArgs e)
{
SidebarDisplayModeChanged((SidebarDisplayMode)e.OldValue);
}

partial void OnIsSelectedChanged(bool newValue)
{
UpdateSelectionState();
}

partial void OnIsExpandedChanged(bool newValue)
{
UpdateExpansionState();
}

partial void OnItemChanged(ISidebarItemModel? newValue)
{
if (sender is not SidebarItem item) return;
if (e.Property == DisplayModeProperty)
{
item.SidebarDisplayModeChanged((SidebarDisplayMode)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());
}
HandleItemChange();
}
}
}
40 changes: 16 additions & 24 deletions src/Files.App.Controls/Sidebar/SidebarItemAutomationPeer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@

namespace Files.App.Controls
{
/// <summary>
/// Automation peer for <see cref="SidebarItem"/>.
/// </summary>
public sealed partial class SidebarItemAutomationPeer : FrameworkElementAutomationPeer, IInvokeProvider, IExpandCollapseProvider, ISelectionItemProvider
{
public ExpandCollapseState ExpandCollapseState
{
get
{
if (Owner.HasChildren)
return Owner.IsExpanded ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed;
return ExpandCollapseState.LeafNode;
}
}
public ExpandCollapseState ExpandCollapseState =>
Owner.HasChildren
? Owner.IsExpanded
? ExpandCollapseState.Expanded
: ExpandCollapseState.Collapsed
: ExpandCollapseState.LeafNode;
public bool IsSelected => Owner.IsSelected;
public IRawElementProviderSimple SelectionContainer => ProviderFromPeer(CreatePeerForElement(Owner.Owner));

private new SidebarItem Owner { get; init; }

public SidebarItemAutomationPeer(SidebarItem owner) : base(owner)
{
this.Owner = owner;
Owner = owner;
}

protected override AutomationControlType GetAutomationControlTypeCore()
Expand All @@ -42,35 +42,29 @@ protected override string GetNameCore()

protected override object GetPatternCore(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.Invoke || patternInterface == PatternInterface.SelectionItem)
if (patternInterface is PatternInterface.Invoke or PatternInterface.SelectionItem)
{
return this;
}
else if (patternInterface == PatternInterface.ExpandCollapse)
else if (patternInterface is 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()
Expand Down Expand Up @@ -106,13 +100,11 @@ protected override int GetPositionInSetCore()
private IList GetOwnerCollection()
{
if (Owner.FindAscendant<SidebarItem>() is SidebarItem parent && parent.Item?.Children is IList list)
{
return list;
}
if (Owner?.Owner is not null && Owner.Owner.ViewModel.SidebarItems is IList items)
{

if (Owner?.Owner is not null && Owner.Owner?.ViewModel?.SidebarItems is IList items)
return items;
}

return new List<object>();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App.Controls/Sidebar/SidebarItemDropPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public enum SidebarItemDropPosition
/// The item was dropped on the top of the sidebar item indicating it should be moved/inserted above this item.
/// </summary>
Top,

/// <summary>
/// The item was dropped on the bottom of the sidebar item indicating it should be moved/inserted below this item.
/// </summary>
Bottom,

/// <summary>
/// The item was dropped on the center of the sidebar item indicating it should be moved/inserted as a child of this item.
/// </summary>
Expand Down
Loading
Loading