gimpcontrollerlist.c 25.4 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3 4 5 6
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
 *
 * gimpcontrollerlist.c
 * Copyright (C) 2005 Michael Natterer <mitch@gimp.org>
 *
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 3 of the License, or
10 11 12 13 14 15 16 17
 * (at your option) any later version.
 *
 * This program 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
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 20 21 22 23 24
 */

#include "config.h"

#include <string.h>

25
#include <gegl.h>
26 27 28 29 30 31 32 33 34 35 36 37 38
#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
#include "libgimpwidgets/gimpcontroller.h"

#include "widgets-types.h"

#include "core/gimp.h"
#include "core/gimpcontainer.h"

#include "gimpcontainertreeview.h"
39
#include "gimpcontainerview.h"
40 41 42 43
#include "gimpcontrollereditor.h"
#include "gimpcontrollerlist.h"
#include "gimpcontrollerinfo.h"
#include "gimpcontrollerkeyboard.h"
44
#include "gimpcontrollermouse.h"
45 46 47 48
#include "gimpcontrollerwheel.h"
#include "gimpcontrollers.h"
#include "gimpdialogfactory.h"
#include "gimphelp-ids.h"
49 50
#include "gimpmessagebox.h"
#include "gimpmessagedialog.h"
51 52
#include "gimppropwidgets.h"
#include "gimpuimanager.h"
Hans Breuer's avatar
updated  
Hans Breuer committed
53
#include "gimpwidgets-utils.h"
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

#include "gimp-intl.h"


enum
{
  PROP_0,
  PROP_GIMP
};

enum
{
  COLUMN_ICON,
  COLUMN_NAME,
  COLUMN_TYPE,
69
  N_COLUMNS
70 71 72
};


73 74
static void gimp_controller_list_constructed     (GObject            *object);
static void gimp_controller_list_finalize        (GObject            *object);
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
static void gimp_controller_list_set_property    (GObject            *object,
                                                  guint               property_id,
                                                  const GValue       *value,
                                                  GParamSpec         *pspec);
static void gimp_controller_list_get_property    (GObject            *object,
                                                  guint               property_id,
                                                  GValue             *value,
                                                  GParamSpec         *pspec);

static void gimp_controller_list_src_sel_changed (GtkTreeSelection   *sel,
                                                  GimpControllerList *list);
static void gimp_controller_list_row_activated   (GtkTreeView        *tv,
                                                  GtkTreePath        *path,
                                                  GtkTreeViewColumn  *column,
                                                  GimpControllerList *list);

static void gimp_controller_list_select_item     (GimpContainerView  *view,
                                                  GimpViewable       *viewable,
                                                  gpointer            insert_data,
                                                  GimpControllerList *list);
static void gimp_controller_list_activate_item   (GimpContainerView  *view,
                                                  GimpViewable       *viewable,
                                                  gpointer            insert_data,
                                                  GimpControllerList *list);

static void gimp_controller_list_add_clicked     (GtkWidget          *button,
                                                  GimpControllerList *list);
static void gimp_controller_list_remove_clicked  (GtkWidget          *button,
                                                  GimpControllerList *list);

static void gimp_controller_list_edit_clicked    (GtkWidget          *button,
                                                  GimpControllerList *list);
static void gimp_controller_list_edit_destroy    (GtkWidget          *widget,
                                                  GimpControllerInfo *info);
109 110 111 112
static void gimp_controller_list_up_clicked      (GtkWidget          *button,
                                                  GimpControllerList *list);
static void gimp_controller_list_down_clicked    (GtkWidget          *button,
                                                  GimpControllerList *list);
113 114


115
G_DEFINE_TYPE (GimpControllerList, gimp_controller_list, GTK_TYPE_BOX)
116

117
#define parent_class gimp_controller_list_parent_class
118 119 120 121 122 123 124


