Revision: 5434
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5434&view=rev
Author:   hofman
Date:     2009-06-17 17:46:26 +0000 (Wed, 17 Jun 2009)

Log Message:
-----------
Revert revisions 5363 and 5364. Don't use NSEditor and NSEditorRegistration to 
commit unfinished changes of the notes window, notes table, and text note. For 
some reason this leads to a crash on Tiger. Almost certainly an AppKit bug, but 
I cannot test out workarounds.

Modified Paths:
--------------
    trunk/SKMainWindowController_UI.m
    trunk/SKNoteWindowController.h
    trunk/SKNoteWindowController.m
    trunk/SKPDFDocument.h
    trunk/SKPDFDocument.m
    trunk/SKPDFView.h
    trunk/SKPDFView.m

Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m   2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKMainWindowController_UI.m   2009-06-17 17:46:26 UTC (rev 5434)
@@ -1077,50 +1077,6 @@
     }
 }
 
-#pragma mark NSControl delegate protocol
-
-- (void)controlTextDidBeginEditing:(NSNotification *)note {
-    if ([[note object] isEqual:noteOutlineView])
-        [[self document] objectDidBeginEditing:self];
-}
-
-- (void)controlTextDidEndEditing:(NSNotification *)note {
-    if ([[note object] isEqual:noteOutlineView])
-        [[self document] objectDidEndEditing:self];
-}
-
-#pragma mark NSEditor protocol
-
-- (void)discardEditing {
-    int row = [noteOutlineView editedRow];
-    if (row != -1) {
-        id item = [noteOutlineView itemAtRow:row];
-        [[noteOutlineView currentEditor] setString:[item string]];
-        [[noteOutlineView window] makeFirstResponder:noteOutlineView];
-    }
-}
-
-- (BOOL)commitEditing {
-    if ([noteOutlineView editedRow] != -1)
-        return [[noteOutlineView window] makeFirstResponder:noteOutlineView];
-    else
-        return YES;
-}
-
-- (void)commitEditingWithDelegate:(id)delegate 
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo {
-    BOOL didCommit = [self commitEditing];
-    if (delegate && didCommitSelector) {
-        // - (void)editor:(id)editor didCommit:(BOOL)didCommit 
contextInfo:(void *)contextInfo
-        NSInvocation *invocation = [NSInvocation 
invocationWithMethodSignature:[delegate 
methodSignatureForSelector:didCommitSelector]];
-        [invocation setTarget:delegate];
-        [invocation setSelector:didCommitSelector];
-        [invocation setArgument:&self atIndex:2];
-        [invocation setArgument:&didCommit atIndex:3];
-        [invocation setArgument:&contextInfo atIndex:4];
-        [invocation invoke];
-    }
-}
-
 #pragma mark SKPDFView delegate protocol
 
 - (void)PDFView:(PDFView *)sender editAnnotation:(PDFAnnotation *)annotation {
@@ -1566,6 +1522,12 @@
     }
 }
 
+- (void)handleDocumentWillSaveNotification:(NSNotification *)notification {
+    [pdfView endAnnotationEdit:self];
+    if ([noteOutlineView editedRow] != -1)
+        [[noteOutlineView window] makeFirstResponder:noteOutlineView];
+}
+
 - (void)handleDidChangeActiveAnnotationNotification:(NSNotification 
*)notification {
     PDFAnnotation *annotation = [pdfView activeAnnotation];
     
@@ -1686,6 +1648,9 @@
                              name:NSApplicationDidResignActiveNotification 
object:NSApp];
     [nc addObserver:self 
selector:@selector(handleApplicationWillBecomeActiveNotification:) 
                              name:NSApplicationWillBecomeActiveNotification 
object:NSApp];
+    // Document
+    [nc addObserver:self 
selector:@selector(handleDocumentWillSaveNotification:) 
+                             name:SKPDFDocumentWillSaveNotification 
object:[self document]];
     // PDFView
     [nc addObserver:self selector:@selector(handlePageChangedNotification:) 
                              name:PDFViewPageChangedNotification 
object:pdfView];

Modified: trunk/SKNoteWindowController.h
===================================================================
--- trunk/SKNoteWindowController.h      2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKNoteWindowController.h      2009-06-17 17:46:26 UTC (rev 5434)
@@ -71,4 +71,6 @@
 
 - (void)statusBarClicked:(id)sender;
 
