summaryrefslogtreecommitdiff
path: root/gedit/osx/gedit-osx.c
blob: e7a18d42f2c5524a9757a890de3503df58f19944 (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
85
86
87
88
89
90
91
92
93
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);
}