Fix dependency bugs

This commit is contained in:
Colin Liu 2016-02-12 17:20:46 +08:00
parent 2d4d7b80c1
commit ca3bedc9a1
9 changed files with 191 additions and 139 deletions

View File

@ -11,8 +11,14 @@ namespace Wox.CommandArgs
public void Execute(IList<string> args) public void Execute(IList<string> args)
{ {
//TODO: Add ToggleWox Method if (App.Window.IsVisible)
//App.API.ToggleWox(); {
App.API.HideApp();
}
else
{
App.API.ShowApp();
}
} }
} }
} }

View File

@ -48,6 +48,8 @@
<KeyBinding Key="D4" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="3"></KeyBinding> <KeyBinding Key="D4" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="3"></KeyBinding>
<KeyBinding Key="D5" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="4"></KeyBinding> <KeyBinding Key="D5" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="4"></KeyBinding>
<KeyBinding Key="D6" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="5"></KeyBinding> <KeyBinding Key="D6" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="5"></KeyBinding>
<KeyBinding Key="Back" Command="{Binding BackCommand}"></KeyBinding>
</Window.InputBindings> </Window.InputBindings>
<Window.Resources> <Window.Resources>
<DataTemplate DataType="{x:Type vm:ResultPanelViewModel}"> <DataTemplate DataType="{x:Type vm:ResultPanelViewModel}">

View File

