Tab: Now adds Next s Title to tbQuery

This commit is contained in:
Aaron Campf 2014-05-08 14:05:48 -07:00
parent b07d1b027c
commit 0b70c5225d

View File

@ -40,527 +40,467 @@ using Rectangle = System.Drawing.Rectangle;
using TextBox = System.Windows.Controls.TextBox; using TextBox = System.Windows.Controls.TextBox;
using ToolTip = System.Windows.Controls.ToolTip; using ToolTip = System.Windows.Controls.ToolTip;
namespace Wox namespace Wox {
{ public partial class MainWindow {
public partial class MainWindow
{ #region Properties
private static readonly object locker = new object();
public static bool initialized = false; private static readonly object locker = new object();
public static bool initialized = false;
private static readonly List<Result> waitShowResultList = new List<Result>();
private readonly GlobalHotkey globalHotkey = new GlobalHotkey(); private static readonly List<Result> waitShowResultList = new List<Result>();
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator()); private readonly GlobalHotkey globalHotkey = new GlobalHotkey();
private readonly Storyboard progressBarStoryboard = new Storyboard(); private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
private bool WinRStroked; private readonly Storyboard progressBarStoryboard = new Storyboard();
private NotifyIcon notifyIcon; private bool WinRStroked;
private bool queryHasReturn; private NotifyIcon notifyIcon;
private string lastQuery; private bool queryHasReturn;
private ToolTip toolTip = new ToolTip(); private string lastQuery;
public MainWindow() private ToolTip toolTip = new ToolTip();
{
InitializeComponent(); private bool isCMDMode = false;
initialized = true; private bool ignoreTextChange = false;
#endregion
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
this.AllowsTransparency = true; #region Public API
System.Net.WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); public void ChangeQuery(string query, bool requery = false) {
tbQuery.Text = query;
progressBar.ToolTip = toolTip; tbQuery.CaretIndex = tbQuery.Text.Length;
InitialTray(); if (requery) {
resultCtrl.OnMouseClickItem += AcceptSelect; TextBoxBase_OnTextChanged(null, null);
}
ThreadPool.SetMaxThreads(30, 10); }
try
{ public void CloseApp() {
SetTheme(UserSettingStorage.Instance.Theme); notifyIcon.Visible = false;
} Close();
catch (Exception) Environment.Exit(0);
{ }
SetTheme(UserSettingStorage.Instance.Theme = "Dark");
} public void HideApp() {
HideWox();
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); }
SetCustomPluginHotkey();
public void ShowApp() {
globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback; ShowWox();
}
this.Closing += MainWindow_Closing;
} public void ShowMsg(string title, string subTitle, string iconPath) {
var m = new Msg { Owner = GetWindow(this) };
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) m.Show(title, subTitle, iconPath);
{ }
this.HideWox();
e.Cancel = true; public void OpenSettingDialog() {
} WindowOpener.Open<SettingWindow>(this);
}
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{ public void ShowCurrentResultItemTooltip(string text) {
Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; toolTip.Content = text;
Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3; toolTip.IsOpen = true;
}
Plugins.Init();
public void StartLoadingBar() {
InitProgressbarAnimation(); Dispatcher.Invoke(new Action(StartProgress));
}
//only works for win7+
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.DWM) public void StopLoadingBar() {
DwmDropShadow.DropShadowToWindow(this); Dispatcher.Invoke(new Action(StopProgress));
}
this.Background = Brushes.Transparent;
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle).CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0); #endregion
WindowIntelopHelper.DisableControlBox(this); public MainWindow() {
} InitializeComponent();
initialized = true;
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
{ if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
var hotkey = new HotkeyModel(hotkeyStr); this.AllowsTransparency = true;
try
{ System.Net.WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
} progressBar.ToolTip = toolTip;
catch (Exception) InitialTray();
{ resultCtrl.OnMouseClickItem += AcceptSelect;
MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
} ThreadPool.SetMaxThreads(30, 10);
} try {
SetTheme(UserSettingStorage.Instance.Theme);
public void RemoveHotkey(string hotkeyStr) }
{ catch (Exception) {
if (!string.IsNullOrEmpty(hotkeyStr)) SetTheme(UserSettingStorage.Instance.Theme = "Dark");
{ }
HotkeyManager.Current.Remove(hotkeyStr);
} SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
} SetCustomPluginHotkey();
private void SetCustomPluginHotkey() globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
{
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return; this.Closing += MainWindow_Closing;
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys) }
{
CustomPluginHotkey hotkey1 = hotkey; void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
SetHotkey(hotkey.Hotkey, delegate this.HideWox();
{ e.Cancel = true;
ShowApp(); }
ChangeQuery(hotkey1.ActionKeyword, true);
}); private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) {
} Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
} Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3;
private void OnHotkey(object sender, HotkeyEventArgs e) Plugins.Init();
{
if (!IsVisible) InitProgressbarAnimation();
{
ShowWox(); //only works for win7+
} if (UserSettingStorage.Instance.OpacityMode == OpacityMode.DWM)
else DwmDropShadow.DropShadowToWindow(this);
{
HideWox(); this.Background = Brushes.Transparent;
} HwndSource.FromHwnd(new WindowInteropHelper(this).Handle).CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
e.Handled = true;
} WindowIntelopHelper.DisableControlBox(this);
}
private void InitProgressbarAnimation()
{ public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) {
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); var hotkey = new HotkeyModel(hotkeyStr);
var da1 = new DoubleAnimation(progressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); try {
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)")); HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)")); }
progressBarStoryboard.Children.Add(da); catch (Exception) {
progressBarStoryboard.Children.Add(da1); MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever; }
progressBar.Visibility = Visibility.Hidden; }
progressBar.BeginStoryboard(progressBarStoryboard);
} public void RemoveHotkey(string hotkeyStr) {
if (!string.IsNullOrEmpty(hotkeyStr)) {
private void InitialTray() HotkeyManager.Current.Remove(hotkeyStr);
{ }
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true }; }
notifyIcon.Click += (o, e) => ShowWox();
var open = new MenuItem("Open"); private void SetCustomPluginHotkey() {
open.Click += (o, e) => ShowWox(); if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
var setting = new MenuItem("Setting"); foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys) {
setting.Click += (o, e) => OpenSettingDialog(); CustomPluginHotkey hotkey1 = hotkey;
var exit = new MenuItem("Exit"); SetHotkey(hotkey.Hotkey, delegate {
exit.Click += (o, e) => CloseApp(); ShowApp();
MenuItem[] childen = { open, setting, exit }; ChangeQuery(hotkey1.ActionKeyword, true);
notifyIcon.ContextMenu = new ContextMenu(childen); });
} }
}
private bool isCMDMode = false;
private bool ignoreTextChange = false; private void OnHotkey(object sender, HotkeyEventArgs e) {
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) if (!IsVisible) {
{ ShowWox();
if (ignoreTextChange) { ignoreTextChange = false; return; } }
else {
lastQuery = tbQuery.Text; HideWox();
toolTip.IsOpen = false; }
resultCtrl.Dirty = true; e.Handled = true;
Dispatcher.DelayInvoke("UpdateSearch", }
o =>
{ private void InitProgressbarAnimation() {
Dispatcher.DelayInvoke("ClearResults", i => 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)));
// first try to use clear method inside resultCtrl, which is more closer to the add new results Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
// and this will not bring splash issues.After waiting 30ms, if there still no results added, we Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
// must clear the result. otherwise, it will be confused why the query changed, but the results progressBarStoryboard.Children.Add(da);
// didn't. progressBarStoryboard.Children.Add(da1);
if (resultCtrl.Dirty) resultCtrl.Clear(); progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
}, TimeSpan.FromMilliseconds(100), null); progressBar.Visibility = Visibility.Hidden;
var q = new Query(lastQuery); progressBar.BeginStoryboard(progressBarStoryboard);
CommandFactory.DispatchCommand(q); }
queryHasReturn = false;
if (Plugins.HitThirdpartyKeyword(q)) private void InitialTray() {
{ notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => notifyIcon.Click += (o, e) => ShowWox();
{ var open = new MenuItem("Open");
if (!queryHasReturn && originQuery == lastQuery) open.Click += (o, e) => ShowWox();
{ var setting = new MenuItem("Setting");
StartProgress(); setting.Click += (o, e) => OpenSettingDialog();
} var exit = new MenuItem("Exit");
}, TimeSpan.FromSeconds(0), lastQuery); exit.Click += (o, e) => CloseApp();
} MenuItem[] childen = { open, setting, exit };
}, TimeSpan.FromMilliseconds((isCMDMode = tbQuery.Text.StartsWith(">")) ? 0 : 150)); notifyIcon.ContextMenu = new ContextMenu(childen);
} }
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) {
{ if (ignoreTextChange) { ignoreTextChange = false; return; }
if (e.ChangedButton == MouseButton.Left) DragMove();
} lastQuery = tbQuery.Text;
toolTip.IsOpen = false;
private void StartProgress() resultCtrl.Dirty = true;
{ Dispatcher.DelayInvoke("UpdateSearch",
progressBar.Visibility = Visibility.Visible; o => {
} Dispatcher.DelayInvoke("ClearResults", i => {
// first try to use clear method inside resultCtrl, which is more closer to the add new results
private void StopProgress() // 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
progressBar.Visibility = Visibility.Hidden; // didn't.
} if (resultCtrl.Dirty) resultCtrl.Clear();
}, TimeSpan.FromMilliseconds(100), null);
private void HideWox() var q = new Query(lastQuery);
{ CommandFactory.DispatchCommand(q);
Hide(); queryHasReturn = false;
} if (Plugins.HitThirdpartyKeyword(q)) {
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => {
private void ShowWox(bool selectAll = true) if (!queryHasReturn && originQuery == lastQuery) {
{ StartProgress();
if (!double.IsNaN(Left) && !double.IsNaN(Top)) }
{ }, TimeSpan.FromSeconds(0), lastQuery);
var origScreen = Screen.FromRectangle(new Rectangle((int) Left, (int) Top, (int) ActualWidth, (int) ActualHeight)); }
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); }, TimeSpan.FromMilliseconds((isCMDMode = tbQuery.Text.StartsWith(">")) ? 0 : 150));
var coordX = (Left - origScreen.WorkingArea.Left)/(origScreen.WorkingArea.Width - ActualWidth); }
var coordY = (Top - origScreen.WorkingArea.Top)/(origScreen.WorkingArea.Height - ActualHeight);
Left = (screen.WorkingArea.Width - ActualWidth)*coordX + screen.WorkingArea.Left; private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) {
Top = (screen.WorkingArea.Height - ActualHeight)*coordY + screen.WorkingArea.Top; if (e.ChangedButton == MouseButton.Left) DragMove();
} }
Show(); private void StartProgress() {
Activate(); progressBar.Visibility = Visibility.Visible;
Focus(); }
tbQuery.Focus();
if (selectAll) tbQuery.SelectAll(); private void StopProgress() {
} progressBar.Visibility = Visibility.Hidden;
}
public void ParseArgs(string[] args)
{ private void HideWox() {
if (args != null && args.Length > 0) Hide();
{ }
switch (args[0].ToLower())
{ private void ShowWox(bool selectAll = true) {
case "reloadplugin": if (!double.IsNaN(Left) && !double.IsNaN(Top)) {
Plugins.Init(); var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
break; var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
case "query": var coordY = (Top - origScreen.WorkingArea.Top) / (origScreen.WorkingArea.Height - ActualHeight);
if (args.Length > 1) Left = (screen.WorkingArea.Width - ActualWidth) * coordX + screen.WorkingArea.Left;
{ Top = (screen.WorkingArea.Height - ActualHeight) * coordY + screen.WorkingArea.Top;
string query = args[1]; }
tbQuery.Text = query;
tbQuery.SelectAll(); Show();
} Activate();
break; Focus();
tbQuery.Focus();
case "hidestart": if (selectAll) tbQuery.SelectAll();
HideApp(); }
break;
public void ParseArgs(string[] args) {
case "installplugin": if (args != null && args.Length > 0) {
var path = args[1]; switch (args[0].ToLower()) {
if (!File.Exists(path)) case "reloadplugin":
{ Plugins.Init();
MessageBox.Show("Plugin " + path + " didn't exist"); break;
return;
} case "query":
PluginInstaller.Install(path); if (args.Length > 1) {
break; string query = args[1];
} tbQuery.Text = query;
} tbQuery.SelectAll();
} }
break;
private void MainWindow_OnDeactivated(object sender, EventArgs e)
{ case "hidestart":
if (UserSettingStorage.Instance.HideWhenDeactive) HideApp();
{ break;
HideWox();
} case "installplugin":
} var path = args[1];
if (!File.Exists(path)) {
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) MessageBox.Show("Plugin " + path + " didn't exist");
{ return;
if (UserSettingStorage.Instance.ReplaceWinR) }
{ PluginInstaller.Install(path);
//todo:need refatoring. move those codes to CMD file or expose events break;
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) }
{ }
WinRStroked = true; }
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
return false; private void MainWindow_OnDeactivated(object sender, EventArgs e) {
} if (UserSettingStorage.Instance.HideWhenDeactive) {
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) HideWox();
{ }
WinRStroked = false; }
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
return false; private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) {
} if (UserSettingStorage.Instance.ReplaceWinR) {
} //todo:need refatoring. move those codes to CMD file or expose events
return true; if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) {
} WinRStroked = true;
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
private void OnWinRPressed() return false;
{ }
ShowWox(false); if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) {
if (!tbQuery.Text.StartsWith(">")) WinRStroked = false;
{ keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
resultCtrl.Clear(); return false;
ChangeQuery(">"); }
} }
tbQuery.CaretIndex = tbQuery.Text.Length; return true;
tbQuery.SelectionStart = 1; }
tbQuery.SelectionLength = tbQuery.Text.Length - 1;
} private void OnWinRPressed() {
ShowWox(false);
private void updateCmdMode() if (!tbQuery.Text.StartsWith(">")) {
{ resultCtrl.Clear();
var selected = resultCtrl.AcceptSelect(); ChangeQuery(">");
if (selected != null) }
{ tbQuery.CaretIndex = tbQuery.Text.Length;
ignoreTextChange = true; tbQuery.SelectionStart = 1;
tbQuery.Text = ">" + selected.Title; tbQuery.SelectionLength = tbQuery.Text.Length - 1;
tbQuery.CaretIndex = tbQuery.Text.Length; }
}
} private void updateCmdMode() {
var selected = resultCtrl.AcceptSelect();
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) if (selected != null) {
{ ignoreTextChange = true;
//when alt is pressed, the real key should be e.SystemKey tbQuery.Text = ">" + selected.Title;
Key key = (e.Key == Key.System ? e.SystemKey : e.Key); tbQuery.CaretIndex = tbQuery.Text.Length;
switch (key) }
{ }
case Key.Escape:
HideWox(); private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) {
e.Handled = true; //when alt is pressed, the real key should be e.SystemKey
break; Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
switch (key) {
case Key.Down: case Key.Escape:
resultCtrl.SelectNext(); HideWox();
if (isCMDMode) updateCmdMode(); e.Handled = true;
toolTip.IsOpen = false; break;
e.Handled = true;
break; case Key.Down:
resultCtrl.SelectNext();
case Key.Up: if (isCMDMode) updateCmdMode();
resultCtrl.SelectPrev(); toolTip.IsOpen = false;
if (isCMDMode) updateCmdMode(); e.Handled = true;
toolTip.IsOpen = false; break;
e.Handled = true;
break; case Key.Up:
resultCtrl.SelectPrev();
case Key.PageDown: if (isCMDMode) updateCmdMode();
resultCtrl.SelectNextPage(); toolTip.IsOpen = false;
if (isCMDMode) updateCmdMode(); e.Handled = true;
toolTip.IsOpen = false; break;
e.Handled = true;
break; case Key.PageDown:
resultCtrl.SelectNextPage();
case Key.PageUp: if (isCMDMode) updateCmdMode();
resultCtrl.SelectPrevPage(); toolTip.IsOpen = false;
if (isCMDMode) updateCmdMode(); e.Handled = true;
toolTip.IsOpen = false; break;
e.Handled = true;
break; case Key.PageUp:
resultCtrl.SelectPrevPage();
case Key.Enter: if (isCMDMode) updateCmdMode();
AcceptSelect(resultCtrl.AcceptSelect()); toolTip.IsOpen = false;
e.Handled = true; e.Handled = true;
break; break;
}
} case Key.Enter:
AcceptSelect(resultCtrl.AcceptSelect());
private void AcceptSelect(Result result) e.Handled = true;
{ break;
if (!resultCtrl.Dirty && result != null)
{ case Key.Tab:
if (result.Action != null) var SelectedItem = resultCtrl.lbResults.SelectedItem as Wox.Plugin.Result;
{ if (SelectedItem != null) {
bool hideWindow = result.Action(new ActionContext() if (tbQuery.Text.Contains("\\")) {
{ var index = tbQuery.Text.LastIndexOf("\\");
SpecialKeyState = new GlobalHotkey().CheckModifiers() tbQuery.Text = tbQuery.Text.Remove(index) + "\\";
}); }
if (hideWindow)
{ tbQuery.Text += SelectedItem.Title;
HideWox(); tbQuery.CaretIndex = int.MaxValue;
} }
UserSelectedRecordStorage.Instance.Add(result);
} e.Handled = true;
} break;
} }
}
public void OnUpdateResultView(List<Result> list)
{ private void AcceptSelect(Result result) {
if (list == null) return; if (!resultCtrl.Dirty && result != null) {
if (result.Action != null) {
queryHasReturn = true; bool hideWindow = result.Action(new ActionContext() {
progressBar.Dispatcher.Invoke(new Action(StopProgress)); SpecialKeyState = new GlobalHotkey().CheckModifiers()
if (list.Count > 0) });
{ if (hideWindow) {
//todo:this should be opened to users, it's their choise to use it or not in thier workflows HideWox();
list.ForEach( }
o => UserSelectedRecordStorage.Instance.Add(result);
{ }
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o); }
}); }
lock (locker)
{ public void OnUpdateResultView(List<Result> list) {
waitShowResultList.AddRange(list); if (list == null) return;
}
Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => queryHasReturn = true;
{ progressBar.Dispatcher.Invoke(new Action(StopProgress));
List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); if (list.Count > 0) {
waitShowResultList.Clear(); //todo:this should be opened to users, it's their choise to use it or not in thier workflows
resultCtrl.AddResults(l); list.ForEach(
})), TimeSpan.FromMilliseconds(isCMDMode ? 0 : 50)); o => {
} if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
} });
lock (locker) {
public void SetTheme(string themeName) waitShowResultList.AddRange(list);
{ }
var dict = new ResourceDictionary Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => {
{ List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) waitShowResultList.Clear();
}; resultCtrl.AddResults(l);
})), TimeSpan.FromMilliseconds(isCMDMode ? 0 : 50));
}
Style queryBoxStyle = dict["QueryBoxStyle"] as Style; }
if (queryBoxStyle != null)
{ public void SetTheme(string themeName) {
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont))); var dict = new ResourceDictionary {
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle))); Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight))); };
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
}
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
Style resultItemStyle = dict["ItemTitleStyle"] as Style; if (queryBoxStyle != null) {
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
if (resultItemStyle != null && resultSubItemStyle != null queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
&& resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) }
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont)); Style resultItemStyle = dict["ItemTitleStyle"] as Style;
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle)); Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight)); Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch)); Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) {
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch }; Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
} Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch));
Application.Current.Resources.MergedDictionaries.Clear();
Application.Current.Resources.MergedDictionaries.Add(dict); Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
if (this.AllowsTransparency) }
this.Opacity = UserSettingStorage.Instance.Opacity;
else Application.Current.Resources.MergedDictionaries.Clear();
this.Opacity = 1; Application.Current.Resources.MergedDictionaries.Add(dict);
}
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
#region Public API }
public void ChangeQuery(string query, bool requery = false) public bool ShellRun(string cmd) {
{ try {
tbQuery.Text = query; if (string.IsNullOrEmpty(cmd))
tbQuery.CaretIndex = tbQuery.Text.Length; throw new ArgumentNullException();
if (requery)
{ Wox.Infrastructure.WindowsShellRun.Start(cmd);
TextBoxBase_OnTextChanged(null, null); return true;
} }
} catch (Exception ex) {
ShowMsg("Could not start " + cmd, ex.Message, null);
public void CloseApp() }
{ return false;
notifyIcon.Visible = false; }
Close();
Environment.Exit(0); }
}
public void HideApp()
{
HideWox();
}
public void ShowApp()
{
ShowWox();
}
public void ShowMsg(string title, string subTitle, string iconPath)
{
var m = new Msg { Owner = GetWindow(this) };
m.Show(title, subTitle, iconPath);
}
public void OpenSettingDialog()
{
WindowOpener.Open<SettingWindow>(this);
}
public void ShowCurrentResultItemTooltip(string text)
{
toolTip.Content = text;
toolTip.IsOpen = true;
}
public void StartLoadingBar()
{
Dispatcher.Invoke(new Action(StartProgress));
}
public void StopLoadingBar()
{
Dispatcher.Invoke(new Action(StopProgress));
}
#endregion
public bool ShellRun(string cmd)
{
try
{
if (string.IsNullOrEmpty(cmd))
throw new ArgumentNullException();
Wox.Infrastructure.WindowsShellRun.Start(cmd);
return true;
}
catch (Exception ex)
{
ShowMsg("Could not start " + cmd, ex.Message, null);
}
return false;
}
}
} }