mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
ReSharper: remove redundant code
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
{
|
||||
@@ -16,51 +17,51 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public AddProgramSource(ProgramSource edit) : this()
|
||||
{
|
||||
this._editing = edit;
|
||||
this.Directory.Text = this._editing.Location;
|
||||
this.MaxDepth.Text = this._editing.MaxDepth.ToString();
|
||||
this.Suffixes.Text = this._editing.Suffixes;
|
||||
_editing = edit;
|
||||
Directory.Text = _editing.Location;
|
||||
MaxDepth.Text = _editing.MaxDepth.ToString();
|
||||
Suffixes.Text = _editing.Suffixes;
|
||||
}
|
||||
|
||||
private void BrowseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new System.Windows.Forms.FolderBrowserDialog();
|
||||
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
|
||||
var dialog = new FolderBrowserDialog();
|
||||
DialogResult result = dialog.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
this.Directory.Text = dialog.SelectedPath;
|
||||
Directory.Text = dialog.SelectedPath;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
int max;
|
||||
if(!int.TryParse(this.MaxDepth.Text, out max))
|
||||
if(!int.TryParse(MaxDepth.Text, out max))
|
||||
{
|
||||
max = -1;
|
||||
}
|
||||
|
||||
if(this._editing == null)
|
||||
if(_editing == null)
|
||||
{
|
||||
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
|
||||
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource
|
||||
{
|
||||
Location = this.Directory.Text,
|
||||
Location = Directory.Text,
|
||||
MaxDepth = max,
|
||||
Suffixes = this.Suffixes.Text,
|
||||
Suffixes = Suffixes.Text,
|
||||
Type = "FileSystemProgramSource",
|
||||
Enabled = true
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this._editing.Location = this.Directory.Text;
|
||||
this._editing.MaxDepth = max;
|
||||
this._editing.Suffixes = this.Suffixes.Text;
|
||||
_editing.Location = Directory.Text;
|
||||
_editing.MaxDepth = max;
|
||||
_editing.Suffixes = Suffixes.Text;
|
||||
}
|
||||
|
||||
ProgramStorage.Instance.Save();
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
DialogResult = true;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
internal class FileChangeWatcher
|
||||
{
|
||||
private static bool isIndexing = false;
|
||||
private static bool isIndexing;
|
||||
private static List<string> watchedPath = new List<string>();
|
||||
|
||||
public static void AddWatch(string path, bool includingSubDirectory = true)
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
protected Program CreateEntry(string file)
|
||||
{
|
||||
var p = new Program()
|
||||
var p = new Program
|
||||
{
|
||||
Title = Path.GetFileNameWithoutExtension(file),
|
||||
IcoPath = file,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using Wox.Infrastructure;
|
||||
|
||||
namespace Wox.Plugin.Program
|
||||
@@ -6,7 +8,7 @@ namespace Wox.Plugin.Program
|
||||
[Serializable]
|
||||
public class Program
|
||||
{
|
||||
private static readonly global::System.Text.RegularExpressions.Regex AbbrRegexp = new global::System.Text.RegularExpressions.Regex("[^A-Z0-9]", global::System.Text.RegularExpressions.RegexOptions.Compiled);
|
||||
private static readonly Regex AbbrRegexp = new Regex("[^A-Z0-9]", RegexOptions.Compiled);
|
||||
private string m_Title;
|
||||
public string Title
|
||||
{
|
||||
@@ -19,7 +21,7 @@ namespace Wox.Plugin.Program
|
||||
m_Title = value;
|
||||
string pinyin = m_Title.Unidecode();
|
||||
PinyinTitle = pinyin;
|
||||
AbbrTitle = AbbrRegexp.Replace(global::System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(pinyin), "");
|
||||
AbbrTitle = AbbrRegexp.Replace(Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(pinyin), "");
|
||||
if (AbbrTitle.Length < 2) AbbrTitle = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -31,9 +31,9 @@ namespace Wox.Plugin.Program
|
||||
programSourceView.Items.Refresh();
|
||||
ThreadPool.QueueUserWorkItem(t =>
|
||||
{
|
||||
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Visible; }));
|
||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Visible; });
|
||||
Programs.IndexPrograms();
|
||||
Dispatcher.Invoke(new Action(() => { indexingPanel.Visibility = Visibility.Hidden; }));
|
||||
Dispatcher.Invoke(() => { indexingPanel.Visibility = Visibility.Hidden; });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Wox.Plugin.Program
|
||||
var add = new AddProgramSource();
|
||||
if(add.ShowDialog() ?? false)
|
||||
{
|
||||
this.ReIndexing();
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace Wox.Plugin.Program
|
||||
var add = new AddProgramSource(selectedProgramSource);
|
||||
if (add.ShowDialog() ?? false)
|
||||
{
|
||||
this.ReIndexing();
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -116,9 +116,9 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
foreach (string s in files)
|
||||
{
|
||||
if (System.IO.Directory.Exists(s) == true)
|
||||
if (Directory.Exists(s))
|
||||
{
|
||||
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource()
|
||||
ProgramStorage.Instance.ProgramSources.Add(new ProgramSource
|
||||
{
|
||||
Location = s,
|
||||
Type = "FileSystemProgramSource",
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (this.Type ?? "") + ":" + this.Location ?? "";
|
||||
return (Type ?? "") + ":" + Location ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
[Serializable]
|
||||
[System.ComponentModel.Browsable(false)]
|
||||
[Browsable(false)]
|
||||
public class AppPathsProgramSource : AbstractProgramSource
|
||||
{
|
||||
public AppPathsProgramSource()
|
||||
@@ -28,7 +31,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
|
||||
private void ReadAppPaths(string rootpath, List<Program> list)
|
||||
{
|
||||
using (var root = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(rootpath))
|
||||
using (var root = Registry.LocalMachine.OpenSubKey(rootpath))
|
||||
{
|
||||
if (root == null) return;
|
||||
foreach (var item in root.GetSubKeyNames())
|
||||
@@ -49,7 +52,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
path = path.Substring(begin + 1, path.Length - 2);
|
||||
}
|
||||
|
||||
if (!System.IO.File.Exists(path)) continue;
|
||||
if (!File.Exists(path)) continue;
|
||||
var entry = CreateEntry(path);
|
||||
entry.ExecuteName = item;
|
||||
list.Add(entry);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
[Serializable]
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
[Browsable(false)]
|
||||
public class CommonStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
[DllImport("shell32.dll")]
|
||||
@@ -28,7 +29,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
public CommonStartMenuProgramSource(ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
public FileSystemProgramSource(ProgramSource source)
|
||||
: this(source.Location, source.MaxDepth, source.Suffixes)
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
@@ -78,7 +78,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(FileSystemProgramSource).Name + ":" + this.baseDirectory;
|
||||
return typeof(FileSystemProgramSource).Name + ":" + baseDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Wox.Plugin.Program.ProgramSources
|
||||
{
|
||||
[Serializable]
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
[Browsable(false)]
|
||||
public class UserStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
public UserStartMenuProgramSource()
|
||||
@@ -14,7 +15,7 @@ namespace Wox.Plugin.Program.ProgramSources
|
||||
public UserStartMenuProgramSource(ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin.Program.ProgramSources;
|
||||
@@ -17,11 +18,12 @@ namespace Wox.Plugin.Program
|
||||
private static object lockObject = new object();
|
||||
private static List<Program> programs = new List<Program>();
|
||||
private static List<IProgramSource> sources = new List<IProgramSource>();
|
||||
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>() {
|
||||
private static Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>
|
||||
{
|
||||
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
||||
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
|
||||
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
|
||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)},
|
||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
|
||||
};
|
||||
private PluginInitContext context;
|
||||
|
||||
@@ -32,14 +34,14 @@ namespace Wox.Plugin.Program
|
||||
var results = programs.Where(p => MatchProgram(p, fuzzyMather)).
|
||||
Select(ScoreFilter).
|
||||
OrderByDescending(p => p.Score)
|
||||
.Select(c => new Result()
|
||||
.Select(c => new Result
|
||||
{
|
||||
Title = c.Title,
|
||||
SubTitle = c.ExecutePath,
|
||||
IcoPath = c.IcoPath,
|
||||
Score = c.Score,
|
||||
ContextData = c,
|
||||
Action = (e) =>
|
||||
Action = e =>
|
||||
{
|
||||
context.API.HideApp();
|
||||
Process.Start(c.ExecutePath);
|
||||
@@ -128,19 +130,19 @@ namespace Wox.Plugin.Program
|
||||
private static List<ProgramSource> LoadDeaultProgramSources()
|
||||
{
|
||||
var list = new List<ProgramSource>();
|
||||
list.Add(new ProgramSource()
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = 0,
|
||||
Enabled = ProgramStorage.Instance.EnableStartMenuSource,
|
||||
Type = "CommonStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource()
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = 0,
|
||||
Enabled = ProgramStorage.Instance.EnableStartMenuSource,
|
||||
Type = "UserStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource()
|
||||
list.Add(new ProgramSource
|
||||
{
|
||||
BonusPoints = -10,
|
||||
Enabled = ProgramStorage.Instance.EnableRegistrySource,
|
||||
@@ -166,7 +168,7 @@ namespace Wox.Plugin.Program
|
||||
|
||||
#region ISettingProvider Members
|
||||
|
||||
public System.Windows.Controls.Control CreateSettingPanel()
|
||||
public Control CreateSettingPanel()
|
||||
{
|
||||
return new ProgramSetting(context);
|
||||
}
|
||||
@@ -190,9 +192,9 @@ namespace Wox.Plugin.Program
|
||||
public List<Result> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
Program p = selectedResult.ContextData as Program;
|
||||
List<Result> contextMenus = new List<Result>()
|
||||
List<Result> contextMenus = new List<Result>
|
||||
{
|
||||
new Result()
|
||||
new Result
|
||||
{
|
||||
Title = context.API.GetTranslation("wox_plugin_program_run_as_administrator"),
|
||||
Action = _ =>
|
||||
@@ -207,7 +209,7 @@ namespace Wox.Plugin.Program
|
||||
},
|
||||
IcoPath = "Images/cmd.png"
|
||||
},
|
||||
new Result()
|
||||
new Result
|
||||
{
|
||||
Title = context.API.GetTranslation("wox_plugin_program_open_containing_folder"),
|
||||
Action = _ =>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -6,13 +7,13 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
public class StringEmptyConverter : MarkupExtension, IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.IsNullOrEmpty((string)value) ? parameter : value;
|
||||
}
|
||||
|
||||
public object ConvertBack(
|
||||
object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user