Skip to content

Commit

Permalink
Code Quality: Moved static methods from MainPageViewModel to Navigati…
Browse files Browse the repository at this point in the history
…onHelpers (#14027)
  • Loading branch information
0x5bfa authored Nov 24, 2023
1 parent a7c48dd commit 237dca7
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 371 deletions.
15 changes: 10 additions & 5 deletions src/Files.App/Actions/Navigation/DuplicateCurrentTabAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ internal class DuplicateCurrentTabAction : IAction
{
private readonly IMultitaskingContext context;

private readonly MainPageViewModel mainPageViewModel;

public string Label
=> "DuplicateTab".GetLocalizedResource();

Expand All @@ -18,16 +16,23 @@ public string Description
public DuplicateCurrentTabAction()
{
context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
}

public async Task ExecuteAsync()
{
var arguments = context.CurrentTabItem.NavigationParameter;

if (arguments is null)
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
}
else
await mainPageViewModel.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.CurrentTabIndex + 1);
{
await NavigationHelpers.AddNewTabByParamAsync(
arguments.InitialPageType,
arguments.NavigationParameter,
context.CurrentTabIndex + 1);
}
}
}
}
12 changes: 7 additions & 5 deletions src/Files.App/Actions/Navigation/DuplicateSelectedTabAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ internal class DuplicateSelectedTabAction : IAction
{
private readonly IMultitaskingContext context;

private readonly MainPageViewModel mainPageViewModel;

public string Label
=> "DuplicateTab".GetLocalizedResource();

Expand All @@ -21,16 +19,20 @@ public HotKey HotKey
public DuplicateSelectedTabAction()
{
context = Ioc.Default.GetRequiredService<IMultitaskingContext>();
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
}

public async Task ExecuteAsync()
{
var arguments = context.SelectedTabItem.NavigationParameter;

if (arguments is null)
await mainPageViewModel.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
{
await NavigationHelpers.AddNewTabByPathAsync(typeof(PaneHolderPage), "Home");
}
else
await mainPageViewModel.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.SelectedTabIndex + 1);
{
await NavigationHelpers.AddNewTabByParamAsync(arguments.InitialPageType, arguments.NavigationParameter, context.SelectedTabIndex + 1);
}
}
}
}
5 changes: 1 addition & 4 deletions src/Files.App/Actions/Navigation/NewTabAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ namespace Files.App.Actions
{
internal class NewTabAction : IAction
{
private readonly MainPageViewModel mainPageViewModel;

public string Label
=> "NewTab".GetLocalizedResource();

Expand All @@ -18,12 +16,11 @@ public HotKey HotKey

public NewTabAction()
{
mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();
}

public Task ExecuteAsync()
{
return mainPageViewModel.AddNewTabAsync();
return NavigationHelpers.AddNewTabAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ internal class OpenDirectoryInNewTabAction : ObservableObject, IAction

private readonly IUserSettingsService userSettingsService;

private readonly MainPageViewModel _mainPageViewModel;

public string Label
=> "OpenInNewTab".GetLocalizedResource();

Expand All @@ -31,7 +29,6 @@ public OpenDirectoryInNewTabAction()
{
context = Ioc.Default.GetRequiredService<IContentPageContext>();
userSettingsService = Ioc.Default.GetRequiredService<IUserSettingsService>();
_mainPageViewModel = Ioc.Default.GetRequiredService<MainPageViewModel>();

context.PropertyChanged += Context_PropertyChanged;
}
Expand All @@ -45,7 +42,7 @@ public async Task ExecuteAsync()
{
await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await _mainPageViewModel.AddNewTabByPathAsync(
await NavigationHelpers.AddNewTabByPathAsync(
typeof(PaneHolderPage),
(listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath);
},
Expand Down
Loading

0 comments on commit 237dca7

Please sign in to comment.