diff --git a/Wox.Plugin.SystemPlugins/UrlPlugin.cs b/Wox.Plugin.SystemPlugins/UrlPlugin.cs new file mode 100644 index 000000000..70ac428df --- /dev/null +++ b/Wox.Plugin.SystemPlugins/UrlPlugin.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Wox.Plugin.SystemPlugins +{ + public class UrlPlugin : BaseSystemPlugin + { + protected override List QueryInternal(Query query) + { + var raw = query.RawQuery; + Uri uri; + if (Uri.TryCreate(raw, UriKind.Absolute, out uri)) + { + return new List + { + new Result + { + Title = raw, + SubTitle = "Open the typed URL...", + IcoPath = "Images/url1.png", + Score = 8, + Action = _ => + { + Process.Start(raw); + return true; + } + } + }; + } + return new List(0); + } + + public override string Name { get { return "URL handler"; } } + public override string Description { get { return "Open the typed URL..."; } } + public override string IcoPath { get { return "Images/url2.png"; } } + + protected override void InitInternal(PluginInitContext context) + { + } + } +} \ No newline at end of file diff --git a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj index 89b0103ed..44c51eae6 100644 --- a/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj +++ b/Wox.Plugin.SystemPlugins/Wox.Plugin.SystemPlugins.csproj @@ -73,6 +73,7 @@ + WebSearchesSetting.xaml diff --git a/Wox/Converters/ConvertorBase.cs b/Wox/Converters/ConvertorBase.cs new file mode 100644 index 000000000..d07965b0b --- /dev/null +++ b/Wox/Converters/ConvertorBase.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Markup; + +namespace Wox.Converters +{ + public abstract class ConvertorBase : MarkupExtension, IValueConverter where T : class, new() + { + private static T converter; + + /// + /// Must be implemented in inheritor. + /// + public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture); + + /// + /// Override if needed. + /// + public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return converter ?? (converter = new T()); + } + } +} \ No newline at end of file diff --git a/Wox/ImagePathConverter.cs b/Wox/Converters/ImagePathConverter.cs similarity index 67% rename from Wox/ImagePathConverter.cs rename to Wox/Converters/ImagePathConverter.cs index 395dda6dc..dbaa0a308 100644 --- a/Wox/ImagePathConverter.cs +++ b/Wox/Converters/ImagePathConverter.cs @@ -3,23 +3,37 @@ using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -namespace Wox +namespace Wox.Converters { public class ImagePathConverter : IMultiValueConverter { - private static Dictionary imageCache = new Dictionary(); - private static List imageExts = new List() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" }; - private static List selfExts = new List() { - ".exe", ".lnk", - ".ani", ".cur", - ".sln", ".appref-ms" + private static readonly Dictionary imageCache = new Dictionary(); + + private static readonly List imageExts = new List + { + ".png", + ".jpg", + ".jpeg", + ".gif", + ".bmp", + ".tiff", + ".ico" + }; + + private static readonly List selfExts = new List + { + ".exe", + ".lnk", + ".ani", + ".cur", + ".sln", + ".appref-ms" }; private static ImageSource GetIcon(string fileName) @@ -29,7 +43,8 @@ namespace Wox if (icon != null) { - return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); + return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, + new Int32Rect(0, 0, icon.Width, icon.Height), BitmapSizeOptions.FromEmptyOptions()); } return null; @@ -37,13 +52,13 @@ namespace Wox public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { - object img = null; + object img; if (values[0] == null) return null; string path = values[0].ToString(); if (path.StartsWith("data:", StringComparison.OrdinalIgnoreCase)) { - return new System.Windows.Media.Imaging.BitmapImage(new Uri(path)); + return new BitmapImage(new Uri(path)); } string pluginDirectory = values[1].ToString(); @@ -74,7 +89,7 @@ namespace Wox { img = GetIcon(resolvedPath); } - else if (!string.IsNullOrEmpty(resolvedPath) && imageExts.Contains(ext) && File.Exists(resolvedPath)) + else if (!string.IsNullOrEmpty(resolvedPath) && imageExts.Contains(ext) && File.Exists(resolvedPath)) { img = new BitmapImage(new Uri(resolvedPath)); } @@ -98,7 +113,7 @@ namespace Wox } // http://blogs.msdn.com/b/oldnewthing/archive/2011/01/27/10120844.aspx - public static System.Drawing.Icon GetFileIcon(string name) + public static Icon GetFileIcon(string name) { SHFILEINFO shfi = new SHFILEINFO(); uint flags = SHGFI_SYSICONINDEX; @@ -106,13 +121,13 @@ namespace Wox IntPtr himl = SHGetFileInfo(name, FILE_ATTRIBUTE_NORMAL, ref shfi, - (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi), + (uint) Marshal.SizeOf(shfi), flags); if (himl != IntPtr.Zero) { IntPtr hIcon = ImageList_GetIcon(himl, shfi.iIcon, ILD_NORMAL); - System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(hIcon).Clone(); + var icon = (Icon) Icon.FromHandle(hIcon).Clone(); DestroyIcon(hIcon); return icon; } @@ -124,12 +139,12 @@ namespace Wox private static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, uint flags); private const int MAX_PATH = 256; + [StructLayout(LayoutKind.Sequential)] private struct SHITEMID { public ushort cb; - [MarshalAs(UnmanagedType.LPArray)] - public byte[] abID; + [MarshalAs(UnmanagedType.LPArray)] public byte[] abID; } [StructLayout(LayoutKind.Sequential)] @@ -144,8 +159,7 @@ namespace Wox public IntPtr hwndOwner; public IntPtr pidlRoot; public IntPtr pszDisplayName; - [MarshalAs(UnmanagedType.LPTStr)] - public string lpszTitle; + [MarshalAs(UnmanagedType.LPTStr)] public string lpszTitle; public uint ulFlags; public IntPtr lpfn; public int lParam; @@ -174,30 +188,28 @@ namespace Wox public IntPtr hIcon; public int iIcon; public uint dwAttributes; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] - public string szDisplayName; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)] - public string szTypeName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)] public string szDisplayName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NAMESIZE)] public string szTypeName; }; - private const uint SHGFI_ICON = 0x000000100; // get icon - private const uint SHGFI_DISPLAYNAME = 0x000000200; // get display name - private const uint SHGFI_TYPENAME = 0x000000400; // get type name - private const uint SHGFI_ATTRIBUTES = 0x000000800; // get attributes - private const uint SHGFI_ICONLOCATION = 0x000001000; // get icon location - private const uint SHGFI_EXETYPE = 0x000002000; // return exe type - private const uint SHGFI_SYSICONINDEX = 0x000004000; // get system icon index - private const uint SHGFI_LINKOVERLAY = 0x000008000; // put a link overlay on icon - private const uint SHGFI_SELECTED = 0x000010000; // show icon in selected state - private const uint SHGFI_ATTR_SPECIFIED = 0x000020000; // get only specified attributes - private const uint SHGFI_LARGEICON = 0x000000000; // get large icon - private const uint SHGFI_SMALLICON = 0x000000001; // get small icon - private const uint SHGFI_OPENICON = 0x000000002; // get open icon - private const uint SHGFI_SHELLICONSIZE = 0x000000004; // get shell size icon - private const uint SHGFI_PIDL = 0x000000008; // pszPath is a pidl - private const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute - private const uint SHGFI_ADDOVERLAYS = 0x000000020; // apply the appropriate overlays - private const uint SHGFI_OVERLAYINDEX = 0x000000040; // Get the index of the overlay + private const uint SHGFI_ICON = 0x000000100; // get icon + private const uint SHGFI_DISPLAYNAME = 0x000000200; // get display name + private const uint SHGFI_TYPENAME = 0x000000400; // get type name + private const uint SHGFI_ATTRIBUTES = 0x000000800; // get attributes + private const uint SHGFI_ICONLOCATION = 0x000001000; // get icon location + private const uint SHGFI_EXETYPE = 0x000002000; // return exe type + private const uint SHGFI_SYSICONINDEX = 0x000004000; // get system icon index + private const uint SHGFI_LINKOVERLAY = 0x000008000; // put a link overlay on icon + private const uint SHGFI_SELECTED = 0x000010000; // show icon in selected state + private const uint SHGFI_ATTR_SPECIFIED = 0x000020000; // get only specified attributes + private const uint SHGFI_LARGEICON = 0x000000000; // get large icon + private const uint SHGFI_SMALLICON = 0x000000001; // get small icon + private const uint SHGFI_OPENICON = 0x000000002; // get open icon + private const uint SHGFI_SHELLICONSIZE = 0x000000004; // get shell size icon + private const uint SHGFI_PIDL = 0x000000008; // pszPath is a pidl + private const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute + private const uint SHGFI_ADDOVERLAYS = 0x000000020; // apply the appropriate overlays + private const uint SHGFI_OVERLAYINDEX = 0x000000040; // Get the index of the overlay private const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010; private const uint FILE_ATTRIBUTE_NORMAL = 0x00000080; diff --git a/Wox/OpacityModeConverter.cs b/Wox/Converters/OpacityModeConverter.cs similarity index 68% rename from Wox/OpacityModeConverter.cs rename to Wox/Converters/OpacityModeConverter.cs index 4e1300cd7..356bb5be7 100644 --- a/Wox/OpacityModeConverter.cs +++ b/Wox/Converters/OpacityModeConverter.cs @@ -1,19 +1,14 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Data; -using System.Windows.Markup; +using System.Globalization; using Wox.Infrastructure.Storage.UserSettings; -namespace Wox +namespace Wox.Converters { - public class OpacityModeConverter : MarkupExtension, IValueConverter + public class OpacityModeConverter : ConvertorBase { - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is OpacityMode)) return value.ToString(); - var mode = (OpacityMode) value; switch (mode) { @@ -37,16 +32,9 @@ namespace Wox return value.ToString(); } - public object ConvertBack( - object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) - { - throw new NotSupportedException(); - } - - public override object ProvideValue(IServiceProvider serviceProvider) { return this; } } -} +} \ No newline at end of file diff --git a/Wox/Converters/StringEmptyConverter.cs b/Wox/Converters/StringEmptyConverter.cs new file mode 100644 index 000000000..be88a4a6b --- /dev/null +++ b/Wox/Converters/StringEmptyConverter.cs @@ -0,0 +1,18 @@ +using System; +using System.Globalization; + +namespace Wox.Converters +{ + public class StringEmptyConverter : ConvertorBase + { + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return string.IsNullOrEmpty((string)value) ? parameter : value; + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return this; + } + } +} \ No newline at end of file diff --git a/Wox/StringNullOrEmptyToVisibilityConverter.cs b/Wox/Converters/StringNullOrEmptyToVisibilityConverter.cs similarity index 50% rename from Wox/StringNullOrEmptyToVisibilityConverter.cs rename to Wox/Converters/StringNullOrEmptyToVisibilityConverter.cs index 8ed4b71c8..d6d01f071 100644 --- a/Wox/StringNullOrEmptyToVisibilityConverter.cs +++ b/Wox/Converters/StringNullOrEmptyToVisibilityConverter.cs @@ -1,26 +1,24 @@ using System; using System.Globalization; using System.Windows; -using System.Windows.Data; -using System.Windows.Markup; -namespace Wox +namespace Wox.Converters { - public class StringNullOrEmptyToVisibilityConverter : MarkupExtension, IValueConverter + public class StringNullOrEmptyToVisibilityConverter : ConvertorBase { - public override object ProvideValue(IServiceProvider serviceProvider) - { - return this; - } - - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return string.IsNullOrEmpty(value as string) ? Visibility.Collapsed : Visibility.Visible; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + return this; + } } } \ No newline at end of file diff --git a/Wox/Images/url1.png b/Wox/Images/url1.png new file mode 100644 index 000000000..3b86b637d Binary files /dev/null and b/Wox/Images/url1.png differ diff --git a/Wox/Images/url2.png b/Wox/Images/url2.png new file mode 100644 index 000000000..44883fd1c Binary files /dev/null and b/Wox/Images/url2.png differ diff --git a/Wox/ResultPanel.xaml b/Wox/ResultPanel.xaml index 0ee443378..641765bc7 100644 --- a/Wox/ResultPanel.xaml +++ b/Wox/ResultPanel.xaml @@ -3,11 +3,10 @@ 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:wox="clr-namespace:Wox" - mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100" - > + xmlns:converters="clr-namespace:Wox.Converters" + mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100"> - + @@ -42,7 +41,7 @@ - + diff --git a/Wox/ResultPanel.xaml.cs b/Wox/ResultPanel.xaml.cs index 151606930..e071a3331 100644 --- a/Wox/ResultPanel.xaml.cs +++ b/Wox/ResultPanel.xaml.cs @@ -1,16 +1,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Windows; using System.Windows.Controls; -using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; -using System.Windows.Media.Animation; -using Wox.Helper; -using Wox.Infrastructure; using Wox.Plugin; -using MessageBox = System.Windows.MessageBox; using UserControl = System.Windows.Controls.UserControl; namespace Wox diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index e228a6a68..e58ea5bc9 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -5,13 +5,14 @@ xmlns:UserSettings="clr-namespace:Wox.Infrastructure.Storage.UserSettings;assembly=Wox.Infrastructure" x:Class="Wox.SettingWindow" xmlns:woxPlugin="clr-namespace:Wox.Plugin;assembly=Wox.Plugin" xmlns:system="clr-namespace:Wox.Plugin.SystemPlugins;assembly=Wox.Plugin.SystemPlugins" + xmlns:converters="clr-namespace:Wox.Converters" Icon="Images\app.png" Title="Wox Setting" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Height="600" Width="800"> - + @@ -71,7 +72,7 @@ - + @@ -98,7 +99,7 @@ - + @@ -122,7 +123,7 @@ - + @@ -215,7 +216,7 @@ DWM - + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 698ea8c9f..4e8a2d2aa 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -9,6 +9,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using IWshRuntimeLibrary; using Microsoft.VisualBasic.ApplicationServices; +using Wox.Converters; using Wox.Infrastructure; using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage.UserSettings; @@ -462,7 +463,7 @@ namespace Wox () => pluginIcon.Source = (ImageSource) - new Wox.ImagePathConverter().Convert( + new ImagePathConverter().Convert( new object[] {pair.Metadata.IcoPath, pair.Metadata.PluginDirecotry}, null, null, null)); } @@ -479,7 +480,7 @@ namespace Wox () => pluginIcon.Source = (ImageSource) - new Wox.ImagePathConverter().Convert( + new ImagePathConverter().Convert( new object[] { sys.IcoPath, sys.PluginDirectory }, null, null, null)); } diff --git a/Wox/StringEmptyConverter.cs b/Wox/StringEmptyConverter.cs deleted file mode 100644 index b9b148ef3..000000000 --- a/Wox/StringEmptyConverter.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Windows.Data; -using System.Windows.Markup; - -namespace Wox -{ - public class StringEmptyConverter : MarkupExtension, IValueConverter - { - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) - { - return string.IsNullOrEmpty((string)value) ? parameter : value; - } - - public object ConvertBack( - object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) - { - throw new NotSupportedException(); - } - - - public override object ProvideValue(IServiceProvider serviceProvider) - { - return this; - } - } -} diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index dd4c4e29d..e1663d5b1 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -109,6 +109,7 @@ + @@ -120,7 +121,7 @@ - + CustomPluginHotkeySetting.xaml @@ -133,7 +134,7 @@ HotkeyControl.xaml - + Msg.xaml @@ -149,8 +150,8 @@ SettingWindow.xaml - - + + Designer MSBuild:Compile