testmerge.c 21.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* testmerge.c
 * Copyright (C) 2003 James Henstridge
 *
 * 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
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17
 */

18
#include "config.h"
19

20 21
#include <stdio.h>
#include <string.h>
22
#ifdef HAVE_UNISTD_H
23
#include <unistd.h>
24
#endif
25

26
#define GDK_DISABLE_DEPRECATION_WARNINGS
27

28 29
#include <gtk/gtk.h>

30 31 32 33
#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1 
#endif

34 35 36 37 38 39 40 41
struct { const gchar *filename; guint merge_id; } merge_ids[] = {
  { "merge-1.ui", 0 },
  { "merge-2.ui", 0 },
  { "merge-3.ui", 0 }
};

static void
dump_tree (GtkWidget    *button, 
42
	   GtkUIManager *merge)
43 44 45
{
  gchar *dump;

46
  dump = gtk_ui_manager_get_ui (merge);
47
  g_message ("%s", dump);
48 49 50
  g_free (dump);
}

51 52 53 54 55 56
static void
dump_accels (void)
{
  gtk_accel_map_save_fd (STDOUT_FILENO);
}

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
static void
print_toplevel (GtkWidget *widget, gpointer user_data)
{
  g_print ("%s\n", G_OBJECT_TYPE_NAME (widget));
}

static void
dump_toplevels (GtkWidget    *button, 
		GtkUIManager *merge)
{
  GSList *toplevels;

  toplevels = gtk_ui_manager_get_toplevels (merge, 
					    GTK_UI_MANAGER_MENUBAR |
					    GTK_UI_MANAGER_TOOLBAR |
					    GTK_UI_MANAGER_POPUP);

74
  g_slist_foreach (toplevels, (GFunc) print_toplevel, NULL);
75 76 77
  g_slist_free (toplevels);
}

78 79 80 81 82 83 84 85 86 87 88
static void
toggle_tearoffs (GtkWidget    *button, 
		 GtkUIManager *merge)
{
  gboolean add_tearoffs;

  add_tearoffs = gtk_ui_manager_get_add_tearoffs (merge);
  
  gtk_ui_manager_set_add_tearoffs (merge, !add_tearoffs);
}

89 90
static gint
delayed_toggle_dynamic (GtkUIManager *merge)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
{
  GtkAction *dyn;
  static GtkActionGroup *dynamic = NULL;
  static guint merge_id = 0;

  if (!dynamic)
    {
      dynamic = gtk_action_group_new ("dynamic");
      gtk_ui_manager_insert_action_group (merge, dynamic, 0);
      dyn = g_object_new (GTK_TYPE_ACTION,
			  "name", "dyn1",
			  "label", "Dynamic action 1",
			  "stock_id", GTK_STOCK_COPY,
			  NULL);
      gtk_action_group_add_action (dynamic, dyn);
      dyn = g_object_new (GTK_TYPE_ACTION,
			  "name", "dyn2",
			  "label", "Dynamic action 2",
			  "stock_id", GTK_STOCK_EXECUTE,
			  NULL);
      gtk_action_group_add_action (dynamic, dyn);
    }
  
  if (merge_id == 0)
    {
      merge_id = gtk_ui_manager_new_merge_id (merge);
      gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder", 
			     "dyn1", "dyn1", 0, 0);
      gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder", 
			     "dynsep", NULL, GTK_UI_MANAGER_SEPARATOR, 0);
      gtk_ui_manager_add_ui (merge, merge_id, "/toolbar1/ToolbarPlaceholder", 
			     "dyn2", "dyn2", 0, 0);

      gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu", 
			     "dyn1menu", "dyn1", GTK_UI_MANAGER_MENU, 0);
      gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu", 
			     "dyn1", "dyn1", GTK_UI_MANAGER_MENUITEM, 0);
128 129
      gtk_ui_manager_add_ui (merge, merge_id, "/menubar/EditMenu/dyn1menu/dyn1", 
			     "dyn2", "dyn2", GTK_UI_MANAGER_AUTO, FALSE);
130 131 132 133 134 135
    }
  else 
    {
      gtk_ui_manager_remove_ui (merge, merge_id);
      merge_id = 0;
    }
136 137

  return FALSE;
138 139
}

