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.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Newtonsoft.Json;
namespace WinAlfred.Plugin.Fanyi

View File

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

View File

@@ -10,7 +10,7 @@
<Setter Property="FontWeight" Value="Medium"/>
<Setter Property="AllowDrop" Value="true"/>
<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="VerticalContentAlignment" Value="Center"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
@@ -53,6 +53,7 @@
</EventTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -20,10 +20,7 @@ namespace WinAlfred.Commands
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.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();
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)
{
lock (syncRoot)
@@ -29,7 +36,7 @@ namespace WinAlfred
var timer = new DispatcherTimer(delay, priority, (s, e) =>
{
RemoveTimer(namedInvocation);
action();
action(arg);
}, dispatcher);
timer.Start();
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>
</Grid.RowDefinitions>
<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" />
</Grid>
</Window>

View File

@@ -26,6 +26,8 @@ namespace WinAlfred
private NotifyIcon notifyIcon;
private Command cmdDispatcher;
Storyboard progressBarStoryboard = new Storyboard();
private bool queryHasReturn = false;
SelectedRecords selectedRecords = new SelectedRecords();
public MainWindow()
{
@@ -40,10 +42,10 @@ namespace WinAlfred
private void InitProgressbarAnimation()
{
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)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X1)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X2)"));
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)));
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
progressBarStoryboard.Children.Add(da);
progressBarStoryboard.Children.Add(da1);
progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
@@ -81,20 +83,45 @@ 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)
{
resultCtrl.Dirty = true;
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);
cmdDispatcher.DispatchCommand(q);
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()
{
progressBar.Visibility = Visibility.Visible;
@@ -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";
if (IsAtuoRun)
@@ -148,10 +175,10 @@ namespace WinAlfred
Plugins.Init(this);
cmdDispatcher = new Command(this);
InitialTray();
selectedRecords.LoadSelectedRecords();
SetAutoStart(true);
//var engine = new Jurassic.ScriptEngine();
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
StartProgress();
}
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
@@ -174,7 +201,15 @@ namespace WinAlfred
break;
case Key.Enter:
if (resultCtrl.AcceptSelect()) HideWinAlfred();
Result result = resultCtrl.AcceptSelect();
if (result != null)
{
selectedRecords.AddSelect(result);
if (!result.DontHideWinAlfredAfterAction)
{
HideWinAlfred();
}
}
e.Handled = true;
break;
}
@@ -182,11 +217,20 @@ namespace WinAlfred
public void OnUpdateResultView(List<Result> list)
{
resultCtrl.Dispatcher.Invoke(new Action(() =>
queryHasReturn = true;
progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list.Count > 0)
{
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
resultCtrl.AddResults(l);
}));
list.ForEach(o =>
{
o.Score += selectedRecords.GetSelectedCount(o);
});
resultCtrl.Dispatcher.Invoke(new Action(() =>
{
List<Result> l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).OrderByDescending(o => o.Score).ToList();
resultCtrl.AddResults(l);
}));
}
}
#region Public API

View File

@@ -24,9 +24,9 @@ namespace WinAlfred.PluginLoader
Plugins = plugins,
ChangeQuery = s => window.ChangeQuery(s),
CloseApp = window.CloseApp,
HideApp = window.HideApp,
HideApp = window.HideApp,
ShowApp = window.ShowApp,
ShowMsg = (title,subTitle,iconPath) => window.ShowMsg(title,subTitle,iconPath)
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath)
}));
}
}
@@ -35,5 +35,12 @@ namespace WinAlfred.PluginLoader
{
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>
</Grid>
<DockPanel Grid.Column="2" Visibility="Hidden">
<Image 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" />
<Image x:Name="img" Source="Images\ctrl.png" VerticalAlignment="Center"/>
<TextBlock x:Name="tbIndex" Visibility="Hidden" FontSize="16" Foreground="#5c1f87" Margin="0 5 0 0" Text="1" VerticalAlignment="Center" HorizontalAlignment="Left" />
</DockPanel>
</Grid>
</UserControl>

View File

@@ -27,6 +27,15 @@ namespace WinAlfred
selected = value;
BrushConverter bc = new BrushConverter();
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);
}
public bool AcceptSelect()
public Result AcceptSelect()
{
int index = GetCurrentSelectedResultIndex();
if (index < 0) return false;
if (index < 0) return null;
var resultItemControl = pnlContainer.Children[index] as ResultItem;
if (resultItemControl != null)
@@ -205,10 +205,10 @@ namespace WinAlfred
resultItemControl.Result.Action();
}
return !resultItemControl.Result.DontHideWinAlfredAfterAction;
return resultItemControl.Result;
}
return true;
return null;
}
public ResultPanel()

View File

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