summaryrefslogtreecommitdiff
path: root/gedit/osx
diff options
context:
space:
mode:
Diffstat (limited to 'gedit/osx')
-rwxr-xr-xgedit/osx/Makefile.am23
-rwxr-xr-xgedit/osx/gedit-osx-delegate.h16
-rwxr-xr-xgedit/osx/gedit-osx-delegate.m84
-rwxr-xr-xgedit/osx/gedit-osx.c94
-rwxr-xr-xgedit/osx/gedit-osx.h17
5 files changed, 234 insertions, 0 deletions
diff --git a/gedit/osx/Makefile.am b/gedit/osx/Makefile.am
new file mode 100755
index 00000000..4d734169
--- /dev/null
+++ b/gedit/osx/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/gedit \
+ -I$(top_builddir)/gedit \
+ $(GEDIT_CFLAGS) \
+ $(IGE_MAC_CFLAGS) \
+ $(WARN_CFLAGS) \
+ $(DISABLE_DEPRECATED_CFLAGS)
+
+noinst_LTLIBRARIES = libosx.la
+
+libosx_la_LDFLAGS = -framework Carbon -framework ApplicationServices -framework Cocoa
+libosx_la_LIBADD = -lobjc
+libosx_la_CFLAGS = -xobjective-c
+
+libosx_la_SOURCES = \
+ gedit-osx.c \
+ gedit-osx.h \
+ gedit-osx-delegate.m \
+ gedit-osx-delegate.h
+
+-include $(top_srcdir)/git.mk
diff --git a/gedit/osx/gedit-osx-delegate.h b/gedit/osx/gedit-osx-delegate.h
new file mode 100755
index 00000000..0b4411e8
--- /dev/null
+++ b/gedit/osx/gedit-osx-delegate.h
@@ -0,0 +1,16 @@
+#ifndef GEDIT_OSX_DELEGATE_H_
+#define GEDIT_OSX_DELEGATE_H_
+
+#import <Foundation/NSAppleEventManager.h>
+
+@interface GeditOSXDelegate : NSObject
+{
+}
+
+-(id) init;
+-(void) openFiles:(NSAppleEventDescriptor*)event
+ withReply:(NSAppleEventDescriptor*)reply;
+
+@end
+
+#endif /* GEDIT_OSX_DELEGATE_H_ */
diff --git a/gedit/osx/gedit-osx-delegate.m b/gedit/osx/gedit-osx-delegate.m
new file mode 100755
index 00000000..41b0b262
--- /dev/null
+++ b/gedit/osx/gedit-osx-delegate.m
@@ -0,0 +1,84 @@
+#import "gedit-osx-delegate.h"
+#import <Foundation/NSAppleEventManager.h>
+#import <Foundation/NSAppleEventDescriptor.h>
+#import <Foundation/NSData.h>
+#include <glib.h>
+#include <gedit/gedit-app.h>
+#include <gedit/gedit-commands.h>
+
+@implementation GeditOSXDelegate
+-(id)init
+{
+ if ((self = [super init]))
+ {
+ NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
+
+ [em setEventHandler:self
+ andSelector:@selector(openFiles:withReply:)
+ forEventClass:kCoreEventClass
+ andEventID:kAEOpenDocuments];
+ }
+
+ return self;
+}
+
+static GeditWindow *
+get_window(NSAppleEventDescriptor *event)
+{
+ GeditApp *app = gedit_app_get_default ();
+ return gedit_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)
+ {
+ GeditWindow *window = get_window (event);
+ gedit_commands_load_uris (window, uris, NULL, 0);
+
+ g_slist_foreach (uris, (GFunc)g_free, NULL);
+ g_slist_free (uris);
+ }
+}
+
+@end \ No newline at end of file
diff --git a/gedit/osx/gedit-osx.c b/gedit/osx/gedit-osx.c
new file mode 100755
index 00000000..e7a18d42
--- /dev/null
+++ b/gedit/osx/gedit-osx.c
@@ -0,0 +1,94 @@
+#include "gedit-osx.h"
+#include <gdk/gdkquartz.h>
+#include <Carbon/Carbon.h>
+
+#import "gedit-osx-delegate.h"
+
+void
+gedit_osx_set_window_title (GeditWindow *window,
+ gchar const *title,
+ GeditDocument *document)
+{
+ NSWindow *native;
+
+ g_return_if_fail (GEDIT_IS_WINDOW (window));
+
+ if (GTK_WIDGET (window)->window == NULL)
+ {
+ return;
+ }
+
+ native = gdk_quartz_window_get_nswindow (GTK_WIDGET (window)->window);
+
+ if (document)
+ {
+ bool ismodified;
+
+ if (gedit_document_is_untitled (document))
+ {
+ [native setRepresentedURL:nil];
+ }
+ else
+ {
+ const gchar *uri = gedit_document_get_uri (document);
+ NSURL *nsurl = [NSURL URLWithString:[NSString stringWithUTF8String:uri]];
+
+ [native setRepresentedURL:nsurl];
+ }
+
+ ismodified = !gedit_document_is_untouched (document);
+ [native setDocumentEdited:ismodified];
+ }
+ else
+ {
+ [native setRepresentedURL:nil];
+ [native setDocumentEdited:false];
+ }
+
+ gtk_window_set_title (GTK_WINDOW (window), title);
+}
+
+gboolean
+gedit_osx_show_url (const gchar *url)
+{
+ return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
+}
+
+gboolean
+gedit_osx_show_help (const gchar *link_id)
+{
+ gchar *link;
+ gboolean ret;
+
+ if (link_id)
+ {
+ link = g_strdup_printf ("http://library.mate.org/users/gedit/stable/%s",
+ link_id);
+ }
+ else
+ {
+ link = g_strdup ("http://library.mate.org/users/gedit/stable/");
+ }
+
+ ret = gedit_osx_show_url (link);
+ g_free (link);
+
+ return ret;
+}
+
+static void
+destroy_delegate (GeditOSXDelegate *delegate)
+{
+ [delegate dealloc];
+}
+
+void
+gedit_osx_init(GeditApp *app)
+{
+ GeditOSXDelegate *delegate = [[GeditOSXDelegate alloc] init];
+
+ g_object_set_data_full (G_OBJECT (app),
+ "GeditOSXDelegate",
+ delegate,
+ (GDestroyNotify)destroy_delegate);
+} \ No newline at end of file
diff --git a/gedit/osx/gedit-osx.h b/gedit/osx/gedit-osx.h
new file mode 100755
index 00000000..82f0120b
--- /dev/null
+++ b/gedit/osx/gedit-osx.h
@@ -0,0 +1,17 @@
+#ifndef __GEDIT_OSX_H__
+#define __GEDIT_OSX_H__
+
+#include <gtk/gtk.h>
+#include <gedit/gedit-window.h>
+#include <gedit/gedit-app.h>
+
+void gedit_osx_init (GeditApp *app);
+
+void gedit_osx_set_window_title (GeditWindow *window,
+ gchar const *title,
+ GeditDocument *document);
+
+gboolean gedit_osx_show_url (const gchar *url);
+gboolean gedit_osx_show_help (const gchar *link_id);
+
+#endif /* __GEDIT_OSX_H__ */