2014-01-29 18:33:24 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
using System.ComponentModel;
|
2014-08-10 22:47:37 +08:00
|
|
|
|
using System.Diagnostics;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
using System.Drawing;
|
2015-02-07 16:53:33 +08:00
|
|
|
|
using System.IO;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Linq;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
using System.Net;
|
2015-02-05 23:29:41 +08:00
|
|
|
|
using System.Reflection;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media.Animation;
|
2014-02-20 23:15:03 +08:00
|
|
|
|
using NHotkey;
|
|
|
|
|
using NHotkey.Wpf;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using Wox.Core.i18n;
|
2014-12-26 19:36:43 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2015-01-02 23:07:49 +08:00
|
|
|
|
using Wox.Core.Theme;
|
2015-01-19 23:08:53 +08:00
|
|
|
|
using Wox.Core.Updater;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2014-03-02 11:04:30 +08:00
|
|
|
|
using Wox.Helper;
|
2014-01-29 22:44:57 +08:00
|
|
|
|
using Wox.Infrastructure;
|
2014-12-21 22:03:03 +08:00
|
|
|
|
using Wox.Infrastructure.Hotkey;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Plugin;
|
2014-12-26 22:51:04 +08:00
|
|
|
|
using Wox.Storage;
|
2014-02-22 11:55:48 +08:00
|
|
|
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
using DataFormats = System.Windows.DataFormats;
|
2014-06-30 22:50:54 +08:00
|
|
|
|
using DragEventArgs = System.Windows.DragEventArgs;
|
2015-02-07 16:53:33 +08:00
|
|
|
|
using IDataObject = System.Windows.IDataObject;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
2014-02-22 11:55:48 +08:00
|
|
|
|
using MenuItem = System.Windows.Forms.MenuItem;
|
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2015-11-08 01:32:58 +08:00
|
|
|
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
2014-02-28 23:21:01 +08:00
|
|
|
|
using ToolTip = System.Windows.Controls.ToolTip;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
|
|
|
|
public partial class MainWindow : IPublicAPI
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
private readonly Storyboard progressBarStoryboard = new Storyboard();
|
|
|
|
|
private NotifyIcon notifyIcon;
|
2015-11-07 11:50:26 +08:00
|
|
|
|
private bool _queryHasReturn;
|
|
|
|
|
private Query _lastQuery = new Query();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
private ToolTip toolTip = new ToolTip();
|
|
|
|
|
|
2015-11-07 11:50:26 +08:00
|
|
|
|
private bool _ignoreTextChange = false;
|
2015-02-07 16:53:33 +08:00
|
|
|
|
private List<Result> CurrentContextMenus = new List<Result>();
|
|
|
|
|
private string textBeforeEnterContextMenuMode;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public API
|
|
|
|
|
|
|
|
|
|
public void ChangeQuery(string query, bool requery = false)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
tbQuery.Text = query;
|
|
|
|
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
|
|
|
|
if (requery)
|
|
|
|
|
{
|
2015-11-01 04:32:28 +08:00
|
|
|
|
TbQuery_OnTextChanged(null, null);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 19:16:13 +08:00
|
|
|
|
public void ChangeQueryText(string query, bool selectAll = false)
|
2015-02-07 16:53:33 +08:00
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
2015-11-07 11:50:26 +08:00
|
|
|
|
_ignoreTextChange = true;
|
2015-02-07 16:53:33 +08:00
|
|
|
|
tbQuery.Text = query;
|
|
|
|
|
tbQuery.CaretIndex = tbQuery.Text.Length;
|
2015-02-09 19:16:13 +08:00
|
|
|
|
if (selectAll)
|
|
|
|
|
{
|
|
|
|
|
tbQuery.SelectAll();
|
|
|
|
|
}
|
2015-02-07 16:53:33 +08:00
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
public void CloseApp()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
notifyIcon.Visible = false;
|
|
|
|
|
Close();
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void HideApp()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(HideWox));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowApp()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() => ShowWox()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowMsg(string title, string subTitle, string iconPath)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
var m = new Msg { Owner = GetWindow(this) };
|
|
|
|
|
m.Show(title, subTitle, iconPath);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-21 21:57:00 +08:00
|
|
|
|
public void OpenSettingDialog(string tabName = "general")
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-02-21 21:57:00 +08:00
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this);
|
|
|
|
|
sw.SwitchTo(tabName);
|
|
|
|
|
}));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StartLoadingBar()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(StartProgress));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopLoadingBar()
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(StopProgress));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void InstallPlugin(string path)
|
|
|
|
|
{
|
2014-12-27 12:34:51 +08:00
|
|
|
|
Dispatcher.Invoke(new Action(() => PluginManager.InstallPlugin(path)));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReloadPlugins()
|
|
|
|
|
{
|
2015-01-02 23:07:49 +08:00
|
|
|
|
Dispatcher.Invoke(new Action(() => PluginManager.Init(this)));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 23:24:11 +08:00
|
|
|
|
public string GetTranslation(string key)
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
return InternationalizationManager.Instance.GetTranslation(key);
|
2015-01-06 23:24:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
public List<PluginPair> GetAllPlugins()
|
|
|
|
|
{
|
2015-11-03 09:33:53 +08:00
|
|
|
|
return PluginManager.AllPlugins.ToList();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event WoxKeyDownEventHandler BackKeyDownEvent;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
public event WoxGlobalKeyboardEventHandler GlobalKeyboardEvent;
|
2015-02-02 23:28:40 +08:00
|
|
|
|
public event ResultItemDropEventHandler ResultItemDropEvent;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2015-01-26 20:54:01 +08:00
|
|
|
|
public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
results.ForEach(o =>
|
|
|
|
|
{
|
|
|
|
|
o.PluginDirectory = plugin.PluginDirectory;
|
2015-01-26 20:54:01 +08:00
|
|
|
|
o.PluginID = plugin.ID;
|
|
|
|
|
o.OriginQuery = query;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
});
|
2015-11-08 04:48:18 +08:00
|
|
|
|
UpdateResultView(results, plugin, query);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 23:16:41 +08:00
|
|
|
|
public void ShowContextMenu(PluginMetadata plugin, List<Result> results)
|
|
|
|
|
{
|
|
|
|
|
if (results != null && results.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
results.ForEach(o =>
|
|
|
|
|
{
|
|
|
|
|
o.PluginDirectory = plugin.PluginDirectory;
|
|
|
|
|
o.PluginID = plugin.ID;
|
|
|
|
|
o.ContextMenu = null;
|
|
|
|
|
});
|
|
|
|
|
pnlContextMenu.Clear();
|
2015-11-08 04:48:18 +08:00
|
|
|
|
pnlContextMenu.AddResults(results, plugin.ID);
|
2015-02-04 23:16:41 +08:00
|
|
|
|
pnlContextMenu.Visibility = Visibility.Visible;
|
|
|
|
|
pnlResult.Visibility = Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-01-08 22:49:42 +08:00
|
|
|
|
ThreadPool.SetMaxThreads(30, 10);
|
|
|
|
|
ThreadPool.SetMinThreads(10, 5);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2015-01-08 22:49:42 +08:00
|
|
|
|
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
|
|
|
|
|
GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
progressBar.ToolTip = toolTip;
|
2014-10-23 18:39:11 +08:00
|
|
|
|
pnlResult.LeftMouseClickEvent += SelectResult;
|
2015-02-02 23:28:40 +08:00
|
|
|
|
pnlResult.ItemDropEvent += pnlResult_ItemDropEvent;
|
2014-10-23 18:39:11 +08:00
|
|
|
|
pnlContextMenu.LeftMouseClickEvent += SelectResult;
|
|
|
|
|
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
|
2015-01-21 23:00:56 +08:00
|
|
|
|
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
|
|
|
|
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
|
|
|
|
|
SetCustomPluginHotkey();
|
2015-02-21 21:57:00 +08:00
|
|
|
|
InitialTray();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2014-11-03 18:49:18 +08:00
|
|
|
|
Closing += MainWindow_Closing;
|
2015-10-31 04:47:03 +08:00
|
|
|
|
|
2015-01-08 22:49:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 18:32:16 +08:00
|
|
|
|
void pnlResult_ItemDropEvent(Result result, IDataObject dropDataObject, DragEventArgs args)
|
2015-02-02 23:28:40 +08:00
|
|
|
|
{
|
2015-02-03 18:32:16 +08:00
|
|
|
|
PluginPair pluginPair = PluginManager.AllPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
|
|
|
|
if (ResultItemDropEvent != null && pluginPair != null)
|
2015-02-02 23:28:40 +08:00
|
|
|
|
{
|
2015-02-03 18:32:16 +08:00
|
|
|
|
foreach (var delegateHandler in ResultItemDropEvent.GetInvocationList())
|
2015-02-02 23:28:40 +08:00
|
|
|
|
{
|
2015-02-03 18:32:16 +08:00
|
|
|
|
if (delegateHandler.Target == pluginPair.Plugin)
|
|
|
|
|
{
|
|
|
|
|
delegateHandler.DynamicInvoke(result, dropDataObject, args);
|
|
|
|
|
}
|
2015-02-02 23:28:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-08 22:49:42 +08:00
|
|
|
|
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
|
|
|
|
|
{
|
|
|
|
|
if (GlobalKeyboardEvent != null)
|
|
|
|
|
{
|
|
|
|
|
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2014-12-18 19:22:47 +08:00
|
|
|
|
}
|
2014-12-14 23:16:29 +08:00
|
|
|
|
|
2014-10-23 18:39:11 +08:00
|
|
|
|
void pnlResult_RightMouseClickEvent(Result result)
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
ShowContextMenu(result);
|
2014-10-23 18:39:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-08 22:49:42 +08:00
|
|
|
|
void MainWindow_Closing(object sender, CancelEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
UserSettingStorage.Instance.WindowLeft = Left;
|
|
|
|
|
UserSettingStorage.Instance.WindowTop = Top;
|
|
|
|
|
UserSettingStorage.Instance.Save();
|
|
|
|
|
this.HideWox();
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2015-02-20 21:45:42 +08:00
|
|
|
|
Left = GetWindowsLeft();
|
|
|
|
|
Top = GetWindowsTop();
|
|
|
|
|
|
|
|
|
|
InitProgressbarAnimation();
|
|
|
|
|
WindowIntelopHelper.DisableControlBox(this);
|
2015-11-10 19:18:03 +08:00
|
|
|
|
WindowIntelopHelper.SetBlurForWindow(this, UserSettingStorage.Instance.ThemeBlurEnabled);
|
2015-02-20 21:45:42 +08:00
|
|
|
|
CheckUpdate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetWindowsLeft()
|
|
|
|
|
{
|
|
|
|
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
|
|
|
|
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-02-20 21:45:42 +08:00
|
|
|
|
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
|
|
|
|
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
|
|
|
|
|
UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-02-20 21:45:42 +08:00
|
|
|
|
UserSettingStorage.Instance.WindowLeft = (screen.WorkingArea.Width - ActualWidth) / 2 + screen.WorkingArea.Left;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-20 21:45:42 +08:00
|
|
|
|
return UserSettingStorage.Instance.WindowLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetWindowsTop()
|
|
|
|
|
{
|
|
|
|
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
|
|
|
|
if (UserSettingStorage.Instance.RememberLastLaunchLocation)
|
|
|
|
|
{
|
|
|
|
|
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
|
|
|
|
|
var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
|
|
|
|
|
UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-02-20 22:18:27 +08:00
|
|
|
|
UserSettingStorage.Instance.WindowTop = (screen.WorkingArea.Height - tbQuery.ActualHeight) / 4 + screen.WorkingArea.Top;
|
2015-02-20 21:45:42 +08:00
|
|
|
|
}
|
|
|
|
|
return UserSettingStorage.Instance.WindowTop;
|
2015-02-01 22:46:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckUpdate()
|
|
|
|
|
{
|
2015-02-04 23:16:41 +08:00
|
|
|
|
UpdaterManager.Instance.PrepareUpdateReady += OnPrepareUpdateReady;
|
2015-02-01 22:46:56 +08:00
|
|
|
|
UpdaterManager.Instance.UpdateError += OnUpdateError;
|
2015-01-19 23:08:53 +08:00
|
|
|
|
UpdaterManager.Instance.CheckUpdate();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-01 22:46:56 +08:00
|
|
|
|
void OnUpdateError(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string updateError = InternationalizationManager.Instance.GetTranslation("update_wox_update_error");
|
|
|
|
|
MessageBox.Show(updateError);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPrepareUpdateReady(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
|
|
|
|
{
|
|
|
|
|
new WoxUpdate().ShowDialog();
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
|
|
|
|
|
{
|
|
|
|
|
var hotkey = new HotkeyModel(hotkeyStr);
|
2015-06-07 11:45:06 +08:00
|
|
|
|
SetHotkey(hotkey, action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetHotkey(HotkeyModel hotkey, EventHandler<HotkeyEventArgs> action)
|
|
|
|
|
{
|
|
|
|
|
string hotkeyStr = hotkey.ToString();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
|
2015-01-02 23:07:49 +08:00
|
|
|
|
MessageBox.Show(errorMsg);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveHotkey(string hotkeyStr)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(hotkeyStr))
|
|
|
|
|
{
|
|
|
|
|
HotkeyManager.Current.Remove(hotkeyStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 06:17:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if Wox should ignore any hotkeys
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private bool ShouldIgnoreHotkeys()
|
|
|
|
|
{
|
2015-10-08 06:52:52 +08:00
|
|
|
|
//double if to omit calling win32 function
|
2015-10-08 07:02:36 +08:00
|
|
|
|
if (UserSettingStorage.Instance.IgnoreHotkeysOnFullscreen)
|
2015-11-03 08:34:27 +08:00
|
|
|
|
if (WindowIntelopHelper.IsWindowFullscreen())
|
2015-10-08 06:52:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
2015-10-08 06:17:37 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
private void SetCustomPluginHotkey()
|
|
|
|
|
{
|
|
|
|
|
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
|
|
|
|
|
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
|
|
|
|
|
{
|
|
|
|
|
CustomPluginHotkey hotkey1 = hotkey;
|
|
|
|
|
SetHotkey(hotkey.Hotkey, delegate
|
|
|
|
|
{
|
2015-10-08 06:17:37 +08:00
|
|
|
|
if (ShouldIgnoreHotkeys()) return;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
ShowApp();
|
|
|
|
|
ChangeQuery(hotkey1.ActionKeyword, true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnHotkey(object sender, HotkeyEventArgs e)
|
2015-01-29 22:35:01 +08:00
|
|
|
|
{
|
2015-10-08 06:17:37 +08:00
|
|
|
|
if (ShouldIgnoreHotkeys()) return;
|
2015-01-29 22:35:01 +08:00
|
|
|
|
ToggleWox();
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToggleWox()
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (!IsVisible)
|
|
|
|
|
{
|
|
|
|
|
ShowWox();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HideWox();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitProgressbarAnimation()
|
|
|
|
|
{
|
|
|
|
|
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
|
|
|
|
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, 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 = "Wox", Icon = Properties.Resources.app, Visible = true };
|
|
|
|
|
notifyIcon.Click += (o, e) => ShowWox();
|
2015-02-21 21:57:00 +08:00
|
|
|
|
var open = new MenuItem(GetTranslation("iconTrayOpen"));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
open.Click += (o, e) => ShowWox();
|
2015-02-21 21:57:00 +08:00
|
|
|
|
var setting = new MenuItem(GetTranslation("iconTraySettings"));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
setting.Click += (o, e) => OpenSettingDialog();
|
2015-02-21 21:57:00 +08:00
|
|
|
|
var about = new MenuItem(GetTranslation("iconTrayAbout"));
|
|
|
|
|
about.Click += (o, e) => OpenSettingDialog("about");
|
|
|
|
|
var exit = new MenuItem(GetTranslation("iconTrayExit"));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
exit.Click += (o, e) => CloseApp();
|
2015-02-21 21:57:00 +08:00
|
|
|
|
MenuItem[] childen = { open, setting, about, exit };
|
2014-07-24 04:46:19 +08:00
|
|
|
|
notifyIcon.ContextMenu = new ContextMenu(childen);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-07 16:53:33 +08:00
|
|
|
|
private void QueryContextMenu()
|
|
|
|
|
{
|
2015-11-08 04:48:18 +08:00
|
|
|
|
var contextMenuId = "Context Menu Id";
|
2015-02-07 16:53:33 +08:00
|
|
|
|
pnlContextMenu.Clear();
|
|
|
|
|
var query = tbQuery.Text.ToLower();
|
|
|
|
|
if (string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
2015-11-08 04:48:18 +08:00
|
|
|
|
pnlContextMenu.AddResults(CurrentContextMenus, contextMenuId);
|
2015-02-07 16:53:33 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<Result> filterResults = new List<Result>();
|
|
|
|
|
foreach (Result contextMenu in CurrentContextMenus)
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
2015-02-07 16:53:33 +08:00
|
|
|
|
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
|
|
|
|
{
|
|
|
|
|
filterResults.Add(contextMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-08 04:48:18 +08:00
|
|
|
|
pnlContextMenu.AddResults(filterResults, contextMenuId);
|
2015-02-07 16:53:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 04:32:28 +08:00
|
|
|
|
private void TbQuery_OnTextChanged(object sender, TextChangedEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-11-07 11:50:26 +08:00
|
|
|
|
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
|
2015-11-08 11:06:34 +08:00
|
|
|
|
|
2015-11-08 04:48:18 +08:00
|
|
|
|
toolTip.IsOpen = false;
|
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
QueryContextMenu();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-11-08 11:06:34 +08:00
|
|
|
|
|
|
|
|
|
string query = tbQuery.Text.Trim();
|
2015-11-07 11:50:26 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(query))
|
2015-11-03 08:34:27 +08:00
|
|
|
|
{
|
2015-11-07 11:50:26 +08:00
|
|
|
|
Query(query);
|
2015-11-07 05:30:38 +08:00
|
|
|
|
//reset query history index after user start new query
|
|
|
|
|
ResetQueryHistoryIndex();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pnlResult.Clear();
|
|
|
|
|
}
|
2015-01-27 22:59:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 19:16:13 +08:00
|
|
|
|
private void ResetQueryHistoryIndex()
|
|
|
|
|
{
|
2015-11-08 10:50:33 +08:00
|
|
|
|
pnlResult.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
2015-02-09 19:16:13 +08:00
|
|
|
|
QueryHistoryStorage.Instance.Reset();
|
|
|
|
|
}
|
2015-11-03 13:09:54 +08:00
|
|
|
|
private void Query(string text)
|
2015-01-16 23:42:12 +08:00
|
|
|
|
{
|
2015-11-08 11:06:34 +08:00
|
|
|
|
_queryHasReturn = false;
|
2015-11-03 13:09:54 +08:00
|
|
|
|
var query = PluginManager.QueryInit(text);
|
2015-11-04 08:26:15 +08:00
|
|
|
|
if (query != null)
|
|
|
|
|
{
|
2015-11-07 11:50:26 +08:00
|
|
|
|
// handle the exclusiveness of plugin using action keyword
|
|
|
|
|
string lastKeyword = _lastQuery.ActionKeyword;
|
|
|
|
|
string keyword = query.ActionKeyword;
|
|
|
|
|
if (string.IsNullOrEmpty(lastKeyword))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
|
|
|
{
|
2015-11-08 10:50:33 +08:00
|
|
|
|
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2015-11-07 11:50:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(keyword))
|
|
|
|
|
{
|
2015-11-08 10:50:33 +08:00
|
|
|
|
pnlResult.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
2015-11-07 11:50:26 +08:00
|
|
|
|
}
|
|
|
|
|
else if (lastKeyword != keyword)
|
|
|
|
|
{
|
2015-11-08 10:50:33 +08:00
|
|
|
|
pnlResult.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2015-11-07 11:50:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_lastQuery = query;
|
2015-11-08 11:06:34 +08:00
|
|
|
|
Dispatcher.DelayInvoke("ShowProgressbar", () =>
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
|
|
|
|
{
|
|
|
|
|
StartProgress();
|
|
|
|
|
}
|
|
|
|
|
}, TimeSpan.FromMilliseconds(150));
|
2015-11-04 08:26:15 +08:00
|
|
|
|
PluginManager.QueryForAllPlugins(query);
|
|
|
|
|
}
|
2015-01-19 19:14:02 +08:00
|
|
|
|
StopProgress();
|
2015-01-16 23:42:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 18:39:11 +08:00
|
|
|
|
private void BackToResultMode()
|
|
|
|
|
{
|
2015-02-07 16:53:33 +08:00
|
|
|
|
ChangeQueryText(textBeforeEnterContextMenuMode);
|
2014-10-23 18:39:11 +08:00
|
|
|
|
pnlResult.Visibility = Visibility.Visible;
|
|
|
|
|
pnlContextMenu.Visibility = Visibility.Collapsed;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ChangedButton == MouseButton.Left) DragMove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartProgress()
|
|
|
|
|
{
|
|
|
|
|
progressBar.Visibility = Visibility.Visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StopProgress()
|
|
|
|
|
{
|
|
|
|
|
progressBar.Visibility = Visibility.Hidden;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HideWox()
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
BackToResultMode();
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
Hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ShowWox(bool selectAll = true)
|
|
|
|
|
{
|
2015-01-29 22:35:01 +08:00
|
|
|
|
UserSettingStorage.Instance.IncreaseActivateTimes();
|
2015-02-20 21:45:42 +08:00
|
|
|
|
Left = GetWindowsLeft();
|
|
|
|
|
Top = GetWindowsTop();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
Activate();
|
|
|
|
|
Focus();
|
|
|
|
|
tbQuery.Focus();
|
2015-02-09 19:16:13 +08:00
|
|
|
|
ResetQueryHistoryIndex();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
if (selectAll) tbQuery.SelectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_OnDeactivated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (UserSettingStorage.Instance.HideWhenDeactive)
|
|
|
|
|
{
|
|
|
|
|
HideWox();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//when alt is pressed, the real key should be e.SystemKey
|
|
|
|
|
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Escape:
|
2014-10-23 18:39:11 +08:00
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
BackToResultMode();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HideWox();
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2014-08-19 15:21:26 +08:00
|
|
|
|
case Key.Tab:
|
2015-01-08 22:49:42 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
2014-08-19 15:21:26 +08:00
|
|
|
|
{
|
|
|
|
|
SelectPrevItem();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectNextItem();
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2015-02-03 12:27:59 +08:00
|
|
|
|
case Key.N:
|
|
|
|
|
case Key.J:
|
2015-02-07 16:53:33 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
2015-02-03 12:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
SelectNextItem();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.P:
|
|
|
|
|
case Key.K:
|
2015-02-07 16:53:33 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
2015-02-03 12:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
SelectPrevItem();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.O:
|
2015-02-07 16:53:33 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
2015-02-03 12:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
BackToResultMode();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
ShowContextMenu(GetActiveResult());
|
2015-02-03 12:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
case Key.Down:
|
2015-02-09 19:16:13 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
DisplayNextQuery();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectNextItem();
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.Up:
|
2015-02-09 19:16:13 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
DisplayPrevQuery();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectPrevItem();
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2015-02-03 12:27:59 +08:00
|
|
|
|
case Key.D:
|
2015-02-07 16:53:33 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
2015-02-03 12:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
pnlResult.SelectNextPage();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
case Key.PageDown:
|
2014-10-23 18:39:11 +08:00
|
|
|
|
pnlResult.SelectNextPage();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2015-02-03 12:27:59 +08:00
|
|
|
|
case Key.U:
|
2015-02-07 16:53:33 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
2015-02-03 12:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
pnlResult.SelectPrevPage();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
case Key.PageUp:
|
2014-10-23 18:39:11 +08:00
|
|
|
|
pnlResult.SelectPrevPage();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
2014-07-27 17:15:12 +08:00
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
case Key.Back:
|
|
|
|
|
if (BackKeyDownEvent != null)
|
|
|
|
|
{
|
2015-01-18 18:21:48 +08:00
|
|
|
|
BackKeyDownEvent(new WoxKeyDownEventArgs()
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
Query = tbQuery.Text,
|
|
|
|
|
keyEventArgs = e
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-07-24 04:20:24 +08:00
|
|
|
|
|
2014-08-10 22:47:37 +08:00
|
|
|
|
case Key.F1:
|
2015-01-02 23:07:49 +08:00
|
|
|
|
Process.Start("http://doc.getwox.com");
|
2014-08-10 22:47:37 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2014-07-27 17:15:12 +08:00
|
|
|
|
case Key.Enter:
|
2014-10-23 18:39:11 +08:00
|
|
|
|
Result activeResult = GetActiveResult();
|
2015-01-08 22:49:42 +08:00
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
2014-10-23 18:39:11 +08:00
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
ShowContextMenu(activeResult);
|
2014-10-23 18:39:11 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-02 23:07:49 +08:00
|
|
|
|
SelectResult(activeResult);
|
2014-10-23 18:39:11 +08:00
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
2015-01-23 18:28:14 +08:00
|
|
|
|
|
|
|
|
|
case Key.D1:
|
|
|
|
|
SelectItem(1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D2:
|
|
|
|
|
SelectItem(2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D3:
|
|
|
|
|
SelectItem(3);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D4:
|
|
|
|
|
SelectItem(4);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D5:
|
|
|
|
|
SelectItem(5);
|
|
|
|
|
break;
|
|
|
|
|
case Key.D6:
|
|
|
|
|
SelectItem(6);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-09 19:16:13 +08:00
|
|
|
|
private void DisplayPrevQuery()
|
|
|
|
|
{
|
|
|
|
|
var prev = QueryHistoryStorage.Instance.Previous();
|
|
|
|
|
DisplayQueryHistory(prev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisplayNextQuery()
|
|
|
|
|
{
|
|
|
|
|
var nextQuery = QueryHistoryStorage.Instance.Next();
|
|
|
|
|
DisplayQueryHistory(nextQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DisplayQueryHistory(HistoryItem history)
|
|
|
|
|
{
|
|
|
|
|
if (history != null)
|
|
|
|
|
{
|
2015-11-08 10:50:33 +08:00
|
|
|
|
var historyMetadata = QueryHistoryStorage.MetaData;
|
2015-02-09 19:16:13 +08:00
|
|
|
|
ChangeQueryText(history.Query, true);
|
2015-02-09 22:14:38 +08:00
|
|
|
|
var executeQueryHistoryTitle = GetTranslation("executeQuery");
|
|
|
|
|
var lastExecuteTime = GetTranslation("lastExecuteTime");
|
2015-11-08 10:50:33 +08:00
|
|
|
|
pnlResult.RemoveResultsExcept(historyMetadata);
|
2015-02-09 19:16:13 +08:00
|
|
|
|
UpdateResultViewInternal(new List<Result>()
|
|
|
|
|
{
|
|
|
|
|
new Result(){
|
2015-02-09 22:14:38 +08:00
|
|
|
|
Title = string.Format(executeQueryHistoryTitle,history.Query),
|
|
|
|
|
SubTitle = string.Format(lastExecuteTime,history.ExecutedDateTime),
|
2015-02-09 19:16:13 +08:00
|
|
|
|
IcoPath = "Images\\history.png",
|
|
|
|
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
|
|
|
|
Action = _ =>{
|
|
|
|
|
ChangeQuery(history.Query,true);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-08 04:48:18 +08:00
|
|
|
|
}, historyMetadata);
|
2015-02-09 19:16:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 18:28:14 +08:00
|
|
|
|
private void SelectItem(int index)
|
|
|
|
|
{
|
|
|
|
|
int zeroBasedIndex = index - 1;
|
|
|
|
|
SpecialKeyState keyState = GlobalHotkey.Instance.CheckModifiers();
|
|
|
|
|
if (keyState.AltPressed || keyState.CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
List<Result> visibleResults = pnlResult.GetVisibleResults();
|
|
|
|
|
if (zeroBasedIndex < visibleResults.Count)
|
|
|
|
|
{
|
|
|
|
|
SelectResult(visibleResults[zeroBasedIndex]);
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 18:39:11 +08:00
|
|
|
|
private bool IsInContextMenuMode
|
|
|
|
|
{
|
|
|
|
|
get { return pnlContextMenu.Visibility == Visibility.Visible; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Result GetActiveResult()
|
|
|
|
|
{
|
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
return pnlContextMenu.GetActiveResult();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return pnlResult.GetActiveResult();
|
|
|
|
|
}
|
2015-01-02 23:07:49 +08:00
|
|
|
|
}
|
2014-10-23 18:39:11 +08:00
|
|
|
|
|
2014-08-19 15:21:26 +08:00
|
|
|
|
private void SelectPrevItem()
|
|
|
|
|
{
|
2014-10-23 18:39:11 +08:00
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
pnlContextMenu.SelectPrev();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pnlResult.SelectPrev();
|
|
|
|
|
}
|
2014-08-19 15:21:26 +08:00
|
|
|
|
toolTip.IsOpen = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectNextItem()
|
|
|
|
|
{
|
2014-10-23 18:39:11 +08:00
|
|
|
|
if (IsInContextMenuMode)
|
|
|
|
|
{
|
|
|
|
|
pnlContextMenu.SelectNext();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pnlResult.SelectNext();
|
|
|
|
|
}
|
2014-08-19 15:21:26 +08:00
|
|
|
|
toolTip.IsOpen = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 18:39:11 +08:00
|
|
|
|
private void SelectResult(Result result)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2014-10-23 18:39:11 +08:00
|
|
|
|
if (result != null)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (result.Action != null)
|
|
|
|
|
{
|
|
|
|
|
bool hideWindow = result.Action(new ActionContext()
|
|
|
|
|
{
|
2015-01-08 22:49:42 +08:00
|
|
|
|
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
2014-07-24 04:46:19 +08:00
|
|
|
|
});
|
|
|
|
|
if (hideWindow)
|
|
|
|
|
{
|
|
|
|
|
HideWox();
|
|
|
|
|
}
|
|
|
|
|
UserSelectedRecordStorage.Instance.Add(result);
|
2015-02-09 19:16:13 +08:00
|
|
|
|
QueryHistoryStorage.Instance.Add(tbQuery.Text);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-08 04:48:18 +08:00
|
|
|
|
private void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-11-07 11:50:26 +08:00
|
|
|
|
_queryHasReturn = true;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
progressBar.Dispatcher.Invoke(new Action(StopProgress));
|
|
|
|
|
|
2015-11-08 04:48:18 +08:00
|
|
|
|
list.ForEach(o =>
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-11-08 04:48:18 +08:00
|
|
|
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
|
|
|
|
});
|
|
|
|
|
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
|
|
|
|
{
|
|
|
|
|
UpdateResultViewInternal(list, metadata);
|
2014-10-23 18:39:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-08 04:48:18 +08:00
|
|
|
|
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
2015-11-08 04:48:18 +08:00
|
|
|
|
Dispatcher.Invoke(new Action(() =>
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
2015-11-08 04:48:18 +08:00
|
|
|
|
Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
|
|
|
|
() => { pnlResult.AddResults(list, metadata.ID); });
|
|
|
|
|
}));
|
2015-02-09 19:16:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-07 23:49:46 +08:00
|
|
|
|
private Result GetTopMostContextMenu(Result result)
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
return new Result(GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
|
|
|
|
Action = _ =>
|
|
|
|
|
{
|
|
|
|
|
TopMostRecordStorage.Instance.Remove(result);
|
|
|
|
|
ShowMsg("Succeed", "", "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-02-07 23:49:46 +08:00
|
|
|
|
};
|
2015-02-05 23:29:41 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-02-07 23:49:46 +08:00
|
|
|
|
return new Result(GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
|
|
|
|
Action = _ =>
|
|
|
|
|
{
|
2015-02-07 20:17:49 +08:00
|
|
|
|
TopMostRecordStorage.Instance.AddOrUpdate(result);
|
2015-02-05 23:29:41 +08:00
|
|
|
|
ShowMsg("Succeed", "", "");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-02-07 23:49:46 +08:00
|
|
|
|
};
|
2015-02-05 23:29:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-07 23:49:46 +08:00
|
|
|
|
private void ShowContextMenu(Result result)
|
2014-10-23 18:39:11 +08:00
|
|
|
|
{
|
2015-11-06 04:44:14 +08:00
|
|
|
|
List<Result> results = PluginManager.GetContextMenusForPlugin(result);
|
2015-02-07 23:49:46 +08:00
|
|
|
|
results.ForEach(o =>
|
2014-10-23 18:39:11 +08:00
|
|
|
|
{
|
2015-11-06 04:44:14 +08:00
|
|
|
|
o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory;
|
2015-02-07 23:49:46 +08:00
|
|
|
|
o.PluginID = result.PluginID;
|
|
|
|
|
o.OriginQuery = result.OriginQuery;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
results.Add(GetTopMostContextMenu(result));
|
|
|
|
|
|
|
|
|
|
textBeforeEnterContextMenuMode = tbQuery.Text;
|
|
|
|
|
ChangeQueryText("");
|
|
|
|
|
pnlContextMenu.Clear();
|
2015-11-08 04:48:18 +08:00
|
|
|
|
pnlContextMenu.AddResults(results, result.PluginID);
|
2015-02-07 23:49:46 +08:00
|
|
|
|
CurrentContextMenus = results;
|
|
|
|
|
pnlContextMenu.Visibility = Visibility.Visible;
|
|
|
|
|
pnlResult.Visibility = Visibility.Collapsed;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 13:09:51 +08:00
|
|
|
|
public bool ShellRun(string cmd, bool runAsAdministrator = false)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(cmd))
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
|
2014-10-24 13:09:51 +08:00
|
|
|
|
WindowsShellRun.Start(cmd, runAsAdministrator);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("couldnotStartCmd"), cmd);
|
2015-01-02 23:07:49 +08:00
|
|
|
|
ShowMsg(errorMsg, ex.Message, null);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MainWindow_OnDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
2015-01-08 22:49:42 +08:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
// Note that you can have more than one file.
|
2015-01-08 22:49:42 +08:00
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
if (files[0].ToLower().EndsWith(".wox"))
|
|
|
|
|
{
|
2014-12-27 12:34:51 +08:00
|
|
|
|
PluginManager.InstallPlugin(files[0]);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|