static void
gimp_controller_list_class_init (GimpControllerListClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

125 126
  object_class->constructed  = gimp_controller_list_constructed;
  object_class->finalize     = gimp_controller_list_finalize;
127 128 129 130 131 132 133
  object_class->set_property = gimp_controller_list_set_property;
  object_class->get_property = gimp_controller_list_get_property;

  g_object_class_install_property (object_class, PROP_GIMP,
                                   g_param_spec_object ("gimp",
                                                        NULL, NULL,
                                                        GIMP_TYPE_GIMP,
134
                                                        GIMP_PARAM_READWRITE |
135 136 137 138 139 140 141 142 143 144 145 146 147
                                                        G_PARAM_CONSTRUCT_ONLY));
}

static void
gimp_controller_list_init (GimpControllerList *list)
{
  GtkWidget         *hbox;
  GtkWidget         *sw;
  GtkWidget         *tv;
  GtkTreeViewColumn *column;
  GtkCellRenderer   *cell;
  GtkWidget         *vbox;
  GtkWidget         *image;
148 149 150
  GtkIconSize        icon_size;
  gint               icon_width;
  gint               icon_height;
151
  GType             *controller_types;
152
  guint              n_controller_types;
153 154
  gint               i;

155 156 157
  gtk_orientable_set_orientation (GTK_ORIENTABLE (list),
                                  GTK_ORIENTATION_VERTICAL);

158 159
  list->gimp = NULL;

Michael Natterer's avatar
Michael Natterer committed
160
  list->hbox = hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
161 162 163 164 165 166 167
  gtk_box_pack_start (GTK_BOX (list), hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                       GTK_SHADOW_IN);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
168 169
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
170 171 172
  gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
  gtk_widget_show (sw);

173
  list->src = gtk_list_store_new (N_COLUMNS,
174 175
                                  G_TYPE_STRING,
                                  G_TYPE_STRING,
176
                                  G_TYPE_GTYPE);
177 178 179 180 181 182 183 184 185 186 187 188
  tv = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list->src));
  g_object_unref (list->src);

  gtk_tree_view_set_headers_clickable (GTK_TREE_VIEW (tv), FALSE);

  column = gtk_tree_view_column_new ();
  gtk_tree_view_column_set_title (column, _("Available Controllers"));
  gtk_tree_view_append_column (GTK_TREE_VIEW (tv), column);

  cell = gtk_cell_renderer_pixbuf_new ();
  gtk_tree_view_column_pack_start (column, cell, FALSE);
  gtk_tree_view_column_set_attributes (column, cell,
189
                                       "icon-name", COLUMN_ICON,
190 191
                                       NULL);

192 193
  g_object_get (cell, "stock-size", &icon_size, NULL);

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
  cell = gtk_cell_renderer_text_new ();
  gtk_tree_view_column_pack_start (column, cell, TRUE);
  gtk_tree_view_column_set_attributes (column, cell,
                                       "text", COLUMN_NAME,
                                       NULL);

  gtk_container_add (GTK_CONTAINER (sw), tv);
  gtk_widget_show (tv);

  g_signal_connect_object (tv, "row-activated",
                           G_CALLBACK (gimp_controller_list_row_activated),
                           G_OBJECT (list), 0);

  list->src_sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tv));
  gtk_tree_selection_set_mode (list->src_sel, GTK_SELECTION_BROWSE);

  g_signal_connect_object (list->src_sel, "changed",
                           G_CALLBACK (gimp_controller_list_src_sel_changed),
                           G_OBJECT (list), 0);

  controller_types = g_type_children (GIMP_TYPE_CONTROLLER,
                                      &n_controller_types);

  for (i = 0; i < n_controller_types; i++)
    {
      GimpControllerClass *controller_class;
      GtkTreeIter          iter;

      controller_class = g_type_class_ref (controller_types[i]);

      gtk_list_store_append (list->src, &iter);
      gtk_list_store_set (list->src, &iter,
226
                          COLUMN_ICON, controller_class->icon_name,
227 228 229 230 231 232 233
                          COLUMN_NAME, controller_class->name,
                          COLUMN_TYPE, controller_types[i],
                          -1);

      g_type_class_unref (controller_class);
    }

234 235
  g_free (controller_types);

Michael Natterer's avatar
Michael Natterer committed
236 237
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_box_set_homogeneous (GTK_BOX (vbox), TRUE);
238 239 240 241 242 243 244 245
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  list->add_button = gtk_button_new ();
  gtk_box_pack_start (GTK_BOX (vbox), list->add_button, TRUE, FALSE, 0);
  gtk_widget_set_sensitive (list->add_button, FALSE);
  gtk_widget_show (list->add_button);