140 141 142 143
static void
toggle_dynamic (GtkWidget    *button, 
		GtkUIManager *merge)
{
144
  gdk_threads_add_timeout (2000, (GSourceFunc)delayed_toggle_dynamic, merge);
145
}
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
static void
activate_action (GtkAction *action)
{
  const gchar *name = gtk_action_get_name (action);
  const gchar *typename = G_OBJECT_TYPE_NAME (action);

  g_message ("Action %s (type=%s) activated", name, typename);
}

static void
toggle_action (GtkAction *action)
{
  const gchar *name = gtk_action_get_name (action);
  const gchar *typename = G_OBJECT_TYPE_NAME (action);

162
  g_message ("ToggleAction %s (type=%s) toggled (active=%d)", name, typename,
163 164 165 166
	     gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
}


167 168 169
static void
radio_action_changed (GtkAction *action, GtkRadioAction *current)
{
170
  g_message ("RadioAction %s (type=%s) activated (active=%d) (value %d)", 
171 172 173 174 175 176 177 178 179 180 181
	     gtk_action_get_name (GTK_ACTION (current)), 
	     G_OBJECT_TYPE_NAME (GTK_ACTION (current)),
	     gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (current)),
	     gtk_radio_action_get_current_value (current));
}

static GtkActionEntry entries[] = {
  { "FileMenuAction", NULL, "_File" },
  { "EditMenuAction", NULL, "_Edit" },
  { "HelpMenuAction", NULL, "_Help" },
  { "JustifyMenuAction", NULL, "_Justify" },
182 183
  { "EmptyMenu1Action", NULL, "Empty 1" },
  { "EmptyMenu2Action", NULL, "Empty 2" },
184 185
  { "Test", NULL, "Test" },

186 187 188
  { "QuitAction",  GTK_STOCK_QUIT,  NULL,     "<control>q", "Quit", G_CALLBACK (gtk_main_quit) },
  { "NewAction",   GTK_STOCK_NEW,   NULL,     "<control>n", "Create something", G_CALLBACK (activate_action) },
  { "New2Action",  GTK_STOCK_NEW,   NULL,     "<control>m", "Create something else", G_CALLBACK (activate_action) },
189
  { "OpenAction",  GTK_STOCK_OPEN,  NULL,     NULL,         "Open it", G_CALLBACK (activate_action) },
190 191 192 193
  { "CutAction",   GTK_STOCK_CUT,   NULL,     "<control>x", "Knive", G_CALLBACK (activate_action) },
  { "CopyAction",  GTK_STOCK_COPY,  NULL,     "<control>c", "Copy", G_CALLBACK (activate_action) },
  { "PasteAction", GTK_STOCK_PASTE, NULL,     "<control>v", "Paste", G_CALLBACK (activate_action) },
  { "AboutAction", NULL,            "_About", NULL,         "About", G_CALLBACK (activate_action) },
194 195 196
};
static guint n_entries = G_N_ELEMENTS (entries);

197
static GtkToggleActionEntry toggle_entries[] = {
198
  { "BoldAction",  GTK_STOCK_BOLD,  "_Bold",  "<control>b", "Make it bold", G_CALLBACK (toggle_action), 
199 200 201 202
    TRUE },
};
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);

203 204 205 206 207 208 209 210 211 212
enum {
  JUSTIFY_LEFT,
  JUSTIFY_CENTER,
  JUSTIFY_RIGHT,
  JUSTIFY_FILL
};

static GtkRadioActionEntry radio_entries[] = {
  { "justify-left", GTK_STOCK_JUSTIFY_LEFT, NULL, "<control>L", 
    "Left justify the text", JUSTIFY_LEFT },
213
  { "justify-center", GTK_STOCK_JUSTIFY_CENTER, NULL, "<super>E",
214
    "Center justify the text", JUSTIFY_CENTER },
215
  { "justify-right", GTK_STOCK_JUSTIFY_RIGHT, NULL, "<hyper>R",
216
    "Right justify the text", JUSTIFY_RIGHT },
217
  { "justify-fill", GTK_STOCK_JUSTIFY_FILL, NULL, "<super><hyper>J",
218 219 220 221
    "Fill justify the text", JUSTIFY_FILL },
};
static guint n_radio_entries = G_N_ELEMENTS (radio_entries);

222
static void
223
add_widget (GtkUIManager *merge, 
224 225 226
	    GtkWidget    *widget, 
	    GtkBox       *box)
{
227
  gtk_box_pack_start (box, widget, FALSE, FALSE, 0);
228 229 230 231 232
  gtk_widget_show (widget);
}

static void
toggle_merge (GtkWidget    *button, 
233
	      GtkUIManager *merge)
