Revision: 3893
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3893&view=rev
Author:   hofman
Date:     2008-05-18 09:29:55 -0700 (Sun, 18 May 2008)

Log Message:
-----------
Be anal and add shadowing ivars we can nset to make KVO working.

Modified Paths:
--------------
    trunk/SKFontWell.m
    trunk/SKMainWindowController.h
    trunk/SKMainWindowController.m
    trunk/SKMainWindowController_UI.m
    trunk/SKPrintAccessoryController.m
    trunk/SKSnapshotWindowController.h
    trunk/SKSnapshotWindowController.m

Modified: trunk/SKFontWell.m
===================================================================
--- trunk/SKFontWell.m  2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKFontWell.m  2008-05-18 16:29:55 UTC (rev 3893)
@@ -65,13 +65,13 @@
 @implementation SKFontWell
 
 + (void)initialize {
-    OBINITIALIZE;
-    
     [self exposeBinding:SKFontWellFontNameKey];
     [self exposeBinding:SKFontWellFontSizeKey];
     
     [self setKeys:[NSArray arrayWithObjects:SKFontWellFontKey, nil] 
triggerChangeNotificationsForDependentKey:SKFontWellFontNameKey];
     [self setKeys:[NSArray arrayWithObjects:SKFontWellFontKey, nil] 
triggerChangeNotificationsForDependentKey:SKFontWellFontSizeKey];
+    
+    OBINITIALIZE;
 }
 
 + (Class)cellClass {

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKMainWindowController.h      2008-05-18 16:29:55 UTC (rev 3893)
@@ -68,9 +68,7 @@
        BOOL autoHidesScrollers;
 } SKPDFViewState;
 
-extern NSString *SKMainWindowPageLabelKey;
 extern NSString *SKMainWindowPageLabelsKey;
-extern NSString *SKMainWindowPageNumberKey;
 extern NSString *SKMainWindowSearchResultsKey;
 extern NSString *SKMainWindowGroupedSearchResultsKey;
 extern NSString *SKMainWindowNotesKey;
@@ -229,6 +227,9 @@
     
     NSMutableArray              *pageLabels;
     
+    NSString                    *pageLabel;
+    unsigned int                pageNumber;
+    
     unsigned int                markedPageIndex;
     unsigned int                beforeMarkedPageIndex;
     

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKMainWindowController.m      2008-05-18 16:29:55 UTC (rev 3893)
@@ -95,9 +95,7 @@
 #import "NSImage_SKExtensions.h"
 #import "SKGroupedSearchResult.h"
 
-NSString *SKMainWindowPageLabelKey = @"pageLabel";
 NSString *SKMainWindowPageLabelsKey = @"pageLabels";
-NSString *SKMainWindowPageNumberKey = @"pageNumber";
 NSString *SKMainWindowSearchResultsKey = @"searchResults";
 NSString *SKMainWindowGroupedSearchResultsKey = @"groupedSearchResults";
 NSString *SKMainWindowNotesKey = @"notes";
@@ -231,6 +229,8 @@
         rightSidePaneState = SKNoteSidePaneState;
         findPaneState = SKSingularFindPaneState;
         temporaryAnnotations = CFSetCreateMutable(kCFAllocatorDefault, 0, 
&kCFTypeSetCallBacks);
+        pageLabel = nil;
+        pageNumber = NSNotFound;
         markedPageIndex = NSNotFound;
         beforeMarkedPageIndex = NSNotFound;
         isAnimating = NO;
@@ -259,6 +259,7 @@
        [notes release];
        [snapshots release];
     [pageLabels release];
+    [pageLabel release];
        CFRelease(rowHeights);
     [lastViewedPages release];
        [leftSideWindow release];
@@ -688,7 +689,6 @@
     int i, count = [pdfDoc pageCount];
     
     // update page labels, also update the size of the table columns 
displaying the labels
-    [self willChangeValueForKey:SKMainWindowPageLabelKey];
     [self willChangeValueForKey:SKMainWindowPageLabelsKey];
     [pageLabels removeAllObjects];
     for (i = 0; i < count; i++) {
@@ -698,8 +698,9 @@
         [pageLabels addObject:label];
     }
     [self didChangeValueForKey:SKMainWindowPageLabelsKey];
-    [self didChangeValueForKey:SKMainWindowPageLabelKey];
     
+    [self setPageLabel:[[pdfView currentPage] label]];
+    
     [self updatePageColumnWidthForTableView:thumbnailTableView];
     [self updatePageColumnWidthForTableView:snapshotTableView];
     [self updatePageColumnWidthForTableView:outlineView];
@@ -880,25 +881,32 @@
 }
 
 - (unsigned int)pageNumber {
-    return [[pdfView currentPage] pageIndex] + 1;
+    return pageNumber;
 }
 
