ActionPanel -> ContextMenu

part of refactoring for PR #494
This commit is contained in:
bao-qian 2016-02-21 14:40:10 +00:00
parent d5696010d9
commit 927277a6cd
5 changed files with 49 additions and 63 deletions

View File

@ -39,7 +39,7 @@
</Line> </Line>
<ContentControl Content="{Binding Results}" Visibility="{Binding IsResultListBoxVisible,Converter={StaticResource VisibilityConverter}}"> <ContentControl Content="{Binding Results}" Visibility="{Binding IsResultListBoxVisible,Converter={StaticResource VisibilityConverter}}">
</ContentControl> </ContentControl>
<ContentControl Content="{Binding ActionPanel}" Visibility="{Binding IsActionPanelVisible,Converter={StaticResource VisibilityConverter}}"> <ContentControl Content="{Binding ContextMenu}" Visibility="{Binding IsContextMenuVisible,Converter={StaticResource VisibilityConverter}}">
</ContentControl> </ContentControl>
</StackPanel> </StackPanel>
</Border> </Border>

View File

@ -181,7 +181,7 @@ namespace Wox
o.PluginID = plugin.ID; o.PluginID = plugin.ID;
}); });
this.MainVM.ShowActionPanel(results, plugin.ID); this.MainVM.ShowContextMenu(results, plugin.ID);
} }
} }

View File

@ -17,9 +17,9 @@
<DataTemplate.DataType> <DataTemplate.DataType>
<x:Type TypeName="vm:ResultItemViewModel" /> <x:Type TypeName="vm:ResultItemViewModel" />
</DataTemplate.DataType> </DataTemplate.DataType>
<Button Command="{Binding OpenResultCommand}"> <Button Command="{Binding OpenResultListBoxItemCommand}">
<Button.InputBindings> <Button.InputBindings>
<MouseBinding Command="{Binding OpenResultActionPanelCommand}" MouseAction="RightClick"></MouseBinding> <MouseBinding Command="{Binding OpenContextMenuItemCommand}" MouseAction="RightClick"></MouseBinding>
</Button.InputBindings> </Button.InputBindings>
<Button.Template> <Button.Template>
<ControlTemplate> <ControlTemplate>

View File

