From ba8bb3a3b89ad9d81cf568011c3c71658d385ff7 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 22 Apr 2023 17:06:38 +0800 Subject: [PATCH] Fix switching preview logic --- Flow.Launcher/ViewModel/MainViewModel.cs | 59 +++++++++++++++++------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 871dd723c..59696aaa6 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -579,18 +579,24 @@ namespace Flow.Launcher.ViewModel { if (Settings.AlwaysPreview == true && PreviewVisible) { + // Only hit this line at first preview toggle after toggle on Flow HideInternalPreview(); // When Always preview, toggle off rather than open external } - else if (!ExternalPreviewOpen) - { - _ = OpenQuickLookPreviewAsync(path); - } else { - _ = CloseQuickLookPreviewAsync(); + ToggleExternalPreview(path); } } - else if (!PreviewVisible) + else + { + // Fallback + ToggleInternalPreview(); + } + } + + private void ToggleInternalPreview() + { + if (!PreviewVisible) { ShowInternalPreview(); } @@ -600,6 +606,18 @@ namespace Flow.Launcher.ViewModel } } + private void ToggleExternalPreview(string path) + { + if (!ExternalPreviewOpen) + { + _ = OpenQuickLookPreviewAsync(path); + } + else + { + _ = CloseQuickLookPreviewAsync(); + } + } + private void ShowInternalPreview() { ResultAreaColumn = 1; @@ -629,21 +647,30 @@ namespace Flow.Launcher.ViewModel { if (Settings.UseQuickLook && CanExternalPreviewSelectedResult(out var path)) { - _ = ToggleQuickLookPreviewAsync(path, ExternalPreviewOpen); - if (PreviewVisible) + // Should use external preview for selected result + if (ExternalPreviewOpen) { + _ = ToggleQuickLookPreviewAsync(path, true); + } + else if(PreviewVisible) + { + // When internal is open and select a result that should use external preview + _ = OpenQuickLookPreviewAsync(path); HideInternalPreview(); } } - else if (PreviewVisible) - { - Results.SelectedItem?.LoadPreviewImage(); - } else { - // When external is open and select a result that can't be previewed by external program - _ = CloseQuickLookPreviewAsync(); - ShowInternalPreview(); + if (PreviewVisible) + { + Results.SelectedItem?.LoadPreviewImage(); + } + else if (ExternalPreviewOpen) + { + // When external is open and select a result that can't use external preview + _ = CloseQuickLookPreviewAsync(); + ShowInternalPreview(); + } } } @@ -677,7 +704,7 @@ namespace Flow.Launcher.ViewModel private bool CanExternalPreviewSelectedResult(out string path) { path = Results.SelectedItem?.Result?.Preview.FilePath; - return string.IsNullOrEmpty(path); + return !string.IsNullOrEmpty(path); } #endregion