updates MainWindow visibility bindings to use System.Windows.Visibility instead of bool

This commit is contained in:
rmterra 2016-02-21 18:27:05 -03:00
parent 5919dd998b
commit cb952b0d3a
4 changed files with 90 additions and 86 deletions

View File

@ -18,13 +18,12 @@
Style="{DynamicResource WindowStyle}" Style="{DynamicResource WindowStyle}"
Icon="Images\app.png" Icon="Images\app.png"
AllowsTransparency="True" AllowsTransparency="True"
Visibility="{Binding IsVisible,Converter={converters:VisibilityConverter}}" Visibility="{Binding WindowVisibility}"
PreviewKeyDown="Window_PreviewKeyDown" d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}"> PreviewKeyDown="Window_PreviewKeyDown" d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}">
<Window.Resources> <Window.Resources>
<DataTemplate DataType="{x:Type vm:ResultsViewModel}"> <DataTemplate DataType="{x:Type vm:ResultsViewModel}">
<wox:ResultListBox></wox:ResultListBox> <wox:ResultListBox></wox:ResultListBox>
</DataTemplate> </DataTemplate>
<converters:VisibilityConverter x:Key="VisibilityConverter" />
</Window.Resources> </Window.Resources>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="Border_OnMouseDown"> <Border Style="{DynamicResource WindowBorderStyle}" MouseDown="Border_OnMouseDown">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
@ -32,14 +31,14 @@
PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True" PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True"
x:Name="tbQuery" /> x:Name="tbQuery" />
<Line Style="{DynamicResource PendingLineStyle}" x:Name="progressBar" Y1="0" Y2="0" X2="100" Height="2" StrokeThickness="1" <Line Style="{DynamicResource PendingLineStyle}" x:Name="progressBar" Y1="0" Y2="0" X2="100" Height="2" StrokeThickness="1"
Visibility="{Binding IsProgressBarVisible,Converter={StaticResource VisibilityConverter}}"> Visibility="{Binding ProgressBarVisibility}">
<Line.ToolTip> <Line.ToolTip>
<ToolTip IsOpen="{Binding IsProgressBarTooltipVisible}"></ToolTip> <ToolTip IsOpen="{Binding IsProgressBarTooltipVisible}"></ToolTip>
</Line.ToolTip> </Line.ToolTip>
</Line> </Line>
<ContentControl Content="{Binding Results}" Visibility="{Binding IsResultListBoxVisible,Converter={StaticResource VisibilityConverter}}"> <ContentControl Content="{Binding Results}" Visibility="{Binding ResultListBoxVisibility}">
</ContentControl> </ContentControl>
<ContentControl Content="{Binding ContextMenu}" Visibility="{Binding IsContextMenuVisible,Converter={StaticResource VisibilityConverter}}"> <ContentControl Content="{Binding ContextMenu}" Visibility="{Binding ContextMenuVisibility}">
</ContentControl> </ContentControl>
</StackPanel> </StackPanel>
</Border> </Border>

View File

