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)
{
//TODO: Add ToggleWox Method
//App.API.ToggleWox();
if (App.Window.IsVisible)
{
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="D5" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="4"></KeyBinding>
<KeyBinding Key="D6" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="5"></KeyBinding>
<KeyBinding Key="Back" Command="{Binding BackCommand}"></KeyBinding>
</Window.InputBindings>
<Window.Resources>
<DataTemplate DataType="{x:Type vm:ResultPanelViewModel}">

View File

@ -64,12 +64,46 @@ namespace Wox
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
Left = GetWindowsLeft();
Top = GetWindowsTop();
InitProgressbarAnimation();
WindowIntelopHelper.DisableControlBox(this);
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()
@ -135,14 +169,13 @@ namespace Wox
{
if (UserSettingStorage.Instance.HideWhenDeactive)
{
//TODO:Hide the window when deactivated
//HideWox();
App.API.HideApp();
}
}
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;
//when alt is pressed, the real key should be e.SystemKey
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
@ -179,21 +212,12 @@ namespace Wox
vm.SelectPrevPageCommand.Execute(null);
e.Handled = true;
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)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))

View File

@ -32,7 +32,7 @@ namespace Wox
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
about.Click += (o, e) => this._api.OpenSettingDialog("about");
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 };
notifyIcon.ContextMenu = new ContextMenu(childen);
}

View File

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

View File

@ -17,62 +17,13 @@ namespace Wox
[Synchronization]
public partial class ResultPanel : UserControl
{
//TODO: Refactor this event
public event Action<Result, IDataObject, DragEventArgs> ItemDropEvent;
public void AddResults(List<Result> newResults, string resultId)
{
//lock (_resultsUpdateLock)
//{
// // 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();
//}
var vm = this.DataContext as ResultPanelViewModel;
vm.AddResults(newResults, resultId);
}

View File

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

View File

@ -5,9 +5,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Core.UserSettings;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
@ -27,6 +29,8 @@ namespace Wox.ViewModel
private bool _isActionPanelVisible;
private bool _isProgressBarVisible;
private bool _isProgressBarTooltipVisible;
private bool _selectAllText;
private int _caretIndex;
private double _left;
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
{
get
@ -246,13 +276,20 @@ namespace Wox.ViewModel
set;
}
public ICommand BackCommand
{
get;
set;
}
#endregion
#region Private Methods
private void InitializeKeyCommands()
{
this.EscCommand = new RelayCommand((parameter) => {
this.EscCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible)
{
@ -265,7 +302,8 @@ namespace Wox.ViewModel
});
this.SelectNextItemCommand = new RelayCommand((parameter) => {
this.SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible)
{
@ -278,7 +316,8 @@ namespace Wox.ViewModel
});
this.SelectPrevItemCommand = new RelayCommand((parameter) => {
this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (this.IsActionPanelVisible)
{
@ -291,7 +330,8 @@ namespace Wox.ViewModel
});
this.CtrlOCommand = new RelayCommand((parameter) => {
this.CtrlOCommand = new RelayCommand((parameter) =>
{
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();
DisplayQueryHistory(nextQuery);
});
this.DisplayPrevQueryCommand = new RelayCommand((parameter) => {
this.DisplayPrevQueryCommand = new RelayCommand((parameter) =>
{
var prev = QueryHistoryStorage.Instance.Previous();
DisplayQueryHistory(prev);
});
this.SelectNextPageCommand = new RelayCommand((parameter) => {
this.SelectNextPageCommand = new RelayCommand((parameter) =>
{
this._searchResultPanel.SelectNextPage();
});
this.SelectPrevPageCommand = new RelayCommand((parameter) => {
this.SelectPrevPageCommand = new RelayCommand((parameter) =>
{
this._searchResultPanel.SelectPrevPage();
});
this.StartHelpCommand = new RelayCommand((parameter) => {
this.StartHelpCommand = new RelayCommand((parameter) =>
{
Process.Start("http://doc.getwox.com");
});
this.ShiftEnterCommand = new RelayCommand((parameter) => {
this.ShiftEnterCommand = new RelayCommand((parameter) =>
{
if (!this.IsActionPanelVisible && null != this._searchResultPanel.SelectedResult)
{
@ -342,7 +388,8 @@ namespace Wox.ViewModel
});
this.OpenResultCommand = new RelayCommand((parameter) => {
this.OpenResultCommand = new RelayCommand((parameter) =>
{
if (null != parameter)
{
@ -355,6 +402,15 @@ namespace Wox.ViewModel
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()
@ -380,27 +436,35 @@ namespace Wox.ViewModel
private void ShowActionPanel(Result result)
{
if (result == null) return;
List<Result> results = PluginManager.GetContextMenusForPlugin(result);
results.ForEach(o =>
this.ShowActionPanel(result, PluginManager.GetContextMenusForPlugin(result));
}
private void ShowActionPanel(Result result, List<Result> actions)
{
actions.ForEach(o =>
{
o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory;
o.PluginID = result.PluginID;
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;
this._actionPanel.Clear();
this._actionPanel.AddResults(results, result.PluginID);
CurrentContextMenus = results;
this._actionPanel.AddResults(actions, pluginID);
CurrentContextMenus = actions;
this.IsActionPanelVisible = true;
this.IsSearchResultPanelVisible = false;
this.QueryText = "";
}
private Result GetTopMostContextMenu(Result result)
@ -413,8 +477,7 @@ namespace Wox.ViewModel
Action = _ =>
{
TopMostRecordStorage.Instance.Remove(result);
//TODO:Modify the way showing this message
//ShowMsg("Succeed", "", "");
App.API.ShowMsg("Succeed", "", "");
return false;
}
};
@ -427,8 +490,7 @@ namespace Wox.ViewModel
Action = _ =>
{
TopMostRecordStorage.Instance.AddOrUpdate(result);
//TODO:Modify the way showing this message
//ShowMsg("Succeed", "", "");
App.API.ShowMsg("Succeed", "", "");
return false;
}
};
@ -576,7 +638,7 @@ namespace Wox.ViewModel
var historyMetadata = QueryHistoryStorage.MetaData;
this.QueryText = history.Query;
//TODO: Need to select all text
this.SelectAllText = true;
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
@ -592,7 +654,7 @@ namespace Wox.ViewModel
Action = _ =>{
this.QueryText = history.Query;
//TODO: Need to select all text
this.SelectAllText = true;
return false;
}
@ -616,7 +678,8 @@ namespace Wox.ViewModel
});
if (originQuery.RawQuery == _lastQuery.RawQuery)
{
Application.Current.Dispatcher.Invoke(() => {
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
UpdateResultViewInternal(list, metadata);
});
}
@ -627,7 +690,30 @@ namespace Wox.ViewModel
}
}
public void ShowActionPanel(List<Result> actions, string pluginID)
{
this.DisplayActionPanel(actions, pluginID);
}
#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
{
//TODO: Some of the properties in Result class may be moved to this class
return this._result.FullIcoPath;
}
}