Revision: 5364
http://skim-app.svn.sourceforge.net/skim-app/?rev=5364&view=rev
Author: hofman
Date: 2009-05-07 15:28:59 +0000 (Thu, 07 May 2009)
Log Message:
-----------
register window controller as editor when editing note outlineview, implement
NSEditor so document save will automatically commit changes
Modified Paths:
--------------
trunk/SKMainWindowController_UI.m
trunk/SKPDFDocument.h
trunk/SKPDFDocument.m
trunk/SKPDFView.h
trunk/SKPDFView.m
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2009-05-07 14:47:30 UTC (rev 5363)
+++ trunk/SKMainWindowController_UI.m 2009-05-07 15:28:59 UTC (rev 5364)
@@ -1077,6 +1077,50 @@
}
}
+#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 {
@@ -1522,12 +1566,6 @@
}
}
-- (void)handleDocumentWillSaveNotification:(NSNotification *)notification {
- [pdfView endAnnotationEdit:self];
- if ([noteOutlineView editedRow] != -1)
- [[noteOutlineView window] makeFirstResponder:noteOutlineView];
-}
-
- (void)handleDidChangeActiveAnnotationNotification:(NSNotification
*)notification {
PDFAnnotation *annotation = [pdfView activeAnnotation];
@@ -1648,9 +1686,6 @@
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/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h 2009-05-07 14:47:30 UTC (rev 5363)
+++ trunk/SKPDFDocument.h 2009-05-07 15:28:59 UTC (rev 5364)
@@ -38,7 +38,6 @@
#import <Cocoa/Cocoa.h>
-extern NSString *SKPDFDocumentWillSaveNotification;
extern NSString *SKSkimFileDidSaveNotification;
enum {
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2009-05-07 14:47:30 UTC (rev 5363)
+++ trunk/SKPDFDocument.m 2009-05-07 15:28:59 UTC (rev 5364)
@@ -81,7 +81,6 @@
#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"
@@ -436,7 +435,6 @@
}
- (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-05-07 14:47:30 UTC (rev 5363)
+++ trunk/SKPDFView.h 2009-05-07 15:28:59 UTC (rev 5364)
@@ -194,7 +194,6 @@
- (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-05-07 14:47:30 UTC (rev 5363)
+++ trunk/SKPDFView.m 2009-05-07 15:28:59 UTC (rev 5364)
@@ -549,7 +549,7 @@
if (activeAnnotation != nil) {
[self setNeedsDisplayForAnnotation:activeAnnotation];
if (changed && [self isEditing])
- [self endAnnotationEdit:nil];
+ [self commitEditing];
}
// Assign.
@@ -2000,7 +2000,7 @@
if (undoable)
[[[self undoManager] prepareWithInvocationTarget:self]
addAnnotation:wasAnnotation toPage:page];
if ([self isEditing] && activeAnnotation == annotation)
- [self endAnnotationEdit:self];
+ [self commitEditing];
if (activeAnnotation == annotation)
[self setActiveAnnotation:nil];
[self setNeedsDisplayForAnnotation:wasAnnotation];
@@ -2038,7 +2038,7 @@
return;
if ([self isEditing])
- [self endAnnotationEdit:self];
+ [self commitEditing];
if (activeAnnotation != annotation)
[self setActiveAnnotation:annotation];
[self editActiveAnnotation:sender];
@@ -2048,7 +2048,7 @@
if (nil == activeAnnotation || hideNotes)
return;
- [self endAnnotationEdit:self];
+ [self commitEditing];
NSString *type = [activeAnnotation type];
@@ -2082,6 +2082,8 @@
[self setNeedsDisplayForAnnotation:activeAnnotation];
+ [[[[self window] windowController] document]
objectDidBeginEditing:self];
+
} else if ([activeAnnotation isEditable]) {
[[SKPDFToolTipWindow sharedToolTipWindow] orderOut:self];
@@ -2093,10 +2095,25 @@
}
-- (void)endAnnotationEdit:(id)sender {
+- (void)discardEditing {
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];
@@ -2105,14 +2122,31 @@
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 endAnnotationEdit:self];
+ [self commitEditing];
[[self window] makeFirstResponder:self];
rv = YES;
}
@@ -2131,7 +2165,7 @@
if (activeAnnotation) {
if ([self isEditing])
- [self endAnnotationEdit:self];
+ [self commitEditing];
pageIndex = [[activeAnnotation page] pageIndex];
i = [[[activeAnnotation page] annotations]
indexOfObject:activeAnnotation];
} else {
@@ -2177,7 +2211,7 @@
if (activeAnnotation) {
if ([self isEditing])
- [self endAnnotationEdit:self];
+ [self commitEditing];
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.
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit