~codygarver/+junk/gnome-builder

« back to all changes in this revision

Viewing changes to src/shortcuts/gb-shortcuts-group.c

  • Committer: Cody Garver
  • Date: 2015-11-21 00:50:38 UTC
  • Revision ID: cody@elementary.io-20151121005038-8wygis63zt0ljqlz
Import https://github.com/chergert/gnome-builder 06e3158922a02a27f4abca250d70aa7b2970e06a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gb-shortcuts-group.c
 
2
 *
 
3
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation, either version 3 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "gb-shortcuts-group.h"
 
20
 
 
21
struct _GbShortcutsGroup
 
22
{
 
23
  GtkBox    parent_instance;
 
24
 
 
25
  GtkLabel *title;
 
26
};
 
27
 
 
28
G_DEFINE_TYPE (GbShortcutsGroup, gb_shortcuts_group, GTK_TYPE_BOX)
 
29
 
 
30
enum {
 
31
  PROP_0,
 
32
  PROP_TITLE,
 
33
  LAST_PROP
 
34
};
 
35
 
 
36
static GParamSpec *gParamSpecs [LAST_PROP];
 
37
 
 
38
static void
 
39
gb_shortcuts_group_get_property (GObject    *object,
 
40
                                 guint       prop_id,
 
41
                                 GValue     *value,
 
42
                                 GParamSpec *pspec)
 
43
{
 
44
  GbShortcutsGroup *self = GB_SHORTCUTS_GROUP (object);
 
45
 
 
46
  switch (prop_id)
 
47
    {
 
48
    case PROP_TITLE:
 
49
      g_value_set_string (value, gtk_label_get_label (self->title));
 
50
      break;
 
51
 
 
52
    default:
 
53
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
54
    }
 
55
}
 
56
 
 
57
static void
 
58
gb_shortcuts_group_set_property (GObject      *object,
 
59
                                 guint         prop_id,
 
60
                                 const GValue *value,
 
61
                                 GParamSpec   *pspec)
 
62
{
 
63
  GbShortcutsGroup *self = GB_SHORTCUTS_GROUP (object);
 
64
 
 
65
  switch (prop_id)
 
66
    {
 
67
    case PROP_TITLE:
 
68
      gtk_label_set_label (self->title, g_value_get_string (value));
 
69
      break;
 
70
 
 
71
    default:
 
72
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
73
    }
 
74
}
 
75
 
 
76
static void
 
77
gb_shortcuts_group_class_init (GbShortcutsGroupClass *klass)
 
78
{
 
79
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
80
 
 
81
  object_class->get_property = gb_shortcuts_group_get_property;
 
82
  object_class->set_property = gb_shortcuts_group_set_property;
 
83
 
 
84
  gParamSpecs [PROP_TITLE] =
 
85
    g_param_spec_string ("title",
 
86
                         "Title",
 
87
                         "Title",
 
88
                         NULL,
 
89
                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
90
 
 
91
  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 
92
}
 
93
 
 
94
static void
 
95
gb_shortcuts_group_init (GbShortcutsGroup *self)
 
96
{
 
97
  PangoAttrList *attrs;
 
98
 
 
99
  gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
 
100
  gtk_box_set_spacing (GTK_BOX (self), 10);
 
101
 
 
102
  attrs = pango_attr_list_new ();
 
103
  pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
 
104
  self->title = g_object_new (GTK_TYPE_LABEL,
 
105
                              "attributes", attrs,
 
106
                              "visible", TRUE,
 
107
                              "xalign", 0.0f,
 
108
                              NULL);
 
109
  gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->title));
 
110
  pango_attr_list_unref (attrs);
 
111
}