blob: 15ecf8132e019ae08e767ceb0f78bcbd0e47b448 (
plain)
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
75
76
77
78
79
80
81
82
83
84
|
#import "pluma-osx-delegate.h"
#import <Foundation/NSAppleEventManager.h>
#import <Foundation/NSAppleEventDescriptor.h>
#import <Foundation/NSData.h>
#include <glib.h>
#include <pluma/pluma-app.h>
#include <pluma/pluma-commands.h>
@implementation PlumaOSXDelegate
-(id)init
{
if ((self = [super init]))
{
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em setEventHandler:self
andSelector:@selector(openFiles:withReply:)
forEventClass:kCoreEventClass
andEventID:kAEOpenDocuments];
}
return self;
}
static PlumaWindow *
get_window(NSAppleEventDescriptor *event)
{
PlumaApp *app = pluma_app_get_default ();
return pluma_app_get_active_window (app);
}
- (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)
{
PlumaWindow *window = get_window (event);
pluma_commands_load_uris (window, uris, NULL, 0);
g_slist_foreach (uris, (GFunc)g_free, NULL);
g_slist_free (uris);
}
}
@end
|