Revision: 5596
http://skim-app.svn.sourceforge.net/skim-app/?rev=5596&view=rev
Author: hofman
Date: 2009-08-29 12:28:08 +0000 (Sat, 29 Aug 2009)
Log Message:
-----------
check the length of the string of a selection to see if it's empty, because
PDFKit on 10.6 has the nasty habit of setting invalid empty selection objects
as the currentSelection
Modified Paths:
--------------
trunk/SKMainWindowController.m
trunk/SKMainWindowController_Toolbar.m
trunk/SKMainWindowController_UI.m
trunk/SKPDFDocument.m
trunk/SKPDFView.m
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2009-08-29 12:06:05 UTC (rev 5595)
+++ trunk/SKMainWindowController.m 2009-08-29 12:28:08 UTC (rev 5596)
@@ -1888,7 +1888,7 @@
- (void)findString:(NSString *)string options:(NSInteger)options{
PDFSelection *sel = [pdfView currentSelection];
NSUInteger pageIndex = [[pdfView currentPage] pageIndex];
- while ([sel string] == nil && pageIndex-- > 0) {
+ while ([[sel string] length] == 0 && pageIndex-- > 0) {
PDFPage *page = [[pdfView document] pageAtIndex:pageIndex];
sel = [page selectionForRect:[page
boundsForBox:kPDFDisplayBoxCropBox]];
}
Modified: trunk/SKMainWindowController_Toolbar.m
===================================================================
--- trunk/SKMainWindowController_Toolbar.m 2009-08-29 12:06:05 UTC (rev
5595)
+++ trunk/SKMainWindowController_Toolbar.m 2009-08-29 12:28:08 UTC (rev
5596)
@@ -702,9 +702,9 @@
} else if ([identifier
isEqualToString:SKDocumentToolbarNewTextNoteItemIdentifier] || [identifier
isEqualToString:SKDocumentToolbarNewCircleNoteItemIdentifier] || [identifier
isEqualToString:SKDocumentToolbarNewLineItemIdentifier]) {
return ([pdfView toolMode] == SKTextToolMode || [pdfView toolMode] ==
SKNoteToolMode) && [pdfView hideNotes] == NO;
} else if ([identifier
isEqualToString:SKDocumentToolbarNewMarkupItemIdentifier]) {
- return ([pdfView toolMode] == SKTextToolMode || [pdfView toolMode] ==
SKNoteToolMode) && [[[pdfView currentSelection] pages] count] && [pdfView
hideNotes] == NO;
+ return ([pdfView toolMode] == SKTextToolMode || [pdfView toolMode] ==
SKNoteToolMode) && [pdfView hideNotes] == NO && [[[pdfView currentSelection]
string] length];
} else if ([identifier
isEqualToString:SKDocumentToolbarNewNoteItemIdentifier]) {
- BOOL enabled = ([pdfView toolMode] == SKTextToolMode || [pdfView
toolMode] == SKNoteToolMode) && [[[pdfView currentSelection] pages] count] &&
[pdfView hideNotes] == NO;
+ BOOL enabled = ([pdfView toolMode] == SKTextToolMode || [pdfView
toolMode] == SKNoteToolMode) && [pdfView hideNotes] == NO && [[[pdfView
currentSelection] string] length];
[noteButton setEnabled:enabled forSegment:SKHighlightNote];
[noteButton setEnabled:enabled forSegment:SKUnderlineNote];
[noteButton setEnabled:enabled forSegment:SKStrikeOutNote];
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2009-08-29 12:06:05 UTC (rev 5595)
+++ trunk/SKMainWindowController_UI.m 2009-08-29 12:28:08 UTC (rev 5596)
@@ -1291,7 +1291,7 @@
SEL action = [menuItem action];
if (action == @selector(createNewNote:)) {
BOOL isMarkup = [menuItem tag] == SKHighlightNote || [menuItem tag] ==
SKUnderlineNote || [menuItem tag] == SKStrikeOutNote;
- return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && (isMarkup == NO ||
[[[pdfView currentSelection] pages] count]) && [pdfView hideNotes] == NO;
+ return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes]
&& (isMarkup == NO || [[[pdfView currentSelection] string] length]) == NO;
} else if (action == @selector(createNewTextNote:)) {
[menuItem setState:[textNoteButton tag] == [menuItem tag] ? NSOnState
: NSOffState];
return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes]
== NO;
@@ -1300,7 +1300,7 @@
return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes]
== NO;
} else if (action == @selector(createNewMarkupNote:)) {
[menuItem setState:[markupNoteButton tag] == [menuItem tag] ?
NSOnState : NSOffState];
- return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [[[pdfView
currentSelection] pages] count] && [pdfView hideNotes] == NO;
+ return [self isPresentation] == NO && ([pdfView toolMode] ==
SKTextToolMode || [pdfView toolMode] == SKNoteToolMode) && [pdfView hideNotes]
== NO && [[[pdfView currentSelection] string] length];
} else if (action == @selector(editNote:)) {
PDFAnnotation *annotation = [pdfView activeAnnotation];
return [self isPresentation] == NO && [annotation isSkimNote] &&
([annotation isEditable]);
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2009-08-29 12:06:05 UTC (rev 5595)
+++ trunk/SKPDFDocument.m 2009-08-29 12:28:08 UTC (rev 5596)
@@ -1963,7 +1963,7 @@
- (id)selectionSpecifier {
PDFSelection *sel = [[self pdfView] currentSelection];
- return sel ? [sel objectSpecifier] : [NSArray array];
+ return [[sel string] length] ? [sel objectSpecifier] : [NSArray array];
}
- (void)setSelectionSpecifier:(id)specifier {
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2009-08-29 12:06:05 UTC (rev 5595)
+++ trunk/SKPDFView.m 2009-08-29 12:28:08 UTC (rev 5596)
@@ -767,14 +767,16 @@
{
if ([[self document] allowsCopying]) {
[super copy:sender];
- } else if ([self currentSelection]) {
- NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+ } else {
NSString *string = [[self currentSelection] string];
- NSAttributedString *attrString = [[self currentSelection]
attributedString];
-
- [pboard declareTypes:[NSArray arrayWithObjects:NSStringPboardType,
NSRTFPboardType, nil] owner:nil];
- [pboard setString:string forType:NSStringPboardType];
- [pboard setData:[attrString RTFFromRange:NSMakeRange(0, [attrString
length]) documentAttributes:nil] forType:NSRTFPboardType];
+ if ([string length]) {
+ NSPasteboard *pboard = [NSPasteboard generalPasteboard];
+ NSAttributedString *attrString = [[self currentSelection]
attributedString];
+
+ [pboard declareTypes:[NSArray arrayWithObjects:NSStringPboardType,
NSRTFPboardType, nil] owner:nil];
+ [pboard setString:string forType:NSStringPboardType];
+ [pboard setData:[attrString RTFFromRange:NSMakeRange(0,
[attrString length]) documentAttributes:nil] forType:NSRTFPboardType];
+ }
}
NSMutableArray *types = [NSMutableArray array];
@@ -809,7 +811,7 @@
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
if ([types count]) {
- if ([[self currentSelection] string])
+ if ([[[self currentSelection] string] length])
[pboard addTypes:types owner:nil];
else
[pboard declareTypes:types owner:nil];
@@ -1128,7 +1130,7 @@
mouseDownInAnnotation = NO;
} else {
[super mouseDown:theEvent];
- if (floor(NSAppKitVersionNumber) >
NSAppKitVersionNumber10_4 && toolMode == SKNoteToolMode && hideNotes == NO &&
[self currentSelection] && (annotationMode == SKHighlightNote || annotationMode
== SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
+ if (floor(NSAppKitVersionNumber) >
NSAppKitVersionNumber10_4 && toolMode == SKNoteToolMode && hideNotes == NO &&
(annotationMode == SKHighlightNote || annotationMode == SKUnderlineNote ||
annotationMode == SKStrikeOutNote) && [[[self currentSelection] string]
length]) {
[self addAnnotationWithType:annotationMode];
[self setCurrentSelection:nil];
}
@@ -1178,7 +1180,7 @@
mouseDownInAnnotation = NO;
dragMask = 0;
}
- if (toolMode == SKNoteToolMode && hideNotes == NO && [self
currentSelection] && (annotationMode == SKHighlightNote || annotationMode ==
SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
+ if (toolMode == SKNoteToolMode && hideNotes == NO &&
(annotationMode == SKHighlightNote || annotationMode == SKUnderlineNote ||
annotationMode == SKStrikeOutNote) && [[[self currentSelection] string]
length]) {
[self addAnnotationWithType:annotationMode];
[self setCurrentSelection:nil];
[super mouseUp:theEvent]; // this may be necssary to clean up
a selection rect
@@ -1248,10 +1250,10 @@
- (void)lookUpCurrentSelectionInDictionary:(id)sender;
{
NSString *text = [[self currentSelection] string];
- if (nil == text)
+ if ([text length])
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL
URLWithString:[@"dict:///" stringByAppendingString:text]]];
+ else
NSBeep();
- else
- [[NSWorkspace sharedWorkspace] openURL:[NSURL
URLWithString:[@"dict:///" stringByAppendingString:text]]];
}
- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
@@ -1344,7 +1346,7 @@
item = [menu insertItemWithTitle:NSLocalizedString(@"Take Snapshot",
@"Menu item title") action:@selector(takeSnapshot:) keyEquivalent:@""
atIndex:0];
[item setTarget:self];
- if ([self toolMode] == SKTextToolMode && [[self currentSelection] string]
&& NSAppKitVersionNumber <= NSAppKitVersionNumber10_4) {
+ if ([self toolMode] == SKTextToolMode && [[[self currentSelection] string]
length] && NSAppKitVersionNumber <= NSAppKitVersionNumber10_4) {
[menu insertItem:[NSMenuItem separatorItem] atIndex:0];
@@ -1373,7 +1375,7 @@
[item setTag:SKSquareNote];
[item setTarget:self];
- if ([self currentSelection]) {
+ if ([[[self currentSelection] string] length]) {
item = [submenu addItemWithTitle:NSLocalizedString(@"Highlight",
@"Menu item title") action:@selector(addAnnotation:) keyEquivalent:@""];
[item setTag:SKHighlightNote];
[item setTarget:self];
@@ -1469,7 +1471,7 @@
item = [menu insertItemWithTitle:NSLocalizedString(@"Paste",
@"Menu item title") action:selector keyEquivalent:@"" atIndex:0];
}
- if ([self currentSelection] || ([activeAnnotation isSkimNote] &&
[activeAnnotation isMovable])) {
+ if (([activeAnnotation isSkimNote] && [activeAnnotation isMovable]) ||
[[[self currentSelection] string] length]) {
if ([activeAnnotation isSkimNote] && [activeAnnotation isMovable])
item = [menu insertItemWithTitle:NSLocalizedString(@"Cut",
@"Menu item title") action:@selector(copy:) keyEquivalent:@"" atIndex:0];
item = [menu insertItemWithTitle:NSLocalizedString(@"Copy", @"Menu
item title") action:@selector(copy:) keyEquivalent:@"" atIndex:0];
@@ -1478,7 +1480,7 @@
if ([[menu itemAtIndex:0] isSeparatorItem])
[menu removeItemAtIndex:0];
- } else if ((toolMode == SKSelectToolMode && NSIsEmptyRect(selectionRect)
== NO) || ([self toolMode] == SKTextToolMode && [self currentSelection] &&
[self hideNotes])) {
+ } else if ((toolMode == SKSelectToolMode && NSIsEmptyRect(selectionRect)
== NO) || ([self toolMode] == SKTextToolMode && [self hideNotes] && [[[self
currentSelection] string] length])) {
[menu insertItem:[NSMenuItem separatorItem] atIndex:0];
@@ -1606,7 +1608,7 @@
PDFSelection *selection = [self currentSelection];
PDFPage *page = [self currentPage];
NSUInteger numRanges, idx = 0;
- if ([[selection pages] count]) {
+ if ([[selection string] length]) {
page = [[selection pages] lastObject];
numRanges = [selection safeNumberOfRangesOnPage:page];
if (numRanges > 0) {
@@ -1622,7 +1624,7 @@
PDFSelection *selection = [self currentSelection];
PDFPage *page = [self currentPage];
NSUInteger idx = 0;
- if ([[selection pages] count]) {
+ if ([[selection string] length]) {
page = [[selection pages] objectAtIndex:0];
if ([selection safeNumberOfRangesOnPage:page] > 0) {
idx = [selection safeRangeAtIndex:0 onPage:page].location;
@@ -1872,9 +1874,7 @@
PDFSelection *selection = [self currentSelection];
NSString *text = nil;
- if (selection != nil) {
- selection = [self currentSelection];
-
+ if ([[selection string] length]) {
text = [selection cleanedString];
// Get bounds (page space) for selection (first page in case
selection spans multiple pages).
@@ -2462,7 +2462,7 @@
[menuItem setState:[self annotationMode] == (SKToolMode)[menuItem
tag] ? NSOnState : NSOffState];
return YES;
} else if (action == @selector(copy:)) {
- if ([self currentSelection])
+ if ([[[self currentSelection] string] length])
return YES;
if ([activeAnnotation isSkimNote] && [activeAnnotation isMovable])
return YES;
@@ -2482,7 +2482,7 @@
} else if (action == @selector(selectAll:)) {
return toolMode == SKTextToolMode;
} else if (action == @selector(deselectAll:)) {
- return [self currentSelection] != nil;
+ return [[[self currentSelection] string] length] != 0;
} else if (action == @selector(autoSelectContent:)) {
return toolMode == SKSelectToolMode;
} else {
@@ -3729,7 +3729,8 @@
[self setCurrentSelection:wasSelection];
} else if (modifiers & NSShiftKeyMask) {
extendSelection = YES;
- wasSelection = [[self currentSelection] retain];
+ if ([[[self currentSelection] string] length])
+ wasSelection = [[self currentSelection] retain];
NSPoint p = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
PDFPage *page = [self pageForPoint:p nearest:YES];
p = [self convertPoint:p toPage:page];
@@ -3788,7 +3789,7 @@
}
}
- if (toolMode == SKNoteToolMode && hideNotes == NO && [self
currentSelection] && (annotationMode == SKHighlightNote || annotationMode ==
SKUnderlineNote || annotationMode == SKStrikeOutNote)) {
+ if (toolMode == SKNoteToolMode && hideNotes == NO && (annotationMode ==
SKHighlightNote || annotationMode == SKUnderlineNote || annotationMode ==
SKStrikeOutNote) && [[[self currentSelection] string] length]) {
[self addAnnotationWithType:annotationMode];
[self setCurrentSelection:nil];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit