Revision: 3727
http://skim-app.svn.sourceforge.net/skim-app/?rev=3727&view=rev
Author: hofman
Date: 2008-04-14 03:26:40 -0700 (Mon, 14 Apr 2008)
Log Message:
-----------
Support drag and drop from font panel to font picker. Enclose in a try block,
because we use non-documented pasteboard types.
Modified Paths:
--------------
trunk/SKFontPicker.m
Modified: trunk/SKFontPicker.m
===================================================================
--- trunk/SKFontPicker.m 2008-04-13 23:07:52 UTC (rev 3726)
+++ trunk/SKFontPicker.m 2008-04-14 10:26:40 UTC (rev 3727)
@@ -39,6 +39,10 @@
#import "SKFontPicker.h"
#import "OBUtilities.h"
+static NSString *SKNSFontPanelDescriptorsPboardType =
@"NSFontPanelDescriptorsPboardType";
+static NSString *SKNSFontPanelFamiliesPboardType =
@"NSFontPanelFamiliesPboardType";
+static NSString *SKNSFontCollectionFontDescriptors =
@"NSFontCollectionFontDescriptors";
+
static NSString *SKFontPickerWillBecomeActiveNotification =
@"SKFontPickerWillBecomeActiveNotification";
NSString *SKFontPickerFontNameKey = @"fontName";
@@ -91,6 +95,7 @@
updatingFromFontPanel = NO;
updatingFromBinding = NO;
bindingInfo = [[NSMutableDictionary alloc] init];
+ [self registerForDraggedTypes:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]];
}
return self;
}
@@ -117,6 +122,7 @@
updatingFromFontPanel = NO;
updatingFromBinding = NO;
bindingInfo = [[NSMutableDictionary alloc] init];
+ [self registerForDraggedTypes:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]];
}
return self;
}
@@ -395,4 +401,66 @@
return info;
}
+#pragma mark NSDraggingDestination protocol
+
+- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
+ if ([self isEnabled] && [sender draggingSource] != self && [[sender
draggingPasteboard] availableTypeFromArray:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]]) {
+ [[self cell] setHighlighted:YES];
+ [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+ [self setNeedsDisplay:YES];
+ return NSDragOperationEvery;
+ } else
+ return NSDragOperationNone;
+}
+
+- (void)draggingExited:(id <NSDraggingInfo>)sender {
+ if ([self isEnabled] && [sender draggingSource] != self && [[sender
draggingPasteboard] availableTypeFromArray:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]]) {
+ [[self cell] setHighlighted:NO];
+ [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+ [self setNeedsDisplay:YES];
+ }
+}
+
+- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender {
+ return [self isEnabled] && [sender draggingSource] != self && [[sender
draggingPasteboard] availableTypeFromArray:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]];
+}
+
+- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender{
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ NSString *type = [pboard availableTypeFromArray:[NSArray
arrayWithObjects:SKNSFontPanelDescriptorsPboardType,
SKNSFontPanelFamiliesPboardType, nil]];
+ NSFont *droppedFont = nil;
+
+ @try {
+ if ([type isEqualToString:SKNSFontPanelDescriptorsPboardType]) {
+ NSData *data = [pboard dataForType:type];
+ NSDictionary *dict = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
+ NSArray *fontDescriptors = [dict
objectForKey:SKNSFontCollectionFontDescriptors];
+ NSFontDescriptor *fontDescriptor = [fontDescriptors count] ?
[fontDescriptors objectAtIndex:0] : nil;
+ NSNumber *size = [[fontDescriptor fontAttributes]
objectForKey:NSFontSizeAttribute];
+ if (size == nil)
+ size = [dict objectForKey:NSFontSizeAttribute];
+ float fontSize = size ? [size floatValue] : [self fontSize];
+ droppedFont = [NSFont fontWithDescriptor:fontDescriptor
size:fontSize];
+ } else if ([type isEqualToString:SKNSFontPanelFamiliesPboardType]) {
+ NSArray *families = [pboard propertyListForType:type];
+ NSString *family = [families count] ? [families objectAtIndex:0] :
nil;
+ droppedFont = [[NSFontManager sharedFontManager] convertFont:[self
font] toFamily:family];
+ }
+ }
+ @catch (id exception) {
+ NSLog(@"Ignroing exception %@ when dropping on SKFontPicker failed",
exception);
+ }
+
+ if (droppedFont) {
+ [self setFont:droppedFont];
+ [self sendAction:[self action] to:[self target]];
+ }
+
+ [[self cell] setHighlighted:NO];
+ [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+ [self setNeedsDisplay:YES];
+
+ return droppedFont != nil;
+}
+
@end
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 the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit