Merge pull request #84 from antigravity/dev

Dev
This commit is contained in:
Yeechan Lu 2014-05-24 03:34:35 -05:00
commit f3088d1c49
15 changed files with 177 additions and 121 deletions

View file

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace Wox.Plugin.SystemPlugins
{
public class UrlPlugin : BaseSystemPlugin
{
protected override List<Result> QueryInternal(Query query)
{
var raw = query.RawQuery;
Uri uri;
if (Uri.TryCreate(raw, UriKind.Absolute, out uri))
{
return new List<Result>
{
new Result
{
Title = raw,
SubTitle = "Open the typed URL...",
IcoPath = "Images/url1.png",
Score = 8,
Action = _ =>
{
Process.Start(raw);
return true;
}
}
};
}
return new List<Result>(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)
{
}
}
}

View file

@ -73,6 +73,7 @@
<Compile Include="Calculator.cs" />
<Compile Include="Program\ProgramSources\FileSystemProgramSource.cs" />
<Compile Include="Program\ProgramSources\UserStartMenuProgramSource.cs" />
<Compile Include="UrlPlugin.cs" />
<Compile Include="WebSearch\WebSearchesSetting.xaml.cs">
<DependentUpon>WebSearchesSetting.xaml</DependentUpon>
</Compile>

View file

@ -0,0 +1,30 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox.Converters
{
public abstract class ConvertorBase<T> : MarkupExtension, IValueConverter where T : class, new()
{
private static T converter;
/// <summary>
/// Must be implemented in inheritor.
/// </summary>
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
/// <summary>
/// Override if needed.
/// </summary>
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());
}
}
}

View file

