|
@@ -26,6 +26,8 @@
|
|
|
|
|
|
#import <PDF_Reader_Pro-Swift.h>
|
|
#import <PDF_Reader_Pro-Swift.h>
|
|
|
|
|
|
|
|
+NSString *SKPasteboardTypeLineStyle = @"net.sourceforge.skim-app.pasteboard.line-style";
|
|
|
|
+
|
|
NSNotificationName const CPDFListViewSelectionChangedNotification = @"CPDFListViewSelectionChangedNotification";
|
|
NSNotificationName const CPDFListViewSelectionChangedNotification = @"CPDFListViewSelectionChangedNotification";
|
|
|
|
|
|
NSNotificationName const CPDFListViewToolModeChangeNotification = @"CPDFListViewToolModeChangeNotification";
|
|
NSNotificationName const CPDFListViewToolModeChangeNotification = @"CPDFListViewToolModeChangeNotification";
|
|
@@ -130,6 +132,9 @@ NSNotificationName const KMPDFViewTableAnnotationDidChangeNotification = @"KMPDF
|
|
|
|
|
|
[self addTrackingArea];
|
|
[self addTrackingArea];
|
|
|
|
|
|
|
|
+// [self registerForDraggedTypes:[NSArray arrayWithObjects:NSPasteboardTypeColor, SKPasteboardTypeLineStyle, nil]];
|
|
|
|
+ [self registerForDraggedTypes:[NSArray arrayWithObjects:NSPasteboardTypeFileURL, nil]];
|
|
|
|
+
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePageChangedNotification:)
|
|
name:CPDFViewPageChangedNotification object:self];
|
|
name:CPDFViewPageChangedNotification object:self];
|
|
|
|
|
|
@@ -1446,6 +1451,117 @@ NSNotificationName const KMPDFViewTableAnnotationDidChangeNotification = @"KMPDF
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#pragma mark NSDraggingDestination protocol
|
|
|
|
+
|
|
|
|
+- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
|
|
|
|
+ NSArray *supportArray = [NSArray arrayWithObjects:@"jpg",@"cur",@"bmp",@"jpeg",@"gif",@"png",@"tiff",@"tif",/*@"pic",*/@"ico",@"icns",@"tga",@"psd",@"eps",@"hdr",@"jp2",@"jpc",@"pict",@"sgi",@"pdf", nil];
|
|
|
|
+
|
|
|
|
+ NSPasteboard *pasteboard = [sender draggingPasteboard];
|
|
|
|
+ if ([pasteboard availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]]) {
|
|
|
|
+ NSArray *fileNames = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
+ NSString *filePath = fileNames.firstObject;
|
|
|
|
+ if (fileNames.count == 1 && [supportArray containsObject:[filePath.pathExtension lowercaseString]]) {
|
|
|
|
+ return NSDragOperationCopy;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return NSDragOperationNone;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender {
|
|
|
|
+ NSDragOperation dragOp = NSDragOperationNone;
|
|
|
|
+ NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
+ if ([pboard canReadItemWithDataConformingToTypes:[NSArray arrayWithObjects:NSPasteboardTypeColor, SKPasteboardTypeLineStyle, nil]]) {
|
|
|
|
+ NSPoint location = [self convertPoint:[sender draggingLocation] fromView:nil];
|
|
|
|
+ CPDFPage *page = [self pageForPoint:location nearest:NO];
|
|
|
|
+ if (page) {
|
|
|
|
+ NSArray *annotations = [page annotations];
|
|
|
|
+ CPDFAnnotation *annotation = nil;
|
|
|
|
+ NSInteger i = [annotations count];
|
|
|
|
+ location = [self convertPoint:location toPage:page];
|
|
|
|
+ while (i-- > 0) {
|
|
|
|
+ annotation = [annotations objectAtIndex:i];
|
|
|
|
+ if ([self annoHitTest:location Anno:annotation] &&
|
|
|
|
+ ([pboard canReadItemWithDataConformingToTypes:[NSArray arrayWithObjects:NSPasteboardTypeColor, nil]] || [annotation hasBorder])) {
|
|
|
|
+// if ([annotation isEqual:highlightAnnotation] == NO) {
|
|
|
|
+// if (highlightAnnotation)
|
|
|
|
+// [self setNeedsDisplayForAnnotation:highlightAnnotation];
|
|
|
|
+// [self setHighlightAnnotation:annotation];
|
|
|
|
+// [self setNeedsDisplayForAnnotation:highlightAnnotation];
|
|
|
|
+// }
|
|
|
|
+ dragOp = NSDragOperationGeneric;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (dragOp == NSDragOperationNone /*&& highlightAnnotation*/) {
|
|
|
|
+// [self setNeedsDisplayForAnnotation:highlightAnnotation];
|
|
|
|
+// [self setHighlightAnnotation:nil];
|
|
|
|
+ }
|
|
|
|
+ } else if ([[CPDFListView superclass] instancesRespondToSelector:_cmd]) {
|
|
|
|
+ dragOp = [super draggingUpdated:sender];
|
|
|
|
+ }
|
|
|
|
+ return dragOp;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (BOOL)annoHitTest:(NSPoint)point Anno: (CPDFAnnotation *)anno{
|
|
|
|
+ return [anno shouldDisplay] ? NSPointInRect(point, [self bounds]) : NO;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)draggingExited:(id <NSDraggingInfo>)sender {
|
|
|
|
+ NSPasteboard *pboard = [sender draggingPasteboard];
|
|
|
|
+ if ([pboard canReadItemWithDataConformingToTypes:[NSArray arrayWithObjects:NSPasteboardTypeColor, SKPasteboardTypeLineStyle, nil]]) {
|
|
|
|
+// if (highlightAnnotation) {
|
|
|
|
+// [self setNeedsDisplayForAnnotation:highlightAnnotation];
|
|
|
|
+// [self setHighlightAnnotation:nil];
|
|
|
|
+// }
|
|
|
|
+ } else if ([[CPDFListView superclass] instancesRespondToSelector:_cmd]) {
|
|
|
|
+ [super draggingExited:sender];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
|
|
|
|
+ BOOL performedDrag = NO;
|
|
|
|
+ NSPasteboard *pasteboard = [sender draggingPasteboard];
|
|
|
|
+ if ([sender draggingSource] != self) {
|
|
|
|
+ NSArray* filePaths = [pasteboard propertyListForType:NSFilenamesPboardType];
|
|
|
|
+ NSArray *supportArray= [NSArray arrayWithObjects:@"jpg",@"cur",@"bmp",@"jpeg",@"gif",@"png",@"tiff",@"tif",/*@"pic",*/@"ico",@"icns",@"tga",@"psd",@"eps",@"hdr",@"jp2",@"jpc",@"pict",@"sgi",@"pdf", nil];
|
|
|
|
+
|
|
|
|
+ NSString *filePath = filePaths.firstObject;
|
|
|
|
+ if ([supportArray containsObject:[filePath.pathExtension lowercaseString]]) {
|
|
|
|
+ if (![[IAPProductsManager defaultManager] isAvailableAllFunction]) {
|
|
|
|
+ [[KMPurchaseCompareWindowController sharedInstance] showWindow:nil];
|
|
|
|
+ return NO;
|
|
|
|
+ }
|
|
|
|
+ if([[filePath.pathExtension lowercaseString] isEqual:@"pdf"]) {
|
|
|
|
+ PDFDocument *document = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:filePath]];
|
|
|
|
+ if([document isLocked]) {
|
|
|
|
+ return NO;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ NSImage *image = [[NSImage alloc] initWithContentsOfFile:filePath];
|
|
|
|
+
|
|
|
|
+ NSPoint point = [sender draggingLocation];
|
|
|
|
+ point = [self convertPoint:point fromView:nil];
|
|
|
|
+ CPDFPage *page = [self pageForPoint:point nearest:YES];
|
|
|
|
+ NSRect rect = NSMakeRect(point.x, point.y - 45, 360, 90);
|
|
|
|
+ NSRect bounds = [self convertRect:rect toPage:page];
|
|
|
|
+ if (page != nil) {
|
|
|
|
+ CPDFListStampAnnotation *newAnnotation = [[CPDFListStampAnnotation alloc] initWithDocument:self.document image:image];
|
|
|
|
+ newAnnotation.bounds = bounds;
|
|
|
|
+ [newAnnotation setBorderBoundsWithImage:image];
|
|
|
|
+
|
|
|
|
+ [self addAnnotation:newAnnotation toPage:page];
|
|
|
|
+ [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")];
|
|
|
|
+
|
|
|
|
+ [self updateActiveAnnotations:@[newAnnotation]];
|
|
|
|
+ [self setNeedsDisplayAnnotation:newAnnotation];
|
|
|
|
+ }
|
|
|
|
+ return YES;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return NO;
|
|
|
|
+}
|
|
|
|
+
|
|
#pragma mark - NSPopoverDelegate
|
|
#pragma mark - NSPopoverDelegate
|
|
|
|
|
|
- (void)popoverWillClose:(NSNotification *)notification {
|
|
- (void)popoverWillClose:(NSNotification *)notification {
|