[stylecop] Launcher (#5968)

* Should be last stylecop change!

* two more tweaks
This commit is contained in:
Clint Rutkas 2020-08-14 13:35:06 -07:00 committed by GitHub
parent e0a1b478a1
commit 6514712054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 594 additions and 597 deletions

View file

@ -13,15 +13,13 @@ namespace Wox
public partial class ActionKeywords : Window
{
private readonly Internationalization _translater = InternationalizationManager.Instance;
private readonly PluginPair _plugin;
private PluginPair _plugin;
private Settings _settings;
public ActionKeywords(string pluginId, Settings settings)
public ActionKeywords(string pluginId)
{
InitializeComponent();
_plugin = PluginManager.GetPluginForId(pluginId);
_settings = settings;
if (_plugin == null)
{
MessageBox.Show(_translater.GetTranslation("cannotFindSpecifiedPlugin"));

View file

@ -16,7 +16,9 @@ namespace PowerLauncher.Helper
{
public static class WindowsInteropHelper
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Matching COM")]
private const int GWL_STYLE = -16; // WPF's Message code for Title Bar's Style
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Matching COM")]
private const int WS_SYSMENU = 0x80000; // WPF's Message code for System Menu
private static IntPtr _hwnd_shell;
private static IntPtr _hwnd_desktop;
@ -42,8 +44,8 @@ namespace PowerLauncher.Helper
[StructLayout(LayoutKind.Sequential)]
internal struct INPUT
{
public INPUTTYPE type;
public InputUnion data;
public INPUTTYPE Type;
public InputUnion Data;
public static int Size
{
@ -52,6 +54,7 @@ namespace PowerLauncher.Helper
}
[StructLayout(LayoutKind.Explicit)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching COM")]
internal struct InputUnion
{
[FieldOffset(0)]
@ -63,6 +66,7 @@ namespace PowerLauncher.Helper
}
[StructLayout(LayoutKind.Sequential)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching COM")]
internal struct MOUSEINPUT
{
internal int dx;
@ -74,6 +78,7 @@ namespace PowerLauncher.Helper
}
[StructLayout(LayoutKind.Sequential)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching COM")]
internal struct KEYBDINPUT
{
internal short wVk;
@ -84,6 +89,7 @@ namespace PowerLauncher.Helper
}
[StructLayout(LayoutKind.Sequential)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Matching COM")]
internal struct HARDWAREINPUT
{
internal int uMsg;
@ -98,10 +104,10 @@ namespace PowerLauncher.Helper
INPUTHARDWARE = 2,
}
private const string WINDOW_CLASS_CONSOLE = "ConsoleWindowClass";
private const string WINDOW_CLASS_WINTAB = "Flip3D";
private const string WINDOW_CLASS_PROGMAN = "Progman";
private const string WINDOW_CLASS_WORKERW = "WorkerW";
private const string WindowClassConsole = "ConsoleWindowClass";
private const string WindowClassWinTab = "Flip3D";
private const string WindowClassProgman = "Progman";
private const string WindowClassWorkerW = "WorkerW";
public static bool IsWindowFullscreen()
{
@ -118,7 +124,7 @@ namespace PowerLauncher.Helper
string windowClass = sb.ToString();
// for Win+Tab (Flip3D)
if (windowClass == WINDOW_CLASS_WINTAB)
if (windowClass == WindowClassWinTab)
{
return false;
}
@ -126,13 +132,13 @@ namespace PowerLauncher.Helper
_ = NativeMethods.GetWindowRect(hWnd, out RECT appBounds);
// for console (ConsoleWindowClass), we have to check for negative dimensions
if (windowClass == WINDOW_CLASS_CONSOLE)
if (windowClass == WindowClassConsole)
{
return appBounds.Top < 0 && appBounds.Bottom < 0;
}
// for desktop (Progman or WorkerW, depends on the system), we have to check
if (windowClass == WINDOW_CLASS_PROGMAN || windowClass == WINDOW_CLASS_WORKERW)
if (windowClass == WindowClassProgman || windowClass == WindowClassWorkerW)
{
IntPtr hWndDesktop = NativeMethods.FindWindowEx(hWnd, IntPtr.Zero, "SHELLDLL_DefView", null);
hWndDesktop = NativeMethods.FindWindowEx(hWndDesktop, IntPtr.Zero, "SysListView32", "FolderView");

View file

@ -20,8 +20,8 @@ namespace PowerLauncher
{
public partial class MainWindow : IDisposable
{
private Settings _settings;
private MainViewModel _viewModel;
private readonly Settings _settings;
private readonly MainViewModel _viewModel;
private bool _isTextSetProgrammatically;
private bool _deletePressed = false;
private Timer _firstDeleteTimer = new Timer();
@ -65,7 +65,7 @@ namespace PowerLauncher
private void BringProcessToForeground()
{
// Use SendInput hack to allow Activate to work - required to resolve focus issue https://github.com/microsoft/PowerToys/issues/4270
WindowsInteropHelper.INPUT input = new WindowsInteropHelper.INPUT { type = WindowsInteropHelper.INPUTTYPE.INPUTMOUSE, data = { } };
WindowsInteropHelper.INPUT input = new WindowsInteropHelper.INPUT { Type = WindowsInteropHelper.INPUTTYPE.INPUTMOUSE, Data = { } };
WindowsInteropHelper.INPUT[] inputs = new WindowsInteropHelper.INPUT[] { input };
// Send empty mouse event. This makes this thread the last to send input, and hence allows it to pass foreground permission checks

View file

@ -259,7 +259,7 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<!--<ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
@ -273,5 +273,5 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>-->
</ItemGroup>
</Project>

View file

@ -18,10 +18,10 @@ namespace PowerLauncher
// Watch for /Local/Microsoft/PowerToys/Launcher/Settings.json changes
public class SettingsWatcher : BaseModel
{
private static int _maxRetries = 10;
private static object _watcherSyncObject = new object();
private FileSystemWatcher _watcher;
private Settings _settings;
private const int MaxRetries = 10;
private static readonly object _watcherSyncObject = new object();
private readonly FileSystemWatcher _watcher;
private readonly Settings _settings;
public SettingsWatcher(Settings settings)
{
@ -96,7 +96,7 @@ namespace PowerLauncher
// This should be changed to properly synch with the settings app instead of retrying.
catch (IOException e)
{
if (retryCount > _maxRetries)
if (retryCount > MaxRetries)
{
retry = false;
}

View file

@ -12,7 +12,7 @@ namespace PowerLauncher.Storage
{
public List<HistoryItem> Items { get; } = new List<HistoryItem>();
private int _maxHistory = 300;
private readonly int _maxHistory = 300;
public void Add(string query)
{

View file

@ -12,7 +12,7 @@ namespace PowerLauncher.Storage
public class UserSelectedRecord
{
[JsonProperty]
private Dictionary<string, int> records = new Dictionary<string, int>();
private readonly Dictionary<string, int> records = new Dictionary<string, int>();
public void Add(Result result)
{

View file

@ -29,7 +29,7 @@ namespace PowerLauncher.ViewModel
{
public class MainViewModel : BaseModel, ISavable, IDisposable
{
private static Query _emptyQuery = new Query();
private static readonly Query _emptyQuery = new Query();
private static bool _disposed;
private readonly WoxJsonStorage<QueryHistory> _historyItemsStorage;
@ -41,6 +41,7 @@ namespace PowerLauncher.ViewModel
private readonly TopMostRecord _topMostRecord;
private readonly object _addResultsLock = new object();
private readonly Internationalization _translator = InternationalizationManager.Instance;
private readonly System.Diagnostics.Stopwatch _hotkeyTimer = new System.Diagnostics.Stopwatch();
private Query _currentQuery;
private string _queryTextBeforeLeaveResults;
@ -49,15 +50,13 @@ namespace PowerLauncher.ViewModel
private CancellationToken _updateToken;
private bool _saved;
private HotkeyManager _hotkeyManager { get; set; }
private ushort _hotkeyHandle;
private System.Diagnostics.Stopwatch hotkeyTimer = new System.Diagnostics.Stopwatch();
internal HotkeyManager HotkeyManager { get; set; }
public MainViewModel(Settings settings)
{
_hotkeyManager = new HotkeyManager();
HotkeyManager = new HotkeyManager();
_saved = false;
_queryTextBeforeLeaveResults = string.Empty;
_currentQuery = _emptyQuery;
@ -88,7 +87,7 @@ namespace PowerLauncher.ViewModel
{
if (!string.IsNullOrEmpty(_settings.PreviousHotkey))
{
_hotkeyManager.UnregisterHotkey(_hotkeyHandle);
HotkeyManager.UnregisterHotkey(_hotkeyHandle);
}
if (!string.IsNullOrEmpty(_settings.Hotkey))
@ -603,12 +602,6 @@ namespace PowerLauncher.ViewModel
return selected;
}
private bool ContextMenuSelected()
{
var selected = SelectedResults == ContextMenu;
return selected;
}
private bool HistorySelected()
{
var selected = SelectedResults == History;
@ -632,10 +625,10 @@ namespace PowerLauncher.ViewModel
Shift = hotkeyModel.Shift,
Ctrl = hotkeyModel.Ctrl,
Win = hotkeyModel.Win,
Key = (byte)KeyInterop.VirtualKeyFromKey(hotkeyModel.CharKey)
Key = (byte)KeyInterop.VirtualKeyFromKey(hotkeyModel.CharKey),
};
_hotkeyHandle = _hotkeyManager.RegisterHotkey(hotkey, action);
_hotkeyHandle = HotkeyManager.RegisterHotkey(hotkey, action);
}
#pragma warning disable CA1031 // Do not catch general exception types
catch (Exception)
@ -799,7 +792,7 @@ namespace PowerLauncher.ViewModel
{
if (!plugin.Metadata.Disabled && plugin.Metadata.Name != "Window Walker")
{
var _ = PluginManager.QueryForPlugin(plugin, query);
_ = PluginManager.QueryForPlugin(plugin, query);
}
}
}
@ -877,10 +870,10 @@ namespace PowerLauncher.ViewModel
{
if (_hotkeyHandle != 0)
{
_hotkeyManager?.UnregisterHotkey(_hotkeyHandle);
HotkeyManager?.UnregisterHotkey(_hotkeyHandle);
}
_hotkeyManager?.Dispose();
HotkeyManager?.Dispose();
_updateSource?.Dispose();
_disposed = true;
}
@ -895,16 +888,16 @@ namespace PowerLauncher.ViewModel
public void StartHotkeyTimer()
{
hotkeyTimer.Start();
_hotkeyTimer.Start();
}
public long GetHotkeyEventTimeMs()
{
hotkeyTimer.Stop();
long recordedTime = hotkeyTimer.ElapsedMilliseconds;
_hotkeyTimer.Stop();
long recordedTime = _hotkeyTimer.ElapsedMilliseconds;
// Reset the stopwatch and return the time elapsed
hotkeyTimer.Reset();
_hotkeyTimer.Reset();
return recordedTime;
}
}

View file

@ -9,7 +9,7 @@ namespace PowerLauncher.ViewModel
{
public class RelayCommand : ICommand
{
private Action<object> _action;
private readonly Action<object> _action;
public RelayCommand(Action<object> action)
{