~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpcontrollerlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimpcontrollerlist.c
 
5
 * Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <string.h>
 
25
 
 
26
#include <gtk/gtk.h>
 
27
 
 
28
#include "libgimpwidgets/gimpwidgets.h"
 
29
 
 
30
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
 
31
#include "libgimpwidgets/gimpcontroller.h"
 
32
 
 
33
#include "widgets-types.h"
 
34
 
 
35
#include "core/gimp.h"
 
36
#include "core/gimpcontainer.h"
 
37
 
 
38
#include "gimpcontainertreeview.h"
 
39
#include "gimpcontainerview.h"
 
40
#include "gimpcontrollereditor.h"
 
41
#include "gimpcontrollerlist.h"
 
42
#include "gimpcontrollerinfo.h"
 
43
#include "gimpcontrollerkeyboard.h"
 
44
#include "gimpcontrollerwheel.h"
 
45
#include "gimpcontrollers.h"
 
46
#include "gimpdialogfactory.h"
 
47
#include "gimphelp-ids.h"
 
48
#include "gimpmessagebox.h"
 
49
#include "gimpmessagedialog.h"
 
50
#include "gimppropwidgets.h"
 
51
#include "gimpuimanager.h"
 
52
#include "gimpwidgets-utils.h"
 
53
 
 
54
#include "gimp-intl.h"
 
55
 
 
56
 
 
57
enum
 
58
{
 
59
  PROP_0,
 
60
  PROP_GIMP
 
61
};
 
62
 
 
63
enum
 
64
{
 
65
  COLUMN_ICON,
 
66
  COLUMN_NAME,
 
67
  COLUMN_TYPE,
 
68
  NUM_COLUMNS
 
69
};
 
70
 
 
71
 
 
72
static GObject * gimp_controller_list_constructor (GType               type,
 
73
                                                   guint               n_params,
 
74
                                                   GObjectConstructParam *params);
 
75
static void gimp_controller_list_set_property    (GObject            *object,
 
76
                                                  guint               property_id,
 
77
                                                  const GValue       *value,
 
78
                                                  GParamSpec         *pspec);
 
79
static void gimp_controller_list_get_property    (GObject            *object,
 
80
                                                  guint               property_id,
 
81
                                                  GValue             *value,
 
82
                                                  GParamSpec         *pspec);
 
83
 
 
84
static void gimp_controller_list_finalize        (GObject            *object);
 
85
 
 
86
static void gimp_controller_list_src_sel_changed (GtkTreeSelection   *sel,
 
87
                                                  GimpControllerList *list);
 
88
static void gimp_controller_list_row_activated   (GtkTreeView        *tv,
 
89
                                                  GtkTreePath        *path,
 
90
                                                  GtkTreeViewColumn  *column,
 
91
                                                  GimpControllerList *list);
 
92
 
 
93
static void gimp_controller_list_select_item     (GimpContainerView  *view,
 
94
                                                  GimpViewable       *viewable,
 
95
                                                  gpointer            insert_data,
 
96
                                                  GimpControllerList *list);
 
97
static void gimp_controller_list_activate_item   (GimpContainerView  *view,
 
98
                                                  GimpViewable       *viewable,
 
99
                                                  gpointer            insert_data,
 
100
                                                  GimpControllerList *list);
 
101
 
 
102
static void gimp_controller_list_add_clicked     (GtkWidget          *button,
 
103
                                                  GimpControllerList *list);
 
104
static void gimp_controller_list_remove_clicked  (GtkWidget          *button,
 
105
                                                  GimpControllerList *list);
 
106
 
 
107
static void gimp_controller_list_edit_clicked    (GtkWidget          *button,
 
108
                                                  GimpControllerList *list);
 
109
static void gimp_controller_list_edit_destroy    (GtkWidget          *widget,
 
110
                                                  GimpControllerInfo *info);
 
111
static void gimp_controller_list_up_clicked      (GtkWidget          *button,
 
112
                                                  GimpControllerList *list);
 
113
static void gimp_controller_list_down_clicked    (GtkWidget          *button,
 
114
                                                  GimpControllerList *list);
 
