diff --git a/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Class1.cs b/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Class1.cs deleted file mode 100644 index 5955ce0204..0000000000 --- a/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Wox.Plugin.Indexer -{ - public class Class1 - { - } -} diff --git a/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Main.cs b/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Main.cs new file mode 100644 index 0000000000..652af40c40 --- /dev/null +++ b/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Main.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Diagnostics; +using System.Text; +using System.Threading.Tasks; +using Wox.Plugin; +using System.IO; +using System.ComponentModel; +using Wox.Infrastructure.Storage; +using Wox.Plugin.Indexer.SearchHelper; +using Microsoft.Search.Interop; + +namespace Wox.Plugin.Indexer +{ + class Main : IPlugin, ISavable, IPluginI18n + { + + // This variable contains metadata about the Plugin + private PluginInitContext _context; + + // This variable contains information about the context menus + private Settings _settings; + + // Contains information about the plugin stored in json format + private PluginJsonStorage _storage; + + // To access Windows Search functionalities + private readonly WindowsSearchAPI _api = new WindowsSearchAPI(); + + // To save the configurations of plugins + public void Save() + { + _storage.Save(); + } + + // This function uses the Windows indexer and returns the list of results obtained + public List Query(Query query) + { + var results = new List(); + if (!string.IsNullOrEmpty(query.Search)) + { + var searchQuery = query.Search; + if (_settings.MaxSearchCount <= 0) + { + _settings.MaxSearchCount = 50; + } + + try + { + var searchResultsList = _api.Search(searchQuery, maxCount: _settings.MaxSearchCount).ToList(); + foreach (var searchResult in searchResultsList) + { + var path = searchResult.Path; + + string workingDir = null; + if (_settings.UseLocationAsWorkingDir) + workingDir = Path.GetDirectoryName(path); + + Result r = new Result(); + r.Title = Path.GetFileName(path); + r.SubTitle = path; + r.IcoPath = path; + r.Action = c => + { + bool hide; + try + { + Process.Start(new ProcessStartInfo + { + FileName = path, + UseShellExecute = true, + WorkingDirectory = workingDir + }); + hide = true; + } + catch (Win32Exception) + { + var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; + var msg = "Can't Open this file"; + _context.API.ShowMsg(name, msg, string.Empty); + hide = false; + } + return hide; + }; + r.ContextData = searchResult; + results.Add(r); + } + } + catch (Exception ex) + { + results.Add(new Result + { + // TODO: Localize the string + Title = "Windows indexer plugin is not running", + IcoPath = "Images\\WindowsIndexerImg.bmp" + }); + } + } + + return results; + } + + public void Init(PluginInitContext context) + { + // initialize the context of the plugin + _context = context; + _storage = new PluginJsonStorage(); + _settings = _storage.Load(); + } + + // TODO: Localize the strings + // Set the Plugin Title + public string GetTranslatedPluginTitle() + { + return "Windows Indexer Plugin"; + } + + // TODO: Localize the string + // Set the plugin Description + public string GetTranslatedPluginDescription() + { + return "Returns files and folders"; + } + + + } +} diff --git a/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Settings.cs b/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Settings.cs new file mode 100644 index 0000000000..6fc9bbbf94 --- /dev/null +++ b/src/modules/launcher/Plugins/Wox.Plugin.Indexer/Settings.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wox.Plugin.Indexer +{ + public class Settings + { + public List ContextMenus = new List(); + public int MaxSearchCount { get; set; } = 100; + public bool UseLocationAsWorkingDir { get; set; } = false; + } + + public class ContextMenu + { + public string Name { get; set; } + public string Command { get; set; } + public string Argument { get; set; } + public string ImagePath { get; set; } + } +}