From 3604e6fa7d3a1398e4490295591c68ee813ee008 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 Jul 2016 23:37:06 +0100 Subject: [PATCH 1/5] fix #813 #823 --- Wox/MainWindow.xaml.cs | 6 +++++- Wox/PublicAPIInstance.cs | 4 ++-- Wox/ViewModel/MainViewModel.cs | 18 +++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index de56fa027a..0110e87339 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -235,7 +235,11 @@ namespace Wox private void OnTextChanged(object sender, TextChangedEventArgs e) { - QueryTextBox.CaretIndex = QueryTextBox.Text.Length; + if (_viewModel.QueryTextCursorMovedToEnd) + { + QueryTextBox.CaretIndex = QueryTextBox.Text.Length; + _viewModel.QueryTextCursorMovedToEnd = false; + } } } } \ No newline at end of file diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index e9801f686c..86f415727e 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -36,12 +36,12 @@ namespace Wox public void ChangeQuery(string query, bool requery = false) { - _mainVM.QueryText = query; + _mainVM.ChangeQueryText(query); } public void ChangeQueryText(string query, bool selectAll = false) { - _mainVM.QueryText = query; + _mainVM.ChangeQueryText(query); } [Obsolete] diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index d5fa307f69..8cc43084c8 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -205,7 +205,19 @@ namespace Wox.ViewModel Query(); } } + + /// + /// we need move cursor to end when we manually changed query + /// but we don't want to move cursor to end when query is updated from TextBox + /// + /// + public void ChangeQueryText(string queryText) + { + QueryTextCursorMovedToEnd = true; + QueryText = queryText; + } public bool QueryTextSelected { get; set; } + public bool QueryTextCursorMovedToEnd { get; set; } private ResultsViewModel _selectedResults; private ResultsViewModel SelectedResults @@ -218,7 +230,7 @@ namespace Wox.ViewModel { ContextMenu.Visbility = Visibility.Collapsed; History.Visbility = Visibility.Collapsed; - QueryText = _queryTextBeforeLeaveResults; + ChangeQueryText(_queryTextBeforeLeaveResults); } else { @@ -325,7 +337,7 @@ namespace Wox.ViewModel Action = _ => { SelectedResults = Results; - QueryText = h.Query; + ChangeQueryText(h.Query); return false; } }; @@ -547,7 +559,7 @@ namespace Wox.ViewModel { if (ShouldIgnoreHotkeys()) return; MainWindowVisibility = Visibility.Visible; - QueryText = hotkey.ActionKeyword; + ChangeQueryText(hotkey.ActionKeyword); }); } } From 390d49d59953985f2d895bf49f78d51955890600 Mon Sep 17 00:00:00 2001 From: Jordy Hulck Date: Thu, 21 Jul 2016 15:50:37 +0200 Subject: [PATCH 2/5] Fix SearchSource editing when action keyword is not changed (#856) * Fixed SearchSource edit * Remove temp var --- Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs b/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs index 55eab81e16..d1b1bab7a1 100644 --- a/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs +++ b/Plugins/Wox.Plugin.WebSearch/SearchSourceSetting.xaml.cs @@ -96,11 +96,10 @@ namespace Wox.Plugin.WebSearch private void EditSearchSource() { - var keyword = _searchSource.ActionKeyword; - if (!PluginManager.ActionKeywordRegistered(keyword)) + var newKeyword = _searchSource.ActionKeyword; + var oldKeyword = _oldSearchSource.ActionKeyword; + if (!PluginManager.ActionKeywordRegistered(newKeyword) || oldKeyword == newKeyword) { - var newKeyword = keyword; - var oldKeyword = _oldSearchSource.ActionKeyword; var id = _context.CurrentPluginMetadata.ID; PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword); From c8d81518cc951b48527ac88178e3c71c56ee17e2 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 21 Jul 2016 00:02:13 +0100 Subject: [PATCH 3/5] simple refactoring --- .../Wox.Plugin.Program/FileChangeWatcher.cs | 23 +++++++------------ Plugins/Wox.Plugin.Program/Main.cs | 5 ++-- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs b/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs index 0ab797d9c9..95853d4628 100644 --- a/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs +++ b/Plugins/Wox.Plugin.Program/FileChangeWatcher.cs @@ -1,33 +1,31 @@ using System.Collections.Generic; using System.IO; -using System.Threading; using System.Threading.Tasks; using Wox.Infrastructure.Logger; namespace Wox.Plugin.Program { - internal class FileChangeWatcher + internal static class FileChangeWatcher { - private static bool isIndexing; - private static List watchedPath = new List(); + private static readonly List WatchedPath = new List(); public static void AddWatch(string path, string[] programSuffixes, bool includingSubDirectory = true) { - if (watchedPath.Contains(path)) return; + if (WatchedPath.Contains(path)) return; if (!Directory.Exists(path)) { Log.Warn($"FileChangeWatcher: {path} doesn't exist"); return; } - watchedPath.Add(path); + WatchedPath.Add(path); foreach (string fileType in programSuffixes) { FileSystemWatcher watcher = new FileSystemWatcher { Path = path, IncludeSubdirectories = includingSubDirectory, - Filter = string.Format("*.{0}", fileType), + Filter = $"*.{fileType}", EnableRaisingEvents = true }; watcher.Changed += FileChanged; @@ -39,15 +37,10 @@ namespace Wox.Plugin.Program private static void FileChanged(object source, FileSystemEventArgs e) { - if (!isIndexing) + Task.Run(() => { - Task.Run(() => - { - Main.IndexPrograms(); - isIndexing = false; - }); - } + Main.IndexPrograms(); + }); } - } } diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index bb0beb7f5f..3ce9971c38 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -14,7 +14,7 @@ namespace Wox.Plugin.Program { public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable { - private static object lockObject = new object(); + private static readonly object IndexLock = new object(); private static List _programs = new List(); private static List _sources = new List(); private static readonly Dictionary SourceTypes = new Dictionary @@ -96,8 +96,7 @@ namespace Wox.Plugin.Program public static void IndexPrograms() { - // todo why there is a lock?? - lock (lockObject) + lock (IndexLock) { var sources = DefaultProgramSources(); if (_settings.ProgramSources != null && From 13a51b6bd300fad3836f2e679e7cb561dd3ba728 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 21 Jul 2016 00:22:00 +0100 Subject: [PATCH 4/5] move files --- .../Wox.Plugin.Program/{ => ProgramSources}/IProgramSource.cs | 0 .../Wox.Plugin.Program/{ => ProgramSources}/ProgramSource.cs | 0 Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename Plugins/Wox.Plugin.Program/{ => ProgramSources}/IProgramSource.cs (100%) rename Plugins/Wox.Plugin.Program/{ => ProgramSources}/ProgramSource.cs (100%) diff --git a/Plugins/Wox.Plugin.Program/IProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs similarity index 100% rename from Plugins/Wox.Plugin.Program/IProgramSource.cs rename to Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs diff --git a/Plugins/Wox.Plugin.Program/ProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs similarity index 100% rename from Plugins/Wox.Plugin.Program/ProgramSource.cs rename to Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index cbc3820a35..65accfe305 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -61,7 +61,7 @@ AddProgramSource.xaml - + @@ -69,7 +69,7 @@ ProgramSetting.xaml - + From 3c53c2c56c1ce1c5ef7d35c47ad11845ec28b6ba Mon Sep 17 00:00:00 2001 From: bao-qian Date: Thu, 21 Jul 2016 19:51:47 +0100 Subject: [PATCH 5/5] Program plugin: remove complicated inheritance --- .../AddProgramSource.xaml.cs | 8 +-- Plugins/Wox.Plugin.Program/Main.cs | 30 ++--------- Plugins/Wox.Plugin.Program/Program.cs | 3 +- .../Wox.Plugin.Program/ProgramSetting.xaml.cs | 8 +-- .../ProgramSources/AppPathsProgramSource.cs | 23 +++------ .../CommonStartMenuProgramSource.cs | 36 +++++-------- .../ProgramSources/FileSystemProgramSource.cs | 44 +++++----------- .../ProgramSources/IProgramSource.cs | 49 ------------------ .../ProgramSources/ProgramSource.cs | 51 ++++++++++++++----- .../UserStartMenuProgramSource.cs | 22 ++------ .../ProgramSuffixes.xaml.cs | 1 + Plugins/Wox.Plugin.Program/Settings.cs | 4 +- .../Wox.Plugin.Program.csproj | 1 - 13 files changed, 93 insertions(+), 187 deletions(-) delete mode 100644 Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs diff --git a/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs index 253bce41ff..507626eb05 100644 --- a/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs +++ b/Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Forms; +using Wox.Plugin.Program.ProgramSources; namespace Wox.Plugin.Program { @@ -9,7 +10,7 @@ namespace Wox.Plugin.Program /// public partial class AddProgramSource { - private ProgramSource _editing; + private FileSystemProgramSource _editing; private Settings _settings; public AddProgramSource(Settings settings) @@ -20,7 +21,7 @@ namespace Wox.Plugin.Program Directory.Focus(); } - public AddProgramSource(ProgramSource edit, Settings settings) + public AddProgramSource(FileSystemProgramSource edit, Settings settings) { _editing = edit; _settings = settings; @@ -51,12 +52,11 @@ namespace Wox.Plugin.Program if(_editing == null) { - var source = new ProgramSource + var source = new FileSystemProgramSource { Location = Directory.Text, MaxDepth = max, Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator), - Type = "FileSystemProgramSource", Enabled = true }; _settings.ProgramSources.Add(source); diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index 3ce9971c38..11b4572c81 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -16,14 +16,6 @@ namespace Wox.Plugin.Program { private static readonly object IndexLock = new object(); private static List _programs = new List(); - private static List _sources = new List(); - private static readonly Dictionary SourceTypes = new Dictionary - { - {"FileSystemProgramSource", typeof(FileSystemProgramSource)}, - {"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)}, - {"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)}, - {"AppPathsProgramSource", typeof(AppPathsProgramSource)} - }; private PluginInitContext _context; @@ -105,18 +97,7 @@ namespace Wox.Plugin.Program sources.AddRange(_settings.ProgramSources); } - _sources = sources.AsParallel() - .Where(s => s.Enabled && SourceTypes.ContainsKey(s.Type)) - .Select(s => - { - var sourceClass = SourceTypes[s.Type]; - var constructorInfo = sourceClass.GetConstructor(new[] { typeof(ProgramSource) }); - var programSource = constructorInfo?.Invoke(new object[] { s }) as IProgramSource; - return programSource; - }) - .Where(s => s != null).ToList(); - - _programs = _sources.AsParallel() + _programs = sources.AsParallel() .SelectMany(s => s.LoadPrograms()) // filter duplicate program .GroupBy(x => new { ExecutePath = x.Path, ExecuteName = x.ExecutableName }) @@ -134,23 +115,20 @@ namespace Wox.Plugin.Program { var list = new List { - new ProgramSource + new CommonStartMenuProgramSource { BonusPoints = 0, Enabled = _settings.EnableStartMenuSource, - Type = "CommonStartMenuProgramSource" }, - new ProgramSource + new UserStartMenuProgramSource { BonusPoints = 0, Enabled = _settings.EnableStartMenuSource, - Type = "UserStartMenuProgramSource" }, - new ProgramSource + new AppPathsProgramSource { BonusPoints = -10, Enabled = _settings.EnableRegistrySource, - Type = "AppPathsProgramSource" } }; return list; diff --git a/Plugins/Wox.Plugin.Program/Program.cs b/Plugins/Wox.Plugin.Program/Program.cs index e8c59ac1fc..ff468e674e 100644 --- a/Plugins/Wox.Plugin.Program/Program.cs +++ b/Plugins/Wox.Plugin.Program/Program.cs @@ -2,6 +2,7 @@ using System; using System.Text.RegularExpressions; using System.Threading; using Wox.Infrastructure; +using Wox.Plugin.Program.ProgramSources; namespace Wox.Plugin.Program { @@ -14,6 +15,6 @@ namespace Wox.Plugin.Program public string Directory { get; set; } public string ExecutableName { get; set; } public int Score { get; set; } - public IProgramSource Source { get; set; } + public ProgramSource Source { get; set; } } } \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs index 5f0430e2b0..f54cc7b3e6 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSetting.xaml.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using Wox.Plugin.Program.ProgramSources; namespace Wox.Plugin.Program { @@ -50,7 +51,7 @@ namespace Wox.Plugin.Program private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e) { - ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource; + var selectedProgramSource = programSourceView.SelectedItem as FileSystemProgramSource; if (selectedProgramSource != null) { string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location); @@ -70,7 +71,7 @@ namespace Wox.Plugin.Program private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e) { - ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource; + var selectedProgramSource = programSourceView.SelectedItem as FileSystemProgramSource; if (selectedProgramSource != null) { var add = new AddProgramSource(selectedProgramSource, _settings); @@ -119,10 +120,9 @@ namespace Wox.Plugin.Program { if (Directory.Exists(s)) { - _settings.ProgramSources.Add(new ProgramSource + _settings.ProgramSources.Add(new FileSystemProgramSource { Location = s, - Type = "FileSystemProgramSource", Enabled = true }); diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs index 47c2b7bae5..9f86e868f4 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/AppPathsProgramSource.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using Microsoft.Win32; using Wox.Infrastructure.Logger; @@ -8,24 +7,19 @@ using Wox.Infrastructure.Logger; namespace Wox.Plugin.Program.ProgramSources { [Serializable] - [Browsable(false)] - public class AppPathsProgramSource : AbstractProgramSource + public class AppPathsProgramSource : ProgramSource { public AppPathsProgramSource() { BonusPoints = -10; } - public AppPathsProgramSource(ProgramSource source) : this() - { - BonusPoints = source.BonusPoints; - } - public override List LoadPrograms() { var list = new List(); ReadAppPaths(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", list); - ReadAppPaths(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths", list); //TODO: need test more on 64-bit + ReadAppPaths(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths", list); + //TODO: need test more on 64-bit return list; } @@ -40,12 +34,12 @@ namespace Wox.Plugin.Program.ProgramSources { using (var key = root.OpenSubKey(item)) { - string path = key.GetValue("") as string; + var path = key.GetValue("") as string; if (string.IsNullOrEmpty(path)) continue; // fix path like this ""\"C:\\folder\\executable.exe\""" const int begin = 0; - int end = path.Length - 1; + var end = path.Length - 1; const char quotationMark = '"'; if (path[begin] == quotationMark && path[end] == quotationMark) { @@ -66,10 +60,5 @@ namespace Wox.Plugin.Program.ProgramSources } } } - - public override string ToString() - { - return typeof(AppPathsProgramSource).Name; - } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/CommonStartMenuProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/CommonStartMenuProgramSource.cs index 2eee434c96..185330be62 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/CommonStartMenuProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/CommonStartMenuProgramSource.cs @@ -1,40 +1,30 @@ using System; -using System.ComponentModel; using System.Runtime.InteropServices; using System.Text; namespace Wox.Plugin.Program.ProgramSources { [Serializable] - [Browsable(false)] - public class CommonStartMenuProgramSource : FileSystemProgramSource + public sealed class CommonStartMenuProgramSource : FileSystemProgramSource { + private const int CSIDL_COMMON_PROGRAMS = 0x17; + + // todo happlebao how to pass location before loadPrograms + public CommonStartMenuProgramSource() + { + Location = getPath(); + } + [DllImport("shell32.dll")] - static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate); - const int CSIDL_COMMON_PROGRAMS = 0x17; + private static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, + bool fCreate); private static string getPath() { - StringBuilder commonStartMenuPath = new StringBuilder(560); + var commonStartMenuPath = new StringBuilder(560); SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false); return commonStartMenuPath.ToString(); } - - public CommonStartMenuProgramSource(string[] suffixes) - : base(getPath(), suffixes) - { - } - - public CommonStartMenuProgramSource(ProgramSource source) - : this(source.Suffixes) - { - BonusPoints = source.BonusPoints; - } - - public override string ToString() - { - return typeof(CommonStartMenuProgramSource).Name; - } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs index 420d6172a3..718aafd7cc 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/FileSystemProgramSource.cs @@ -8,35 +8,17 @@ using Wox.Infrastructure.Logger; namespace Wox.Plugin.Program.ProgramSources { [Serializable] - public class FileSystemProgramSource : AbstractProgramSource + public class FileSystemProgramSource : ProgramSource { - private string _baseDirectory; - private int _maxDepth; - private string[] _suffixes; - - public FileSystemProgramSource(string baseDirectory, int maxDepth, string[] suffixes) - { - _baseDirectory = baseDirectory; - _maxDepth = maxDepth; - _suffixes = suffixes; - } - - public FileSystemProgramSource(string baseDirectory, string[] suffixes) - : this(baseDirectory, -1, suffixes) {} - - public FileSystemProgramSource(ProgramSource source) - : this(source.Location, source.MaxDepth, source.Suffixes) - { - BonusPoints = source.BonusPoints; - } + public string Location { get; set; } = ""; public override List LoadPrograms() { - List list = new List(); - if (Directory.Exists(_baseDirectory)) + var list = new List(); + if (Directory.Exists(Location)) { - GetAppFromDirectory(_baseDirectory, list); - FileChangeWatcher.AddWatch(_baseDirectory, _suffixes); + GetAppFromDirectory(Location, list); + FileChangeWatcher.AddWatch(Location, Suffixes); } return list; } @@ -48,17 +30,17 @@ namespace Wox.Plugin.Program.ProgramSources private void GetAppFromDirectory(string path, List list, int depth) { - if(_maxDepth != -1 && depth > _maxDepth) + if (MaxDepth != -1 && depth > MaxDepth) { return; } try { - foreach (string file in Directory.GetFiles(path)) + foreach (var file in Directory.GetFiles(path)) { - if (_suffixes.Any(o => file.EndsWith("." + o))) + if (Suffixes.Any(o => file.EndsWith("." + o))) { - Program p = CreateEntry(file); + var p = CreateEntry(file); p.Source = this; list.Add(p); } @@ -75,10 +57,10 @@ namespace Wox.Plugin.Program.ProgramSources Log.Exception(woxPluginException); } } - public override string ToString() { - return typeof(FileSystemProgramSource).Name + ":" + _baseDirectory; + var display = GetType().Name + Location; + return display; } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs deleted file mode 100644 index 6df37995c9..0000000000 --- a/Plugins/Wox.Plugin.Program/ProgramSources/IProgramSource.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; - -namespace Wox.Plugin.Program -{ - public interface IProgramSource - { - List LoadPrograms(); - int BonusPoints { get; set; } - } - - [Serializable] - public abstract class AbstractProgramSource : IProgramSource - { - public abstract List LoadPrograms(); - - public int BonusPoints { get; set; } - - protected Program CreateEntry(string file) - { - var p = new Program - { - Title = Path.GetFileNameWithoutExtension(file), - IcoPath = file, - Path = file, - Directory = Directory.GetParent(file).FullName - }; - - switch (Path.GetExtension(file).ToLower()) - { - case ".exe": - p.ExecutableName = Path.GetFileName(file); - try - { - FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(file); - if (!string.IsNullOrEmpty(versionInfo.FileDescription)) - { - p.Title = versionInfo.FileDescription; - } - } - catch (Exception) { } - break; - } - return p; - } - } -} diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs index 1345c51f4a..9e4e839e32 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/ProgramSource.cs @@ -1,24 +1,51 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; -namespace Wox.Plugin.Program +namespace Wox.Plugin.Program.ProgramSources { [Serializable] - public class ProgramSource + public abstract class ProgramSource { - public string Location { get; set; } - public string Type { get; set; } - public int BonusPoints { get; set; } - public bool Enabled { get; set; } + public const char SuffixSeperator = ';'; + + public int BonusPoints { get; set; } = 0; + public bool Enabled { get; set; } = true; // happlebao todo: temp hack for program suffixes public string[] Suffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"}; - public const char SuffixSeperator = ';'; - public int MaxDepth { get; set; } - public Dictionary Meta { get; set; } + public int MaxDepth { get; set; } = -1; - public override string ToString() + public abstract List LoadPrograms(); + + protected Program CreateEntry(string file) { - return (Type ?? "") + ":" + Location ?? ""; + var p = new Program + { + Title = Path.GetFileNameWithoutExtension(file), + IcoPath = file, + Path = file, + Directory = Directory.GetParent(file).FullName + }; + + switch (Path.GetExtension(file).ToLower()) + { + case ".exe": + p.ExecutableName = Path.GetFileName(file); + try + { + var versionInfo = FileVersionInfo.GetVersionInfo(file); + if (!string.IsNullOrEmpty(versionInfo.FileDescription)) + { + p.Title = versionInfo.FileDescription; + } + } + catch (Exception) + { + } + break; + } + return p; } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSources/UserStartMenuProgramSource.cs b/Plugins/Wox.Plugin.Program/ProgramSources/UserStartMenuProgramSource.cs index 97acba337f..d6489c0f45 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSources/UserStartMenuProgramSource.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSources/UserStartMenuProgramSource.cs @@ -1,26 +1,14 @@ using System; -using System.ComponentModel; namespace Wox.Plugin.Program.ProgramSources { + [Serializable] - [Browsable(false)] - public class UserStartMenuProgramSource : FileSystemProgramSource + public sealed class UserStartMenuProgramSource : FileSystemProgramSource { - public UserStartMenuProgramSource(string[] suffixes) - : base(Environment.GetFolderPath(Environment.SpecialFolder.Programs), suffixes) + public UserStartMenuProgramSource() { - } - - public UserStartMenuProgramSource(ProgramSource source) - : this(source.Suffixes) - { - BonusPoints = source.BonusPoints; - } - - public override string ToString() - { - return typeof(UserStartMenuProgramSource).Name; + Location = Environment.GetFolderPath(Environment.SpecialFolder.Programs); } } -} +} \ No newline at end of file diff --git a/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs b/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs index 390e16d164..e484ba55ab 100644 --- a/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs +++ b/Plugins/Wox.Plugin.Program/ProgramSuffixes.xaml.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Linq; +using Wox.Plugin.Program.ProgramSources; namespace Wox.Plugin.Program { diff --git a/Plugins/Wox.Plugin.Program/Settings.cs b/Plugins/Wox.Plugin.Program/Settings.cs index 9acd01d727..6fc052247c 100644 --- a/Plugins/Wox.Plugin.Program/Settings.cs +++ b/Plugins/Wox.Plugin.Program/Settings.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.ComponentModel; +using Wox.Plugin.Program.ProgramSources; namespace Wox.Plugin.Program { public class Settings { - public List ProgramSources { get; set; } = new List(); + public List ProgramSources { get; set; } = new List(); public string[] ProgramSuffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"}; public bool EnableStartMenuSource { get; set; } = true; diff --git a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj index 65accfe305..874d0b5b48 100644 --- a/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj +++ b/Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj @@ -61,7 +61,6 @@ AddProgramSource.xaml -