115
 
 
116
 
 
117
G_DEFINE_TYPE (GimpControllerList, gimp_controller_list, GTK_TYPE_VBOX)
 
118
 
 
119
#define parent_class gimp_controller_list_parent_class
 
120
 
 
121
 
 
122
static void
 
123
gimp_controller_list_class_init (GimpControllerListClass *klass)
 
124
{
 
125
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
126
 
 
127
  object_class->constructor  = gimp_controller_list_constructor;
 
128
  object_class->set_property = gimp_controller_list_set_property;
 
129
  object_class->get_property = gimp_controller_list_get_property;
 
130
  object_class->finalize     = gimp_controller_list_finalize;
 
131
 
 
132
  g_object_class_install_property (object_class, PROP_GIMP,
 
133
                                   g_param_spec_object ("gimp",
 
134
                                                        NULL, NULL,
 
135
                                                        GIMP_TYPE_GIMP,
 
136
                                                        GIMP_PARAM_READWRITE |
 
137
                                                        G_PARAM_CONSTRUCT_ONLY));
 
138
}
 
139
 
 
140
static void
 
141
gimp_controller_list_init (GimpControllerList *list)
 
142
{
 
143
  GtkWidget         *hbox;
 
144
  GtkWidget         *sw;
 
145
  GtkWidget         *tv;
 
146
  GtkTreeViewColumn *column;
 
147
  GtkCellRenderer   *cell;
 
148
  GtkWidget         *vbox;
 
149
  GtkWidget         *image;
 
150
  GtkIconSize        icon_size;
 
151
  gint               icon_width;
 
152
  gint               icon_height;
 
153
  GType             *controller_types;
 
154
  guint              n_controller_types;
 
155
  gint               i;
 
156
 
 
157
  list->gimp = NULL;
 
158
 
 
159
  list->hbox = hbox = gtk_hbox_new (FALSE, 6);
 
160
  gtk_box_pack_start (GTK_BOX (list), hbox, TRUE, TRUE, 0);
 
161
  gtk_widget_show (hbox);
 
162
 
 
163
  sw = gtk_scrolled_window_new (NULL, NULL);
 
164
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
 
165
                                       GTK_SHADOW_IN);
 
166
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
 
167
                                  GTK_POLICY_AUTOMATIC,
 
168
                                  GTK_POLICY_AUTOMATIC);
 
169
  gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
 
170
  gtk_widget_show (sw);
 
171
 
 
172
  list->src = gtk_list_store_new (NUM_COLUMNS,
 
173
                                  G_TYPE_STRING,
 
174
                                  G_TYPE_STRING,
 
175
                                  G_TYPE_GTYPE);
 
176
  tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list->src));
 
177
  g_object_unref (list->src);
 
178
 
 
179
  gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (tv), FALSE);
 
180
 
 
181
  column = gtk_tree_view_column_new ();
 
182
  gtk_tree_view_column_set_title (column, _("Available Controllers"));
 
183
  gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);
 
184
 
 
185
  cell = gtk_cell_renderer_pixbuf_new ();
 
186
  gtk_tree_view_column_pack_start (column, cell, FALSE);
 
187
  gtk_tree_view_column_set_attributes (column, cell,
 
188
                                       "stock-id", COLUMN_ICON,
 
189
                                       NULL);
 
190
 
 
191
  g_object_get (cell, "stock-size", &icon_size, NULL);
 
192
 
 
193
  cell = gtk_cell_renderer_text_new ();
 
194
  gtk_tree_view_column_pack_start (column, cell, TRUE);
 
195
  gtk_tree_view_column_set_attributes (column, cell,
 
196
                                       "text", COLUMN_NAME,
 
197
                                       NULL);
 
198
 
 
199
  gtk_container_add (GTK_CONTAINER (sw), tv);
 
200
  gtk_widget_show (tv);
 
201
 
 
202
  g_signal_connect_object (tv, "row-activated",
 
203
                           G_CALLBACK (gimp_controller_list_row_activated),
 
204
                           G_OBJECT (list), 0);
 
205
 
 
206
  list->src_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
 
207
  gtk_tree_selection_set_mode (list->src_sel, GTK_SELECTION_BROWSE);
 
