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:
@@ -0,0 +1,36 @@
|
||||
// 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 System.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels.Commands
|
||||
{
|
||||
public class ButtonClickCommand : ICommand
|
||||
{
|
||||
private readonly Action _execute;
|
||||
|
||||
public ButtonClickCommand(Action execute)
|
||||
{
|
||||
_execute = execute;
|
||||
}
|
||||
|
||||
// Occurs when changes occur that affect whether or not the command should execute.
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
// Defines the method that determines whether the command can execute in its current state.
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Defines the method to be called when the command is invoked.
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute();
|
||||
}
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
140
src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs
Normal file
140
src/settings-ui/Settings.UI/ViewModels/ShellViewModel.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Services;
|
||||
using Windows.System;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using WinUI = Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
public class ShellViewModel : Observable
|
||||
{
|
||||
private readonly KeyboardAccelerator altLeftKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.Left, VirtualKeyModifiers.Menu);
|
||||
|
||||
private readonly KeyboardAccelerator backKeyboardAccelerator = BuildKeyboardAccelerator(VirtualKey.GoBack);
|
||||
|
||||
private bool isBackEnabled;
|
||||
private IList<KeyboardAccelerator> keyboardAccelerators;
|
||||
private WinUI.NavigationView navigationView;
|
||||
private WinUI.NavigationViewItem selected;
|
||||
private ICommand loadedCommand;
|
||||
private ICommand itemInvokedCommand;
|
||||
|
||||
public bool IsBackEnabled
|
||||
{
|
||||
get { return isBackEnabled; }
|
||||
set { Set(ref isBackEnabled, value); }
|
||||
}
|
||||
|
||||
public bool IsVideoConferenceBuild
|
||||
{
|
||||
get
|
||||
{
|
||||
var mfHandle = NativeMethods.LoadLibrary("mf.dll");
|
||||
bool mfAvailable = mfHandle != null;
|
||||
if (mfAvailable)
|
||||
{
|
||||
NativeMethods.FreeLibrary(mfHandle);
|
||||
}
|
||||
|
||||
return this != null && File.Exists("modules/VideoConference/PowerToys.VideoConferenceModule.dll") && mfAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
public WinUI.NavigationViewItem Selected
|
||||
{
|
||||
get { return selected; }
|
||||
set { Set(ref selected, value); }
|
||||
}
|
||||
|
||||
public ICommand LoadedCommand => loadedCommand ?? (loadedCommand = new RelayCommand(OnLoaded));
|
||||
|
||||
public ICommand ItemInvokedCommand => itemInvokedCommand ?? (itemInvokedCommand = new RelayCommand<WinUI.NavigationViewItemInvokedEventArgs>(OnItemInvoked));
|
||||
|
||||
public ShellViewModel()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialize(Frame frame, WinUI.NavigationView navigationView, IList<KeyboardAccelerator> keyboardAccelerators)
|
||||
{
|
||||
this.navigationView = navigationView;
|
||||
this.keyboardAccelerators = keyboardAccelerators;
|
||||
NavigationService.Frame = frame;
|
||||
NavigationService.NavigationFailed += Frame_NavigationFailed;
|
||||
NavigationService.Navigated += Frame_Navigated;
|
||||
this.navigationView.BackRequested += OnBackRequested;
|
||||
}
|
||||
|
||||
private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
|
||||
{
|
||||
var keyboardAccelerator = new KeyboardAccelerator() { Key = key };
|
||||
if (modifiers.HasValue)
|
||||
{
|
||||
keyboardAccelerator.Modifiers = modifiers.Value;
|
||||
}
|
||||
|
||||
keyboardAccelerator.Invoked += OnKeyboardAcceleratorInvoked;
|
||||
return keyboardAccelerator;
|
||||
}
|
||||
|
||||
private static void OnKeyboardAcceleratorInvoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
|
||||
{
|
||||
var result = NavigationService.GoBack();
|
||||
args.Handled = result;
|
||||
}
|
||||
|
||||
private async void OnLoaded()
|
||||
{
|
||||
// Keyboard accelerators are added here to avoid showing 'Alt + left' tooltip on the page.
|
||||
// More info on tracking issue https://github.com/Microsoft/microsoft-ui-xaml/issues/8
|
||||
keyboardAccelerators.Add(altLeftKeyboardAccelerator);
|
||||
keyboardAccelerators.Add(backKeyboardAccelerator);
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void OnItemInvoked(WinUI.NavigationViewItemInvokedEventArgs args)
|
||||
{
|
||||
var item = navigationView.MenuItems
|
||||
.OfType<WinUI.NavigationViewItem>()
|
||||
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
|
||||
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
|
||||
NavigationService.Navigate(pageType);
|
||||
}
|
||||
|
||||
private void OnBackRequested(WinUI.NavigationView sender, WinUI.NavigationViewBackRequestedEventArgs args)
|
||||
{
|
||||
NavigationService.GoBack();
|
||||
}
|
||||
|
||||
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
throw e.Exception;
|
||||
}
|
||||
|
||||
private void Frame_Navigated(object sender, NavigationEventArgs e)
|
||||
{
|
||||
IsBackEnabled = NavigationService.CanGoBack;
|
||||
Selected = navigationView.MenuItems
|
||||
.OfType<WinUI.NavigationViewItem>()
|
||||
.FirstOrDefault(menuItem => IsMenuItemForPageType(menuItem, e.SourcePageType));
|
||||
}
|
||||
|
||||
private static bool IsMenuItemForPageType(WinUI.NavigationViewItem menuItem, Type sourcePageType)
|
||||
{
|
||||
var pageType = menuItem.GetValue(NavHelper.NavigateToProperty) as Type;
|
||||
return pageType == sourcePageType;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user