Merge branch 'V1.1.0' into dev

This commit is contained in:
qianlifeng
2014-12-12 12:21:23 +08:00
42 changed files with 1603 additions and 121 deletions

View File

@@ -10,21 +10,11 @@ namespace Wox.Commands
{
internal static class CommandFactory
{
private static PluginCommand pluginCmd;
private static SystemCommand systemCmd;
private static PluginCommand pluginCmd = new PluginCommand();
private static SystemCommand systemCmd = new SystemCommand();
public static void DispatchCommand(Query query)
{
//lazy init command instance.
if (pluginCmd == null)
{
pluginCmd = new PluginCommand();
}
if (systemCmd == null)
{
systemCmd = new SystemCommand();
}
if (Plugins.HitThirdpartyKeyword(query))
{
pluginCmd.Dispatch(query);

View File

@@ -12,19 +12,21 @@ namespace Wox.Commands
{
public class SystemCommand : BaseCommand
{
private IEnumerable<PluginPair> allSytemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System);
public override void Dispatch(Query query)
{
var allSytemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System);
var queryPlugins = allSytemPlugins;
if (UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == query.ActionName && o.Enabled))
{
//websearch mode
allSytemPlugins = new List<PluginPair>()
queryPlugins = new List<PluginPair>()
{
allSytemPlugins.First(o => ((ISystemPlugin)o.Plugin).ID == "565B73353DBF4806919830B9202EE3BF")
};
}
foreach (PluginPair pair in allSytemPlugins)
foreach (PluginPair pair in queryPlugins)
{
PluginPair pair1 = pair;
ThreadPool.QueueUserWorkItem(state =>

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using Wox.Plugin;
namespace Wox.Converters
{
@@ -21,4 +23,23 @@ namespace Wox.Converters
return this;
}
}
public class ContextMenuEmptyToWidthConverter : ConvertorBase<ContextMenuEmptyToWidthConverter>
{
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
List<Result> results = value as List<Result>;
return results == null || results.Count == 0 ? 0 : 17;
}
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/menu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

BIN
Wox/Images/open.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 B

View File

@@ -22,7 +22,8 @@
<StackPanel Orientation="Vertical">
<TextBox Style="{DynamicResource QueryBoxStyle}" PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True" Grid.Row="0" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" />
<Line Style="{DynamicResource PendingLineStyle}" x:Name="progressBar" Y1="0" Y2="0" X2="100" Grid.Row="1" Height="2" StrokeThickness="1"></Line>
<wox:ResultPanel x:Name="resultCtrl" />
<wox:ResultPanel x:Name="pnlResult" />
<wox:ResultPanel x:Name="pnlContextMenu" Visibility="Collapsed" />
</StackPanel>
</Border>
</Window>

View File

@@ -140,6 +140,13 @@ namespace Wox
results.ForEach(o =>
{
o.PluginDirectory = plugin.PluginDirectory;
if (o.ContextMenu != null)
{
o.ContextMenu.ForEach(t =>
{
t.PluginDirectory = plugin.PluginDirectory;
});
}
o.OriginQuery = query;
});
OnUpdateResultView(results);
@@ -147,7 +154,6 @@ namespace Wox
#endregion
public MainWindow()
{
InitializeComponent();
@@ -159,7 +165,9 @@ namespace Wox
progressBar.ToolTip = toolTip;
InitialTray();
resultCtrl.OnMouseClickItem += AcceptSelect;
pnlResult.LeftMouseClickEvent += SelectResult;
pnlContextMenu.LeftMouseClickEvent += SelectResult;
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
ThreadPool.SetMaxThreads(30, 10);
try
@@ -176,7 +184,15 @@ namespace Wox
globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
this.Closing += MainWindow_Closing;
Closing += MainWindow_Closing;
//since MainWIndow implement IPublicAPI, so we need to finish ctor MainWindow object before
//PublicAPI invoke in plugin init methods. E.g FolderPlugin
ThreadPool.QueueUserWorkItem(o => Plugins.Init());
}
void pnlResult_RightMouseClickEvent(Result result)
{
ShowContextMenu(result);
}
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@@ -204,8 +220,6 @@ namespace Wox
Top = UserSettingStorage.Instance.WindowTop;
}
Plugins.Init();
InitProgressbarAnimation();
//only works for win7+
@@ -299,21 +313,22 @@ namespace Wox
lastQuery = tbQuery.Text;
toolTip.IsOpen = false;
resultCtrl.Dirty = true;
pnlResult.Dirty = true;
Dispatcher.DelayInvoke("UpdateSearch",
o =>
{
Dispatcher.DelayInvoke("ClearResults", i =>
{
// first try to use clear method inside resultCtrl, which is more closer to the add new results
// first try to use clear method inside pnlResult, which is more closer to the add new results
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we
// must clear the result. otherwise, it will be confused why the query changed, but the results
// didn't.
if (resultCtrl.Dirty) resultCtrl.Clear();
if (pnlResult.Dirty) pnlResult.Clear();
}, TimeSpan.FromMilliseconds(100), null);
queryHasReturn = false;
var q = new Query(lastQuery);
CommandFactory.DispatchCommand(q);
BackToResultMode();
if (Plugins.HitThirdpartyKeyword(q))
{
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
@@ -327,6 +342,12 @@ namespace Wox
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150));
}
private void BackToResultMode()
{
pnlResult.Visibility = Visibility.Visible;
pnlContextMenu.Visibility = Visibility.Collapsed;
}
private bool ShouldNotDelayQuery
{
get
@@ -426,7 +447,7 @@ namespace Wox
ShowWox(false);
if (!tbQuery.Text.StartsWith(">"))
{
resultCtrl.Clear();
pnlResult.Clear();
ChangeQuery(">");
}
tbQuery.CaretIndex = tbQuery.Text.Length;
@@ -436,7 +457,7 @@ namespace Wox
private void updateCmdMode()
{
var currentSelectedItem = resultCtrl.GetActiveResult();
var currentSelectedItem = pnlResult.GetActiveResult();
if (currentSelectedItem != null)
{
ignoreTextChange = true;
@@ -452,7 +473,14 @@ namespace Wox
switch (key)
{
case Key.Escape:
HideWox();
if (IsInContextMenuMode)
{
BackToResultMode();
}
else
{
HideWox();
}
e.Handled = true;
break;
@@ -479,14 +507,14 @@ namespace Wox
break;
case Key.PageDown:
resultCtrl.SelectNextPage();
pnlResult.SelectNextPage();
if (IsCMDMode) updateCmdMode();
toolTip.IsOpen = false;
e.Handled = true;
break;
case Key.PageUp:
resultCtrl.SelectPrevPage();
pnlResult.SelectPrevPage();
if (IsCMDMode) updateCmdMode();
toolTip.IsOpen = false;
e.Handled = true;
@@ -508,29 +536,68 @@ namespace Wox
break;
case Key.Enter:
AcceptSelect(resultCtrl.GetActiveResult());
Result activeResult = GetActiveResult();
if (globalHotkey.CheckModifiers().ShiftPressed)
{
ShowContextMenu(activeResult);
}
else
{
SelectResult(activeResult);
}
e.Handled = true;
break;
}
}
private bool IsInContextMenuMode
{
get { return pnlContextMenu.Visibility == Visibility.Visible; }
}
private Result GetActiveResult()
{
if (IsInContextMenuMode)
{
return pnlContextMenu.GetActiveResult();
}
else
{
return pnlResult.GetActiveResult();
}
}
private void SelectPrevItem()
{
resultCtrl.SelectPrev();
if (IsCMDMode) updateCmdMode();
if (IsInContextMenuMode)
{
pnlContextMenu.SelectPrev();
}
else
{
pnlResult.SelectPrev();
if (IsCMDMode) updateCmdMode();
}
toolTip.IsOpen = false;
}
private void SelectNextItem()
{
resultCtrl.SelectNext();
if (IsCMDMode) updateCmdMode();
if (IsInContextMenuMode)
{
pnlContextMenu.SelectNext();
}
else
{
pnlResult.SelectNext();
if (IsCMDMode) updateCmdMode();
}
toolTip.IsOpen = false;
}
private void AcceptSelect(Result result)
private void SelectResult(Result result)
{
if (!resultCtrl.Dirty && result != null)
if (result != null)
{
if (result.Action != null)
{
@@ -562,7 +629,20 @@ namespace Wox
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
});
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
Dispatcher.Invoke(new Action(() => resultCtrl.AddResults(l)));
Dispatcher.Invoke(new Action(() =>
pnlResult.AddResults(l))
);
}
}
private void ShowContextMenu(Result result)
{
if (result.ContextMenu != null && result.ContextMenu.Count > 0)
{
pnlContextMenu.Clear();
pnlContextMenu.AddResults(result.ContextMenu);
pnlContextMenu.Visibility = Visibility.Visible;
pnlResult.Visibility = Visibility.Collapsed;
}
}
@@ -604,14 +684,14 @@ namespace Wox
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
}
public bool ShellRun(string cmd)
public bool ShellRun(string cmd, bool runAsAdministrator = false)
{
try
{
if (string.IsNullOrEmpty(cmd))
throw new ArgumentNullException();
Wox.Infrastructure.WindowsShellRun.Start(cmd);
WindowsShellRun.Start(cmd, runAsAdministrator);
return true;
}
catch (Exception ex)

View File

@@ -1,9 +1,12 @@
using System.Reflection;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Wox")]
[assembly: AssemblyDescription("https://github.com/qianlifeng/Wox")]
[assembly: AssemblyConfiguration("")]
@@ -12,10 +15,41 @@ using System.Windows;
[assembly: AssemblyCopyright("The MIT License (MIT)")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请在
//<PropertyGroup> 中的 .csproj 文件中
//设置 <UICulture>CultureYouAreCodingWith</UICulture>。例如,如果您在源文件中
//使用的是美国英语,请将 <UICulture> 设置为 en-US。然后取消
//对以下 NeutralResourceLanguage 特性的注释。更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None,
ResourceDictionaryLocation.SourceAssembly
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(在页面或应用程序资源词典中
// 未找到某个资源的情况下使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(在页面、应用程序或任何主题特定资源词典中
// 未找到某个资源的情况下使用)
)]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -7,7 +7,7 @@
mc:Ignorable="d" d:DesignWidth="100" d:DesignHeight="100">
<!-- set max height of listbox to allow 6 results showed at once -->
<ListBox x:Name="lbResults" MaxHeight="300" PreviewMouseDown="LbResults_OnPreviewMouseDown" Style="{DynamicResource BaseListboxStyle}" SelectionChanged ="lbResults_SelectionChanged" Focusable="False" KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard">
<ListBox x:Name="lbResults" MaxHeight="300" HorizontalContentAlignment="Stretch" PreviewMouseDown="LbResults_OnPreviewMouseDown" Style="{DynamicResource BaseListboxStyle}" SelectionChanged ="lbResults_SelectionChanged" Focusable="False" KeyboardNavigation.DirectionalNavigation="Cycle" SelectionMode="Single" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard">
<ListBox.Resources>
<!--SelectedItem with focus-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="{DynamicResource ItemSelectedBackgroundColor}"/>
@@ -17,13 +17,14 @@
<ListBox.ItemTemplate>
<DataTemplate>
<!-- a result item height is 50 including margin -->
<Grid HorizontalAlignment="Stretch" Height="40" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
<Grid HorizontalAlignment="Stretch" Height="40" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
<Grid.Resources>
<converters:ImagePathConverter x:Key="ImageConverter" />
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32"></ColumnDefinition>
<ColumnDefinition/>
<ColumnDefinition x:Name="contextMenuDefinition" Width="0"/>
</Grid.ColumnDefinitions>
<Image x:Name="imgIco" Width="32" Height="32" HorizontalAlignment="Left" Source="{Binding FullIcoPath,Converter={StaticResource ImageConverter},IsAsync=True}" >
</Image>
@@ -32,14 +33,16 @@
<RowDefinition></RowDefinition>
<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 ItemTitleStyle}" DockPanel.Dock="Left" VerticalAlignment="Center" ToolTip="{Binding Title}" x:Name="tbTitle" Text="{Binding Title}"></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>
<Image Grid.Column="2" VerticalAlignment="Center" Margin="5 0 0 0" Width="12" x:Name="contextMenu" Source="Images/menu.png" ToolTip="Shift + Enter to open context menu"></Image>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
<Setter TargetName="tbTitle" Property="Style" Value="{DynamicResource ItemTitleSelectedStyle}"/>
<Setter TargetName="tbSubTitle" Property="Style" Value="{DynamicResource ItemSubTitleSelectedStyle}"/>
<Setter TargetName="contextMenuDefinition" Property="Width" Value="{Binding ContextMenu, Converter={converters:ContextMenuEmptyToWidthConverter}}"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

View File

@@ -14,11 +14,18 @@ namespace Wox
{
public partial class ResultPanel : UserControl
{
public event Action<Result> OnMouseClickItem;
public event Action<Result> LeftMouseClickEvent;
public event Action<Result> RightMouseClickEvent;
protected virtual void OnOnMouseClickItem(Result result)
protected virtual void OnRightMouseClick(Result result)
{
Action<Result> handler = OnMouseClickItem;
Action<Result> handler = RightMouseClickEvent;
if (handler != null) handler(result);
}
protected virtual void OnLeftMouseClick(Result result)
{
Action<Result> handler = LeftMouseClickEvent;
if (handler != null) handler(result);
}
@@ -133,9 +140,13 @@ namespace Wox
private void LbResults_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
var item = ItemsControl.ContainerFromElement(lbResults, e.OriginalSource as DependencyObject) as ListBoxItem;
if (item != null)
if (item != null && e.ChangedButton == MouseButton.Left)
{
OnOnMouseClickItem(item.DataContext as Result);
OnLeftMouseClick(item.DataContext as Result);
}
if (item != null && e.ChangedButton == MouseButton.Right)
{
OnRightMouseClick(item.DataContext as Result);
}
}

15
Wox/app.manifest Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>