Revision: 2907
http://skim-app.svn.sourceforge.net/skim-app/?rev=2907&view=rev
Author: hofman
Date: 2007-09-12 05:13:42 -0700 (Wed, 12 Sep 2007)
Log Message:
-----------
Make reading notes from skim or fdf file undoable.
Modified Paths:
--------------
trunk/SKDocument.m
trunk/SKMainWindowController.h
trunk/SKMainWindowController.m
Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m 2007-09-12 10:02:33 UTC (rev 2906)
+++ trunk/SKDocument.m 2007-09-12 12:13:42 UTC (rev 2907)
@@ -140,7 +140,7 @@
[mainController setPdfDocument:pdfDocument];
[self setPDFDoc:nil];
- [mainController setAnnotationsFromDictionaries:noteDicts];
+ [mainController setAnnotationsFromDictionaries:noteDicts undoable:NO];
[self setNoteDicts:nil];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
forKey:SKAutoCheckFileUpdateKey];
@@ -411,7 +411,7 @@
[pdfDocument autorelease];
pdfDocument = nil;
if (noteDicts) {
- [[self mainWindowController]
setAnnotationsFromDictionaries:noteDicts];
+ [[self mainWindowController]
setAnnotationsFromDictionaries:noteDicts undoable:NO];
[self setNoteDicts:nil];
}
[[self undoManager] removeAllActions];
@@ -677,13 +677,13 @@
}
if (array) {
- if ([[oPanel accessoryView] isEqual:readNotesAccessoryView] &&
[replaceNotesCheckButton state] == NSOnState)
- [[self mainWindowController]
setAnnotationsFromDictionaries:array];
- else
- [[self mainWindowController]
addAnnotationsFromDictionaries:array];
- // previous undo actions are not reliable anymore
- [[self undoManager] removeAllActions];
- [self updateChangeCount:NSChangeDone];
+ if ([[oPanel accessoryView] isEqual:readNotesAccessoryView] &&
[replaceNotesCheckButton state] == NSOnState) {
+ [[self mainWindowController]
setAnnotationsFromDictionaries:array undoable:YES];
+ [[self undoManager] setActionName:NSLocalizedString(@"Replace
Notes", @"Undo action name")];
+ } else {
+ [[self mainWindowController]
addAnnotationsFromDictionaries:array undoable:YES];
+ [[self undoManager] setActionName:NSLocalizedString(@"Add
Notes", @"Undo action name")];
+ }
} else
NSBeep();
Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h 2007-09-12 10:02:33 UTC (rev 2906)
+++ trunk/SKMainWindowController.h 2007-09-12 12:13:42 UTC (rev 2907)
@@ -349,8 +349,8 @@
- (void)registerAsObserver;
- (void)unregisterAsObserver;
-- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts;
-- (void)setAnnotationsFromDictionaries:(NSArray *)noteDicts;
+- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
undoable:(BOOL)undoable;
+- (void)setAnnotationsFromDictionaries:(NSArray *)noteDicts
undoable:(BOOL)undoable;
- (void)setupWindow:(NSDictionary *)setup;
- (NSDictionary *)currentSetup;
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2007-09-12 10:02:33 UTC (rev 2906)
+++ trunk/SKMainWindowController.m 2007-09-12 12:13:42 UTC (rev 2907)
@@ -867,7 +867,7 @@
}
}
-- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts{
+- (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts
undoable:(BOOL)undoable{
NSEnumerator *e = [noteDicts objectEnumerator];
PDFAnnotation *annotation;
NSDictionary *dict;
@@ -878,16 +878,20 @@
while (dict = [e nextObject]) {
unsigned pageIndex = [[dict objectForKey:@"pageIndex"]
unsignedIntValue];
if (annotation = [[PDFAnnotation alloc] initWithDictionary:dict]) {
- [annotation setShouldDisplay:[pdfView hideNotes] == NO];
- [annotation setShouldPrint:[pdfView hideNotes] == NO];
if (pageIndex == NSNotFound)
pageIndex = 0;
else if (pageIndex >= [pdfDoc pageCount])
pageIndex = [pdfDoc pageCount] - 1;
PDFPage *page = [pdfDoc pageAtIndex:pageIndex];
- [page addAnnotation:annotation];
- [pdfView setNeedsDisplayForAnnotation:annotation];
- [observedNotes addObject:annotation];
+ if (undoable) {
+ [pdfView addAnnotation:annotation toPage:page];
+ } else {
+ [annotation setShouldDisplay:[pdfView hideNotes] == NO];
+ [annotation setShouldPrint:[pdfView hideNotes] == NO];
+ [page addAnnotation:annotation];
+ [pdfView setNeedsDisplayForAnnotation:annotation];
+ [observedNotes addObject:annotation];
+ }
[annotation release];
}
}
@@ -896,8 +900,8 @@
[pdfView resetHoverRects];
}
-- (void)setAnnotationsFromDictionaries:(NSArray *)noteDicts{
- NSEnumerator *e = [notes objectEnumerator];
+- (void)setAnnotationsFromDictionaries:(NSArray *)noteDicts
undoable:(BOOL)undoable{
+ NSEnumerator *e = [[[notes copy] autorelease] objectEnumerator];
PDFAnnotation *annotation;
[pdfView removeHoverRects];
@@ -905,13 +909,18 @@
// remove the current annotations
[pdfView setActiveAnnotation:nil];
while (annotation = [e nextObject]) {
- [pdfView setNeedsDisplayForAnnotation:annotation];
- [[annotation page] removeAnnotation:annotation];
+ if (undoable) {
+ [pdfView removeAnnotation:annotation];
+ } else {
+ [pdfView setNeedsDisplayForAnnotation:annotation];
+ [[annotation page] removeAnnotation:annotation];
+ }
}
- [[self mutableArrayValueForKey:@"notes"] removeAllObjects];
+ if (undoable == NO)
+ [[self mutableArrayValueForKey:@"notes"] removeAllObjects];
- [self addAnnotationsFromDictionaries:noteDicts];
+ [self addAnnotationsFromDictionaries:noteDicts undoable:undoable];
}
- (SKPDFView *)pdfView {
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 2005.
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