Skip to content

Commit 237dca7

Browse files
authored
Code Quality: Moved static methods from MainPageViewModel to NavigationHelpers (#14027)
1 parent a7c48dd commit 237dca7

File tree

12 files changed

+359
-371
lines changed

12 files changed

+359
-371
lines changed

src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ internal class DuplicateCurrentTabAction : IAction
77
{
88
private readonly IMultitaskingContext context;
99

10-
private readonly MainPageViewModel mainPageViewModel;
11-
1210
public string Label
1311
=> "DuplicateTab".GetLocalizedResource();
1412

@@ -18,16 +16,23 @@ public string Description
1816
public DuplicateCurrentTabAction()
1917
{
2018
context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
21-
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
2219
}
2320

2421
public async Task ExecuteAsync()
2522
{
2623
var arguments = context.CurrentTabItem.NavigationParameter;
24+
2725
if (arguments is null)
28-
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
26+
{
27+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
28+
}
2929
else
30-
await mainPageViewModel.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.CurrentTabIndex + 1);
30+
{
31+
await NavigationHelpers.AddNewTabByParamAsync(
32+
arguments.InitialPageType,
33+
arguments.NavigationParameter,
34+
context.CurrentTabIndex + 1);
35+
}
3136
}
3237
}
3338
}

src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ internal class DuplicateSelectedTabAction : IAction
77
{
88
private readonly IMultitaskingContext context;
99

10-
private readonly MainPageViewModel mainPageViewModel;
11-
1210
public string Label
1311
=> "DuplicateTab".GetLocalizedResource();
1412

@@ -21,16 +19,20 @@ public HotKey HotKey
2119
public DuplicateSelectedTabAction()
2220
{
2321
context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
24-
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
2522
}
2623

2724
public async Task ExecuteAsync()
2825
{
2926
var arguments = context.SelectedTabItem.NavigationParameter;
27+
3028
if (arguments is null)
31-
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
29+
{
30+
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
31+
}
3232
else
33-
await mainPageViewModel.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.SelectedTabIndex + 1);
33+
{
34+
await NavigationHelpers.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.SelectedTabIndex + 1);
35+
}
3436
}
3537
}
3638
}

src/Files.App/Actions/Navigation/NewTabAction.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace Files.App.Actions
55
{
66
internal class NewTabAction : IAction
77
{
8-
private readonly MainPageViewModel mainPageViewModel;
9-
108
public string Label
119
=> "NewTab".GetLocalizedResource();
1210

@@ -18,12 +16,11 @@ public HotKey HotKey
1816

1917
public NewTabAction()
2018
{
21-
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
2219
}
2320

2421
public Task ExecuteAsync()
2522
{
26-
return mainPageViewModel.AddNewTabAsync();
23+
return NavigationHelpers.AddNewTabAsync();
2724
}
2825
}
2926
}

src/Files.App/Actions/Navigation/OpenDirectoryInNewTabAction.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ internal class OpenDirectoryInNewTabAction : ObservableObject, IAction
99

1010
private readonly IUserSettingsService userSettingsService;
1111

12-
private readonly MainPageViewModel _mainPageViewModel;
13-
1412
public string Label
1513
=> "OpenInNewTab".GetLocalizedResource();
1614

@@ -31,7 +29,6 @@ public OpenDirectoryInNewTabAction()
3129
{
3230
context = Ioc.Default.GetRequiredService<IContentPageContext>();
3331
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
34-
_mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
3532

3633
context.PropertyChanged += Context_PropertyChanged;
3734
}
@@ -45,7 +42,7 @@ public async Task ExecuteAsync()
4542
{
4643
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
4744
{
48-
await _mainPageViewModel.AddNewTabByPathAsync(
45+
await NavigationHelpers.AddNewTabByPathAsync(
4946
typeof(PaneHolderPage),
5047
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
5148
},

0 commit comments

Comments
 (0)