From 68b6c49983c5ba7f3863e1312532635bf3623a90 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 05 Oct 2018 08:34:18 -0400 Subject: MqAccelGroup: New class --- diff --git a/src/accel-group.c b/src/accel-group.c new file mode 100644 index 0000000..1b598b9 --- /dev/null +++ b/src/accel-group.c @@ -0,0 +1,153 @@ +/* + * 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 . + */ + +#include "accel-group.h" + +#include + +#include +#include + +#include "application.h" +#include "config/config.h" +#include "i18n.h" +#include "notebook.h" +#include "window.h" + +struct _MqAccelGroup { + GtkAccelGroup parent_instance; + MqWindow *window; + MqConfig *config; +}; + +enum { + PROP_WINDOW = 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)); + + gtk_window_add_accel_group(GTK_WINDOW(accel_group->window), + GTK_ACCEL_GROUP(accel_group)); +} + +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_WINDOW: + g_value_set_pointer(value, accel_group->window); + 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_WINDOW: + accel_group->window = g_value_get_pointer(value); + accel_group->config = mq_application_get_config( + mq_window_get_application(accel_group->window)); + 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_WINDOW] = g_param_spec_pointer( + "window", + P_("Window"), + P_("The attached MqWindow 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(MqWindow *window) +{ + return g_object_new(MQ_TYPE_ACCEL_GROUP, + "window", window, + NULL); +} diff --git a/src/accel-group.h b/src/accel-group.h new file mode 100644 index 0000000..3f95dc1 --- /dev/null +++ b/src/accel-group.h @@ -0,0 +1,55 @@ +/* + * 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 . + */ + +#ifndef MQ_ACCEL_GROUP_H +#define MQ_ACCEL_GROUP_H + +typedef struct _MqAccelGroup MqAccelGroup; +typedef struct _MqAccelGroupClass MqAccelGroupClass; + +#include +#include + +#include "window.h" + +G_BEGIN_DECLS + +#define MQ_TYPE_ACCEL_GROUP (mq_accel_group_get_type()) +#define MQ_ACCEL_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + MQ_TYPE_ACCEL_GROUP, MqAccelGroup)) +#define MQ_IS_ACCEL_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + MQ_TYPE_ACCEL_GROUP)) +#define MQ_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + MQ_TYPE_ACCEL_GROUP, MqAccelGroupClass)) +#define MQ_IS_ACCEL_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + MQ_TYPE_ACCEL_GROUP)) +#define MQ_ACCEL_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + MQ_TYPE_ACCEL_GROUP, MqAccelGroupClass)) + +GType +mq_accel_group_get_type(void); + +MqAccelGroup * +mq_accel_group_new(MqWindow *window); + +G_END_DECLS + +#endif /* MQ_ACCEL_GROUP_H */ diff --git a/src/local.mk b/src/local.mk index ee0be5e..b3cd013 100644 --- a/src/local.mk +++ b/src/local.mk @@ -1,4 +1,6 @@ marquee_SOURCES += \ + %reldir%/accel-group.c \ + %reldir%/accel-group.h \ %reldir%/application.c \ %reldir%/application.h \ %reldir%/download.c \ -- cgit v0.9.1