@ -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<string, object> imageCache = new Dictionary<string, object>();
private static List<string> imageExts = new List<string>() { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" };
private static List<string> selfExts = new List<string>() {
".exe", ".lnk",
".ani", ".cur",
".sln", ".appref-ms"
private static readonly Dictionary<string, object> imageCache = new Dictionary<string, object>();
private static readonly List<string> imageExts = new List<string>
{
".png",
".jpg",
".jpeg",
".gif",
".bmp",
".tiff",
".ico"
};
private static readonly List<string> selfExts = new List<string>
{
".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;

View file

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

View file

@ -0,0 +1,18 @@
using System;
using System.Globalization;
namespace Wox.Converters
{
public class StringEmptyConverter : ConvertorBase<StringEmptyConverter>
{
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;
}
}
}

View file

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

BIN
Wox/Images/url1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
Wox/Images/url2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -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">
<UserControl.Resources>
<wox:ImagePathConverter x:Key="ImagePathConverter"/>
<converters:ImagePathConverter x:Key="ImagePathConverter"/>
</UserControl.Resources>
<!-- set max height of listbox to allow 6 results showed at once -->
@ -42,7 +41,7 @@
<RowDefinition Height="Auto" x:Name="SubTitleRowDefinition"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Style="{DynamicResource ItemTitleStyle}" VerticalAlignment="Center" ToolTip="{Binding Title}" x:Name="tbTitle" Text="{Binding Title}"></TextBlock>
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding SubTitle}" Visibility="{Binding SubTitle, Converter={wox:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding SubTitle}"></TextBlock>
<TextBlock Style="{DynamicResource ItemSubTitleStyle}" ToolTip="{Binding SubTitle}" Visibility="{Binding SubTitle, Converter={converters:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding SubTitle}"></TextBlock>
</Grid>
</Grid>
<DataTemplate.Triggers>

View file

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

View file

@ -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">
<Window.Resources>
<wox:ImagePathConverter x:Key="ImagePathConverter"/>
<converters:ImagePathConverter x:Key="ImagePathConverter"/>
<ListBoxItem HorizontalContentAlignment="Stretch"
IsEnabled="False"
IsHitTestVisible="False" x:Key="FeatureBoxSeperator">
@ -71,7 +72,7 @@
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" ToolTip="{Binding Name}" x:Name="tbTitle" Text="{Binding Name}"></TextBlock>
<TextBlock ToolTip="{Binding Description}" Visibility="{Binding Description, Converter={wox:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding Description}" Opacity="0.5"></TextBlock>
<TextBlock ToolTip="{Binding Description}" Visibility="{Binding Description, Converter={converters:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding Description}" Opacity="0.5"></TextBlock>
</Grid>
<CheckBox Content="Enabled" />
</Grid>
@ -98,7 +99,7 @@
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" ToolTip="{Binding Metadata.Name}" x:Name="tbTitle" Text="{Binding Metadata.Name}"></TextBlock>
<TextBlock ToolTip="{Binding Metadata.Description}" Visibility="{Binding Metadata.Description, Converter={wox:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding Metadata.Description}" Opacity="0.5"></TextBlock>
<TextBlock ToolTip="{Binding Metadata.Description}" Visibility="{Binding Metadata.Description, Converter={converters:StringNullOrEmptyToVisibilityConverter}}" Grid.Row="1" x:Name="tbSubTitle" Text="{Binding Metadata.Description}" Opacity="0.5"></TextBlock>
</Grid>
</Grid>
</DataTemplate>
@ -122,7 +123,7 @@
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" x:Name="pluginTitle" ToolTip="{Binding Source=pluginTitle, Path=Text}" FontSize="24"></TextBlock>
<TextBlock Grid.Row="1" x:Name="pluginSubTitle" Opacity="0.5" ToolTip="{Binding Source=pluginSubTitle, Path=Text}" Visibility="{Binding Source=pluginSubTitle, Path=Text, Converter={wox:StringNullOrEmptyToVisibilityConverter}}" ></TextBlock>
<TextBlock Grid.Row="1" x:Name="pluginSubTitle" Opacity="0.5" ToolTip="{Binding Source=pluginSubTitle, Path=Text}" Visibility="{Binding Source=pluginSubTitle, Path=Text, Converter={converters:StringNullOrEmptyToVisibilityConverter}}" ></TextBlock>
</Grid>
</Grid>
</ContentControl>
@ -215,7 +216,7 @@
<UserSettings:OpacityMode>DWM</UserSettings:OpacityMode>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={wox:OpacityModeConverter}}" />
<TextBlock Text="{Binding Converter={converters:OpacityModeConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

View file

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

View file

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

View file

@ -109,6 +109,7 @@
<Compile Include="Commands\CommandFactory.cs" />
<Compile Include="Commands\PluginCommand.cs" />
<Compile Include="Commands\SystemCommand.cs" />
<Compile Include="Converters\ConvertorBase.cs" />
<Compile Include="Helper\DataWebRequestFactory.cs" />
<Compile Include="Helper\ErrorReporting\ErrorReporting.cs" />
<Compile Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml.cs">
@ -120,7 +121,7 @@
<Compile Include="Helper\WallpaperPathRetrieval.cs" />
<Compile Include="Helper\WindowIntelopHelper.cs" />
<Compile Include="Helper\WindowOpener.cs" />
<Compile Include="OpacityModeConverter.cs" />
<Compile Include="Converters\OpacityModeConverter.cs" />
<Compile Include="CustomPluginHotkeySetting.xaml.cs">
<DependentUpon>CustomPluginHotkeySetting.xaml</DependentUpon>
</Compile>
@ -133,7 +134,7 @@
<Compile Include="HotkeyControl.xaml.cs">
<DependentUpon>HotkeyControl.xaml</DependentUpon>
</Compile>
<Compile Include="ImagePathConverter.cs" />
<Compile Include="Converters\ImagePathConverter.cs" />
<Compile Include="Msg.xaml.cs">
<DependentUpon>Msg.xaml</DependentUpon>
</Compile>
@ -149,8 +150,8 @@
<Compile Include="SettingWindow.xaml.cs">
<DependentUpon>SettingWindow.xaml</DependentUpon>
</Compile>
<Compile Include="StringEmptyConverter.cs" />
<Compile Include="StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="Converters\StringEmptyConverter.cs" />
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
<Page Include="Helper\ErrorReporting\WPFErrorReportingDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>