Skip to content

Commit aff9970

Browse files
committed
We now automatically resize and hide the thumbnail panel as appropriate.
1 parent 2081a4a commit aff9970

12 files changed

+147
-123
lines changed

PGBezelPanel.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ DEALINGS WITH THE SOFTWARE. */
2929
#import "PGGeometry.h"
3030

3131
extern NSString *const PGBezelPanelFrameShouldChangeNotification;
32+
extern NSString *const PGBezelPanelFrameDidChangeNotification;
3233

3334
@interface PGBezelPanel : PGFadeOutPanel
3435
{

PGBezelPanel.m

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ copy of this software and associated documentation files (the "Software"),
2929
#import "NSWindowAdditions.h"
3030

3131
NSString *const PGBezelPanelFrameShouldChangeNotification = @"PGBezelPanelFrameShouldChange";
32+
NSString *const PGBezelPanelFrameDidChangeNotification = @"PGBezelPanelFrameDidChange";
3233

3334
@interface PGBezelPanel (Private)
3435

@@ -131,6 +132,7 @@ - (void)_updateFrameWithWindow:(NSWindow *)aWindow
131132
{
132133
float const s = [self AE_userSpaceScaleFactor];
133134
[self setFrame:[[self contentView] bezelPanel:self frameForContentRect:PGInsetRect([aWindow AE_contentRect], PGScaleInset(_frameInset, 1.0f / s)) scale:s] display:NO];
135+
[self AE_postNotificationName:PGBezelPanelFrameDidChangeNotification];
134136
}
135137

136138
#pragma mark NSStandardKeyBindingMethods Protocol

PGColumnView.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ DEALINGS WITH THE SOFTWARE. */
3737
float _columnWidth;
3838
}
3939

40+
- (unsigned)numberOfColumns;
4041
- (NSArray *)views;
4142
- (id)lastView;
4243
- (id)viewAtIndex:(unsigned)index;
4344

4445
- (void)addColumnWithView:(NSView *)aView;
4546
- (void)insertColumnWithView:(NSView *)aView atIndex:(unsigned)index;
46-
- (void)removeColumnWithView:(NSView *)aView;
4747
- (void)removeColumnsAfterView:(NSView *)aView;
48-
- (void)removeAllColumns;
4948

5049
- (float)columnWidth;
5150
- (void)setColumnWidth:(float)width;

PGColumnView.m

+5-22
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ @implementation PGColumnView
3131

3232
#pragma mark Instance Methods
3333

34+
- (unsigned)numberOfColumns
35+
{
36+
return [_views count];
37+
}
3438
- (NSArray *)views
3539
{
3640
return [[_views copy] autorelease];
@@ -68,22 +72,9 @@ - (void)insertColumnWithView:(NSView *)aView
6872
[aView setAutoresizingMask:NSViewWidthSizable];
6973
[self scrollToTopOfColumnWithView:aView];
7074
}
71-
- (void)removeColumnWithView:(NSView *)aView
72-
{
73-
NSParameterAssert(aView);
74-
unsigned const i = [_views indexOfObjectIdenticalTo:aView];
75-
NSParameterAssert(NSNotFound != i);
76-
(void)[[aView retain] autorelease];
77-
PGClipView *const clip = [_clipViews objectAtIndex:i];
78-
[clip setDocumentView:nil];
79-
[clip removeFromSuperview];
80-
[_clipViews removeObjectAtIndex:i];
81-
[_views removeObjectAtIndex:i];
82-
[self layout];
83-
}
8475
- (void)removeColumnsAfterView:(NSView *)aView
8576
{
86-
unsigned const i = [_views indexOfObject:aView];
77+
unsigned const i = aView ? [_views indexOfObject:aView] : 0;
8778
NSParameterAssert(NSNotFound != i);
8879
while([_views count] > i + 1) {
8980
PGClipView *const clip = [_clipViews lastObject];
@@ -94,14 +85,6 @@ - (void)removeColumnsAfterView:(NSView *)aView
9485
}
9586
[self layout];
9687
}
97-
- (void)removeAllColumns
98-
{
99-
[_clipViews makeObjectsPerformSelector:@selector(setDocumentView:) withObject:nil];
100-
[_clipViews makeObjectsPerformSelector:@selector(removeFromSuperview)];
101-
[_clipViews removeAllObjects];
102-
[_views removeAllObjects];
103-
[self layout];
104-
}
10588

10689
#pragma mark -
10790

PGContainerAdapter.m

+15-8
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,6 @@ - (void)setNode:(PGNode *)aNode
161161

162162
#pragma mark -
163163

