start issue#11

This commit is contained in:
qianlifeng
2014-01-07 23:27:05 +08:00
parent a5f3359d32
commit 70339423d0
17 changed files with 139 additions and 33 deletions

View File

@@ -5,7 +5,9 @@ using System.Linq;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace WinAlfred.Plugin.Fanyi namespace WinAlfred.Plugin.Fanyi

View File

@@ -70,7 +70,7 @@ namespace WinAlfred.Plugin.System
Title = "Exit", Title = "Exit",
SubTitle = "Close this app", SubTitle = "Close this app",
Score = 110, Score = 110,
IcoPath = "Images\\exit.png", IcoPath = "Images\\ico.png",
Action = () => context.CloseApp() Action = () => context.CloseApp()
}); });
} }

View File

@@ -10,7 +10,7 @@
<Setter Property="FontWeight" Value="Medium"/> <Setter Property="FontWeight" Value="Medium"/>
<Setter Property="AllowDrop" Value="true"/> <Setter Property="AllowDrop" Value="true"/>
<Setter Property="Background" Value="Transparent"/> <Setter Property="Background" Value="Transparent"/>
<Setter Property="Margin" Value="10"/> <Setter Property="Margin" Value="10 10 10 5"/>
<Setter Property="Height" Value="36"/> <Setter Property="Height" Value="36"/>
<Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
@@ -53,6 +53,7 @@
</EventTrigger> </EventTrigger>
</Style.Triggers> </Style.Triggers>
</Style> </Style>
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>

View File

@@ -19,11 +19,8 @@ namespace WinAlfred.Commands
} }
protected void UpdateResultView(List<Result> results) protected void UpdateResultView(List<Result> results)
{
if (results.Count > 0)
{ {
window.OnUpdateResultView(results); window.OnUpdateResultView(results);
} }
} }
} }
}

View File

@@ -31,7 +31,7 @@ namespace WinAlfred.Commands
result.PluginDirectory = pair1.Metadata.PluginDirecotry; result.PluginDirectory = pair1.Metadata.PluginDirecotry;
result.OriginQuery = query; result.OriginQuery = query;
} }
UpdateResultView(results); if(results.Count > 0) UpdateResultView(results);
}); });
} }
} }

View File