246
  image = gtk_image_new_from_icon_name (GIMP_ICON_GO_NEXT,
247
                                        GTK_ICON_SIZE_BUTTON);
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
  gtk_container_add (GTK_CONTAINER (list->add_button), image);
  gtk_widget_show (image);

  g_signal_connect (list->add_button, "clicked",
                    G_CALLBACK (gimp_controller_list_add_clicked),
                    list);

  g_object_add_weak_pointer (G_OBJECT (list->add_button),
                             (gpointer) &list->add_button);

  list->remove_button = gtk_button_new ();
  gtk_box_pack_start (GTK_BOX (vbox), list->remove_button, TRUE, FALSE, 0);
  gtk_widget_set_sensitive (list->remove_button, FALSE);
  gtk_widget_show (list->remove_button);

263
  image = gtk_image_new_from_icon_name (GIMP_ICON_GO_PREVIOUS,
264
                                        GTK_ICON_SIZE_BUTTON);
265 266 267 268 269 270 271 272 273 274
  gtk_container_add (GTK_CONTAINER (list->remove_button), image);
  gtk_widget_show (image);

  g_signal_connect (list->remove_button, "clicked",
                    G_CALLBACK (gimp_controller_list_remove_clicked),
                    list);

  g_object_add_weak_pointer (G_OBJECT (list->remove_button),
                             (gpointer) &list->remove_button);

275
  gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (GTK_WIDGET (list)),
276
                                     icon_size, &icon_width, &icon_height);
277

278
  list->dest = gimp_container_tree_view_new (NULL, NULL, icon_height, 0);
279 280
  gimp_container_tree_view_set_main_column_title (GIMP_CONTAINER_TREE_VIEW (list->dest),
                                                  _("Active Controllers"));
281 282 283 284 285 286 287 288 289 290 291 292 293 294
  gtk_tree_view_set_headers_visible (GIMP_CONTAINER_TREE_VIEW (list->dest)->view,
                                     TRUE);
  gtk_box_pack_start (GTK_BOX (list->hbox), list->dest, TRUE, TRUE, 0);
  gtk_widget_show (list->dest);

  g_signal_connect_object (list->dest, "select-item",
                           G_CALLBACK (gimp_controller_list_select_item),
                           G_OBJECT (list), 0);
  g_signal_connect_object (list->dest, "activate-item",
                           G_CALLBACK (gimp_controller_list_activate_item),
                           G_OBJECT (list), 0);

  list->edit_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
295
                            GIMP_ICON_DOCUMENT_PROPERTIES,
296 297 298 299 300
                            _("Configure the selected controller"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_edit_clicked),
                            NULL,
                            list);
301 302
  list->up_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
303
                            GIMP_ICON_GO_UP,
304 305 306 307 308 309 310
                            _("Move the selected controller up"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_up_clicked),
                            NULL,
                            list);
  list->down_button =
    gimp_editor_add_button (GIMP_EDITOR (list->dest),
311
                            GIMP_ICON_GO_DOWN,
312 313 314 315 316 317
                            _("Move the selected controller down"),
                            NULL,
                            G_CALLBACK (gimp_controller_list_down_clicked),
                            NULL,
                            list);

318
  gtk_widget_set_sensitive (list->edit_button, FALSE);
319 320 321 322
  gtk_widget_set_sensitive (list->up_button,   FALSE);
  gtk_widget_set_sensitive (list->down_button, FALSE);
}

323 324
static void
gimp_controller_list_constructed (GObject *object)
325
{
326
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);
327

328
  G_OBJECT_CLASS (parent_class)->constructed (object);
329

330
  gimp_assert (GIMP_IS_GIMP (list->gimp));
331 332 333

  gimp_container_view_set_container (GIMP_CONTAINER_VIEW (list->dest),
                                     gimp_controllers_get_list (list->gimp));
334

335 336
  gimp_container_view_set_context (GIMP_CONTAINER_VIEW (list->dest),
                                   gimp_get_user_context (list->gimp));