@ -64,12 +64,46 @@ namespace Wox
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language); InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
Left = GetWindowsLeft();
Top = GetWindowsTop();
InitProgressbarAnimation(); InitProgressbarAnimation();
WindowIntelopHelper.DisableControlBox(this); WindowIntelopHelper.DisableControlBox(this);
CheckUpdate(); CheckUpdate();
var vm = this.DataContext as MainViewModel;
vm.PropertyChanged += (o, eve) =>
{
if(eve.PropertyName == "SelectAllText")
{
if (vm.SelectAllText)
{
this.tbQuery.SelectAll();
}
}
else if(eve.PropertyName == "CaretIndex")
{
this.tbQuery.CaretIndex = vm.CaretIndex;
}
else if(eve.PropertyName == "Left")
{
this.Left = vm.Left;
}
else if(eve.PropertyName == "Top")
{
this.Top = vm.Top;
}
else if(eve.PropertyName == "IsVisible")
{
if (vm.IsVisible)
{
this.tbQuery.Focus();
}
}
};
vm.Left = GetWindowsLeft();
vm.Top = GetWindowsTop();
this.Activate();
this.Focus();
this.tbQuery.Focus();
} }
private double GetWindowsLeft() private double GetWindowsLeft()
@ -135,14 +169,13 @@ namespace Wox
{ {
if (UserSettingStorage.Instance.HideWhenDeactive) if (UserSettingStorage.Instance.HideWhenDeactive)
{ {
//TODO:Hide the window when deactivated App.API.HideApp();
//HideWox();
} }
} }
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{ {
//The code here is to supress the conflict of Window.InputBinding and ListBox native Down/Up Key handle //The code here is to supress the conflict of Window.InputBinding and ListBox/TextBox native Key handle
var vm = this.DataContext as MainViewModel; var vm = this.DataContext as MainViewModel;
//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);
@ -179,21 +212,12 @@ namespace Wox
vm.SelectPrevPageCommand.Execute(null); vm.SelectPrevPageCommand.Execute(null);
e.Handled = true; e.Handled = true;
break; break;
case Key.Back:
vm.BackCommand.Execute(e);
break;
} }
} }
//TODO: Colin - Figure out how to raise BackKeyDownEvent?
// case Key.Back:
// if (BackKeyDownEvent != null)
// {
// BackKeyDownEvent(new WoxKeyDownEventArgs
// {
// Query = tbQuery.Text,
// keyEventArgs = e
// });
// }
// break;
private void MainWindow_OnDrop(object sender, DragEventArgs e) private void MainWindow_OnDrop(object sender, DragEventArgs e)
{ {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) if (e.Data.GetDataPresent(DataFormats.FileDrop))

View File

@ -32,7 +32,7 @@ namespace Wox
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout")); var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
about.Click += (o, e) => this._api.OpenSettingDialog("about"); about.Click += (o, e) => this._api.OpenSettingDialog("about");
var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit")); var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
exit.Click += (o, e) => this._api.HideApp(); exit.Click += (o, e) => this._api.CloseApp();
MenuItem[] childen = { open, setting, about, exit }; MenuItem[] childen = { open, setting, about, exit };
notifyIcon.ContextMenu = new ContextMenu(childen); notifyIcon.ContextMenu = new ContextMenu(childen);
} }

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Input;
using System.Windows.Threading; using System.Windows.Threading;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
@ -36,6 +37,22 @@ namespace Wox
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey(); SetCustomPluginHotkey();
this.MainVM.ListeningKeyPressed += (o, e) => {
if(e.KeyEventArgs.Key == Key.Back)
{
if (null != this.BackKeyDownEvent)
{
BackKeyDownEvent(new WoxKeyDownEventArgs
{
Query = this.MainVM.QueryText,
keyEventArgs = e.KeyEventArgs
});
}
}
};
} }
#endregion #endregion
@ -55,33 +72,14 @@ namespace Wox
public void ChangeQuery(string query, bool requery = false) public void ChangeQuery(string query, bool requery = false)
{ {
this.MainVM.QueryText = query; this.MainVM.QueryText = query;
this.MainVM.CaretIndex = this.MainVM.QueryText.Length;
//TODO: Colin - Adjust CaretIndext
//Application.Current.Dispatcher.Invoke(() =>
//{
// tbQuery.CaretIndex = this.MainVM.QueryText.Length;
// if (requery)
// {
// TbQuery_OnTextChanged(null, null);
// }
//});
} }
public void ChangeQueryText(string query, bool selectAll = false) public void ChangeQueryText(string query, bool selectAll = false)
{ {
this.MainVM.QueryText = query; this.MainVM.QueryText = query;
this.MainVM.SelectAllText = true;
//TODO: Colin - Select all text
//Application.Current.Dispatcher.Invoke(() =>
//{
// tbQuery.CaretIndex = tbQuery.Text.Length;
// if (selectAll)
// {
// tbQuery.SelectAll();
// }
//});
} }
public void CloseApp() public void CloseApp()
@ -183,13 +181,7 @@ namespace Wox
o.PluginID = plugin.ID; o.PluginID = plugin.ID;
}); });
this.MainVM.ActionPanel.Clear(); this.MainVM.ShowActionPanel(results, plugin.ID);
//TODO:Show Action Panel accordingly
//pnlContextMenu.Clear();
//pnlContextMenu.AddResults(results, plugin.ID);
//pnlContextMenu.Visibility = Visibility.Visible;
//pnlResult.Visibility = Visibility.Collapsed;
} }
} }
@ -217,17 +209,7 @@ namespace Wox
{ {
UserSettingStorage.Instance.IncreaseActivateTimes(); UserSettingStorage.Instance.IncreaseActivateTimes();
this.MainVM.IsVisible = true; this.MainVM.IsVisible = true;
this.MainVM.SelectAllText = true;
//TODO: Colin - Adjust window properties
//Left = GetWindowsLeft();
//Top = GetWindowsTop();
//Show();
//Activate();
//Focus();
//tbQuery.Focus();
//ResetQueryHistoryIndex();
//if (selectAll) tbQuery.SelectAll();
} }
public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action) public void SetHotkey(string hotkeyStr, EventHandler<HotkeyEventArgs> action)

View File

