Settingsv2 fix warnings (#2076)

* updating a ton of warnings.

* bunch of cleanup

* few smaller ones

* fixed naming

* reversing an oops

* adjusting json to use attribute

* more json properties
This commit is contained in:
Clint Rutkas
2020-04-10 15:22:07 -07:00
committed by GitHub
parent 3a46f4589b
commit 6fbed4ad5c
55 changed files with 354 additions and 357 deletions

View File

@@ -12,4 +12,4 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
}
}
}
}

View File

@@ -12,4 +12,4 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
}
}
}
}

View File

@@ -0,0 +1,13 @@
// 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.
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class Keys
{
public string From { get; set; }
public string To { get; set; }
}
}

View File

@@ -19,45 +19,45 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
if (SettingsUtils.SettingsExists(POWERTOYNAME))
{
this.settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
}
else
{
this.settings = new PowerLauncherSettings();
settings = new PowerLauncherSettings();
}
}
private void UpdateSettings([CallerMemberName] string propertyName = null)
{
// Notify UI of property change
this.OnPropertyChanged(propertyName);
OnPropertyChanged(propertyName);
// Save settings to file
var options = new JsonSerializerOptions
{
WriteIndented = true,
};
SettingsUtils.SaveSettings(JsonSerializer.Serialize(this.settings, options), POWERTOYNAME);
SettingsUtils.SaveSettings(JsonSerializer.Serialize(settings, options), POWERTOYNAME);
// Propagate changes to Power Launcher through IPC
var propertiesJson = JsonSerializer.Serialize(this.settings.properties);
var propertiesJson = JsonSerializer.Serialize(settings.properties);
ShellPage.DefaultSndMSGCallback(
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(this.settings.properties)));
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
}
public bool EnablePowerLauncher
{
get
{
return this.settings.properties.enable_powerlauncher;
return settings.properties.enable_powerlauncher;
}
set
{
if (this.settings.properties.enable_powerlauncher != value)
if (settings.properties.enable_powerlauncher != value)
{
this.settings.properties.enable_powerlauncher = value;
this.UpdateSettings();
settings.properties.enable_powerlauncher = value;
UpdateSettings();
}
}
}
@@ -66,15 +66,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.search_result_preference;
return settings.properties.search_result_preference;
}
set
{
if (this.settings.properties.search_result_preference != value)
if (settings.properties.search_result_preference != value)
{
this.settings.properties.search_result_preference = value;
this.UpdateSettings();
settings.properties.search_result_preference = value;
UpdateSettings();
}
}
}
@@ -83,15 +83,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.search_type_preference;
return settings.properties.search_type_preference;
}
set
{
if (this.settings.properties.search_type_preference != value)
if (settings.properties.search_type_preference != value)
{
this.settings.properties.search_type_preference = value;
this.UpdateSettings();
settings.properties.search_type_preference = value;
UpdateSettings();
}
}
}
@@ -100,15 +100,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.maximum_number_of_results;
return settings.properties.maximum_number_of_results;
}
set
{
if (this.settings.properties.maximum_number_of_results != value)
if (settings.properties.maximum_number_of_results != value)
{
this.settings.properties.maximum_number_of_results = value;
this.UpdateSettings();
settings.properties.maximum_number_of_results = value;
UpdateSettings();
}
}
}
@@ -117,15 +117,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.open_powerlauncher;
return settings.properties.open_powerlauncher;
}
set
{
if (this.settings.properties.open_powerlauncher != value)
if (settings.properties.open_powerlauncher != value)
{
this.settings.properties.open_powerlauncher = value;
this.UpdateSettings();
settings.properties.open_powerlauncher = value;
UpdateSettings();
}
}
}
@@ -134,15 +134,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.open_file_location;
return settings.properties.open_file_location;
}
set
{
if (this.settings.properties.open_file_location != value)
if (settings.properties.open_file_location != value)
{
this.settings.properties.open_file_location = value;
this.UpdateSettings();
settings.properties.open_file_location = value;
UpdateSettings();
}
}
}
@@ -151,15 +151,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.copy_path_location;
return settings.properties.copy_path_location;
}
set
{
if (this.settings.properties.copy_path_location != value)
if (settings.properties.copy_path_location != value)
{
this.settings.properties.copy_path_location = value;
this.UpdateSettings();
settings.properties.copy_path_location = value;
UpdateSettings();
}
}
}
@@ -168,15 +168,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.open_console;
return settings.properties.open_console;
}
set
{
if (this.settings.properties.open_console != value)
if (settings.properties.open_console != value)
{
this.settings.properties.open_console = value;
this.UpdateSettings();
settings.properties.open_console = value;
UpdateSettings();
}
}
}
@@ -185,15 +185,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.override_win_r_key;
return settings.properties.override_win_r_key;
}
set
{
if (this.settings.properties.override_win_r_key != value)
if (settings.properties.override_win_r_key != value)
{
this.settings.properties.override_win_r_key = value;
this.UpdateSettings();
settings.properties.override_win_r_key = value;
UpdateSettings();
}
}
}
@@ -202,15 +202,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
get
{
return this.settings.properties.override_win_s_key;
return settings.properties.override_win_s_key;
}
set
{
if (this.settings.properties.override_win_s_key != value)
if (settings.properties.override_win_s_key != value)
{
this.settings.properties.override_win_s_key = value;
this.UpdateSettings();
settings.properties.override_win_s_key = value;
UpdateSettings();
}
}
}

