2015-10-11 20:39:18 +00:00
|
|
|
/* gtkshortcutsshortcut.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Christian Hergert <christian@hergert.me>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkshortcutsshortcut.h"
|
|
|
|
|
|
|
|
#include "gtkshortcutlabelprivate.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkshortcutsshortcut
|
|
|
|
* @Title: GtkShortcutsShortcut
|
|
|
|
* @Short_description: Represents a keyboard shortcut in a GtkShortcutsWindow
|
|
|
|
*
|
2015-11-22 07:24:12 +00:00
|
|
|
* A GtkShortcutsShortcut represents a single keyboard shortcut or gesture
|
|
|
|
* with a short text. This widget is only meant to be used with #GtkShortcutsWindow.
|
2015-10-11 20:39:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GtkShortcutsShortcut
|
|
|
|
{
|
|
|
|
GtkBox parent_instance;
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
GtkImage *image;
|
2015-10-11 20:39:18 +00:00
|
|
|
GtkShortcutLabel *accelerator;
|
|
|
|
GtkLabel *title;
|
2015-11-22 06:18:54 +00:00
|
|
|
GtkLabel *subtitle;
|
|
|
|
GtkLabel *title_box;
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
GtkSizeGroup *accel_size_group;
|
|
|
|
GtkSizeGroup *title_size_group;
|
2015-11-15 03:34:19 +00:00
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
gboolean subtitle_set;
|
|
|
|
gboolean icon_set;
|
2015-11-15 03:34:19 +00:00
|
|
|
GtkTextDirection direction;
|
2015-11-22 07:24:12 +00:00
|
|
|
GtkShortcutType shortcut_type;
|
2015-10-11 20:39:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkShortcutsShortcutClass
|
|
|
|
{
|
|
|
|
GtkBoxClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkShortcutsShortcut, gtk_shortcuts_shortcut, GTK_TYPE_BOX)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_ACCELERATOR,
|
2015-11-22 06:18:54 +00:00
|
|
|
PROP_ICON,
|
2015-11-22 20:27:05 +00:00
|
|
|
PROP_ICON_SET,
|
2015-10-11 20:39:18 +00:00
|
|
|
PROP_TITLE,
|
2015-11-22 06:18:54 +00:00
|
|
|
PROP_SUBTITLE,
|
2015-11-22 20:27:05 +00:00
|
|
|
PROP_SUBTITLE_SET,
|
2015-10-11 20:39:18 +00:00
|
|
|
PROP_ACCEL_SIZE_GROUP,
|
|
|
|
PROP_TITLE_SIZE_GROUP,
|
2015-11-15 03:34:19 +00:00
|
|
|
PROP_DIRECTION,
|
2015-11-22 07:24:12 +00:00
|
|
|
PROP_SHORTCUT_TYPE,
|
2015-10-11 20:39:18 +00:00
|
|
|
LAST_PROP
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties[LAST_PROP];
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_accelerator (GtkShortcutsShortcut *self,
|
|
|
|
const gchar *accelerator)
|
|
|
|
{
|
|
|
|
gtk_shortcut_label_set_accelerator (self->accelerator, accelerator);
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_accel_size_group (GtkShortcutsShortcut *self,
|
|
|
|
GtkSizeGroup *group)
|
|
|
|
{
|
|
|
|
if (self->accel_size_group)
|
2015-11-22 06:18:54 +00:00
|
|
|
{
|
|
|
|
gtk_size_group_remove_widget (self->accel_size_group, GTK_WIDGET (self->accelerator));
|
|
|
|
gtk_size_group_remove_widget (self->accel_size_group, GTK_WIDGET (self->image));
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
if (group)
|
2015-11-22 06:18:54 +00:00
|
|
|
{
|
|
|
|
gtk_size_group_add_widget (group, GTK_WIDGET (self->accelerator));
|
|
|
|
gtk_size_group_add_widget (group, GTK_WIDGET (self->image));
|
|
|
|
}
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
g_set_object (&self->accel_size_group, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_title_size_group (GtkShortcutsShortcut *self,
|
|
|
|
GtkSizeGroup *group)
|
|
|
|
{
|
|
|
|
if (self->title_size_group)
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_size_group_remove_widget (self->title_size_group, GTK_WIDGET (self->title_box));
|
2015-10-11 20:39:18 +00:00
|
|
|
if (group)
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_size_group_add_widget (group, GTK_WIDGET (self->title_box));
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
g_set_object (&self->title_size_group, group);
|
|
|
|
}
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
static void
|
|
|
|
update_subtitle_from_type (GtkShortcutsShortcut *self)
|
|
|
|
{
|
|
|
|
const gchar *subtitle;
|
|
|
|
|
|
|
|
if (self->subtitle_set)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (self->shortcut_type)
|
|
|
|
{
|
|
|
|
case GTK_SHORTCUT_ACCELERATOR:
|
|
|
|
case GTK_SHORTCUT_GESTURE:
|
|
|
|
subtitle = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_PINCH:
|
|
|
|
subtitle = _("Two finger pinch");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_STRETCH:
|
|
|
|
subtitle = _("Two finger stretch");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE:
|
|
|
|
subtitle = _("Rotate clockwise");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE:
|
|
|
|
subtitle = _("Rotate counterclockwise");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT:
|
|
|
|
subtitle = _("Two finger swipe left");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT:
|
|
|
|
subtitle = _("Two finger swipe right");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
subtitle = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_label_set_label (self->subtitle, subtitle);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->subtitle), subtitle != NULL);
|
|
|
|
g_object_notify (G_OBJECT (self), "subtitle");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_subtitle_set (GtkShortcutsShortcut *self,
|
|
|
|
gboolean subtitle_set)
|
|
|
|
{
|
|
|
|
if (self->subtitle_set != subtitle_set)
|
|
|
|
{
|
|
|
|
self->subtitle_set = subtitle_set;
|
|
|
|
g_object_notify (G_OBJECT (self), "subtitle-set");
|
|
|
|
}
|
|
|
|
update_subtitle_from_type (self);
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_shortcuts_shortcut_set_subtitle (GtkShortcutsShortcut *self,
|
|
|
|
const gchar *subtitle)
|
2015-10-11 20:39:18 +00:00
|
|
|
{
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_label_set_label (self->subtitle, subtitle);
|
2015-11-22 20:27:05 +00:00
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->subtitle), subtitle && subtitle[0]);
|
|
|
|
gtk_shortcuts_shortcut_set_subtitle_set (self, subtitle && subtitle[0]);
|
|
|
|
|
2015-11-22 07:24:12 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "subtitle");
|
2015-11-22 06:18:54 +00:00
|
|
|
}
|
2015-11-15 03:34:19 +00:00
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
static void
|
2015-11-22 20:27:05 +00:00
|
|
|
update_icon_from_type (GtkShortcutsShortcut *self)
|
2015-11-22 06:18:54 +00:00
|
|
|
{
|
2015-11-23 15:07:44 +00:00
|
|
|
GIcon *icon;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
if (self->icon_set)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (self->shortcut_type)
|
|
|
|
{
|
|
|
|
case GTK_SHORTCUT_GESTURE_PINCH:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-pinch-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_STRETCH:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-stretch-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_ROTATE_CLOCKWISE:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-rotate-clockwise-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_ROTATE_COUNTERCLOCKWISE:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-rotate-anticlockwise-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_LEFT:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-two-finger-swipe-left-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_SHORTCUT_GESTURE_TWO_FINGER_SWIPE_RIGHT:
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = g_themed_icon_new ("gesture-two-finger-swipe-right-symbolic");
|
2015-11-22 20:27:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: ;
|
2015-11-23 15:07:44 +00:00
|
|
|
icon = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
gtk_image_set_from_gicon (self->image, icon, GTK_ICON_SIZE_DIALOG);
|
|
|
|
gtk_image_set_pixel_size (self->image, 64);
|
|
|
|
g_object_unref (icon);
|
2015-11-22 20:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_icon_set (GtkShortcutsShortcut *self,
|
|
|
|
gboolean icon_set)
|
|
|
|
{
|
|
|
|
if (self->icon_set != icon_set)
|
|
|
|
{
|
|
|
|
self->icon_set = icon_set;
|
|
|
|
g_object_notify (G_OBJECT (self), "icon-set");
|
|
|
|
}
|
|
|
|
update_icon_from_type (self);
|
2015-11-22 06:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_icon (GtkShortcutsShortcut *self,
|
|
|
|
GIcon *gicon)
|
|
|
|
{
|
|
|
|
gtk_image_set_from_gicon (self->image, gicon, GTK_ICON_SIZE_DIALOG);
|
2015-11-22 20:27:05 +00:00
|
|
|
gtk_shortcuts_shortcut_set_icon_set (self, gicon != NULL);
|
|
|
|
g_object_notify (G_OBJECT (self), "icon");
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
static void
|
2015-11-22 20:27:05 +00:00
|
|
|
update_visible_from_direction (GtkShortcutsShortcut *self)
|
2015-11-15 03:34:19 +00:00
|
|
|
{
|
|
|
|
if (self->direction == GTK_TEXT_DIR_NONE ||
|
|
|
|
self->direction == gtk_widget_get_direction (GTK_WIDGET (self)))
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self), TRUE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_direction (GtkShortcutsShortcut *self,
|
|
|
|
GtkTextDirection direction)
|
|
|
|
{
|
|
|
|
if (self->direction == direction)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->direction = direction;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
update_visible_from_direction (self);
|
2015-11-19 23:05:35 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "direction");
|
2015-11-15 03:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_direction_changed (GtkWidget *widget,
|
|
|
|
GtkTextDirection previous_dir)
|
|
|
|
{
|
2015-11-22 20:27:05 +00:00
|
|
|
update_visible_from_direction (GTK_SHORTCUTS_SHORTCUT (widget));
|
2015-11-15 03:34:19 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_shortcuts_shortcut_parent_class)->direction_changed (widget, previous_dir);
|
|
|
|
}
|
|
|
|
|
2015-11-22 07:24:12 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_type (GtkShortcutsShortcut *self,
|
|
|
|
GtkShortcutType type)
|
|
|
|
{
|
|
|
|
if (self->shortcut_type == type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->shortcut_type = type;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
update_subtitle_from_type (self);
|
|
|
|
update_icon_from_type (self);
|
2015-11-22 07:24:12 +00:00
|
|
|
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->accelerator), type == GTK_SHORTCUT_ACCELERATOR);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (self->image), type != GTK_SHORTCUT_ACCELERATOR);
|
|
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (self), "shortcut-type");
|
|
|
|
}
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkShortcutsShortcut *self = GTK_SHORTCUTS_SHORTCUT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_TITLE:
|
|
|
|
g_value_set_string (value, gtk_label_get_label (self->title));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_SUBTITLE:
|
|
|
|
g_value_set_string (value, gtk_label_get_label (self->subtitle));
|
|
|
|
break;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
case PROP_SUBTITLE_SET:
|
|
|
|
g_value_set_boolean (value, self->subtitle_set);
|
|
|
|
break;
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
case PROP_ACCELERATOR:
|
|
|
|
g_value_set_string (value, gtk_shortcut_label_get_accelerator (self->accelerator));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON:
|
|
|
|
{
|
|
|
|
GIcon *icon;
|
|
|
|
|
|
|
|
gtk_image_get_gicon (self->image, &icon, NULL);
|
|
|
|
g_value_set_object (value, icon);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
case PROP_ICON_SET:
|
|
|
|
g_value_set_boolean (value, self->icon_set);
|
|
|
|
break;
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
case PROP_DIRECTION:
|
|
|
|
g_value_set_enum (value, self->direction);
|
|
|
|
break;
|
|
|
|
|
2015-11-22 07:24:12 +00:00
|
|
|
case PROP_SHORTCUT_TYPE:
|
|
|
|
g_value_set_enum (value, self->shortcut_type);
|
|
|
|
break;
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkShortcutsShortcut *self = GTK_SHORTCUTS_SHORTCUT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_ACCELERATOR:
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_shortcuts_shortcut_set_accelerator (self, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ICON:
|
|
|
|
gtk_shortcuts_shortcut_set_icon (self, g_value_get_object (value));
|
2015-10-11 20:39:18 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
case PROP_ICON_SET:
|
|
|
|
gtk_shortcuts_shortcut_set_icon_set (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
case PROP_ACCEL_SIZE_GROUP:
|
|
|
|
gtk_shortcuts_shortcut_set_accel_size_group (self, GTK_SIZE_GROUP (g_value_get_object (value)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TITLE:
|
|
|
|
gtk_label_set_label (self->title, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
case PROP_SUBTITLE:
|
|
|
|
gtk_shortcuts_shortcut_set_subtitle (self, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
case PROP_SUBTITLE_SET:
|
|
|
|
gtk_shortcuts_shortcut_set_subtitle_set (self, g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
case PROP_TITLE_SIZE_GROUP:
|
|
|
|
gtk_shortcuts_shortcut_set_title_size_group (self, GTK_SIZE_GROUP (g_value_get_object (value)));
|
|
|
|
break;
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
case PROP_DIRECTION:
|
|
|
|
gtk_shortcuts_shortcut_set_direction (self, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
2015-11-22 07:24:12 +00:00
|
|
|
case PROP_SHORTCUT_TYPE:
|
|
|
|
gtk_shortcuts_shortcut_set_type (self, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkShortcutsShortcut *self = GTK_SHORTCUTS_SHORTCUT (object);
|
|
|
|
|
|
|
|
g_clear_object (&self->accel_size_group);
|
|
|
|
g_clear_object (&self->title_size_group);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_shortcuts_shortcut_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_add (GtkContainer *container,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_warning ("Can't add children to %s", G_OBJECT_TYPE_NAME (container));
|
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gtk_shortcuts_shortcut_child_type (GtkContainer *container)
|
|
|
|
{
|
|
|
|
return G_TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_class_init (GtkShortcutsShortcutClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2015-11-15 03:34:19 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
|
2015-10-11 20:39:18 +00:00
|
|
|
|
|
|
|
object_class->finalize = gtk_shortcuts_shortcut_finalize;
|
|
|
|
object_class->get_property = gtk_shortcuts_shortcut_get_property;
|
|
|
|
object_class->set_property = gtk_shortcuts_shortcut_set_property;
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
widget_class->direction_changed = gtk_shortcuts_shortcut_direction_changed;
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
container_class->add = gtk_shortcuts_shortcut_add;
|
|
|
|
container_class->child_type = gtk_shortcuts_shortcut_child_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:accelerator:
|
|
|
|
*
|
2015-11-22 20:27:05 +00:00
|
|
|
* The accelerator(s) represented by this object. This property is used
|
|
|
|
* if #GtkShorcutsShortcut:shortcut-type is set to #GTK_SHORTCUT_ACCELERATOR.
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
2015-11-22 20:27:05 +00:00
|
|
|
* The syntax of this property is (an extension of) the syntax understood by
|
|
|
|
* gtk_accelerator_parse(). Multiple accelerators can be specified by separating
|
|
|
|
* them with a space, but keep in mind that the available width is limited.
|
|
|
|
* It is also possible to specify ranges of shortcuts, using ... between the keys.
|
|
|
|
* Sequences of keys can be specified using a + between the keys.
|
2015-10-22 18:31:06 +00:00
|
|
|
*
|
2015-11-22 20:27:05 +00:00
|
|
|
* Examples:
|
2015-11-15 02:34:43 +00:00
|
|
|
* - A single shortcut: <ctl><alt>delete
|
2015-10-22 18:31:06 +00:00
|
|
|
* - Two alternative shortcuts: <shift>a Home
|
2015-11-15 02:34:43 +00:00
|
|
|
* - A range of shortcuts: <alt>1...<alt>9
|
|
|
|
* - A sequence of key combinations: <ctl>c+<ctl>x
|
2015-10-11 20:39:18 +00:00
|
|
|
*
|
2015-11-13 11:37:59 +00:00
|
|
|
* Note that < and > need to be escaped as < and > when used
|
2015-10-11 20:39:18 +00:00
|
|
|
* in .ui files.
|
|
|
|
*/
|
|
|
|
properties[PROP_ACCELERATOR] =
|
|
|
|
g_param_spec_string ("accelerator",
|
|
|
|
P_("Accelerator"),
|
2015-11-22 20:27:05 +00:00
|
|
|
P_("The accelerator keys for shortcuts of type 'Accelerator'"),
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:icon:
|
|
|
|
*
|
2015-11-22 20:27:05 +00:00
|
|
|
* An icon to represent the shortcut or gesture. This property is used if
|
|
|
|
* #GtkShortcutsShortcut:shortcut-type is set to #GTK_SHORTCUT_GESTURE.
|
|
|
|
* For the other predefined gesture types, GTK+ provides an icon on its own.
|
2015-11-22 06:18:54 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_ICON] =
|
|
|
|
g_param_spec_object ("icon",
|
|
|
|
P_("Icon"),
|
2015-11-22 20:27:05 +00:00
|
|
|
P_("The icon to show for shortcuts of type 'Other Gesture'"),
|
2015-11-22 06:18:54 +00:00
|
|
|
G_TYPE_ICON,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:icon-set:
|
|
|
|
*
|
|
|
|
* %TRUE if an icon has been set.
|
|
|
|
*/
|
|
|
|
properties[PROP_ICON_SET] =
|
|
|
|
g_param_spec_boolean ("icon-set",
|
|
|
|
P_("Icon Set"),
|
|
|
|
P_("Whether an icon has been set"),
|
|
|
|
FALSE,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:title:
|
|
|
|
*
|
2015-11-22 06:18:54 +00:00
|
|
|
* The textual description for the shortcut or gesture represented by
|
2015-11-22 20:27:05 +00:00
|
|
|
* this object. This should be a short string that can fit in a single line.
|
2015-10-11 20:39:18 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_TITLE] =
|
|
|
|
g_param_spec_string ("title",
|
|
|
|
P_("Title"),
|
2015-11-22 20:27:05 +00:00
|
|
|
P_("A short description for the shortcut"),
|
2015-10-27 12:48:08 +00:00
|
|
|
"",
|
2015-10-11 20:39:18 +00:00
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:subtitle:
|
|
|
|
*
|
|
|
|
* The subtitle for the shortcut or gesture.
|
|
|
|
*
|
|
|
|
* This is typically used for gestures and should be a short, one-line
|
2015-11-22 20:27:05 +00:00
|
|
|
* text that describes the gesture itself. For the predefined gesture
|
|
|
|
* types, GTK+ provides a subtitle on its own.
|
2015-11-22 06:18:54 +00:00
|
|
|
*/
|
|
|
|
properties[PROP_SUBTITLE] =
|
|
|
|
g_param_spec_string ("subtitle",
|
|
|
|
P_("Subtitle"),
|
2015-11-22 20:27:05 +00:00
|
|
|
P_("A short description for the gesture"),
|
2015-11-22 06:18:54 +00:00
|
|
|
"",
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:subtitle-set:
|
|
|
|
*
|
|
|
|
* %TRUE if a subtitle has been set.
|
|
|
|
*/
|
|
|
|
properties[PROP_SUBTITLE_SET] =
|
|
|
|
g_param_spec_boolean ("subtitle-set",
|
|
|
|
P_("Subtitle Set"),
|
|
|
|
P_("Whether a subtitle has been set"),
|
|
|
|
FALSE,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:accel-size-group:
|
|
|
|
*
|
|
|
|
* The size group for the accelerator portion of this shortcut.
|
|
|
|
*
|
|
|
|
* This is used internally by GTK+, and must not be modified by applications.
|
|
|
|
*/
|
|
|
|
properties[PROP_ACCEL_SIZE_GROUP] =
|
|
|
|
g_param_spec_object ("accel-size-group",
|
|
|
|
P_("Accelerator Size Group"),
|
|
|
|
P_("Accelerator Size Group"),
|
|
|
|
GTK_TYPE_SIZE_GROUP,
|
|
|
|
(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:title-size-group:
|
|
|
|
*
|
|
|
|
* The size group for the textual portion of this shortcut.
|
|
|
|
*
|
|
|
|
* This is used internally by GTK+, and must not be modified by applications.
|
|
|
|
*/
|
|
|
|
properties[PROP_TITLE_SIZE_GROUP] =
|
|
|
|
g_param_spec_object ("title-size-group",
|
|
|
|
P_("Title Size Group"),
|
|
|
|
P_("Title Size Group"),
|
|
|
|
GTK_TYPE_SIZE_GROUP,
|
|
|
|
(G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:direction:
|
|
|
|
*
|
|
|
|
* The text direction for which this shortcut is active. If the shortcut
|
|
|
|
* is used regardless of the text direction, set this property to
|
|
|
|
* #GTK_TEXT_DIR_NONE.
|
|
|
|
*/
|
2015-11-15 03:34:19 +00:00
|
|
|
properties[PROP_DIRECTION] =
|
|
|
|
g_param_spec_enum ("direction",
|
|
|
|
P_("Direction"),
|
2015-11-22 07:24:12 +00:00
|
|
|
P_("Text direction for which this shortcut is active"),
|
2015-11-15 03:34:19 +00:00
|
|
|
GTK_TYPE_TEXT_DIRECTION,
|
|
|
|
GTK_TEXT_DIR_NONE,
|
2015-11-19 23:05:35 +00:00
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
|
2015-11-15 03:34:19 +00:00
|
|
|
|
2015-11-22 20:27:05 +00:00
|
|
|
/**
|
|
|
|
* GtkShortcutsShortcut:shortcut-type:
|
|
|
|
*
|
|
|
|
* The type of shortcut that is represented.
|
|
|
|
*/
|
2015-11-22 07:24:12 +00:00
|
|
|
properties[PROP_SHORTCUT_TYPE] =
|
|
|
|
g_param_spec_enum ("shortcut-type",
|
|
|
|
P_("Shortcut Type"),
|
|
|
|
P_("The type of shortcut that is represented"),
|
|
|
|
GTK_TYPE_SHORTCUT_TYPE,
|
|
|
|
GTK_SHORTCUT_ACCELERATOR,
|
|
|
|
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_shortcuts_shortcut_init (GtkShortcutsShortcut *self)
|
|
|
|
{
|
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
gtk_box_set_spacing (GTK_BOX (self), 12);
|
|
|
|
|
2015-11-15 03:34:19 +00:00
|
|
|
self->direction = GTK_TEXT_DIR_NONE;
|
2015-11-22 07:24:12 +00:00
|
|
|
self->shortcut_type = GTK_SHORTCUT_ACCELERATOR;
|
2015-11-15 03:34:19 +00:00
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
self->image = g_object_new (GTK_TYPE_IMAGE,
|
|
|
|
"visible", FALSE,
|
|
|
|
"valign", GTK_ALIGN_CENTER,
|
|
|
|
"no-show-all", TRUE,
|
|
|
|
NULL);
|
|
|
|
GTK_CONTAINER_CLASS (gtk_shortcuts_shortcut_parent_class)->add (GTK_CONTAINER (self), GTK_WIDGET (self->image));
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
self->accelerator = g_object_new (GTK_TYPE_SHORTCUT_LABEL,
|
|
|
|
"visible", TRUE,
|
2015-11-22 06:18:54 +00:00
|
|
|
"valign", GTK_ALIGN_CENTER,
|
|
|
|
"no-show-all", TRUE,
|
2015-10-11 20:39:18 +00:00
|
|
|
NULL);
|
|
|
|
GTK_CONTAINER_CLASS (gtk_shortcuts_shortcut_parent_class)->add (GTK_CONTAINER (self), GTK_WIDGET (self->accelerator));
|
|
|
|
|
2015-11-22 06:18:54 +00:00
|
|
|
self->title_box = g_object_new (GTK_TYPE_BOX,
|
|
|
|
"visible", TRUE,
|
|
|
|
"valign", GTK_ALIGN_CENTER,
|
|
|
|
"hexpand", TRUE,
|
|
|
|
"orientation", GTK_ORIENTATION_VERTICAL,
|
|
|
|
NULL);
|
|
|
|
GTK_CONTAINER_CLASS (gtk_shortcuts_shortcut_parent_class)->add (GTK_CONTAINER (self), GTK_WIDGET (self->title_box));
|
|
|
|
|
2015-10-11 20:39:18 +00:00
|
|
|
self->title = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"visible", TRUE,
|
|
|
|
"xalign", 0.0f,
|
|
|
|
NULL);
|
2015-11-22 06:18:54 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (self->title_box), GTK_WIDGET (self->title));
|
|
|
|
|
|
|
|
self->subtitle = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"visible", FALSE,
|
|
|
|
"no-show-all", TRUE,
|
|
|
|
"xalign", 0.0f,
|
|
|
|
NULL);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self->subtitle)),
|
|
|
|
GTK_STYLE_CLASS_DIM_LABEL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (self->title_box), GTK_WIDGET (self->subtitle));
|
2015-10-11 20:39:18 +00:00
|
|
|
}
|