aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rwxr-xr-xlib/egg/egg-editable-toolbar.c70
-rwxr-xr-xlib/egg/egg-toolbar-editor.c2
-rwxr-xr-xlib/egg/egg-toolbars-model.c20
-rwxr-xr-xlib/egg/egg-toolbars-model.h6
-rwxr-xr-xsrc/ephy-toolbars-model.c35
6 files changed, 76 insertions, 70 deletions
diff --git a/ChangeLog b/ChangeLog
index 62716c35c..0ff976525 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-06-09 Marco Pesenti Gritti <marco@gnome.org>
+
+ * lib/egg/egg-editable-toolbar.c: (drag_data_get_cb),
+ (set_item_drag_source), (create_item_from_action), (create_item),
+ (drag_data_received_cb), (egg_editable_toolbar_set_edit_mode):
+ * lib/egg/egg-toolbar-editor.c: (model_has_action):
+ * lib/egg/egg-toolbars-model.c: (egg_toolbars_model_item_nth):
+ * lib/egg/egg-toolbars-model.h:
+ * src/ephy-toolbars-model.c: (get_toolbar_and_item_pos),
+ (ephy_toolbars_model_class_init), (item_added):
+
+ Retain custom types when moving items around
+
2004-06-08 Christian Persch <chpe@cvs.gnome.org>
* embed/mozilla/EventContext.cpp:
diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c
index 7b44fd427..ca8fa69da 100755
--- a/lib/egg/egg-editable-toolbar.c
+++ b/lib/egg/egg-editable-toolbar.c
@@ -47,11 +47,6 @@ static void egg_editable_toolbar_finalize (GObject *object);
#define MIN_TOOLBAR_HEIGHT 20
-static GtkTargetEntry source_drag_types[] = {
- {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
-};
-static int n_source_drag_types = G_N_ELEMENTS (source_drag_types);
-
static GtkTargetEntry dest_drag_types[] = {
{EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
};
@@ -243,16 +238,7 @@ drag_data_get_cb (GtkWidget *widget,
g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
- action = GTK_ACTION (g_object_get_data (G_OBJECT (widget), "gtk-action"));
-
- if (action)
- {
- target = gtk_action_get_name (action);
- }
- else
- {
- target = "separator";
- }
+ target = g_object_get_data (G_OBJECT (widget), "name");
gtk_selection_data_set (selection_data,
selection_data->target, 8, target, strlen (target));
@@ -285,29 +271,44 @@ unset_drag_cursor (GtkWidget *widget)
}
static void
-set_item_drag_source (GtkWidget *item,
- GtkAction *action,
- gboolean is_separator)
+set_item_drag_source (EggToolbarsModel *model,
+ GtkWidget *item,
+ GtkAction *action,
+ gboolean is_separator,
+ const char *type)
{
+ GtkTargetEntry target_entry;
+ char *name;
+
+ target_entry.target = (char *)type;
+ target_entry.flags = GTK_TARGET_SAME_APP;
+ target_entry.info = 0;
+
gtk_drag_source_set (item, GDK_BUTTON1_MASK,
- source_drag_types, n_source_drag_types,
- GDK_ACTION_MOVE);
+ &target_entry, 1,
+ GDK_ACTION_MOVE);
if (is_separator)
{
GtkWidget *icon;
GdkPixbuf *pixbuf;
+ name = g_strdup ("separator");
+
icon = _egg_editable_toolbar_new_separator_image ();
pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (icon));
gtk_drag_source_set_icon_pixbuf (item, pixbuf);
}
else
{
+ const char *action_name;
const char *stock_id;
GValue value = { 0, };
GdkPixbuf *pixbuf;
+ action_name = gtk_action_get_name (action);
+ name = egg_toolbars_model_get_item_name (model, type, action_name);
+
g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (action), "stock_id", &value);
stock_id = g_value_get_string (&value);
@@ -328,11 +329,15 @@ set_item_drag_source (GtkWidget *item,
g_value_unset (&value);
}
+
+ g_object_set_data_full (G_OBJECT (item), "name",
+ name, g_free);
}
static GtkWidget *
create_item_from_action (EggEditableToolbar *t,
const char *action_name,
+ const char *type,
gboolean is_separator,
GtkAction **ret_action)
{
@@ -375,7 +380,8 @@ create_item_from_action (EggEditableToolbar *t,
{
set_drag_cursor (item);
gtk_widget_set_sensitive (item, TRUE);
- set_item_drag_source (item, action, is_separator);
+ set_item_drag_source (t->priv->model, item, action,
+ is_separator, type);
gtk_tool_item_set_use_drag_window (GTK_TOOL_ITEM (item), TRUE);
}
@@ -394,12 +400,13 @@ create_item (EggEditableToolbar *t,
int position,
GtkAction **ret_action)
{
- const char *action_name;
+ const char *action_name, *type;
gboolean is_separator;
- action_name = egg_toolbars_model_item_nth
- (model, toolbar_position, position, &is_separator);
- return create_item_from_action (t, action_name, is_separator, ret_action);
+ egg_toolbars_model_item_nth (model, toolbar_position, position,
+ &is_separator, &action_name, &type);
+ return create_item_from_action (t, action_name, type,
+ is_separator, ret_action);
}
static gboolean
@@ -449,7 +456,8 @@ drag_data_received_cb (GtkWidget *widget,
{
etoolbar->priv->pending = FALSE;
etoolbar->priv->dragged_item =
- create_item_from_action (etoolbar, id, data_is_separator (id), NULL);
+ create_item_from_action (etoolbar, id, type,
+ data_is_separator (id), NULL);
g_object_ref (etoolbar->priv->dragged_item);
gtk_object_sink (GTK_OBJECT (etoolbar->priv->dragged_item));
}
@@ -1134,13 +1142,12 @@ egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
for (l = 0; l < n_items; l++)
{
GtkToolItem *item;
- const char *action_name;
+ const char *action_name, *type;
gboolean is_separator;
GtkAction *action;
- action_name = egg_toolbars_model_item_nth
- (etoolbar->priv->model, i, l,
- &is_separator);
+ egg_toolbars_model_item_nth (etoolbar->priv->model, i, l,
+ &is_separator, &action_name, &type);
action = find_action (etoolbar, action_name);
item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
@@ -1150,7 +1157,8 @@ egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
{
set_drag_cursor (GTK_WIDGET (item));
gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
- set_item_drag_source (GTK_WIDGET (item), action, is_separator);
+ set_item_drag_source (etoolbar->priv->model, GTK_WIDGET (item),
+ action, is_separator, type);
}
else
{
diff --git a/lib/egg/egg-toolbar-editor.c b/lib/egg/egg-toolbar-editor.c
index 01d1b37c6..360cb50c6 100755
--- a/lib/egg/egg-toolbar-editor.c
+++ b/lib/egg/egg-toolbar-editor.c
@@ -649,7 +649,7 @@ model_has_action (EggToolbarsModel *model, GtkAction *action)
const char *action_name;
gboolean sep;
- name = egg_toolbars_model_item_nth (model, i, l, &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;
}
diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c
index 0da5cbd69..7535c7d66 100755
--- a/lib/egg/egg-toolbars-model.c
+++ b/lib/egg/egg-toolbars-model.c
@@ -632,27 +632,37 @@ egg_toolbars_model_n_items (EggToolbarsModel *t,
return g_node_n_children (toolbar);
}
-const char *
+void
egg_toolbars_model_item_nth (EggToolbarsModel *t,
int toolbar_position,
int position,
- gboolean *is_separator)
+ gboolean *is_separator,
+ const char **id,
+ const char **type)
{
GNode *toolbar;
GNode *item;
EggToolbarsItem *idata;
toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position);
- g_return_val_if_fail (toolbar != NULL, NULL);
+ g_return_if_fail (toolbar != NULL);
item = g_node_nth_child (toolbar, position);
- g_return_val_if_fail (item != NULL, NULL);
+ g_return_if_fail (item != NULL);
idata = item->data;
*is_separator = idata->separator;
- return idata->id;
+ if (id)
+ {
+ *id = idata->id;
+ }
+
+ if (type)
+ {
+ *type = idata->type;
+ }
}
int
diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h
index 1f5451585..c5fbfafc3 100755
--- a/lib/egg/egg-toolbars-model.h
+++ b/lib/egg/egg-toolbars-model.h
@@ -128,10 +128,12 @@ void egg_toolbars_model_remove_item (EggToolbarsModel *t,
int position);
int egg_toolbars_model_n_items (EggToolbarsModel *t,
int toolbar_position);
-const char *egg_toolbars_model_item_nth (EggToolbarsModel *t,
+void egg_toolbars_model_item_nth (EggToolbarsModel *t,
int toolbar_position,
int position,
- gboolean *is_separator);
+ gboolean *is_separator,
+ const char **id,
+ const char **type);
int egg_toolbars_model_n_toolbars (EggToolbarsModel *t);
const char *egg_toolbars_model_toolbar_nth (EggToolbarsModel *t,
int position);
diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c
index 180e9a4d4..92bc0e1ab 100755
--- a/src/ephy-toolbars-model.c
+++ b/src/ephy-toolbars-model.c
@@ -267,9 +267,8 @@ get_toolbar_and_item_pos (EphyToolbarsModel *model,
const char *i_name;
gboolean is_separator;
- i_name = egg_toolbars_model_item_nth
- (EGG_TOOLBARS_MODEL (model), t, i,
- &is_separator);
+ egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model),
+ t, i, &is_separator, &i_name, NULL);
g_return_val_if_fail (i_name != NULL, FALSE);
if (strcmp (i_name, action_name) == 0)
@@ -309,30 +308,6 @@ get_toolbar_pos (EphyToolbarsModel *model,
return -1;
}
-static gboolean
-impl_add_item (EggToolbarsModel *t,
- int toolbar_position,
- int position,
- const char *id,
- const char *type)
-{
- EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (t);
- gboolean is_bookmark;
-
- is_bookmark = strcmp (type, EPHY_DND_TOPIC_TYPE) == 0 ||
- strcmp (type, EPHY_DND_URL_TYPE) == 0;
-
- if (!is_bookmark || !get_toolbar_and_item_pos (model, id, NULL, NULL))
- {
- return EGG_TOOLBARS_MODEL_CLASS (parent_class)->add_item
- (t, toolbar_position, position, id, type);
- }
- else
- {
- return FALSE;
- }
-}
-
static void
connect_item (EphyToolbarsModel *model,
const char *name)
@@ -463,7 +438,6 @@ ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass)
object_class->set_property = ephy_toolbars_model_set_property;
object_class->get_property = ephy_toolbars_model_get_property;
- etm_class->add_item = impl_add_item;
etm_class->get_item_id = impl_get_item_id;
etm_class->get_item_name = impl_get_item_name;
etm_class->get_item_type = impl_get_item_type;
@@ -496,9 +470,8 @@ item_added (EphyToolbarsModel *model, int toolbar_position, int position)
const char *i_name;
gboolean is_separator;
- i_name = egg_toolbars_model_item_nth
- (EGG_TOOLBARS_MODEL (model), toolbar_position,
- position, &is_separator);
+ egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model), toolbar_position,
+ position, &is_separator, &i_name, NULL);
if (!is_separator)
{
connect_item (model, i_name);