From 7f0e735cb65d16b8f0b602090c2a5e142da52281 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Thu, 22 Dec 2022 22:10:21 +0800 Subject: [PATCH] Use data binding --- Flow.Launcher/MainWindow.xaml | 18 ++++++---- Flow.Launcher/MainWindow.xaml.cs | 23 ++----------- Flow.Launcher/ViewModel/MainViewModel.cs | 43 +++++++++++++++++++++++- 3 files changed, 56 insertions(+), 28 deletions(-) diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index 095382e76..faf9f670a 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -343,7 +343,7 @@ + Grid.ColumnSpan="{Binding ResultAreaColumn}"> @@ -397,11 +397,13 @@ x:Name="Preview" Grid.Column="1" VerticalAlignment="Stretch" - d:DataContext="{d:DesignInstance vm:ResultViewModel}" - DataContext="{Binding SelectedItem, ElementName=ResultListBox}" Style="{DynamicResource PreviewArea}" - Visibility="Collapsed"> - + Visibility="{Binding PreviewVisible, Converter={StaticResource BoolToVisibilityConverter}}"> + - + diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index a645a702c..ac360e31c 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -633,30 +633,11 @@ namespace Flow.Launcher public void PreviewReset() { - if (_settings.AlwaysPreview == true) - { - ResultArea.SetValue(Grid.ColumnSpanProperty, 1); - Preview.Visibility = Visibility.Visible; - } - else - { - ResultArea.SetValue(Grid.ColumnSpanProperty, 2); - Preview.Visibility = Visibility.Collapsed; - } + _viewModel.ResetPreview(); } public void PreviewToggle() { - - if (Preview.Visibility == Visibility.Collapsed) - { - ResultArea.SetValue(Grid.ColumnSpanProperty, 1); - Preview.Visibility = Visibility.Visible; - } - else - { - ResultArea.SetValue(Grid.ColumnSpanProperty, 2); - Preview.Visibility = Visibility.Collapsed; - } + _viewModel.TogglePreview(); } private void MoveQueryTextToEnd() diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 09bba6e5c..7db49bd79 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -104,7 +104,7 @@ namespace Flow.Launcher.ViewModel RegisterResultsUpdatedEvent(); RegisterClockAndDateUpdateAsync(); - SetOpenResultModifiers(); + SetOpenResultModifiers(); // TODO? } private void RegisterViewUpdate() @@ -424,6 +424,43 @@ namespace Flow.Launcher.ViewModel Settings.MaxResultsToShow -= 1; } + [RelayCommand] + public void TogglePreview() + { + if (!PreviewVisible) + { + ShowPreview(); + } + else + { + HidePreview(); + } + } + + private void ShowPreview() + { + ResultAreaColumn = 1; + PreviewVisible = true; + } + + private void HidePreview() + { + ResultAreaColumn = 2; + PreviewVisible = false; + } + + public void ResetPreview() + { + if (Settings.AlwaysPreview == true) + { + ShowPreview(); + } + else + { + HidePreview(); + } + } + /// /// we need move cursor to end when we manually changed query /// but we don't want to move cursor to end when query is updated from TextBox @@ -519,6 +556,10 @@ namespace Flow.Launcher.ViewModel public bool StartWithEnglishMode => Settings.AlwaysStartEn; + public bool PreviewVisible { get; set; } = false; + + public int ResultAreaColumn { get; set; } = 1; + #endregion public void Query()