164-
- (BOOL)hasViewableNodes
165-
{
166-
if([[self node] isViewable]) return YES;
167-
PGNode *child;
168-
NSEnumerator *const childEnum = [[self unsortedChildren] objectEnumerator];
169-
while((child = [childEnum nextObject])) if([[child resourceAdapter] hasViewableNodes]) return YES;
170-
return NO;
171-
}
172164
- (BOOL)hasDataNodes
173165
{
174166
if([self canGetData]) return YES;
@@ -185,6 +177,21 @@ - (unsigned)viewableNodeCount
185177
while((child = [childEnum nextObject])) count += [[child resourceAdapter] viewableNodeCount];
186178
return count;
187179
}
180+
- (BOOL)hasViewableNodeCountGreaterThan:(unsigned)anInt
181+
{
182+
unsigned count = [[self node] isViewable] ? 1 : 0;
183+
if(count > anInt) return YES;
184+
PGNode *child;
185+
NSEnumerator *const childEnum = [[self unsortedChildren] objectEnumerator];
186+
while((child = [childEnum nextObject])) {
187+
PGResourceAdapter *const adapter = [child resourceAdapter];
188+
if([adapter hasViewableNodeCountGreaterThan:anInt - count]) return YES;
189+
if(![child isViewable]) continue;
190+
count++;
191+
if(count > anInt) return YES;
192+
}
193+
return NO;
194+
}
188195

189196
#pragma mark -
190197

PGDisplayController.h

+4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ extern NSString *const PGDisplayControllerTimerDidChangeNotification;
135135
- (BOOL)tryToLoopForward:(BOOL)forward toNode:(PGNode *)node initialLocation:(PGPageLocation)loc allowAlerts:(BOOL)flag;
136136
- (void)activateNode:(PGNode *)node;
137137

138+
- (BOOL)canShowInfo;
138139
- (BOOL)shouldShowInfo;
140+
- (BOOL)canShowThumbnails;
141+
- (BOOL)shouldShowThumbnails;
139142

140143
- (BOOL)loadingIndicatorShown;
141144
- (void)showLoadingIndicator;
@@ -164,6 +167,7 @@ extern NSString *const PGDisplayControllerTimerDidChangeNotification;
164167
- (void)documentImageScaleDidChange:(NSNotification *)aNotif;
165168
- (void)documentBaseOrientationDidChange:(NSNotification *)aNotif;
166169

170+
- (void)thumbnailPanelFrameDidChange:(NSNotification *)aNotif;
167171
- (void)prefControllerBackgroundPatternColorDidChange:(NSNotification *)aNotif;
168172

169173
@end

PGDisplayController.m

+70-47
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ - (void)_readActiveNode;
7777
- (void)_readFinished;
7878
- (NSSize)_sizeForImageRep:(NSImageRep *)rep orientation:(PGOrientation)orientation;
7979
- (void)_updateImageViewSizeAllowAnimation:(BOOL)flag;
80-
- (void)_updateInfoWithNodeCount;
80+
- (void)_noteViewableNodeCountDidChange;
8181
- (void)_updateNodeIndex;
8282
- (void)_updateInfoPanelText;
8383
- (void)_runTimer;
@@ -342,7 +342,7 @@ - (BOOL)setActiveDocument:(PGDocument *)document
342342
[self setTimerInterval:0];
343343
if(_activeDocument) {
344344
NSDisableScreenUpdates();
345-
if(![_activeDocument showsThumbnails]) [_thumbnailPanel close];
345+
if(![self shouldShowThumbnails]) [_thumbnailPanel close];
346346
[self documentShowsThumbnailsDidChange:nil];
347347
PGNode *node;
348348
PGImageView *view;
@@ -432,10 +432,22 @@ - (void)activateNode:(PGNode *)node
432432

433433
#pragma mark -
434434

435-
- (BOOL)shouldShowInfo
435+
- (BOOL)canShowInfo
436436
{
437437
return YES;
438438
}
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+
}
439451

440452
#pragma mark -
441453

@@ -553,10 +565,10 @@ - (void)documentWillRemoveNodes:(NSNotification *)aNotif
553565
}
554566
- (void)documentSortedNodesDidChange:(NSNotification *)aNotif
555567
{
556-
[self _updateInfoWithNodeCount];
568+
[self _noteViewableNodeCountDidChange];
557569
if(![self activeNode]) [self setActiveNode:[[[self activeDocument] node] sortedViewableNodeFirst:YES] initialLocation:PGHomeLocation];
558570
else [self _updateNodeIndex];
559-
if([[self activeDocument] showsThumbnails]) {
571+
if([self shouldShowThumbnails]) {
560572
[[_thumbnailPanel content] reloadData];
561573
[[_thumbnailPanel content] setSelectedItem:[self activeNode]];
562574
}
@@ -576,55 +588,32 @@ - (void)documentNodeIsViewableDidChange:(NSNotification *)aNotif
576588
} else if([self activeNode] == node) {
577589
if(![node isViewable] && ![self tryToGoForward:YES allowAlerts:NO] && ![self tryToGoForward:NO allowAlerts:NO]) [self setActiveNode:[[[self activeDocument] node] sortedViewableNodeFirst:YES] initialLocation:PGHomeLocation];
578590
}
579-
[self _updateInfoWithNodeCount];
591+
[self _noteViewableNodeCountDidChange];
580592
[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];
582594
}
583595
- (void)documentNodeThumbnailDidChange:(NSNotification *)aNotif
584596
{
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];
586598
}
587599