208
 
 
209
  g_signal_connect_object (list->src_sel, "changed",
 
210
                           G_CALLBACK (gimp_controller_list_src_sel_changed),
 
211
                           G_OBJECT (list), 0);
 
212
 
 
213
  controller_types = g_type_children (GIMP_TYPE_CONTROLLER,
 
214
                                      &n_controller_types);
 
215
 
 
216
  for (i = 0; i < n_controller_types; i++)
 
217
    {
 
218
      GimpControllerClass *controller_class;
 
219
      GtkTreeIter          iter;
 
220
 
 
221
      controller_class = g_type_class_ref (controller_types[i]);
 
222
 
 
223
      gtk_list_store_append (list->src, &iter);
 
224
      gtk_list_store_set (list->src, &iter,
 
225
                          COLUMN_ICON, controller_class->stock_id,
 
226
                          COLUMN_NAME, controller_class->name,
 
227
                          COLUMN_TYPE, controller_types[i],
 
228
                          -1);
 
229
 
 
230
      g_type_class_unref (controller_class);
 
231
    }
 
232
 
 
233
  vbox = gtk_vbox_new (TRUE, 0);
 
234
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
 
235
  gtk_widget_show (vbox);
 
236
 
 
237
  list->add_button = gtk_button_new ();
 
238
  gtk_box_pack_start (GTK_BOX (vbox), list->add_button, TRUE, FALSE, 0);
 
239
  gtk_widget_set_sensitive (list->add_button, FALSE);
 
240
  gtk_widget_show (list->add_button);
 
241
 
 
242
  image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON);
 
243
  gtk_container_add (GTK_CONTAINER (list->add_button), image);
 
244
  gtk_widget_show (image);
 
245
 
 
246
  g_signal_connect (list->add_button, "clicked",
 
247
                    G_CALLBACK (gimp_controller_list_add_clicked),
 
248
                    list);
 
249
 
 
250
  g_object_add_weak_pointer (G_OBJECT (list->add_button),
 
251
                             (gpointer) &list->add_button);
 
252
 
 
253
  list->remove_button = gtk_button_new ();
 
254
  gtk_box_pack_start (GTK_BOX (vbox), list->remove_button, TRUE, FALSE, 0);
 
255
  gtk_widget_set_sensitive (list->remove_button, FALSE);
 
256
  gtk_widget_show (list->remove_button);
 
257
 
 
258
  image = gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON);
 
259
  gtk_container_add (GTK_CONTAINER (list->remove_button), image);
 
260
  gtk_widget_show (image);
 
261
 
 
262
  g_signal_connect (list->remove_button, "clicked",
 
263
                    G_CALLBACK (gimp_controller_list_remove_clicked),
 
264
                    list);
 
265
 
 
266
  g_object_add_weak_pointer (G_OBJECT (list->remove_button),
 
267
                             (gpointer) &list->remove_button);
 
268
 
 
269
  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (list)),
 
270
                                     icon_size, &icon_width, &icon_height);
 
271
 
 
272
  list->dest = gimp_container_tree_view_new (NULL, NULL, icon_height, 0);
 
273
  gtk_tree_view_column_set_title (GIMP_CONTAINER_TREE_VIEW (list->dest)->main_column,
 
274
                                  _("Active Controllers"));
 
275
  gtk_tree_view_set_headers_visible (GIMP_CONTAINER_TREE_VIEW (list->dest)->view,
 
276
                                     TRUE);
 
277
  gtk_box_pack_start (GTK_BOX (list->hbox), list->dest, TRUE, TRUE, 0);
 
278
  gtk_widget_show (list->dest);
 
279
 
 
280
  g_signal_connect_object (list->dest, "select-item",
 
281
                           G_CALLBACK (gimp_controller_list_select_item),
 
282
                           G_OBJECT (list), 0);
 
283
  g_signal_connect_object (list->dest, "activate-item",
 
284
                           G_CALLBACK (gimp_controller_list_activate_item),
 
285
                           G_OBJECT (list), 0);
 
286
 
 
287
  list->edit_button =
 
288
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
 
289
                            GTK_STOCK_EDIT,
 