234 235 236 237 238 239 240 241 242 243 244
{
  gint mergenum;

  mergenum = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "mergenum"));

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
    {
      GError *err = NULL;

      g_message ("merging %s", merge_ids[mergenum].filename);
      merge_ids[mergenum].merge_id =
245
	gtk_ui_manager_add_ui_from_file (merge, merge_ids[mergenum].filename, &err);
246 247 248 249 250 251 252 253 254
      if (err != NULL)
	{
	  GtkWidget *dialog;

	  dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
					   0, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK,
					   "could not merge %s: %s", merge_ids[mergenum].filename,
					   err->message);

255
	  g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
256 257 258 259 260 261 262 263 264
	  gtk_widget_show (dialog);

	  g_clear_error (&err);
	}
    }
  else
    {
      g_message ("unmerging %s (merge_id=%u)", merge_ids[mergenum].filename,
		 merge_ids[mergenum].merge_id);
265
      gtk_ui_manager_remove_ui (merge, merge_ids[mergenum].merge_id);
266 267 268 269 270 271 272 273 274 275 276 277 278 279
    }
}

static void  
set_name_func (GtkTreeViewColumn *tree_column,
	       GtkCellRenderer   *cell,
	       GtkTreeModel      *tree_model,
	       GtkTreeIter       *iter,
	       gpointer           data)
{
  GtkAction *action;
  char *name;
  
  gtk_tree_model_get (tree_model, iter, 0, &action, -1);
280 281
  g_object_get (action, "name", &name, NULL);
  g_object_set (cell, "text", name, NULL);
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
  g_free (name);
  g_object_unref (action);
}

static void
set_sensitive_func (GtkTreeViewColumn *tree_column,
		    GtkCellRenderer   *cell,
		    GtkTreeModel      *tree_model,
		    GtkTreeIter       *iter,
		    gpointer           data)
{
  GtkAction *action;
  gboolean sensitive;
  
  gtk_tree_model_get (tree_model, iter, 0, &action, -1);
297 298
  g_object_get (action, "sensitive", &sensitive, NULL);
  g_object_set (cell, "active", sensitive, NULL);
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  g_object_unref (action);
}


static void
set_visible_func (GtkTreeViewColumn *tree_column,
		  GtkCellRenderer   *cell,
		  GtkTreeModel      *tree_model,
		  GtkTreeIter       *iter,
		  gpointer           data)
{
  GtkAction *action;
  gboolean visible;
  
  gtk_tree_model_get (tree_model, iter, 0, &action, -1);
314 315
  g_object_get (action, "visible", &visible, NULL);
  g_object_set (cell, "active", visible, NULL);
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
  g_object_unref (action);
}

static void
sensitivity_toggled (GtkCellRendererToggle *cell, 
		     const gchar           *path_str,
		     GtkTreeModel          *model)
{
  GtkTreePath *path;
  GtkTreeIter iter;
  GtkAction *action;
  gboolean sensitive;

  path = gtk_tree_path_new_from_string (path_str);
  gtk_tree_model_get_iter (model, &iter, path);

  gtk_tree_model_get (model, &iter, 0, &action, -1);
333 334
  g_object_get (action, "sensitive", &sensitive, NULL);
  g_object_set (action, "sensitive", !sensitive, NULL);
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
  gtk_tree_model_row_changed (model, path, &iter);
  gtk_tree_path_free (path);
}

static void
visibility_toggled (GtkCellRendererToggle *cell, 
		    const gchar           *path_str, 
		    GtkTreeModel          *model)
{
  GtkTreePath *path;
  GtkTreeIter iter;
  GtkAction *action;
  gboolean visible;

  path = gtk_tree_path_new_from_string (path_str);
  gtk_tree_model_get_iter (model, &iter, path);

  gtk_tree_model_get (model, &iter, 0, &action, -1);
353 354
  g_object_get (action, "visible", &visible, NULL);
  g_object_set (action, "visible", !visible, NULL);
355 356 357 358 359 360 361 362 363 364
  gtk_tree_model_row_changed (model, path, &iter);
  gtk_tree_path_free (path);
}

