mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Getting Shell on stylecop (#5620)
This commit is contained in:
@@ -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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin.SharedCommands;
|
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
|
using Wox.Plugin.SharedCommands;
|
||||||
using Control = System.Windows.Controls.Control;
|
using Control = System.Windows.Controls.Control;
|
||||||
using System.Windows.Input;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Shell
|
namespace Microsoft.Plugin.Shell
|
||||||
{
|
{
|
||||||
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
|
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
|
||||||
{
|
{
|
||||||
private string IconPath { get; set; }
|
|
||||||
private PluginInitContext _context;
|
|
||||||
|
|
||||||
private readonly Settings _settings;
|
private readonly Settings _settings;
|
||||||
private readonly PluginJsonStorage<Settings> _storage;
|
private readonly PluginJsonStorage<Settings> _storage;
|
||||||
|
|
||||||
|
private string IconPath { get; set; }
|
||||||
|
|
||||||
|
private PluginInitContext _context;
|
||||||
|
|
||||||
public Main()
|
public Main()
|
||||||
{
|
{
|
||||||
_storage = new PluginJsonStorage<Settings>();
|
_storage = new PluginJsonStorage<Settings>();
|
||||||
@@ -34,7 +39,6 @@ namespace Microsoft.Plugin.Shell
|
|||||||
_storage.Save();
|
_storage.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
List<Result> results = new List<Result>();
|
List<Result> results = new List<Result>();
|
||||||
@@ -83,7 +87,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(m));
|
Execute(Process.Start, PrepareProcessStartInfo(m));
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,6 +95,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
{
|
{
|
||||||
Log.Exception($"|Microsoft.Plugin.Shell.Main.Query|Exception when query for <{query}>", e);
|
Log.Exception($"|Microsoft.Plugin.Shell.Main.Query|Exception when query for <{query}>", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +121,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
return ret;
|
return ret;
|
||||||
}).Where(o => o != null).Take(4);
|
}).Where(o => o != null).Take(4);
|
||||||
@@ -135,7 +140,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(cmd));
|
Execute(Process.Start, PrepareProcessStartInfo(cmd));
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -153,7 +158,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
Execute(Process.Start, PrepareProcessStartInfo(m.Key));
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
}).Take(5);
|
}).Take(5);
|
||||||
return history.ToList();
|
return history.ToList();
|
||||||
}
|
}
|
||||||
@@ -163,7 +168,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
command = command.Trim();
|
command = command.Trim();
|
||||||
command = Environment.ExpandEnvironmentVariables(command);
|
command = Environment.ExpandEnvironmentVariables(command);
|
||||||
var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas";
|
var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? string.Empty : "runas";
|
||||||
|
|
||||||
ProcessStartInfo info;
|
ProcessStartInfo info;
|
||||||
if (_settings.Shell == Shell.Cmd)
|
if (_settings.Shell == Shell.Cmd)
|
||||||
@@ -188,7 +193,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
}
|
}
|
||||||
else if (_settings.Shell == Shell.RunCommand)
|
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))
|
if (Directory.Exists(command) || File.Exists(command))
|
||||||
{
|
{
|
||||||
info = ShellCommand.SetProcessStartInfo("explorer.exe", arguments: command, verb: runAsAdministratorArg);
|
info = ShellCommand.SetProcessStartInfo("explorer.exe", arguments: command, verb: runAsAdministratorArg);
|
||||||
@@ -267,6 +272,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -296,7 +302,7 @@ namespace Microsoft.Plugin.Shell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnThemeChanged(Theme _, Theme newTheme)
|
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
|
||||||
{
|
{
|
||||||
UpdateIconPath(newTheme);
|
UpdateIconPath(newTheme);
|
||||||
}
|
}
|
||||||
@@ -327,13 +333,13 @@ namespace Microsoft.Plugin.Shell
|
|||||||
Glyph = "\xE7EF",
|
Glyph = "\xE7EF",
|
||||||
FontFamily = "Segoe MDL2 Assets",
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
AcceleratorKey = Key.Enter,
|
AcceleratorKey = Key.Enter,
|
||||||
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
|
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
|
Execute(Process.Start, PrepareProcessStartInfo(selectedResult.Title, true));
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return resultlist;
|
return resultlist;
|
||||||
|
|||||||
@@ -108,5 +108,19 @@
|
|||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</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>
|
</Project>
|
||||||
@@ -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
|
namespace Microsoft.Plugin.Shell
|
||||||
{
|
{
|
||||||
@@ -9,9 +13,12 @@ namespace Microsoft.Plugin.Shell
|
|||||||
// not overriding Win+R
|
// not overriding Win+R
|
||||||
// crutkas we need to earn the right for Win+R override
|
// crutkas we need to earn the right for Win+R override
|
||||||
public bool ReplaceWinR { get; set; } = false;
|
public bool ReplaceWinR { get; set; } = false;
|
||||||
|
|
||||||
public bool LeaveShellOpen { get; set; }
|
public bool LeaveShellOpen { get; set; }
|
||||||
|
|
||||||
public bool RunAsAdministrator { get; set; } = false;
|
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 Dictionary<string, int> Count = new Dictionary<string, int>();
|
||||||
|
|
||||||
public void AddCmdHistory(string cmdName)
|
public void AddCmdHistory(string cmdName)
|
||||||
@@ -32,6 +39,5 @@ namespace Microsoft.Plugin.Shell
|
|||||||
Cmd = 0,
|
Cmd = 0,
|
||||||
Powershell = 1,
|
Powershell = 1,
|
||||||
RunCommand = 2,
|
RunCommand = 2,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace Microsoft.Plugin.Shell
|
namespace Microsoft.Plugin.Shell
|
||||||
|
|||||||
Reference in New Issue
Block a user