290
                            _("Configure the selected controller"),
 
291
                            NULL,
 
292
                            G_CALLBACK (gimp_controller_list_edit_clicked),
 
293
                            NULL,
 
294
                            list);
 
295
  list->up_button =
 
296
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
 
297
                            GTK_STOCK_GO_UP,
 
298
                            _("Move the selected controller up"),
 
299
                            NULL,
 
300
                            G_CALLBACK (gimp_controller_list_up_clicked),
 
301
                            NULL,
 
302
                            list);
 
303
  list->down_button =
 
304
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
 
305
                            GTK_STOCK_GO_DOWN,
 
306
                            _("Move the selected controller down"),
 
307
                            NULL,
 
308
                            G_CALLBACK (gimp_controller_list_down_clicked),
 
309
                            NULL,
 
310
                            list);
 
311
 
 
312
  gtk_widget_set_sensitive (list->edit_button, FALSE);
 
313
  gtk_widget_set_sensitive (list->up_button,   FALSE);
 
314
  gtk_widget_set_sensitive (list->down_button, FALSE);
 
315
}
 
316
 
 
317
static GObject *
 
318
gimp_controller_list_constructor (GType                  type,
 
319
                                  guint                  n_params,
 
320
                                  GObjectConstructParam *params)
 
321
{
 
322
  GObject            *object;
 
323
  GimpControllerList *list;
 
324
 
 
325
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
326
 
 
327
  list = GIMP_CONTROLLER_LIST (object);
 
328
 
 
329
  g_assert (GIMP_IS_GIMP (list->gimp));
 
330
 
 
331
  gimp_container_view_set_container (GIMP_CONTAINER_VIEW (list->dest),
 
332
                                     gimp_controllers_get_list (list->gimp));
 
333
 
 
334
  gimp_container_view_set_context (GIMP_CONTAINER_VIEW (list->dest),
 
335
                                   gimp_get_user_context (list->gimp));
 
336
 
 
337
  return object;
 
338
}
 
339
 
 
340
static void
 
341
gimp_controller_list_set_property (GObject      *object,
 
342
                                   guint         property_id,
 
343
                                   const GValue *value,
 
344
                                   GParamSpec   *pspec)
 
345
{
 
346
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
 
347
 
 
348
  switch (property_id)
 
349
    {
 
350
    case PROP_GIMP:
 
351
      list->gimp = GIMP (g_value_dup_object (value));
 
352
      break;
 
353
    default:
 
354
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
355
      break;
 
356
    }
 
357
}
 
358
 
 
359
static void
 
360
gimp_controller_list_get_property (GObject    *object,
 
361
                                   guint       property_id,
 
362
                                   GValue     *value,
 
363
                                   GParamSpec *pspec)
 
364
{
 
365
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
 
366
 
 
367
  switch (property_id)
 
368
    {
 
369
    case PROP_GIMP:
 
370
      g_value_set_object (value, list->gimp);
 
371
      break;
 
372
    default:
 
373
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
374
      break;
 
375
    }
 
376
}
 
377
 
 
378
static void
 
379
gimp_controller_list_finalize (GObject *object)
 
380
{
 
381
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
 
382
 
 
383
  if (list->gimp)
 
384
    {
 
385
      g_object_unref (list->gimp);
 
386
      list->gimp = NULL;
 
387
    }
 
388
 
 
389
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
390
}
 
391
 
 
392
 
 
393
/*  public functions  */
 
394
 
 
395
GtkWidget *
 
396
gimp_controller_list_new (Gimp *gimp)
 
397
{
 
398
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
399
 
 
400
  return g_object_new (GIMP_TYPE_CONTROLLER_LIST,
 
401
                       "gimp", gimp,
 
402
                       NULL);
 
403
}
 
404
 
 
405
 
 
406
/*  private functions  */
 
407
 
 
408
static void
 
409
gimp_controller_list_src_sel_changed (GtkTreeSelection   *sel,
 
410
                                      GimpControllerList *list)
 
