1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <glib/gi18n.h>
27 #include <gtk/gtkscrolledwindow.h>
28 #include <gtk/gtkiconfactory.h>
29 #include <gtk/gtktreeview.h>
30 #include <gtk/gtktreestore.h>
31 #include <gtk/gtkcellrenderertoggle.h>
32 #include <gtk/gtkaccelmap.h>
33 #include <gtk/gtkcellrendererpixbuf.h>
34 #include <gtk/gtkimage.h>
35 #include <gtk/gtklabel.h>
37 #include <libgnome/gnome-macros.h>
39 #include <libegg/treeviewutils/eggcellrendererkeys.h>
41 #include "resources.h"
42 #include "anjuta-ui.h"
43 #include "anjuta-debug.h"
45 struct _AnjutaUIPrivate
{
46 GtkIconFactory
*icon_factory
;
48 GHashTable
*customizable_actions_hash
;
49 GHashTable
*uncustomizable_actions_hash
;
64 sensitivity_toggled (GtkCellRendererToggle
*cell
,
65 const gchar
*path_str
, GtkTreeModel
*model
)
72 path
= gtk_tree_path_new_from_string (path_str
);
73 gtk_tree_model_get_iter (model
, &iter
, path
);
75 gtk_tree_model_get (model
, &iter
,
76 COLUMN_SENSITIVE
, &sensitive
,
77 COLUMN_DATA
, &action
, -1);
78 g_object_set (G_OBJECT (action
), "sensitive", !sensitive
, NULL
);
79 gtk_tree_store_set (GTK_TREE_STORE (model
), &iter
,
80 COLUMN_SENSITIVE
, !sensitive
, -1);
81 gtk_tree_path_free (path
);
86 visibility_toggled (GtkCellRendererToggle
*cell
,
87 const gchar
*path_str
, GtkTreeModel
*model
)
94 path
= gtk_tree_path_new_from_string (path_str
);
95 gtk_tree_model_get_iter (model
, &iter
, path
);
97 gtk_tree_model_get (model
, &iter
,
98 COLUMN_VISIBLE
, &visible
,
99 COLUMN_DATA
, &action
, -1);
100 g_object_set (G_OBJECT (action
), "visible", !visible
, NULL
);
101 gtk_tree_store_set (GTK_TREE_STORE (model
), &iter
,
102 COLUMN_VISIBLE
, !visible
, -1);
103 gtk_tree_path_free (path
);
107 get_action_label (GtkAction
*action
)
109 gchar
*action_label
= NULL
;
111 g_object_get (G_OBJECT (action
), "label", &action_label
, NULL
);
112 if (action_label
&& strlen (action_label
))
115 s
= d
= action_label
;
118 /* FIXME: May break with multibyte chars */
126 action_label
= g_strdup (gtk_action_get_name (action
));
131 get_action_accel_path (GtkAction
*action
, const gchar
*group_name
)
134 accel_path
= g_strconcat ("<Actions>/", group_name
,
135 "/", gtk_action_get_name (action
), NULL
);
140 get_action_accel (GtkAction
*action
, const gchar
*group_name
)
146 accel_path
= get_action_accel_path (action
, group_name
);
147 if ( gtk_accel_map_lookup_entry (accel_path
, &key
))
148 accel_name
= gtk_accelerator_name (key
.accel_key
, key
.accel_mods
);
150 accel_name
= strdup ("");
156 accel_edited_callback (GtkCellRendererText
*cell
,
157 const char *path_string
,
159 GdkModifierType mask
,
160 guint hardware_keycode
,
163 GtkTreeModel
*model
= (GtkTreeModel
*)data
;
164 GtkTreePath
*path
= gtk_tree_path_new_from_string (path_string
);
167 gchar
*accel_path
, *action_group
;
169 gtk_tree_model_get_iter (model
, &iter
, path
);
170 gtk_tree_model_get (model
, &iter
,
171 COLUMN_DATA
, &action
,
172 COLUMN_GROUP
, &action_group
, -1);
175 if (action
== NULL
|| action_group
== NULL
)
178 accel_path
= get_action_accel_path (action
, action_group
);
180 gtk_accel_map_change_entry (accel_path
, keyval
, mask
, TRUE
);
184 gtk_tree_path_free (path
);
188 iter_compare_func (GtkTreeModel
*model
, GtkTreeIter
*a
,
189 GtkTreeIter
*b
, gpointer user_data
)
195 gtk_tree_model_get (model
, a
, COLUMN_ACTION
, &text_a
, -1);
196 gtk_tree_model_get (model
, b
, COLUMN_ACTION
, &text_b
, -1);
197 if (text_a
== NULL
&& text_b
== NULL
) retval
= 0;
198 else if (text_a
== NULL
) retval
= -1;
199 else if (text_b
== NULL
) retval
= 1;
200 else retval
= strcasecmp (text_a
, text_b
);
205 binding_from_string (const char *str
,
206 guint
*accelerator_key
,
207 GdkModifierType
*accelerator_mods
)
209 EggVirtualModifierType
virtual;
211 g_return_val_if_fail (accelerator_key
!= NULL
, FALSE
);
213 if (str
== NULL
|| (str
&& strcmp (str
, "disabled") == 0))
215 *accelerator_key
= 0;
216 *accelerator_mods
= 0;
220 if (!egg_accelerator_parse_virtual (str
, accelerator_key
, &virtual))
223 egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (),
227 /* Be sure the GTK accelerator system will be able to handle this
228 * accelerator. Be sure to allow no-accelerator accels like F1.
230 if ((*accelerator_mods
& gtk_accelerator_get_default_mod_mask ()) == 0 &&
231 *accelerator_mods
!= 0)
234 if (*accelerator_key
== 0)
241 accel_set_func (GtkTreeViewColumn
*tree_column
,
242 GtkCellRenderer
*cell
,
251 GdkModifierType keymods
;
253 gtk_tree_model_get (model
, iter
,
254 COLUMN_DATA
, &action
,
255 COLUMN_GROUP
, &group_name
, -1);
257 g_object_set (G_OBJECT (cell
), "visible", FALSE
, NULL
);
260 accel_name
= get_action_accel (action
, group_name
);
261 if (binding_from_string (accel_name
, &keyval
, &keymods
))
263 g_object_set (G_OBJECT (cell
), "visible", TRUE
,
265 "accel_mask", keymods
, NULL
);
268 g_object_set (G_OBJECT (cell
), "visible", TRUE
,
270 "accel_mask", 0, NULL
);
275 static void anjuta_ui_class_init (AnjutaUIClass
*class);
276 static void anjuta_ui_instance_init (AnjutaUI
*ui
);
278 GNOME_CLASS_BOILERPLATE (AnjutaUI
, anjuta_ui
,
279 GtkUIManager
, GTK_TYPE_UI_MANAGER
);
282 anjuta_ui_dispose (GObject
*obj
)
284 AnjutaUI
*ui
= ANJUTA_UI (obj
);
286 if (ui
->priv
->model
) {
287 /* This will also release the refs on actions.
288 * Clear is necessary because following unref() might not actually
289 * finalize the model. It basically ensures all refs on actions
290 * are released irrespective of whether the model is finalized
293 gtk_tree_store_clear (GTK_TREE_STORE (ui
->priv
->model
));
295 g_object_unref (G_OBJECT (ui
->priv
->model
));
296 ui
->priv
->model
= NULL
;
298 if (ui
->priv
->customizable_actions_hash
)
300 /* This will also release the refs on all action groups */
301 g_hash_table_destroy (ui
->priv
->customizable_actions_hash
);
302 ui
->priv
->customizable_actions_hash
= NULL
;
304 if (ui
->priv
->uncustomizable_actions_hash
)
306 /* This will also release the refs on all action groups */
307 g_hash_table_destroy (ui
->priv
->uncustomizable_actions_hash
);
308 ui
->priv
->uncustomizable_actions_hash
= NULL
;
310 if (ui
->priv
->icon_factory
) {
311 g_object_unref (G_OBJECT (ui
->priv
->icon_factory
));
312 ui
->priv
->icon_factory
= NULL
;
314 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
318 anjuta_ui_finalize (GObject
*obj
)
320 AnjutaUI
*ui
= ANJUTA_UI (obj
);
322 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (obj
));
326 anjuta_ui_class_init (AnjutaUIClass
*class)
328 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
330 parent_class
= g_type_class_peek_parent (class);
332 object_class
->dispose
= anjuta_ui_dispose
;
333 object_class
->finalize
= anjuta_ui_finalize
;
337 anjuta_ui_instance_init (AnjutaUI
*ui
)
341 /* Initialize member data */
342 ui
->priv
= g_new0 (AnjutaUIPrivate
, 1);
343 ui
->priv
->customizable_actions_hash
=
344 g_hash_table_new_full (g_str_hash
,
346 (GDestroyNotify
) g_free
,
348 ui
->priv
->uncustomizable_actions_hash
=
349 g_hash_table_new_full (g_str_hash
,
351 (GDestroyNotify
) g_free
,
353 /* Create Icon factory */
354 ui
->priv
->icon_factory
= gtk_icon_factory_new ();
355 gtk_icon_factory_add_default (ui
->priv
->icon_factory
);
357 /* Create Accel editor model */
358 store
= gtk_tree_store_new (N_COLUMNS
,
365 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(store
), COLUMN_ACTION
,
366 iter_compare_func
, NULL
, NULL
);
367 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(store
),
368 COLUMN_ACTION
, GTK_SORT_ASCENDING
);
370 /* unreferenced in dispose() method. */
371 ui
->priv
->model
= GTK_TREE_MODEL (store
);
377 * Creates a new instance of #AnjutaUI.
379 * Return value: A #AnjutaUI object
384 return g_object_new (ANJUTA_TYPE_UI
, NULL
);
388 * anjuta_ui_add_action_group_entries:
389 * @ui: A #AnjutaUI object.
390 * @action_group_name: Untranslated name of the action group.
391 * @action_group_label: Translated label of the action group.
392 * @entries: An array of action entries.
393 * @num_entries: Number of elements in the action entries array.
394 * @can_customize: If true the actions are customizable by user.
395 * @translation_domain: The translation domain used to translated the entries.
396 * It is usually the GETTEXT_PACKAGE macro in a project.
397 * @user_data: User data to pass to action objects. This is the data that
398 * will come as user_data in "activate" signal of the actions.
400 * #GtkAction objects are created from the #GtkActionEntry structures and
401 * added to the UI Manager. "activate" signal of #GtkAction is connected for
402 * all the action objects using the callback in the entry structure and the
403 * @user_data passed here.
405 * This group of actions are registered with the name @action_group_name
406 * in #AnjutaUI. A #GtkAction object from this action group can be later
407 * retrieved by anjuta_ui_get_action() using @action_group_name and action name.
408 * @action_group_label is used as the display name for the action group in
409 * UI manager dialog where action shortcuts are configured.
411 * Return value: A #GtkActionGroup object holding all the action objects.
414 anjuta_ui_add_action_group_entries (AnjutaUI
*ui
,
415 const gchar
*action_group_name
,
416 const gchar
*action_group_label
,
417 GtkActionEntry
*entries
,
419 const gchar
*translation_domain
,
420 gboolean can_customize
,
423 GtkActionGroup
*action_group
;
425 g_return_val_if_fail (ANJUTA_IS_UI (ui
), NULL
);
426 g_return_val_if_fail (action_group_name
!= NULL
, NULL
);
427 g_return_val_if_fail (action_group_name
!= NULL
, NULL
);
429 action_group
= gtk_action_group_new (action_group_name
);
431 gtk_action_group_set_translation_domain (action_group
, translation_domain
);
432 gtk_action_group_add_actions (action_group
, entries
, num_entries
,
434 anjuta_ui_add_action_group (ui
, action_group_name
,
435 action_group_label
, action_group
,
441 * anjuta_ui_add_toggle_action_group_entries:
442 * @ui: A #AnjutaUI object.
443 * @action_group_name: Untranslated name of the action group.
444 * @action_group_label: Translated label of the action group.
445 * @entries: An array of action entries.
446 * @num_entries: Number of elements in the action entries array.
447 * @translation_domain: The translation domain used to translated the entries.
448 * It is usually the GETTEXT_PACKAGE macro in a project.
449 * @user_data: User data to pass to action objects. This is the data that
450 * will come as user_data in "activate" signal of the actions.
452 * This is similar to anjuta_ui_add_action_group_entries(), except that
453 * it adds #GtkToggleAction objects after creating them from the @entries.
455 * Return value: A #GtkActionGroup object holding all the action objects.
458 anjuta_ui_add_toggle_action_group_entries (AnjutaUI
*ui
,
459 const gchar
*action_group_name
,
460 const gchar
*action_group_label
,
461 GtkToggleActionEntry
*entries
,
463 const gchar
*translation_domain
,
464 gboolean can_customize
,
467 GtkActionGroup
*action_group
;
469 g_return_val_if_fail (ANJUTA_IS_UI (ui
), NULL
);
470 g_return_val_if_fail (action_group_name
!= NULL
, NULL
);
471 g_return_val_if_fail (action_group_name
!= NULL
, NULL
);
473 action_group
= gtk_action_group_new (action_group_name
);
474 gtk_action_group_set_translation_domain (action_group
, translation_domain
);
475 gtk_action_group_add_toggle_actions (action_group
, entries
, num_entries
,
477 anjuta_ui_add_action_group (ui
, action_group_name
,
478 action_group_label
, action_group
,
484 * anjuta_ui_add_action_group:
485 * @ui: A #AnjutaUI object.
486 * @action_group_name: Untranslated name of the action group.
487 * @action_group_label: Translated label of the action group.
488 * @action_group: #GtkActionGroup object to add.
490 * This is similar to anjuta_ui_add_action_group_entries(), except that
491 * it adds #GtkActionGroup object @action_group directly. All actions in this
492 * group are automatically registered in #AnjutaUI and can be retrieved
493 * normally with anjuta_ui_get_action().
496 anjuta_ui_add_action_group (AnjutaUI
*ui
,
497 const gchar
*action_group_name
,
498 const gchar
*action_group_label
,
499 GtkActionGroup
*action_group
,
500 gboolean can_customize
)
505 gint n_actions_added
= 0;
507 g_return_if_fail (ANJUTA_IS_UI (ui
));
508 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group
));
509 g_return_if_fail (action_group_name
!= NULL
);
510 g_return_if_fail (action_group_name
!= NULL
);
512 gtk_ui_manager_insert_action_group (GTK_UI_MANAGER (ui
), action_group
, 0);
516 g_hash_table_insert (ui
->priv
->customizable_actions_hash
,
517 g_strdup (action_group_name
), action_group
);
521 g_hash_table_insert (ui
->priv
->uncustomizable_actions_hash
,
522 g_strdup (action_group_name
), action_group
);
525 actions
= gtk_action_group_list_actions (action_group
);
526 gtk_tree_store_append (GTK_TREE_STORE (ui
->priv
->model
),
529 gtk_tree_store_set (GTK_TREE_STORE (ui
->priv
->model
), &parent
,
530 COLUMN_PIXBUF
, pixbuf
,
531 COLUMN_ACTION
, action_group_label
,
532 COLUMN_GROUP
, action_group_name
,
534 for (l
= actions
; l
; l
= l
->next
)
541 GtkAction
*action
= l
->data
;
546 signal_id
= g_signal_lookup ("activate", GTK_TYPE_ACTION
);
547 n_handlers
= g_signal_has_handler_pending (action
, signal_id
,
550 continue; /* The action element is not user configuration */
554 gtk_tree_store_append (GTK_TREE_STORE (ui
->priv
->model
),
556 action_label
= get_action_label (action
);
557 g_object_get (G_OBJECT (action
), "stock-id", &icon
, NULL
);
560 GtkWidget
*dummy
= gtk_label_new ("Dummy");
561 pixbuf
= gtk_widget_render_icon (dummy
, icon
,
562 GTK_ICON_SIZE_MENU
, NULL
);
563 gtk_tree_store_set (GTK_TREE_STORE (ui
->priv
->model
), &iter
,
564 COLUMN_PIXBUF
, pixbuf
,
565 COLUMN_ACTION
, action_label
,
566 COLUMN_VISIBLE
, gtk_action_get_visible (action
),
567 COLUMN_SENSITIVE
, gtk_action_get_sensitive(action
),
569 COLUMN_GROUP
, action_group_name
,
571 g_object_unref (G_OBJECT (pixbuf
));
572 gtk_widget_destroy (dummy
);
577 gtk_tree_store_set (GTK_TREE_STORE (ui
->priv
->model
), &iter
,
578 COLUMN_ACTION
, action_label
,
579 COLUMN_VISIBLE
, gtk_action_get_visible (action
),
580 COLUMN_SENSITIVE
, gtk_action_get_sensitive (action
),
582 COLUMN_GROUP
, action_group_name
,
585 g_free (action_label
);
588 /* If there are no actions in the group, removed the group node */
589 if (n_actions_added
== 0)
590 gtk_tree_store_remove (GTK_TREE_STORE (ui
->priv
->model
),
595 on_action_group_remove_hash (gpointer key
, gpointer value
, gpointer data
)
604 * anjuta_ui_remove_action_group:
605 * @ui: A #AnjutaUI object
606 * @action_group: #GtkActionGroup object to remove.
608 * Removes a previous added action group. All actions in this group are
609 * also unregistered from UI manager.
612 anjuta_ui_remove_action_group (AnjutaUI
*ui
, GtkActionGroup
*action_group
)
618 g_return_if_fail (ANJUTA_IS_UI (ui
));
621 name
= gtk_action_group_get_name (action_group
);
622 model
= ui
->priv
->model
;
623 valid
= gtk_tree_model_get_iter_first (model
, &iter
);
627 const gchar
*group_name
;
629 gtk_tree_model_get (model
, &iter
, COLUMN_GROUP
, &group
, -1);
630 group_name
= gtk_action_group_get_name (GTK_ACTION_GROUP (action_group
));
632 if (group_name
== NULL
|| group
== NULL
)
634 valid
= gtk_tree_model_iter_next (model
, &iter
);
637 if (strcmp (group_name
, group
) == 0)
639 valid
= gtk_tree_store_remove (GTK_TREE_STORE (model
), &iter
);
642 valid
= gtk_tree_model_iter_next (model
, &iter
);
644 gtk_ui_manager_remove_action_group (GTK_UI_MANAGER (ui
), action_group
);
646 g_hash_table_foreach_remove (ui
->priv
->customizable_actions_hash
,
647 on_action_group_remove_hash
, action_group
);
648 g_hash_table_foreach_remove (ui
->priv
->uncustomizable_actions_hash
,
649 on_action_group_remove_hash
, action_group
);
653 * anjuta_ui_get_action:
654 * @ui: This #AnjutaUI object
655 * @action_group_name: Group name.
656 * @action_name: Action name.
657 * returns: A #GtkAction object
659 * Returns the action object with the name @action_name in @action_group_name.
660 * Note that it will be only sucessully returned if the group has been added
661 * using methods in #AnjutaUI.
664 anjuta_ui_get_action (AnjutaUI
*ui
, const gchar
*action_group_name
,
665 const gchar
*action_name
)
667 GtkActionGroup
*action_group
;
670 g_return_val_if_fail (ANJUTA_IS_UI (ui
), NULL
);
672 action_group
= g_hash_table_lookup (ui
->priv
->customizable_actions_hash
,
676 action_group
= g_hash_table_lookup (ui
->priv
->uncustomizable_actions_hash
,
679 if (GTK_IS_ACTION_GROUP (action_group
) == FALSE
)
681 g_warning ("Unable to find action group \"%s\"", action_group_name
);
684 action
= gtk_action_group_get_action (action_group
, action_name
);
685 if (GTK_IS_ACTION (action
))
687 g_warning ("Unable to find action \"%s\" in group \"%s\"",
688 action_name
, action_group_name
);
693 * anjuta_ui_activate_action_by_path:
694 * @ui: This #AnjutaUI object
695 * @action_path: Path of the action in the form "GroupName/ActionName"
697 * Activates the action represented by @action_path. The path is in the form
698 * "ActionGroupName/ActionName". Note that it will only work if the group has
699 * been added using methods in #AnjutaUI.
702 anjuta_ui_activate_action_by_path (AnjutaUI
*ui
, const gchar
*action_path
)
704 const gchar
*action_group_name
;
705 const gchar
*action_name
;
709 g_return_if_fail (ANJUTA_IS_UI (ui
));
710 g_return_if_fail (action_path
!= NULL
);
712 strv
= g_strsplit (action_path
, "/", 2);
713 action_group_name
= strv
[0];
714 action_name
= strv
[1];
716 g_return_if_fail (action_group_name
!= NULL
&& action_name
!= NULL
);
718 action
= anjuta_ui_get_action (ui
, action_group_name
, action_name
);
720 gtk_action_activate (action
);
725 * anjuta_ui_activate_action_by_group:
726 * @ui: This #AnjutaUI object
727 * @action_group: Action group.
728 * @action_name: Action name.
730 * Activates the action @action_name in the #GtkActionGroup @action_group.
731 * "ActionGroupName/ActionName". Note that it will only work if the group has
732 * been added using methods in #AnjutaUI.
735 anjuta_ui_activate_action_by_group (AnjutaUI
*ui
, GtkActionGroup
*action_group
,
736 const gchar
*action_name
)
740 g_return_if_fail (ANJUTA_IS_UI (ui
));
741 g_return_if_fail (action_group
!= NULL
&& action_name
!= NULL
);
743 action
= gtk_action_group_get_action (action_group
, action_name
);
744 if (GTK_IS_ACTION (action
))
745 gtk_action_activate (action
);
750 * @ui: A #AnjutaUI object.
751 * @ui_filename: UI file to merge into UI manager.
753 * Merges XML UI definition in @ui_filename. UI elements defined in the xml
754 * are merged with existing UI elements in UI manager. The format of the
755 * file content is the standard XML UI definition tree. For more detail,
756 * read the documentation for #GtkUIManager.
758 * Return value: Integer merge ID
761 anjuta_ui_merge (AnjutaUI
*ui
, const gchar
*ui_filename
)
766 g_return_val_if_fail (ANJUTA_IS_UI (ui
), -1);
767 g_return_val_if_fail (ui_filename
!= NULL
, -1);
768 id
= gtk_ui_manager_add_ui_from_file(GTK_UI_MANAGER (ui
),
772 gchar
*basename
= g_path_get_basename (ui_filename
);
773 DEBUG_PRINT ("merged [%d] %s", id
, basename
);
777 g_warning ("Could not merge [%s]: %s", ui_filename
, err
->message
);
783 * @ui: A #AnjutaUI object.
784 * @id: Merge ID returned by anjuta_ui_merge().
786 * Unmerges UI with the ID value @id (returned by anjuta_ui_merge() when
787 * it was merged. For more detail, read the documentation for #GtkUIManager.
790 anjuta_ui_unmerge (AnjutaUI
*ui
, gint id
)
792 /* DEBUG_PRINT ("Menu unmerging %d", id); */
793 g_return_if_fail (ANJUTA_IS_UI (ui
));
794 gtk_ui_manager_remove_ui(GTK_UI_MANAGER (ui
), id
);
798 * anjuta_ui_get_accel_group:
799 * @ui: A #AnjutaUI object.
800 * returns: A #GtkAccelGroup object.
802 * Returns the #GtkAccelGroup object associated with this UI manager.
805 anjuta_ui_get_accel_group (AnjutaUI
*ui
)
807 g_return_val_if_fail (ANJUTA_IS_UI (ui
), NULL
);
808 return gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (ui
));
812 * anjuta_ui_get_accel_editor:
813 * @ui: A #AnjutaUI object.
814 * returns: A #GtkWidget object.
816 * Creates an accel editor widget and returns it. It should be added to
817 * container and displayed to users.
819 * Returns a #GtkWidget containing the editor.
822 anjuta_ui_get_accel_editor (AnjutaUI
*ui
)
824 GtkWidget
*tree_view
, *sw
;
826 GtkTreeViewColumn
*column
;
827 GtkCellRenderer
*renderer
;
829 store
= GTK_TREE_STORE (ui
->priv
->model
);
831 tree_view
= gtk_tree_view_new_with_model (GTK_TREE_MODEL (store
));
832 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view
), TRUE
);
835 column
= gtk_tree_view_column_new ();
836 /* gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); */
837 gtk_tree_view_column_set_title (column
, _("Action"));
839 renderer
= gtk_cell_renderer_pixbuf_new ();
840 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
841 gtk_tree_view_column_add_attribute (column
, renderer
, "pixbuf",
844 renderer
= gtk_cell_renderer_text_new ();
845 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
846 gtk_tree_view_column_add_attribute (column
, renderer
, "text",
848 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view
), column
);
849 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree_view
), column
);
850 gtk_tree_view_column_set_sort_column_id (column
, 0);
852 renderer
= gtk_cell_renderer_toggle_new ();
853 g_signal_connect (G_OBJECT (renderer
), "toggled",
854 G_CALLBACK (visibility_toggled
), store
);
855 column
= gtk_tree_view_column_new_with_attributes (_("Visible"),
860 /* gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); */
861 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view
), column
);
863 renderer
= gtk_cell_renderer_toggle_new ();
864 g_signal_connect (G_OBJECT (renderer
), "toggled",
865 G_CALLBACK (sensitivity_toggled
), store
);
866 column
= gtk_tree_view_column_new_with_attributes (_("Sensitive"),
871 /* gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); */
872 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view
), column
);
874 column
= gtk_tree_view_column_new ();
875 gtk_tree_view_column_set_title (column
, _("Shortcut"));
876 /* gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); */
877 renderer
= g_object_new (EGG_TYPE_CELL_RENDERER_KEYS
,
879 "accel_mode", EGG_CELL_RENDERER_KEYS_MODE_GTK
,
881 g_signal_connect (G_OBJECT (renderer
), "keys_edited",
882 G_CALLBACK (accel_edited_callback
),
884 g_object_set (G_OBJECT (renderer
), "editable", TRUE
, NULL
);
885 gtk_tree_view_column_pack_start (column
, renderer
, TRUE
);
886 gtk_tree_view_column_set_cell_data_func (column
, renderer
, accel_set_func
, NULL
, NULL
);
887 gtk_tree_view_column_set_sort_column_id (column
, COLUMN_DATA
);
888 gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view
), column
);
890 sw
= gtk_scrolled_window_new (NULL
, NULL
);
891 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw
),
892 GTK_POLICY_AUTOMATIC
,
893 GTK_POLICY_AUTOMATIC
);
894 gtk_container_add (GTK_CONTAINER (sw
), tree_view
);
895 gtk_widget_show_all (sw
);
900 * anjuta_ui_get_icon_factory:
901 * @ui: A #AnjutaUI object
903 * This returns the IconFactory object. All icons should be registered using
904 * this icon factory. Read the documentation for #GtkIconFactory on how to
907 * Return value: The #GtkIconFactory object used by it
910 anjuta_ui_get_icon_factory (AnjutaUI
*ui
)
912 g_return_val_if_fail (ANJUTA_IS_UI (ui
), NULL
);
913 return ui
->priv
->icon_factory
;
917 * anjuta_ui_dump_tree:
918 * @ui: A #AnjutaUI object.
920 * Dumps the current UI XML tree in STDOUT. Useful for debugging.
923 anjuta_ui_dump_tree (AnjutaUI
*ui
)
927 g_return_if_fail (ANJUTA_IS_UI(ui
));
929 gtk_ui_manager_ensure_update (GTK_UI_MANAGER (ui
));
930 ui_str
= gtk_ui_manager_get_ui (GTK_UI_MANAGER (ui
));
931 /* DEBUG_PRINT ("%s", ui_str); */