-- (void)setPageNumber:(unsigned int)pageNumber {
+- (void)setPageNumber:(unsigned int)number {
     // Check that the page number exists
     unsigned int pageCount = [[pdfView document] pageCount];
-    if (pageNumber > pageCount)
-        [self goToPage:[[pdfView document] pageAtIndex:pageCount - 1]];
-    else if (pageNumber > 0)
-        [self goToPage:[[pdfView document] pageAtIndex:pageNumber - 1]];
+    if (number > pageCount)
+        number = pageCount;
+    if (number > 0) {
+        pageNumber = number;
+        if ([[pdfView currentPage] pageIndex] != pageNumber - 1)
+            [self goToPage:[[pdfView document] pageAtIndex:pageNumber - 1]];
+    }
 }
 
 - (NSString *)pageLabel {
-    return [[pdfView currentPage] label];
+    return pageLabel;
 }
 
 - (void)setPageLabel:(NSString *)label {
+    if (label != pageLabel) {
+        [pageLabel release];
+        pageLabel = [label retain];
+    }
     unsigned int idx = [pageLabels indexOfObject:label];
-    if (idx != NSNotFound)
+    if (idx != NSNotFound && [[[pdfView currentPage] label] isEqual:label] == 
NO)
         [self goToPage:[[pdfView document] pageAtIndex:idx]];
 }
 

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKMainWindowController_UI.m   2008-05-18 16:29:55 UTC (rev 3893)
@@ -1239,16 +1239,16 @@
 }
 
 - (void)handlePageChangedNotification:(NSNotification *)notification {
-    [lastViewedPages insertObject:[NSNumber numberWithInt:[[pdfView 
currentPage] pageIndex]] atIndex:0];
+    PDFPage *page = [pdfView currentPage];
+    
+    [lastViewedPages insertObject:[NSNumber numberWithUnsignedInt:[page 
pageIndex]] atIndex:0];
     if ([lastViewedPages count] > 5)
         [lastViewedPages removeLastObject];
     [thumbnailTableView setNeedsDisplay:YES];
     [outlineView setNeedsDisplay:YES];
     
-    [self willChangeValueForKey:SKMainWindowPageNumberKey];
-    [self willChangeValueForKey:SKMainWindowPageLabelKey];
-    [self didChangeValueForKey:SKMainWindowPageLabelKey];
-    [self didChangeValueForKey:SKMainWindowPageNumberKey];
+    [self setPageLabel:[page label]];
+    [self setPageNumber:[page pageIndex] + 1];
     
     [previousNextPageButton setEnabled:[pdfView canGoToPreviousPage] 
forSegment:0];
     [previousNextPageButton setEnabled:[pdfView canGoToNextPage] forSegment:1];

Modified: trunk/SKPrintAccessoryController.m
===================================================================
--- trunk/SKPrintAccessoryController.m  2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKPrintAccessoryController.m  2008-05-18 16:29:55 UTC (rev 3893)
@@ -45,6 +45,7 @@
     [self setKeys:[NSArray arrayWithObjects:@"autoRotate", 
@"printScalingMode", nil] 
triggerChangeNotificationsForDependentKey:@"localizedSummaryItems"];
     [self setKeys:[NSArray arrayWithObjects:@"representedObject", nil] 
triggerChangeNotificationsForDependentKey:@"autoRotate"];
     [self setKeys:[NSArray arrayWithObjects:@"representedObject", nil] 
triggerChangeNotificationsForDependentKey:@"printScalingMode"];
+    [super initialize];
 }
 
 - (NSString *)nibName {

Modified: trunk/SKSnapshotWindowController.h
===================================================================
--- trunk/SKSnapshotWindowController.h  2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKSnapshotWindowController.h  2008-05-18 16:29:55 UTC (rev 3893)
@@ -46,6 +46,8 @@
     IBOutlet BDSKZoomablePDFView* pdfView;
     NSImage *thumbnail;
     id delegate;
+    NSString *pageLabel;
+    BOOL hasWindow;
     BOOL miniaturizing;
     BOOL forceOnTop;
 }
@@ -65,7 +67,8 @@
 - (void)setThumbnail:(NSImage *)newThumbnail;
 
 - (unsigned int)pageIndex;
-
+- (NSString *)pageLabel;
+- (BOOL)hasWindow;
 - (NSDictionary *)pageAndWindow;
 
 - (NSDictionary *)currentSetup;

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2008-05-18 14:09:31 UTC (rev 3892)
+++ trunk/SKSnapshotWindowController.m  2008-05-18 16:29:55 UTC (rev 3893)
@@ -50,6 +50,7 @@
 #import "NSGeometry_SKExtensions.h"
 #import "PDFPage_SKExtensions.h"
 #import "SKSnapshotPageCell.h"
+#import "SKUtilities.h"
 
 NSString *SKSnapshotCurrentSetupKey = @"currentSetup";
 
@@ -60,7 +61,8 @@
 static NSString *SKSnapshotHasWindowKey = @"hasWindow";
 static NSString *SKSnapshotWindowFrameKey = @"windowFrame";
 
