Merge branch 'dev'

This commit is contained in:
jhdxr 2019-02-23 04:06:45 +08:00
commit 4bb460528f
23 changed files with 269 additions and 38 deletions

View File

@ -9,6 +9,10 @@
<system:String x:Key="wox_plugin_everything_open_containing_folder">Open parent folder</system:String>
<system:String x:Key="wox_plugin_everything_open_with_editor">Open with {0}</system:String>
<system:String x:Key="wox_plugin_everything_editor_path">Editor Path</system:String>
<system:String x:Key="wox_plugin_everything_copy_path">Copy path</system:String>
<system:String x:Key="wox_plugin_everything_copy">Copy</system:String>
<system:String x:Key="wox_plugin_everything_delete">Delete</system:String>
<system:String x:Key="wox_plugin_everything_canot_delete">Can't delete {0}</system:String>
<system:String x:Key="wox_plugin_everything_plugin_name">Everything</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">Search on-disk files using Everything</system:String>

View File

@ -9,6 +9,10 @@
<system:String x:Key="wox_plugin_everything_open_containing_folder">打开所属文件夹</system:String>
<system:String x:Key="wox_plugin_everything_open_with_editor">使用{0}打开</system:String>
<system:String x:Key="wox_plugin_everything_editor_path">编辑器路径</system:String>
<system:String x:Key="wox_plugin_everything_copy_path">拷贝路径</system:String>
<system:String x:Key="wox_plugin_everything_copy">拷贝</system:String>
<system:String x:Key="wox_plugin_everything_delete">删除</system:String>
<system:String x:Key="wox_plugin_everything_canot_delete">无法删除 {0}</system:String>
<system:String x:Key="wox_plugin_everything_plugin_name">Everything</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">利用 Everything 搜索磁盘文件</system:String>

View File

@ -211,6 +211,53 @@ namespace Wox.Plugin.Everything
}
}
var icoPath = (record.Type == ResultType.File) ? "Images\\file.png" : "Images\\folder.png";
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_copy_path"),
Action = (context) =>
{
Clipboard.SetText(record.FullPath);
return true;
},
IcoPath = icoPath
});
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_copy"),
Action = (context) =>
{
Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { record.FullPath });
return true;
},
IcoPath = icoPath
});
if (record.Type == ResultType.File || record.Type == ResultType.Folder)
contextMenus.Add(new Result
{
Title = _context.API.GetTranslation("wox_plugin_everything_delete"),
Action = (context) =>
{
try
{
if (record.Type == ResultType.File)
System.IO.File.Delete(record.FullPath);
else
System.IO.Directory.Delete(record.FullPath);
}
catch
{
_context.API.ShowMsg(string.Format(_context.API.GetTranslation("wox_plugin_everything_canot_delete"), record.FullPath), string.Empty, string.Empty);
return false;
}
return true;
},
IcoPath = icoPath
});
return contextMenus;
}

View File

@ -8,4 +8,8 @@
<system:String x:Key="wox_plugin_url_plugin_name">URL</system:String>
<system:String x:Key="wox_plugin_url_plugin_description">Open the typed URL from Wox</system:String>
<system:String x:Key="wox_plugin_url_plugin_set_tip">Please set your browser path:</system:String>
<system:String x:Key="wox_plugin_url_plugin_choose">Choose</system:String>
<system:String x:Key="wox_plugin_url_plugin_apply">Apply</system:String>
<system:String x:Key="wox_plugin_url_plugin_filter">Application(*.exe)|*.exe|All files|*.*</system:String>
</ResourceDictionary>

View File

@ -8,4 +8,8 @@
<system:String x:Key="wox_plugin_url_plugin_name">URL</system:String>
<system:String x:Key="wox_plugin_url_plugin_description">从Wox打开链接</system:String>
<system:String x:Key="wox_plugin_url_plugin_set_tip">请设置你的浏览器路径:</system:String>
<system:String x:Key="wox_plugin_url_plugin_choose">选择</system:String>
<system:String x:Key="wox_plugin_url_plugin_apply">应用</system:String>
<system:String x:Key="wox_plugin_url_plugin_filter">程序文件(*.exe)|*.exe|所有文件|*.*</system:String>
</ResourceDictionary>

View File