View File

@@ -12,4 +12,4 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
}
}
}
}

View File

@@ -2,30 +2,23 @@
// 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.Collections.ObjectModel;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
// Dummy data model for the UI. Will be removed moving forward.
public class RemapKeysModel : ObservableCollection<Keys>
{
public RemapKeysModel()
{
this.Add(new Keys { From = "A", To = "B" });
this.Add(new Keys { From = "B", To = "A" });
this.Add(new Keys { From = "Ctrl", To = "Shift" });
this.Add(new Keys { From = "Shift", To = "Ctrl" });
this.Add(new Keys { From = "A", To = "B" });
this.Add(new Keys { From = "B", To = "B" });
this.Add(new Keys { From = "Ctrl", To = "Shift" });
this.Add(new Keys { From = "Shift", To = "Ctrl" });
}
}
public class Keys
{
public string From { get; set; }
public string To { get; set; }
}
}
using System.Collections.ObjectModel;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
// Dummy data model for the UI. Will be removed moving forward.
public class RemapKeysModel : ObservableCollection<Keys>
{
public RemapKeysModel()
{
Add(new Keys { From = "A", To = "B" });
Add(new Keys { From = "B", To = "A" });
Add(new Keys { From = "Ctrl", To = "Shift" });
Add(new Keys { From = "Shift", To = "Ctrl" });
Add(new Keys { From = "A", To = "B" });
Add(new Keys { From = "B", To = "B" });
Add(new Keys { From = "Ctrl", To = "Shift" });
Add(new Keys { From = "Shift", To = "Ctrl" });
}
}
}

View File

@@ -32,19 +32,19 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public bool IsBackEnabled
{
get { return this.isBackEnabled; }
set { this.Set(ref this.isBackEnabled, value); }
get { return isBackEnabled; }
set { Set(ref isBackEnabled, value); }
}
public WinUI.NavigationViewItem Selected
{
get { return this.selected; }
set { this.Set(ref this.selected, value); }
get { return selected; }
set { Set(ref selected, value); }
}
public ICommand LoadedCommand => this.loadedCommand ?? (this.loadedCommand = new RelayCommand(this.OnLoaded));
public ICommand LoadedCommand => loadedCommand ?? (loadedCommand = new RelayCommand(OnLoaded));
public ICommand ItemInvokedCommand => this.itemInvokedCommand ?? (this.itemInvokedCommand = new RelayCommand<WinUI.NavigationViewItemInvokedEventArgs>(this.OnItemInvoked));
public ICommand ItemInvokedCommand => itemInvokedCommand ?? (itemInvokedCommand = new RelayCommand<WinUI.NavigationViewItemInvokedEventArgs>(OnItemInvoked));
public ShellViewModel()
{
@@ -55,9 +55,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
this.navigationView = navigationView;
this.keyboardAccelerators = keyboardAccelerators;
NavigationService.Frame = frame;
NavigationService.NavigationFailed += this.Frame_NavigationFailed;
NavigationService.Navigated += this.Frame_Navigated;
this.navigationView.BackRequested += this.OnBackRequested;
NavigationService.NavigationFailed += Frame_NavigationFailed;
NavigationService.Navigated += Frame_Navigated;
this.navigationView.BackRequested += OnBackRequested;
}
private static KeyboardAccelerator BuildKeyboardAccelerator(VirtualKey key, VirtualKeyModifiers? modifiers = null)
@@ -82,14 +82,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
// 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
this.keyboardAccelerators.Add(this.altLeftKeyboardAccelerator);
this.keyboardAccelerators.Add(this.backKeyboardAccelerator);
keyboardAccelerators.Add(altLeftKeyboardAccelerator);
keyboardAccelerators.Add(backKeyboardAccelerator);
await Task.CompletedTask;
}
private void OnItemInvoked(WinUI.NavigationViewItemInvokedEventArgs args)
{
var item = this.navigationView.MenuItems
var item = navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.First(menuItem => (string)menuItem.Content == (string)args.InvokedItem);
var pageType = item.GetValue(NavHelper.NavigateToProperty) as Type;
@@ -108,10 +108,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_Navigated(object sender, NavigationEventArgs e)
{
this.IsBackEnabled = NavigationService.CanGoBack;
this.Selected = this.navigationView.MenuItems
IsBackEnabled = NavigationService.CanGoBack;
Selected = navigationView.MenuItems
.OfType<WinUI.NavigationViewItem>()
.FirstOrDefault(menuItem => this.IsMenuItemForPageType(menuItem, e.SourcePageType));
.FirstOrDefault(menuItem => IsMenuItemForPageType(menuItem, e.SourcePageType));
}
private bool IsMenuItemForPageType(WinUI.NavigationViewItem menuItem, Type sourcePageType)

View File

@@ -12,4 +12,4 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
}
}
}
}