Skip to content

Commit 6fff25f

Browse files
authored
Code Quality: Removed App.Interacts namespace (#12723)
1 parent 84a62bb commit 6fff25f

22 files changed

+409
-383
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal class OpenDirectoryInNewPaneAction : ObservableObject, IAction
7+
{
8+
private readonly IContentPageContext context;
9+
10+
private readonly IUserSettingsService userSettingsService;
11+
12+
public string Label
13+
=> "OpenInNewPane".GetLocalizedResource();
14+
15+
public string Description
16+
=> "OpenDirectoryInNewPaneDescription".GetLocalizedResource();
17+
18+
public bool IsExecutable =>
19+
context.SelectedItem is not null &&
20+
context.SelectedItem.IsFolder &&
21+
userSettingsService.GeneralSettingsService.ShowOpenInNewPane;
22+
23+
public OpenDirectoryInNewPaneAction()
24+
{
25+
context = Ioc.Default.GetRequiredService<IContentPageContext>();
26+
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
27+
28+
context.PropertyChanged += Context_PropertyChanged;
29+
}
30+
31+
public Task ExecuteAsync()
32+
{
33+
NavigationHelpers.OpenInSecondaryPane(
34+
context.ShellPage,
35+
context.ShellPage.SlimContentPage.SelectedItems.FirstOrDefault());
36+
37+
return Task.CompletedTask;
38+
}
39+
40+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
41+
{
42+
switch (e.PropertyName)
43+
{
44+
case nameof(IContentPageContext.ShellPage):
45+
case nameof(IContentPageContext.PageType):
46+
case nameof(IContentPageContext.HasSelection):
47+
case nameof(IContentPageContext.SelectedItems):
48+
OnPropertyChanged(nameof(IsExecutable));
49+
break;
50+
}
51+
}
52+
}
53+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
namespace Files.App.Actions
5+
{
6+
internal class OpenDirectoryInNewTabAction : ObservableObject, IAction
7+
{
8+
private readonly IContentPageContext context;
9+
10+
private readonly IUserSettingsService userSettingsService;
11+
12+
private readonly MainPageViewModel _mainPageViewModel;
13+
14+
public string Label
15+
=> "OpenInNewTab".GetLocalizedResource();
16+
17+
public string Description
18+
=> "OpenDirectoryInNewTabDescription".GetLocalizedResource();
19+
20+
public RichGlyph Glyph
21+
=> new(opacityStyle: "ColorIconOpenInNewTab");
22+
23+
public bool IsExecutable =>
24+
context.SelectedItems.Count <= 5 &&
25+
context.SelectedItems.Where(x => x.IsFolder == true).Count() == context.SelectedItems.Count &&
26+
userSettingsService.GeneralSettingsService.ShowOpenInNewTab;
27+
28+
public OpenDirectoryInNewTabAction()
29+
{
30+
context = Ioc.Default.GetRequiredService<IContentPageContext>();
31+
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
32+
_mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
33+
34+
context.PropertyChanged += Context_PropertyChanged;
35+
}
36+
37+
public async Task ExecuteAsync()
38+
{
39+
foreach (ListedItem listedItem in context.ShellPage.SlimContentPage.SelectedItems)
40+
{
41+
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
42+
{
43+
await _mainPageViewModel.AddNewTabByPathAsync(
44+
typeof(PaneHolderPage),
45+
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
46+
},
47+
Microsoft.UI.Dispatching.DispatcherQueuePriority.Low);
48+
}
49+
}
50+
51+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
52+
{
53+
switch (e.PropertyName)
54+
{
55+
case nameof(IContentPageContext.ShellPage):
56+
case nameof(IContentPageContext.PageType):
57+
case nameof(IContentPageContext.HasSelection):
58+
case nameof(IContentPageContext.SelectedItems):
59+
OnPropertyChanged(nameof(IsExecutable));
60+
break;
61+
}
62+
}
63+
}
64+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2023 Files Community
2+
// Licensed under the MIT License. See the LICENSE.
3+
4+
using Windows.System;
5+
6+
namespace Files.App.Actions
7+
{
8+
internal class OpenInNewWindowItemAction : ObservableObject, IAction
9+
{
10+
private readonly IContentPageContext context;
11+
12+
private readonly IUserSettingsService userSettingsService;
13+
14+
public string Label
15+
=> "OpenInNewWindow".GetLocalizedResource();
16+
17+
public string Description
18+
=> "OpenInNewWindowDescription".GetLocalizedResource();
19+
20+
public RichGlyph Glyph
21+
=> new(opacityStyle: "ColorIconOpenInNewWindow");
22+
23+
public bool IsExecutable =>
24+
context.SelectedItems.Count <= 5 &&
25+
context.SelectedItems.Where(x => x.IsFolder == true).Count() == context.SelectedItems.Count &&
26+
userSettingsService.GeneralSettingsService.ShowOpenInNewWindow;
27+
28+
public OpenInNewWindowItemAction()
29+
{
30+
context = Ioc.Default.GetRequiredService<IContentPageContext>();
31+
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
32+
33+
context.PropertyChanged += Context_PropertyChanged;
34+
}
35+
36+
public async Task ExecuteAsync()
37+
{
38+
List<ListedItem> items = context.ShellPage.SlimContentPage.SelectedItems;
39+
40+
foreach (ListedItem listedItem in items)
41+
{
42+
var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath;
43+
var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}");
44+
45+
await Launcher.LaunchUriAsync(folderUri);
46+
}
47+
}
48+
49+
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e)
50+
{
51+
switch (e.PropertyName)
52+
{
53+
case nameof(IContentPageContext.ShellPage):
54+
case nameof(IContentPageContext.PageType):
55+
case nameof(IContentPageContext.HasSelection):
56+
case nameof(IContentPageContext.SelectedItems):
57+
OnPropertyChanged(nameof(IsExecutable));
58+
break;
59+
}
60+
}
61+
}
62+
}

