diff options
author | Peter Harvey <peter.a.harvey@gmail.com> | 2006-02-04 18:43:25 +0800 |
---|---|---|
committer | Peter Anthony Harvey <paharvey@src.gnome.org> | 2006-02-04 18:43:25 +0800 |
commit | aa0171e76962bcdc240f3a0b3b25b15855803b7b (patch) | |
tree | 2e7015eca562bed70b63ee6b122887834c6ada9e /lib | |
parent | be7c992ff6b3a05d6facf24e42826fe14a94ad89 (diff) | |
download | gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar.gz gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar.bz2 gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar.lz gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar.xz gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.tar.zst gsoc2013-epiphany-aa0171e76962bcdc240f3a0b3b25b15855803b7b.zip |
lib/egg/egg-editable-toolbar.c lib/egg/egg-toolbar-editor.c
2006-02-04 Peter Harvey <peter.a.harvey@gmail.com>
* lib/egg/egg-editable-toolbar.c
* lib/egg/egg-toolbar-editor.c
* lib/egg/egg-toolbars-model.c
* lib/egg/egg-toolbars-model.h
* src/bookmarks/ephy-bookmark-factory-action.c
* src/bookmarks/ephy-topic-factory-action.c
* src/ephy-toolbars-model.c
* src/epiphany.defs
Improve the system for testing whether an item has already
been used on the toolbar.
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 48 | ||||
-rwxr-xr-x | lib/egg/egg-toolbar-editor.c | 8 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.c | 146 | ||||
-rwxr-xr-x | lib/egg/egg-toolbars-model.h | 25 |
4 files changed, 186 insertions, 41 deletions
diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index e7deb4129..42fa32ee3 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -230,7 +230,7 @@ drag_data_delete_cb (GtkWidget *widget, toolbar_pos = get_toolbar_position (etoolbar, widget->parent); egg_toolbars_model_remove_item (etoolbar->priv->model, - toolbar_pos, pos); + toolbar_pos, pos); } static void @@ -238,7 +238,23 @@ drag_begin_cb (GtkWidget *widget, GdkDragContext *context, EggEditableToolbar *etoolbar) { + GtkAction *action; + gint flags; + gtk_widget_hide (widget); + + action = g_object_get_data (G_OBJECT (widget), "gtk-action"); + if (action == NULL) return; + + flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model, + gtk_action_get_name (action)); + if (!(flags & EGG_TB_MODEL_NAME_INFINITE)) + { + flags &= ~EGG_TB_MODEL_NAME_USED; + egg_toolbars_model_set_name_flags (etoolbar->priv->model, + gtk_action_get_name (action), + flags); + } } static void @@ -246,7 +262,26 @@ drag_end_cb (GtkWidget *widget, GdkDragContext *context, EggEditableToolbar *etoolbar) { - gtk_widget_show (widget); + GtkAction *action; + gint flags; + + if (gtk_widget_get_parent (widget) != NULL) + { + gtk_widget_show (widget); + + action = g_object_get_data (G_OBJECT (widget), "gtk-action"); + if (action == NULL) return; + + flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model, + gtk_action_get_name (action)); + if (!(flags & EGG_TB_MODEL_NAME_INFINITE)) + { + flags |= EGG_TB_MODEL_NAME_USED; + egg_toolbars_model_set_name_flags (etoolbar->priv->model, + gtk_action_get_name (action), + flags); + } + } } static void @@ -557,12 +592,17 @@ toolbar_drag_data_received_cb (GtkToolbar *toolbar, int ipos = -1; char *name = NULL; + gboolean used = FALSE; /* Find out where the drop is occuring, and the name of what is being dropped. */ if (selection_data->length >= 0) { ipos = gtk_toolbar_get_drop_index (toolbar, x, y); name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE); + if (name != NULL) + { + used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0); + } } /* If we just want a highlight item, then . */ @@ -570,7 +610,7 @@ toolbar_drag_data_received_cb (GtkToolbar *toolbar, { etoolbar->priv->dnd_pending--; - if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar) + if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used) { etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name); gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar, @@ -589,7 +629,7 @@ toolbar_drag_data_received_cb (GtkToolbar *toolbar, name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE); } - if (name != NULL) + if (name != NULL && !used) { gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar)); egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name); diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c index b03973a07..ca3e2f1ea 100755 --- a/lib/egg/egg-toolbar-editor.c +++ b/lib/egg/egg-toolbar-editor.c @@ -532,7 +532,7 @@ update_editor_sheet (EggToolbarEditor *editor) GtkWidget *viewport; g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); - + /* Create new table. */ table = gtk_table_new (0, 0, TRUE); editor->priv->table = table; @@ -544,16 +544,18 @@ update_editor_sheet (EggToolbarEditor *editor) GDK_ACTION_MOVE | GDK_ACTION_COPY); /* Build two lists of items (one for copying, one for moving). */ - items = egg_toolbars_model_get_avail (editor->priv->model); + items = egg_toolbars_model_get_name_avail (editor->priv->model); while (items->len > 0) { GtkWidget *item; const char *name; + gint flags; name = g_ptr_array_index (items, 0); g_ptr_array_remove_index_fast (items, 0); - if (egg_toolbars_model_get_n_avail (editor->priv->model, name) == 1) + flags = egg_toolbars_model_get_name_flags (editor->priv->model, name); + if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) { item = editor_create_item_from_name (editor, name, GDK_ACTION_MOVE); if (item != NULL) diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c index 682ee59b3..51ada3703 100755 --- a/lib/egg/egg-toolbars-model.c +++ b/lib/egg/egg-toolbars-model.c @@ -65,7 +65,7 @@ struct EggToolbarsModelPrivate { GNode *toolbars; GList *types; - GHashTable *avail; + GHashTable *flags; }; GType @@ -223,9 +223,9 @@ safe_save_xml (const char *xml_file, xmlDocPtr doc) } void -egg_toolbars_model_save (EggToolbarsModel *model, - const char *xml_file, - const char *version) +egg_toolbars_model_save_toolbars (EggToolbarsModel *model, + const char *xml_file, + const char *version) { xmlDocPtr doc; xmlNodePtr root; @@ -239,6 +239,32 @@ egg_toolbars_model_save (EggToolbarsModel *model, xmlFreeDoc (doc); } +static gboolean +is_unique (EggToolbarsModel *model, + EggToolbarsItem *idata) +{ + EggToolbarsItem *idata2; + GNode *toolbar, *item; + + + for(toolbar = g_node_first_child (model->priv->toolbars); + toolbar != NULL; toolbar = g_node_next_sibling (toolbar)) + { + for(item = g_node_first_child (toolbar); + item != NULL; item = g_node_next_sibling (item)) + { + idata2 = item->data; + + if (idata != idata2 && strcmp (idata->name, idata2->name) == 0) + { + return FALSE; + } + } + } + + return TRUE; +} + static GNode * toolbar_node_new (const char *name) { @@ -255,18 +281,18 @@ static GNode * item_node_new (const char *name, EggToolbarsModel *model) { EggToolbarsItem *item; - int count; + int flags; g_return_val_if_fail (name != NULL, NULL); item = g_new (EggToolbarsItem, 1); item->name = g_strdup (name); - count = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->avail, item->name)); - if (count > G_MININT && count < G_MAXINT) - g_hash_table_insert (model->priv->avail, + flags = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, item->name)); + if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) + g_hash_table_insert (model->priv->flags, g_strdup (item->name), - GINT_TO_POINTER (count - 1)); + GINT_TO_POINTER (flags | EGG_TB_MODEL_NAME_USED)); return g_node_new (item); } @@ -275,13 +301,13 @@ static void item_node_free (GNode *item_node, EggToolbarsModel *model) { EggToolbarsItem *item = item_node->data; - int count; + int flags; - count = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->avail, item->name)); - if (count < G_MAXINT - 1) - g_hash_table_insert (model->priv->avail, + flags = GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, item->name)); + if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0 && is_unique (model, item)) + g_hash_table_insert (model->priv->flags, g_strdup (item->name), - GINT_TO_POINTER (count + 1)); + GINT_TO_POINTER (flags & ~EGG_TB_MODEL_NAME_USED)); g_free (item->name); g_free (item); @@ -582,8 +608,8 @@ parse_toolbars (EggToolbarsModel *model, } gboolean -egg_toolbars_model_load (EggToolbarsModel *model, - const char *xml_file) +egg_toolbars_model_load_toolbars (EggToolbarsModel *model, + const char *xml_file) { xmlDocPtr doc; xmlNodePtr root; @@ -608,6 +634,70 @@ egg_toolbars_model_load (EggToolbarsModel *model, } static void +parse_available_list (EggToolbarsModel *model, + xmlNodePtr child) +{ + gint flags; + + while (child) + { + if (xmlStrEqual (child->name, (const xmlChar*) "toolitem")) + { + xmlChar *name; + + name = xmlGetProp (child, (const xmlChar*) "name"); + flags = egg_toolbars_model_get_name_flags + (model, (const char*)name); + egg_toolbars_model_set_name_flags + (model, (const char*)name, flags | EGG_TB_MODEL_NAME_KNOWN); + xmlFree (name); + } + child = child->next; + } +} + +static void +parse_names (EggToolbarsModel *model, + xmlNodePtr child) +{ + while (child) + { + if (xmlStrEqual (child->name, (const xmlChar*) "available")) + { + parse_available_list (model, child->children); + } + + child = child->next; + } +} + +gboolean +egg_toolbars_model_load_names (EggToolbarsModel *model, + const char *xml_file) +{ + xmlDocPtr doc; + xmlNodePtr root; + + g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (model), FALSE); + + if (!xml_file || !g_file_test (xml_file, G_FILE_TEST_EXISTS)) return FALSE; + + doc = xmlParseFile (xml_file); + if (doc == NULL) + { + g_warning ("Failed to load XML data from %s", xml_file); + return FALSE; + } + root = xmlDocGetRootElement (doc); + + parse_names (model, root->children); + + xmlFreeDoc (doc); + + return TRUE; +} + +static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -663,8 +753,10 @@ egg_toolbars_model_init (EggToolbarsModel *model) model->priv =EGG_TOOLBARS_MODEL_GET_PRIVATE (model); model->priv->toolbars = g_node_new (NULL); - model->priv->avail = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - egg_toolbars_model_set_n_avail (model, "_separator", G_MAXINT); + model->priv->flags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + egg_toolbars_model_set_name_flags (model, "_separator", + EGG_TB_MODEL_NAME_KNOWN | + EGG_TB_MODEL_NAME_INFINITE); } static void @@ -675,7 +767,7 @@ egg_toolbars_model_finalize (GObject *object) g_node_children_foreach (model->priv->toolbars, G_TRAVERSE_ALL, (GNodeForeachFunc) toolbar_node_free, model); g_node_destroy (model->priv->toolbars); - g_hash_table_destroy (model->priv->avail); + g_hash_table_destroy (model->priv->flags); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -891,25 +983,27 @@ egg_toolbars_model_set_types (EggToolbarsModel *model, GList *types) static void fill_avail_array (gpointer key, gpointer value, GPtrArray *array) { - if (GPOINTER_TO_INT (value) > 0) g_ptr_array_add (array, key); + int flags = GPOINTER_TO_INT (value); + if ((flags & EGG_TB_MODEL_NAME_KNOWN) && !(flags & EGG_TB_MODEL_NAME_USED)) + g_ptr_array_add (array, key); } GPtrArray * -egg_toolbars_model_get_avail (EggToolbarsModel *model) +egg_toolbars_model_get_name_avail (EggToolbarsModel *model) { GPtrArray *array = g_ptr_array_new (); - g_hash_table_foreach (model->priv->avail, (GHFunc) fill_avail_array, array); + g_hash_table_foreach (model->priv->flags, (GHFunc) fill_avail_array, array); return array; } gint -egg_toolbars_model_get_n_avail (EggToolbarsModel *model, const char *name) +egg_toolbars_model_get_name_flags (EggToolbarsModel *model, const char *name) { - return GPOINTER_TO_INT (g_hash_table_lookup (model->priv->avail, name)); + return GPOINTER_TO_INT (g_hash_table_lookup (model->priv->flags, name)); } void -egg_toolbars_model_set_n_avail (EggToolbarsModel *model, const char *name, gint count) +egg_toolbars_model_set_name_flags (EggToolbarsModel *model, const char *name, gint flags) { - g_hash_table_insert (model->priv->avail, g_strdup (name), GINT_TO_POINTER (count)); + g_hash_table_insert (model->priv->flags, g_strdup (name), GINT_TO_POINTER (flags)); } diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h index cfc19a75d..415328948 100755 --- a/lib/egg/egg-toolbars-model.h +++ b/lib/egg/egg-toolbars-model.h @@ -52,6 +52,13 @@ typedef enum EGG_TB_MODEL_HIDDEN = 1 << 6 } EggTbModelFlags; +typedef enum +{ + EGG_TB_MODEL_NAME_USED = 1 << 0, + EGG_TB_MODEL_NAME_INFINITE = 1 << 1, + EGG_TB_MODEL_NAME_KNOWN = 1 << 2 +} EggTbModelNameFlags; + struct EggToolbarsModel { GObject parent_object; @@ -105,9 +112,11 @@ struct EggToolbarsItemType GType egg_toolbars_model_flags_get_type (void); GType egg_toolbars_model_get_type (void); EggToolbarsModel *egg_toolbars_model_new (void); -gboolean egg_toolbars_model_load (EggToolbarsModel *model, +gboolean egg_toolbars_model_load_names (EggToolbarsModel *model, const char *xml_file); -void egg_toolbars_model_save (EggToolbarsModel *model, +gboolean egg_toolbars_model_load_toolbars (EggToolbarsModel *model, + const char *xml_file); +void egg_toolbars_model_save_toolbars (EggToolbarsModel *model, const char *xml_file, const char *version); @@ -126,12 +135,12 @@ char * egg_toolbars_model_get_data (EggToolbarsModel *model, const char *name); /* Functions for retrieving what items are available for adding to the toolbars. */ -GPtrArray * egg_toolbars_model_get_avail (EggToolbarsModel *model); -gint egg_toolbars_model_get_n_avail (EggToolbarsModel *model, - const char *name); -void egg_toolbars_model_set_n_avail (EggToolbarsModel *model, - const char *name, - gint count); +GPtrArray * egg_toolbars_model_get_name_avail (EggToolbarsModel *model); +gint egg_toolbars_model_get_name_flags (EggToolbarsModel *model, + const char *name); +void egg_toolbars_model_set_name_flags (EggToolbarsModel *model, + const char *name, + gint flags); /* Functions for manipulating flags on individual toolbars. */ EggTbModelFlags egg_toolbars_model_get_flags (EggToolbarsModel *model, |