From 6b9f96697bb53f38ad01a11dee7ae9ef05924e72 Mon Sep 17 00:00:00 2001 From: Aaron Campf Date: Sun, 30 Mar 2014 16:03:07 -0700 Subject: [PATCH] Added Plugin for searching additional directories --- LICENSE | 1 - .../Storage/UserSettings/FolderLink.cs | 10 ++ .../UserSettings/UserSettingStorage.cs | 3 + Wox.Infrastructure/Wox.Infrastructure.csproj | 1 + .../DirectoryIndicator.cs | 3 +- .../Folder Links/FolderLink.cs | 10 ++ .../Folder Links/FolderLinksPlugin.cs | 143 ++++++++++++++++++ .../Folder Links/FolderLinksSettings.xaml | 32 ++++ .../Folder Links/FolderLinksSettings.xaml.cs | 64 ++++++++ .../Folder Links/FolderLinks_Edit.xaml | 32 ++++ .../Folder Links/FolderLinks_Edit.xaml.cs | 24 +++ .../Wox.Plugin.SystemPlugins.csproj | 8 + 12 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 Wox.Infrastructure/Storage/UserSettings/FolderLink.cs create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLink.cs create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLinksPlugin.cs create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLinksSettings.xaml create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLinksSettings.xaml.cs create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLinks_Edit.xaml create mode 100644 Wox.Plugin.SystemPlugins/Folder Links/FolderLinks_Edit.xaml.cs diff --git a/LICENSE b/LICENSE index 81c06e2b15..f12e92657f 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,3 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - \ No newline at end of file diff --git a/Wox.Infrastructure/Storage/UserSettings/FolderLink.cs b/Wox.Infrastructure/Storage/UserSettings/FolderLink.cs new file mode 100644 index 0000000000..2479443ed2 --- /dev/null +++ b/Wox.Infrastructure/Storage/UserSettings/FolderLink.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Infrastructure.Storage.UserSettings { + public class FolderLink { + public string Path { get; set; } + } +} diff --git a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs index f876498dd6..3723a14c07 100644 --- a/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs +++ b/Wox.Infrastructure/Storage/UserSettings/UserSettingStorage.cs @@ -47,6 +47,9 @@ namespace Wox.Infrastructure.Storage.UserSettings [JsonProperty] public List ProgramSources { get; set; } + [JsonProperty] + public List FolderLinks { get; set; } //Aaron + [JsonProperty] public List CustomPluginHotkeys { get; set; } diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index 1fde15964c..d1dda9db37 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -49,6 +49,7 @@ + diff --git a/Wox.Plugin.SystemPlugins/DirectoryIndicator.cs b/Wox.Plugin.SystemPlugins/DirectoryIndicator.cs index 80372bf675..da3c398eee 100644 --- a/Wox.Plugin.SystemPlugins/DirectoryIndicator.cs +++ b/Wox.Plugin.SystemPlugins/DirectoryIndicator.cs @@ -30,7 +30,8 @@ namespace Wox.Plugin.SystemPlugins InitialDriverList(); var input = query.RawQuery.ToLower(); - if (driverNames.FirstOrDefault(x => input.StartsWith(x)) == null) return results; + //if (driverNames.FirstOrDefault(x => input.StartsWith(x)) == null) return results; + if (!driverNames.Any(x => input.StartsWith(x))) return results; if (Directory.Exists(query.RawQuery)) { diff --git a/Wox.Plugin.SystemPlugins/Folder Links/FolderLink.cs b/Wox.Plugin.SystemPlugins/Folder Links/FolderLink.cs new file mode 100644 index 0000000000..a61a18cb0b --- /dev/null +++ b/Wox.Plugin.SystemPlugins/Folder Links/FolderLink.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Plugin.SystemPlugins.Folder_Links { + public class FolderLink { + public string Path { get; set; } + } +} diff --git a/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksPlugin.cs b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksPlugin.cs new file mode 100644 index 0000000000..d60f5a4fa5 --- /dev/null +++ b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksPlugin.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using Wox.Infrastructure.Storage.UserSettings; + +namespace Wox.Plugin.SystemPlugins.Folder_Links { + public class FolderLinksPlugin : BaseSystemPlugin, ISettingProvider { + private PluginInitContext context; + + //private static List driverNames = null; + private static Dictionary parentDirectories = new Dictionary(); + + public override string Name { get { return "Folder Links"; } } + public override string Description { get { return "Adds additional folders you can search"; } } + public override string IcoPath { get { return @"Images\folder.png"; } } + + protected override void InitInternal(PluginInitContext context) { + this.context = context; + } + + public System.Windows.Controls.Control CreateSettingPanel() { + //return new WebSearchesSetting(); + return new FolderLinksSettings(); + } + + protected override List QueryInternal(Query query) { + var Saved_Folders = UserSettingStorage.Instance.FolderLinks.Select(x => x.Path).ToList(); + + //TODO: Consider always clearing the cache + List results = new List(); + if (string.IsNullOrEmpty(query.RawQuery)) { + // clear the cache + if (parentDirectories.Count > 0) + parentDirectories.Clear(); + + return results; + } + + var input = query.RawQuery.ToLower(); + var Input_Name = input.Split(new string[] { @"\" }, StringSplitOptions.None).First().ToLower(); + var Current_Path = Saved_Folders.FirstOrDefault(x => + x.Split(new string[] { @"\" }, StringSplitOptions.None).Last().ToLower() == Input_Name); + if (Current_Path == null) return results; + + Current_Path += query.RawQuery.ToLower().Remove(0, Input_Name.Length); + + if (Directory.Exists(Current_Path)) { + // show all child directory + if (input.EndsWith("\\") || input.EndsWith("/")) { + var dirInfo = new DirectoryInfo(Current_Path); + var dirs = dirInfo.GetDirectories(); + + var parentDirKey = input.TrimEnd('\\', '/'); + if (!parentDirectories.ContainsKey(parentDirKey)) + parentDirectories.Add(parentDirKey, dirs); + + foreach (var dir in dirs) { + if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + continue; + + var dirPath = dir.FullName; + Result result = new Result { + Title = dir.Name, + IcoPath = "Images/folder.png", + Action = (c) => { + context.ChangeQuery(dirPath); + return false; + } + }; + results.Add(result); + } + + if (results.Count == 0) { + Result result = new Result { + Title = "Open this directory", + SubTitle = "No files in this directory", + IcoPath = "Images/folder.png", + Action = (c) => { + Process.Start(Current_Path); + return true; + } + }; + results.Add(result); + } + } + else { + Result result = new Result { + Title = "Open this directory", + SubTitle = string.Format("path: {0}", Current_Path), + Score = 50, + IcoPath = "Images/folder.png", + Action = (c) => { + Process.Start(Current_Path); + return true; + } + }; + results.Add(result); + } + + } + + // change to search in current directory + var parentDir = Path.GetDirectoryName(input); + if (!string.IsNullOrEmpty(parentDir) && results.Count == 0) { + parentDir = parentDir.TrimEnd('\\', '/'); + if (parentDirectories.ContainsKey(parentDir)) { + + var dirs = parentDirectories[parentDir]; + var queryFileName = Path.GetFileName(Current_Path).ToLower(); + var fuzzy = Wox.Infrastructure.FuzzyMatcher.Create(queryFileName); + foreach (var dir in dirs) { + if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) + continue; + + var matchResult = fuzzy.Evaluate(dir.Name); + if (!matchResult.Success) + continue; + + var dirPath = dir.FullName; + Result result = new Result { + Title = dir.Name, + IcoPath = "Images/folder.png", + Score = matchResult.Score, + Action = (c) => { + context.ChangeQuery(dirPath); + return false; + } + }; + results.Add(result); + } + } + } + + + return results; + } + + + } +} diff --git a/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksSettings.xaml b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksSettings.xaml new file mode 100644 index 0000000000..8817bf3a64 --- /dev/null +++ b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinksSettings.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wox.Plugin.SystemPlugins/Folder Links/FolderLinks_Edit.xaml.cs b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinks_Edit.xaml.cs new file mode 100644 index 0000000000..869f8825a7 --- /dev/null +++ b/Wox.Plugin.SystemPlugins/Folder Links/FolderLinks_Edit.xaml.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Wox.Plugin.SystemPlugins.Folder_Links { + /// + /// Interaction logic for FolderLinks_Editxaml.xaml + /// + public partial class FolderLinks_Editxaml : Window { + public FolderLinks_Editxaml() { + InitializeComponent(); + } + } +} diff --git a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj index 1f945e09c9..191d22d2f5 100644 --- a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj +++ b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj @@ -55,6 +55,10 @@ + + + FolderLinksSettings.xaml + ProgramSetting.xaml @@ -99,6 +103,10 @@ + + Designer + MSBuild:Compile + Designer MSBuild:Compile