/
NewTabButton.m
74 lines (56 loc) · 1.67 KB
/
NewTabButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// NewTabButton.m
// StainlessClient
//
// Created by Danny Espinoza on 2/24/09.
// Copyright 2009 Mesa Dynamics, LLC. All rights reserved.
//
#import "NewTabButton.h"
#import "StainlessController.h"
extern NSString* StainlessBookmarkPboardType;
extern NSString* WebURLPboardType;
@implementation NewTabButton
- (id)initWithFrame:(NSRect)frame
{
if(self = [super initWithFrame:frame]) {
[self setIgnoresMultiClick:YES];
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSURLPboardType, WebURLPboardType, nil]];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
// NSDraggingDestination protocol
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
{
return NSDragOperationCopy;
}
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender
{
NSString* urlString = nil;
NSPasteboard* pboard = [sender draggingPasteboard];
[pboard types];
NSString* bookmarkIndexString = [pboard stringForType:StainlessBookmarkPboardType];
if(bookmarkIndexString) {
StainlessController* controller = (StainlessController*)[NSApp delegate];
[controller openURLString:bookmarkIndexString expandGroup:NO];
return YES;
}
NSURL* url = [NSURL URLFromPasteboard:pboard];
if(url)
urlString = [url absoluteString];
if(urlString == nil) {
NSData* data = [pboard dataForType:WebURLPboardType];
if(data)
urlString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
}
if(urlString && ([urlString hasPrefix:@"http:"] || [urlString hasPrefix:@"https:"])) {
StainlessController* controller = (StainlessController*)[NSApp delegate];
[controller openURLString:urlString];
return YES;
}
return NO;
}
@end