@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Url
{
public class Main : IPlugin, IPluginI18n
public class Main : ISettingProvider,IPlugin, IPluginI18n, ISavable
{
//based on https://gist.github.com/dperini/729294
private const string urlPattern = "^" +
@ -42,6 +44,19 @@ namespace Wox.Plugin.Url
"$";
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
private PluginInitContext context;
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
public Main()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
}
public void Save()
{
_storage.Save();
}
public List<Result> Query(Query query)
{
@ -64,7 +79,15 @@ namespace Wox.Plugin.Url
}
try
{
Process.Start(raw);
if (_settings.BrowserPath.Length == 0)
{
Process.Start(raw);
}
else
{
Process.Start(_settings.BrowserPath,raw);
}
return true;
}
catch(Exception ex)
@ -79,6 +102,12 @@ namespace Wox.Plugin.Url
return new List<Result>(0);
}
public Control CreateSettingPanel()
{
return new SettingsControl(context.API,_settings);
}
public bool IsURL(string raw)
{
raw = raw.ToLower();

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Wox.Plugin.Url
{
public class Settings
{
public string BrowserPath { get; set; }
}
}

View File

@ -0,0 +1,25 @@
<UserControl x:Class="Wox.Plugin.Url.SettingsControl"
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"
xmlns:local="clr-namespace:Wox.Plugin.Url"
mc:Ignorable="d" Height="300" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="0*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="0*"/>
<ColumnDefinition Width="0*"/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<Label HorizontalAlignment="Left" Margin="99,22,0,0" VerticalAlignment="Top" Height="43" Width="318" FontSize="20" Content="{DynamicResource wox_plugin_url_plugin_set_tip}"/>
<TextBox x:Name="browserPathBox" HorizontalAlignment="Left" Height="34" Margin="35,90,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="311"/>
<Button x:Name="setButton" HorizontalAlignment="Left" Margin="356,247,0,0" VerticalAlignment="Top" Width="110" Height="33" FontSize="20" Click="OnApplyBTClick" Content="{DynamicResource wox_plugin_url_plugin_apply}"/>
<Button x:Name="viewButton" HorizontalAlignment="Left" Margin="369,90,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="OnChooseClick" FontSize="20" Content="{DynamicResource wox_plugin_url_plugin_choose}"/>
</Grid>
</UserControl>

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 Microsoft.Win32;
namespace Wox.Plugin.Url
{
/// <summary>
/// SettingsControl.xaml 的交互逻辑
/// </summary>
public partial class SettingsControl : UserControl
{
private Settings _settings;
private IPublicAPI _woxAPI;
public SettingsControl(IPublicAPI woxAPI,Settings settings)
{
InitializeComponent();
_settings = settings;
_woxAPI = woxAPI;
browserPathBox.Text = _settings.BrowserPath;
}
private void OnApplyBTClick(object sender, RoutedEventArgs e)
{
_settings.BrowserPath = browserPathBox.Text;
}
private void OnChooseClick(object sender, RoutedEventArgs e)
{
var fileBrowserDialog = new OpenFileDialog();
fileBrowserDialog.Filter = _woxAPI.GetTranslation("wox_plugin_url_plugin_filter"); ;
fileBrowserDialog.CheckFileExists = true;
fileBrowserDialog.CheckPathExists = true;
if (fileBrowserDialog.ShowDialog() == true)
{
browserPathBox.Text = fileBrowserDialog.FileName;
}
}
}
}

View File

@ -37,9 +37,12 @@
<HintPath>..\..\packages\JetBrains.Annotations.10.3.0\lib\net\JetBrains.Annotations.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\SolutionAssemblyInfo.cs">
@ -47,6 +50,10 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Main.cs" />
<Compile Include="Settings.cs" />
<Compile Include="SettingsControl.xaml.cs">
<DependentUpon>SettingsControl.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@ -104,6 +111,12 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Page Include="SettingsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using Wox.Infrastructure;
using Wox.Infrastructure.Logger;
@ -22,10 +23,12 @@ namespace Wox.Core.Resource
private const string Folder = "Themes";
private const string Extension = ".xaml";
private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder);
private string UserDirectoryPath => Path.Combine(Constant.DataDirectory, Folder);
public Theme()
{
_themeDirectories.Add(DirectoryPath);
_themeDirectories.Add(UserDirectoryPath);
MakesureThemeDirectoriesExist();
var dicts = Application.Current.Resources.MergedDictionaries;
@ -60,38 +63,21 @@ namespace Wox.Core.Resource
}
}
public void ChangeTheme(string theme)
public bool ChangeTheme(string theme)
{
const string dark = "Dark";
bool valid;
const string defaultTheme = "Dark";
string path = GetThemePath(theme);
if (string.IsNullOrEmpty(path))
try
{
Log.Error($"|Theme.ChangeTheme|Theme path can't be found <{path}>, use default dark theme");
path = GetThemePath(dark);
if (string.IsNullOrEmpty(path))
{
valid = false;
Log.Error($"|Theme.ChangeTheme|Default theme path can't be found <{path}>");
}
else
{
valid = true;
theme = dark;
}
}
else
{
valid = true;
}
throw new DirectoryNotFoundException("Theme path can't be found <{path}>");
if (valid)
{
Settings.Theme = theme;
var dicts = Application.Current.Resources.MergedDictionaries;
if (_oldTheme != theme)
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
if (_oldTheme != theme || theme == defaultTheme)
{
dicts.Remove(_oldResource);
var newResource = GetResourceDictionary();
@ -100,6 +86,27 @@ namespace Wox.Core.Resource
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
}
}
catch (DirectoryNotFoundException e)
{
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> path can't be found");
if (theme != defaultTheme)
{
MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme));
ChangeTheme(defaultTheme);
}
return false;
}
catch (XamlParseException e)
{
Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse");
if (theme != defaultTheme)
{
MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme));
ChangeTheme(defaultTheme);
}
return false;
}
return true;
}
public ResourceDictionary GetResourceDictionary()