static gint
iter_compare_func (GtkTreeModel *model, 
		   GtkTreeIter  *a, 
		   GtkTreeIter  *b,
		   gpointer      user_data)
{
Javier Jardón's avatar
Javier Jardón committed
365
  GValue a_value = G_VALUE_INIT, b_value = G_VALUE_INIT;
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
  GtkAction *a_action, *b_action;
  const gchar *a_name, *b_name;
  gint retval = 0;

  gtk_tree_model_get_value (model, a, 0, &a_value);
  gtk_tree_model_get_value (model, b, 0, &b_value);
  a_action = GTK_ACTION (g_value_get_object (&a_value));
  b_action = GTK_ACTION (g_value_get_object (&b_value));

  a_name = gtk_action_get_name (a_action);
  b_name = gtk_action_get_name (b_action);
  if (a_name == NULL && b_name == NULL) 
    retval = 0;
  else if (a_name == NULL)
    retval = -1;
  else if (b_name == NULL) 
    retval = 1;
  else 
    retval = strcmp (a_name, b_name);

  g_value_unset (&b_value);
  g_value_unset (&a_value);

  return retval;
}

static GtkWidget *
393
create_tree_view (GtkUIManager *merge)
394 395 396 397 398 399 400 401 402 403 404 405
{
  GtkWidget *tree_view, *sw;
  GtkListStore *store;
  GList *p;
  GtkCellRenderer *cell;
  
  store = gtk_list_store_new (1, GTK_TYPE_ACTION);
  gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), 0,
				   iter_compare_func, NULL, NULL);
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0,
					GTK_SORT_ASCENDING);
  
406
  for (p = gtk_ui_manager_get_action_groups (merge); p; p = p->next)
407 408 409 410 411 412 413 414 415 416 417 418
    {
      GList *actions, *l;

      actions = gtk_action_group_list_actions (p->data);

      for (l = actions; l; l = l->next)
	{
	  GtkTreeIter iter;

	  gtk_list_store_append (store, &iter);
	  gtk_list_store_set (store, &iter, 0, l->data, -1);
	}
419 420

      g_list_free (actions);
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    }
  
  tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
  g_object_unref (store);

  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
					      -1, "Action",
					      gtk_cell_renderer_text_new (),
					      set_name_func, NULL, NULL);

  gtk_tree_view_column_set_sort_column_id (gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), 0), 0);

  cell = gtk_cell_renderer_toggle_new ();
  g_signal_connect (cell, "toggled", G_CALLBACK (sensitivity_toggled), store);
  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
					      -1, "Sensitive",
					      cell,
					      set_sensitive_func, NULL, NULL);

  cell = gtk_cell_renderer_toggle_new ();
  g_signal_connect (cell, "toggled", G_CALLBACK (visibility_toggled), store);
  gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
					      -1, "Visible",
					      cell,
					      set_visible_func, NULL, NULL);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
				  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
  gtk_container_add (GTK_CONTAINER (sw), tree_view);
  
  return sw;
}

static gboolean
area_press (GtkWidget      *drawing_area,
	    GdkEventButton *event,
458
	    GtkUIManager   *merge)
459 460 461
{
  gtk_widget_grab_focus (drawing_area);

462
  if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
463 464
      event->type == GDK_BUTTON_PRESS)
    {
465
      GtkWidget *menu = gtk_ui_manager_get_widget (merge, "/FileMenu");
466 467 468 469 470 471 472 473 474 475 476 477 478 479
      
      if (GTK_IS_MENU (menu)) 
	{
	  gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
			  NULL, drawing_area,
			  3, event->time);
	  return TRUE;
	}
    }

  return FALSE;
  
}

480 481 482 483
static void
activate_path (GtkWidget      *button,
	       GtkUIManager   *merge)
{
484 485 486 487 488 489
  GtkAction *action = gtk_ui_manager_get_action (merge, 
						 "/menubar/HelpMenu/About");
  if (action)
    gtk_action_activate (action);
  else 
    g_message ("no action found");
490 491
}

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
typedef struct _ActionStatus ActionStatus;

struct _ActionStatus {
  GtkAction *action;
  GtkWidget *statusbar;
};

static void
action_status_destroy (gpointer data)
{
  ActionStatus *action_status = data;

  g_object_unref (action_status->action);
  g_object_unref (action_status->statusbar);

  g_free (action_status);
}

static void
set_tip (GtkWidget *widget)
{
  ActionStatus *data;
  gchar *tooltip;
  
  data = g_object_get_data (G_OBJECT (widget), "action-status");
  
  if (data) 
    {
520
      g_object_get (data->action, "tooltip", &tooltip, NULL);
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
      
      gtk_statusbar_push (GTK_STATUSBAR (data->statusbar), 0, 
			  tooltip ? tooltip : "");
      
      g_free (tooltip);
    }
}