337
}
338

339 340 341 342 343
static void
gimp_controller_list_finalize (GObject *object)
{
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);

344
  g_clear_object (&list->gimp);
345 346

  G_OBJECT_CLASS (parent_class)->finalize (object);
347 348 349 350 351 352 353 354 355 356 357 358 359
}

static void
gimp_controller_list_set_property (GObject      *object,
                                   guint         property_id,
                                   const GValue *value,
                                   GParamSpec   *pspec)
{
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);

  switch (property_id)
    {
    case PROP_GIMP:
360
      list->gimp = g_value_dup_object (value);
361
      break;
362

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}

static void
gimp_controller_list_get_property (GObject    *object,
                                   guint       property_id,
                                   GValue     *value,
                                   GParamSpec *pspec)
{
  GimpControllerList *list = GIMP_CONTROLLER_LIST (object);

  switch (property_id)
    {
    case PROP_GIMP:
      g_value_set_object (value, list->gimp);
      break;
382

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
    }
}


/*  public functions  */

GtkWidget *
gimp_controller_list_new (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  return g_object_new (GIMP_TYPE_CONTROLLER_LIST,
                       "gimp", gimp,
                       NULL);
}


/*  private functions  */

static void
gimp_controller_list_src_sel_changed (GtkTreeSelection   *sel,
                                      GimpControllerList *list)
{
  GtkTreeModel *model;
  GtkTreeIter   iter;
411
  gchar        *tip = NULL;
412 413 414

  if (gtk_tree_selection_get_selected (sel, &model, &iter))
    {
415 416
      gchar *name;

417
      gtk_tree_model_get (model, &iter,
418
                          COLUMN_NAME, &name,
419 420 421 422
                          COLUMN_TYPE, &list->src_gtype,
                          -1);

      if (list->add_button)
423 424 425 426 427 428 429 430
        {
          tip =
            g_strdup_printf (_("Add '%s' to the list of active controllers"),
                             name);
          gtk_widget_set_sensitive (list->add_button, TRUE);
        }

      g_free (name);
431 432 433 434 435 436
    }
  else
    {
      if (list->add_button)
        gtk_widget_set_sensitive (list->add_button, FALSE);
    }
437 438 439 440 441 442

  if (list->add_button)
    {
      gimp_help_set_help_data (list->add_button, tip, NULL);
      g_free (tip);
    }
443 444 445 446 447 448 449 450
}

static void
gimp_controller_list_row_activated (GtkTreeView        *tv,
                                    GtkTreePath        *path,
                                    GtkTreeViewColumn  *column,
                                    GimpControllerList *list)
{
451
  if (gtk_widget_is_sensitive (list->add_button))
452 453 454 455 456 457 458 459 460
    gtk_button_clicked (GTK_BUTTON (list->add_button));
}

static void
gimp_controller_list_select_item (GimpContainerView  *view,
                                  GimpViewable       *viewable,
                                  gpointer            insert_data,
                                  GimpControllerList *list)
{
461 462
  gboolean selected;

463 464
  list->dest_info = GIMP_CONTROLLER_INFO (viewable);

465 466
  selected = GIMP_IS_CONTROLLER_INFO (list->dest_info);

467
  if (list->remove_button)
468 469 470 471 472 473 474 475 476 477 478 479 480 481
    {
      GimpObject *object = GIMP_OBJECT (list->dest_info);
      gchar      *tip    = NULL;

      gtk_widget_set_sensitive (list->remove_button, selected);

      if (selected)
        tip =
          g_strdup_printf (_("Remove '%s' from the list of active controllers"),
                           gimp_object_get_name (object));

      gimp_help_set_help_data (list->remove_button, tip, NULL);
      g_free (tip);
    }
482

483 484 485
  gtk_widget_set_sensitive (list->edit_button, selected);
  gtk_widget_set_sensitive (list->up_button,   selected);
  gtk_widget_set_sensitive (list->down_button, selected);
486 487 488 489 490 491 492 493
}

