diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index 7ce73b08ec..361b621d20 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -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}"> - @@ -32,14 +31,14 @@ PreviewDragOver="TbQuery_OnPreviewDragOver" AllowDrop="True" x:Name="tbQuery" /> + Visibility="{Binding ProgressBarVisibility}"> - + - + diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 4430fd6fe9..7757b80ad4 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -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(); } diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index b0c07cd646..85384dc50a 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -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(); } diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 4acdaeebb7..38d788125e 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -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; } }