Added rudimentary support for drag and drop of files on window.

git-svn-id: http://macvim.googlecode.com/svn/trunk@90 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
Bjorn Winckler
2007-08-06 13:23:35 +00:00
parent 7249a58d74
commit 31d4006d77
3 changed files with 127 additions and 0 deletions
+55
View File
@@ -1075,6 +1075,61 @@ static int specialKeyToNSKey(int key);
}
} else if (VimShouldCloseMsgID == msgid) {
gui_shell_closed();
} else if (DropFilesMsgID == msgid) {
#ifdef FEAT_DND
const void *bytes = [data bytes];
int n = *((int*)bytes); bytes += sizeof(int);
#if 0
int row = *((int*)bytes); bytes += sizeof(int);
int col = *((int*)bytes); bytes += sizeof(int);
char_u **fnames = (char_u **)alloc(n * sizeof(char_u *));
if (fnames) {
const void *end = [data bytes] + [data length];
int i = 0;
while (bytes < end && i < n) {
int len = *((int*)bytes); bytes += sizeof(int);
fnames[i++] = vim_strnsave((char_u*)bytes, len);
bytes += len;
}
// NOTE! This function will free 'fnames'.
gui_handle_drop(col, row, 0, fnames, i < n ? i : n);
}
#else
// HACK! I'm not sure how to get Vim to open a list of files in tabs,
// so instead I create a ':tab drop' command with all the files to open
// and execute it.
NSMutableString *cmd = [NSMutableString stringWithString:@":tab drop"];
const void *end = [data bytes] + [data length];
int i;
for (i = 0; i < n && bytes < end; ++i) {
int len = *((int*)bytes); bytes += sizeof(int);
NSString *file = [NSString stringWithUTF8String:bytes];
bytes += len;
[cmd appendString:@" "];
[cmd appendString:file];
}
// By going to the last tabpage we ensure that the new tabs will appear
// last (if this call is left out, the taborder becomes messy).
goto_tabpage(9999);
do_cmdline_cmd((char_u*)[cmd UTF8String]);
#if 1
// This code was taken from the end of gui_handle_drop().
update_screen(NOT_VALID);
setcursor();
out_flush();
gui_update_cursor(FALSE, FALSE);
gui_mch_flush();
#endif
#endif
#endif // FEAT_DND
} else {
NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid);
}
+71
View File
@@ -259,6 +259,77 @@
}
#endif
#if 1
- (NSArray *)acceptableDragTypes
{
return [NSArray arrayWithObjects:NSFilenamesPboardType, nil];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
int i, numberOfFiles = [files count];
NSMutableData *data = [NSMutableData data];
[data appendBytes:&numberOfFiles length:sizeof(int)];
#if 0
int row, col;
NSPoint pt = [self convertPoint:[sender draggingLocation] fromView:nil];
if (![self convertPoint:pt toRow:&row column:&col])
return NO;
[data appendBytes:&row length:sizeof(int)];
[data appendBytes:&col length:sizeof(int)];
#endif
for (i = 0; i < numberOfFiles; ++i) {
NSString *file = [files objectAtIndex:i];
int len = [file lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
if (len > 0) {
++len; // append NUL as well
[data appendBytes:&len length:sizeof(int)];
[data appendBytes:[file UTF8String] length:len];
}
}
[[self vimController] sendMessage:DropFilesMsgID data:data wait:NO];
return YES;
}
return NO;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType]
&& (sourceDragMask & NSDragOperationCopy) )
return NSDragOperationCopy;
return NSDragOperationNone;
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
NSDragOperation sourceDragMask = [sender draggingSourceOperationMask];
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType]
&& (sourceDragMask & NSDragOperationCopy) )
return NSDragOperationCopy;
return NSDragOperationNone;
}
#endif
@end // MMTextView
+1
View File
@@ -90,6 +90,7 @@ enum {
VimShouldCloseMsgID,
SetDefaultColorsMsgID,
ExecuteActionMsgID,
DropFilesMsgID,
};