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}"
Icon="Images\app.png"
AllowsTransparency="True"
Visibility="{Binding IsVisible,Converter={converters:VisibilityConverter}}"
Visibility="{Binding WindowVisibility}"
PreviewKeyDown="Window_PreviewKeyDown" d:DataContext="{d:DesignInstance vm:MainViewModel, IsDesignTimeCreatable=True}">
<Window.Resources>
<DataTemplate DataType="{x:Type vm:ResultsViewModel}">
<wox:ResultListBox></wox:ResultListBox>
</DataTemplate>
<converters:VisibilityConverter x:Key="VisibilityConverter" />
</Window.Resources>
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="Border_OnMouseDown">
<StackPanel Orientation="Vertical">
@ -32,14 +31,14 @@
PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True"
x:Name="tbQuery" />
<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>
<ToolTip IsOpen="{Binding IsProgressBarTooltipVisible}"></ToolTip>
</Line.ToolTip>
</Line>
<ContentControl Content="{Binding Results}" Visibility="{Binding IsResultListBoxVisible,Converter={StaticResource VisibilityConverter}}">
<ContentControl Content="{Binding Results}" Visibility="{Binding ResultListBoxVisibility}">
</ContentControl>
<ContentControl Content="{Binding ContextMenu}" Visibility="{Binding IsContextMenuVisible,Converter={StaticResource VisibilityConverter}}">
<ContentControl Content="{Binding ContextMenu}" Visibility="{Binding ContextMenuVisibility}">
</ContentControl>
</StackPanel>
</Border>

View File

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

View File

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

View File

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