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.
Feature: Added an action to open Storage Sense (files-community#16467)
- Loading branch information
Showing
10 changed files
with
149 additions
and
24 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,44 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class OpenStorageSenseAction : ObservableObject, IAction | ||
{ | ||
private readonly IContentPageContext context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>(); | ||
|
||
public virtual string Label | ||
=> Strings.Cleanup.GetLocalizedResource(); | ||
|
||
public virtual string Description | ||
=> Strings.OpenStorageSenseDescription.GetLocalizedResource(); | ||
|
||
public virtual bool IsExecutable => | ||
context.HasItem && | ||
!context.HasSelection && | ||
drivesViewModel.Drives | ||
.Cast<DriveItem>() | ||
.FirstOrDefault(x => string.Equals(x.Path, context.Folder?.ItemPath)) is DriveItem driveItem && | ||
driveItem.Type != DriveType.Network; | ||
|
||
public virtual bool IsAccessibleGlobally | ||
=> true; | ||
|
||
public OpenStorageSenseAction() | ||
{ | ||
context.PropertyChanged += Context_PropertyChanged; | ||
} | ||
|
||
public virtual Task ExecuteAsync(object? parameter = null) | ||
{ | ||
return StorageSenseHelper.OpenStorageSenseAsync(context.Folder?.ItemPath ?? string.Empty); | ||
} | ||
|
||
public void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName is nameof(IContentPageContext.HasItem)) | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Files.App/Actions/Open/OpenStorageSenseFromHomeAction.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,28 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal sealed class OpenStorageSenseFromHomeAction : OpenStorageSenseAction | ||
{ | ||
private IHomePageContext HomePageContext { get; } = Ioc.Default.GetRequiredService<IHomePageContext>(); | ||
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>(); | ||
|
||
public override bool IsExecutable => | ||
HomePageContext.IsAnyItemRightClicked && | ||
HomePageContext.RightClickedItem is not null && | ||
HomePageContext.RightClickedItem.Path is not null && | ||
drivesViewModel.Drives | ||
.Cast<DriveItem>() | ||
.FirstOrDefault(x => string.Equals(x.Path, HomePageContext.RightClickedItem.Path)) is DriveItem driveItem && | ||
driveItem.Type != DriveType.Network; | ||
|
||
public override bool IsAccessibleGlobally | ||
=> false; | ||
|
||
public override Task ExecuteAsync(object? parameter = null) | ||
{ | ||
return StorageSenseHelper.OpenStorageSenseAsync(HomePageContext?.RightClickedItem?.Path ?? string.Empty); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Files.App/Actions/Open/OpenStorageSenseFromSidebarAction.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,28 @@ | ||
// Copyright (c) 2024 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal sealed class OpenStorageSenseFromSidebarAction : OpenStorageSenseAction | ||
{ | ||
private ISidebarContext SidebarContext { get; } = Ioc.Default.GetRequiredService<ISidebarContext>(); | ||
private readonly DrivesViewModel drivesViewModel = Ioc.Default.GetRequiredService<DrivesViewModel>(); | ||
|
||
public override bool IsExecutable => | ||
SidebarContext.IsItemRightClicked && | ||
SidebarContext.RightClickedItem is not null && | ||
SidebarContext.RightClickedItem.Path is not null && | ||
drivesViewModel.Drives | ||
.Cast<DriveItem>() | ||
.FirstOrDefault(x => string.Equals(x.Path, SidebarContext.RightClickedItem.Path)) is DriveItem driveItem && | ||
driveItem.Type != DriveType.Network; | ||
|
||
public override bool IsAccessibleGlobally | ||
=> false; | ||
|
||
public override Task ExecuteAsync(object? parameter = null) | ||
{ | ||
return StorageSenseHelper.OpenStorageSenseAsync(SidebarContext?.RightClickedItem?.Path ?? string.Empty); | ||
} | ||
} | ||
} |
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
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