* data/default.proflie, data/Makefile.am, src/anjuta.c,
[anjuta-git-plugin.git] / libanjuta / anjuta-ui.c
blob0155c1813bb16861d60e8e4383e36e7b87554d37
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta-ui.c
4 * Copyright (C) Naba Kumar <naba@gnome.org>
5 *
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
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <stdio.h>
25 #include <string.h>
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;
47 GtkTreeModel *model;
48 GHashTable *customizable_actions_hash;
49 GHashTable *uncustomizable_actions_hash;
52 enum {
53 COLUMN_PIXBUF,
54 COLUMN_ACTION,
55 COLUMN_VISIBLE,
56 COLUMN_SENSITIVE,
57 COLUMN_DATA,
58 COLUMN_GROUP,
59 N_COLUMNS
62 #if 0
63 static void
64 sensitivity_toggled (GtkCellRendererToggle *cell,
65 const gchar *path_str, GtkTreeModel *model)
67 GtkTreePath *path;
68 GtkTreeIter iter;
69 GtkAction *action;
70 gboolean sensitive;
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);
83 #endif
85 static void
86 visibility_toggled (GtkCellRendererToggle *cell,
87 const gchar *path_str, GtkTreeModel *model)
89 GtkTreePath *path;
90 GtkTreeIter iter;
91 GtkAction *action;
92 gboolean visible;
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);
106 static gchar*
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))
114 gchar *s, *d;
115 s = d = action_label;
116 while (*s)
118 /* FIXME: May break with multibyte chars */
119 if (*s == '_')
120 s++;
121 *d = *s; d++; s++;
123 *d = '\0';
125 else
126 action_label = g_strdup (gtk_action_get_name (action));
127 return action_label;
130 static gchar*
131 get_action_accel_path (GtkAction *action, const gchar *group_name)
133 gchar *accel_path;
134 accel_path = g_strconcat ("<Actions>/", group_name,
135 "/", gtk_action_get_name (action), NULL);
136 return accel_path;
139 static gchar*
140 get_action_accel (GtkAction *action, const gchar *group_name)
142 gchar *accel_path;
143 gchar *accel_name;
144 GtkAccelKey key;
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);
149 else
150 accel_name = strdup ("");
151 g_free (accel_path);
152 return accel_name;
155 static void
156 accel_edited_callback (GtkCellRendererText *cell,
157 const char *path_string,
158 guint keyval,
159 GdkModifierType mask,
160 guint hardware_keycode,
161 gpointer data)
163 GtkTreeModel *model = (GtkTreeModel *)data;
164 GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
165 GtkTreeIter iter;
166 GtkAction *action;
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);
174 /* sanity check */
175 if (action == NULL || action_group == NULL)
176 return;
178 accel_path = get_action_accel_path (action, action_group);
179 if (accel_path) {
180 gtk_accel_map_change_entry (accel_path, keyval, mask, TRUE);
181 g_free (accel_path);
184 gtk_tree_path_free (path);
187 static gint
188 iter_compare_func (GtkTreeModel *model, GtkTreeIter *a,
189 GtkTreeIter *b, gpointer user_data)
191 const gchar *text_a;
192 const gchar *text_b;
193 gint retval = 0;
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);
201 return retval;
204 static gboolean
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;
217 return TRUE;
220 if (!egg_accelerator_parse_virtual (str, accelerator_key, &virtual))
221 return FALSE;
223 egg_keymap_resolve_virtual_modifiers (gdk_keymap_get_default (),
224 virtual,
225 accelerator_mods);
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)
232 return FALSE;
234 if (*accelerator_key == 0)
235 return FALSE;
236 else
237 return TRUE;
240 static void
241 accel_set_func (GtkTreeViewColumn *tree_column,
242 GtkCellRenderer *cell,
243 GtkTreeModel *model,
244 GtkTreeIter *iter,
245 gpointer data)
247 GtkAction *action;
248 gchar *accel_name;
249 gchar *group_name;
250 guint keyval;
251 GdkModifierType keymods;
253 gtk_tree_model_get (model, iter,
254 COLUMN_DATA, &action,
255 COLUMN_GROUP, &group_name, -1);
256 if (action == NULL)
257 g_object_set (G_OBJECT (cell), "visible", FALSE, NULL);
258 else
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,
264 "accel_key", keyval,
265 "accel_mask", keymods, NULL);
267 else
268 g_object_set (G_OBJECT (cell), "visible", TRUE,
269 "accel_key", 0,
270 "accel_mask", 0, NULL);
271 g_free (accel_name);
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);
281 static void
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
291 * or not.
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));
317 static void
318 anjuta_ui_finalize (GObject *obj)
320 AnjutaUI *ui = ANJUTA_UI (obj);
321 g_free (ui->priv);
322 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
325 static void
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;
336 static void
337 anjuta_ui_instance_init (AnjutaUI *ui)
339 GtkTreeStore *store;
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,
345 g_str_equal,
346 (GDestroyNotify) g_free,
347 NULL);
348 ui->priv->uncustomizable_actions_hash =
349 g_hash_table_new_full (g_str_hash,
350 g_str_equal,
351 (GDestroyNotify) g_free,
352 NULL);
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,
359 GDK_TYPE_PIXBUF,
360 G_TYPE_STRING,
361 G_TYPE_BOOLEAN,
362 G_TYPE_BOOLEAN,
363 G_TYPE_OBJECT,
364 G_TYPE_STRING);
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);
375 * anjuta_ui_new:
377 * Creates a new instance of #AnjutaUI.
379 * Return value: A #AnjutaUI object
381 AnjutaUI *
382 anjuta_ui_new (void)
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.
413 GtkActionGroup*
414 anjuta_ui_add_action_group_entries (AnjutaUI *ui,
415 const gchar *action_group_name,
416 const gchar *action_group_label,
417 GtkActionEntry *entries,
418 gint num_entries,
419 const gchar *translation_domain,
420 gboolean can_customize,
421 gpointer user_data)
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,
433 user_data);
434 anjuta_ui_add_action_group (ui, action_group_name,
435 action_group_label, action_group,
436 can_customize);
437 return 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.
457 GtkActionGroup*
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,
462 gint num_entries,
463 const gchar *translation_domain,
464 gboolean can_customize,
465 gpointer user_data)
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,
476 user_data);
477 anjuta_ui_add_action_group (ui, action_group_name,
478 action_group_label, action_group,
479 can_customize);
480 return 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().
495 void
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)
502 GList *actions, *l;
503 GtkTreeIter parent;
504 GdkPixbuf *pixbuf;
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);
514 if (can_customize)
516 g_hash_table_insert (ui->priv->customizable_actions_hash,
517 g_strdup (action_group_name), action_group);
519 else
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),
527 &parent, NULL);
528 pixbuf = NULL;
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,
533 -1);
534 for (l = actions; l; l = l->next)
536 gchar *action_label;
537 gchar *icon;
538 guint signal_id;
539 gint n_handlers;
540 GtkTreeIter iter;
541 GtkAction *action = l->data;
543 if (!action)
544 continue;
546 signal_id = g_signal_lookup ("activate", GTK_TYPE_ACTION);
547 n_handlers = g_signal_has_handler_pending (action, signal_id,
548 0, TRUE);
549 if (n_handlers == 0)
550 continue; /* The action element is not user configuration */
552 n_actions_added++;
554 gtk_tree_store_append (GTK_TREE_STORE (ui->priv->model),
555 &iter, &parent);
556 action_label = get_action_label (action);
557 g_object_get (G_OBJECT (action), "stock-id", &icon, NULL);
558 if (icon)
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),
568 COLUMN_DATA, action,
569 COLUMN_GROUP, action_group_name,
570 -1);
571 g_object_unref (G_OBJECT (pixbuf));
572 gtk_widget_destroy (dummy);
573 g_free (icon);
575 else
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),
581 COLUMN_DATA, action,
582 COLUMN_GROUP, action_group_name,
583 -1);
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),
591 &parent);
594 static gboolean
595 on_action_group_remove_hash (gpointer key, gpointer value, gpointer data)
597 if (data == value)
598 return TRUE;
599 else
600 return FALSE;
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.
611 void
612 anjuta_ui_remove_action_group (AnjutaUI *ui, GtkActionGroup *action_group)
614 GtkTreeModel *model;
615 GtkTreeIter iter;
616 gboolean valid;
618 g_return_if_fail (ANJUTA_IS_UI (ui));
620 const gchar *name;
621 name = gtk_action_group_get_name (action_group);
622 model = ui->priv->model;
623 valid = gtk_tree_model_get_iter_first (model, &iter);
624 while (valid)
626 const gchar *group;
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);
635 continue;
637 if (strcmp (group_name, group) == 0)
639 valid = gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
641 else
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.
663 GtkAction*
664 anjuta_ui_get_action (AnjutaUI *ui, const gchar *action_group_name,
665 const gchar *action_name)
667 GtkActionGroup *action_group;
668 GtkAction *action;
670 g_return_val_if_fail (ANJUTA_IS_UI (ui), NULL);
672 action_group = g_hash_table_lookup (ui->priv->customizable_actions_hash,
673 action_group_name);
674 if (!action_group)
676 action_group = g_hash_table_lookup (ui->priv->uncustomizable_actions_hash,
677 action_group_name);
679 if (GTK_IS_ACTION_GROUP (action_group) == FALSE)
681 g_warning ("Unable to find action group \"%s\"", action_group_name);
682 return NULL;
684 action = gtk_action_group_get_action (action_group, action_name);
685 if (GTK_IS_ACTION (action))
686 return action;
687 g_warning ("Unable to find action \"%s\" in group \"%s\"",
688 action_name, action_group_name);
689 return NULL;
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.
701 void
702 anjuta_ui_activate_action_by_path (AnjutaUI *ui, const gchar *action_path)
704 const gchar *action_group_name;
705 const gchar *action_name;
706 GtkAction *action;
707 gchar **strv;
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);
719 if (action)
720 gtk_action_activate (action);
721 g_strfreev (strv);
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.
734 void
735 anjuta_ui_activate_action_by_group (AnjutaUI *ui, GtkActionGroup *action_group,
736 const gchar *action_name)
738 GtkAction *action;
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);
749 * anjuta_ui_merge:
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
760 gint
761 anjuta_ui_merge (AnjutaUI *ui, const gchar *ui_filename)
763 gint id;
764 GError *err = NULL;
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),
769 ui_filename, &err);
770 #ifdef DEBUG
772 gchar *basename = g_path_get_basename (ui_filename);
773 DEBUG_PRINT ("merged [%d] %s", id, basename);
775 #endif
776 if (err != NULL)
777 g_warning ("Could not merge [%s]: %s", ui_filename, err->message);
778 return id;
782 * anjuta_ui_unmerge:
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.
789 void
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.
804 GtkAccelGroup*
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.
821 GtkWidget *
822 anjuta_ui_get_accel_editor (AnjutaUI *ui)
824 GtkWidget *tree_view, *sw;
825 GtkTreeStore *store;
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);
834 /* Columns */
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",
842 COLUMN_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",
847 COLUMN_ACTION);
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"),
856 renderer,
857 "active",
858 COLUMN_VISIBLE,
859 NULL);
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);
862 #if 0
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"),
867 renderer,
868 "active",
869 COLUMN_SENSITIVE,
870 NULL);
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);
873 #endif
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,
878 "editable", TRUE,
879 "accel_mode", EGG_CELL_RENDERER_KEYS_MODE_GTK,
880 NULL);
881 g_signal_connect (G_OBJECT (renderer), "keys_edited",
882 G_CALLBACK (accel_edited_callback),
883 store);
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);
896 return 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
905 * use it.
907 * Return value: The #GtkIconFactory object used by it
909 GtkIconFactory*
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.
922 void
923 anjuta_ui_dump_tree (AnjutaUI *ui)
925 gchar *ui_str;
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); */
932 g_free (ui_str);