@ -16,6 +16,7 @@ using KeyEventArgs = System.Windows.Input.KeyEventArgs;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
using Wox.ViewModel; using Wox.ViewModel;
using Wox.Plugin; using Wox.Plugin;
using Wox.Extensions;
namespace Wox namespace Wox
{ {
@ -76,7 +77,7 @@ namespace Wox
} }
else if(eve.PropertyName == "IsVisible") else if(eve.PropertyName == "IsVisible")
{ {
if (vm.IsVisible) if (vm.WindowVisibility.IsVisible())
{ {
this.tbQuery.Focus(); this.tbQuery.Focus();
} }

View File

@ -18,6 +18,7 @@ using Wox.Helper;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
using Wox.ViewModel; using Wox.ViewModel;
using Wox.Extensions;
namespace Wox namespace Wox
{ {
@ -127,12 +128,12 @@ namespace Wox
public void StartLoadingBar() public void StartLoadingBar()
{ {
this.MainVM.IsProgressBarVisible = true; this.MainVM.ProgressBarVisibility = Visibility.Visible;
} }
public void StopLoadingBar() public void StopLoadingBar()
{ {
this.MainVM.IsProgressBarVisible = false; this.MainVM.ProgressBarVisibility = Visibility.Collapsed;
} }
public void InstallPlugin(string path) public void InstallPlugin(string path)
@ -201,13 +202,13 @@ namespace Wox
{ {
UserSettingStorage.Instance.WindowLeft = this.MainVM.Left; UserSettingStorage.Instance.WindowLeft = this.MainVM.Left;
UserSettingStorage.Instance.WindowTop = this.MainVM.Top; UserSettingStorage.Instance.WindowTop = this.MainVM.Top;
this.MainVM.IsVisible = false; this.MainVM.WindowVisibility = Visibility.Collapsed;
} }
private void ShowWox(bool selectAll = true) private void ShowWox(bool selectAll = true)
{ {
UserSettingStorage.Instance.IncreaseActivateTimes(); UserSettingStorage.Instance.IncreaseActivateTimes();
this.MainVM.IsVisible = true; this.MainVM.WindowVisibility = Visibility.Visible;
this.MainVM.SelectAllText = true; this.MainVM.SelectAllText = true;
} }
@ -277,7 +278,7 @@ namespace Wox
private void ToggleWox() private void ToggleWox()
{ {
if (!MainVM.IsVisible) if (MainVM.WindowVisibility.IsNotVisible())
{ {
ShowWox(); ShowWox();
} }

View File

@ -14,6 +14,7 @@ using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
using Wox.Storage; using Wox.Storage;
using Wox.Extensions;
namespace Wox.ViewModel namespace Wox.ViewModel
{ {
@ -22,16 +23,18 @@ namespace Wox.ViewModel
#region Private Fields #region Private Fields
private string _queryText; private string _queryText;
private bool _isVisible;
private bool _isResultListBoxVisible;
private bool _isContextMenuVisible;
private bool _isProgressBarVisible;
private bool _isProgressBarTooltipVisible; private bool _isProgressBarTooltipVisible;
private bool _selectAllText; private bool _selectAllText;
private int _caretIndex; private int _caretIndex;
private double _left; private double _left;
private double _top; private double _top;
private Visibility _contextMenuVisibility;
private Visibility _progressBarVisibility;
private Visibility _resultListBoxVisibility;
private Visibility _windowVisibility;
private bool _queryHasReturn; private bool _queryHasReturn;
private Query _lastQuery = new Query(); private Query _lastQuery = new Query();
private bool _ignoreTextChange; private bool _ignoreTextChange;
@ -100,63 +103,6 @@ namespace Wox.ViewModel
} }
} }
public bool IsVisible
{
get
{
return this._isVisible;
}
set
{
this._isVisible = value;
OnPropertyChanged("IsVisible");
if (!value && this.IsContextMenuVisible)
{
this.BackToSearchMode();
}
}
}
public bool IsResultListBoxVisible
{
get
{
return this._isResultListBoxVisible;
}
set
{
this._isResultListBoxVisible = value;
OnPropertyChanged("IsResultListBoxVisible");
}
}
public bool IsContextMenuVisible
{
get
{
return this._isContextMenuVisible;
}
set
{
this._isContextMenuVisible = value;
OnPropertyChanged("IsContextMenuVisible");
}
}
public bool IsProgressBarVisible
{
get
{
return this._isProgressBarVisible;
}
set
{
this._isProgressBarVisible = value;
OnPropertyChanged("IsProgressBarVisible");
}
}
public bool IsProgressBarTooltipVisible public bool IsProgressBarTooltipVisible
{ {
get get
@ -196,6 +142,63 @@ namespace Wox.ViewModel
} }
} }
public Visibility ContextMenuVisibility
{
get
{
return this._contextMenuVisibility;
}
set
{
this._contextMenuVisibility = value;
OnPropertyChanged("ContextMenuVisibility");
}
}
public Visibility ProgressBarVisibility
{
get
{
return this._progressBarVisibility;
}
set
{
this._progressBarVisibility = value;
OnPropertyChanged("ProgressBarVisibility");
}
}
public Visibility ResultListBoxVisibility
{
get
{
return this._resultListBoxVisibility;
}
set
{
this._resultListBoxVisibility = value;
OnPropertyChanged("ResultListBoxVisibility");
}
}
public Visibility WindowVisibility
{
get
{
return this._windowVisibility;
}
set
{
this._windowVisibility = value;
OnPropertyChanged("WindowVisibility");
if (value.IsNotVisible() && this.ContextMenuVisibility.IsVisible())
{
this.BackToSearchMode();
}
}
}
public ICommand EscCommand public ICommand EscCommand
{ {
get; get;
@ -277,13 +280,13 @@ namespace Wox.ViewModel
this.EscCommand = new RelayCommand((parameter) => this.EscCommand = new RelayCommand((parameter) =>
{ {
if (this.IsContextMenuVisible) if (this.ContextMenuVisibility.IsVisible())
{ {
this.BackToSearchMode(); this.BackToSearchMode();
} }
else else
{ {
this.IsVisible = false; this.WindowVisibility = Visibility.Collapsed;
} }
}); });
@ -291,7 +294,7 @@ namespace Wox.ViewModel
this.SelectNextItemCommand = new RelayCommand((parameter) => this.SelectNextItemCommand = new RelayCommand((parameter) =>
{ {
if (this.IsContextMenuVisible) if (this.ContextMenuVisibility.IsVisible())
{ {
this.ContextMenu.SelectNextResult(); this.ContextMenu.SelectNextResult();
} }
@ -305,7 +308,7 @@ namespace Wox.ViewModel
this.SelectPrevItemCommand = new RelayCommand((parameter) => this.SelectPrevItemCommand = new RelayCommand((parameter) =>
{ {
if (this.IsContextMenuVisible) if (this.ContextMenuVisibility.IsVisible())
{ {
this.ContextMenu.SelectPrevResult(); this.ContextMenu.SelectPrevResult();
} }
@ -319,7 +322,7 @@ namespace Wox.ViewModel
this.CtrlOCommand = new RelayCommand((parameter) => this.CtrlOCommand = new RelayCommand((parameter) =>
{ {
if (this.IsContextMenuVisible) if (this.ContextMenuVisibility.IsVisible())
{ {
BackToSearchMode(); BackToSearchMode();
} }
@ -367,7 +370,7 @@ namespace Wox.ViewModel
this.ShiftEnterCommand = new RelayCommand((parameter) => this.ShiftEnterCommand = new RelayCommand((parameter) =>
{ {
if (!this.IsContextMenuVisible && null != this.Results.SelectedResult) if (this.ContextMenuVisibility.IsNotVisible() && null != this.Results.SelectedResult)
{ {
this.ShowContextMenu(this.Results.SelectedResult.RawResult); this.ShowContextMenu(this.Results.SelectedResult.RawResult);
} }
@ -402,7 +405,7 @@ namespace Wox.ViewModel
private void InitializeResultListBox() private void InitializeResultListBox()
{ {
this.Results = new ResultsViewModel(); this.Results = new ResultsViewModel();
this.IsResultListBoxVisible = false; this.ResultListBoxVisibility = Visibility.Collapsed;
} }
private void ShowContextMenu(Result result) private void ShowContextMenu(Result result)
@ -433,8 +436,8 @@ namespace Wox.ViewModel
this.ContextMenu.AddResults(actions, pluginID); this.ContextMenu.AddResults(actions, pluginID);
CurrentContextMenus = actions; CurrentContextMenus = actions;
this.IsContextMenuVisible = true; this.ContextMenuVisibility = Visibility.Visible;
this.IsResultListBoxVisible = false; this.ResultListBoxVisibility = Visibility.Collapsed;
this.QueryText = ""; this.QueryText = "";
} }
@ -472,7 +475,7 @@ namespace Wox.ViewModel
private void InitializeContextMenu() private void InitializeContextMenu()
{ {
this.ContextMenu = new ResultsViewModel(); this.ContextMenu = new ResultsViewModel();
this.IsContextMenuVisible = false; this.ContextMenuVisibility = Visibility.Collapsed;
} }
private void HandleQueryTextUpdated() private void HandleQueryTextUpdated()
@ -480,7 +483,7 @@ namespace Wox.ViewModel
if (_ignoreTextChange) { _ignoreTextChange = false; return; } if (_ignoreTextChange) { _ignoreTextChange = false; return; }
this.IsProgressBarTooltipVisible = false; this.IsProgressBarTooltipVisible = false;
if (this.IsContextMenuVisible) if (this.ContextMenuVisibility.IsVisible())
{ {
QueryContextMenu(); QueryContextMenu();
} }
@ -592,8 +595,8 @@ namespace Wox.ViewModel
private void BackToSearchMode() private void BackToSearchMode()
{ {
this.QueryText = _textBeforeEnterContextMenuMode; this.QueryText = _textBeforeEnterContextMenuMode;
this.IsContextMenuVisible = false; this.ContextMenuVisibility = Visibility.Collapsed;
this.IsResultListBoxVisible = true; this.ResultListBoxVisibility = Visibility.Visible;
this.CaretIndex = this.QueryText.Length; this.CaretIndex = this.QueryText.Length;
} }
@ -652,7 +655,7 @@ namespace Wox.ViewModel
if (list.Count > 0) if (list.Count > 0)
{ {
this.IsResultListBoxVisible = true; this.ResultListBoxVisibility = Visibility.Visible;
} }
} }