@@ -77,7 +77,7 @@ - (void)_readActiveNode;
77
77
- (void )_readFinished ;
78
78
- (NSSize )_sizeForImageRep : (NSImageRep *)rep orientation : (PGOrientation)orientation ;
79
79
- (void )_updateImageViewSizeAllowAnimation : (BOOL )flag ;
80
- - (void )_updateInfoWithNodeCount ;
80
+ - (void )_noteViewableNodeCountDidChange ;
81
81
- (void )_updateNodeIndex ;
82
82
- (void )_updateInfoPanelText ;
83
83
- (void )_runTimer ;
@@ -342,7 +342,7 @@ - (BOOL)setActiveDocument:(PGDocument *)document
342
342
[self setTimerInterval: 0 ];
343
343
if (_activeDocument) {
344
344
NSDisableScreenUpdates ();
345
- if (![_activeDocument showsThumbnails ]) [_thumbnailPanel close ];
345
+ if (![self shouldShowThumbnails ]) [_thumbnailPanel close ];
346
346
[self documentShowsThumbnailsDidChange: nil ];
347
347
PGNode *node;
348
348
PGImageView *view;
@@ -432,10 +432,22 @@ - (void)activateNode:(PGNode *)node
432
432
433
433
#pragma mark -
434
434
435
- - (BOOL )shouldShowInfo
435
+ - (BOOL )canShowInfo
436
436
{
437
437
return YES ;
438
438
}
439
+ - (BOOL )shouldShowInfo
440
+ {
441
+ return [[self activeDocument ] showsInfo ] && [self canShowInfo ];
442
+ }
443
+ - (BOOL )canShowThumbnails
444
+ {
445
+ return [[[self activeDocument ] node ] hasViewableNodeCountGreaterThan: 1 ];
446
+ }
447
+ - (BOOL )shouldShowThumbnails
448
+ {
449
+ return [[self activeDocument ] showsThumbnails ] && [self canShowThumbnails ];
450
+ }
439
451
440
452
#pragma mark -
441
453
@@ -553,10 +565,10 @@ - (void)documentWillRemoveNodes:(NSNotification *)aNotif
553
565
}
554
566
- (void )documentSortedNodesDidChange : (NSNotification *)aNotif
555
567
{
556
- [self _updateInfoWithNodeCount ];
568
+ [self _noteViewableNodeCountDidChange ];
557
569
if (![self activeNode ]) [self setActiveNode: [[[self activeDocument ] node ] sortedViewableNodeFirst: YES ] initialLocation: PGHomeLocation];
558
570
else [self _updateNodeIndex ];
559
- if ([[ self activeDocument ] showsThumbnails ]) {
571
+ if ([self shouldShowThumbnails ]) {
560
572
[[_thumbnailPanel content ] reloadData ];
561
573
[[_thumbnailPanel content ] setSelectedItem: [self activeNode ]];
562
574
}
@@ -576,55 +588,32 @@ - (void)documentNodeIsViewableDidChange:(NSNotification *)aNotif
576
588
} else if ([self activeNode ] == node) {
577
589
if (![node isViewable ] && ![self tryToGoForward: YES allowAlerts: NO ] && ![self tryToGoForward: NO allowAlerts: NO ]) [self setActiveNode: [[[self activeDocument ] node ] sortedViewableNodeFirst: YES ] initialLocation: PGHomeLocation];
578
590
}
579
- [self _updateInfoWithNodeCount ];
591
+ [self _noteViewableNodeCountDidChange ];
580
592
[self _updateNodeIndex ];
581
- if ([[ self activeDocument ] showsThumbnails ]) [[_thumbnailPanel content ] reloadItem: [node parentNode ] reloadChildren: YES ];
593
+ if ([self shouldShowThumbnails ]) [[_thumbnailPanel content ] reloadItem: [node parentNode ] reloadChildren: YES ];
582
594
}
583
595
- (void )documentNodeThumbnailDidChange : (NSNotification *)aNotif
584
596
{
585
- if ([[ self activeDocument ] showsThumbnails ]) [[_thumbnailPanel content ] reloadItem: [[aNotif userInfo ] objectForKey: PGDocumentNodeKey] reloadChildren: NO ];
597
+ if ([self shouldShowThumbnails ]) [[_thumbnailPanel content ] reloadItem: [[aNotif userInfo ] objectForKey: PGDocumentNodeKey] reloadChildren: NO ];
586
598
}
587
599
588
600
- (void )documentShowsInfoDidChange : (NSNotification *)aNotif
589
601
{
590
- if ([[self activeDocument ] showsInfo ]) [self _updateInfoWithNodeCount ];
591
- else [_infoPanel fadeOut ];
602
+ if ([self shouldShowInfo ]) {
603
+ [[_infoPanel content ] setCount: [[[self activeDocument ] node ] viewableNodeCount ]];
604
+ [_infoPanel displayOverWindow: [self window ]];
605
+ } else [_infoPanel fadeOut ];
592
606
}
593
607
- (void )documentShowsThumbnailsDidChange : (NSNotification *)aNotif
594
608
{
595
- if ([[ self activeDocument ] showsThumbnails ]) {
609
+ if ([self shouldShowThumbnails ]) {
596
610
NSDisableScreenUpdates ();
597
611
[_thumbnailPanel displayOverWindow: [self window ]];
598
612
[[_thumbnailPanel content ] reloadData ];
599
613
[[_thumbnailPanel content ] setSelectedItem: [self activeNode ]];
600
- float const panelWidth = NSWidth ([_thumbnailPanel frame ]);
601
- NSWindow *const w = [self window ];
602
- [w setMinSize: NSMakeSize (PGWindowMinSize + panelWidth, PGWindowMinSize)];
603
- NSRect currentFrame = [w frame ];
604
- if (NSWidth (currentFrame) < PGWindowMinSize + panelWidth) {
605
- currentFrame.size .width = PGWindowMinSize + panelWidth;
606
- [w setFrame: currentFrame display: YES ];
607
- }
608
- PGInset const inset = PGMakeInset (panelWidth, 0 , 0 , 0 );
609
- [clipView setBoundsInset: inset];
610
- [_findPanel setFrameInset: inset];
611
- [_graphicPanel setFrameInset: inset];
612
- [self _updateImageViewSizeAllowAnimation: NO ];
613
- [self documentReadingDirectionDidChange: nil ];
614
- [_findPanel updateFrame ];
615
- [_graphicPanel updateFrame ];
616
614
NSEnableScreenUpdates ();
617
615
} else {
618
- [clipView setBoundsInset: PGZeroInset];
619
- [_findPanel setFrameInset: PGZeroInset];
620
- [_graphicPanel setFrameInset: PGZeroInset];
621
- NSDisableScreenUpdates ();
622
- [self _updateImageViewSizeAllowAnimation: NO ];
623
- [_findPanel updateFrame ];
624
- [_graphicPanel updateFrame ];
625
- [self documentReadingDirectionDidChange: nil ];
626
- NSEnableScreenUpdates ();
627
- [[self window ] setMinSize: NSMakeSize (PGWindowMinSize, PGWindowMinSize)];
616
+ [self thumbnailPanelFrameDidChange: nil ];
628
617
[_thumbnailPanel fadeOut ];
629
618
}
630
619
}
@@ -638,7 +627,7 @@ - (void)documentReadingDirectionDidChange:(NSNotification *)aNotif
638
627
case PGMinXMinYCorner: inset.minY = [self findPanelShown ] ? NSHeight ([_findPanel frame ]) : 0 ; break ;
639
628
case PGMaxXMinYCorner: inset.minX = [self findPanelShown ] ? NSWidth ([_findPanel frame ]) : 0 ; break ;
640
629
}
641
- if ([[ self activeDocument ] showsThumbnails ]) inset.minX += NSWidth ([_thumbnailPanel frame ]);
630
+ if ([self shouldShowThumbnails ]) inset.minX += NSWidth ([_thumbnailPanel frame ]);
642
631
[_infoPanel setFrameInset: inset];
643
632
[[_infoPanel content ] setOrigin: corner];
644
633
[_infoPanel updateFrame ];
@@ -654,6 +643,38 @@ - (void)documentBaseOrientationDidChange:(NSNotification *)aNotif
654
643
655
644
#pragma mark -
656
645
646
+ - (void )thumbnailPanelFrameDidChange : (NSNotification *)aNotif
647
+ {
648
+ NSDisableScreenUpdates ();
649
+ if ([self shouldShowThumbnails ]) {
650
+ float const panelWidth = NSWidth ([_thumbnailPanel frame ]);
651
+ NSWindow *const w = [self window ];
652
+ [w setMinSize: NSMakeSize (PGWindowMinSize + panelWidth, PGWindowMinSize)];
653
+ NSRect currentFrame = [w frame ];
654
+ if (NSWidth (currentFrame) < PGWindowMinSize + panelWidth) {
655
+ currentFrame.size .width = PGWindowMinSize + panelWidth;
656
+ [w setFrame: currentFrame display: YES ];
657
+ }
658
+ PGInset const inset = PGMakeInset (panelWidth, 0 , 0 , 0 );
659
+ [clipView setBoundsInset: inset];
660
+ [_findPanel setFrameInset: inset];
661
+ [_graphicPanel setFrameInset: inset];
662
+ [self _updateImageViewSizeAllowAnimation: NO ];
663
+ [self documentReadingDirectionDidChange: nil ];
664
+ [_findPanel updateFrame ];
665
+ [_graphicPanel updateFrame ];
666
+ } else {
667
+ [clipView setBoundsInset: PGZeroInset];
668
+ [_findPanel setFrameInset: PGZeroInset];
669
+ [_graphicPanel setFrameInset: PGZeroInset];
670
+ [self _updateImageViewSizeAllowAnimation: NO ];
671
+ [_findPanel updateFrame ];
672
+ [_graphicPanel updateFrame ];
673
+ [self documentReadingDirectionDidChange: nil ];
674
+ [[self window ] setMinSize: NSMakeSize (PGWindowMinSize, PGWindowMinSize)];
675
+ }
676
+ NSEnableScreenUpdates ();
677
+ }
657
678
- (void )prefControllerBackgroundPatternColorDidChange : (NSNotification *)aNotif ;
658
679
{
659
680
[clipView setBackgroundColor: [[PGPrefController sharedPrefController ] backgroundPatternColor ]];
@@ -682,7 +703,7 @@ - (BOOL)_setActiveNode:(PGNode *)aNode
682
703
_activeNode = [aNode retain ];
683
704
[self _updateNodeIndex ];
684
705
[self _updateInfoPanelText ];
685
- if ([[ self activeDocument ] showsThumbnails ]) [[_thumbnailPanel content ] setSelectedItem: aNode];
706
+ if ([self shouldShowThumbnails ]) [[_thumbnailPanel content ] setSelectedItem: aNode];
686
707
return YES ;
687
708
}
688
709
- (void )_readActiveNode
@@ -742,12 +763,10 @@ - (void)_updateImageViewSizeAllowAnimation:(BOOL)flag
742
763
{
743
764
[_imageView setSize: [self _sizeForImageRep: [_imageView rep ] orientation: [_imageView orientation ]] allowAnimation: flag];
744
765
}
745
- - (void )_updateInfoWithNodeCount
766
+ - (void )_noteViewableNodeCountDidChange
746
767
{
747
- if (![self shouldShowInfo ]) return [_infoPanel close ];
748
- unsigned const count = [[[self activeDocument ] node ] viewableNodeCount ];
749
- [[_infoPanel content ] setCount: count];
750
- [_infoPanel displayOverWindow: [self window ]];
768
+ [self documentShowsInfoDidChange: nil ];
769
+ [self documentShowsThumbnailsDidChange: nil ];
751
770
}
752
771
- (void )_updateNodeIndex
753
772
{
@@ -820,9 +839,12 @@ - (BOOL)validateMenuItem:(NSMenuItem *)anItem
820
839
case NSFindPanelActionPrevious: break ;
821
840
default : return NO ;
822
841
}
823
- if (![self shouldShowInfo ]) {
842
+ if (![self canShowInfo ]) {
824
843
if (@selector (toggleInfo: ) == action) return NO ;
825
844
}
845
+ if (![self canShowThumbnails ]) {
846
+ if (@selector (toggleThumbnails: ) == action) return NO ;
847
+ }
826
848
if ([[self activeDocument ] baseOrientation ] == PGUpright) {
827
849
if (@selector (revertOrientation: ) == action) return NO ;
828
850
}
@@ -832,7 +854,7 @@ - (BOOL)validateMenuItem:(NSMenuItem *)anItem
832
854
if (@selector (zoomOut: ) == action && [_imageView averageScaleFactor ] <= PGScaleMin) return NO ;
833
855
}
834
856
PGNode *const firstNode = [[[self activeDocument ] node ] sortedViewableNodeFirst: YES ];
835
- if (!firstNode) { // We could use -hasViewableNodes, but we might have to get -firstNode anyway.
857
+ if (!firstNode) { // We might have to get -firstNode anyway.
836
858
if (@selector (firstPage: ) == action) return NO ;
837
859
if (@selector (previousPage: ) == action) return NO ;
838
860
if (@selector (nextPage: ) == action) return NO ;
@@ -1077,7 +1099,7 @@ - (NSImage *)thumbnailView:(PGThumbnailView *)sender
1077
1099
- (BOOL )thumbnailView : (PGThumbnailView *)sender
1078
1100
canSelectItem : (id )item ;
1079
1101
{
1080
- return [item hasViewableNodes ];
1102
+ return [item hasViewableNodeCountGreaterThan: 0 ];
1081
1103
}
1082
1104
1083
1105
#pragma mark NSServicesRequests Protocol
@@ -1220,6 +1242,7 @@ - (id)init
1220
1242
[_thumbnailPanel setDelegate: self ];
1221
1243
[[_thumbnailPanel content ] setDataSource: self ];
1222
1244
[[_thumbnailPanel content ] setDelegate: self ];
1245
+ [_thumbnailPanel AE_addObserver: self selector: @selector (thumbnailPanelFrameDidChange: ) name: PGBezelPanelFrameDidChangeNotification];
1223
1246
1224
1247
[[PGPrefController sharedPrefController ] AE_addObserver: self selector: @selector (prefControllerBackgroundPatternColorDidChange: ) name: PGPrefControllerBackgroundPatternColorDidChangeNotification];
1225
1248
}
0 commit comments