Getting Shell on stylecop (#5620)

This commit is contained in:
Clint Rutkas 2020-08-04 16:27:35 -07:00 committed by GitHub
parent 1f590c45be
commit 296d103f68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 23 deletions

View file

@ -1,28 +1,33 @@
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 System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Input;
using Microsoft.PowerToys.Settings.UI.Lib;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using Wox.Plugin.SharedCommands;
using Wox.Plugin;
using Wox.Plugin.SharedCommands;
using Control = System.Windows.Controls.Control;
using System.Windows.Input;
using System.Reflection;
namespace Microsoft.Plugin.Shell
{
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
{
private string IconPath { get; set; }
private PluginInitContext _context;
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
private string IconPath { get; set; }
private PluginInitContext _context;
public Main()
{
_storage = new PluginJsonStorage<Settings>();
@ -34,7 +39,6 @@ namespace Microsoft.Plugin.Shell
_storage.Save();
}
public List<Result> Query(Query query)
{
List<Result> results = new List<Result>();
@ -83,7 +87,7 @@ namespace Microsoft.Plugin.Shell
{
Execute(Process.Start, PrepareProcessStartInfo(m));
return true;
}
},
}));
}
}
@ -91,6 +95,7 @@ namespace Microsoft.Plugin.Shell
{
Log.Exception($"|Microsoft.Plugin.Shell.Main.Query|Exception when query for <{query}>", e);
}
return results;
}
}
@ -116,7 +121,7 @@ namespace Microsoft.Plugin.Shell
{
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
return true;
}
},
};
return ret;
}).Where(o => o != null).Take(4);
@ -135,7 +140,7 @@ namespace Microsoft.Plugin.Shell
{
Execute(Process.Start, PrepareProcessStartInfo(cmd));
return true;
}
},
};
return result;
@ -153,7 +158,7 @@ namespace Microsoft.Plugin.Shell
{
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
return true;
}
},
}).Take(5);
return history.ToList();
}
@ -163,7 +168,7 @@ namespace Microsoft.Plugin.Shell
command = command.Trim();
command = Environment.ExpandEnvironmentVariables(command);
var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas";
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? string.Empty : "runas";
ProcessStartInfo info;
if (_settings.Shell == Shell.Cmd)
@ -188,7 +193,7 @@ namespace Microsoft.Plugin.Shell
}
else if (_settings.Shell == Shell.RunCommand)
{
//Open explorer if the path is a file or directory
// Open explorer if the path is a file or directory
if (Directory.Exists(command) || File.Exists(command))
{
info = ShellCommand.SetProcessStartInfo("explorer.exe", arguments: command, verb: runAsAdministratorArg);
@ -267,6 +272,7 @@ namespace Microsoft.Plugin.Shell
return true;
}
}
return false;
}
else
@ -296,7 +302,7 @@ namespace Microsoft.Plugin.Shell
}
}
private void OnThemeChanged(Theme _, Theme newTheme)
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
@ -327,13 +333,13 @@ namespace Microsoft.Plugin.Shell
Glyph = "\xE7EF",
FontFamily = "Segoe MDL2 Assets",
AcceleratorKey = Key.Enter,
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
Action = c =>
{
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
return true;
}
}
},
},
};
return resultlist;

View file

@ -108,5 +108,19 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -1,4 +1,8 @@
using System.Collections.Generic;
// 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.Collections.Generic;
namespace Microsoft.Plugin.Shell
{
@ -6,12 +10,15 @@ namespace Microsoft.Plugin.Shell
{
public Shell Shell { get; set; } = Shell.RunCommand;
// not overriding Win+R
// not overriding Win+R
// crutkas we need to earn the right for Win+R override
public bool ReplaceWinR { get; set; } = false;
public bool LeaveShellOpen { get; set; }
public bool RunAsAdministrator { get; set; } = false;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "StyleCop error, actually used in main.cs")]
public Dictionary<string, int> Count = new Dictionary<string, int>();
public void AddCmdHistory(string cmdName)
@ -32,6 +39,5 @@ namespace Microsoft.Plugin.Shell
Cmd = 0,
Powershell = 1,
RunCommand = 2,
}
}

View file

@ -1,4 +1,8 @@
using System.Windows;
// 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.Windows;
using System.Windows.Controls;
namespace Microsoft.Plugin.Shell