From 78f26a368971fac9d360d9fb12aaeb61ff6ef95a Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 26 Jan 2014 11:01:13 +0800 Subject: [PATCH] fix CMD issues and add history support. --- WinAlfred.Plugin.System/CMD.cs | 94 ++- WinAlfred/{ => Helper}/KeyboardListener.cs | 4 +- WinAlfred/MainWindow.xaml.cs | 704 ++++++++++----------- WinAlfred/WinAlfred.csproj | 18 +- 4 files changed, 445 insertions(+), 375 deletions(-) rename WinAlfred/{ => Helper}/KeyboardListener.cs (98%) diff --git a/WinAlfred.Plugin.System/CMD.cs b/WinAlfred.Plugin.System/CMD.cs index 659b9ed2e..64dbc6b5a 100644 --- a/WinAlfred.Plugin.System/CMD.cs +++ b/WinAlfred.Plugin.System/CMD.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; +using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Windows.Forms; @@ -9,6 +11,9 @@ namespace WinAlfred.Plugin.System { public class CMD : BaseSystemPlugin { + private Dictionary cmdHistory = new Dictionary(); + private string filePath = Directory.GetCurrentDirectory() + "\\CMDHistory.dat"; + protected override List QueryInternal(Query query) { List results = new List(); @@ -18,29 +23,96 @@ namespace WinAlfred.Plugin.System Result result = new Result { Title = cmd, - SubTitle = "execute command through command shell" , + Score = 5000, + SubTitle = "execute command through command shell", IcoPath = "Images/cmd.png", Action = () => { - Process process = new Process(); - ProcessStartInfo startInfo = new ProcessStartInfo - { - WindowStyle = ProcessWindowStyle.Normal, - FileName = "cmd.exe", - Arguments = "/C " + cmd - }; - process.StartInfo = startInfo; - process.Start(); + ExecuteCmd(cmd); + AddCmdHistory(cmd); } }; results.Add(result); + + IEnumerable history = cmdHistory.Where(o => o.Key.Contains(cmd)) + .OrderByDescending(o => o.Value) + .Select(m => new Result + { + Title = m.Key, + SubTitle = "this command has been executed " + m.Value + " times", + IcoPath = "Images/cmd.png", + Action = () => + { + ExecuteCmd(m.Key); + AddCmdHistory(m.Key); + } + }).Take(4); + + results.AddRange(history); } return results; } - protected override void InitInternal(PluginInitContext context) + private static void ExecuteCmd(string cmd) { + try + { + Process process = new Process(); + process.StartInfo.UseShellExecute = true; + process.StartInfo.FileName = cmd; + process.Start(); + } + catch (Exception e) + { + MessageBox.Show("WinAlfred cound't execute this command."); + } } + protected override void InitInternal(PluginInitContext context) + { + LoadCmdHistory(); + } + + //todo:we need provide a common data persist interface for user? + private void AddCmdHistory(string cmdName) + { + if (cmdHistory.ContainsKey(cmdName)) + { + cmdHistory[cmdName] += 1; + } + else + { + cmdHistory.Add(cmdName, 1); + } + PersistCmdHistory(); + } + + public void LoadCmdHistory() + { + if (File.Exists(filePath)) + { + FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); + BinaryFormatter b = new BinaryFormatter(); + cmdHistory = (Dictionary)b.Deserialize(fileStream); + fileStream.Close(); + } + + if (cmdHistory.Count > 1000) + { + List onlyOnceKeys = (from c in cmdHistory where c.Value == 1 select c.Key).ToList(); + foreach (string onlyOnceKey in onlyOnceKeys) + { + cmdHistory.Remove(onlyOnceKey); + } + } + } + + private void PersistCmdHistory() + { + FileStream fileStream = new FileStream(filePath, FileMode.Create); + BinaryFormatter b = new BinaryFormatter(); + b.Serialize(fileStream, cmdHistory); + fileStream.Close(); + } } } diff --git a/WinAlfred/KeyboardListener.cs b/WinAlfred/Helper/KeyboardListener.cs similarity index 98% rename from WinAlfred/KeyboardListener.cs rename to WinAlfred/Helper/KeyboardListener.cs index 36cc54552..01a9e1c02 100644 --- a/WinAlfred/KeyboardListener.cs +++ b/WinAlfred/Helper/KeyboardListener.cs @@ -2,10 +2,8 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Windows.Input; -using System.Windows.Threading; -namespace WinAlfred +namespace WinAlfred.Helper { public enum KeyEvent : int { diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 75a6d2b76..dfc916e62 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -1,362 +1,362 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Runtime.InteropServices; -using System.Threading; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Forms; -using System.Windows.Input; -using System.Windows.Media.Animation; -using WinAlfred.Commands; -using WinAlfred.Helper; -using WinAlfred.Plugin; -using WinAlfred.PluginLoader; -using Application = System.Windows.Application; -using KeyEventArgs = System.Windows.Input.KeyEventArgs; -using MessageBox = System.Windows.MessageBox; - -namespace WinAlfred -{ - public partial class MainWindow - { - private KeyboardHook hook = new KeyboardHook(); - private NotifyIcon notifyIcon; - private Command cmdDispatcher; - Storyboard progressBarStoryboard = new Storyboard(); - private bool queryHasReturn = false; - SelectedRecords selectedRecords = new SelectedRecords(); - - private KeyboardListener keyboardListener = new KeyboardListener(); +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Forms; +using System.Windows.Input; +using System.Windows.Media.Animation; +using WinAlfred.Commands; +using WinAlfred.Helper; +using WinAlfred.Plugin; +using WinAlfred.PluginLoader; +using Application = System.Windows.Application; +using KeyEventArgs = System.Windows.Input.KeyEventArgs; +using MessageBox = System.Windows.MessageBox; + +namespace WinAlfred +{ + public partial class MainWindow + { + private KeyboardHook hook = new KeyboardHook(); + private NotifyIcon notifyIcon; + private Command cmdDispatcher; + Storyboard progressBarStoryboard = new Storyboard(); + private bool queryHasReturn = false; + SelectedRecords selectedRecords = new SelectedRecords(); + + private KeyboardListener keyboardListener = new KeyboardListener(); private bool WinRStroked = false; - private WindowsInput.KeyboardSimulator keyboardSimulator = new WindowsInput.KeyboardSimulator(new WindowsInput.InputSimulator()); - - public MainWindow() - { - InitializeComponent(); - - hook.KeyPressed += OnHotKey; - hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); - resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; - ThreadPool.SetMaxThreads(30, 10); + private WindowsInput.KeyboardSimulator keyboardSimulator = new WindowsInput.KeyboardSimulator(new WindowsInput.InputSimulator()); + + public MainWindow() + { + InitializeComponent(); + + hook.KeyPressed += OnHotKey; + hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); + resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; + ThreadPool.SetMaxThreads(30, 10); InitProgressbarAnimation(); - try - { + try + { ChangeStyles(Settings.Instance.Theme); - + } catch (System.IO.IOException) { ChangeStyles(Settings.Instance.Theme = "Default"); - } - } - - private void WakeupApp() - { - //After hide winalfred in the background for a long time. It will become very slow in the next show. - //This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every min - //which may prevent sysetem uninstall memory from RAM to disk. - - System.Timers.Timer t = new System.Timers.Timer(1000 * 60 * 5) { AutoReset = true, Enabled = true }; - t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() => - { - if (Visibility != Visibility.Visible) - { - double oldLeft = Left; - Left = 20000; - ShowWinAlfred(); - cmdDispatcher.DispatchCommand(new Query("qq"), false); - HideWinAlfred(); - Left = oldLeft; - } - })); - } - - 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.X2)")); - Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)")); - progressBarStoryboard.Children.Add(da); - progressBarStoryboard.Children.Add(da1); - progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; - progressBar.Visibility = Visibility.Hidden; - progressBar.BeginStoryboard(progressBarStoryboard); - } - - private void InitialTray() - { - notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true }; - notifyIcon.Click += (o, e) => ShowWinAlfred(); - System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); - open.Click += (o, e) => ShowWinAlfred(); - System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); - exit.Click += (o, e) => CloseApp(); - System.Windows.Forms.MenuItem[] childen = { open, exit }; - notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); - } - - private void resultCtrl_resultItemChangedEvent() - { - resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0 ? new Thickness { Top = grid.Margin.Top } : new Thickness { Top = 0 }; - } - - private void OnHotKey(object sender, KeyPressedEventArgs e) - { - if (!IsVisible) - { - ShowWinAlfred(); - } - else - { - HideWinAlfred(); - } - } - - private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) - { - resultCtrl.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 - // 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; - } - - private void StopProgress() - { - progressBar.Visibility = Visibility.Hidden; - } - - private void HideWinAlfred() - { - Hide(); - } - - private void ShowWinAlfred() - { - Show(); - Activate(); - tbQuery.SelectAll(); - Focus(); - tbQuery.Focus(); - } - - public void ParseArgs(string[] args) - { - if (args != null && args.Length > 0) - { - switch (args[0]) - { - case "reloadWorkflows": - Plugins.Init(this); - break; - - case "query": - if (args.Length > 1) - { - string query = args[1]; - tbQuery.Text = query; - tbQuery.SelectAll(); - } - break; - } - } - } - - private void SetAutoStart(bool IsAtuoRun) - { - //string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; - //if (IsAtuoRun) - //{ - // WshShell shell = new WshShell(); - // IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath); - // shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; - // shortcut.WorkingDirectory = Environment.CurrentDirectory; - // shortcut.WindowStyle = 1; //normal window - // shortcut.Description = "WinAlfred"; - // shortcut.Save(); - //} - //else - //{ - // System.IO.File.Delete(LnkPath); - //} - } - - private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) - { - Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; - Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3; - - Plugins.Init(this); - cmdDispatcher = new Command(this); - InitialTray(); - selectedRecords.LoadSelectedRecords(); - SetAutoStart(true); - WakeupApp(); - //var engine = new Jurassic.ScriptEngine(); - //MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString()); - keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback; - } - - private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) - { - if (Settings.Instance.ReplaceWinR) - { - if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) - { - Dispatcher.BeginInvoke(new Action(() => - { - resultCtrl.Clear(); - ShowWinAlfred(); - ChangeQuery(">"); - WinRStroked = true; - })); - return false; - } - if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) - { - WinRStroked = false; - keyboardSimulator.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LWIN, WindowsInput.Native.VirtualKeyCode.CONTROL); - return false; - } - } - return true; - } - - private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) - { - switch (e.Key) - { - case Key.Escape: - HideWinAlfred(); - e.Handled = true; - break; - - case Key.Down: - resultCtrl.SelectNext(); - e.Handled = true; - break; - - case Key.Up: - resultCtrl.SelectPrev(); - e.Handled = true; - break; - - case Key.Enter: - Result result = resultCtrl.AcceptSelect(); - if (result != null) - { - selectedRecords.AddSelect(result); - if (!result.DontHideWinAlfredAfterSelect) - { - HideWinAlfred(); - } - } - e.Handled = true; - break; - } - } - - public void OnUpdateResultView(List list) - { - queryHasReturn = true; - progressBar.Dispatcher.Invoke(new Action(StopProgress)); - if (list.Count > 0) - { - //todo:this should be opened to users, it's their choise to use it or not in thier workflows - list.ForEach(o => - { - if (o.AutoAjustScore) o.Score += selectedRecords.GetSelectedCount(o); - }); - resultCtrl.Dispatcher.Invoke(new Action(() => - { - List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList(); - resultCtrl.AddResults(l); - })); - } - } - - public void ChangeStyles(string themeName) - { - ResourceDictionary dict = new ResourceDictionary - { - Source = new Uri("pack://application:,,,/Themes/" + themeName + ".xaml") - }; - - Application.Current.Resources.MergedDictionaries.Clear(); - Application.Current.Resources.MergedDictionaries.Add(dict); - } - - #region Public API - - //Those method can be invoked by plugins - - public void ChangeQuery(string query) - { - tbQuery.Text = query; - tbQuery.CaretIndex = tbQuery.Text.Length; - } - - public void CloseApp() - { - notifyIcon.Visible = false; - Environment.Exit(0); - } - - public void HideApp() - { - HideWinAlfred(); - } - - public void ShowApp() - { - ShowWinAlfred(); - } - - public void ShowMsg(string title, string subTitle, string iconPath) - { - Msg m = new Msg { Owner = GetWindow(this) }; - m.Show(title, subTitle, iconPath); - } - - public void OpenSettingDialog() - { - SettingWidow s = new SettingWidow(this); - s.Show(); - } - - #endregion - - } + } + } + + private void WakeupApp() + { + //After hide winalfred in the background for a long time. It will become very slow in the next show. + //This is caused by the Virtual Mermory Page Mechanisam. So, our solution is execute some codes in every min + //which may prevent sysetem uninstall memory from RAM to disk. + + System.Timers.Timer t = new System.Timers.Timer(1000 * 60 * 5) { AutoReset = true, Enabled = true }; + t.Elapsed += (o, e) => Dispatcher.Invoke(new Action(() => + { + if (Visibility != Visibility.Visible) + { + double oldLeft = Left; + Left = 20000; + ShowWinAlfred(); + cmdDispatcher.DispatchCommand(new Query("qq"), false); + HideWinAlfred(); + Left = oldLeft; + } + })); + } + + 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.X2)")); + Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)")); + progressBarStoryboard.Children.Add(da); + progressBarStoryboard.Children.Add(da1); + progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; + progressBar.Visibility = Visibility.Hidden; + progressBar.BeginStoryboard(progressBarStoryboard); + } + + private void InitialTray() + { + notifyIcon = new NotifyIcon { Text = "WinAlfred", Icon = Properties.Resources.app, Visible = true }; + notifyIcon.Click += (o, e) => ShowWinAlfred(); + System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("Open"); + open.Click += (o, e) => ShowWinAlfred(); + System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("Exit"); + exit.Click += (o, e) => CloseApp(); + System.Windows.Forms.MenuItem[] childen = { open, exit }; + notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen); + } + + private void resultCtrl_resultItemChangedEvent() + { + resultCtrl.Margin = resultCtrl.GetCurrentResultCount() > 0 ? new Thickness { Top = grid.Margin.Top } : new Thickness { Top = 0 }; + } + + private void OnHotKey(object sender, KeyPressedEventArgs e) + { + if (!IsVisible) + { + ShowWinAlfred(); + } + else + { + HideWinAlfred(); + } + } + + private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) + { + resultCtrl.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 + // 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; + } + + private void StopProgress() + { + progressBar.Visibility = Visibility.Hidden; + } + + private void HideWinAlfred() + { + Hide(); + } + + private void ShowWinAlfred() + { + Show(); + Activate(); + tbQuery.SelectAll(); + Focus(); + tbQuery.Focus(); + } + + public void ParseArgs(string[] args) + { + if (args != null && args.Length > 0) + { + switch (args[0]) + { + case "reloadWorkflows": + Plugins.Init(this); + break; + + case "query": + if (args.Length > 1) + { + string query = args[1]; + tbQuery.Text = query; + tbQuery.SelectAll(); + } + break; + } + } + } + + private void SetAutoStart(bool IsAtuoRun) + { + //string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk"; + //if (IsAtuoRun) + //{ + // WshShell shell = new WshShell(); + // IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath); + // shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; + // shortcut.WorkingDirectory = Environment.CurrentDirectory; + // shortcut.WindowStyle = 1; //normal window + // shortcut.Description = "WinAlfred"; + // shortcut.Save(); + //} + //else + //{ + // System.IO.File.Delete(LnkPath); + //} + } + + private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) + { + Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; + Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3; + + Plugins.Init(this); + cmdDispatcher = new Command(this); + InitialTray(); + selectedRecords.LoadSelectedRecords(); + SetAutoStart(true); + WakeupApp(); + //var engine = new Jurassic.ScriptEngine(); + //MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString()); + keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback; + } + + private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) + { + if (Settings.Instance.ReplaceWinR) + { + if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) + { + Dispatcher.BeginInvoke(new Action(() => + { + resultCtrl.Clear(); + ShowWinAlfred(); + ChangeQuery(">"); + WinRStroked = true; + })); + return false; + } + if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) + { + WinRStroked = false; + keyboardSimulator.ModifiedKeyStroke(WindowsInput.Native.VirtualKeyCode.LWIN, WindowsInput.Native.VirtualKeyCode.CONTROL); + return false; + } + } + return true; + } + + private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) + { + switch (e.Key) + { + case Key.Escape: + HideWinAlfred(); + e.Handled = true; + break; + + case Key.Down: + resultCtrl.SelectNext(); + e.Handled = true; + break; + + case Key.Up: + resultCtrl.SelectPrev(); + e.Handled = true; + break; + + case Key.Enter: + Result result = resultCtrl.AcceptSelect(); + if (result != null) + { + selectedRecords.AddSelect(result); + if (!result.DontHideWinAlfredAfterSelect) + { + HideWinAlfred(); + } + } + e.Handled = true; + break; + } + } + + public void OnUpdateResultView(List list) + { + queryHasReturn = true; + progressBar.Dispatcher.Invoke(new Action(StopProgress)); + if (list.Count > 0) + { + //todo:this should be opened to users, it's their choise to use it or not in thier workflows + list.ForEach(o => + { + if (o.AutoAjustScore) o.Score += selectedRecords.GetSelectedCount(o); + }); + resultCtrl.Dispatcher.Invoke(new Action(() => + { + List l = list.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == tbQuery.Text).ToList(); + resultCtrl.AddResults(l); + })); + } + } + + public void ChangeStyles(string themeName) + { + ResourceDictionary dict = new ResourceDictionary + { + Source = new Uri("pack://application:,,,/Themes/" + themeName + ".xaml") + }; + + Application.Current.Resources.MergedDictionaries.Clear(); + Application.Current.Resources.MergedDictionaries.Add(dict); + } + + #region Public API + + //Those method can be invoked by plugins + + public void ChangeQuery(string query) + { + tbQuery.Text = query; + tbQuery.CaretIndex = tbQuery.Text.Length; + } + + public void CloseApp() + { + notifyIcon.Visible = false; + Environment.Exit(0); + } + + public void HideApp() + { + HideWinAlfred(); + } + + public void ShowApp() + { + ShowWinAlfred(); + } + + public void ShowMsg(string title, string subTitle, string iconPath) + { + Msg m = new Msg { Owner = GetWindow(this) }; + m.Show(title, subTitle, iconPath); + } + + public void OpenSettingDialog() + { + SettingWidow s = new SettingWidow(this); + s.Show(); + } + + #endregion + + } } \ No newline at end of file diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index 739f0155e..a468c8b70 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -121,7 +121,7 @@ - + Msg.xaml @@ -268,15 +268,15 @@ - xcopy /Y $(ProjectDir)Images\*.* $(TargetDir)Images\ -xcopy /Y $(ProjectDir)app.ico $(TargetDir) + xcopy /Y $(ProjectDir)Images\*.* $(TargetDir)Images\ +xcopy /Y $(ProjectDir)app.ico $(TargetDir) xcopy /Y $(ProjectDir)Themes\*.* $(TargetDir)Themes\ - \ No newline at end of file