@@ -13,7 +13,14 @@ namespace WinAlfred
private static readonly object syncRoot = new object(); private static readonly object syncRoot = new object();
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation, public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
Action action, TimeSpan delay, Action<string> action, TimeSpan delay,
DispatcherPriority priority = DispatcherPriority.Normal)
{
return DelayInvoke(dispatcher, namedInvocation, action, delay, string.Empty, priority);
}
public static string DelayInvoke(this Dispatcher dispatcher, string namedInvocation,
Action<string> action, TimeSpan delay, string arg,
DispatcherPriority priority = DispatcherPriority.Normal) DispatcherPriority priority = DispatcherPriority.Normal)
{ {
lock (syncRoot) lock (syncRoot)
@@ -29,7 +36,7 @@ namespace WinAlfred
var timer = new DispatcherTimer(delay, priority, (s, e) => var timer = new DispatcherTimer(delay, priority, (s, e) =>
{ {
RemoveTimer(namedInvocation); RemoveTimer(namedInvocation);
action(); action(arg);
}, dispatcher); }, dispatcher);
timer.Start(); timer.Start();
timers.Add(namedInvocation, timer); timers.Add(namedInvocation, timer);

View File

@@ -0,0 +1,38 @@
using WinAlfred.Plugin;
namespace WinAlfred.Helper
{
public class SelectedRecords
{
private int hasAddedCount = 0;
public void LoadSelectedRecords()
{
}
public void AddSelect(Result result)
{
hasAddedCount++;
if (hasAddedCount == 10)
{
SaveSelectedRecords();
hasAddedCount = 0;
}
}
public int GetSelectedCount(Result result)
{
return 0;
}
public void SaveSelectedRecords()
{
}
}
}

BIN
WinAlfred/Images/enter.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 367 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -19,7 +19,7 @@
<RowDefinition></RowDefinition> <RowDefinition></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox Style="{DynamicResource defaultQueryBoxStyle}" Grid.Row="0" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" /> <TextBox Style="{DynamicResource defaultQueryBoxStyle}" Grid.Row="0" x:Name="tbQuery" PreviewKeyDown="TbQuery_OnPreviewKeyDown" TextChanged="TextBoxBase_OnTextChanged" />
<Line Stroke="Blue" x:Name="progressBar" X2="100" Grid.Row="1" Height="2" StrokeThickness="1"></Line> <Line Stroke="Blue" x:Name="progressBar" Y1="0" Y2="0" X2="100" Grid.Row="1" Height="2" StrokeThickness="1"></Line>
<winAlfred:ResultPanel x:Name="resultCtrl" Grid.Row="2" Margin="10 0 10 0" /> <winAlfred:ResultPanel x:Name="resultCtrl" Grid.Row="2" Margin="10 0 10 0" />
</Grid> </Grid>
</Window> </Window>

View File

@@ -26,6 +26,8 @@ namespace WinAlfred
private NotifyIcon notifyIcon; private NotifyIcon notifyIcon;
private Command cmdDispatcher; private Command cmdDispatcher;
Storyboard progressBarStoryboard = new Storyboard(); Storyboard progressBarStoryboard = new Storyboard();
private bool queryHasReturn = false;
SelectedRecords selectedRecords = new SelectedRecords();
public MainWindow() public MainWindow()
{ {
@@ -42,8 +44,8 @@ namespace WinAlfred
{ {
DoubleAnimation da = new DoubleAnimation(progressBar.X2, Width + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); DoubleAnimation da = new DoubleAnimation(progressBar.X2, Width + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
DoubleAnimation da1 = new DoubleAnimation(progressBar.X1, Width, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); DoubleAnimation da1 = new DoubleAnimation(progressBar.X1, Width, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X1)")); Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X2)")); Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
progressBarStoryboard.Children.Add(da); progressBarStoryboard.Children.Add(da);
progressBarStoryboard.Children.Add(da1); progressBarStoryboard.Children.Add(da1);
progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
@@ -81,19 +83,44 @@ namespace WinAlfred
} }
} }
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
// Begin dragging the window
this.DragMove();
}
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
{ {
resultCtrl.Dirty = true; resultCtrl.Dirty = true;
Dispatcher.DelayInvoke("UpdateSearch", Dispatcher.DelayInvoke("UpdateSearch",
() => o =>
{ {
resultCtrl.Clear(); Dispatcher.DelayInvoke("ClearResults", i =>
{
// first try to use clear method inside resultCtrl, 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();
}, TimeSpan.FromMilliseconds(30), null);
var q = new Query(tbQuery.Text); var q = new Query(tbQuery.Text);
cmdDispatcher.DispatchCommand(q); cmdDispatcher.DispatchCommand(q);
}, TimeSpan.FromMilliseconds(300)); queryHasReturn = false;
if (Plugins.HitThirdpartyKeyword(q))
{
Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{
if (!queryHasReturn && originQuery == tbQuery.Text)
{
StartProgress();
}
}, TimeSpan.FromSeconds(1), tbQuery.Text);
} }
}, TimeSpan.FromMilliseconds(300));
}
private void StartProgress() private void StartProgress()
{ {
@@ -124,7 +151,7 @@ namespace WinAlfred
} }
} }
public void SetAutoStart(bool IsAtuoRun) private void SetAutoStart(bool IsAtuoRun)
{ {
string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk";
if (IsAtuoRun) if (IsAtuoRun)
@@ -148,10 +175,10 @@ namespace WinAlfred
Plugins.Init(this); Plugins.Init(this);
cmdDispatcher = new Command(this); cmdDispatcher = new Command(this);
InitialTray(); InitialTray();
selectedRecords.LoadSelectedRecords();
SetAutoStart(true); SetAutoStart(true);
//var engine = new Jurassic.ScriptEngine(); //var engine = new Jurassic.ScriptEngine();
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString()); //MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
StartProgress();
} }
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
@@ -174,7 +201,15 @@ namespace WinAlfred
break; break;
case Key.Enter: case Key.Enter:
if (resultCtrl.AcceptSelect()) HideWinAlfred(); Result result = resultCtrl.AcceptSelect();
if (result != null)
{
selectedRecords.AddSelect(result);
if (!result.DontHideWinAlfredAfterAction)
{
HideWinAlfred();
}
}
e.Handled = true; e.Handled = true;
break; break;
} }
@@ -182,12 +217,21 @@ namespace WinAlfred
public void OnUpdateResultView(List<Result> list) public void OnUpdateResultView(List<Result> list)
{ {
queryHasReturn = true;
progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list.Count > 0)
{
list.ForEach(o =>
{
o.Score += selectedRecords.GetSelectedCount(o);
});
resultCtrl.Dispatcher.Invoke(new Action(() => resultCtrl.Dispatcher.Invoke(new Action(() =>
{ {
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList(); List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
resultCtrl.AddResults(l); resultCtrl.AddResults(l);
})); }));
} }
}
#region Public API #region Public API

