-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Quality: Introduced HomePageContext #14115
Merged
yaira2
merged 5 commits into
files-community:main
from
0x5bfa:5bfa/Introduce-WidgetsContext
Dec 19, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this get garbage-collected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know why we've put the last opened flyout to the App.LastOpenedFlyout at the first place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not needed I'd advise to remove it. It's definitely not getting GC'd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m gonna try to find who added this line and remove if it seems to be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use it to dismiss open context menus when closing the app, otherwise we found that it could cause the app to hang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fyi @hishitetsu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a workaround for #10110. This workaround is still necessary to avoid crashes.