/*
* 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;
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);
}