View File

@ -99,8 +99,8 @@ namespace Wox.Infrastructure.Image
private int width;
private int height;
public int Width { set => width = value; }
public int Height { set => height = value; }
public int Width { set { width = value; } }
public int Height { set { height = value; } }
};

View File

@ -52,6 +52,8 @@
<system:String x:Key="resultItemFont">Result Item Font</system:String>
<system:String x:Key="windowMode">Window Mode</system:String>
<system:String x:Key="opacity">Opacity</system:String>
<system:String x:Key="theme_load_failure_path_not_exists">Theme {0} not exists, fallback to default theme</system:String>
<system:String x:Key="theme_load_failure_parse_error">Fail to load theme {0}, fallback to default theme</system:String>
<!--Setting Hotkey-->
<system:String x:Key="hotkey">Hotkey</system:String>

View File

@ -52,6 +52,8 @@
<system:String x:Key="resultItemFont">结果项字体</system:String>
<system:String x:Key="windowMode">窗口模式</system:String>
<system:String x:Key="opacity">透明度</system:String>
<system:String x:Key="theme_load_failure_path_not_exists">无法找到主题 {0} ,切换为默认主题</system:String>
<system:String x:Key="theme_load_failure_parse_error">无法加载主题 {0} ,切换为默认主题</system:String>
<!--设置,热键-->
<system:String x:Key="hotkey">热键</system:String>

View File

@ -16,7 +16,8 @@
KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard"
SelectionChanged="OnSelectionChanged"
IsSynchronizedWithCurrentItem="True">
IsSynchronizedWithCurrentItem="True"
PreviewMouseDown="ListBox_PreviewMouseDown">
<!--IsSynchronizedWithCurrentItem: http://stackoverflow.com/a/7833798/2833083-->
<ListBox.ItemTemplate>
<DataTemplate>
@ -65,6 +66,7 @@
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseEnter" Handler="OnMouseEnter" />
<EventSetter Event="MouseMove" Handler="OnMouseMove" />
<Setter Property="Height" Value="50" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />

View File

@ -1,4 +1,5 @@
using System.Runtime.Remoting.Contexts;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -7,6 +8,8 @@ namespace Wox
[Synchronization]
public partial class ResultListBox
{
private Point _lastpos;
private ListBoxItem curItem = null;
public ResultListBox()
{
InitializeComponent();
@ -22,7 +25,26 @@ namespace Wox
private void OnMouseEnter(object sender, MouseEventArgs e)
{
((ListBoxItem) sender).IsSelected = true;
curItem = (ListBoxItem)sender;
var p = e.GetPosition((IInputElement)sender);
_lastpos = p;
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
var p = e.GetPosition((IInputElement)sender);
if (_lastpos != p)
{
((ListBoxItem) sender).IsSelected = true;
}
}
private void ListBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (curItem != null)
{
curItem.IsSelected = true;
}
}
}
}

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml" />
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<system:Boolean x:Key="ThemeBlurEnabled">True</system:Boolean>

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml" />
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<system:Boolean x:Key="ThemeBlurEnabled">True</system:Boolean>

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml" />
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml" />
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#EDEDED" />

View File

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml"></ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">

View File

@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml"></ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#ffffff"/>

View File

@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base.xaml"></ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Themes/Base.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="#1f1d1f"/>