forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Quality: Introduced HomePageContext (files-community#14115)
- Loading branch information
Showing
9 changed files
with
251 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Files.App.UserControls.Widgets; | ||
using Files.App.ViewModels.Widgets; | ||
using Microsoft.UI.Xaml.Controls; | ||
using System.Collections.Immutable; | ||
|
||
namespace Files.App.Data.Contexts | ||
{ | ||
internal class HomePageContext : ObservableObject, IHomePageContext | ||
{ | ||
private static readonly IImmutableList<FileTagsItemViewModel> emptyTaggedItems = Enumerable.Empty<FileTagsItemViewModel>().ToImmutableList(); | ||
|
||
public bool IsAnyItemRightClicked => rightClickedItem is not null; | ||
|
||
private WidgetCardItem? rightClickedItem = null; | ||
public WidgetCardItem? RightClickedItem => rightClickedItem; | ||
|
||
private CommandBarFlyout? itemContextFlyoutMenu = null; | ||
public CommandBarFlyout? ItemContextFlyoutMenu => itemContextFlyoutMenu; | ||
|
||
private IReadOnlyList<FileTagsItemViewModel> selectedTaggedItems = emptyTaggedItems; | ||
public IReadOnlyList<FileTagsItemViewModel> SelectedTaggedItems | ||
{ | ||
get => selectedTaggedItems; | ||
set => selectedTaggedItems = value ?? emptyTaggedItems; | ||
} | ||
|
||
public HomePageContext() | ||
{ | ||
HomePageWidget.RightClickedItemChanged += HomePageWidget_RightClickedItemChanged; | ||
FileTagsWidget.SelectedTaggedItemsChanged += FileTagsWidget_SelectedTaggedItemsChanged; | ||
} | ||
|
||
private void FileTagsWidget_SelectedTaggedItemsChanged(object? sender, IEnumerable<FileTagsItemViewModel> e) | ||
{ | ||
SetProperty(ref selectedTaggedItems, e.ToList()); | ||
} | ||
|
||
private void HomePageWidget_RightClickedItemChanged(object? sender, WidgetsRightClickedItemChangedEventArgs e) | ||
{ | ||
if (SetProperty(ref rightClickedItem, e.Item, nameof(RightClickedItem))) | ||
OnPropertyChanged(nameof(IsAnyItemRightClicked)); | ||
|
||
SetProperty(ref itemContextFlyoutMenu, e.Flyout, nameof(ItemContextFlyoutMenu)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Files.App.UserControls.Widgets; | ||
using Files.App.ViewModels.Widgets; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Files.App.Data.Contexts | ||
{ | ||
internal interface IHomePageContext | ||
{ | ||
/// <summary> | ||
/// The last right clicked item | ||
/// </summary> | ||
WidgetCardItem? RightClickedItem { get; } | ||
|
||
/// <summary> | ||
/// The last opened widget's context menu instance | ||
/// </summary> | ||
CommandBarFlyout? ItemContextFlyoutMenu { get; } | ||
|
||
/// <summary> | ||
/// An list containing all the selected tagged items | ||
/// </summary> | ||
IReadOnlyList<FileTagsItemViewModel> SelectedTaggedItems { get; } | ||
|
||
/// <summary> | ||
/// Tells whether any item has been right clicked | ||
/// </summary> | ||
bool IsAnyItemRightClicked { get; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Files.App/Data/EventArguments/WidgetsRightClickedItemChangedEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Files.App.UserControls.Widgets; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Files.App.Data.EventArguments | ||
{ | ||
public class WidgetsRightClickedItemChangedEventArgs | ||
{ | ||
public WidgetCardItem? Item { get; set; } | ||
|
||
public CommandBarFlyout? Flyout { get; set; } | ||
|
||
public WidgetsRightClickedItemChangedEventArgs(WidgetCardItem? item = null, CommandBarFlyout? flyout = null) | ||
{ | ||
Item = item; | ||
Flyout = flyout; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.