From aa8e74d93a2c9fb43da9a5a8259cce7c75b1677f Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Thu, 19 Feb 2004 00:24:50 +0000 Subject: When removing a toolbar, make its items available again in the toolbar 2004-02-19 Christian Persch * lib/egg/egg-toolbar-editor.c: (toolbar_removed_cb), (egg_toolbar_editor_set_model), (egg_toolbar_editor_class_init), (update_actions_list), (egg_toolbar_editor_load_actions): * lib/egg/egg-toolbar-editor.h: When removing a toolbar, make its items available again in the toolbar editor. Fixes bug #131182. --- lib/egg/egg-toolbar-editor.c | 61 ++++++++++++++++++++++++++++++++------------ lib/egg/egg-toolbar-editor.h | 2 -- 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'lib/egg') diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c index a317ff458..7924e91ef 100755 --- a/lib/egg/egg-toolbar-editor.c +++ b/lib/egg/egg-toolbar-editor.c @@ -44,6 +44,7 @@ static int n_source_drag_types = G_N_ELEMENTS (source_drag_types); static void egg_toolbar_editor_class_init (EggToolbarEditorClass *klass); static void egg_toolbar_editor_init (EggToolbarEditor *t); static void egg_toolbar_editor_finalize (GObject *object); +static void update_actions_list (EggToolbarEditor *editor); static void update_editor_sheet (EggToolbarEditor *editor); enum @@ -160,6 +161,15 @@ egg_toolbar_editor_set_merge (EggToolbarEditor *t, t->priv->merge = g_object_ref (merge); } +static void +toolbar_removed_cb (EggToolbarsModel *model, + int position, + EggToolbarEditor *editor) +{ + update_actions_list (editor); + update_editor_sheet (editor); +} + static void egg_toolbar_editor_set_model (EggToolbarEditor *t, EggToolbarsModel *model) @@ -167,6 +177,9 @@ egg_toolbar_editor_set_model (EggToolbarEditor *t, g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t)); t->priv->model = g_object_ref (model); + + g_signal_connect_object (model, "toolbar_removed", + G_CALLBACK (toolbar_removed_cb), t, 0); } static void @@ -224,14 +237,16 @@ egg_toolbar_editor_class_init (EggToolbarEditorClass *klass) "MenuMerge", "Menu merge", GTK_TYPE_UI_MANAGER, - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_TOOLBARS_MODEL, g_param_spec_object ("ToolbarsModel", "ToolbarsModel", "Toolbars Model", EGG_TYPE_TOOLBARS_MODEL, - G_PARAM_READWRITE)); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); g_type_class_add_private (object_class, sizeof (EggToolbarEditorPrivate)); } @@ -581,7 +596,7 @@ egg_toolbar_editor_init (EggToolbarEditor *t) setup_editor (t); } -void +static void egg_toolbar_editor_add_action (EggToolbarEditor *editor, const char *action_name) { @@ -638,6 +653,31 @@ model_has_action (EggToolbarsModel *model, GtkAction *action) return FALSE; } +static void +update_actions_list (EggToolbarEditor *editor) +{ + GList *l; + + if (editor->priv->actions_list) + g_list_free (editor->priv->actions_list); + + /* Remove the already used items */ + editor->priv->actions_list = NULL; + + for (l = editor->priv->default_actions_list; l != NULL; l = l->next) + { + GtkAction *action = GTK_ACTION (l->data); + + if (!model_has_action (editor->priv->model, action)) + { + editor->priv->actions_list = g_list_prepend + (editor->priv->actions_list, action); + } + } + + sort_list (editor); +} + void egg_toolbar_editor_load_actions (EggToolbarEditor *editor, const char *xml_file) @@ -662,19 +702,6 @@ egg_toolbar_editor_load_actions (EggToolbarEditor *editor, xmlFreeDoc (doc); - /* Remove the already used items */ - editor->priv->actions_list = g_list_copy (editor->priv->default_actions_list); - for (l = editor->priv->default_actions_list; l != NULL; l = l->next) - { - GtkAction *action = GTK_ACTION (l->data); - - if (model_has_action (editor->priv->model, action)) - { - editor->priv->actions_list = g_list_remove - (editor->priv->actions_list, action); - } - } - sort_list (editor); - + update_actions_list (editor); update_editor_sheet (editor); } diff --git a/lib/egg/egg-toolbar-editor.h b/lib/egg/egg-toolbar-editor.h index 671dfa26e..5a96ad46f 100755 --- a/lib/egg/egg-toolbar-editor.h +++ b/lib/egg/egg-toolbar-editor.h @@ -56,8 +56,6 @@ struct EggToolbarEditorClass GType egg_toolbar_editor_get_type (void); GtkWidget *egg_toolbar_editor_new (GtkUIManager *merge, EggToolbarsModel *model); -void egg_toolbar_editor_add_action (EggToolbarEditor *editor, - const char *action_name); void egg_toolbar_editor_load_actions (EggToolbarEditor *editor, const char *xml_file); -- cgit v1.2.3