mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-24 12:25:12 +08:00
Enabling StyleCop for folder plugin (#5844)
This commit is contained in:
parent
013ffe1626
commit
7bfd0823db
@ -1,16 +1,17 @@
|
||||
// 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.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Plugin.SharedCommands;
|
||||
using Wox.Plugin;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
@ -57,7 +58,7 @@ namespace Microsoft.Plugin.Folder
|
||||
_context.API.ShowMsg(message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
contextMenus.Add(new ContextMenuResult
|
||||
@ -89,7 +90,7 @@ namespace Microsoft.Plugin.Folder
|
||||
Log.Exception($"|Microsoft.Plugin.Folder.ContextMenuLoader.LoadContextMenus| Failed to open {record.FullPath} in console, {e.Message}", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -106,7 +107,7 @@ namespace Microsoft.Plugin.Folder
|
||||
Glyph = "\xE838",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.E,
|
||||
AcceleratorModifiers = (ModifierKeys.Control | ModifierKeys.Shift),
|
||||
AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift,
|
||||
Action = _ =>
|
||||
{
|
||||
try
|
||||
@ -122,7 +123,7 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -132,16 +133,10 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
}
|
||||
|
||||
public class SearchResult
|
||||
{
|
||||
public string FullPath { get; set; }
|
||||
public ResultType Type { get; set; }
|
||||
}
|
||||
|
||||
public enum ResultType
|
||||
{
|
||||
Volume,
|
||||
Folder,
|
||||
File
|
||||
File,
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
using System;
|
||||
// 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.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -11,8 +11,8 @@
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
<ListView x:Name="lbxFolders" Grid.Row="0" AllowDrop="True"
|
||||
Drop="lbxFolders_Drop"
|
||||
DragEnter="lbxFolders_DragEnter">
|
||||
Drop="LbxFolders_Drop"
|
||||
DragEnter="LbxFolders_DragEnter">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="{DynamicResource wox_plugin_folder_folder_path}" Width="180">
|
||||
@ -26,9 +26,9 @@
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<Button x:Name="btnDelete" Click="btnDelete_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_delete}"/>
|
||||
<Button x:Name="btnEdit" Click="btnEdit_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_edit}"/>
|
||||
<Button x:Name="btnAdd" Click="btnAdd_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_add}"/>
|
||||
<Button x:Name="btnDelete" Click="BtnDelete_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_delete}"/>
|
||||
<Button x:Name="btnEdit" Click="BtnEdit_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_edit}"/>
|
||||
<Button x:Name="btnAdd" Click="BtnAdd_Click" Width="100" Margin="10" Content="{DynamicResource wox_plugin_folder_add}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
@ -1,5 +1,8 @@
|
||||
using System;
|
||||
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;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -13,26 +16,24 @@ using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
|
||||
public partial class FileSystemSettings
|
||||
{
|
||||
private IPublicAPI woxAPI;
|
||||
private IPublicAPI _woxAPI;
|
||||
private FolderSettings _settings;
|
||||
|
||||
public FileSystemSettings(IPublicAPI woxAPI, FolderSettings settings)
|
||||
{
|
||||
this.woxAPI = woxAPI;
|
||||
_woxAPI = woxAPI;
|
||||
InitializeComponent();
|
||||
_settings = settings ?? throw new ArgumentNullException(paramName:nameof(settings));
|
||||
_settings = settings ?? throw new ArgumentNullException(paramName: nameof(settings));
|
||||
lbxFolders.ItemsSource = _settings.FolderLinks;
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, RoutedEventArgs e)
|
||||
private void BtnDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedFolder = lbxFolders.SelectedItem as FolderLink;
|
||||
if (selectedFolder != null)
|
||||
if (lbxFolders.SelectedItem is FolderLink selectedFolder)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, woxAPI.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path);
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _woxAPI.GetTranslation("wox_plugin_folder_delete_folder_link"), selectedFolder.Path);
|
||||
|
||||
if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
@ -42,15 +43,14 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
else
|
||||
{
|
||||
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
|
||||
string warning = _woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEdit_Click(object sender, RoutedEventArgs e)
|
||||
private void BtnEdit_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedFolder = lbxFolders.SelectedItem as FolderLink;
|
||||
if (selectedFolder != null)
|
||||
if (lbxFolders.SelectedItem is FolderLink selectedFolder)
|
||||
{
|
||||
using (var folderBrowserDialog = new FolderBrowserDialog())
|
||||
{
|
||||
@ -66,12 +66,12 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
else
|
||||
{
|
||||
string warning = woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
|
||||
string warning = _woxAPI.GetTranslation("wox_plugin_folder_select_folder_link_warning");
|
||||
MessageBox.Show(warning);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||
private void BtnAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
using (var folderBrowserDialog = new FolderBrowserDialog())
|
||||
{
|
||||
@ -79,7 +79,7 @@ namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
var newFolder = new FolderLink
|
||||
{
|
||||
Path = folderBrowserDialog.SelectedPath
|
||||
Path = folderBrowserDialog.SelectedPath,
|
||||
};
|
||||
|
||||
_settings.FolderLinks.Add(newFolder);
|
||||
@ -89,7 +89,7 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
}
|
||||
|
||||
private void lbxFolders_Drop(object sender, DragEventArgs e)
|
||||
private void LbxFolders_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
|
||||
@ -101,7 +101,7 @@ namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
var newFolder = new FolderLink
|
||||
{
|
||||
Path = s
|
||||
Path = s,
|
||||
};
|
||||
|
||||
_settings.FolderLinks.Add(newFolder);
|
||||
@ -112,7 +112,7 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
}
|
||||
|
||||
private void lbxFolders_DragEnter(object sender, DragEventArgs e)
|
||||
private void LbxFolders_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
||||
{
|
||||
|
@ -0,0 +1,15 @@
|
||||
// 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;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
public class FolderSettings
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<FolderLink> FolderLinks { get; } = new List<FolderLink>();
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
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.Diagnostics;
|
||||
@ -8,6 +11,7 @@ using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
@ -22,11 +26,13 @@ namespace Microsoft.Plugin.Folder
|
||||
public const string CopyImagePath = "Images\\copy.dark.png";
|
||||
|
||||
private const string _fileExplorerProgramName = "explorer";
|
||||
private static List<string> _driverNames;
|
||||
private PluginInitContext _context;
|
||||
|
||||
private readonly FolderSettings _settings;
|
||||
private readonly PluginJsonStorage<FolderSettings> _storage;
|
||||
|
||||
private static List<string> _driverNames;
|
||||
private PluginInitContext _context;
|
||||
|
||||
private IContextMenu _contextMenuLoader;
|
||||
|
||||
public Main()
|
||||
@ -55,7 +61,7 @@ namespace Microsoft.Plugin.Folder
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
if(query == null)
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName: nameof(query));
|
||||
}
|
||||
@ -64,7 +70,9 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
string search = query.Search.ToLower(CultureInfo.InvariantCulture);
|
||||
if (!IsDriveOrSharedFolder(search))
|
||||
{
|
||||
return results;
|
||||
}
|
||||
|
||||
results.AddRange(QueryInternal_Directory_Exists(query));
|
||||
|
||||
@ -111,14 +119,14 @@ namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
Process.Start(_fileExplorerProgramName, path);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
|
||||
private List<Result> GetUserFolderResults(Query query)
|
||||
{
|
||||
if(query == null)
|
||||
if (query == null)
|
||||
{
|
||||
throw new ArgumentNullException(paramName: nameof(query));
|
||||
}
|
||||
@ -147,7 +155,7 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
private static readonly char[] _specialSearchChars = new char[]
|
||||
{
|
||||
'?', '*', '>'
|
||||
'?', '*', '>',
|
||||
};
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "Do not want to change the behavior of the application, but want to enforce static analysis")]
|
||||
@ -156,7 +164,7 @@ namespace Microsoft.Plugin.Folder
|
||||
var search = query.Search;
|
||||
var results = new List<Result>();
|
||||
var hasSpecial = search.IndexOfAny(_specialSearchChars) >= 0;
|
||||
string incompleteName = "";
|
||||
string incompleteName = string.Empty;
|
||||
if (hasSpecial || !Directory.Exists(search + "\\"))
|
||||
{
|
||||
// if folder doesn't exist, we want to take the last part and use it afterwards to help the user
|
||||
@ -185,7 +193,7 @@ namespace Microsoft.Plugin.Folder
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(CreateOpenCurrentFolderResult( search));
|
||||
results.Add(CreateOpenCurrentFolderResult(search));
|
||||
|
||||
var searchOption = SearchOption.TopDirectoryOnly;
|
||||
incompleteName += "*";
|
||||
@ -210,7 +218,10 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
foreach (var fileSystemInfo in fileSystemInfos)
|
||||
{
|
||||
if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
|
||||
if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fileSystemInfo is DirectoryInfo)
|
||||
{
|
||||
@ -262,7 +273,7 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
return true;
|
||||
},
|
||||
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath }
|
||||
ContextData = new SearchResult { Type = ResultType.File, FullPath = filePath },
|
||||
};
|
||||
return result;
|
||||
}
|
||||
@ -273,6 +284,7 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
var folderName = search.TrimEnd('\\').Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last();
|
||||
var sanitizedPath = Regex.Replace(search, @"[\/\\]+", "\\");
|
||||
|
||||
// A network path must start with \\
|
||||
if (sanitizedPath.StartsWith("\\", StringComparison.InvariantCulture))
|
||||
{
|
||||
@ -290,7 +302,7 @@ namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
Process.Start(_fileExplorerProgramName, sanitizedPath);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -311,7 +323,6 @@ namespace Microsoft.Plugin.Folder
|
||||
|
||||
public void UpdateSettings(PowerLauncherSettings settings)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -135,5 +135,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>
|
@ -0,0 +1,24 @@
|
||||
// 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.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
public string FullPath { get; set; }
|
||||
|
||||
public ResultType Type { get; set; }
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
namespace Microsoft.Plugin.Folder
|
||||
{
|
||||
public class FolderSettings
|
||||
{
|
||||
[JsonProperty]
|
||||
public List<FolderLink> FolderLinks { get;} = new List<FolderLink>();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user