static void
gimp_controller_list_activate_item (GimpContainerView  *view,
                                    GimpViewable       *viewable,
                                    gpointer            insert_data,
                                    GimpControllerList *list)
{
494
  if (gtk_widget_is_sensitive (list->edit_button))
495 496 497 498 499 500 501 502 503 504 505 506 507
    gtk_button_clicked (GTK_BUTTON (list->edit_button));
}

static void
gimp_controller_list_add_clicked (GtkWidget          *button,
                                  GimpControllerList *list)
{
  GimpControllerInfo *info;
  GimpContainer      *container;

  if (list->src_gtype == GIMP_TYPE_CONTROLLER_KEYBOARD &&
      gimp_controllers_get_keyboard (list->gimp) != NULL)
    {
508
      gimp_message_literal (list->gimp,
509 510 511 512 513
                            G_OBJECT (button), GIMP_MESSAGE_WARNING,
                            _("There can only be one active keyboard "
                              "controller.\n\n"
                              "You already have a keyboard controller in "
                              "your list of active controllers."));
514 515 516 517 518
      return;
    }
  else if (list->src_gtype == GIMP_TYPE_CONTROLLER_WHEEL &&
           gimp_controllers_get_wheel (list->gimp) != NULL)
    {
519
      gimp_message_literal (list->gimp,
520 521 522 523 524
                            G_OBJECT (button), GIMP_MESSAGE_WARNING,
                            _("There can only be one active wheel "
                              "controller.\n\n"
                              "You already have a wheel controller in "
                              "your list of active controllers."));
525 526
      return;
    }
527 528 529 530
  else if (list->src_gtype == GIMP_TYPE_CONTROLLER_MOUSE &&
           gimp_controllers_get_mouse (list->gimp) != NULL)
    {
      gimp_message_literal (list->gimp,
531 532 533 534 535
                            G_OBJECT (button), GIMP_MESSAGE_WARNING,
                            _("There can only be one active mouse "
                              "controller.\n\n"
                              "You already have a mouse controller in "
                              "your list of active controllers."));
536 537
      return;
    }
538 539 540 541 542

  info = gimp_controller_info_new (list->src_gtype);
  container = gimp_controllers_get_list (list->gimp);
  gimp_container_add (container, GIMP_OBJECT (info));
  g_object_unref (info);
543 544 545 546

  gimp_container_view_select_item (GIMP_CONTAINER_VIEW (list->dest),
                                   GIMP_VIEWABLE (info));
  gimp_controller_list_edit_clicked (NULL, list);
547 548 549 550 551 552
}

static void
gimp_controller_list_remove_clicked (GtkWidget          *button,
                                     GimpControllerList *list)
{
553 554
  GtkWidget   *dialog;
  const gchar *name;
555 556 557 558

#define RESPONSE_DISABLE 1

  dialog = gimp_message_dialog_new (_("Remove Controller?"),
559
                                    GIMP_ICON_DIALOG_WARNING,
560 561 562
                                    GTK_WIDGET (list), GTK_DIALOG_MODAL,
                                    NULL, NULL,

563 564 565
                                    _("_Disable Controller"), RESPONSE_DISABLE,
                                    _("_Cancel"),             GTK_RESPONSE_CANCEL,
                                    _("_Remove Controller"),  GTK_RESPONSE_OK,
566 567 568 569 570 571 572 573 574

                                    NULL);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           RESPONSE_DISABLE,
                                           -1);

575
  name = gimp_object_get_name (list->dest_info);
576
  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box,
577
                                     _("Remove Controller '%s'?"), name);
578

579
  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box,
Jehan's avatar
Jehan committed
580
                             "%s",
581
                             _("Removing this controller from the list of "
Jehan's avatar
Jehan committed
582 583 584 585
                               "active controllers will permanently delete "
                               "all event mappings you have configured.\n\n"
                               "Selecting \"Disable Controller\" will disable "
                               "the controller without removing it."));
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614

  switch (gimp_dialog_run (GIMP_DIALOG (dialog)))
    {
    case RESPONSE_DISABLE:
      gimp_controller_info_set_enabled (list->dest_info, FALSE);
      break;

    case GTK_RESPONSE_OK:
      {
        GtkWidget     *editor_dialog;
        GimpContainer *container;

        editor_dialog = g_object_get_data (G_OBJECT (list->dest_info),
                                           "gimp-controller-editor-dialog");

        if (editor_dialog)
          gtk_dialog_response (GTK_DIALOG (editor_dialog),
                               GTK_RESPONSE_DELETE_EVENT);

        container = gimp_controllers_get_list (list->gimp);
        gimp_container_remove (container, GIMP_OBJECT (list->dest_info));
      }
      break;

    default:
      break;
    }

  gtk_widget_destroy (dialog);
