2016-02-18 19:30:36 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-02-12 14:21:12 +08:00
|
|
|
|
using System.Diagnostics;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
using System.Windows.Forms;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Wox.Core.Plugin;
|
|
|
|
|
using Wox.Core.Resource;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using Wox.Infrastructure;
|
|
|
|
|
using Wox.Infrastructure.Hotkey;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using Wox.Storage;
|
|
|
|
|
|
|
|
|
|
namespace Wox.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class MainViewModel : BaseViewModel
|
|
|
|
|
{
|
|
|
|
|
#region Private Fields
|
|
|
|
|
|
|
|
|
|
private string _queryText;
|
|
|
|
|
private bool _isVisible;
|
2016-02-21 22:22:34 +08:00
|
|
|
|
private bool _isResultListBoxVisible;
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private bool _isContextMenuVisible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
private bool _isProgressBarVisible;
|
|
|
|
|
private bool _isProgressBarTooltipVisible;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
private bool _selectAllText;
|
|
|
|
|
private int _caretIndex;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
private double _left;
|
|
|
|
|
private double _top;
|
|
|
|
|
|
|
|
|
|
private bool _queryHasReturn;
|
|
|
|
|
private Query _lastQuery = new Query();
|
|
|
|
|
private bool _ignoreTextChange;
|
|
|
|
|
private List<Result> CurrentContextMenus = new List<Result>();
|
|
|
|
|
private string _textBeforeEnterContextMenuMode;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
|
|
public MainViewModel()
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.InitializeResultListBox();
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.InitializeContextMenu();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
this.InitializeKeyCommands();
|
|
|
|
|
|
|
|
|
|
this._queryHasReturn = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ViewModel Properties
|
|
|
|
|
|
2016-02-21 22:33:18 +08:00
|
|
|
|
public ResultsViewModel Results { get; private set; }
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
public ResultsViewModel ContextMenu { get; private set; }
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
|
|
|
|
public string QueryText
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._queryText;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._queryText = value;
|
|
|
|
|
OnPropertyChanged("QueryText");
|
|
|
|
|
|
|
|
|
|
this.HandleQueryTextUpdated();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public bool IsVisible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._isVisible;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._isVisible = value;
|
|
|
|
|
OnPropertyChanged("IsVisible");
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (!value && this.IsContextMenuVisible)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
this.BackToSearchMode();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:22:34 +08:00
|
|
|
|
public bool IsResultListBoxVisible
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
return this._isResultListBoxVisible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this._isResultListBoxVisible = value;
|
|
|
|
|
OnPropertyChanged("IsResultListBoxVisible");
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
public bool IsContextMenuVisible
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
return this._isContextMenuVisible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this._isContextMenuVisible = value;
|
|
|
|
|
OnPropertyChanged("IsContextMenuVisible");
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsProgressBarVisible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._isProgressBarVisible;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._isProgressBarVisible = value;
|
|
|
|
|
OnPropertyChanged("IsProgressBarVisible");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsProgressBarTooltipVisible
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._isProgressBarTooltipVisible;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._isProgressBarTooltipVisible = value;
|
|
|
|
|
OnPropertyChanged("IsProgressBarTooltipVisible");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double Left
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._left;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._left = value;
|
|
|
|
|
OnPropertyChanged("Left");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double Top
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._top;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
this._top = value;
|
|
|
|
|
OnPropertyChanged("Top");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand EscCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 14:21:12 +08:00
|
|
|
|
public ICommand SelectNextItemCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand SelectPrevItemCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand CtrlOCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand DisplayNextQueryCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICommand DisplayPrevQueryCommand
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
public ICommand BackCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private Methods
|
|
|
|
|
|
|
|
|
|
private void InitializeKeyCommands()
|
|
|
|
|
{
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.EscCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (this.IsContextMenuVisible)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
this.BackToSearchMode();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.IsVisible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectNextItemCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (this.IsContextMenuVisible)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.SelectNextResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.SelectNextResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectPrevItemCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (this.IsContextMenuVisible)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.SelectPrevResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.SelectPrevResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.CtrlOCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (this.IsContextMenuVisible)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
|
|
|
|
BackToSearchMode();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
ShowContextMenu(this.Results.SelectedResult.RawResult);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.DisplayNextQueryCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
var nextQuery = QueryHistoryStorage.Instance.Next();
|
|
|
|
|
DisplayQueryHistory(nextQuery);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.DisplayPrevQueryCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
var prev = QueryHistoryStorage.Instance.Previous();
|
|
|
|
|
DisplayQueryHistory(prev);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectNextPageCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.SelectNextPage();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectPrevPageCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.SelectPrevPage();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.StartHelpCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
Process.Start("http://doc.getwox.com");
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.ShiftEnterCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (!this.IsContextMenuVisible && null != this.Results.SelectedResult)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ShowContextMenu(this.Results.SelectedResult.RawResult);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.OpenResultCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
if (null != parameter)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
|
|
|
|
var index = int.Parse(parameter.ToString());
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.SelectResult(index);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:22:34 +08:00
|
|
|
|
if (null != this.Results.SelectedResult)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-02-12 17:20:46 +08:00
|
|
|
|
|
|
|
|
|
this.BackCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
|
|
|
|
if (null != ListeningKeyPressed)
|
|
|
|
|
{
|
|
|
|
|
this.ListeningKeyPressed(this, new ListeningKeyPressedEventArgs(parameter as System.Windows.Input.KeyEventArgs));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:22:34 +08:00
|
|
|
|
private void InitializeResultListBox()
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-02-21 22:33:18 +08:00
|
|
|
|
this.Results = new ResultsViewModel();
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.IsResultListBoxVisible = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private void ShowContextMenu(Result result)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (result == null) return;
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
|
2016-02-12 17:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private void ShowContextMenu(Result result, List<Result> actions)
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
actions.ForEach(o =>
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
o.PluginDirectory = PluginManager.GetPluginForId(result.PluginID).Metadata.PluginDirectory;
|
|
|
|
|
o.PluginID = result.PluginID;
|
|
|
|
|
o.OriginQuery = result.OriginQuery;
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
actions.Add(GetTopMostContextMenu(result));
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.DisplayContextMenu(actions, result.PluginID);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
}
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private void DisplayContextMenu(List<Result> actions, string pluginID)
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-18 19:30:36 +08:00
|
|
|
|
_textBeforeEnterContextMenuMode = this.QueryText;
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.Clear();
|
|
|
|
|
this.ContextMenu.AddResults(actions, pluginID);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
CurrentContextMenus = actions;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.IsContextMenuVisible = true;
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.IsResultListBoxVisible = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
|
|
|
|
this.QueryText = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Result GetTopMostContextMenu(Result result)
|
|
|
|
|
{
|
|
|
|
|
if (TopMostRecordStorage.Instance.IsTopMost(result))
|
|
|
|
|
{
|
|
|
|
|
return new Result(InternationalizationManager.Instance.GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
|
|
|
|
|
{
|
|
|
|
|
PluginDirectory = WoxDirectroy.Executable,
|
|
|
|
|
Action = _ =>
|
|
|
|
|
{
|
|
|
|
|
TopMostRecordStorage.Instance.Remove(result);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
App.API.ShowMsg("Succeed", "", "");
|
2016-02-18 19:30:36 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Result(InternationalizationManager.Instance.GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
|
|
|
|
|
{
|
|
|
|
|
PluginDirectory = WoxDirectroy.Executable,
|
|
|
|
|
Action = _ =>
|
|
|
|
|
{
|
|
|
|
|
TopMostRecordStorage.Instance.AddOrUpdate(result);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
App.API.ShowMsg("Succeed", "", "");
|
2016-02-18 19:30:36 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private void InitializeContextMenu()
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu = new ResultsViewModel();
|
|
|
|
|
this.IsContextMenuVisible = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleQueryTextUpdated()
|
|
|
|
|
{
|
|
|
|
|
if (_ignoreTextChange) { _ignoreTextChange = false; return; }
|
|
|
|
|
|
|
|
|
|
this.IsProgressBarTooltipVisible = false;
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (this.IsContextMenuVisible)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
QueryContextMenu();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string query = this.QueryText.Trim();
|
|
|
|
|
if (!string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
|
|
|
|
Query(query);
|
|
|
|
|
//reset query history index after user start new query
|
|
|
|
|
ResetQueryHistoryIndex();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.Clear();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
private void QueryContextMenu()
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
var contextMenuId = "Context Menu Id";
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.Clear();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
var query = this.QueryText.ToLower();
|
|
|
|
|
if (string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<Result> filterResults = new List<Result>();
|
|
|
|
|
foreach (Result contextMenu in CurrentContextMenus)
|
|
|
|
|
{
|
|
|
|
|
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
|
|
|
|
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
|
|
|
|
{
|
|
|
|
|
filterResults.Add(contextMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.ContextMenu.AddResults(filterResults, contextMenuId);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Query(string text)
|
|
|
|
|
{
|
|
|
|
|
_queryHasReturn = false;
|
|
|
|
|
var query = PluginManager.QueryInit(text);
|
|
|
|
|
if (query != null)
|
|
|
|
|
{
|
|
|
|
|
// handle the exclusiveness of plugin using action keyword
|
|
|
|
|
string lastKeyword = _lastQuery.ActionKeyword;
|
|
|
|
|
string keyword = query.ActionKeyword;
|
|
|
|
|
if (string.IsNullOrEmpty(lastKeyword))
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(keyword))
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(keyword))
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else if (lastKeyword != keyword)
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_lastQuery = query;
|
|
|
|
|
|
|
|
|
|
Action action = new Action(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(150);
|
|
|
|
|
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
|
|
|
|
{
|
|
|
|
|
this.IsProgressBarTooltipVisible = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
action.Invoke();
|
|
|
|
|
|
|
|
|
|
//Application.Current.Dispatcher.InvokeAsync(async () =>
|
|
|
|
|
//{
|
|
|
|
|
// await Task.Delay(150);
|
|
|
|
|
// if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
|
|
|
|
// {
|
|
|
|
|
// StartProgress();
|
|
|
|
|
// }
|
|
|
|
|
//});
|
|
|
|
|
PluginManager.QueryForAllPlugins(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.IsProgressBarTooltipVisible = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetQueryHistoryIndex()
|
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.RemoveResultsFor(QueryHistoryStorage.MetaData);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
QueryHistoryStorage.Instance.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateResultViewInternal(List<Result> list, PluginMetadata metadata)
|
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
Infrastructure.Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
2016-02-21 22:22:34 +08:00
|
|
|
|
() => { this.Results.AddResults(list, metadata.ID); });
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BackToSearchMode()
|
|
|
|
|
{
|
|
|
|
|
this.QueryText = _textBeforeEnterContextMenuMode;
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.IsContextMenuVisible = false;
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.IsResultListBoxVisible = true;
|
2016-02-19 22:59:01 +08:00
|
|
|
|
this.CaretIndex = this.QueryText.Length;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 14:21:12 +08:00
|
|
|
|
private void DisplayQueryHistory(HistoryItem history)
|
|
|
|
|
{
|
|
|
|
|
if (history != null)
|
|
|
|
|
{
|
|
|
|
|
var historyMetadata = QueryHistoryStorage.MetaData;
|
|
|
|
|
|
|
|
|
|
this.QueryText = history.Query;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectAllText = true;
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
|
|
|
|
|
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.Results.RemoveResultsExcept(historyMetadata);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
UpdateResultViewInternal(new List<Result>
|
|
|
|
|
{
|
|
|
|
|
new Result
|
|
|
|
|
{
|
|
|
|
|
Title = string.Format(executeQueryHistoryTitle,history.Query),
|
|
|
|
|
SubTitle = string.Format(lastExecuteTime,history.ExecutedDateTime),
|
|
|
|
|
IcoPath = "Images\\history.png",
|
|
|
|
|
PluginDirectory = WoxDirectroy.Executable,
|
|
|
|
|
Action = _ =>{
|
|
|
|
|
|
|
|
|
|
this.QueryText = history.Query;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
this.SelectAllText = true;
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, historyMetadata);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Public Methods
|
|
|
|
|
|
|
|
|
|
public void UpdateResultView(List<Result> list, PluginMetadata metadata, Query originQuery)
|
|
|
|
|
{
|
|
|
|
|
_queryHasReturn = true;
|
|
|
|
|
this.IsProgressBarTooltipVisible = false;
|
|
|
|
|
|
|
|
|
|
list.ForEach(o =>
|
|
|
|
|
{
|
|
|
|
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
|
|
|
|
});
|
|
|
|
|
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
|
|
|
|
{
|
2016-02-12 17:20:46 +08:00
|
|
|
|
System.Windows.Application.Current.Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
2016-02-18 19:30:36 +08:00
|
|
|
|
UpdateResultViewInternal(list, metadata);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
if (list.Count > 0)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-02-21 22:22:34 +08:00
|
|
|
|
this.IsResultListBoxVisible = true;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
public void ShowContextMenu(List<Result> actions, string pluginID)
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.DisplayContextMenu(actions, pluginID);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|