588600
- (void)documentShowsInfoDidChange:(NSNotification *)aNotif
589601
{
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];
592606
}
593607
- (void)documentShowsThumbnailsDidChange:(NSNotification *)aNotif
594608
{
595-
if([[self activeDocument] showsThumbnails]) {
609+
if([self shouldShowThumbnails]) {
596610
NSDisableScreenUpdates();
597611
[_thumbnailPanel displayOverWindow:[self window]];
598612
[[_thumbnailPanel content] reloadData];
599613
[[_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];
616614
NSEnableScreenUpdates();
617615
} 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];
628617
[_thumbnailPanel fadeOut];
629618
}
630619
}
@@ -638,7 +627,7 @@ - (void)documentReadingDirectionDidChange:(NSNotification *)aNotif
638627
case PGMinXMinYCorner: inset.minY = [self findPanelShown] ? NSHeight([_findPanel frame]) : 0; break;
639628
case PGMaxXMinYCorner: inset.minX = [self findPanelShown] ? NSWidth([_findPanel frame]) : 0; break;
640629
}
641-
if([[self activeDocument] showsThumbnails]) inset.minX += NSWidth([_thumbnailPanel frame]);
630+
if([self shouldShowThumbnails]) inset.minX += NSWidth([_thumbnailPanel frame]);
642631
[_infoPanel setFrameInset:inset];
643632
[[_infoPanel content] setOrigin:corner];
644633
[_infoPanel updateFrame];
@@ -654,6 +643,38 @@ - (void)documentBaseOrientationDidChange:(NSNotification *)aNotif
654643

655644
#pragma mark -
656645

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+
}
657678
- (void)prefControllerBackgroundPatternColorDidChange:(NSNotification *)aNotif;
658679
{
659680
[clipView setBackgroundColor:[[PGPrefController sharedPrefController] backgroundPatternColor]];
@@ -682,7 +703,7 @@ - (BOOL)_setActiveNode:(PGNode *)aNode
682703
_activeNode = [aNode retain];
683704
[self _updateNodeIndex];
684705
[self _updateInfoPanelText];
685-
if([[self activeDocument] showsThumbnails]) [[_thumbnailPanel content] setSelectedItem:aNode];
706+
if([self shouldShowThumbnails]) [[_thumbnailPanel content] setSelectedItem:aNode];
686707
return YES;
687708
}
688709
- (void)_readActiveNode
@@ -742,12 +763,10 @@ - (void)_updateImageViewSizeAllowAnimation:(BOOL)flag
742763
{
743764
[_imageView setSize:[self _sizeForImageRep:[_imageView rep] orientation:[_imageView orientation]] allowAnimation:flag];
744765
}
745-
- (void)_updateInfoWithNodeCount
766+
- (void)_noteViewableNodeCountDidChange
746767
{
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];
751770
}
752771
- (void)_updateNodeIndex
753772
{
@@ -820,9 +839,12 @@ - (BOOL)validateMenuItem:(NSMenuItem *)anItem
820839
case NSFindPanelActionPrevious: break;
821840
default: return NO;
822841
}
823-
if(![self shouldShowInfo]) {
842+
if(![self canShowInfo]) {
824843
if(@selector(toggleInfo:) == action) return NO;
825844
}
845+
if(![self canShowThumbnails]) {
846+
if(@selector(toggleThumbnails:) == action) return NO;
847+
}
826848
if([[self activeDocument] baseOrientation] == PGUpright) {
827849
if(@selector(revertOrientation:) == action) return NO;
828850
}
@@ -832,7 +854,7 @@ - (BOOL)validateMenuItem:(NSMenuItem *)anItem
832854
if(@selector(zoomOut:) == action && [_imageView averageScaleFactor] <= PGScaleMin) return NO;
833855
}
834856
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.
836858
if(@selector(firstPage:) == action) return NO;
837859
if(@selector(previousPage:) == action) return NO;
838860
if(@selector(nextPage:) == action) return NO;
@@ -1077,7 +1099,7 @@ - (NSImage *)thumbnailView:(PGThumbnailView *)sender
10771099
- (BOOL)thumbnailView:(PGThumbnailView *)sender
10781100
canSelectItem:(id)item;
10791101
{
1080-
return [item hasViewableNodes];
1102+
return [item hasViewableNodeCountGreaterThan:0];
10811103
}
10821104

10831105
#pragma mark NSServicesRequests Protocol
@@ -1220,6 +1242,7 @@ - (id)init
12201242
[_thumbnailPanel setDelegate:self];
12211243
[[_thumbnailPanel content] setDataSource:self];
12221244
[[_thumbnailPanel content] setDelegate:self];
1245+
[_thumbnailPanel AE_addObserver:self selector:@selector(thumbnailPanelFrameDidChange:) name:PGBezelPanelFrameDidChangeNotification];
12231246

12241247
[[PGPrefController sharedPrefController] AE_addObserver:self selector:@selector(prefControllerBackgroundPatternColorDidChange:) name:PGPrefControllerBackgroundPatternColorDidChangeNotification];
12251248
}

0 commit comments

Comments
 (0)