+- (void)handleDocumentWillSaveNotification:(NSNotification *)notification;
+
 @end

Modified: trunk/SKNoteWindowController.m
===================================================================
--- trunk/SKNoteWindowController.m      2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKNoteWindowController.m      2009-06-17 17:46:26 UTC (rev 5434)
@@ -195,6 +195,9 @@
     [self updateStatusMessage];
     
     [self setWindowFrameAutosaveNameOrCascade:[self isNoteType] ? 
SKNoteWindowFrameAutosaveName : SKGenericNoteWindowFrameAutosaveName];
+    
+    [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleDocumentWillSaveNotification:) 
+                                                 
name:SKPDFDocumentWillSaveNotification object:[self document]];
 }
 
 - (void)windowWillClose:(NSNotification *)aNotification {
@@ -266,22 +269,16 @@
     [pdfView setActiveAnnotation:note];
 }
 
+- (void)handleDocumentWillSaveNotification:(NSNotification *)notification {
+    [noteController commitEditing];
+}
+
 - (NSUndoManager *)undoManagerForTextView:(NSTextView *)aTextView {
     if (textViewUndoManager == nil)
         textViewUndoManager = [[NSUndoManager alloc] init];
     return textViewUndoManager;
 }
 
-#pragma mark NSEditorRegistration protocol
-
-- (void)objectDidBeginEditing:(id)editor {
-    [[self document] objectDidBeginEditing:editor];
-}
-
-- (void)objectDidEndEditing:(id)editor {
-    [[self document] objectDidEndEditing:editor];
-}
-
 #pragma mark BDSKDragImageView delegate protocol
 
 - (BOOL)dragImageView:(BDSKDragImageView *)view 
