~ubuntu-branches/debian/stretch/gnome-builder/stretch

« back to all changes in this revision

Viewing changes to src/workbench/gb-workspace.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2015-10-11 12:38:45 UTC
  • Revision ID: package-import@ubuntu.com-20151011123845-a0hvkz01se0p1p5a
Tags: upstream-3.16.3
ImportĀ upstreamĀ versionĀ 3.16.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gb-workspace.c
 
2
 *
 
3
 * Copyright (C) 2014 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 <glib/gi18n.h>
 
20
 
 
21
#include "gb-workspace.h"
 
22
 
 
23
typedef struct
 
24
{
 
25
  gchar *icon_name;
 
26
  gchar *title;
 
27
} GbWorkspacePrivate;
 
28
 
 
29
enum {
 
30
  PROP_0,
 
31
  PROP_ICON_NAME,
 
32
  PROP_TITLE,
 
33
  LAST_PROP
 
34
};
 
35
 
 
36
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GbWorkspace, gb_workspace, GTK_TYPE_BIN)
 
37
 
 
38
static GParamSpec *gParamSpecs[LAST_PROP];
 
39
 
 
40
const gchar *
 
41
gb_workspace_get_icon_name (GbWorkspace *self)
 
42
{
 
43
  GbWorkspacePrivate *priv = gb_workspace_get_instance_private (self);
 
44
 
 
45
  g_return_val_if_fail (GB_IS_WORKSPACE (self), NULL);
 
46
 
 
47
  return priv->icon_name;
 
48
}
 
49
 
 
50
void
 
51
gb_workspace_set_icon_name (GbWorkspace *self,
 
52
                            const gchar *icon_name)
 
53
{
 
54
  GbWorkspacePrivate *priv = gb_workspace_get_instance_private (self);
 
55
 
 
56
  g_return_if_fail (GB_IS_WORKSPACE (self));
 
57
 
 
58
  if (priv->icon_name != icon_name)
 
59
    {
 
60
      g_free (priv->icon_name);
 
61
      priv->icon_name = g_strdup (icon_name);
 
62
      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs[PROP_ICON_NAME]);
 
63
    }
 
64
}
 
65
 
 
66
const gchar *
 
67
gb_workspace_get_title (GbWorkspace *self)
 
68
{
 
69
  GbWorkspacePrivate *priv = gb_workspace_get_instance_private (self);
 
70
 
 
71
  g_return_val_if_fail (GB_IS_WORKSPACE (self), NULL);
 
72
 
 
73
  return priv->title;
 
74
}
 
75
 
 
76
void
 
77
gb_workspace_set_title (GbWorkspace *self,
 
78
                        const gchar *title)
 
79
{
 
80
  GbWorkspacePrivate *priv = gb_workspace_get_instance_private (self);
 
81
 
 
82
  g_return_if_fail (GB_IS_WORKSPACE (self));
 
83
 
 
84
  if (priv->title != title)
 
85
    {
 
86
      g_free (priv->title);
 
87
      priv->title = g_strdup (title);
 
88
      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_TITLE]);
 
89
    }
 
90
}
 
91
 
 
92
static void
 
93
gb_workspace_finalize (GObject *object)
 
94
{
 
95
  GbWorkspace *self = (GbWorkspace *)object;
 
96
  GbWorkspacePrivate *priv = gb_workspace_get_instance_private (self);
 
97
 
 
98
  g_clear_pointer (&priv->icon_name, g_free);
 
99
  g_clear_pointer (&priv->title, g_free);
 
100
 
 
101
  G_OBJECT_CLASS (gb_workspace_parent_class)->finalize (object);
 
102
}
 
103
 
 
104
static void
 
105
gb_workspace_get_property (GObject    *object,
 
106
                           guint       prop_id,
 
107
                           GValue     *value,
 
108
                           GParamSpec *pspec)
 
109
{
 
110
  GbWorkspace *self = GB_WORKSPACE (object);
 
111
 
 
112
  switch (prop_id)
 
113
    {
 
114
    case PROP_ICON_NAME:
 
115
      g_value_set_string (value, gb_workspace_get_icon_name (self));
 
116
      break;
 
117
 
 
118
    case PROP_TITLE:
 
119
      g_value_set_string (value, gb_workspace_get_title (self));
 
120
      break;
 
121
 
 
122
    default:
 
123
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
124
    }
 
125
}
 
126
 
 
127
static void
 
128
gb_workspace_set_property (GObject      *object,
 
129
                           guint         prop_id,
 
130
                           const GValue *value,
 
131
                           GParamSpec   *pspec)
 
132
{
 
133
  GbWorkspace *self = GB_WORKSPACE (object);
 
134
 
 
135
  switch (prop_id)
 
136
    {
 
137
    case PROP_ICON_NAME:
 
138
      gb_workspace_set_icon_name (self, g_value_get_string (value));
 
139
      break;
 
140
 
 
141
    case PROP_TITLE:
 
142
      gb_workspace_set_title (self, g_value_get_string (value));
 
143
      break;
 
144
 
 
145
    default:
 
146
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
147
    }
 
148
}
 
149
 
 
150
static void
 
151
gb_workspace_class_init (GbWorkspaceClass *klass)
 
152
{
 
153
  GObjectClass *object_class;
 
154
 
 
155
  object_class = G_OBJECT_CLASS (klass);
 
156
  object_class->finalize = gb_workspace_finalize;
 
157
  object_class->get_property = gb_workspace_get_property;
 
158
  object_class->set_property = gb_workspace_set_property;
 
159
 
 
160
  gParamSpecs[PROP_TITLE] =
 
161
    g_param_spec_string ("title",
 
162
                         _("Title"),
 
163
                         _("The title of the workspace."),
 
164
                         NULL,
 
165
                         (G_PARAM_READWRITE |
 
166
                          G_PARAM_STATIC_STRINGS));
 
167
 
 
168
  gParamSpecs[PROP_ICON_NAME] =
 
169
    g_param_spec_string ("icon-name",
 
170
                         _("Icon Name"),
 
171
                         _("The name of the icon to use."),
 
172
                         NULL,
 
173
                         (G_PARAM_READWRITE |
 
174
                          G_PARAM_STATIC_STRINGS));
 
175
 
 
176
  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
 
177
}
 
178
 
 
179
static void
 
180
gb_workspace_init (GbWorkspace *workspace)
 
181
{
 
182
}
 
183
 
 
184
void
 
185
gb_workspace_views_foreach (GbWorkspace *self,
 
186
                            GtkCallback  callback,
 
187
                            gpointer     callback_data)
 
188
{
 
189
  g_return_if_fail (GB_IS_WORKSPACE (self));
 
190
  g_return_if_fail (callback != NULL);
 
191
 
 
192
  if (GB_WORKSPACE_GET_CLASS (self)->views_foreach)
 
193
    GB_WORKSPACE_GET_CLASS (self)->views_foreach (self, callback, callback_data);
 
194
}