-static NSString *SKSnapshotWindowPageIndexKey = @"pageIndex";
+static NSString *SKSnapshotWindowPageLabelKey = @"pageLabel";
+static NSString *SKSnapshotWindowHasWindowKey = @"hasWindow";
 static NSString *SKSnapshotWindowPageAndWindowKey = @"pageAndWindow";
 
 static NSString *SKSnapshotWindowFrameAutosaveName = @"SKSnapshotWindow";
@@ -68,11 +70,22 @@
 
 static void *SKSnaphotWindowDefaultsObservationContext = (void 
*)@"SKSnaphotWindowDefaultsObservationContext";
 
[EMAIL PROTECTED] SKSnapshotWindowController (SKPrivate) 
+- (void)setPageLabel:(NSString *)newPageLabel;
+- (void)setHasWindow:(BOOL)flag;
[EMAIL PROTECTED]
+
 @implementation SKSnapshotWindowController
 
++ (void)initialize {
+    [self setKeys:[NSArray arrayWithObjects:SKSnapshotWindowPageLabelKey, 
SKSnapshotWindowHasWindowKey, nil] 
triggerChangeNotificationsForDependentKey:SKSnapshotWindowPageAndWindowKey];
+    OBINITIALIZE;
+}
+
 - (void)dealloc {
        [[NSNotificationCenter defaultCenter] removeObserver: self];
     [thumbnail release];
+    [pageLabel release];
     [super dealloc];
 }
 
@@ -87,6 +100,10 @@
     [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self 
forKey:SKSnapshotsOnTopKey context:SKSnaphotWindowDefaultsObservationContext];
 }
 
+- (void)windowDidExpose:(NSNotification *)notification {
+    [self setHasWindow:YES];
+}
+
 - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName {
     return [NSString stringWithFormat:NSLocalizedString(@"%@ %C Page %@", 
@"Window title format: [filename] - Page [number]"), displayName, 0x2014, 
[[pdfView currentPage] label]];
 }
@@ -122,17 +139,15 @@
 }
 
 - (void)handlePageChangedNotification:(NSNotification *)notification {
+    NSString *label = [[pdfView currentPage] label];
+    [self setPageLabel:label ? label : [NSString stringWithFormat:@"%i", [self 
pageIndex]]];
     [[self window] setTitle:[self windowTitleForDocumentDisplayName:[[self 
document] displayName]]];
-    [self willChangeValueForKey:SKSnapshotWindowPageIndexKey];
-    [self didChangeValueForKey:SKSnapshotWindowPageIndexKey];
-    [self willChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
-    [self didChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
 }
 
 - (void)handleDocumentDidUnlockNotification:(NSNotification *)notification {
     [[self window] setTitle:[self windowTitleForDocumentDisplayName:[[self 
document] displayName]]];
-    [self willChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
-    [self didChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
+    NSString *label = [[pdfView currentPage] label];
+    [self setPageLabel:label ? label : [NSString stringWithFormat:@"%i", [self 
pageIndex]]];
 }
 
 - (void)handlePDFViewFrameChangedNotification:(NSNotification *)notification {
@@ -296,10 +311,27 @@
     return [[pdfView currentPage] pageIndex];
 }
 
+- (NSString *)pageLabel {
+    return pageLabel;
+}
+
+- (void)setPageLabel:(NSString *)newPageLabel {
+    if (pageLabel != newPageLabel) {
+        [pageLabel release];
+        pageLabel = [newPageLabel retain];
+    }
+}
+
+- (BOOL)hasWindow {
+    return hasWindow;
+}
+
+- (void)setHasWindow:(BOOL)flag {
+    hasWindow = flag;
+}
+
 - (NSDictionary *)pageAndWindow {
-    NSString *label = [[pdfView currentPage] label];
-    NSNumber *hasWindow = [NSNumber numberWithBool:[[self window] isVisible]];
-    return [NSDictionary dictionaryWithObjectsAndKeys:label ? label : @"", 
SKSnapshotPageCellLabelKey, hasWindow, SKSnapshotPageCellHasWindowKey, nil];
+    return [NSDictionary dictionaryWithObjectsAndKeys:[self pageLabel], 
SKSnapshotPageCellLabelKey, [NSNumber numberWithBool:[self hasWindow]], 
SKSnapshotPageCellHasWindowKey, nil];
 }
 
 - (BOOL)forceOnTop {
@@ -505,8 +537,7 @@
         [[self window] orderOut:self];
     }
     miniaturizing = NO;
-    [self willChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
-    [self didChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
+    [self setHasWindow:NO];
 }
 
 - (void)deminiaturize {
@@ -526,8 +557,7 @@
     } else {
         [self showWindow:self];
     }
-    [self willChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
-    [self didChangeValueForKey:SKSnapshotWindowPageAndWindowKey];
+    [self setHasWindow:YES];
 }
 
 #pragma mark KVO


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to