writeDataToPasteboard:(NSPasteboard *)pasteboard {

Modified: trunk/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h       2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKPDFDocument.h       2009-06-17 17:46:26 UTC (rev 5434)
@@ -38,6 +38,7 @@
 
 #import <Cocoa/Cocoa.h>
 
+extern NSString *SKPDFDocumentWillSaveNotification;
 extern NSString *SKSkimFileDidSaveNotification;
 
 enum {

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKPDFDocument.m       2009-06-17 17:46:26 UTC (rev 5434)
@@ -81,6 +81,7 @@
 #define OPEN_META_TAGS_KEY @"com.apple.metadata:kOMUserTags"
 #define OPEN_META_RATING_KEY @"com.apple.metadata:kOMStarRating"
 
+NSString *SKPDFDocumentWillSaveNotification = 
@"SKPDFDocumentWillSaveNotification";
 NSString *SKSkimFileDidSaveNotification = @"SKSkimFileDidSaveNotification";
 
 #define SKLastExportedTypeKey @"SKLastExportedType"
@@ -435,6 +436,7 @@
 }
 
 - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName 
error:(NSError **)outError{
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFDocumentWillSaveNotification object:self];
     BOOL didWrite = NO;
     NSError *error = nil;
     if (SKIsEmbeddedPDFDocumentType(typeName)) {

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKPDFView.h   2009-06-17 17:46:26 UTC (rev 5434)
@@ -194,6 +194,7 @@
 
 - (void)editActiveAnnotation:(id)sender;
 - (void)editThisAnnotation:(id)sender;
+- (void)endAnnotationEdit:(id)sender;
 
 - (void)selectNextActiveAnnotation:(id)sender;
 - (void)selectPreviousActiveAnnotation:(id)sender;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2009-06-17 17:30:58 UTC (rev 5433)
+++ trunk/SKPDFView.m   2009-06-17 17:46:26 UTC (rev 5434)
@@ -554,7 +554,7 @@
        if (activeAnnotation != nil) {
                [self setNeedsDisplayForAnnotation:activeAnnotation];
         if (changed && [self isEditing])
-            [self commitEditing];
+            [self endAnnotationEdit:nil];
        }
     
        // Assign.
@@ -2001,7 +2001,7 @@
     if (undoable)
         [[[self undoManager] prepareWithInvocationTarget:self] 
addAnnotation:wasAnnotation toPage:page];
     if ([self isEditing] && activeAnnotation == annotation)
-        [self commitEditing];
+        [self endAnnotationEdit:self];
        if (activeAnnotation == annotation)
                [self setActiveAnnotation:nil];
     [self setNeedsDisplayForAnnotation:wasAnnotation];
@@ -2039,7 +2039,7 @@
         return;
     
     if ([self isEditing])
-        [self commitEditing];
+        [self endAnnotationEdit:self];
     if (activeAnnotation != annotation)
         [self setActiveAnnotation:annotation];
     [self editActiveAnnotation:sender];
@@ -2049,7 +2049,7 @@
     if (nil == activeAnnotation || hideNotes)
         return;
     
-    [self commitEditing];
+    [self endAnnotationEdit:self];
     
     NSString *type = [activeAnnotation type];
     
@@ -2083,8 +2083,6 @@
         
         [self setNeedsDisplayForAnnotation:activeAnnotation];
         
-        [[[[self window] windowController] document] 
objectDidBeginEditing:self];
-        
     } else if ([activeAnnotation isEditable]) {
         
         [[SKPDFToolTipWindow sharedToolTipWindow] orderOut:self];
@@ -2096,25 +2094,10 @@
     
 }
 
-- (void)discardEditing {
+- (void)endAnnotationEdit:(id)sender {
     if (editField) {
         if ([[self window] firstResponder] == [editField currentEditor] && 
[[self window] makeFirstResponder:self] == NO)
             [[self window] endEditingFor:nil];
-        [editField removeFromSuperview];
-        [editField release];
-        editField = nil;
-        
-        if ([[activeAnnotation type] isEqualToString:SKNFreeTextString])
-            [self setNeedsDisplayForAnnotation:activeAnnotation];
-        
-        [[[[self window] windowController] document] objectDidEndEditing:self];
-    }
-}
-
-- (BOOL)commitEditing {
-    if (editField) {
-        if ([[self window] firstResponder] == [editField currentEditor] && 
[[self window] makeFirstResponder:self] == NO)
-            return NO;
         if ([[editField stringValue] isEqualToString:[activeAnnotation 
string]] == NO)
             [activeAnnotation setString:[editField stringValue]];
         [editField removeFromSuperview];
@@ -2123,31 +2106,14 @@
         
         if ([[activeAnnotation type] isEqualToString:SKNFreeTextString])
             [self setNeedsDisplayForAnnotation:activeAnnotation];
-        
-        [[[[self window] windowController] document] objectDidEndEditing:self];
     }
-    return YES;
 }
 
-- (void)commitEditingWithDelegate:(id)delegate 
didCommitSelector:(SEL)didCommitSelector contextInfo:(void *)contextInfo {
-    BOOL didCommit = [self commitEditing];
-    if (delegate && didCommitSelector) {
-        // - (void)editor:(id)editor didCommit:(BOOL)didCommit 
contextInfo:(void *)contextInfo
-        NSInvocation *invocation = [NSInvocation 
invocationWithMethodSignature:[delegate 
methodSignatureForSelector:didCommitSelector]];
-        [invocation setTarget:delegate];
-        [invocation setSelector:didCommitSelector];
-        [invocation setArgument:&self atIndex:2];
-        [invocation setArgument:&didCommit atIndex:3];
-        [invocation setArgument:&contextInfo atIndex:4];
-        [invocation invoke];
-    }
-}
-
 - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView 
doCommandBySelector:(SEL)command {
     BOOL rv = NO;
     if ([control isEqual:editField]) {
         if (command == @selector(insertNewline:) || command == 
@selector(insertTab:) || command == @selector(insertBacktab:)) {
-            [self commitEditing];
+            [self endAnnotationEdit:self];
             [[self window] makeFirstResponder:self];
             rv = YES;
         }
@@ -2166,7 +2132,7 @@
     
     if (activeAnnotation) {
         if ([self isEditing])
-            [self commitEditing];
+            [self endAnnotationEdit:self];
         pageIndex = [[activeAnnotation page] pageIndex];
         i = [[[activeAnnotation page] annotations] 
indexOfObject:activeAnnotation];
     } else {
@@ -2212,7 +2178,7 @@
     
     if (activeAnnotation) {
         if ([self isEditing])
-            [self commitEditing];
+            [self endAnnotationEdit:self];
         pageIndex = [[activeAnnotation page] pageIndex];
         annotations = [[activeAnnotation page] annotations];
         i = [annotations indexOfObject:activeAnnotation];


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

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to