xed/pluma/osx/pluma-osx-delegate.m

84 lines
1.7 KiB
Mathematica
Raw Normal View History

2011-11-07 16:52:18 -06:00
#import "pluma-osx-delegate.h"
2011-11-07 13:46:58 -06:00
#import <Foundation/NSAppleEventManager.h>
#import <Foundation/NSAppleEventDescriptor.h>
#import <Foundation/NSData.h>
#include <glib.h>
2011-11-07 16:52:18 -06:00
#include <pluma/pluma-app.h>
#include <pluma/pluma-commands.h>
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
@implementation PlumaOSXDelegate
2011-11-07 13:46:58 -06:00
-(id)init
{
if ((self = [super init]))
{
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(openFiles:withReply:)
forEventClass:kCoreEventClass
andEventID:kAEOpenDocuments];
}
return self;
}
2011-11-07 16:52:18 -06:00
static PlumaWindow *
2011-11-07 13:46:58 -06:00
get_window(NSAppleEventDescriptor *event)
{
2011-11-07 16:52:18 -06:00
PlumaApp *app = pluma_app_get_default ();
return pluma_app_get_active_window (app);
2011-11-07 13:46:58 -06:00
}
- (void)openFiles:(NSAppleEventDescriptor*)event
withReply:(NSAppleEventDescriptor*)reply
{
NSAppleEventDescriptor *fileList = [event paramDescriptorForKeyword:keyDirectObject];
NSInteger i;
GSList *uris = NULL;
if (!fileList)
{
return;
}
for (i = 1; i <= [fileList numberOfItems]; ++i)
{
NSAppleEventDescriptor *fileAliasDesc = [fileList descriptorAtIndex:i];
NSAppleEventDescriptor *fileURLDesc;
NSData *fileURLData;
gchar *url;
if (!fileAliasDesc)
{
continue;
}
fileURLDesc = [fileAliasDesc coerceToDescriptorType:typeFileURL];
if (!fileURLDesc)
{
continue;
}
fileURLData = [fileURLDesc data];
if (!fileURLData)
{
continue;
}
url = g_strndup([fileURLData bytes], [fileURLData length]);
uris = g_slist_prepend (uris, url);
}
if (uris != NULL)
{
2011-11-07 16:52:18 -06:00
PlumaWindow *window = get_window (event);
pluma_commands_load_uris (window, uris, NULL, 0);
2011-11-07 13:46:58 -06:00
g_slist_foreach (uris, (GFunc)g_free, NULL);
g_slist_free (uris);
}
}
@end