src/Files.App/Commands/CommandCodes.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ public enum CommandCodes
171171
CloseTabsToTheRightSelected,
172172
CloseOtherTabsCurrent,
173173
CloseOtherTabsSelected,
174+
OpenDirectoryInNewPane,
175+
OpenDirectoryInNewTab,
176+
OpenInNewWindowItem,
174177
ReopenClosedTab,
175178
PreviousTab,
176179
NextTab,

src/Files.App/Commands/Manager/CommandManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public IRichCommand this[HotKey hotKey]
150150
public IRichCommand CloseTabsToTheRightSelected => commands[CommandCodes.CloseTabsToTheRightSelected];
151151
public IRichCommand CloseOtherTabsCurrent => commands[CommandCodes.CloseOtherTabsCurrent];
152152
public IRichCommand CloseOtherTabsSelected => commands[CommandCodes.CloseOtherTabsSelected];
153+
public IRichCommand OpenDirectoryInNewPaneAction => commands[CommandCodes.OpenDirectoryInNewPane];
154+
public IRichCommand OpenDirectoryInNewTabAction => commands[CommandCodes.OpenDirectoryInNewTab];
155+
public IRichCommand OpenInNewWindowItemAction => commands[CommandCodes.OpenInNewWindowItem];
153156
public IRichCommand ReopenClosedTab => commands[CommandCodes.ReopenClosedTab];
154157
public IRichCommand PreviousTab => commands[CommandCodes.PreviousTab];
155158
public IRichCommand NextTab => commands[CommandCodes.NextTab];
@@ -307,6 +310,9 @@ public CommandManager()
307310
[CommandCodes.CloseTabsToTheRightSelected] = new CloseTabsToTheRightSelectedAction(),
308311
[CommandCodes.CloseOtherTabsCurrent] = new CloseOtherTabsCurrentAction(),
309312
[CommandCodes.CloseOtherTabsSelected] = new CloseOtherTabsSelectedAction(),
313+
[CommandCodes.OpenDirectoryInNewPane] = new OpenDirectoryInNewPaneAction(),
314+
[CommandCodes.OpenDirectoryInNewTab] = new OpenDirectoryInNewTabAction(),
315+
[CommandCodes.OpenInNewWindowItem] = new OpenInNewWindowItemAction(),
310316
[CommandCodes.ReopenClosedTab] = new ReopenClosedTabAction(),
311317
[CommandCodes.PreviousTab] = new PreviousTabAction(),
312318
[CommandCodes.NextTab] = new NextTabAction(),

