Merge branch 'dev'

This commit is contained in:
rmterra
2016-02-23 23:07:35 -03:00
9 changed files with 232 additions and 347 deletions

View File

@@ -47,11 +47,11 @@ namespace Wox.ViewModel
public MainViewModel()
{
this.InitializeResultListBox();
this.InitializeContextMenu();
this.InitializeKeyCommands();
InitializeResultListBox();
InitializeContextMenu();
InitializeKeyCommands();
this._queryHasReturn = false;
_queryHasReturn = false;
}
#endregion
@@ -66,14 +66,14 @@ namespace Wox.ViewModel
{
get
{
return this._queryText;
return _queryText;
}
set
{
this._queryText = value;
_queryText = value;
OnPropertyChanged("QueryText");
this.HandleQueryTextUpdated();
HandleQueryTextUpdated();
}
}
@@ -81,11 +81,11 @@ namespace Wox.ViewModel
{
get
{
return this._selectAllText;
return _selectAllText;
}
set
{
this._selectAllText = value;
_selectAllText = value;
OnPropertyChanged("SelectAllText");
}
}
@@ -94,11 +94,11 @@ namespace Wox.ViewModel
{
get
{
return this._caretIndex;
return _caretIndex;
}
set
{
this._caretIndex = value;
_caretIndex = value;
OnPropertyChanged("CaretIndex");
}
}
@@ -107,11 +107,11 @@ namespace Wox.ViewModel
{
get
{
return this._isProgressBarTooltipVisible;
return _isProgressBarTooltipVisible;
}
set
{
this._isProgressBarTooltipVisible = value;
_isProgressBarTooltipVisible = value;
OnPropertyChanged("IsProgressBarTooltipVisible");
}
}
@@ -120,11 +120,11 @@ namespace Wox.ViewModel
{
get
{
return this._left;
return _left;
}
set
{
this._left = value;
_left = value;
OnPropertyChanged("Left");
}
}
@@ -133,11 +133,11 @@ namespace Wox.ViewModel
{
get
{
return this._top;
return _top;
}
set
{
this._top = value;
_top = value;
OnPropertyChanged("Top");
}
}
@@ -146,11 +146,11 @@ namespace Wox.ViewModel
{
get
{
return this._contextMenuVisibility;
return _contextMenuVisibility;
}
set
{
this._contextMenuVisibility = value;
_contextMenuVisibility = value;
OnPropertyChanged("ContextMenuVisibility");
}
}
@@ -159,11 +159,11 @@ namespace Wox.ViewModel
{
get
{
return this._progressBarVisibility;
return _progressBarVisibility;
}
set
{
this._progressBarVisibility = value;
_progressBarVisibility = value;
OnPropertyChanged("ProgressBarVisibility");
}
}
@@ -172,11 +172,11 @@ namespace Wox.ViewModel
{
get
{
return this._resultListBoxVisibility;
return _resultListBoxVisibility;
}
set
{
this._resultListBoxVisibility = value;
_resultListBoxVisibility = value;
OnPropertyChanged("ResultListBoxVisibility");
}
}
@@ -185,154 +185,102 @@ namespace Wox.ViewModel
{
get
{
return this._windowVisibility;
return _windowVisibility;
}
set
{
this._windowVisibility = value;
_windowVisibility = value;
OnPropertyChanged("WindowVisibility");
if (value.IsNotVisible() && this.ContextMenuVisibility.IsVisible())
if (value.IsNotVisible() && ContextMenuVisibility.IsVisible())
{
this.BackToSearchMode();
BackToSearchMode();
}
}
}
public ICommand EscCommand
{
get;
set;
}
public ICommand EscCommand { get; set; }
public ICommand SelectNextItemCommand
{
get;
set;
}
public ICommand SelectNextItemCommand { get; set; }
public ICommand SelectPrevItemCommand
{
get;
set;
}
public ICommand SelectPrevItemCommand { get; set; }
public ICommand CtrlOCommand
{
get;
set;
}
public ICommand CtrlOCommand { get; set; }
public ICommand DisplayNextQueryCommand
{
get;
set;
}
public ICommand DisplayNextQueryCommand { get; set; }
public ICommand DisplayPrevQueryCommand
{
get;
set;
}
public ICommand DisplayPrevQueryCommand { get; set; }
public ICommand SelectNextPageCommand
{
get;
set;
}
public ICommand SelectNextPageCommand { get; set; }
public ICommand SelectPrevPageCommand
{
get;
set;
}
public ICommand StartHelpCommand
{
get;
set;
}
public ICommand ShiftEnterCommand
{
get;
set;
}
public ICommand OpenResultCommand
{
get;
set;
}
public ICommand BackCommand
{
get;
set;
}
public ICommand SelectPrevPageCommand { get; set; }
public ICommand StartHelpCommand { get; set; }
public ICommand ShiftEnterCommand { get; set; }
public ICommand OpenResultCommand { get; set; }
public ICommand BackCommand { get; set; }
#endregion
#region Private Methods
private void InitializeKeyCommands()
{
this.EscCommand = new RelayCommand((parameter) =>
EscCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{
this.BackToSearchMode();
}
else
{
this.WindowVisibility = Visibility.Collapsed;
}
});
this.SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{
this.ContextMenu.SelectNextResult();
}
else
{
this.Results.SelectNextResult();
}
});
this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
{
this.ContextMenu.SelectPrevResult();
}
else
{
this.Results.SelectPrevResult();
}
});
this.CtrlOCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsVisible())
if (ContextMenuVisibility.IsVisible())
{
BackToSearchMode();
}
else
{
ShowContextMenu(this.Results.SelectedResult.RawResult);
WindowVisibility = Visibility.Collapsed;
}
});
SelectNextItemCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
ContextMenu.SelectNextResult();
}
else
{
Results.SelectNextResult();
}
});
SelectPrevItemCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
ContextMenu.SelectPrevResult();
}
else
{
Results.SelectPrevResult();
}
});
CtrlOCommand = new RelayCommand((parameter) =>
{
if (ContextMenuVisibility.IsVisible())
{
BackToSearchMode();
}
else
{
ShowContextMenu(Results.SelectedResult.RawResult);
}
});
this.DisplayNextQueryCommand = new RelayCommand((parameter) =>
DisplayNextQueryCommand = new RelayCommand((parameter) =>
{
var nextQuery = QueryHistoryStorage.Instance.Next();
@@ -340,7 +288,7 @@ namespace Wox.ViewModel
});
this.DisplayPrevQueryCommand = new RelayCommand((parameter) =>
DisplayPrevQueryCommand = new RelayCommand((parameter) =>
{
var prev = QueryHistoryStorage.Instance.Previous();
@@ -348,55 +296,55 @@ namespace Wox.ViewModel
});
this.SelectNextPageCommand = new RelayCommand((parameter) =>
SelectNextPageCommand = new RelayCommand((parameter) =>
{
this.Results.SelectNextPage();
Results.SelectNextPage();
});
this.SelectPrevPageCommand = new RelayCommand((parameter) =>
SelectPrevPageCommand = new RelayCommand((parameter) =>
{
this.Results.SelectPrevPage();
Results.SelectPrevPage();
});
this.StartHelpCommand = new RelayCommand((parameter) =>
StartHelpCommand = new RelayCommand((parameter) =>
{
Process.Start("http://doc.getwox.com");
});
this.ShiftEnterCommand = new RelayCommand((parameter) =>
ShiftEnterCommand = new RelayCommand((parameter) =>
{
if (this.ContextMenuVisibility.IsNotVisible() && null != this.Results.SelectedResult)
if (ContextMenuVisibility.IsNotVisible() && null != Results.SelectedResult)
{
this.ShowContextMenu(this.Results.SelectedResult.RawResult);
ShowContextMenu(Results.SelectedResult.RawResult);
}
});
this.OpenResultCommand = new RelayCommand((parameter) =>
OpenResultCommand = new RelayCommand((parameter) =>
{
if (null != parameter)
{
var index = int.Parse(parameter.ToString());
this.Results.SelectResult(index);
Results.SelectResult(index);
}
if (null != this.Results.SelectedResult)
if (null != Results.SelectedResult)
{
this.Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
}
});
this.BackCommand = new RelayCommand((parameter) =>
BackCommand = new RelayCommand((parameter) =>
{
if (null != ListeningKeyPressed)
{
this.ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
}
});
@@ -404,14 +352,14 @@ namespace Wox.ViewModel
private void InitializeResultListBox()
{
this.Results = new ResultsViewModel();
this.ResultListBoxVisibility = Visibility.Collapsed;
Results = new ResultsViewModel();
ResultListBoxVisibility = Visibility.Collapsed;
}
private void ShowContextMenu(Result result)
{
if (result == null) return;
this.ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
}
private void ShowContextMenu(Result result, List<Result> actions)
@@ -425,21 +373,21 @@ namespace Wox.ViewModel
actions.Add(GetTopMostContextMenu(result));
this.DisplayContextMenu(actions, result.PluginID);
DisplayContextMenu(actions, result.PluginID);
}
private void DisplayContextMenu(List<Result> actions, string pluginID)
{
_textBeforeEnterContextMenuMode = this.QueryText;
_textBeforeEnterContextMenuMode = QueryText;
this.ContextMenu.Clear();
this.ContextMenu.AddResults(actions, pluginID);
ContextMenu.Clear();
ContextMenu.AddResults(actions, pluginID);
CurrentContextMenus = actions;
this.ContextMenuVisibility = Visibility.Visible;
this.ResultListBoxVisibility = Visibility.Collapsed;
ContextMenuVisibility = Visibility.Visible;
ResultListBoxVisibility = Visibility.Collapsed;
this.QueryText = "";
QueryText = "";
}
private Result GetTopMostContextMenu(Result result)
@@ -474,22 +422,22 @@ namespace Wox.ViewModel
private void InitializeContextMenu()
{
this.ContextMenu = new ResultsViewModel();
this.ContextMenuVisibility = Visibility.Collapsed;
ContextMenu = new ResultsViewModel();
ContextMenuVisibility = Visibility.Collapsed;
}
private void HandleQueryTextUpdated()
{
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
this.IsProgressBarTooltipVisible = false;
if (this.ContextMenuVisibility.IsVisible())
IsProgressBarTooltipVisible = false;
if (ContextMenuVisibility.IsVisible())
{
QueryContextMenu();
}
else
{
string query = this.QueryText.Trim();
string query = QueryText.Trim();
if (!string.IsNullOrEmpty(query))
{
Query(query);
@@ -498,7 +446,7 @@ namespace Wox.ViewModel
}
else
{
this.Results.Clear();
Results.Clear();
}
}
}
@@ -506,11 +454,11 @@ namespace Wox.ViewModel
private void QueryContextMenu()
{
var contextMenuId = "Context Menu Id";
this.ContextMenu.Clear();
var query = this.QueryText.ToLower();
ContextMenu.Clear();
var query = QueryText.ToLower();
if (string.IsNullOrEmpty(query))
{
this.ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
}
else
{
@@ -523,7 +471,7 @@ namespace Wox.ViewModel
filterResults.Add(contextMenu);
}
}
this.ContextMenu.AddResults(filterResults, contextMenuId);
ContextMenu.AddResults(filterResults, contextMenuId);
}
}
@@ -540,18 +488,18 @@ namespace Wox.ViewModel
{
if (!string.IsNullOrEmpty(keyword))
{
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
}
}
else
{
if (string.IsNullOrEmpty(keyword))
{
this.Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
}
else if (lastKeyword != keyword)
{
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
}
}
_lastQuery = query;
@@ -561,7 +509,7 @@ namespace Wox.ViewModel
await Task.Delay(150);
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
{
this.IsProgressBarTooltipVisible = true;
IsProgressBarTooltipVisible = true;
}
});
action.Invoke();
@@ -577,27 +525,27 @@ namespace Wox.ViewModel
PluginManager.QueryForAllPlugins(query);
}
this.IsProgressBarTooltipVisible = false;
IsProgressBarTooltipVisible = false;
}
private void ResetQueryHistoryIndex()
{
this.Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
QueryHistoryStorage.Instance.Reset();
}
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
{
Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}",
() => { this.Results.AddResults(list, metadata.ID); });
() => { Results.AddResults(list, metadata.ID); });
}
private void BackToSearchMode()
{
this.QueryText = _textBeforeEnterContextMenuMode;
this.ContextMenuVisibility = Visibility.Collapsed;
this.ResultListBoxVisibility = Visibility.Visible;
this.CaretIndex = this.QueryText.Length;
QueryText = _textBeforeEnterContextMenuMode;
ContextMenuVisibility = Visibility.Collapsed;
ResultListBoxVisibility = Visibility.Visible;
CaretIndex = QueryText.Length;
}
private void DisplayQueryHistory(HistoryItem history)
@@ -606,12 +554,12 @@ namespace Wox.ViewModel
{
var historyMetadata = QueryHistoryStorage.MetaData;
this.QueryText = history.Query;
this.SelectAllText = true;
QueryText = history.Query;
SelectAllText = true;
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
this.Results.RemoveResultsExcept(historyMetadata);
Results.RemoveResultsExcept(historyMetadata);
UpdateResultViewInternal(new List<Result>
{
new Result
@@ -622,8 +570,8 @@ namespace Wox.ViewModel
PluginDirectory = WoxDirectroy.Executable,
Action = _ =>{
this.QueryText = history.Query;
this.SelectAllText = true;
QueryText = history.Query;
SelectAllText = true;
return false;
}
@@ -639,7 +587,7 @@ namespace Wox.ViewModel
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
{
_queryHasReturn = true;
this.IsProgressBarTooltipVisible = false;
IsProgressBarTooltipVisible = false;
list.ForEach(o =>
{
@@ -655,13 +603,13 @@ namespace Wox.ViewModel
if (list.Count > 0)
{
this.ResultListBoxVisibility = Visibility.Visible;
ResultListBoxVisibility = Visibility.Visible;
}
}
public void ShowContextMenu(List<Result> actions, string pluginID)
{
this.DisplayContextMenu(actions, pluginID);
DisplayContextMenu(actions, pluginID);
}
#endregion
@@ -681,7 +629,7 @@ namespace Wox.ViewModel
public ListeningKeyPressedEventArgs(System.Windows.Input.KeyEventArgs keyEventArgs)
{
this.KeyEventArgs = keyEventArgs;
KeyEventArgs = keyEventArgs;
}
}