View File

@@ -35,5 +35,12 @@ namespace WinAlfred.PluginLoader
{ {
get { return plugins; } get { return plugins; }
} }
public static bool HitThirdpartyKeyword(Query query)
{
if (string.IsNullOrEmpty(query.ActionName)) return false;
return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName);
}
} }
} }

View File

@@ -22,8 +22,8 @@
<TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock> <TextBlock Grid.Row="1" Foreground="#8e94a4" x:Name="tbSubTitle">sdfdsf</TextBlock>
</Grid> </Grid>
<DockPanel Grid.Column="2" Visibility="Hidden"> <DockPanel Grid.Column="2" Visibility="Hidden">
<Image Source="Images\ctrl.png" VerticalAlignment="Center"/> <Image x:Name="img" Source="Images\ctrl.png" VerticalAlignment="Center"/>
<TextBlock x:Name="tbIndex" FontSize="16" Foreground="#5c1f87" Margin="0 5 0 0" Text="1" VerticalAlignment="Center" HorizontalAlignment="Left" /> <TextBlock x:Name="tbIndex" Visibility="Hidden" FontSize="16" Foreground="#5c1f87" Margin="0 5 0 0" Text="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
</DockPanel> </DockPanel>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -27,6 +27,15 @@ namespace WinAlfred
selected = value; selected = value;
BrushConverter bc = new BrushConverter(); BrushConverter bc = new BrushConverter();
Background = selected ? (Brush)(bc.ConvertFrom("#d1d1d1")) : (Brush)(bc.ConvertFrom("#ebebeb")); Background = selected ? (Brush)(bc.ConvertFrom("#d1d1d1")) : (Brush)(bc.ConvertFrom("#ebebeb"));
if (selected)
{
img.Visibility = Visibility.Visible;
img.Source = new BitmapImage(new Uri(Directory.GetCurrentDirectory()+"\\Images\\enter.png"));
}
else
{
img.Visibility = Visibility.Hidden;
}
} }
} }

View File

@@ -192,10 +192,10 @@ namespace WinAlfred
Select(0); Select(0);
} }
public bool AcceptSelect() public Result AcceptSelect()
{ {
int index = GetCurrentSelectedResultIndex(); int index = GetCurrentSelectedResultIndex();
if (index < 0) return false; if (index < 0) return null;
var resultItemControl = pnlContainer.Children[index] as ResultItem; var resultItemControl = pnlContainer.Children[index] as ResultItem;
if (resultItemControl != null) if (resultItemControl != null)
@@ -205,10 +205,10 @@ namespace WinAlfred
resultItemControl.Result.Action(); resultItemControl.Result.Action();
} }
return !resultItemControl.Result.DontHideWinAlfredAfterAction; return resultItemControl.Result;
} }
return true; return null;
} }
public ResultPanel() public ResultPanel()

View File

@@ -112,6 +112,7 @@
<Compile Include="ResultItem.xaml.cs"> <Compile Include="ResultItem.xaml.cs">
<DependentUpon>ResultItem.xaml</DependentUpon> <DependentUpon>ResultItem.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Helper\SelectedRecords.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>