static GtkToolItem * create_item_from_position (EggEditableToolbar *etoolbar, int toolbar_position, int position) { GtkToolItem *item; const char *name; name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position); item = create_item_from_action (etoolbar, name); return item; }
static gboolean model_has_action (EggToolbarsModel *model, GtkAction *action) { int i, l, n_items, n_toolbars; n_toolbars = egg_toolbars_model_n_toolbars (model); for (i = 0; i < n_toolbars; i++) { n_items = egg_toolbars_model_n_items (model, i); for (l = 0; l < n_items; l++) { const char *name; const char *action_name; gboolean sep; egg_toolbars_model_item_nth (model, i, l, &sep, &name, NULL); action_name = gtk_action_get_name (action); if (!sep && strcmp (name, action_name) == 0) return TRUE; } } return FALSE; }
static void toolbar_visibility_refresh (EggEditableToolbar *etoolbar) { EggEditableToolbarPrivate *priv = etoolbar->priv; gint n_toolbars, n_items, i, j, k; GtkToggleAction *action; GList *list; GString *string; gboolean showing; char action_name[40]; char *action_label; char *tmp; if (priv == NULL || priv->model == NULL || priv->manager == NULL || priv->visibility_paths == NULL || priv->actions == NULL) { return; } if (priv->visibility_actions == NULL) { priv->visibility_actions = g_ptr_array_new (); } if (priv->visibility_id != 0) { gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id); } priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager); showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar)); n_toolbars = egg_toolbars_model_n_toolbars (priv->model); for (i = 0; i < n_toolbars; i++) { string = g_string_sized_new (0); n_items = egg_toolbars_model_n_items (priv->model, i); for (k = 0, j = 0; j < n_items; j++) { GValue value = { 0, }; GtkAction *action; const char *name; name = egg_toolbars_model_item_nth (priv->model, i, j); if (name == NULL) continue; action = find_action (etoolbar, name); if (action == NULL) continue; g_value_init (&value, G_TYPE_STRING); g_object_get_property (G_OBJECT (action), "label", &value); name = g_value_get_string (&value); if (name == NULL) { g_value_unset (&value); continue; } k += g_utf8_strlen (name, -1) + 2; if (j > 0) { g_string_append (string, ", "); if (j > 1 && k > 25) { g_value_unset (&value); break; } } g_string_append (string, name); g_value_unset (&value); } if (j < n_items) { g_string_append (string, " ..."); } tmp = g_string_free (string, FALSE); for (j = 0, k = 0; tmp[j]; j++) { if (tmp[j] == '_') continue; tmp[k] = tmp[j]; k++; } tmp[k] = 0; /* Translaters: This string is for a toggle to display a toolbar. * The name of the toolbar is automatically computed from the widgets * on the toolbar, and is placed at the %s. Note the _ before the %s * which is used to add mnemonics. We know that this is likely to * produce duplicates, but don't worry about it. If your language * normally has a mnemonic at the start, please use the _. If not, * please remove. */ action_label = g_strdup_printf (_("Show “_%s”"), tmp); g_free (tmp); sprintf(action_name, "ToolbarToggle%d", i); if (i >= priv->visibility_actions->len) { action = gtk_toggle_action_new (action_name, action_label, NULL, NULL); g_ptr_array_add (priv->visibility_actions, action); g_signal_connect_object (action, "toggled", G_CALLBACK (toggled_visibility_cb), etoolbar, 0); gtk_action_group_add_action (priv->actions, GTK_ACTION (action)); } else { action = g_ptr_array_index (priv->visibility_actions, i); g_object_set (action, "label", action_label, NULL); } gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i) & EGG_TB_MODEL_NOT_REMOVABLE) == 0); gtk_action_set_sensitive (GTK_ACTION (action), showing); gtk_toggle_action_set_active (action, gtk_widget_get_visible (get_dock_nth (etoolbar, i))); for (list = priv->visibility_paths; list != NULL; list = g_list_next (list)) { gtk_ui_manager_add_ui (priv->manager, priv->visibility_id, (const char *)list->data, action_name, action_name, GTK_UI_MANAGER_MENUITEM, FALSE); } g_free (action_label); } gtk_ui_manager_ensure_update (priv->manager); while (i < priv->visibility_actions->len) { action = g_ptr_array_index (priv->visibility_actions, i); g_ptr_array_remove_index_fast (priv->visibility_actions, i); gtk_action_group_remove_action (priv->actions, GTK_ACTION (action)); i++; } }