From 867949b349d9d54079e1a274fe7f0a93de16a830 Mon Sep 17 00:00:00 2001 From: Yair <39923744+yaira2@users.noreply.github.com> Date: Sun, 6 Apr 2025 16:26:45 -0400 Subject: [PATCH] Feature: Replaced settings dialog with page --- .../Actions/Open/OpenSettingsAction.cs | 27 ++-- src/Files.App/Data/Contracts/IShellPage.cs | 5 + src/Files.App/Dialogs/SettingsDialog.xaml.cs | 86 ------------ .../Helpers/Application/AppLifecycleHelper.cs | 2 +- .../Helpers/Navigation/NavigationHelpers.cs | 16 +-- .../Services/App/AppDialogService.cs | 1 - .../Storage/Helpers/StorageFileExtensions.cs | 5 +- .../Dialogs/SettingsDialogViewModel.cs | 9 -- .../ViewModels/Settings/SettingsViewModel.cs | 9 ++ .../NavigationToolbarViewModel.cs | 11 +- src/Files.App/Views/ReleaseNotesPage.xaml.cs | 2 +- src/Files.App/Views/Settings/AboutPage.xaml | 7 - src/Files.App/Views/Settings/ActionsPage.xaml | 7 - .../Views/Settings/AdvancedPage.xaml | 7 - .../Views/Settings/AppearancePage.xaml | 7 - .../Views/Settings/DevToolsPage.xaml | 7 - src/Files.App/Views/Settings/FoldersPage.xaml | 7 - src/Files.App/Views/Settings/GeneralPage.xaml | 7 - src/Files.App/Views/Settings/LayoutPage.xaml | 7 - .../Settings/SettingsPage.xaml} | 93 ++++++------- .../Views/Settings/SettingsPage.xaml.cs | 130 ++++++++++++++++++ src/Files.App/Views/Settings/TagsPage.xaml | 7 - src/Files.App/Views/Shells/BaseShellPage.cs | 2 + .../Views/Shells/ColumnShellPage.xaml.cs | 5 + .../Views/Shells/ModernShellPage.xaml.cs | 27 ++-- 25 files changed, 244 insertions(+), 249 deletions(-) delete mode 100644 src/Files.App/Dialogs/SettingsDialog.xaml.cs delete mode 100644 src/Files.App/ViewModels/Dialogs/SettingsDialogViewModel.cs create mode 100644 src/Files.App/ViewModels/Settings/SettingsViewModel.cs rename src/Files.App/{Dialogs/SettingsDialog.xaml => Views/Settings/SettingsPage.xaml} (71%) create mode 100644 src/Files.App/Views/Settings/SettingsPage.xaml.cs diff --git a/src/Files.App/Actions/Open/OpenSettingsAction.cs b/src/Files.App/Actions/Open/OpenSettingsAction.cs index 80f1d03531f4..1126f4415a74 100644 --- a/src/Files.App/Actions/Open/OpenSettingsAction.cs +++ b/src/Files.App/Actions/Open/OpenSettingsAction.cs @@ -5,11 +5,9 @@ namespace Files.App.Actions { - internal sealed partial class OpenSettingsAction : BaseUIAction, IAction + internal sealed partial class OpenSettingsAction : ObservableObject, IAction { - private readonly IDialogService dialogService = Ioc.Default.GetRequiredService(); - - private readonly SettingsDialogViewModel viewModel = new(); + private readonly IContentPageContext context = Ioc.Default.GetRequiredService(); public string Label => Strings.Settings.GetLocalizedResource(); @@ -22,11 +20,20 @@ public HotKey HotKey public Task ExecuteAsync(object? parameter = null) { - var dialog = dialogService.GetDialog(viewModel); - if (parameter is not null && parameter is SettingsNavigationParams navParams) - ((SettingsDialog)dialog).NavigateTo(navParams); - - return dialog.TryShowAsync(); + // Find index of existing Settings tab or open new one + var existingTabIndex = MainPageViewModel.AppInstances + .Select((tabItem, index) => new { TabItem = tabItem, Index = index }) + .FirstOrDefault(item => + item.TabItem.NavigationParameter.NavigationParameter is PaneNavigationArguments paneArgs && + (paneArgs.LeftPaneNavPathParam == "Settings" || paneArgs.RightPaneNavPathParam == "Settings")) + ?.Index ?? -1; + + if (existingTabIndex >= 0) + App.AppModel.TabStripSelectedIndex = existingTabIndex; + else + NavigationHelpers.OpenPathInNewTab("Settings", true); + + return Task.CompletedTask; } } -} +} \ No newline at end of file diff --git a/src/Files.App/Data/Contracts/IShellPage.cs b/src/Files.App/Data/Contracts/IShellPage.cs index fdf28822d652..5a973efa912e 100644 --- a/src/Files.App/Data/Contracts/IShellPage.cs +++ b/src/Files.App/Data/Contracts/IShellPage.cs @@ -70,6 +70,11 @@ public interface IShellPage : ITabBarItemContent, IMultiPaneInfo, IDisposable, I /// Navigates to the release notes page /// public void NavigateToReleaseNotes(); + + /// + /// Navigates to the settings page + /// + public void NavigateToSettings(); void NavigateWithArguments(Type sourcePageType, NavigationArguments navArgs); diff --git a/src/Files.App/Dialogs/SettingsDialog.xaml.cs b/src/Files.App/Dialogs/SettingsDialog.xaml.cs deleted file mode 100644 index 0147a2533344..000000000000 --- a/src/Files.App/Dialogs/SettingsDialog.xaml.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) Files Community -// Licensed under the MIT License. - -using Files.App.Views.Settings; -using Microsoft.UI.Xaml; -using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Media.Animation; - -namespace Files.App.Dialogs -{ - public sealed partial class SettingsDialog : ContentDialog, IDialog - { - public SettingsDialogViewModel ViewModel { get; set; } - - private FrameworkElement RootAppElement - => (FrameworkElement)MainWindow.Instance.Content; - - public SettingsDialog() - { - InitializeComponent(); - - MainWindow.Instance.SizeChanged += Current_SizeChanged; - UpdateDialogLayout(); - } - - public new async Task ShowAsync() - { - return (DialogResult)await base.ShowAsync(); - } - - public void NavigateTo(SettingsNavigationParams navParams) - { - var defaultTag = SettingsPageKind.AppearancePage.ToString(); - var oldSelection = MainSettingsNavigationView.MenuItems.FirstOrDefault(item => ((NavigationViewItem)item).IsSelected) as NavigationViewItem; - var targetSection = MainSettingsNavigationView.MenuItems.FirstOrDefault( - item => Enum.Parse(((NavigationViewItem)item).Tag.ToString() ?? defaultTag) == navParams.PageKind - ); - if (oldSelection is not null) - oldSelection.IsSelected = false; - - MainSettingsNavigationView.SelectedItem = targetSection; - } - - private void Current_SizeChanged(object sender, WindowSizeChangedEventArgs e) - { - UpdateDialogLayout(); - } - - private void UpdateDialogLayout() - { - ContainerGrid.Height = MainWindow.Instance.Bounds.Height <= 760 ? MainWindow.Instance.Bounds.Height - 70 : 690; - ContainerGrid.Width = MainWindow.Instance.Bounds.Width <= 1100 ? MainWindow.Instance.Bounds.Width : 1100; - MainSettingsNavigationView.PaneDisplayMode = MainWindow.Instance.Bounds.Width < 700 ? NavigationViewPaneDisplayMode.LeftCompact : NavigationViewPaneDisplayMode.Left; - } - - private void MainSettingsNavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) - { - SettingsContentScrollViewer.ChangeView(null, 0, null, true); - var selectedItem = (NavigationViewItem)args.SelectedItem; - - _ = Enum.Parse(selectedItem.Tag.ToString()) switch - { - SettingsPageKind.GeneralPage => SettingsContentFrame.Navigate(typeof(GeneralPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.AppearancePage => SettingsContentFrame.Navigate(typeof(AppearancePage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.LayoutPage => SettingsContentFrame.Navigate(typeof(LayoutPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.FoldersPage => SettingsContentFrame.Navigate(typeof(FoldersPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.ActionsPage => SettingsContentFrame.Navigate(typeof(ActionsPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.TagsPage => SettingsContentFrame.Navigate(typeof(TagsPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.DevToolsPage => SettingsContentFrame.Navigate(typeof(DevToolsPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.AdvancedPage => SettingsContentFrame.Navigate(typeof(AdvancedPage), null, new SuppressNavigationTransitionInfo()), - SettingsPageKind.AboutPage => SettingsContentFrame.Navigate(typeof(AboutPage), null, new SuppressNavigationTransitionInfo()), - _ => SettingsContentFrame.Navigate(typeof(AppearancePage), null, new SuppressNavigationTransitionInfo()) - }; - } - - private void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) - { - MainWindow.Instance.SizeChanged -= Current_SizeChanged; - } - - private void CloseSettingsDialogButton_Click(object sender, RoutedEventArgs e) - { - Hide(); - } - } -} diff --git a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs index 571ffbc1d128..4adbb16e1dc3 100644 --- a/src/Files.App/Helpers/Application/AppLifecycleHelper.cs +++ b/src/Files.App/Helpers/Application/AppLifecycleHelper.cs @@ -246,7 +246,7 @@ public static IHost ConfigureHost() .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() // Utilities .AddSingleton() .AddSingleton() diff --git a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs index 8cdf346e50ae..64aade24b3a4 100644 --- a/src/Files.App/Helpers/Navigation/NavigationHelpers.cs +++ b/src/Files.App/Helpers/Navigation/NavigationHelpers.cs @@ -159,9 +159,8 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati imageSource = new BitmapImage(new Uri(Constants.FluentIconsPaths.HomeIcon)); else if (path == "ReleaseNotes") imageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); - // TODO add settings page - //else if (path == "Settings") - // imageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); + else if (path == "Settings") + imageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); else if (WSLDistroManager.TryGetDistro(path, out WslDistroItem? wslDistro) && path.Equals(wslDistro.Path)) imageSource = new BitmapImage(wslDistro.Icon); else @@ -202,12 +201,11 @@ private static async Task UpdateTabInfoAsync(TabBarItem tabItem, object navigati tabLocationHeader = Strings.ReleaseNotes.GetLocalizedResource(); iconSource.ImageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); } - // TODO add settings page - //else if (currentPath == "Settings") - //{ - // tabLocationHeader = Strings.Settings.GetLocalizedResource(); - // iconSource.ImageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); - //} + else if (currentPath == "Settings") + { + tabLocationHeader = Strings.Settings.GetLocalizedResource(); + iconSource.ImageSource = new BitmapImage(new Uri(AppLifecycleHelper.AppIconPath)); + } else if (currentPath.Equals(Constants.UserEnvironmentPaths.DesktopPath, StringComparison.OrdinalIgnoreCase)) tabLocationHeader = Strings.Desktop.GetLocalizedResource(); else if (currentPath.Equals(Constants.UserEnvironmentPaths.DownloadsPath, StringComparison.OrdinalIgnoreCase)) diff --git a/src/Files.App/Services/App/AppDialogService.cs b/src/Files.App/Services/App/AppDialogService.cs index d5859b77d53d..0eb6c18a4078 100644 --- a/src/Files.App/Services/App/AppDialogService.cs +++ b/src/Files.App/Services/App/AppDialogService.cs @@ -28,7 +28,6 @@ public DialogService() { typeof(ElevateConfirmDialogViewModel), () => new ElevateConfirmDialog() }, { typeof(FileSystemDialogViewModel), () => new FilesystemOperationDialog() }, { typeof(DecompressArchiveDialogViewModel), () => new DecompressArchiveDialog() }, - { typeof(SettingsDialogViewModel), () => new SettingsDialog() }, { typeof(CreateShortcutDialogViewModel), () => new CreateShortcutDialog() }, { typeof(ReorderSidebarItemsDialogViewModel), () => new ReorderSidebarItemsDialog() }, { typeof(AddBranchDialogViewModel), () => new AddBranchDialog() }, diff --git a/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs b/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs index 4e34d36aebbc..a5419f49166b 100644 --- a/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs +++ b/src/Files.App/Utils/Storage/Helpers/StorageFileExtensions.cs @@ -142,9 +142,8 @@ public static async Task> GetDirectoryPathComponentsWithDispla item.Title = Strings.Home.GetLocalizedResource(); if (item.Path == "ReleaseNotes") item.Title = Strings.ReleaseNotes.GetLocalizedResource(); - // TODO add settings page - //if (item.Path == "Settings") - // item.Title = Strings.Settings.GetLocalizedResource(); + if (item.Path == "Settings") + item.Title = Strings.Settings.GetLocalizedResource(); else { BaseStorageFolder folder = await FilesystemTasks.Wrap(() => DangerousGetFolderFromPathAsync(item.Path)); diff --git a/src/Files.App/ViewModels/Dialogs/SettingsDialogViewModel.cs b/src/Files.App/ViewModels/Dialogs/SettingsDialogViewModel.cs deleted file mode 100644 index ac9dc60a3b0c..000000000000 --- a/src/Files.App/ViewModels/Dialogs/SettingsDialogViewModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) Files Community -// Licensed under the MIT License. - -namespace Files.App.ViewModels.Dialogs -{ - public sealed partial class SettingsDialogViewModel : ObservableObject - { - } -} diff --git a/src/Files.App/ViewModels/Settings/SettingsViewModel.cs b/src/Files.App/ViewModels/Settings/SettingsViewModel.cs new file mode 100644 index 000000000000..8bb441aa2d2e --- /dev/null +++ b/src/Files.App/ViewModels/Settings/SettingsViewModel.cs @@ -0,0 +1,9 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +namespace Files.App.ViewModels +{ + public sealed partial class SettingsViewModel : ObservableObject + { + } +} diff --git a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs index 455aea1d3c4a..a3bbf8d6148c 100644 --- a/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs +++ b/src/Files.App/ViewModels/UserControls/NavigationToolbarViewModel.cs @@ -779,12 +779,11 @@ await DialogDisplayHelper.ShowDialogAsync(Strings.CommandNotExecutable.GetLocali SavePathToHistory("ReleaseNotes"); shellPage.NavigateToReleaseNotes(); } - // TODO add settings page - //else if (normalizedInput.Equals("Settings", StringComparison.OrdinalIgnoreCase) || normalizedInput.Equals(Strings.Settings.GetLocalizedResource(), StringComparison.OrdinalIgnoreCase)) - //{ - // SavePathToHistory("Settings"); - // shellPage.NavigateToReleaseNotes(); - //} + else if (normalizedInput.Equals("Settings", StringComparison.OrdinalIgnoreCase) || normalizedInput.Equals(Strings.Settings.GetLocalizedResource(), StringComparison.OrdinalIgnoreCase)) + { + SavePathToHistory("Settings"); + shellPage.NavigateToReleaseNotes(); + } else { normalizedInput = StorageFileExtensions.GetResolvedPath(normalizedInput, isFtp); diff --git a/src/Files.App/Views/ReleaseNotesPage.xaml.cs b/src/Files.App/Views/ReleaseNotesPage.xaml.cs index c587062f3c37..b9ebb8de74ae 100644 --- a/src/Files.App/Views/ReleaseNotesPage.xaml.cs +++ b/src/Files.App/Views/ReleaseNotesPage.xaml.cs @@ -14,7 +14,6 @@ public sealed partial class ReleaseNotesPage : Page, IDisposable // Dependency injections public ReleaseNotesViewModel ViewModel { get; } = Ioc.Default.GetRequiredService(); - private FrameworkElement RootAppElement => (FrameworkElement)MainWindow.Instance.Content; @@ -43,6 +42,7 @@ protected override async void OnNavigatedTo(NavigationEventArgs e) AppInstance.InstanceViewModel.GitRepositoryPath = null; AppInstance.InstanceViewModel.IsGitRepository = false; AppInstance.InstanceViewModel.IsPageTypeReleaseNotes = true; + AppInstance.InstanceViewModel.IsPageTypeSettings = false; AppInstance.ToolbarViewModel.CanRefresh = false; AppInstance.ToolbarViewModel.CanGoBack = AppInstance.CanNavigateBackward; AppInstance.ToolbarViewModel.CanGoForward = AppInstance.CanNavigateForward; diff --git a/src/Files.App/Views/Settings/AboutPage.xaml b/src/Files.App/Views/Settings/AboutPage.xaml index 52a8b3eb841e..ea2be17795b9 100644 --- a/src/Files.App/Views/Settings/AboutPage.xaml +++ b/src/Files.App/Views/Settings/AboutPage.xaml @@ -22,13 +22,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - - - - diff --git a/src/Files.App/Views/Settings/AdvancedPage.xaml b/src/Files.App/Views/Settings/AdvancedPage.xaml index 3bd7abf2c820..15bb166e1707 100644 --- a/src/Files.App/Views/Settings/AdvancedPage.xaml +++ b/src/Files.App/Views/Settings/AdvancedPage.xaml @@ -28,13 +28,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - - - - diff --git a/src/Files.App/Views/Settings/DevToolsPage.xaml b/src/Files.App/Views/Settings/DevToolsPage.xaml index 51049b070199..5ced88c5a711 100644 --- a/src/Files.App/Views/Settings/DevToolsPage.xaml +++ b/src/Files.App/Views/Settings/DevToolsPage.xaml @@ -38,13 +38,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - diff --git a/src/Files.App/Views/Settings/FoldersPage.xaml b/src/Files.App/Views/Settings/FoldersPage.xaml index 4ca4000fa3cf..974a20ba9496 100644 --- a/src/Files.App/Views/Settings/FoldersPage.xaml +++ b/src/Files.App/Views/Settings/FoldersPage.xaml @@ -21,13 +21,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - - - - diff --git a/src/Files.App/Views/Settings/LayoutPage.xaml b/src/Files.App/Views/Settings/LayoutPage.xaml index 901832a9e3e7..f161280eafb7 100644 --- a/src/Files.App/Views/Settings/LayoutPage.xaml +++ b/src/Files.App/Views/Settings/LayoutPage.xaml @@ -28,13 +28,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - diff --git a/src/Files.App/Dialogs/SettingsDialog.xaml b/src/Files.App/Views/Settings/SettingsPage.xaml similarity index 71% rename from src/Files.App/Dialogs/SettingsDialog.xaml rename to src/Files.App/Views/Settings/SettingsPage.xaml index 451a492f67d2..a8b8f23b9726 100644 --- a/src/Files.App/Dialogs/SettingsDialog.xaml +++ b/src/Files.App/Views/Settings/SettingsPage.xaml @@ -1,78 +1,45 @@ - - + - 1100 - 0 - - - - - - - - + + - - - - - - + + + + @@ -163,11 +137,32 @@ - - + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/Files.App/Views/Settings/SettingsPage.xaml.cs b/src/Files.App/Views/Settings/SettingsPage.xaml.cs new file mode 100644 index 000000000000..83e6adebb2b2 --- /dev/null +++ b/src/Files.App/Views/Settings/SettingsPage.xaml.cs @@ -0,0 +1,130 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +using Files.App.Views.Settings; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Media.Animation; +using Microsoft.UI.Xaml.Navigation; + +namespace Files.App.Views +{ + public sealed partial class SettingsPage : Page + { + // Dependency injections + public SettingsViewModel ViewModel { get; } = Ioc.Default.GetRequiredService(); + + private FrameworkElement RootAppElement + => (FrameworkElement)MainWindow.Instance.Content; + + private IShellPage AppInstance { get; set; } = null!; + + public SettingsPage() + { + InitializeComponent(); + + // Manually invoke the UpdateVisualStates event to ensure the visual state is set correctly when the page is first loaded + UpdateVisualStates(this.Width); + } + + protected override async void OnNavigatedTo(NavigationEventArgs e) + { + if (e.Parameter is not NavigationArguments parameters) + return; + + AppInstance = parameters.AssociatedTabInstance!; + + AppInstance.InstanceViewModel.IsPageTypeNotHome = true; + AppInstance.InstanceViewModel.IsPageTypeSearchResults = false; + AppInstance.InstanceViewModel.IsPageTypeMtpDevice = false; + AppInstance.InstanceViewModel.IsPageTypeRecycleBin = false; + AppInstance.InstanceViewModel.IsPageTypeCloudDrive = false; + AppInstance.InstanceViewModel.IsPageTypeFtp = false; + AppInstance.InstanceViewModel.IsPageTypeZipFolder = false; + AppInstance.InstanceViewModel.IsPageTypeLibrary = false; + AppInstance.InstanceViewModel.GitRepositoryPath = null; + AppInstance.InstanceViewModel.IsGitRepository = false; + AppInstance.InstanceViewModel.IsPageTypeReleaseNotes = false; + AppInstance.InstanceViewModel.IsPageTypeSettings = true; + AppInstance.ToolbarViewModel.CanRefresh = false; + AppInstance.ToolbarViewModel.CanGoBack = AppInstance.CanNavigateBackward; + AppInstance.ToolbarViewModel.CanGoForward = AppInstance.CanNavigateForward; + AppInstance.ToolbarViewModel.CanNavigateToParent = false; + + // Set path of working directory empty + await AppInstance.ShellViewModel.SetWorkingDirectoryAsync("Settings"); + AppInstance.ShellViewModel.CheckForBackgroundImage(); + + AppInstance.SlimContentPage?.StatusBarViewModel.UpdateGitInfo(false, string.Empty, null); + + AppInstance.ToolbarViewModel.PathComponents.Clear(); + + string componentLabel = + parameters?.NavPathParam == "Settings" + ? Strings.Settings.GetLocalizedResource() + : parameters?.NavPathParam + ?? string.Empty; + + string tag = parameters?.NavPathParam ?? string.Empty; + + var item = new PathBoxItem() + { + Title = componentLabel, + Path = tag, + }; + + AppInstance.ToolbarViewModel.PathComponents.Add(item); + + base.OnNavigatedTo(e); + } + + public void NavigateTo(SettingsNavigationParams navParams) + { + var defaultTag = SettingsPageKind.AppearancePage.ToString(); + var oldSelection = MainSettingsNavigationView.MenuItems.FirstOrDefault(item => ((NavigationViewItem)item).IsSelected) as NavigationViewItem; + var targetSection = MainSettingsNavigationView.MenuItems.FirstOrDefault( + item => Enum.Parse(((NavigationViewItem)item).Tag.ToString() ?? defaultTag) == navParams.PageKind + ); + if (oldSelection is not null) + oldSelection.IsSelected = false; + + MainSettingsNavigationView.SelectedItem = targetSection; + } + + private void MainSettingsNavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) + { + SettingsContentScrollViewer.ChangeView(null, 0, null, true); + var selectedItem = (NavigationViewItem)args.SelectedItem; + + _ = Enum.Parse(selectedItem.Tag.ToString()) switch + { + SettingsPageKind.GeneralPage => SettingsContentFrame.Navigate(typeof(GeneralPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.AppearancePage => SettingsContentFrame.Navigate(typeof(AppearancePage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.LayoutPage => SettingsContentFrame.Navigate(typeof(LayoutPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.FoldersPage => SettingsContentFrame.Navigate(typeof(FoldersPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.ActionsPage => SettingsContentFrame.Navigate(typeof(ActionsPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.TagsPage => SettingsContentFrame.Navigate(typeof(TagsPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.DevToolsPage => SettingsContentFrame.Navigate(typeof(DevToolsPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.AdvancedPage => SettingsContentFrame.Navigate(typeof(AdvancedPage), null, new SuppressNavigationTransitionInfo()), + SettingsPageKind.AboutPage => SettingsContentFrame.Navigate(typeof(AboutPage), null, new SuppressNavigationTransitionInfo()), + _ => SettingsContentFrame.Navigate(typeof(AppearancePage), null, new SuppressNavigationTransitionInfo()) + }; + + PageHeaderTextBlock.Text = selectedItem.Content.ToString(); + } + + private void Page_SizeChanged(object sender, SizeChangedEventArgs e) + { + UpdateVisualStates(e.NewSize.Width); + } + + private void UpdateVisualStates(double pageWidth) + { + // Define your width threshold (e.g., 700 pixels) + if (pageWidth < 700) + VisualStateManager.GoToState(this, "Narrow", true); + else + VisualStateManager.GoToState(this, "Wide", true); + } + } +} diff --git a/src/Files.App/Views/Settings/TagsPage.xaml b/src/Files.App/Views/Settings/TagsPage.xaml index 1a1d0fe70246..ee164474b04c 100644 --- a/src/Files.App/Views/Settings/TagsPage.xaml +++ b/src/Files.App/Views/Settings/TagsPage.xaml @@ -39,13 +39,6 @@ VerticalAlignment="Stretch" Spacing="4"> - - - diff --git a/src/Files.App/Views/Shells/BaseShellPage.cs b/src/Files.App/Views/Shells/BaseShellPage.cs index 76000bad73c3..0f133ba87129 100644 --- a/src/Files.App/Views/Shells/BaseShellPage.cs +++ b/src/Files.App/Views/Shells/BaseShellPage.cs @@ -808,6 +808,8 @@ private void HandleBackForwardRequest(PageStackEntry pageContent) public abstract void NavigateToReleaseNotes(); + public abstract void NavigateToSettings(); + public abstract void NavigateToPath(string? navigationPath, Type? sourcePageType, NavigationArguments? navArgs = null); private void UpdateDateDisplayTimer_Tick(object sender, object e) diff --git a/src/Files.App/Views/Shells/ColumnShellPage.xaml.cs b/src/Files.App/Views/Shells/ColumnShellPage.xaml.cs index 4c8accff8cf1..71e4a7bd9c01 100644 --- a/src/Files.App/Views/Shells/ColumnShellPage.xaml.cs +++ b/src/Files.App/Views/Shells/ColumnShellPage.xaml.cs @@ -190,6 +190,11 @@ public override void NavigateToReleaseNotes() this.FindAscendant()?.ParentShellPageInstance?.NavigateToReleaseNotes(); } + public override void NavigateToSettings() + { + this.FindAscendant()?.ParentShellPageInstance?.NavigateToSettings(); + } + public override Task WhenIsCurrent() => Task.WhenAll(_IsCurrentInstanceTCS.Task, this.FindAscendant()?.ParentShellPageInstance?.WhenIsCurrent() ?? Task.CompletedTask); } diff --git a/src/Files.App/Views/Shells/ModernShellPage.xaml.cs b/src/Files.App/Views/Shells/ModernShellPage.xaml.cs index f876feec5dcf..9b8e4b17d334 100644 --- a/src/Files.App/Views/Shells/ModernShellPage.xaml.cs +++ b/src/Files.App/Views/Shells/ModernShellPage.xaml.cs @@ -99,17 +99,10 @@ protected override void OnNavigationParamsChanged() AssociatedTabInstance = this }, new SuppressNavigationTransitionInfo()); } - // TODO add settings page - //else if (NavParams.NavPath == "Settings") - //{ - // ItemDisplayFrame.Navigate( - // typeof(ReleaseNotesPage), - // new NavigationArguments() - // { - // NavPathParam = NavParams?.NavPath, - // AssociatedTabInstance = this - // }, new SuppressNavigationTransitionInfo()); - //} + else if (NavParams.NavPath == "Settings") + { + NavigateToSettings(); + } else { var isTagSearch = NavParams.NavPath.StartsWith("tag:"); @@ -300,6 +293,18 @@ public override void NavigateToReleaseNotes() }, new SuppressNavigationTransitionInfo()); } + + public override void NavigateToSettings() + { + ItemDisplayFrame.Navigate( + typeof(SettingsPage), + new NavigationArguments() + { + NavPathParam = "Settings", + AssociatedTabInstance = this + }, + new SuppressNavigationTransitionInfo()); + } public override void NavigateToPath(string? navigationPath, Type? sourcePageType, NavigationArguments? navArgs = null) {