411
{
 
412
  GtkTreeModel *model;
 
413
  GtkTreeIter   iter;
 
414
  gchar        *tip = NULL;
 
415
 
 
416
  if (gtk_tree_selection_get_selected (sel, &model, &iter))
 
417
    {
 
418
      gchar *name;
 
419
 
 
420
      gtk_tree_model_get (model, &iter,
 
421
                          COLUMN_NAME, &name,
 
422
                          COLUMN_TYPE, &list->src_gtype,
 
423
                          -1);
 
424
 
 
425
      if (list->add_button)
 
426
        {
 
427
          tip =
 
428
            g_strdup_printf (_("Add '%s' to the list of active controllers"),
 
429
                             name);
 
430
          gtk_widget_set_sensitive (list->add_button, TRUE);
 
431
        }
 
432
 
 
433
      g_free (name);
 
434
    }
 
435
  else
 
436
    {
 
437
      if (list->add_button)
 
438
        gtk_widget_set_sensitive (list->add_button, FALSE);
 
439
    }
 
440
 
 
441
  if (list->add_button)
 
442
    {
 
443
      gimp_help_set_help_data (list->add_button, tip, NULL);
 
444
      g_free (tip);
 
445
    }
 
446
}
 
447
 
 
448
static void
 
449
gimp_controller_list_row_activated (GtkTreeView        *tv,
 
450
                                    GtkTreePath        *path,
 
451
                                    GtkTreeViewColumn  *column,
 
452
                                    GimpControllerList *list)
 
453
{
 
454
  if (GTK_WIDGET_IS_SENSITIVE (list->add_button))
 
455
    gtk_button_clicked (GTK_BUTTON (list->add_button));
 
456
}
 
457
 
 
458
static void
 
459
gimp_controller_list_select_item (GimpContainerView  *view,
 
460
                                  GimpViewable       *viewable,
 
461
                                  gpointer            insert_data,
 
462
                                  GimpControllerList *list)
 
463
{
 
464
  gboolean selected;
 
465
 
 
466
  list->dest_info = GIMP_CONTROLLER_INFO (viewable);
 
467
 
 
468
  selected = GIMP_IS_CONTROLLER_INFO (list->dest_info);
 
469
 
 
470
  if (list->remove_button)
 
471
    {
 
472
      GimpObject *object = GIMP_OBJECT (list->dest_info);
 
473
      gchar      *tip    = NULL;
 
474
 
 
475
      gtk_widget_set_sensitive (list->remove_button, selected);
 
476
 
 
477
      if (selected)
 
478
        tip =
 
479
          g_strdup_printf (_("Remove '%s' from the list of active controllers"),
 
480
                           gimp_object_get_name (object));
 
481
 
 
482
      gimp_help_set_help_data (list->remove_button, tip, NULL);
 
483
      g_free (tip);
 
484
    }
 
485
 
 
486
  gtk_widget_set_sensitive (list->edit_button, selected);
 
487
  gtk_widget_set_sensitive (list->up_button,   selected);
 
488
  gtk_widget_set_sensitive (list->down_button, selected);
 
489
}
 
490
 
 
491
static void
 
492
gimp_controller_list_activate_item (GimpContainerView  *view,
 
493
                                    GimpViewable       *viewable,
 
494
                                    gpointer            insert_data,
 
495
                                    GimpControllerList *list)
 
496
{
 
497
  if (GTK_WIDGET_IS_SENSITIVE (list->edit_button))
 
498
    gtk_button_clicked (GTK_BUTTON (list->edit_button));
 
499
}
 
500
 
 
501
static void
 
502
gimp_controller_list_add_clicked (GtkWidget          *button,
 
503
                                  GimpControllerList *list)
 