static void
unset_tip (GtkWidget *widget)
{
  ActionStatus *data;

  data = g_object_get_data (G_OBJECT (widget), "action-status");

  if (data)
    gtk_statusbar_pop (GTK_STATUSBAR (data->statusbar), 0);
}
		    
static void
541 542
connect_proxy (GtkUIManager *merge,
	       GtkAction    *action,
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
	       GtkWidget    *proxy,
	       GtkWidget    *statusbar)
{
  if (GTK_IS_MENU_ITEM (proxy)) 
    {
      ActionStatus *data;

      data = g_object_get_data (G_OBJECT (proxy), "action-status");
      if (data)
	{
	  g_object_unref (data->action);
	  g_object_unref (data->statusbar);

	  data->action = g_object_ref (action);
	  data->statusbar = g_object_ref (statusbar);
	}
      else
	{
	  data = g_new0 (ActionStatus, 1);

	  data->action = g_object_ref (action);
	  data->statusbar = g_object_ref (statusbar);

	  g_object_set_data_full (G_OBJECT (proxy), "action-status", 
				  data, action_status_destroy);
	  
569 570
	  g_signal_connect (proxy, "select",  G_CALLBACK (set_tip), NULL);
	  g_signal_connect (proxy, "deselect", G_CALLBACK (unset_tip), NULL);
571 572 573 574
	}
    }
}

575 576 577 578
int
main (int argc, char **argv)
{
  GtkActionGroup *action_group;
579
  GtkAction *action;
580
  GtkUIManager *merge;
581
  GtkWidget *window, *grid, *frame, *menu_box, *vbox, *view;
582
  GtkWidget *button, *area, *statusbar;
Matthias Clasen's avatar
Matthias Clasen committed
583
  GtkWidget *box;
584 585 586 587 588
  gint i;
  
  gtk_init (&argc, &argv);

  action_group = gtk_action_group_new ("TestActions");
589 590 591
  gtk_action_group_add_actions (action_group, 
				entries, n_entries, 
				NULL);
592
  action = gtk_action_group_get_action (action_group, "EmptyMenu1Action");
593
  g_object_set (action, "hide_if_empty", FALSE, NULL);
594
  action = gtk_action_group_get_action (action_group, "EmptyMenu2Action");
595
  g_object_set (action, "hide_if_empty", TRUE, NULL);
596 597 598
  gtk_action_group_add_toggle_actions (action_group, 
				       toggle_entries, n_toggle_entries, 
				       NULL);
599 600
  gtk_action_group_add_radio_actions (action_group, 
				      radio_entries, n_radio_entries, 
601
				      JUSTIFY_RIGHT,
602
				      G_CALLBACK (radio_action_changed), NULL);
603 604 605 606 607

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), -1, 400);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

608 609 610 611 612
  grid = gtk_grid_new ();
  gtk_grid_set_row_spacing (GTK_GRID (grid), 2);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 2);
  gtk_container_set_border_width (GTK_CONTAINER (grid), 2);
  gtk_container_add (GTK_CONTAINER (window), grid);
613 614

  frame = gtk_frame_new ("Menus and Toolbars");
615
  gtk_grid_attach (GTK_GRID (grid), frame, 0, 1, 2, 1);
616
  
617
  menu_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
618 619
  gtk_container_set_border_width (GTK_CONTAINER (menu_box), 2);
  gtk_container_add (GTK_CONTAINER (frame), menu_box);
620 621 622 623

  statusbar = gtk_statusbar_new ();
  gtk_box_pack_end (GTK_BOX (menu_box), statusbar, FALSE, FALSE, 0);
    
624 625 626 627 628 629
  area = gtk_drawing_area_new ();
  gtk_widget_set_events (area, GDK_BUTTON_PRESS_MASK);
  gtk_widget_set_size_request (area, -1, 40);
  gtk_box_pack_end (GTK_BOX (menu_box), area, FALSE, FALSE, 0);
  gtk_widget_show (area);

630 631
  button = gtk_button_new ();
  gtk_box_pack_end (GTK_BOX (menu_box), button, FALSE, FALSE, 0);
632 633 634
  gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
			    gtk_action_group_get_action (action_group, "AboutAction"));

635 636 637 638
  gtk_widget_show (button);

  button = gtk_check_button_new ();
  gtk_box_pack_end (GTK_BOX (menu_box), button, FALSE, FALSE, 0);