615 616 617 618 619 620 621 622 623 624
}

static void
gimp_controller_list_edit_clicked (GtkWidget          *button,
                                   GimpControllerList *list)
{
  GtkWidget *dialog;
  GtkWidget *editor;

  dialog = g_object_get_data (G_OBJECT (list->dest_info),
625
                              "gimp-controller-editor-dialog");
626 627 628 629 630 631 632

  if (dialog)
    {
      gtk_window_present (GTK_WINDOW (dialog));
      return;
    }

633 634
  dialog = gimp_dialog_new (_("Configure Input Controller"),
                            "gimp-controller-editor-dialog",
635
                            gtk_widget_get_toplevel (GTK_WIDGET (list)),
636 637 638
                            GTK_DIALOG_DESTROY_WITH_PARENT,
                            gimp_standard_help_func,
                            GIMP_HELP_PREFS_INPUT_CONTROLLERS,
639

640
                            _("_Close"), GTK_RESPONSE_CLOSE,
641

642
                            NULL);
643

644
  gimp_dialog_factory_add_foreign (gimp_dialog_factory_get_singleton (),
645
                                   "gimp-controller-editor-dialog",
646 647 648
                                   dialog,
                                   gtk_widget_get_screen (button),
                                   gimp_widget_get_monitor (button));
649

650 651 652 653
  g_signal_connect (dialog, "response",
                    G_CALLBACK (gtk_widget_destroy),
                    NULL);

654 655
  editor = gimp_controller_editor_new (list->dest_info,
                                       gimp_get_user_context (list->gimp));
656
  gtk_container_set_border_width (GTK_CONTAINER (editor), 12);
657 658
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      editor, TRUE, TRUE, 0);
659 660
  gtk_widget_show (editor);

661
  g_object_set_data (G_OBJECT (list->dest_info), "gimp-controller-editor-dialog",
662 663 664 665 666 667
                     dialog);

  g_signal_connect_object (dialog, "destroy",
                           G_CALLBACK (gimp_controller_list_edit_destroy),
                           G_OBJECT (list->dest_info), 0);

668 669 670 671 672 673 674 675 676
  g_signal_connect_object (list, "destroy",
                           G_CALLBACK (gtk_widget_destroy),
                           G_OBJECT (dialog),
                           G_CONNECT_SWAPPED);
  g_signal_connect_object (list, "unmap",
                           G_CALLBACK (gtk_widget_destroy),
                           G_OBJECT (dialog),
                           G_CONNECT_SWAPPED);

677 678 679 680 681 682 683
  gtk_widget_show (dialog);
}

static void
gimp_controller_list_edit_destroy (GtkWidget          *widget,
                                   GimpControllerInfo *info)
{
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
  g_object_set_data (G_OBJECT (info), "gimp-controller-editor-dialog", NULL);
}

static void
gimp_controller_list_up_clicked (GtkWidget          *button,
                                 GimpControllerList *list)
{
  GimpContainer *container;
  gint           index;

  container = gimp_controllers_get_list (list->gimp);

  index = gimp_container_get_child_index (container,
                                          GIMP_OBJECT (list->dest_info));

  if (index > 0)
    gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),
                            index - 1);
}

static void
gimp_controller_list_down_clicked (GtkWidget          *button,
                                   GimpControllerList *list)
{
  GimpContainer *container;
  gint           index;

  container = gimp_controllers_get_list (list->gimp);

  index = gimp_container_get_child_index (container,
                                          GIMP_OBJECT (list->dest_info));

716
  if (index < gimp_container_get_n_children (container) - 1)
717 718
    gimp_container_reorder (container, GIMP_OBJECT (list->dest_info),
                            index + 1);
719
}