Finally Fixed AutoFormatting

This commit is contained in:
Aaron Campf
2014-07-23 13:46:19 -07:00
parent 0982e12a80
commit 6820a05efc

View File

@@ -35,8 +35,10 @@ 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 : IPublicAPI { {
public partial class MainWindow : IPublicAPI
{
#region Properties #region Properties
@@ -58,67 +60,84 @@ namespace Wox {
#region Public API #region Public API
public void ChangeQuery(string query, bool requery = false) { public void ChangeQuery(string query, bool requery = false)
Dispatcher.Invoke(new Action(() => { {
Dispatcher.Invoke(new Action(() =>
{
tbQuery.Text = query; tbQuery.Text = query;
tbQuery.CaretIndex = tbQuery.Text.Length; tbQuery.CaretIndex = tbQuery.Text.Length;
if (requery) { if (requery)
{
TextBoxBase_OnTextChanged(null, null); TextBoxBase_OnTextChanged(null, null);
} }
})); }));
} }
public void CloseApp() { public void CloseApp()
Dispatcher.Invoke(new Action(() => { {
Dispatcher.Invoke(new Action(() =>
{
notifyIcon.Visible = false; notifyIcon.Visible = false;
Close(); Close();
Environment.Exit(0); Environment.Exit(0);
})); }));
} }
public void HideApp() { public void HideApp()
{
Dispatcher.Invoke(new Action(HideWox)); Dispatcher.Invoke(new Action(HideWox));
} }
public void ShowApp() { public void ShowApp()
{
Dispatcher.Invoke(new Action(() => ShowWox())); Dispatcher.Invoke(new Action(() => ShowWox()));
} }
public void ShowMsg(string title, string subTitle, string iconPath) { public void ShowMsg(string title, string subTitle, string iconPath)
Dispatcher.Invoke(new Action(() => { {
Dispatcher.Invoke(new Action(() =>
{
var m = new Msg { Owner = GetWindow(this) }; var m = new Msg { Owner = GetWindow(this) };
m.Show(title, subTitle, iconPath); m.Show(title, subTitle, iconPath);
})); }));
} }
public void OpenSettingDialog() { public void OpenSettingDialog()
{
Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this))); Dispatcher.Invoke(new Action(() => WindowOpener.Open<SettingWindow>(this)));
} }
public void StartLoadingBar() { public void StartLoadingBar()
{
Dispatcher.Invoke(new Action(StartProgress)); Dispatcher.Invoke(new Action(StartProgress));
} }
public void StopLoadingBar() { public void StopLoadingBar()
{
Dispatcher.Invoke(new Action(StopProgress)); Dispatcher.Invoke(new Action(StopProgress));
} }
public void InstallPlugin(string path) { public void InstallPlugin(string path)
{
Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path))); Dispatcher.Invoke(new Action(() => PluginInstaller.Install(path)));
} }
public void ReloadPlugins() { public void ReloadPlugins()
{
Dispatcher.Invoke(new Action(Plugins.Init)); Dispatcher.Invoke(new Action(Plugins.Init));
} }
public List<PluginPair> GetAllPlugins() { public List<PluginPair> GetAllPlugins()
{
return Plugins.AllPlugins; return Plugins.AllPlugins;
} }
public event WoxKeyDownEventHandler BackKeyDownEvent; public event WoxKeyDownEventHandler BackKeyDownEvent;
public void PushResults(Query query, PluginMetadata plugin, List<Result> results) { public void PushResults(Query query, PluginMetadata plugin, List<Result> results)
results.ForEach(o => { {
results.ForEach(o =>
{
o.PluginDirectory = plugin.PluginDirectory; o.PluginDirectory = plugin.PluginDirectory;
o.OriginQuery = query; o.OriginQuery = query;
}); });
@@ -128,7 +147,8 @@ namespace Wox {
#endregion #endregion
public MainWindow() { public MainWindow()
{
InitializeComponent(); InitializeComponent();
if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow) if (UserSettingStorage.Instance.OpacityMode == OpacityMode.LayeredWindow)
@@ -141,10 +161,12 @@ namespace Wox {
resultCtrl.OnMouseClickItem += AcceptSelect; resultCtrl.OnMouseClickItem += AcceptSelect;
ThreadPool.SetMaxThreads(30, 10); ThreadPool.SetMaxThreads(30, 10);
try { try
{
SetTheme(UserSettingStorage.Instance.Theme); SetTheme(UserSettingStorage.Instance.Theme);
} }
catch (Exception) { catch (Exception)
{
SetTheme(UserSettingStorage.Instance.Theme = "Dark"); SetTheme(UserSettingStorage.Instance.Theme = "Dark");
} }
@@ -156,7 +178,8 @@ namespace Wox {
this.Closing += MainWindow_Closing; this.Closing += MainWindow_Closing;
} }
void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
UserSettingStorage.Instance.WindowLeft = Left; UserSettingStorage.Instance.WindowLeft = Left;
UserSettingStorage.Instance.WindowTop = Top; UserSettingStorage.Instance.WindowTop = Top;
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
@@ -164,15 +187,18 @@ namespace Wox {
e.Cancel = true; e.Cancel = true;
} }
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
if (UserSettingStorage.Instance.WindowLeft == 0 if (UserSettingStorage.Instance.WindowLeft == 0
&& UserSettingStorage.Instance.WindowTop == 0) { && UserSettingStorage.Instance.WindowTop == 0)
{
Left = UserSettingStorage.Instance.WindowLeft Left = UserSettingStorage.Instance.WindowLeft
= (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2;
Top = UserSettingStorage.Instance.WindowTop Top = UserSettingStorage.Instance.WindowTop
= (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5; = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 5;
} }
else { else
{
Left = UserSettingStorage.Instance.WindowLeft; Left = UserSettingStorage.Instance.WindowLeft;
Top = UserSettingStorage.Instance.WindowTop; Top = UserSettingStorage.Instance.WindowTop;
} }
@@ -191,44 +217,56 @@ namespace Wox {
WindowIntelopHelper.DisableControlBox(this); WindowIntelopHelper.DisableControlBox(this);
} }
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) { public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)
{
var hotkey = new HotkeyModel(hotkeyStr); var hotkey = new HotkeyModel(hotkeyStr);
try { try
{
HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action); HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action);
} }
catch (Exception) { catch (Exception)
{
MessageBox.Show("Register hotkey: " + hotkeyStr + " failed."); MessageBox.Show("Register hotkey: " + hotkeyStr + " failed.");
} }
} }
public void RemoveHotkey(string hotkeyStr) { public void RemoveHotkey(string hotkeyStr)
if (!string.IsNullOrEmpty(hotkeyStr)) { {
if (!string.IsNullOrEmpty(hotkeyStr))
{
HotkeyManager.Current.Remove(hotkeyStr); HotkeyManager.Current.Remove(hotkeyStr);
} }
} }
private void SetCustomPluginHotkey() { private void SetCustomPluginHotkey()
{
if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return; if (UserSettingStorage.Instance.CustomPluginHotkeys == null) return;
foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys) { foreach (CustomPluginHotkey hotkey in UserSettingStorage.Instance.CustomPluginHotkeys)
{
CustomPluginHotkey hotkey1 = hotkey; CustomPluginHotkey hotkey1 = hotkey;
SetHotkey(hotkey.Hotkey, delegate { SetHotkey(hotkey.Hotkey, delegate
{
ShowApp(); ShowApp();
ChangeQuery(hotkey1.ActionKeyword, true); ChangeQuery(hotkey1.ActionKeyword, true);
}); });
} }
} }
private void OnHotkey(object sender, HotkeyEventArgs e) { private void OnHotkey(object sender, HotkeyEventArgs e)
if (!IsVisible) { {
if (!IsVisible)
{
ShowWox(); ShowWox();
} }
else { else
{
HideWox(); HideWox();
} }
e.Handled = true; e.Handled = true;
} }
private void InitProgressbarAnimation() { private void InitProgressbarAnimation()
{
var da = new DoubleAnimation(progressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600))); 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))); 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(da, new PropertyPath("(Line.X2)"));
@@ -240,7 +278,8 @@ namespace Wox {
progressBar.BeginStoryboard(progressBarStoryboard); progressBar.BeginStoryboard(progressBarStoryboard);
} }
private void InitialTray() { private void InitialTray()
{
notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true }; notifyIcon = new NotifyIcon { Text = "Wox", Icon = Properties.Resources.app, Visible = true };
notifyIcon.Click += (o, e) => ShowWox(); notifyIcon.Click += (o, e) => ShowWox();
var open = new MenuItem("Open"); var open = new MenuItem("Open");
@@ -253,15 +292,18 @@ namespace Wox {
notifyIcon.ContextMenu = new ContextMenu(childen); notifyIcon.ContextMenu = new ContextMenu(childen);
} }
private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) { private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e)
{
if (ignoreTextChange) { ignoreTextChange = false; return; } if (ignoreTextChange) { ignoreTextChange = false; return; }
lastQuery = tbQuery.Text; lastQuery = tbQuery.Text;
toolTip.IsOpen = false; toolTip.IsOpen = false;
resultCtrl.Dirty = true; resultCtrl.Dirty = true;
Dispatcher.DelayInvoke("UpdateSearch", Dispatcher.DelayInvoke("UpdateSearch",
o => { o =>
Dispatcher.DelayInvoke("ClearResults", i => { {
Dispatcher.DelayInvoke("ClearResults", i =>
{
// first try to use clear method inside resultCtrl, which is more closer to the add new results // 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 // 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 // must clear the result. otherwise, it will be confused why the query changed, but the results
@@ -271,31 +313,41 @@ namespace Wox {
queryHasReturn = false; queryHasReturn = false;
var q = new Query(lastQuery); var q = new Query(lastQuery);
CommandFactory.DispatchCommand(q); CommandFactory.DispatchCommand(q);
if (Plugins.HitThirdpartyKeyword(q)) { if (Plugins.HitThirdpartyKeyword(q))
Dispatcher.DelayInvoke("ShowProgressbar", originQuery => { {
if (!queryHasReturn && originQuery == lastQuery) { Dispatcher.DelayInvoke("ShowProgressbar", originQuery =>
{
if (!queryHasReturn && originQuery == lastQuery)
{
StartProgress(); StartProgress();
} }
}, TimeSpan.FromSeconds(0), lastQuery); }, TimeSpan.FromSeconds(0), lastQuery);
} }
}, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150)); }, TimeSpan.FromMilliseconds(ShouldNotDelayQuery ? 0 : 150));
} }
private bool ShouldNotDelayQuery { private bool ShouldNotDelayQuery
get { {
return (bool)Dispatcher.Invoke(new Func<bool>(() => { get
{
return (bool)Dispatcher.Invoke(new Func<bool>(() =>
{
return IsCMDMode || IsWebSearchMode; return IsCMDMode || IsWebSearchMode;
})); }));
} }
} }
private bool IsCMDMode { private bool IsCMDMode
get { {
get
{
return tbQuery.Text.StartsWith(">"); return tbQuery.Text.StartsWith(">");
} }
} }
private bool IsWebSearchMode { private bool IsWebSearchMode
get { {
get
{
Query q = new Query(tbQuery.Text); Query q = new Query(tbQuery.Text);
return !UserSettingStorage.Instance.EnableWebSearchSuggestion && return !UserSettingStorage.Instance.EnableWebSearchSuggestion &&
UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == q.ActionName && o.Enabled); UserSettingStorage.Instance.WebSearches.Exists(o => o.ActionWord == q.ActionName && o.Enabled);
@@ -303,24 +355,30 @@ namespace Wox {
} }
private void Border_OnMouseDown(object sender, MouseButtonEventArgs e) { private void Border_OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) DragMove(); if (e.ChangedButton == MouseButton.Left) DragMove();
} }
private void StartProgress() { private void StartProgress()
{
progressBar.Visibility = Visibility.Visible; progressBar.Visibility = Visibility.Visible;
} }
private void StopProgress() { private void StopProgress()
{
progressBar.Visibility = Visibility.Hidden; progressBar.Visibility = Visibility.Hidden;
} }
private void HideWox() { private void HideWox()
{
Hide(); Hide();
} }
private void ShowWox(bool selectAll = true) { private void ShowWox(bool selectAll = true)
if (!double.IsNaN(Left) && !double.IsNaN(Top)) { {
if (!double.IsNaN(Left) && !double.IsNaN(Top))
{
var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight)); var origScreen = Screen.FromRectangle(new Rectangle((int)Left, (int)Top, (int)ActualWidth, (int)ActualHeight));
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position); var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth); var coordX = (Left - origScreen.WorkingArea.Left) / (origScreen.WorkingArea.Width - ActualWidth);
@@ -336,15 +394,19 @@ namespace Wox {
if (selectAll) tbQuery.SelectAll(); if (selectAll) tbQuery.SelectAll();
} }
public void ParseArgs(string[] args) { public void ParseArgs(string[] args)
if (args != null && args.Length > 0) { {
switch (args[0].ToLower()) { if (args != null && args.Length > 0)
{
switch (args[0].ToLower())
{
case "reloadplugin": case "reloadplugin":
Plugins.Init(); Plugins.Init();
break; break;
case "query": case "query":
if (args.Length > 1) { if (args.Length > 1)
{
string query = args[1]; string query = args[1];
tbQuery.Text = query; tbQuery.Text = query;
tbQuery.SelectAll(); tbQuery.SelectAll();
@@ -357,7 +419,8 @@ namespace Wox {
case "installplugin": case "installplugin":
var path = args[1]; var path = args[1];
if (!File.Exists(path)) { if (!File.Exists(path))
{
MessageBox.Show("Plugin " + path + " didn't exist"); MessageBox.Show("Plugin " + path + " didn't exist");
return; return;
} }
@@ -367,21 +430,27 @@ namespace Wox {
} }
} }
private void MainWindow_OnDeactivated(object sender, EventArgs e) { private void MainWindow_OnDeactivated(object sender, EventArgs e)
if (UserSettingStorage.Instance.HideWhenDeactive) { {
if (UserSettingStorage.Instance.HideWhenDeactive)
{
HideWox(); HideWox();
} }
} }
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) { private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
if (UserSettingStorage.Instance.ReplaceWinR) { {
if (UserSettingStorage.Instance.ReplaceWinR)
{
//todo:need refactoring. move those codes to CMD file or expose events //todo:need refactoring. move those codes to CMD file or expose events
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) { if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
{
WinRStroked = true; WinRStroked = true;
Dispatcher.BeginInvoke(new Action(OnWinRPressed)); Dispatcher.BeginInvoke(new Action(OnWinRPressed));
return false; return false;
} }
if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin) { if (keyevent == KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
{
WinRStroked = false; WinRStroked = false;
keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL); keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
return false; return false;
@@ -390,9 +459,11 @@ namespace Wox {
return true; return true;
} }
private void OnWinRPressed() { private void OnWinRPressed()
{
ShowWox(false); ShowWox(false);
if (!tbQuery.Text.StartsWith(">")) { if (!tbQuery.Text.StartsWith(">"))
{
resultCtrl.Clear(); resultCtrl.Clear();
ChangeQuery(">"); ChangeQuery(">");
} }
@@ -401,19 +472,23 @@ namespace Wox {
tbQuery.SelectionLength = tbQuery.Text.Length - 1; tbQuery.SelectionLength = tbQuery.Text.Length - 1;
} }
private void updateCmdMode() { private void updateCmdMode()
{
var currentSelectedItem = resultCtrl.GetActiveResult(); var currentSelectedItem = resultCtrl.GetActiveResult();
if (currentSelectedItem != null) { if (currentSelectedItem != null)
{
ignoreTextChange = true; ignoreTextChange = true;
tbQuery.Text = ">" + currentSelectedItem.Title; tbQuery.Text = ">" + currentSelectedItem.Title;
tbQuery.CaretIndex = tbQuery.Text.Length; tbQuery.CaretIndex = tbQuery.Text.Length;
} }
} }
private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e) { private void TbQuery_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
//when alt is pressed, the real key should be e.SystemKey //when alt is pressed, the real key should be e.SystemKey
Key key = (e.Key == Key.System ? e.SystemKey : e.Key); Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
switch (key) { switch (key)
{
case Key.Escape: case Key.Escape:
HideWox(); HideWox();
e.Handled = true; e.Handled = true;
@@ -448,8 +523,10 @@ namespace Wox {
break; break;
case Key.Back: case Key.Back:
if (BackKeyDownEvent != null) { if (BackKeyDownEvent != null)
BackKeyDownEvent(tbQuery, new WoxKeyDownEventArgs() { {
BackKeyDownEvent(tbQuery, new WoxKeyDownEventArgs()
{
Query = tbQuery.Text, Query = tbQuery.Text,
keyEventArgs = e keyEventArgs = e
}); });
@@ -464,13 +541,18 @@ namespace Wox {
} }
} }
private void AcceptSelect(Result result) { private void AcceptSelect(Result result)
if (!resultCtrl.Dirty && result != null) { {
if (result.Action != null) { if (!resultCtrl.Dirty && result != null)
bool hideWindow = result.Action(new ActionContext() { {
if (result.Action != null)
{
bool hideWindow = result.Action(new ActionContext()
{
SpecialKeyState = new GlobalHotkey().CheckModifiers() SpecialKeyState = new GlobalHotkey().CheckModifiers()
}); });
if (hideWindow) { if (hideWindow)
{
HideWox(); HideWox();
} }
UserSelectedRecordStorage.Instance.Add(result); UserSelectedRecordStorage.Instance.Add(result);
@@ -478,21 +560,26 @@ namespace Wox {
} }
} }
public void OnUpdateResultView(List<Result> list) { public void OnUpdateResultView(List<Result> list)
{
queryHasReturn = true; queryHasReturn = true;
progressBar.Dispatcher.Invoke(new Action(StopProgress)); progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list == null || list.Count == 0) return; if (list == null || list.Count == 0) return;
if (list.Count > 0) { if (list.Count > 0)
{
//todo:this should be opened to users, it's their choice to use it or not in their workflows //todo:this should be opened to users, it's their choice to use it or not in their workflows
list.ForEach( list.ForEach(
o => { o =>
{
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o); if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);
}); });
lock (locker) { lock (locker)
{
waitShowResultList.AddRange(list); waitShowResultList.AddRange(list);
} }
Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() => { Dispatcher.DelayInvoke("ShowResult", k => resultCtrl.Dispatcher.Invoke(new Action(() =>
{
List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList(); List<Result> l = waitShowResultList.Where(o => o.OriginQuery != null && o.OriginQuery.RawQuery == lastQuery).ToList();
waitShowResultList.Clear(); waitShowResultList.Clear();
resultCtrl.AddResults(l); resultCtrl.AddResults(l);
@@ -500,14 +587,17 @@ namespace Wox {
} }
} }
public void SetTheme(string themeName) { public void SetTheme(string themeName)
var dict = new ResourceDictionary { {
var dict = new ResourceDictionary
{
Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute)
}; };
Style queryBoxStyle = dict["QueryBoxStyle"] as Style; Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
if (queryBoxStyle != null) { if (queryBoxStyle != null)
{
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
@@ -518,7 +608,8 @@ namespace Wox {
Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style;
Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style;
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) { if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
{
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont)); Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont));
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle)); Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle));
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight)); Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight));
@@ -534,34 +625,42 @@ namespace Wox {
this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1; this.Opacity = this.AllowsTransparency ? UserSettingStorage.Instance.Opacity : 1;
} }
public bool ShellRun(string cmd) { public bool ShellRun(string cmd)
try { {
try
{
if (string.IsNullOrEmpty(cmd)) if (string.IsNullOrEmpty(cmd))
throw new ArgumentNullException(); throw new ArgumentNullException();
Wox.Infrastructure.WindowsShellRun.Start(cmd); Wox.Infrastructure.WindowsShellRun.Start(cmd);
return true; return true;
} }
catch (Exception ex) { catch (Exception ex)
{
ShowMsg("Could not start " + cmd, ex.Message, null); ShowMsg("Could not start " + cmd, ex.Message, null);
} }
return false; return false;
} }
private void MainWindow_OnDrop(object sender, DragEventArgs e) { private void MainWindow_OnDrop(object sender, DragEventArgs e)
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) { {
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
{
// Note that you can have more than one file. // Note that you can have more than one file.
string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop); string[] files = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
if (files[0].ToLower().EndsWith(".wox")) { if (files[0].ToLower().EndsWith(".wox"))
{
PluginInstaller.Install(files[0]); PluginInstaller.Install(files[0]);
} }
else { else
{
MessageBox.Show("incorrect wox plugin file."); MessageBox.Show("incorrect wox plugin file.");
} }
} }
} }
private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e) { private void TbQuery_OnPreviewDragOver(object sender, DragEventArgs e)
{
e.Handled = true; e.Handled = true;
} }
} }