dragging webloc to tab widget "downloads" webloc rather than opening URL. b=270123 sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2004-12-29 20:12:45 +00:00
parent b5905c1157
commit 1a62ac1991
3 changed files with 84 additions and 17 deletions

View File

@ -202,4 +202,8 @@ typedef enum EBookmarkOpenBehavior
// prompts the user to reset the cache, then does it
- (IBAction)emptyCache:(id)sender;
// open different URL file types
+(NSString*)urlStringFromWebloc:(NSString*)inFile;
+(NSString*)urlStringFromIEURLFile:(NSString*)inFile;
@end

View File

@ -38,6 +38,7 @@
#include <mach-o/dyld.h>
#include <sys/utsname.h>
#import <Carbon/Carbon.h>
#import "NSString+Utils.h"
@ -1496,4 +1497,55 @@ static int SortByProtocolAndName(NSDictionary* item1, NSDictionary* item2, void
queue->ProcessPendingEvents();
}
// Reads the URL from a .webloc . Returns nil on failure.
+(NSString*)urlStringFromWebloc:(NSString*)inFile
{
FSRef ref;
FSSpec spec;
NSString *ret = nil;
if (inFile && !FSPathMakeRef((UInt8 *)[inFile fileSystemRepresentation], &ref, NULL) && !FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &spec, NULL)) {
short resRef;
resRef = FSpOpenResFile(&spec, fsRdPerm);
if (resRef != -1) { // Has resouce fork.
Handle urlResHandle;
if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource with ID 256.
long size;
size = GetMaxResourceSize(urlResHandle);
ret = [NSString stringWithCString:(char *)*urlResHandle length:size];
}
CloseResFile(resRef);
}
}
return ret;
}
// Reads the URL from a .url . Returns nil on failure.
+(NSString*)urlStringFromIEURLFile:(NSString*)inFile
{
NSString *ret = nil;
// Is this really an IE .url file? (Is this too strict?)
if (inFile) {
NSArray *contents = [[NSString stringWithContentsOfFile:inFile] componentsSeparatedByString:@"\r\n"];
unsigned idx = [contents indexOfObject:@"[InternetShortcut]"];
if (idx != NSNotFound) {
NSString *urlline = [contents objectAtIndex:idx + 1];
if ([urlline hasPrefix:@"URL="]) {
ret = [urlline substringFromIndex:4];
}
}
}
return ret;
}
@end

View File

@ -48,6 +48,7 @@
#import "Bookmark.h"
#import "BookmarkToolbar.h"
#import "BrowserTabBarView.h"
#import "MainController.h"
//////////////////////////
@ -397,8 +398,8 @@
// if there's no tabviewitem at the point within our view, check the tabbar as well.
overTabViewItem = [mTabBar tabViewItemAtPoint:[sender draggingLocation]];
if ([pasteBoardTypes containsObject: @"MozBookmarkType"]) {
NSArray* draggedItems = [NSArray pointerArrayFromDataArrayForMozBookmarkDrop:[[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]];
if ([pasteBoardTypes containsObject:@"MozBookmarkType"]) {
NSArray *draggedItems = [NSArray pointerArrayFromDataArrayForMozBookmarkDrop:[[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"]];
if (draggedItems) {
id aBookmark;
if ([draggedItems count] == 1) {
@ -423,18 +424,32 @@
}
}
}
else if ([pasteBoardTypes containsObject: @"MozURLType"]) {
else if ([pasteBoardTypes containsObject:@"MozURLType"]) {
// drag type is MozURLType
NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
NSDictionary *data = [[sender draggingPasteboard] propertyListForType:@"MozURLType"];
if (data) {
NSString* urlString = [data objectForKey:@"url"];
NSString *urlString = [data objectForKey:@"url"];
return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
} // check for NSFilenamesPboardType first so we always handle multiple filenames when we should
else if ([pasteBoardTypes containsObject: NSFilenamesPboardType]) {
} // check for NSFilenamesPboardType next so we always handle multiple filenames when we should
else if ([pasteBoardTypes containsObject:NSFilenamesPboardType]) {
NSArray *files = [[sender draggingPasteboard] propertyListForType:NSFilenamesPboardType];
for (int i = 0; i < [files count]; i ++) {
NSString* urlString = [files objectAtIndex:i];
for (unsigned int i = 0; i < [files count]; i++) {
NSString *file = [files objectAtIndex:i];
NSString *ext = [file pathExtension];
NSString *urlString = nil;
// Check whether the file is a .webloc, a .url, or some other kind of file.
if ([ext isEqualToString:@"webloc"]) // Webloc file
urlString = [MainController urlStringFromWebloc:file];
else if ([ext isEqualToString:@"url"]) // IE URL file
urlString = [MainController urlStringFromIEURLFile:file];
// Use the filename if not a .webloc or .url file, or if either of the
// functions returns nil.
if (!urlString)
urlString = file;
if (i == 0) {
// if we're over the content area, just load the first one
if (overContentArea)
@ -449,12 +464,12 @@
}
return YES;
}
else if ([pasteBoardTypes containsObject: NSStringPboardType]) {
NSString* urlString = [[sender draggingPasteboard] stringForType: NSStringPboardType];
else if ([pasteBoardTypes containsObject:NSStringPboardType]) {
NSString *urlString = [[sender draggingPasteboard] stringForType: NSStringPboardType];
return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:urlString];
}
else if ([pasteBoardTypes containsObject: NSURLPboardType]) {
NSURL* urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
else if ([pasteBoardTypes containsObject:NSURLPboardType]) {
NSURL *urlData = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
return [self handleDropOnTab:overTabViewItem overContent:overContentArea withURL:[urlData absoluteString]];
}
@ -476,7 +491,3 @@
}
@end