summaryrefslogtreecommitdiffstats
path: root/src/accel-group.c
blob: 8e16c6bd7f4ba538de45d1d5219f4e960e1aa38e (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
 * Keyboard accelerators
 *
 * Copyright (C) 2018  Patrick McDermott
 *
 * This file is part of Marquee.
 *
 * Marquee is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Marquee is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Marquee.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "accel-group.h"

#include <stdlib.h>

#include <glib.h>
#include <gtk/gtk.h>

#include "application.h"
#include "config/config.h"
#include "i18n.h"
#include "notebook.h"
#include "window.h"

struct _MqAccelGroup {
	GtkAccelGroup  parent_instance;
	MqConfig      *config;
};

enum {
	PROP_CONFIG = 1,
	N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,};

struct _MqAccelGroupClass {
	GtkAccelGroupClass parent_class;
};

G_DEFINE_TYPE(MqAccelGroup, mq_accel_group, GTK_TYPE_ACCEL_GROUP)

static gboolean
accel_close_tab(G_GNUC_UNUSED GtkAccelGroup *accel_group,
	GObject *acceleratable, G_GNUC_UNUSED guint keyval,
	G_GNUC_UNUSED GdkModifierType modifier,
	G_GNUC_UNUSED gpointer user_data)
{
	MqWindow *window;

	window = MQ_WINDOW(acceleratable);

	mq_notebook_remove_current_page(mq_window_get_notebook(window));
	return TRUE;
}

static void
constructed(GObject *object)
{
	MqAccelGroup *accel_group;

	accel_group = MQ_ACCEL_GROUP(object);

	gtk_accel_group_connect(GTK_ACCEL_GROUP(accel_group),
		GDK_KEY_W, GDK_CONTROL_MASK, 0,
		g_cclosure_new(G_CALLBACK(accel_close_tab), NULL, NULL));
}

static void
get_property(GObject *object, guint property_id, GValue *value,
	GParamSpec *param_spec)
{
	MqAccelGroup *accel_group;

	accel_group = MQ_ACCEL_GROUP(object);

	switch (property_id) {
		case PROP_CONFIG:
			g_value_set_pointer(value, accel_group->config);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
				param_spec);
			break;
	}
}

static void
set_property(GObject *object, guint property_id, const GValue *value,
	GParamSpec *param_spec)
{
	MqAccelGroup *accel_group;

	accel_group = MQ_ACCEL_GROUP(object);

	switch (property_id) {
		case PROP_CONFIG:
			accel_group->config = g_value_get_pointer(value);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
				param_spec);
			break;
	}
}

static void
mq_accel_group_class_init(MqAccelGroupClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS(klass);

	object_class->constructed  = constructed;
	object_class->get_property = get_property;
	object_class->set_property = set_property;

	obj_properties[PROP_CONFIG] = g_param_spec_pointer(
		"config",
		P_("MqConfig"),
		P_("The application's MqConfig instance"),
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	g_object_class_install_properties(object_class, N_PROPERTIES,
		obj_properties);
}

static void
mq_accel_group_init(G_GNUC_UNUSED MqAccelGroup *accel_group)
{
}

MqAccelGroup *
mq_accel_group_new(MqConfig *config)
{
	return g_object_new(MQ_TYPE_ACCEL_GROUP,
		"config", config,
		NULL);
}