mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[Settings, Common.UI, runner exe] Unify exe/dll naming (#15005)
* Unify exe/dll naming - PowerToys.Runner Align naming with other exes - PowerToys Runner -> PowerToys.Runner * Unify exe/dll naming - Microsoft.PowerToys.Common.UI Project name - Microsoft.PowerToys.Common.UI -> Common.UI dll name - Microsoft.PowerToys.Common.UI.dll -> PowerToys.Common.UI.dll * Unify exe/dll naming - Settings Project names - Microsoft.PowerToys.Settings* -> Settings* Dll names - Microsoft.PowerToys.Settings*.dll -> PowerToys.Settings*.dll * Revert file autoformat * [Docs] Update paths to settings projects/files * Fix tests - Update path
This commit is contained in:
105
src/settings-ui/Settings.UI/Services/NavigationService.cs
Normal file
105
src/settings-ui/Settings.UI/Services/NavigationService.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Services
|
||||
{
|
||||
public static class NavigationService
|
||||
{
|
||||
public static event NavigatedEventHandler Navigated;
|
||||
|
||||
public static event NavigationFailedEventHandler NavigationFailed;
|
||||
|
||||
private static Frame frame;
|
||||
private static object lastParamUsed;
|
||||
|
||||
public static Frame Frame
|
||||
{
|
||||
get
|
||||
{
|
||||
if (frame == null)
|
||||
{
|
||||
frame = Window.Current.Content as Frame;
|
||||
RegisterFrameEvents();
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
UnregisterFrameEvents();
|
||||
frame = value;
|
||||
RegisterFrameEvents();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CanGoBack => Frame.CanGoBack;
|
||||
|
||||
public static bool CanGoForward => Frame.CanGoForward;
|
||||
|
||||
public static bool GoBack()
|
||||
{
|
||||
if (CanGoBack)
|
||||
{
|
||||
Frame.GoBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void GoForward() => Frame.GoForward();
|
||||
|
||||
public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
|
||||
{
|
||||
// Don't open the same page multiple times
|
||||
if (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(lastParamUsed)))
|
||||
{
|
||||
var navigationResult = Frame.Navigate(pageType, parameter, infoOverride);
|
||||
if (navigationResult)
|
||||
{
|
||||
lastParamUsed = parameter;
|
||||
}
|
||||
|
||||
return navigationResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Navigate<T>(object parameter = null, NavigationTransitionInfo infoOverride = null)
|
||||
where T : Page
|
||||
=> Navigate(typeof(T), parameter, infoOverride);
|
||||
|
||||
private static void RegisterFrameEvents()
|
||||
{
|
||||
if (frame != null)
|
||||
{
|
||||
frame.Navigated += Frame_Navigated;
|
||||
frame.NavigationFailed += Frame_NavigationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
private static void UnregisterFrameEvents()
|
||||
{
|
||||
if (frame != null)
|
||||
{
|
||||
frame.Navigated -= Frame_Navigated;
|
||||
frame.NavigationFailed -= Frame_NavigationFailed;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e) => NavigationFailed?.Invoke(sender, e);
|
||||
|
||||
private static void Frame_Navigated(object sender, NavigationEventArgs e) => Navigated?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user