@ -17,62 +17,13 @@ namespace Wox
[Synchronization] [Synchronization]
public partial class ResultPanel : UserControl public partial class ResultPanel : UserControl
{ {
//TODO: Refactor this event
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent; public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
public void AddResults(List<Result> newResults, string resultId) public void AddResults(List<Result> newResults, string resultId)
{ {
//lock (_resultsUpdateLock) var vm = this.DataContext as ResultPanelViewModel;
//{ vm.AddResults(newResults, resultId);
// // todo use async to do new result calculation
// var resultsCopy = _results.ToList();
// var oldResults = resultsCopy.Where(r => r.PluginID == resultId).ToList();
// // intersection of A (old results) and B (new newResults)
// var intersection = oldResults.Intersect(newResults).ToList();
// // remove result of relative complement of B in A
// foreach (var result in oldResults.Except(intersection))
// {
// resultsCopy.Remove(result);
// }
// // update scores
// foreach (var result in newResults)
// {
// if (IsTopMostResult(result))
// {
// result.Score = int.MaxValue;
// }
// }
// // update index for result in intersection of A and B
// foreach (var commonResult in intersection)
// {
// int oldIndex = resultsCopy.IndexOf(commonResult);
// int oldScore = resultsCopy[oldIndex].Score;
// int newScore = newResults[newResults.IndexOf(commonResult)].Score;
// if (newScore != oldScore)
// {
// var oldResult = resultsCopy[oldIndex];
// oldResult.Score = newScore;
// resultsCopy.RemoveAt(oldIndex);
// int newIndex = InsertIndexOf(newScore, resultsCopy);
// resultsCopy.Insert(newIndex, oldResult);
// }
// }
// // insert result in relative complement of A in B
// foreach (var result in newResults.Except(intersection))
// {
// int newIndex = InsertIndexOf(result.Score, resultsCopy);
// resultsCopy.Insert(newIndex, result);
// }
// // update UI in one run, so it can avoid UI flickering
// _results.Update(resultsCopy);
// lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
// SelectFirst();
//}
} }

View File

@ -22,6 +22,7 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using NHotkey.Wpf; using NHotkey.Wpf;
using NHotkey; using NHotkey;
using Wox.ViewModel;
namespace Wox namespace Wox
{ {
@ -36,6 +37,7 @@ namespace Wox
{ {
this._api = api; this._api = api;
InitializeComponent(); InitializeComponent();
this.resultPanelPreview.DataContext = new ResultPanelViewModel();
Loaded += Setting_Loaded; Loaded += Setting_Loaded;
} }

View File

@ -5,9 +5,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using System.Windows.Input; using System.Windows.Input;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Core.Resource; using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
@ -27,6 +29,8 @@ namespace Wox.ViewModel
private bool _isActionPanelVisible; private bool _isActionPanelVisible;
private bool _isProgressBarVisible; private bool _isProgressBarVisible;
private bool _isProgressBarTooltipVisible; private bool _isProgressBarTooltipVisible;
private bool _selectAllText;
private int _caretIndex;
private double _left; private double _left;
private double _top; private double _top;
@ -84,6 +88,32 @@ namespace Wox.ViewModel
} }
} }
public bool SelectAllText
{
get
{
return this._selectAllText;
}
set
{
this._selectAllText = value;
OnPropertyChanged("SelectAllText");
}
}
public int CaretIndex
{
get
{
return this._caretIndex;
}
set
{
this._caretIndex = value;
OnPropertyChanged("CaretIndex");
}
}
public bool IsVisible public bool IsVisible
{ {
get get
@ -246,13 +276,20 @@ namespace Wox.ViewModel
set; set;
} }
public ICommand BackCommand
{
get;
set;
}
#endregion #endregion
#region Private Methods #region Private Methods
private void InitializeKeyCommands() private void InitializeKeyCommands()
{ {
this.EscCommand = new RelayCommand((parameter) => { this.EscCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible) if (this.IsActionPanelVisible)
{ {
@ -265,7 +302,8 @@ namespace Wox.ViewModel
}); });
this.SelectNextItemCommand = new RelayCommand((parameter) => { this.SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible) if (this.IsActionPanelVisible)
{ {
@ -278,7 +316,8 @@ namespace Wox.ViewModel
}); });
this.SelectPrevItemCommand = new RelayCommand((parameter) => { this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible) if (this.IsActionPanelVisible)
{ {
@ -291,7 +330,8 @@ namespace Wox.ViewModel
}); });
this.CtrlOCommand = new RelayCommand((parameter) => { this.CtrlOCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible) if (this.IsActionPanelVisible)
{ {
@ -303,37 +343,43 @@ namespace Wox.ViewModel
} }
}); });
this.DisplayNextQueryCommand = new RelayCommand((parameter) => { this.DisplayNextQueryCommand = new RelayCommand((parameter) =>
{
var nextQuery = QueryHistoryStorage.Instance.Next(); var nextQuery = QueryHistoryStorage.Instance.Next();
DisplayQueryHistory(nextQuery); DisplayQueryHistory(nextQuery);
}); });
this.DisplayPrevQueryCommand = new RelayCommand((parameter) => { this.DisplayPrevQueryCommand = new RelayCommand((parameter) =>
{
var prev = QueryHistoryStorage.Instance.Previous(); var prev = QueryHistoryStorage.Instance.Previous();
DisplayQueryHistory(prev); DisplayQueryHistory(prev);
}); });
this.SelectNextPageCommand = new RelayCommand((parameter) => { this.SelectNextPageCommand = new RelayCommand((parameter) =>
{
this._searchResultPanel.SelectNextPage(); this._searchResultPanel.SelectNextPage();
}); });
this.SelectPrevPageCommand = new RelayCommand((parameter) => { this.SelectPrevPageCommand = new RelayCommand((parameter) =>
{
this._searchResultPanel.SelectPrevPage(); this._searchResultPanel.SelectPrevPage();
}); });
this.StartHelpCommand = new RelayCommand((parameter) => { this.StartHelpCommand = new RelayCommand((parameter) =>
{
Process.Start("http://doc.getwox.com"); Process.Start("http://doc.getwox.com");
}); });
this.ShiftEnterCommand = new RelayCommand((parameter) => { this.ShiftEnterCommand = new RelayCommand((parameter) =>
{
if (!this.IsActionPanelVisible && null != this._searchResultPanel.SelectedResult) if (!this.IsActionPanelVisible && null != this._searchResultPanel.SelectedResult)
{ {
@ -342,9 +388,10 @@ namespace Wox.ViewModel
}); });
this.OpenResultCommand = new RelayCommand((parameter) => { this.OpenResultCommand = new RelayCommand((parameter) =>
{
if(null != parameter) if (null != parameter)
{ {
var index = int.Parse(parameter.ToString()); var index = int.Parse(parameter.ToString());
this._searchResultPanel.SelectResult(index); this._searchResultPanel.SelectResult(index);
@ -355,6 +402,15 @@ namespace Wox.ViewModel
this._searchResultPanel.SelectedResult.OpenResultCommand.Execute(null); this._searchResultPanel.SelectedResult.OpenResultCommand.Execute(null);
} }
}); });
this.BackCommand = new RelayCommand((parameter) =>
{
if (null != ListeningKeyPressed)
{
this.ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
}
});
} }
private void InitializeResultPanel() private void InitializeResultPanel()
@ -380,27 +436,35 @@ namespace Wox.ViewModel
private void ShowActionPanel(Result result) private void ShowActionPanel(Result result)
{ {
if (result == null) return; if (result == null) return;
List<Result> results = PluginManager.GetContextMenusForPlugin(result); this.ShowActionPanel(result, PluginManager.GetContextMenusForPlugin(result));
results.ForEach(o => }
private void ShowActionPanel(Result result, List<Result> actions)
{
actions.ForEach(o =>
{ {
o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory; o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory;
o.PluginID = result.PluginID; o.PluginID = result.PluginID;
o.OriginQuery = result.OriginQuery; o.OriginQuery = result.OriginQuery;
}); });
results.Add(GetTopMostContextMenu(result)); actions.Add(GetTopMostContextMenu(result));
this.DisplayActionPanel(actions, result.PluginID);
}
private void DisplayActionPanel(List<Result> actions, string pluginID)
{
_textBeforeEnterContextMenuMode = this.QueryText; _textBeforeEnterContextMenuMode = this.QueryText;
this._actionPanel.Clear(); this._actionPanel.Clear();
this._actionPanel.AddResults(results, result.PluginID); this._actionPanel.AddResults(actions, pluginID);
CurrentContextMenus = results; CurrentContextMenus = actions;
this.IsActionPanelVisible = true; this.IsActionPanelVisible = true;
this.IsSearchResultPanelVisible = false; this.IsSearchResultPanelVisible = false;
this.QueryText = ""; this.QueryText = "";
} }
private Result GetTopMostContextMenu(Result result) private Result GetTopMostContextMenu(Result result)
@ -413,8 +477,7 @@ namespace Wox.ViewModel
Action = _ => Action = _ =>
{ {
TopMostRecordStorage.Instance.Remove(result); TopMostRecordStorage.Instance.Remove(result);
//TODO:Modify the way showing this message App.API.ShowMsg("Succeed", "", "");
//ShowMsg("Succeed", "", "");
return false; return false;
} }
}; };
@ -427,8 +490,7 @@ namespace Wox.ViewModel
Action = _ => Action = _ =>
{ {
TopMostRecordStorage.Instance.AddOrUpdate(result); TopMostRecordStorage.Instance.AddOrUpdate(result);
//TODO:Modify the way showing this message App.API.ShowMsg("Succeed", "", "");
//ShowMsg("Succeed", "", "");
return false; return false;
} }
}; };
@ -576,7 +638,7 @@ namespace Wox.ViewModel
var historyMetadata = QueryHistoryStorage.MetaData; var historyMetadata = QueryHistoryStorage.MetaData;
this.QueryText = history.Query; this.QueryText = history.Query;
//TODO: Need to select all text this.SelectAllText = true;
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery"); var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime"); var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
@ -592,7 +654,7 @@ namespace Wox.ViewModel
Action = _ =>{ Action = _ =>{
this.QueryText = history.Query; this.QueryText = history.Query;
//TODO: Need to select all text this.SelectAllText = true;
return false; return false;
} }
@ -616,18 +678,42 @@ namespace Wox.ViewModel
}); });
if (originQuery.RawQuery == _lastQuery.RawQuery) if (originQuery.RawQuery == _lastQuery.RawQuery)
{ {
Application.Current.Dispatcher.Invoke(() => { System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
UpdateResultViewInternal(list, metadata); UpdateResultViewInternal(list, metadata);
}); });
} }
if(list.Count > 0) if (list.Count > 0)
{ {
this.IsSearchResultPanelVisible = true; this.IsSearchResultPanelVisible = true;
} }
} }
public void ShowActionPanel(List<Result> actions, string pluginID)
{
this.DisplayActionPanel(actions, pluginID);
}
#endregion #endregion
public event EventHandler<ListeningKeyPressedEventArgs> ListeningKeyPressed;
}
public class ListeningKeyPressedEventArgs : EventArgs
{
public System.Windows.Input.KeyEventArgs KeyEventArgs
{
get;
private set;
}
public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs)
{
this.KeyEventArgs = keyEventArgs;
}
} }
} }

View File

@ -73,7 +73,6 @@ namespace Wox.ViewModel
{ {
get get
{ {
//TODO: Some of the properties in Result class may be moved to this class
return this._result.FullIcoPath; return this._result.FullIcoPath;
} }
} }