This commit is contained in:
qianlifeng
2013-12-25 00:21:54 +08:00
parent 87225e64fa
commit 94cd2c0599
8 changed files with 65 additions and 26 deletions

View File

@@ -38,6 +38,7 @@ extern "C" __declspec(dllexport) char* ExecPython(char* directory, char* file, c
// Call a method of the class with two parameters // Call a method of the class with two parameters
pValue = PyObject_CallMethod(pInstance,"query", "(s)",query); pValue = PyObject_CallMethod(pInstance,"query", "(s)",query);
char * str_ret = PyString_AsString(pValue); char * str_ret = PyString_AsString(pValue);
// Finish the Python Interpreter // Finish the Python Interpreter
Py_Finalize(); Py_Finalize();

View File

@@ -75,6 +75,7 @@
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>C:\Python27\include;$(IncludePath)</IncludePath> <IncludePath>C:\Python27\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Python27\libs;$(LibraryPath)</LibraryPath> <LibraryPath>C:\Python27\libs;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)WinAlfred\bin\Debug\</OutDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental> <LinkIncremental>false</LinkIncremental>

View File

@@ -17,4 +17,4 @@
<appender-ref ref="LogFileAppender"/> <appender-ref ref="LogFileAppender"/>
</root> </root>
</log4net> </log4net>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

View File

@@ -4,6 +4,33 @@
StartupUri="MainWindow.xaml"> StartupUri="MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<Style x:Key="defaultQueryBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="FontWeight" Value="Medium"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Margin" Value="10"/>
<Setter Property="Height" Value="36"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" Background="Transparent" BorderBrush="Transparent" CornerRadius="3" BorderThickness="0">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="Silver"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="windowShow" TargetType="Window"> <Style x:Key="windowShow" TargetType="Window">
<Setter Property="Border.RenderTransform"> <Setter Property="Border.RenderTransform">
<Setter.Value> <Setter.Value>

View File

@@ -14,7 +14,7 @@
Icon="Images\ico.png" Icon="Images\ico.png"
> >
<DockPanel> <DockPanel>
<TextBox DockPanel.Dock="Top" Margin="10" VerticalContentAlignment="Center" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" Height="26.965" /> <TextBox Style="{DynamicResource defaultQueryBoxStyle}" DockPanel.Dock="Top" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" />
<winAlfred:ResultPanel x:Name="resultCtrl" Margin="10 0 10 0" /> <winAlfred:ResultPanel x:Name="resultCtrl" Margin="10 0 10 0" />
</DockPanel> </DockPanel>
</Window> </Window>

View File

@@ -2,10 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports; using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading;
using WinAlfred.Helper; using WinAlfred.Helper;
using WinAlfred.Plugin; using WinAlfred.Plugin;
using WinAlfred.PluginLoader; using WinAlfred.PluginLoader;
@@ -26,6 +28,7 @@ namespace WinAlfred
hook.KeyPressed += OnHotKey; hook.KeyPressed += OnHotKey;
hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space);
resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent;
ThreadPool.SetMaxThreads(10, 5);
} }
private void InitialTray() private void InitialTray()
@@ -63,11 +66,14 @@ namespace WinAlfred
} }
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
{
string query = tbQuery.Text;
ThreadPool.QueueUserWorkItem(state =>
{ {
results.Clear(); results.Clear();
foreach (PluginPair pair in plugins) foreach (PluginPair pair in plugins)
{ {
var q = new Query(tbQuery.Text); var q = new Query(query);
if (pair.Metadata.ActionKeyword == q.ActionName) if (pair.Metadata.ActionKeyword == q.ActionName)
{ {
try try
@@ -87,8 +93,12 @@ namespace WinAlfred
} }
} }
} }
resultCtrl.Dispatcher.Invoke(new Action(() =>
{
resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList()); resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList());
resultCtrl.SelectFirst(); resultCtrl.SelectFirst();
}));
});
} }
private void HideWinAlfred() private void HideWinAlfred()
@@ -99,9 +109,9 @@ namespace WinAlfred
private void ShowWinAlfred() private void ShowWinAlfred()
{ {
tbQuery.SelectAll(); tbQuery.SelectAll();
Focus();
tbQuery.Focus();
Show(); Show();
Focus();
FocusManager.SetFocusedElement(this, tbQuery);
} }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)

View File

@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WinAlfred</RootNamespace> <RootNamespace>WinAlfred</RootNamespace>
<AssemblyName>WinAlfred</AssemblyName> <AssemblyName>WinAlfred</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" /> <package id="log4net" version="2.0.3" targetFramework="net35" requireReinstallation="True" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" /> <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net35" requireReinstallation="True" />
</packages> </packages>