@@ -564,8 +564,6 @@ public string PreviewHotkey
564
564
565
565
public bool PreviewVisible { get ; set ; } = false ;
566
566
567
- public bool ExternalPreviewOpen { get ; set ; } = false ;
568
-
569
567
public int ResultAreaColumn { get ; set ; } = 1 ;
570
568
571
569
#endregion
@@ -608,14 +606,24 @@ private void ToggleInternalPreview()
608
606
609
607
private void ToggleExternalPreview ( string path )
610
608
{
611
- if ( ! ExternalPreviewOpen )
612
- {
613
- _ = OpenQuickLookPreviewAsync ( path ) . ConfigureAwait ( false ) ;
614
- }
615
- else
616
- {
617
- _ = CloseQuickLookPreviewAsync ( ) . ConfigureAwait ( false ) ;
618
- }
609
+ _ = QuickLookHelper . ToggleQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
610
+ }
611
+
612
+ private void OpenExternalPreview ( string path )
613
+ {
614
+ _ = QuickLookHelper . OpenQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
615
+ }
616
+
617
+ private void CloseExternalPreview ( )
618
+ {
619
+ _ = QuickLookHelper . CloseQuickLookAsync ( ) . ConfigureAwait ( false ) ;
620
+ }
621
+
622
+ private void SwitchExternalPreview ( string path )
623
+ {
624
+ // Switches preview content
625
+ // When external is off, do nothing
626
+ _ = QuickLookHelper . SwitchQuickLookAsync ( path ) . ConfigureAwait ( false ) ;
619
627
}
620
628
621
629
private void ShowInternalPreview ( )
@@ -645,61 +653,41 @@ public void ResetPreview()
645
653
646
654
private void UpdatePreview ( )
647
655
{
648
- if ( Settings . UseQuickLook && CanExternalPreviewSelectedResult ( out var path ) )
649
- {
650
- // TODO: When always preview (internal is open) and select another result can use external preview
651
- // then switched to external, looks bad
652
- // Should use external preview for selected result
653
- if ( ExternalPreviewOpen )
654
- {
655
- _ = ToggleQuickLookPreviewAsync ( path , true ) . ConfigureAwait ( false ) ;
656
- }
657
- else if ( PreviewVisible )
658
- {
659
- // When internal is open and select a result that should use external preview
660
- _ = OpenQuickLookPreviewAsync ( path ) . ConfigureAwait ( false ) ;
661
- HideInternalPreview ( ) ;
662
- }
663
- }
664
- else
656
+ if ( Settings . UseQuickLook )
665
657
{
666
- if ( PreviewVisible )
658
+ if ( CanExternalPreviewSelectedResult ( out var path ) )
667
659
{
668
- Results . SelectedItem ? . LoadPreviewImage ( ) ;
660
+ // Should use external preview for selected result
661
+ if ( PreviewVisible )
662
+ {
663
+ // Previewing
664
+ // When internal is open and select a result that should use external preview
665
+ // External must be off when PreviewVisible
666
+ HideInternalPreview ( ) ;
667
+ OpenExternalPreview ( path ) ;
668
+ }
669
+ else
670
+ {
671
+ // Internal is off, try to switch preview content
672
+ SwitchExternalPreview ( path ) ;
673
+ }
669
674
}
670
- else if ( ExternalPreviewOpen )
675
+ else
671
676
{
672
- // When external is open and select a result that can't use external preview
673
- _ = CloseQuickLookPreviewAsync ( ) . ConfigureAwait ( false ) ;
674
- ShowInternalPreview ( ) ;
677
+ // Should use internal preview for selected result
678
+ if ( PreviewVisible )
679
+ {
680
+ Results . SelectedItem ? . LoadPreviewImage ( ) ;
681
+ }
682
+ else
683
+ {
684
+ CloseExternalPreview ( ) ; // Forcibly close, ideally should only close when it's on
685
+ }
675
686
}
676
687
}
677
- }
678
-
679
- private async Task ToggleQuickLookPreviewAsync ( string path , bool switchFile = false )
680
- {
681
- bool success = await QuickLookHelper . ToggleQuickLookAsync ( path , switchFile ) ;
682
- if ( success )
683
- {
684
- ExternalPreviewOpen = switchFile || ! ExternalPreviewOpen ;
685
- }
686
- }
687
-
688
- private async Task OpenQuickLookPreviewAsync ( string path )
689
- {
690
- bool success = await QuickLookHelper . OpenQuickLookAsync ( path ) ;
691
- if ( success )
692
- {
693
- ExternalPreviewOpen = true ;
694
- }
695
- }
696
-
697
- private async Task CloseQuickLookPreviewAsync ( )
698
- {
699
- bool success = await QuickLookHelper . CloseQuickLookAsync ( ) ;
700
- if ( success )
688
+ else if ( PreviewVisible )
701
689
{
702
- ExternalPreviewOpen = false ;
690
+ Results . SelectedItem ? . LoadPreviewImage ( ) ;
703
691
}
704
692
}
705
693
@@ -1112,10 +1100,7 @@ public async void Hide()
1112
1100
// Trick for no delay
1113
1101
MainWindowOpacity = 0 ;
1114
1102
1115
- if ( ExternalPreviewOpen )
1116
- {
1117
- _ = CloseQuickLookPreviewAsync ( ) . ConfigureAwait ( false ) ;
1118
- }
1103
+ CloseExternalPreview ( ) ;
1119
1104
1120
1105
if ( ! SelectedIsFromQueryResults ( ) )
1121
1106
{
0 commit comments