639 640
  gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
			    gtk_action_group_get_action (action_group, "BoldAction"));
641
  gtk_widget_show (button);
642

Matthias Clasen's avatar
Matthias Clasen committed
643 644 645 646 647 648 649 650 651
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_end (GTK_BOX (menu_box), box, FALSE, FALSE, 0);
  gtk_container_add (GTK_CONTAINER (box), gtk_label_new ("Bold:"));
  button = gtk_switch_new ();
  gtk_container_add (GTK_CONTAINER (box), button);
  gtk_activatable_set_related_action (GTK_ACTIVATABLE (button),
                            gtk_action_group_get_action (action_group, "BoldAction"));
  gtk_widget_show_all (box);

652
  merge = gtk_ui_manager_new ();
653 654

  g_signal_connect (merge, "connect-proxy", G_CALLBACK (connect_proxy), statusbar);
655
  g_signal_connect (area, "button_press_event", G_CALLBACK (area_press), merge);
656

657
  gtk_ui_manager_insert_action_group (merge, action_group, 0);
658 659 660
  g_signal_connect (merge, "add_widget", G_CALLBACK (add_widget), menu_box);

  gtk_window_add_accel_group (GTK_WINDOW (window), 
661
			      gtk_ui_manager_get_accel_group (merge));
662 663
  
  frame = gtk_frame_new ("UI Files");
664 665
  gtk_widget_set_vexpand (frame, TRUE);
  gtk_grid_attach (GTK_GRID (grid), frame, 0, 0, 1, 1);
666

667
  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
668 669 670 671 672 673 674 675 676 677 678 679
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

  for (i = 0; i < G_N_ELEMENTS (merge_ids); i++)
    {
      button = gtk_check_button_new_with_label (merge_ids[i].filename);
      g_object_set_data (G_OBJECT (button), "mergenum", GINT_TO_POINTER (i));
      g_signal_connect (button, "toggled", G_CALLBACK (toggle_merge), merge);
      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
    }

680 681 682 683
  button = gtk_check_button_new_with_label ("Tearoffs");
  g_signal_connect (button, "clicked", G_CALLBACK (toggle_tearoffs), merge);
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);

684 685 686 687
  button = gtk_check_button_new_with_label ("Dynamic");
  g_signal_connect (button, "clicked", G_CALLBACK (toggle_dynamic), merge);
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);

688 689 690 691 692
  button = gtk_button_new_with_label ("Activate path");
  g_signal_connect (button, "clicked", G_CALLBACK (activate_path), merge);
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  button = gtk_button_new_with_label ("Dump Tree");
693
  g_signal_connect (button, "clicked", G_CALLBACK (dump_tree), merge);
694
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
695

696 697 698 699
  button = gtk_button_new_with_label ("Dump Toplevels");
  g_signal_connect (button, "clicked", G_CALLBACK (dump_toplevels), merge);
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);

700 701 702 703
  button = gtk_button_new_with_label ("Dump Accels");
  g_signal_connect (button, "clicked", G_CALLBACK (dump_accels), NULL);
  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);

704
  view = create_tree_view (merge);
705 706 707
  gtk_widget_set_hexpand (view, TRUE);
  gtk_widget_set_vexpand (view, TRUE);
  gtk_grid_attach (GTK_GRID (grid), view, 1, 0, 1, 1);
708 709 710 711

  gtk_widget_show_all (window);
  gtk_main ();

712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
#ifdef DEBUG_UI_MANAGER
  {
    GList *action;
    
    g_print ("\n> before unreffing the ui manager <\n");
    for (action = gtk_action_group_list_actions (action_group);
	 action; 
	 action = action->next)
      {
	GtkAction *a = action->data;
	g_print ("  action %s ref count %d\n", 
		 gtk_action_get_name (a), G_OBJECT (a)->ref_count);
      }
  }
#endif

728
  g_object_unref (merge);
729

730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
#ifdef DEBUG_UI_MANAGER
  {
    GList *action;

    g_print ("\n> after unreffing the ui manager <\n");
    for (action = gtk_action_group_list_actions (action_group);
	 action; 
	 action = action->next)
      {
	GtkAction *a = action->data;
	g_print ("  action %s ref count %d\n", 
		 gtk_action_get_name (a), G_OBJECT (a)->ref_count);
      }
  }
#endif

  g_object_unref (action_group);

748 749
  return 0;
}