Skip to content

Commit

Permalink
getting stylecop undercontrol for UI warnings (#5630)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutkas committed Aug 6, 2020
1 parent ed36447 commit 7b767df
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.PowerToys.Settings.UI.Lib;
// 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;
using Microsoft.PowerToys.Settings.UI.Lib;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
Expand Down
1 change: 1 addition & 0 deletions src/core/Microsoft.PowerToys.Settings.UI/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static ICoreWindowInterop GetInterop(this Windows.UI.Core.CoreWindow @thi
[DllImport("user32.dll")]
public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow);

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop naming consistancy")]
public const int SW_HIDE = 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// 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.Linq;
using System.Text.Json;

using Microsoft.PowerToys.Settings.UI.Helpers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ButtonClickCommand : ICommand

public ButtonClickCommand(Action execute)
{
this._execute = execute;
_execute = execute;
}

// Occurs when changes occur that affect whether or not the command should execute.
Expand All @@ -30,5 +30,7 @@ public void Execute(object parameter)
{
_execute();
}

public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
// 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.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.UI;
using Windows.UI.Popups;

namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
Expand All @@ -35,32 +32,32 @@ public FancyZonesViewModel()
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
}

this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

this._shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
this._mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
this._overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
this._moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
this._displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
this._zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
this._appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
this._openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
this._restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
this._showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
this._makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
this._highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
this._excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
this.EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

_shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
_mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
_overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
_moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
_displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
_zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
_appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
_openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
_restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
_useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
_showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
_makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;

string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
this._zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor.ToColor() : "#F5FCFF".ToColor();
_zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor.ToColor() : "#F5FCFF".ToColor();

string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
this._zoneBorderColor = borderColor != string.Empty ? borderColor.ToColor() : "#FFFFFF".ToColor();
_zoneBorderColor = borderColor != string.Empty ? borderColor.ToColor() : "#FFFFFF".ToColor();

string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
this._zoneHighlightColor = highlightColor != string.Empty ? highlightColor.ToColor() : "#0078D7".ToColor();
_zoneHighlightColor = highlightColor != string.Empty ? highlightColor.ToColor() : "#0078D7".ToColor();

GeneralSettings generalSettings;
try
Expand All @@ -73,7 +70,7 @@ public FancyZonesViewModel()
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}

this._isEnabled = generalSettings.Enabled.FancyZones;
_isEnabled = generalSettings.Enabled.FancyZones;
}

private bool _isEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels.Commands;
using Microsoft.PowerToys.Settings.UI.Views;
using Windows.ApplicationModel.Resources;
using Windows.Data.Html;
using Windows.System;
using Windows.UI.Popups;
using Windows.UI.Xaml;

namespace Microsoft.PowerToys.Settings.UI.ViewModels
Expand All @@ -29,13 +25,24 @@ public class GeneralViewModel : Observable

private ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();

public readonly string RunningAsUserDefaultText;
public readonly string RunningAsAdminDefaultText;
public string RunningAsUserDefaultText { get; private set; }

public string RunningAsAdminDefaultText { get; private set; }

private bool _packaged = false;
private bool _startup = false;
private bool _isElevated = false;
private bool _runElevated = false;
private bool _isAdmin = false;
private bool _isDarkThemeRadioButtonChecked = false;
private bool _isLightThemeRadioButtonChecked = false;
private bool _isSystemThemeRadioButtonChecked = false;
private bool _autoDownloadUpdates = false;

public GeneralViewModel()
{
this.CheckFoUpdatesEventHandler = new ButtonClickCommand(CheckForUpdates_Click);
this.RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated);
CheckFoUpdatesEventHandler = new ButtonClickCommand(CheckForUpdates_Click);
RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated);

try
{
Expand Down Expand Up @@ -107,16 +114,6 @@ public GeneralViewModel()
_isAdmin = ShellPage.IsUserAnAdmin;
}

private bool _packaged = false;
private bool _startup = false;
private bool _isElevated = false;
private bool _runElevated = false;
private bool _isAdmin = false;
private bool _isDarkThemeRadioButtonChecked = false;
private bool _isLightThemeRadioButtonChecked = false;
private bool _isSystemThemeRadioButtonChecked = false;
private bool _autoDownloadUpdates = false;