src/Files.App/Commands/Manager/ICommandManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ public interface ICommandManager : IEnumerable<IRichCommand>
152152
IRichCommand CloseTabsToTheRightSelected { get; }
153153
IRichCommand CloseOtherTabsCurrent { get; }
154154
IRichCommand CloseOtherTabsSelected { get; }
155+
IRichCommand OpenDirectoryInNewPaneAction { get; }
156+
IRichCommand OpenDirectoryInNewTabAction { get; }
157+
IRichCommand OpenInNewWindowItemAction { get; }
155158
IRichCommand ReopenClosedTab { get; }
156159
IRichCommand PreviousTab { get; }
157160
IRichCommand NextTab { get; }

src/Files.App/Interacts/IStatusCenterActions.cs renamed to src/Files.App/Data/Models/IStatusCenterActions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System;
77
using System.Threading;
88

9-
namespace Files.App.Interacts
9+
namespace Files.App.Data.Models
1010
{
1111
public interface IOngoingTasksActions
1212
{

src/Files.App/Interacts/ItemManipulationModel.cs renamed to src/Files.App/Data/Models/ItemManipulationModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77

8-
namespace Files.App.Interacts
8+
namespace Files.App.Data.Models
99
{
1010
public class ItemManipulationModel
1111
{

src/Files.App/Interacts/RemovableDevice.cs renamed to src/Files.App/Data/Models/RemovableDevice.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
using System.Threading.Tasks;
77
using static Files.App.Helpers.NativeIoDeviceControlHelper;
88

9-
namespace Files.App.Interacts
9+
namespace Files.App.Data.Models
1010
{
1111
public class RemovableDevice
1212
{
13-
private IntPtr handle;
13+
private nint handle;
1414
private char driveLetter;
1515

1616
public RemovableDevice(string letter)
@@ -22,7 +22,7 @@ public RemovableDevice(string letter)
2222
handle = CreateFileFromAppW(filename,
2323
GENERIC_READ | GENERIC_WRITE,
2424
FILE_SHARE_READ | FILE_SHARE_WRITE,
25-
IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
25+
nint.Zero, OPEN_EXISTING, 0, nint.Zero);
2626
}
2727

2828
public async Task<bool> EjectAsync()
@@ -52,7 +52,7 @@ private async Task<bool> LockVolumeAsync()
5252

5353
for (int i = 0; i < 5; i++)
5454
{
55-
if (DeviceIoControl(handle, FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out _, IntPtr.Zero))
55+
if (DeviceIoControl(handle, FSCTL_LOCK_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero))
5656
{
5757
Debug.WriteLine("Lock successful!");
5858
result = true;
@@ -72,20 +72,20 @@ private async Task<bool> LockVolumeAsync()
7272

7373
private bool DismountVolume()
7474
{
75-
return DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out _, IntPtr.Zero);
75+
return DeviceIoControl(handle, FSCTL_DISMOUNT_VOLUME, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero);
7676
}
7777

7878
private bool PreventRemovalOfVolume(bool prevent)
7979
{
8080
byte[] buf = new byte[1];
8181
buf[0] = prevent ? (byte)1 : (byte)0;
8282

83-
return DeviceIoControl(handle, IOCTL_STORAGE_MEDIA_REMOVAL, buf, 1, IntPtr.Zero, 0, out _, IntPtr.Zero);
83+
return DeviceIoControl(handle, IOCTL_STORAGE_MEDIA_REMOVAL, buf, 1, nint.Zero, 0, out _, nint.Zero);
8484
}
8585

8686
private bool AutoEjectVolume()
8787
{
88-
return DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, out _, IntPtr.Zero);
88+
return DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, nint.Zero, 0, nint.Zero, 0, out _, nint.Zero);
8989
}
9090

9191
private bool CloseVolume()

src/Files.App/GlobalUsings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
global using global::Files.App.Data.Items;
4545
global using global::Files.App.Data.Models;
4646
global using global::Files.App.Data.Parameters;
47-
global using global::Files.App.Interacts;
4847
global using global::Files.App.UserControls;
4948
global using global::Files.App.ViewModels;
5049
global using global::Files.App.ViewModels.UserControls;

0 commit comments

Comments
 (0)