504
{
 
505
  GimpControllerInfo *info;
 
506
  GimpContainer      *container;
 
507
 
 
508
  if (list->src_gtype == GIMP_TYPE_CONTROLLER_KEYBOARD &&
 
509
      gimp_controllers_get_keyboard (list->gimp) != NULL)
 
510
    {
 
511
      gimp_message (list->gimp, G_OBJECT (button), GIMP_MESSAGE_WARNING,
 
512
                    _("There can only be one active keyboard "
 
513
                      "controller.\n\n"
 
514
                      "You already have a keyboard controller in "
 
515
                      "your list of active controllers."));
 
516
      return;
 
517
    }
 
518
  else if (list->src_gtype == GIMP_TYPE_CONTROLLER_WHEEL &&
 
519
           gimp_controllers_get_wheel (list->gimp) != NULL)
 
520
    {
 
521
      gimp_message (list->gimp, G_OBJECT (button), GIMP_MESSAGE_WARNING,
 
522
                    _("There can only be one active wheel "
 
523
                      "controller.\n\n"
 
524
                      "You already have a wheel controller in "
 
525
                      "your list of active controllers."));
 
526
      return;
 
527
    }
 
528
 
 
529
  info = gimp_controller_info_new (list->src_gtype);
 
530
  container = gimp_controllers_get_list (list->gimp);
 
531
  gimp_container_add (container, GIMP_OBJECT (info));
 
532
  g_object_unref (info);
 
533
 
 
534
  gimp_container_view_select_item (GIMP_CONTAINER_VIEW (list->dest),
 
535
                                   GIMP_VIEWABLE (info));
 
536
  gimp_controller_list_edit_clicked (NULL, list);
 
537
}
 
538
 
 
539
static void
 
540
gimp_controller_list_remove_clicked (GtkWidget          *button,
 
541
                                     GimpControllerList *list)
 
542
{
 
543
  GtkWidget *dialog;
 
544
  gchar     *primary;
 
545
  gchar     *secondary;
 
546
 
 
547
#define RESPONSE_DISABLE 1
 
548
 
 
549
  dialog = gimp_message_dialog_new (_("Remove Controller?"),
 
550
                                    GIMP_STOCK_WARNING,
 
551
                                    GTK_WIDGET (list), GTK_DIALOG_MODAL,
 
552
                                    NULL, NULL,
 
553
 
 
554
                                    _("Disable Controller"), RESPONSE_DISABLE,
 
555
                                    GTK_STOCK_CANCEL,        GTK_RESPONSE_CANCEL,
 
556
                                    _("Remove Controller"),  GTK_RESPONSE_OK,
 
557
 
 
558
                                    NULL);
 
559
 
 
560
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
 
561
                                           GTK_RESPONSE_OK,
 
562
                                           GTK_RESPONSE_CANCEL,
 
563
                                           RESPONSE_DISABLE,
 
564
                                           -1);
 
565
 
 
566
  primary =
 
567
    g_strdup_printf (_("Remove Controller '%s'?"),
 
568
                     gimp_object_get_name (GIMP_OBJECT (list->dest_info)));
 
569
 
 
570
  secondary =
 
571
    g_strdup_printf (_("Removing this controller from the list of "
 
572
                       "active controllers will permanently delete "
 
573
                       "all event mappings you have configured.\n\n"
 
574
                       "Selecting \"Disable Controller\" will disable "
 
575
                       "the controller without removing it."));
 
576
 
 
577
  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
 
578
                                     primary);
 
579
  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
 
580
                             secondary);
 
581
 
 
582
  g_free (primary);
 
583
  g_free (secondary);
 
584
 
 
585
  switch (gimp_dialog_run (GIMP_DIALOG (dialog)))
 
586
    {
 
587
    case RESPONSE_DISABLE:
 
588
      gimp_controller_info_set_enabled (list->dest_info, FALSE);
 
589
      break;
 
590
 
 
591
    case GTK_RESPONSE_OK:
 
592
      {
 
593
        GtkWidget     *editor_dialog;
 
594
        GimpContainer *container;
 
595
 
 
596
        editor_dialog = g_object_get_data (G_OBJECT (list->dest_info),
 
597
                                           "gimp-controller-editor-dialog");
 
598
 
 
599
        if (editor_dialog)
 
600
          gtk_dialog_response (GTK_DIALOG (editor_dialog),
 
601
                               GTK_RESPONSE_DELETE_EVENT);
 
602
 
 
603
        container = gimp_controllers_get_list (list->gimp);
 
604
        gimp_container_remove (container, GIMP_OBJECT (list->dest_info));
 
605
      }
 
606
      break;
 
607
 
 
608
    default:
 
609
      break;
 
610
    }
 
611
 
 
612
  gtk_widget_destroy (dialog);
 
