summaryrefslogtreecommitdiff
path: root/pluma/osx/pluma-osx.c
blob: b9e23c90e204e4c75eff00cfb703737217112939 (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 "pluma-osx.h"
#include <gdk/gdkquartz.h>
#include <Carbon/Carbon.h>

#import "pluma-osx-delegate.h"

void
pluma_osx_set_window_title (PlumaWindow   *window, 
			    gchar const   *title,
			    PlumaDocument *document)
{
	NSWindow *native;

	g_return_if_fail (PLUMA_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 (pluma_document_is_untitled (document))
		{
			[native setRepresentedURL:nil];
		}
		else
		{
			const gchar *uri = pluma_document_get_uri (document);
			NSURL *nsurl = [NSURL URLWithString:[NSString stringWithUTF8String:uri]];
			
			[native setRepresentedURL:nsurl];
		}

		ismodified = !pluma_document_is_untouched (document); 
		[native setDocumentEdited:ismodified];
	}
	else
	{
		[native setRepresentedURL:nil];
		[native setDocumentEdited:false];
	}

	gtk_window_set_title (GTK_WINDOW (window), title);
}

gboolean
pluma_osx_show_url (const gchar *url)
{
 	return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
}

gboolean
pluma_osx_show_help (const gchar *link_id)
{
	gchar *link;
	gboolean ret;

	if (link_id)
	{
		link = g_strdup_printf ("http://library.gnome.org/users/pluma/stable/%s",
					link_id);
	}
	else
	{
		link = g_strdup ("http://library.gnome.org/users/pluma/stable/");
	}

	ret = pluma_osx_show_url (link);
	g_free (link);

	return ret;
}

static void
destroy_delegate (PlumaOSXDelegate *delegate)
{
	[delegate dealloc];
}

void
pluma_osx_init(PlumaApp *app)
{
	PlumaOSXDelegate *delegate = [[PlumaOSXDelegate alloc] init];
	
	g_object_set_data_full (G_OBJECT (app),
	                        "PlumaOSXDelegate",
	                        delegate,
							(GDestroyNotify)destroy_delegate);
}