Added Plugin for searching additional directories

This commit is contained in:
Aaron Campf 2014-03-30 16:03:07 -07:00
parent dc5eeb8476
commit 6b9f96697b
12 changed files with 329 additions and 2 deletions

View File

@ -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.

View File

@ -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; }
}
}

View File

@ -47,6 +47,9 @@ namespace Wox.Infrastructure.Storage.UserSettings
[JsonProperty]
public List<ProgramSource> ProgramSources { get; set; }
[JsonProperty]
public List<FolderLink> FolderLinks { get; set; } //Aaron
[JsonProperty]
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }

View File

@ -49,6 +49,7 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Storage\UserSettings\FolderLink.cs" />
<Compile Include="Unidecoder.Characters.cs" />
<Compile Include="ChineseToPinYin.cs" />
<Compile Include="HttpRequest.cs" />

View File

@ -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))
{

View File

@ -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; }
}
}

View File

@ -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<string> driverNames = null;
private static Dictionary<string, DirectoryInfo[]> parentDirectories = new Dictionary<string, DirectoryInfo[]>();
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<Result> QueryInternal(Query query) {
var Saved_Folders = UserSettingStorage.Instance.FolderLinks.Select(x => x.Path).ToList();
//TODO: Consider always clearing the cache
List<Result> results = new List<Result>();
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;
}
}
}

View File

@ -0,0 +1,32 @@
<UserControl x:Class="Wox.Plugin.SystemPlugins.Folder_Links.FolderLinksSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<ListView x:Name="lbxFolders" Grid.Row="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Folder Path" Width="180">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button x:Name="btnDelete" Click="btnDelete_Click" Width="100" Margin="10" Content="Delete"/>
<Button x:Name="btnEdit" Click="btnEdit_Click" Width="100" Margin="10" Content="Edit"/>
<Button x:Name="btnAdd" Click="btnAdd_Click" Width="100" Margin="10" Content="Add"/>
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,64 @@
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;
using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.SystemPlugins.Folder_Links {
/// <summary>
/// Interaction logic for FolderLinksSettings.xaml
/// </summary>
public partial class FolderLinksSettings : UserControl {
public FolderLinksSettings() {
InitializeComponent();
lbxFolders.ItemsSource = Wox.Infrastructure.Storage.UserSettings.UserSettingStorage.Instance.FolderLinks;
}
private void btnDelete_Click(object sender, RoutedEventArgs e) {
}
private void btnEdit_Click(object sender, RoutedEventArgs e) {
var SelectedFolder = lbxFolders.SelectedItem as FolderLink;
var Folder = new System.Windows.Forms.FolderBrowserDialog();
Folder.SelectedPath = SelectedFolder.Path;
if (Folder.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
var Result = UserSettingStorage.Instance.FolderLinks.First(x => x.Path == SelectedFolder.Path);
Result.Path = Folder.SelectedPath;
UserSettingStorage.Instance.Save();
}
lbxFolders.Items.Refresh();
}
private void btnAdd_Click(object sender, RoutedEventArgs e) {
var Folder = new System.Windows.Forms.FolderBrowserDialog();
if (Folder.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
var New_Folder = new Wox.Infrastructure.Storage.UserSettings.FolderLink() {
Path = Folder.SelectedPath
};
if (UserSettingStorage.Instance.FolderLinks == null) {
UserSettingStorage.Instance.FolderLinks = new List<FolderLink>();
}
UserSettingStorage.Instance.FolderLinks.Add(New_Folder);
UserSettingStorage.Instance.Save();
}
lbxFolders.Items.Refresh();
}
}
}

View File

@ -0,0 +1,32 @@
<Window x:Class="Wox.Plugin.SystemPlugins.Folder_Links.FolderLinks_Editxaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Title="Folder"
Height="350"
Width="674.766"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
>
<Grid RenderTransformOrigin="0.504,0.245">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="0,129,10,13" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right">Title:</TextBlock>
<TextBox x:Name="tbTitle" Margin="10,127.5,0,11.5" Grid.Row="0" Width="400" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="5" Grid.Column="1">
<Button x:Name="btnCancel" Click="BtnCancel_OnClick" Margin="10,27,10,109" Width="80" Height="25">Cancel</Button>
<Button x:Name="btnAdd" Margin="10,27,10,109" Width="80" Height="25" Click="btnAdd_OnClick">
<TextBlock x:Name="lblAdd">Add</TextBlock>
</Button>
</StackPanel>
</Grid>
</Window>

View File

@ -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 {
/// <summary>
/// Interaction logic for FolderLinks_Editxaml.xaml
/// </summary>
public partial class FolderLinks_Editxaml : Window {
public FolderLinks_Editxaml() {
InitializeComponent();
}
}
}

View File

@ -55,6 +55,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CMD\CMDStorage.cs" />
<Compile Include="Folder Links\FolderLinksPlugin.cs" />
<Compile Include="Folder Links\FolderLinksSettings.xaml.cs">
<DependentUpon>FolderLinksSettings.xaml</DependentUpon>
</Compile>
<Compile Include="Program\ProgramSetting.xaml.cs">
<DependentUpon>ProgramSetting.xaml</DependentUpon>
</Compile>
@ -99,6 +103,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="Folder Links\FolderLinksSettings.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Program\ProgramSetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>