// Gets or sets a value indicating whether packaged.
public bool Packaged
{
Expand Down Expand Up @@ -350,18 +347,15 @@ public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
}

// callback function to launch the URL to check for updates.
private async void CheckForUpdates_Click()
private void CheckForUpdates_Click()
{
GeneralSettings settings = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
settings.CustomActionName = "check_for_updates";

OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

if (ShellPage.CheckForUpdatesMsgCallback != null)
{
ShellPage.CheckForUpdatesMsgCallback(customaction.ToString());
}
ShellPage.CheckForUpdatesMsgCallback?.Invoke(customaction.ToString());
}

public void Restart_Elevated()
Expand All @@ -372,10 +366,7 @@ public void Restart_Elevated()
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);

if (ShellPage.SndRestartAsAdminMsgCallback != null)
{
ShellPage.SndRestartAsAdminMsgCallback(customaction.ToString());
}
ShellPage.SndRestartAsAdminMsgCallback?.Invoke(customaction.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
// 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.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Views;
using Windows.UI.Popups;

namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
Expand Down Expand Up @@ -47,14 +42,14 @@ public ImageResizerViewModel()
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}

this._isEnabled = generalSettings.Enabled.ImageResizer;
this._advancedSizes = Settings.Properties.ImageresizerSizes.Value;
this._jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value;
this._pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
this._tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
this._fileName = Settings.Properties.ImageresizerFileName.Value;
this._keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value;
this._encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);
_isEnabled = generalSettings.Enabled.ImageResizer;
_advancedSizes = Settings.Properties.ImageresizerSizes.Value;
_jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value;
_pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
_tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
_fileName = Settings.Properties.ImageresizerFileName.Value;
_keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value;
_encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);

int i = 0;
foreach (ImageSize size in _advancedSizes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public PowerPreviewViewModel()
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
}

this._svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
this._svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
this._mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
}

private bool _svgRenderIsEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public ShortcutGuideViewModel()
SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
}

this._isEnabled = generalSettings.Enabled.ShortcutGuide;
this._pressTime = Settings.Properties.PressTime.Value;
this._opacity = Settings.Properties.OverlayOpacity.Value;
_isEnabled = generalSettings.Enabled.ShortcutGuide;
_pressTime = Settings.Properties.PressTime.Value;
_opacity = Settings.Properties.OverlayOpacity.Value;

string theme = Settings.Properties.Theme.Value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@
// 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.WindowsRuntime;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.PowerToys.Settings.UI.Views
{
Expand All @@ -26,7 +13,7 @@ public sealed partial class FancyZonesPage : Page

public FancyZonesPage()
{
this.InitializeComponent();
InitializeComponent();
ViewModel = new FancyZonesViewModel();
MainView.DataContext = ViewModel;
}
Expand Down
13 changes: 3 additions & 10 deletions src/core/Microsoft.PowerToys.Settings.UI/Views/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@
// 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.IO;
using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.System;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.PowerToys.Settings.UI.Views
{
Expand All @@ -30,10 +23,10 @@ public sealed partial class GeneralPage : Page
/// </summary>
public GeneralPage()
{
this.InitializeComponent();
InitializeComponent();

this.ViewModel = new GeneralViewModel();
this.GeneralSettingsView.DataContext = this.ViewModel;
ViewModel = new GeneralViewModel();
GeneralSettingsView.DataContext = ViewModel;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml.Controls;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// 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 Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.PowerToys.Settings.UI.Views
{
Expand All @@ -16,13 +12,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views
/// </summary>
public sealed partial class PowerPreviewPage : Page
{
public PowerPreviewViewModel viewModel { get; set; }
public PowerPreviewViewModel ViewModel { get; set; }

public PowerPreviewPage()
{
this.InitializeComponent();
viewModel = new PowerPreviewViewModel();
this.PowerPreviewSettingsView.DataContext = viewModel;
InitializeComponent();
ViewModel = new PowerPreviewViewModel();
PowerPreviewSettingsView.DataContext = ViewModel;
}
}
}

0 comments on commit 7b767df

Please sign in to comment.