mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Mouse select support & Code refactoring
This commit is contained in:
parent
36018fe570
commit
c7dfaac61a
12 changed files with 106 additions and 89 deletions
|
|
@ -51,7 +51,16 @@ namespace WinAlfred
|
||||||
|
|
||||||
public partial class App : Application
|
public partial class App : Application
|
||||||
{
|
{
|
||||||
private MainWindow window;
|
|
||||||
|
private static MainWindow window;
|
||||||
|
|
||||||
|
public static MainWindow Window
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnStartup(StartupEventArgs e)
|
protected override void OnStartup(StartupEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,11 @@ namespace WinAlfred.Commands
|
||||||
{
|
{
|
||||||
public abstract class BaseCommand
|
public abstract class BaseCommand
|
||||||
{
|
{
|
||||||
private MainWindow window;
|
public abstract void Dispatch(Query query, bool updateView = true);
|
||||||
|
|
||||||
public void Dispatch(Query query)
|
|
||||||
{
|
|
||||||
Dispatch(query, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Dispatch(Query query, bool updateView);
|
|
||||||
|
|
||||||
//TODO:Ugly, we should subscribe events here, instead of just use usercontrol as the parameter
|
|
||||||
protected BaseCommand(MainWindow window)
|
|
||||||
{
|
|
||||||
this.window = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateResultView(List<Result> results)
|
protected void UpdateResultView(List<Result> results)
|
||||||
{
|
{
|
||||||
window.OnUpdateResultView(results);
|
App.Window.OnUpdateResultView(results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using WinAlfred.Helper;
|
|
||||||
using WinAlfred.Plugin;
|
|
||||||
|
|
||||||
namespace WinAlfred.Commands
|
|
||||||
{
|
|
||||||
public class Command
|
|
||||||
{
|
|
||||||
private PluginCommand pluginCmd;
|
|
||||||
private SystemCommand systemCmd;
|
|
||||||
|
|
||||||
public Command(MainWindow window)
|
|
||||||
{
|
|
||||||
pluginCmd = new PluginCommand(window);
|
|
||||||
systemCmd = new SystemCommand(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DispatchCommand(Query query)
|
|
||||||
{
|
|
||||||
systemCmd.Dispatch(query);
|
|
||||||
pluginCmd.Dispatch(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DispatchCommand(Query query,bool updateView)
|
|
||||||
{
|
|
||||||
systemCmd.Dispatch(query,updateView);
|
|
||||||
pluginCmd.Dispatch(query,updateView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
31
WinAlfred/Commands/CommandFactory.cs
Normal file
31
WinAlfred/Commands/CommandFactory.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using WinAlfred.Helper;
|
||||||
|
using WinAlfred.Plugin;
|
||||||
|
|
||||||
|
namespace WinAlfred.Commands
|
||||||
|
{
|
||||||
|
internal static class CommandFactory
|
||||||
|
{
|
||||||
|
private static PluginCommand pluginCmd;
|
||||||
|
private static SystemCommand systemCmd;
|
||||||
|
|
||||||
|
public static void DispatchCommand(Query query, bool updateView = true)
|
||||||
|
{
|
||||||
|
//lazy init command instance.
|
||||||
|
if (pluginCmd == null)
|
||||||
|
{
|
||||||
|
pluginCmd = new PluginCommand();
|
||||||
|
}
|
||||||
|
if (systemCmd == null)
|
||||||
|
{
|
||||||
|
systemCmd = new SystemCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
systemCmd.Dispatch(query,updateView);
|
||||||
|
pluginCmd.Dispatch(query,updateView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,13 +14,7 @@ namespace WinAlfred.Commands
|
||||||
private string currentPythonModulePath = string.Empty;
|
private string currentPythonModulePath = string.Empty;
|
||||||
private IntPtr GIL;
|
private IntPtr GIL;
|
||||||
|
|
||||||
public PluginCommand(MainWindow mainWindow)
|
public override void Dispatch(Query q,bool updateView = true)
|
||||||
: base(mainWindow)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Dispatch(Query q,bool updateView)
|
|
||||||
{
|
{
|
||||||
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName);
|
PluginPair thirdPlugin = Plugins.AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == q.ActionName);
|
||||||
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
|
if (thirdPlugin != null && !string.IsNullOrEmpty(thirdPlugin.Metadata.ActionKeyword))
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,12 @@ namespace WinAlfred.Commands
|
||||||
{
|
{
|
||||||
private List<PluginPair> systemPlugins;
|
private List<PluginPair> systemPlugins;
|
||||||
|
|
||||||
public SystemCommand(MainWindow window)
|
public SystemCommand()
|
||||||
: base(window)
|
|
||||||
{
|
{
|
||||||
systemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System).ToList();
|
systemPlugins = Plugins.AllPlugins.Where(o => o.Metadata.PluginType == PluginType.System).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispatch(Query query,bool updateView)
|
public override void Dispatch(Query query,bool updateView = true)
|
||||||
{
|
{
|
||||||
foreach (PluginPair pair in systemPlugins)
|
foreach (PluginPair pair in systemPlugins)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,22 @@ namespace WinAlfred.Helper
|
||||||
private int hasAddedCount = 0;
|
private int hasAddedCount = 0;
|
||||||
private Dictionary<string, int> dict = new Dictionary<string, int>();
|
private Dictionary<string, int> dict = new Dictionary<string, int>();
|
||||||
private string filePath = Directory.GetCurrentDirectory() + "\\selectedRecords.dat";
|
private string filePath = Directory.GetCurrentDirectory() + "\\selectedRecords.dat";
|
||||||
|
private static readonly SelectedRecords instance = new SelectedRecords();
|
||||||
|
|
||||||
public void LoadSelectedRecords()
|
private SelectedRecords()
|
||||||
|
{
|
||||||
|
LoadSelectedRecords();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SelectedRecords Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadSelectedRecords()
|
||||||
{
|
{
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ using WinAlfred.PluginLoader;
|
||||||
using Application = System.Windows.Application;
|
using Application = System.Windows.Application;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
using UserControl = System.Windows.Controls.UserControl;
|
||||||
|
|
||||||
namespace WinAlfred
|
namespace WinAlfred
|
||||||
{
|
{
|
||||||
|
|
@ -23,10 +24,8 @@ namespace WinAlfred
|
||||||
{
|
{
|
||||||
private KeyboardHook hook = new KeyboardHook();
|
private KeyboardHook hook = new KeyboardHook();
|
||||||
private NotifyIcon notifyIcon;
|
private NotifyIcon notifyIcon;
|
||||||
private Command cmdDispatcher;
|
|
||||||
Storyboard progressBarStoryboard = new Storyboard();
|
Storyboard progressBarStoryboard = new Storyboard();
|
||||||
private bool queryHasReturn = false;
|
private bool queryHasReturn = false;
|
||||||
SelectedRecords selectedRecords = new SelectedRecords();
|
|
||||||
|
|
||||||
private KeyboardListener keyboardListener = new KeyboardListener();
|
private KeyboardListener keyboardListener = new KeyboardListener();
|
||||||
private bool WinRStroked = false;
|
private bool WinRStroked = false;
|
||||||
|
|
@ -68,7 +67,7 @@ namespace WinAlfred
|
||||||
double oldLeft = Left;
|
double oldLeft = Left;
|
||||||
Left = 20000;
|
Left = 20000;
|
||||||
ShowWinAlfred();
|
ShowWinAlfred();
|
||||||
cmdDispatcher.DispatchCommand(new Query("qq"), false);
|
CommandFactory.DispatchCommand(new Query("qq"), false);
|
||||||
HideWinAlfred();
|
HideWinAlfred();
|
||||||
Left = oldLeft;
|
Left = oldLeft;
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +131,7 @@ namespace WinAlfred
|
||||||
if (resultCtrl.Dirty) resultCtrl.Clear();
|
if (resultCtrl.Dirty) resultCtrl.Clear();
|
||||||
}, TimeSpan.FromMilliseconds(30), null);
|
}, TimeSpan.FromMilliseconds(30), null);
|
||||||
var q = new Query(tbQuery.Text);
|
var q = new Query(tbQuery.Text);
|
||||||
cmdDispatcher.DispatchCommand(q);
|
CommandFactory.DispatchCommand(q);
|
||||||
queryHasReturn = false;
|
queryHasReturn = false;
|
||||||
if (Plugins.HitThirdpartyKeyword(q))
|
if (Plugins.HitThirdpartyKeyword(q))
|
||||||
{
|
{
|
||||||
|
|
@ -169,7 +168,7 @@ namespace WinAlfred
|
||||||
Activate();
|
Activate();
|
||||||
Focus();
|
Focus();
|
||||||
tbQuery.Focus();
|
tbQuery.Focus();
|
||||||
if(selectAll) tbQuery.SelectAll();
|
if (selectAll) tbQuery.SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ParseArgs(string[] args)
|
public void ParseArgs(string[] args)
|
||||||
|
|
@ -179,7 +178,7 @@ namespace WinAlfred
|
||||||
switch (args[0])
|
switch (args[0])
|
||||||
{
|
{
|
||||||
case "reloadWorkflows":
|
case "reloadWorkflows":
|
||||||
Plugins.Init(this);
|
Plugins.Init();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "query":
|
case "query":
|
||||||
|
|
@ -218,12 +217,11 @@ namespace WinAlfred
|
||||||
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
|
||||||
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
|
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
|
||||||
|
|
||||||
Plugins.Init(this);
|
Plugins.Init();
|
||||||
cmdDispatcher = new Command(this);
|
|
||||||
InitialTray();
|
InitialTray();
|
||||||
selectedRecords.LoadSelectedRecords();
|
|
||||||
SetAutoStart(true);
|
SetAutoStart(true);
|
||||||
WakeupApp();
|
WakeupApp();
|
||||||
|
|
||||||
//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());
|
||||||
keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
||||||
|
|
@ -279,20 +277,25 @@ namespace WinAlfred
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.Enter:
|
case Key.Enter:
|
||||||
Result result = resultCtrl.AcceptSelect();
|
AcceptSelect();
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
selectedRecords.AddSelect(result);
|
|
||||||
if (!result.DontHideWinAlfredAfterSelect)
|
|
||||||
{
|
|
||||||
HideWinAlfred();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AcceptSelect()
|
||||||
|
{
|
||||||
|
Result result = resultCtrl.AcceptSelect();
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
SelectedRecords.Instance.AddSelect(result);
|
||||||
|
if (!result.DontHideWinAlfredAfterSelect)
|
||||||
|
{
|
||||||
|
HideWinAlfred();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void OnUpdateResultView(List<Result> list)
|
public void OnUpdateResultView(List<Result> list)
|
||||||
{
|
{
|
||||||
queryHasReturn = true;
|
queryHasReturn = true;
|
||||||
|
|
@ -302,7 +305,7 @@ namespace WinAlfred
|
||||||
//todo:this should be opened to users, it's their choise to use it or not in thier workflows
|
//todo:this should be opened to users, it's their choise to use it or not in thier workflows
|
||||||
list.ForEach(o =>
|
list.ForEach(o =>
|
||||||
{
|
{
|
||||||
if (o.AutoAjustScore) o.Score += selectedRecords.GetSelectedCount(o);
|
if (o.AutoAjustScore) o.Score += SelectedRecords.Instance.GetSelectedCount(o);
|
||||||
});
|
});
|
||||||
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
resultCtrl.Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace WinAlfred.PluginLoader
|
||||||
{
|
{
|
||||||
private static List<PluginPair> plugins = new List<PluginPair>();
|
private static List<PluginPair> plugins = new List<PluginPair>();
|
||||||
|
|
||||||
public static void Init(MainWindow window)
|
public static void Init()
|
||||||
{
|
{
|
||||||
plugins.Clear();
|
plugins.Clear();
|
||||||
BasePluginLoader.ParsePluginsConfig();
|
BasePluginLoader.ParsePluginsConfig();
|
||||||
|
|
@ -30,12 +30,12 @@ namespace WinAlfred.PluginLoader
|
||||||
{
|
{
|
||||||
Plugins = plugins,
|
Plugins = plugins,
|
||||||
PluginMetadata = metadata,
|
PluginMetadata = metadata,
|
||||||
ChangeQuery = s => window.ChangeQuery(s),
|
ChangeQuery = s => App.Window.ChangeQuery(s),
|
||||||
CloseApp = window.CloseApp,
|
CloseApp = App.Window.CloseApp,
|
||||||
HideApp = window.HideApp,
|
HideApp = App.Window.HideApp,
|
||||||
ShowApp = () => window.ShowApp(),
|
ShowApp = () => App.Window.ShowApp(),
|
||||||
ShowMsg = (title, subTitle, iconPath) => window.ShowMsg(title, subTitle, iconPath),
|
ShowMsg = (title, subTitle, iconPath) => App.Window.ShowMsg(title, subTitle, iconPath),
|
||||||
OpenSettingDialog = ()=> window.OpenSettingDialog()
|
OpenSettingDialog = () => App.Window.OpenSettingDialog()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
x:Name="resultItemControl"
|
x:Name="resultItemControl"
|
||||||
Style="{DynamicResource ItemStyle}"
|
Style="{DynamicResource ItemStyle}"
|
||||||
Height="50">
|
Height="50">
|
||||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" >
|
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" Cursor="Hand">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="32"></ColumnDefinition>
|
<ColumnDefinition Width="32"></ColumnDefinition>
|
||||||
<ColumnDefinition/>
|
<ColumnDefinition/>
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@ using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using WinAlfred.Annotations;
|
using WinAlfred.Annotations;
|
||||||
|
using WinAlfred.Helper;
|
||||||
using WinAlfred.Plugin;
|
using WinAlfred.Plugin;
|
||||||
using Brush = System.Windows.Media.Brush;
|
using Brush = System.Windows.Media.Brush;
|
||||||
|
|
||||||
|
|
@ -14,6 +16,7 @@ namespace WinAlfred
|
||||||
{
|
{
|
||||||
public partial class ResultItem : UserControl, INotifyPropertyChanged
|
public partial class ResultItem : UserControl, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
|
||||||
private bool selected;
|
private bool selected;
|
||||||
|
|
||||||
public Result Result { get; private set; }
|
public Result Result { get; private set; }
|
||||||
|
|
@ -47,7 +50,6 @@ namespace WinAlfred
|
||||||
|
|
||||||
public ResultItem(Result result)
|
public ResultItem(Result result)
|
||||||
{
|
{
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Result = result;
|
Result = result;
|
||||||
|
|
||||||
|
|
@ -74,6 +76,17 @@ namespace WinAlfred
|
||||||
imgIco.Source = new BitmapImage(new Uri(path));
|
imgIco.Source = new BitmapImage(new Uri(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddHandler(MouseLeftButtonUpEvent, new RoutedEventHandler((o, e) =>
|
||||||
|
{
|
||||||
|
Result.Action();
|
||||||
|
SelectedRecords.Instance.AddSelect(result);
|
||||||
|
if (!result.DontHideWinAlfredAfterSelect)
|
||||||
|
{
|
||||||
|
App.Window.HideApp();
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImageSource GetIcon(string fileName)
|
private static ImageSource GetIcon(string fileName)
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="Commands\BaseCommand.cs" />
|
<Compile Include="Commands\BaseCommand.cs" />
|
||||||
<Compile Include="Commands\Command.cs" />
|
<Compile Include="Commands\CommandFactory.cs" />
|
||||||
<Compile Include="Commands\PluginCommand.cs" />
|
<Compile Include="Commands\PluginCommand.cs" />
|
||||||
<Compile Include="Commands\SystemCommand.cs" />
|
<Compile Include="Commands\SystemCommand.cs" />
|
||||||
<Compile Include="DispatcherExtensions.cs" />
|
<Compile Include="DispatcherExtensions.cs" />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue