2016-02-18 19:30:36 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-02-27 07:43:57 +08:00
|
|
|
|
using System.ComponentModel;
|
2016-02-12 14:21:12 +08:00
|
|
|
|
using System.Diagnostics;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Wox.Core.Plugin;
|
|
|
|
|
using Wox.Core.Resource;
|
2016-02-26 20:05:32 +08:00
|
|
|
|
using Wox.Helper;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
using Wox.Infrastructure;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using Wox.Storage;
|
2016-02-23 05:43:37 +08:00
|
|
|
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class MainViewModel : BaseViewModel
|
|
|
|
|
{
|
|
|
|
|
#region Private Fields
|
|
|
|
|
|
|
|
|
|
private string _queryText;
|
2016-02-22 05:27:05 +08:00
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
private bool _isProgressBarTooltipVisible;
|
|
|
|
|
private double _left;
|
|
|
|
|
private double _top;
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
private Visibility _contextMenuVisibility;
|
|
|
|
|
private Visibility _progressBarVisibility;
|
|
|
|
|
private Visibility _resultListBoxVisibility;
|
2016-02-26 20:05:32 +08:00
|
|
|
|
private Visibility _mainWindowVisibility;
|
2016-02-22 05:27:05 +08:00
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
private bool _queryHasReturn;
|
|
|
|
|
private Query _lastQuery = new Query();
|
|
|
|
|
private bool _ignoreTextChange;
|
2016-02-23 05:43:37 +08:00
|
|
|
|
private List<Result> _currentContextMenus = new List<Result>();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
private string _textBeforeEnterContextMenuMode;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
|
|
public MainViewModel()
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
InitializeResultListBox();
|
|
|
|
|
InitializeContextMenu();
|
|
|
|
|
InitializeKeyCommands();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
_queryHasReturn = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
return _queryText;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
_queryText = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-21 23:42:37 +08:00
|
|
|
|
HandleQueryTextUpdated();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public bool IsProgressBarTooltipVisible
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _isProgressBarTooltipVisible;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_isProgressBarTooltipVisible = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public double Left
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _left;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_left = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public double Top
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _top;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_top = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public Visibility ContextMenuVisibility
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _contextMenuVisibility;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_contextMenuVisibility = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public Visibility ProgressBarVisibility
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _progressBarVisibility;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_progressBarVisibility = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:27:05 +08:00
|
|
|
|
public Visibility ResultListBoxVisibility
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
return _resultListBoxVisibility;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
_resultListBoxVisibility = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 20:05:32 +08:00
|
|
|
|
public Visibility MainWindowVisibility
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-26 20:05:32 +08:00
|
|
|
|
return _mainWindowVisibility;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-02-26 20:05:32 +08:00
|
|
|
|
_mainWindowVisibility = value;
|
2016-02-27 08:09:12 +08:00
|
|
|
|
OnPropertyChanged();
|
2016-02-27 07:43:57 +08:00
|
|
|
|
MainWindowVisibilityChanged?.Invoke(this, new EventArgs());
|
2016-02-22 05:27:05 +08:00
|
|
|
|
|
2016-02-26 20:05:32 +08:00
|
|
|
|
if (!value.IsVisible() && ContextMenuVisibility.IsVisible())
|
2016-02-22 05:27:05 +08:00
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
BackToSearchMode();
|
2016-02-22 05:27:05 +08:00
|
|
|
|
}
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
public ICommand EscCommand { get; set; }
|
|
|
|
|
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; }
|
|
|
|
|
public ICommand BackCommand { get; set; }
|
2016-02-18 19:30:36 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Private Methods
|
|
|
|
|
|
|
|
|
|
private void InitializeKeyCommands()
|
|
|
|
|
{
|
2016-02-23 05:43:37 +08:00
|
|
|
|
EscCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
if (ContextMenuVisibility.IsVisible())
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
BackToSearchMode();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-26 20:05:32 +08:00
|
|
|
|
MainWindowVisibility = Visibility.Collapsed;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
SelectNextItemCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
if (ContextMenuVisibility.IsVisible())
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
ContextMenu.SelectNextResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.SelectNextResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
SelectPrevItemCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
if (ContextMenuVisibility.IsVisible())
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
ContextMenu.SelectPrevResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.SelectPrevResult();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
CtrlOCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-24 10:07:35 +08:00
|
|
|
|
if (ContextMenuVisibility.IsVisible())
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
|
|
|
|
BackToSearchMode();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
ShowContextMenu(Results.SelectedResult.RawResult);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
DisplayNextQueryCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
var nextQuery = QueryHistoryStorage.Instance.Next();
|
|
|
|
|
DisplayQueryHistory(nextQuery);
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
DisplayPrevQueryCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
var prev = QueryHistoryStorage.Instance.Previous();
|
|
|
|
|
DisplayQueryHistory(prev);
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
SelectNextPageCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.SelectNextPage();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
SelectPrevPageCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.SelectPrevPage();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
StartHelpCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-12 14:21:12 +08:00
|
|
|
|
Process.Start("http://doc.getwox.com");
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
ShiftEnterCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-26 20:05:32 +08:00
|
|
|
|
if (!ContextMenuVisibility.IsVisible() && null != Results.SelectedResult)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
ShowContextMenu(Results.SelectedResult.RawResult);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
OpenResultCommand = new RelayCommand(o =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-23 05:47:10 +08:00
|
|
|
|
if (o != null)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-23 05:43:37 +08:00
|
|
|
|
var index = int.Parse(o.ToString());
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.SelectResult(index);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
2016-02-23 05:43:37 +08:00
|
|
|
|
Results.SelectedResult?.OpenResultListBoxItemCommand.Execute(null);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
});
|
2016-02-12 17:20:46 +08:00
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
BackCommand = new RelayCommand(_ =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-23 05:43:37 +08:00
|
|
|
|
ListeningKeyPressed?.Invoke(this, new ListeningKeyPressedEventArgs(_ as KeyEventArgs));
|
2016-02-12 17:20:46 +08:00
|
|
|
|
});
|
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 23:42:37 +08:00
|
|
|
|
Results = new ResultsViewModel();
|
2016-02-24 10:07:35 +08:00
|
|
|
|
ResultListBoxVisibility = Visibility.Collapsed;
|
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 23:42:37 +08:00
|
|
|
|
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 23:42:37 +08:00
|
|
|
|
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-21 23:42:37 +08:00
|
|
|
|
_textBeforeEnterContextMenuMode = QueryText;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
ContextMenu.Clear();
|
|
|
|
|
ContextMenu.AddResults(actions, pluginID);
|
2016-02-23 05:43:37 +08:00
|
|
|
|
_currentContextMenus = actions;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-24 10:07:35 +08:00
|
|
|
|
ContextMenuVisibility = Visibility.Visible;
|
|
|
|
|
ResultListBoxVisibility = Visibility.Collapsed;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
QueryText = "";
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-27 08:09:12 +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-27 08:09:12 +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 23:42:37 +08:00
|
|
|
|
ContextMenu = new ResultsViewModel();
|
2016-02-24 10:07:35 +08:00
|
|
|
|
ContextMenuVisibility = Visibility.Collapsed;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleQueryTextUpdated()
|
|
|
|
|
{
|
2016-02-27 07:43:57 +08:00
|
|
|
|
if (_ignoreTextChange)
|
|
|
|
|
{
|
|
|
|
|
_ignoreTextChange = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
IsProgressBarTooltipVisible = false;
|
2016-02-24 10:07:35 +08:00
|
|
|
|
if (ContextMenuVisibility.IsVisible())
|
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
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
string query = QueryText.Trim();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
|
|
|
|
Query(query);
|
|
|
|
|
//reset query history index after user start new query
|
|
|
|
|
ResetQueryHistoryIndex();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
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 23:42:37 +08:00
|
|
|
|
ContextMenu.Clear();
|
|
|
|
|
var query = QueryText.ToLower();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
if (string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
2016-02-23 05:43:37 +08:00
|
|
|
|
ContextMenu.AddResults(_currentContextMenus, contextMenuId);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
List<Result> filterResults = new List<Result>();
|
2016-02-23 05:43:37 +08:00
|
|
|
|
foreach (Result contextMenu in _currentContextMenus)
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (StringMatcher.IsMatch(contextMenu.Title, query)
|
|
|
|
|
|| StringMatcher.IsMatch(contextMenu.SubTitle, query))
|
|
|
|
|
{
|
|
|
|
|
filterResults.Add(contextMenu);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-21 23:42:37 +08:00
|
|
|
|
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 23:42:37 +08:00
|
|
|
|
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(keyword))
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.RemoveResultsFor(PluginManager.NonGlobalPlugins[lastKeyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
else if (lastKeyword != keyword)
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
Results.RemoveResultsExcept(PluginManager.NonGlobalPlugins[keyword].Metadata);
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_lastQuery = query;
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
Action action = async () =>
|
2016-02-18 19:30:36 +08:00
|
|
|
|
{
|
|
|
|
|
await Task.Delay(150);
|
|
|
|
|
if (!string.IsNullOrEmpty(query.RawQuery) && query.RawQuery == _lastQuery.RawQuery && !_queryHasReturn)
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
IsProgressBarTooltipVisible = true;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
2016-02-23 05:43:37 +08:00
|
|
|
|
};
|
2016-02-18 19:30:36 +08:00
|
|
|
|
action.Invoke();
|
|
|
|
|
PluginManager.QueryForAllPlugins(query);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
IsProgressBarTooltipVisible = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetQueryHistoryIndex()
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
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-23 05:43:37 +08:00
|
|
|
|
Stopwatch.Normal($"UI update cost for {metadata.Name}",
|
2016-02-21 23:42:37 +08:00
|
|
|
|
() => { Results.AddResults(list, metadata.ID); });
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BackToSearchMode()
|
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
QueryText = _textBeforeEnterContextMenuMode;
|
2016-02-24 10:07:35 +08:00
|
|
|
|
ContextMenuVisibility = Visibility.Collapsed;
|
|
|
|
|
ResultListBoxVisibility = Visibility.Visible;
|
2016-02-27 07:43:57 +08:00
|
|
|
|
OnCursorMovedToEnd();
|
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;
|
|
|
|
|
|
2016-02-21 23:42:37 +08:00
|
|
|
|
QueryText = history.Query;
|
2016-02-27 07:43:57 +08:00
|
|
|
|
OnTextBoxSelected();
|
2016-02-12 14:21:12 +08:00
|
|
|
|
|
|
|
|
|
var executeQueryHistoryTitle = InternationalizationManager.Instance.GetTranslation("executeQuery");
|
|
|
|
|
var lastExecuteTime = InternationalizationManager.Instance.GetTranslation("lastExecuteTime");
|
2016-02-21 23:42:37 +08:00
|
|
|
|
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 = _ =>{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
QueryText = history.Query;
|
2016-02-27 07:43:57 +08:00
|
|
|
|
OnTextBoxSelected();
|
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;
|
2016-02-21 23:42:37 +08:00
|
|
|
|
IsProgressBarTooltipVisible = false;
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
|
|
|
|
list.ForEach(o =>
|
|
|
|
|
{
|
|
|
|
|
o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o) * 5;
|
|
|
|
|
});
|
|
|
|
|
if (originQuery.RawQuery == _lastQuery.RawQuery)
|
|
|
|
|
{
|
2016-02-23 05:43:37 +08:00
|
|
|
|
Application.Current.Dispatcher.Invoke(() =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
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-24 10:07:35 +08:00
|
|
|
|
ResultListBoxVisibility = Visibility.Visible;
|
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 23:42:37 +08:00
|
|
|
|
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;
|
2016-02-27 07:43:57 +08:00
|
|
|
|
public event EventHandler MainWindowVisibilityChanged;
|
|
|
|
|
|
|
|
|
|
public event EventHandler CursorMovedToEnd;
|
|
|
|
|
public void OnCursorMovedToEnd()
|
|
|
|
|
{
|
|
|
|
|
CursorMovedToEnd?.Invoke(this, new EventArgs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event EventHandler TextBoxSelected;
|
|
|
|
|
public void OnTextBoxSelected()
|
|
|
|
|
{
|
|
|
|
|
TextBoxSelected?.Invoke(this, new EventArgs());
|
|
|
|
|
}
|
2016-02-12 17:20:46 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ListeningKeyPressedEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
public KeyEventArgs KeyEventArgs
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 05:43:37 +08:00
|
|
|
|
public ListeningKeyPressedEventArgs(KeyEventArgs keyEventArgs)
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
KeyEventArgs = keyEventArgs;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|