613
}
 
614
 
 
615
static void
 
616
gimp_controller_list_edit_clicked (GtkWidget          *button,
 
617
                                   GimpControllerList *list)
 
618
{
 
619
  GtkWidget *dialog;
 
620
  GtkWidget *editor;
 
621
 
 
622
  dialog = g_object_get_data (G_OBJECT (list->dest_info),
 
623
                              "gimp-controller-editor-dialog");
 
624
 
 
625
  if (dialog)
 
626
    {
 
627
      gtk_window_present (GTK_WINDOW (dialog));
 
628
      return;
 
629
    }
 
630
 
 
631
  dialog = gimp_dialog_new (_("Configure Input Controller"),
 
632
                            "gimp-controller-editor-dialog",
 
633
                            gtk_widget_get_toplevel (GTK_WIDGET (list)),
 
634
                            GTK_DIALOG_DESTROY_WITH_PARENT,
 
635
                            gimp_standard_help_func,
 
636
                            GIMP_HELP_PREFS_INPUT_CONTROLLERS,
 
637
 
 
638
                            GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
 
639
 
 
640
                            NULL);
 
641
 
 
642
  gimp_dialog_factory_add_foreign (gimp_dialog_factory_from_name ("toplevel"),
 
643
                                   "gimp-controller-editor-dialog",
 
644
                                   dialog);
 
645
 
 
646
  g_signal_connect (dialog, "response",
 
647
                    G_CALLBACK (gtk_widget_destroy),
 
648
                    NULL);
 
649
 
 
650
  editor = gimp_controller_editor_new (list->dest_info,
 
651
                                       gimp_get_user_context (list->gimp));
 
652
  gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
 
653
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), editor);
 
654
  gtk_widget_show (editor);
 
655
 
 
656
  g_object_set_data (G_OBJECT (list->dest_info), "gimp-controller-editor-dialog",
 
657
                     dialog);
 
658
 
 
659
  g_signal_connect_object (dialog, "destroy",
 
660
                           G_CALLBACK (gimp_controller_list_edit_destroy),
 
661
                           G_OBJECT (list->dest_info), 0);
 
662
 
 
663
  g_signal_connect_object (list, "destroy",
 
664
                           G_CALLBACK (gtk_widget_destroy),
 
665
                           G_OBJECT (dialog),
 
666
                           G_CONNECT_SWAPPED);
 
667
  g_signal_connect_object (list, "unmap",
 
668
                           G_CALLBACK (gtk_widget_destroy),
 
669
                           G_OBJECT (dialog),
 
670
                           G_CONNECT_SWAPPED);
 
671
 
 
672
  gtk_widget_show (dialog);
 
673
}
 
674
 
 
675
static void
 
676
gimp_controller_list_edit_destroy (GtkWidget          *widget,
 
677
                                   GimpControllerInfo *info)
 
678
{
 
679
  g_object_set_data (G_OBJECT (info), "gimp-controller-editor-dialog", NULL);
 
680
}
 
681
 
 
682
static void
 
683
gimp_controller_list_up_clicked (GtkWidget          *button,
 
684
                                 GimpControllerList *list)
 
685
{
 
686
  GimpContainer *container;
 
687
  gint           index;
 
688
 
 
689
  container = gimp_controllers_get_list (list->gimp);
 
690
 
 
691
  index = gimp_container_get_child_index (container,
 
692
                                          GIMP_OBJECT (list->dest_info));
 
693
 
 
694
  if (index > 0)
 
695
    gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),
 
696
                            index - 1);
 
697
}
 
698
 
 
699
static void
 
700
gimp_controller_list_down_clicked (GtkWidget          *button,
 
701
                                   GimpControllerList *list)
 
702
{
 
703
  GimpContainer *container;
 
704
  gint           index;
 
705
 
 
706
  container = gimp_controllers_get_list (list->gimp);
 
707
 
 
708
  index = gimp_container_get_child_index (container,
 
709
                                          GIMP_OBJECT (list->dest_info));
 
710
 
 
711
  if (index < gimp_container_num_children (container) - 1)
 
712
    gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),
 
713
                            index + 1);
 
714
}