@ -21,11 +21,10 @@ namespace Wox.ViewModel
{ {
#region Private Fields #region Private Fields
private ResultsViewModel _actionPanel;
private string _queryText; private string _queryText;
private bool _isVisible; private bool _isVisible;
private bool _isResultListBoxVisible; private bool _isResultListBoxVisible;
private bool _isActionPanelVisible; private bool _isContextMenuVisible;
private bool _isProgressBarVisible; private bool _isProgressBarVisible;
private bool _isProgressBarTooltipVisible; private bool _isProgressBarTooltipVisible;
private bool _selectAllText; private bool _selectAllText;
@ -46,7 +45,7 @@ namespace Wox.ViewModel
public MainViewModel() public MainViewModel()
{ {
this.InitializeResultListBox(); this.InitializeResultListBox();
this.InitializeActionPanel(); this.InitializeContextMenu();
this.InitializeKeyCommands(); this.InitializeKeyCommands();
this._queryHasReturn = false; this._queryHasReturn = false;
@ -58,13 +57,7 @@ namespace Wox.ViewModel
public ResultsViewModel Results { get; private set; } public ResultsViewModel Results { get; private set; }
public ResultsViewModel ActionPanel public ResultsViewModel ContextMenu { get; private set; }
{
get
{
return this._actionPanel;
}
}
public string QueryText public string QueryText
{ {
@ -118,7 +111,7 @@ namespace Wox.ViewModel
this._isVisible = value; this._isVisible = value;
OnPropertyChanged("IsVisible"); OnPropertyChanged("IsVisible");
if (!value && this.IsActionPanelVisible) if (!value && this.IsContextMenuVisible)
{ {
this.BackToSearchMode(); this.BackToSearchMode();
} }
@ -138,16 +131,16 @@ namespace Wox.ViewModel
} }
} }
public bool IsActionPanelVisible public bool IsContextMenuVisible
{ {
get get
{ {
return this._isActionPanelVisible; return this._isContextMenuVisible;
} }
set set
{ {
this._isActionPanelVisible = value; this._isContextMenuVisible = value;
OnPropertyChanged("IsActionPanelVisible"); OnPropertyChanged("IsContextMenuVisible");
} }
} }
@ -284,7 +277,7 @@ namespace Wox.ViewModel
this.EscCommand = new RelayCommand((parameter) => this.EscCommand = new RelayCommand((parameter) =>
{ {
if (this.IsActionPanelVisible) if (this.IsContextMenuVisible)
{ {
this.BackToSearchMode(); this.BackToSearchMode();
} }
@ -298,9 +291,9 @@ namespace Wox.ViewModel
this.SelectNextItemCommand = new RelayCommand((parameter) => this.SelectNextItemCommand = new RelayCommand((parameter) =>
{ {
if (this.IsActionPanelVisible) if (this.IsContextMenuVisible)
{ {
this._actionPanel.SelectNextResult(); this.ContextMenu.SelectNextResult();
} }
else else
{ {
@ -312,9 +305,9 @@ namespace Wox.ViewModel
this.SelectPrevItemCommand = new RelayCommand((parameter) => this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{ {
if (this.IsActionPanelVisible) if (this.IsContextMenuVisible)
{ {
this._actionPanel.SelectPrevResult(); this.ContextMenu.SelectPrevResult();
} }
else else
{ {
@ -326,13 +319,13 @@ namespace Wox.ViewModel
this.CtrlOCommand = new RelayCommand((parameter) => this.CtrlOCommand = new RelayCommand((parameter) =>
{ {
if (this.IsActionPanelVisible) if (this.IsContextMenuVisible)
{ {
BackToSearchMode(); BackToSearchMode();
} }
else else
{ {
ShowActionPanel(this.Results.SelectedResult.RawResult); ShowContextMenu(this.Results.SelectedResult.RawResult);
} }
}); });
@ -374,9 +367,9 @@ namespace Wox.ViewModel
this.ShiftEnterCommand = new RelayCommand((parameter) => this.ShiftEnterCommand = new RelayCommand((parameter) =>
{ {
if (!this.IsActionPanelVisible && null != this.Results.SelectedResult) if (!this.IsContextMenuVisible && null != this.Results.SelectedResult)
{ {
this.ShowActionPanel(this.Results.SelectedResult.RawResult); this.ShowContextMenu(this.Results.SelectedResult.RawResult);
} }
}); });
@ -392,7 +385,7 @@ namespace Wox.ViewModel
if (null != this.Results.SelectedResult) if (null != this.Results.SelectedResult)
{ {
this.Results.SelectedResult.OpenResultCommand.Execute(null); this.Results.SelectedResult.OpenResultListBoxItemCommand.Execute(null);
} }
}); });
@ -412,13 +405,13 @@ namespace Wox.ViewModel
this.IsResultListBoxVisible = false; this.IsResultListBoxVisible = false;
} }
private void ShowActionPanel(Result result) private void ShowContextMenu(Result result)
{ {
if (result == null) return; if (result == null) return;
this.ShowActionPanel(result, PluginManager.GetContextMenusForPlugin(result)); this.ShowContextMenu(result, PluginManager.GetContextMenusForPlugin(result));
} }
private void ShowActionPanel(Result result, List<Result> actions) private void ShowContextMenu(Result result, List<Result> actions)
{ {
actions.ForEach(o => actions.ForEach(o =>
{ {
@ -429,18 +422,18 @@ namespace Wox.ViewModel
actions.Add(GetTopMostContextMenu(result)); actions.Add(GetTopMostContextMenu(result));
this.DisplayActionPanel(actions, result.PluginID); this.DisplayContextMenu(actions, result.PluginID);
} }
private void DisplayActionPanel(List<Result> actions, string pluginID) private void DisplayContextMenu(List<Result> actions, string pluginID)
{ {
_textBeforeEnterContextMenuMode = this.QueryText; _textBeforeEnterContextMenuMode = this.QueryText;
this._actionPanel.Clear(); this.ContextMenu.Clear();
this._actionPanel.AddResults(actions, pluginID); this.ContextMenu.AddResults(actions, pluginID);
CurrentContextMenus = actions; CurrentContextMenus = actions;
this.IsActionPanelVisible = true; this.IsContextMenuVisible = true;
this.IsResultListBoxVisible = false; this.IsResultListBoxVisible = false;
this.QueryText = ""; this.QueryText = "";
@ -476,10 +469,10 @@ namespace Wox.ViewModel
} }
} }
private void InitializeActionPanel() private void InitializeContextMenu()
{ {
this._actionPanel = new ResultsViewModel(); this.ContextMenu = new ResultsViewModel();
this.IsActionPanelVisible = false; this.IsContextMenuVisible = false;
} }
private void HandleQueryTextUpdated() private void HandleQueryTextUpdated()
@ -487,9 +480,9 @@ namespace Wox.ViewModel
if (_ignoreTextChange) { _ignoreTextChange = false; return; } if (_ignoreTextChange) { _ignoreTextChange = false; return; }
this.IsProgressBarTooltipVisible = false; this.IsProgressBarTooltipVisible = false;
if (this.IsActionPanelVisible) if (this.IsContextMenuVisible)
{ {
QueryActionPanel(); QueryContextMenu();
} }
else else
{ {
@ -507,14 +500,14 @@ namespace Wox.ViewModel
} }
} }
private void QueryActionPanel() private void QueryContextMenu()
{ {
var contextMenuId = "Context Menu Id"; var contextMenuId = "Context Menu Id";
this._actionPanel.Clear(); this.ContextMenu.Clear();
var query = this.QueryText.ToLower(); var query = this.QueryText.ToLower();
if (string.IsNullOrEmpty(query)) if (string.IsNullOrEmpty(query))
{ {
this._actionPanel.AddResults(CurrentContextMenus, contextMenuId); this.ContextMenu.AddResults(CurrentContextMenus, contextMenuId);
} }
else else
{ {
@ -527,7 +520,7 @@ namespace Wox.ViewModel
filterResults.Add(contextMenu); filterResults.Add(contextMenu);
} }
} }
this._actionPanel.AddResults(filterResults, contextMenuId); this.ContextMenu.AddResults(filterResults, contextMenuId);
} }
} }
@ -599,7 +592,7 @@ namespace Wox.ViewModel
private void BackToSearchMode() private void BackToSearchMode()
{ {
this.QueryText = _textBeforeEnterContextMenuMode; this.QueryText = _textBeforeEnterContextMenuMode;
this.IsActionPanelVisible = false; this.IsContextMenuVisible = false;
this.IsResultListBoxVisible = true; this.IsResultListBoxVisible = true;
this.CaretIndex = this.QueryText.Length; this.CaretIndex = this.QueryText.Length;
} }
@ -663,9 +656,9 @@ namespace Wox.ViewModel
} }
} }
public void ShowActionPanel(List<Result> actions, string pluginID) public void ShowContextMenu(List<Result> actions, string pluginID)
{ {
this.DisplayActionPanel(actions, pluginID); this.DisplayContextMenu(actions, pluginID);
} }
#endregion #endregion

View File

@ -25,11 +25,12 @@ namespace Wox.ViewModel
public ResultItemViewModel(Result result) public ResultItemViewModel(Result result)
{ {
if(null!= result) if (null != result)
{ {
this._result = result; this._result = result;
this.OpenResultCommand = new RelayCommand((parameter) => { this.OpenResultListBoxItemCommand = new RelayCommand((parameter) =>
{
bool hideWindow = result.Action(new ActionContext bool hideWindow = result.Action(new ActionContext
{ {
@ -44,7 +45,7 @@ namespace Wox.ViewModel
} }
}); });
this.OpenResultActionPanelCommand = new RelayCommand((parameter) => this.OpenContextMenuItemCommand = new RelayCommand((parameter) =>
{ {
var actions = PluginManager.GetContextMenusForPlugin(result); var actions = PluginManager.GetContextMenusForPlugin(result);
@ -104,17 +105,9 @@ namespace Wox.ViewModel
} }
} }
public RelayCommand OpenResultCommand public RelayCommand OpenResultListBoxItemCommand { get; set; }
{
get;
set;
}
public RelayCommand OpenResultActionPanelCommand public RelayCommand OpenContextMenuItemCommand { get; set; }
{
get;
set;
}
#endregion #endregion