|
1 |
| -using System; |
| 1 | +using System; |
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Threading;
|
@@ -601,20 +601,57 @@ public bool InternalPreviewVisible
|
601 | 601 |
|
602 | 602 | public int ResultAreaColumn { get; set; } = ResultAreaColumnPreviewShown;
|
603 | 603 |
|
604 |
| - } |
605 |
| - else if(Settings.UseExternalPreview && CanExternalPreviewSelectedResult(out var path)) |
| 604 | + // This is not a reliable indicator of whether external preview is visible due to the |
| 605 | + // ability of manually closing/exiting the external preview program, and this does not inform flow that |
| 606 | + // preview is no longer available. |
| 607 | + public bool ExternalPreviewVisible { get; set; } = false; |
| 608 | + |
| 609 | + private void ShowPreview() |
| 610 | + { |
| 611 | + var useExternalPreview = PluginManager.UseExternalPreview(); |
| 612 | + |
| 613 | + if (!useExternalPreview) |
| 614 | + ShowInternalPreview(); |
| 615 | + |
| 616 | + if (useExternalPreview) |
606 | 617 | {
|
607 |
| - _ = ToggleExternalPreviewAsync(path); |
| 618 | + // Internal preview may still be on when user switches to external |
| 619 | + if (InternalPreviewVisible) |
| 620 | + HideInternalPreview(); |
| 621 | + |
| 622 | + if (CanExternalPreviewSelectedResult(out var path)) |
| 623 | + OpenExternalPreview(path); |
608 | 624 | }
|
609 |
| - else |
| 625 | + |
| 626 | + } |
| 627 | + |
| 628 | + private void HidePreview() |
| 629 | + { |
| 630 | + if (PluginManager.UseExternalPreview()) |
| 631 | + CloseExternalPreview(); |
| 632 | + |
| 633 | + if (InternalPreviewVisible) |
| 634 | + HideInternalPreview(); |
| 635 | + } |
| 636 | + |
| 637 | + [RelayCommand] |
| 638 | + private void TogglePreview() |
| 639 | + { |
| 640 | + switch (InternalPreviewVisible || ExternalPreviewVisible) |
610 | 641 | {
|
611 |
| - ShowInternalPreview(); |
| 642 | + case true: |
| 643 | + HidePreview(); |
| 644 | + break; |
| 645 | + |
| 646 | + case false: |
| 647 | + ShowPreview(); |
| 648 | + break; |
612 | 649 | }
|
613 | 650 | }
|
614 | 651 |
|
615 | 652 | private void ToggleInternalPreview()
|
616 | 653 | {
|
617 |
| - if (!PreviewVisible) |
| 654 | + if (!InternalPreviewVisible) |
618 | 655 | {
|
619 | 656 | ShowInternalPreview();
|
620 | 657 | }
|
@@ -643,45 +680,53 @@ private void SwitchExternalPreview(string path, bool sendFailToast = true)
|
643 | 680 |
|
644 | 681 | private void ShowInternalPreview()
|
645 | 682 | {
|
646 |
| - ResultAreaColumn = 1; |
647 |
| - PreviewVisible = true; |
| 683 | + ResultAreaColumn = ResultAreaColumnPreviewShown; |
648 | 684 | Results.SelectedItem?.LoadPreviewImage();
|
649 | 685 | }
|
650 | 686 |
|
651 | 687 | private void HideInternalPreview()
|
652 | 688 | {
|
653 |
| - ResultAreaColumn = 3; |
654 |
| - PreviewVisible = false; |
| 689 | + ResultAreaColumn = ResultAreaColumnPreviewHidden; |
655 | 690 | }
|
656 | 691 |
|
657 | 692 | public void ResetPreview()
|
658 | 693 | {
|
659 |
| - if (Settings.AlwaysPreview == true && !PreviewVisible) |
| 694 | + switch (Settings.AlwaysPreview) |
660 | 695 | {
|
661 |
| - ShowInternalPreview(); |
662 |
| - } |
663 |
| - else |
664 |
| - { |
665 |
| - HideInternalPreview(); |
| 696 | + case true: |
| 697 | + ShowPreview(); |
| 698 | + break; |
| 699 | + |
| 700 | + case false: |
| 701 | + HidePreview(); |
| 702 | + break; |
666 | 703 | }
|
667 | 704 | }
|
668 | 705 |
|
669 | 706 | private void UpdatePreview()
|
670 | 707 | {
|
671 |
| - if (PreviewVisible) |
| 708 | + if (InternalPreviewVisible) |
672 | 709 | {
|
673 | 710 | Results.SelectedItem?.LoadPreviewImage();
|
| 711 | + return; |
674 | 712 | }
|
675 |
| - else if (Settings.UseExternalPreview) |
| 713 | + |
| 714 | + switch (PluginManager.UseExternalPreview()) |
676 | 715 | {
|
677 |
| - if (CanExternalPreviewSelectedResult(out var path)) |
678 |
| - { |
679 |
| - _ = SwitchExternalPreviewAsync(path, false); |
680 |
| - } |
681 |
| - else |
682 |
| - { |
683 |
| - _ = CloseExternalPreviewAsync(); |
684 |
| - } |
| 716 | + case true |
| 717 | + when ExternalPreviewVisible && CanExternalPreviewSelectedResult(out var path): |
| 718 | + SwitchExternalPreview(path, false); |
| 719 | + break; |
| 720 | + |
| 721 | + case true |
| 722 | + when !ExternalPreviewVisible && Settings.AlwaysPreview && CanExternalPreviewSelectedResult(out var path): |
| 723 | + ShowPreview(); |
| 724 | + break; |
| 725 | + |
| 726 | + case true |
| 727 | + when !CanExternalPreviewSelectedResult(out var _): |
| 728 | + HidePreview(); |
| 729 | + break; |
685 | 730 | }
|
686 | 731 | }
|
687 | 732 |
|
@@ -1097,8 +1142,8 @@ public async void Hide()
|
1097 | 1142 | // Trick for no delay
|
1098 | 1143 | MainWindowOpacity = 0;
|
1099 | 1144 |
|
1100 |
| - if (Settings.UseExternalPreview) |
1101 |
| - _ = CloseExternalPreviewAsync(); |
| 1145 | + if (ExternalPreviewVisible) |
| 1146 | + CloseExternalPreview(); |
1102 | 1147 |
|
1103 | 1148 | if (!SelectedIsFromQueryResults())
|
1104 | 1149 | {
|
|
0 commit comments