aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2004-07-11 18:31:28 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2004-07-11 18:31:28 +0800
commitb341a4983b97e022d87e16590d5b7d8aa88c5374 (patch)
treeadc72d21c5fc21df52a0df1549a7b1acedae4df3
parent391cc13ee086c2af18e9ad75ad0c626d7e6a26e6 (diff)
downloadgsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar.gz
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar.bz2
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar.lz
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar.xz
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.tar.zst
gsoc2013-epiphany-b341a4983b97e022d87e16590d5b7d8aa88c5374.zip
Add api to move items.
2004-07-11 Marco Pesenti Gritti <marco@gnome.org> * lib/egg/egg-toolbars-model.c: (egg_toolbars_model_move_item): * lib/egg/egg-toolbars-model.h: Add api to move items. * src/bookmarks/ephy-bookmark-action.c: (get_item_position), (remove_from_model), (move_in_model), (move_left_activate_cb), (move_right_activate_cb), (show_context_menu): * src/bookmarks/ephy-topic-action.c: (get_item_position), (remove_from_model), (move_in_model), (move_left_activate_cb), (move_right_activate_cb), (show_context_menu): Add Move Left/Move Right context menus.
-rw-r--r--ChangeLog16
-rwxr-xr-xlib/egg/egg-toolbars-model.c31
-rwxr-xr-xlib/egg/egg-toolbars-model.h5
-rw-r--r--src/bookmarks/ephy-bookmark-action.c86
-rw-r--r--src/bookmarks/ephy-topic-action.c82
5 files changed, 202 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index e97488bb9..3e2a44548 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2004-07-11 Marco Pesenti Gritti <marco@gnome.org>
+ * lib/egg/egg-toolbars-model.c: (egg_toolbars_model_move_item):
+ * lib/egg/egg-toolbars-model.h:
+
+ Add api to move items.
+
+ * src/bookmarks/ephy-bookmark-action.c: (get_item_position),
+ (remove_from_model), (move_in_model), (move_left_activate_cb),
+ (move_right_activate_cb), (show_context_menu):
+ * src/bookmarks/ephy-topic-action.c: (get_item_position),
+ (remove_from_model), (move_in_model), (move_left_activate_cb),
+ (move_right_activate_cb), (show_context_menu):
+
+ Add Move Left/Move Right context menus.
+
+2004-07-11 Marco Pesenti Gritti <marco@gnome.org>
+
* src/bookmarks/ephy-bookmark-action.c: (drag_begin_cb),
(drag_end_cb), (connect_proxy):
* src/bookmarks/ephy-topic-action.c: (drag_begin_cb),
diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c
index f10dcc25b..e38d0f96d 100755
--- a/lib/egg/egg-toolbars-model.c
+++ b/lib/egg/egg-toolbars-model.c
@@ -668,6 +668,37 @@ egg_toolbars_model_remove_item (EggToolbarsModel *t,
toolbar_position, position);
}
+void
+egg_toolbars_model_move_item (EggToolbarsModel *t,
+ int toolbar_position,
+ int position,
+ int new_toolbar_position,
+ int new_position)
+{
+ GNode *node, *toolbar, *new_toolbar;
+
+ g_return_if_fail (EGG_IS_TOOLBARS_MODEL (t));
+
+ toolbar = g_node_nth_child (t->priv->toolbars, toolbar_position);
+ g_return_if_fail (toolbar != NULL);
+
+ new_toolbar = g_node_nth_child (t->priv->toolbars, new_toolbar_position);
+ g_return_if_fail (new_toolbar != NULL);
+
+ node = g_node_nth_child (toolbar, position);
+ g_return_if_fail (node != NULL);
+
+ g_node_unlink (node);
+
+ g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_REMOVED], 0,
+ toolbar_position, position);
+
+ g_node_insert (new_toolbar, new_position, node);
+
+ g_signal_emit (G_OBJECT (t), egg_toolbars_model_signals[ITEM_ADDED], 0,
+ new_toolbar_position, new_position);
+}
+
int
egg_toolbars_model_n_items (EggToolbarsModel *t,
int toolbar_position)
diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h
index 565b9ae01..9ac2f97a2 100755
--- a/lib/egg/egg-toolbars-model.h
+++ b/lib/egg/egg-toolbars-model.h
@@ -127,6 +127,11 @@ void egg_toolbars_model_remove_toolbar (EggToolbarsModel *t,
void egg_toolbars_model_remove_item (EggToolbarsModel *t,
int toolbar_position,
int position);
+void egg_toolbars_model_move_item (EggToolbarsModel *t,
+ int toolbar_position,
+ int position,
+ int new_toolbar_position,
+ int new_position);
int egg_toolbars_model_n_items (EggToolbarsModel *t,
int toolbar_position);
void egg_toolbars_model_item_nth (EggToolbarsModel *t,
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c
index 35b066a2d..40d6987d3 100644
--- a/src/bookmarks/ephy-bookmark-action.c
+++ b/src/bookmarks/ephy-bookmark-action.c
@@ -417,26 +417,60 @@ drag_data_get_cb (GtkWidget *widget, GdkDragContext *context,
address, strlen (address));
}
+static int
+get_item_position (GtkWidget *widget, gboolean *last)
+{
+ GtkWidget *item, *toolbar;
+ int index;
+
+ item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
+ g_return_val_if_fail (item != NULL, -1);
+
+ toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR);
+ g_return_val_if_fail (toolbar != NULL, -1);
+
+ index = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
+ GTK_TOOL_ITEM (item));
+ if (last)
+ {
+ int n_items;
+
+ n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
+ *last = (index == n_items - 1);
+ }
+
+ return index;
+}
+
static void
remove_from_model (GtkWidget *widget)
{
EphyBookmarks *bookmarks;
EggToolbarsModel *model;
- GtkWidget *item, *toolbar;
int pos;
- item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
- g_return_if_fail (item != NULL);
+ pos = get_item_position (widget, NULL);
- toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR);
- g_return_if_fail (toolbar != NULL);
+ bookmarks = ephy_shell_get_bookmarks (ephy_shell);
+ model = ephy_bookmarks_get_toolbars_model (bookmarks);
- pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (item));
+ egg_toolbars_model_remove_item (model, 0, pos);
+}
+
+static void
+move_in_model (GtkWidget *widget, int direction)
+{
+ EphyBookmarks *bookmarks;
+ EggToolbarsModel *model;
+ int pos, new_pos;
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
model = ephy_bookmarks_get_toolbars_model (bookmarks);
- egg_toolbars_model_remove_item (model, 0, pos);
+
+ pos = get_item_position (widget, NULL);
+ new_pos = MAX (0, pos + direction);
+
+ egg_toolbars_model_move_item (model, 0, pos, 0, new_pos);
}
static void
@@ -473,20 +507,33 @@ remove_activate_cb (GtkWidget *menu, GtkWidget *proxy)
}
static void
+move_left_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+{
+ move_in_model (proxy, -1);
+}
+
+static void
+move_right_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+{
+ move_in_model (proxy, +1);
+}
+
+static void
show_context_menu (EphyBookmarkAction *action, GtkWidget *proxy,
GtkMenuPositionFunc func)
{
GtkWidget *menu, *item;
+ gboolean last;
menu = gtk_menu_new ();
- item = gtk_menu_item_new_with_mnemonic (_("_Open in New Tab"));
+ item = gtk_menu_item_new_with_mnemonic (_("Open in New _Tab"));
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (item, "activate",
G_CALLBACK (open_in_tab_activate_cb), action);
- item = gtk_menu_item_new_with_mnemonic (_("_Open in New Window"));
+ item = gtk_menu_item_new_with_mnemonic (_("Open in New _Window"));
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
g_signal_connect (item, "activate",
@@ -502,6 +549,25 @@ show_context_menu (EphyBookmarkAction *action, GtkWidget *proxy,
g_signal_connect (item, "activate",
G_CALLBACK (remove_activate_cb), proxy);
+ item = gtk_separator_menu_item_new ();
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move _Left"));
+ gtk_widget_set_sensitive (item, get_item_position (proxy, NULL) > 0);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (move_left_activate_cb), proxy);
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move Ri_ght"));
+ get_item_position (proxy, &last);
+ gtk_widget_set_sensitive (item, !last);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (move_right_activate_cb), proxy);
+
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, func, proxy, 3,
gtk_get_current_event_time ());
}
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index d6231634c..80994db8f 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -361,26 +361,60 @@ open_in_tabs_activate_cb (GtkWidget *menu, EphyTopicAction *action)
g_list_free (uri_list);
}
+static int
+get_item_position (GtkWidget *widget, gboolean *last)
+{
+ GtkWidget *item, *toolbar;
+ int index;
+
+ item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
+ g_return_val_if_fail (item != NULL, -1);
+
+ toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR);
+ g_return_val_if_fail (toolbar != NULL, -1);
+
+ index = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
+ GTK_TOOL_ITEM (item));
+ if (last)
+ {
+ int n_items;
+
+ n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
+ *last = (index == n_items - 1);
+ }
+
+ return index;
+}
+
static void
remove_from_model (GtkWidget *widget)
{
EphyBookmarks *bookmarks;
EggToolbarsModel *model;
- GtkWidget *item, *toolbar;
int pos;
- item = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
- g_return_if_fail (item != NULL);
+ pos = get_item_position (widget, NULL);
- toolbar = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR);
- g_return_if_fail (toolbar != NULL);
+ bookmarks = ephy_shell_get_bookmarks (ephy_shell);
+ model = ephy_bookmarks_get_toolbars_model (bookmarks);
- pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolbar),
- GTK_TOOL_ITEM (item));
+ egg_toolbars_model_remove_item (model, 0, pos);
+}
+
+static void
+move_in_model (GtkWidget *widget, int direction)
+{
+ EphyBookmarks *bookmarks;
+ EggToolbarsModel *model;
+ int pos, new_pos;
bookmarks = ephy_shell_get_bookmarks (ephy_shell);
model = ephy_bookmarks_get_toolbars_model (bookmarks);
- egg_toolbars_model_remove_item (model, 0, pos);
+
+ pos = get_item_position (widget, NULL);
+ new_pos = MAX (0, pos + direction);
+
+ egg_toolbars_model_move_item (model, 0, pos, 0, new_pos);
}
static void
@@ -389,6 +423,18 @@ remove_activate_cb (GtkWidget *menu, GtkWidget *proxy)
remove_from_model (proxy);
}
+static void
+move_left_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+{
+ move_in_model (proxy, -1);
+}
+
+static void
+move_right_activate_cb (GtkWidget *menu, GtkWidget *proxy)
+{
+ move_in_model (proxy, +1);
+}
+
static GtkWidget *
add_open_in_tabs_menu (EphyTopicAction *action, GtkWidget *menu)
{
@@ -694,6 +740,7 @@ show_context_menu (EphyTopicAction *action, GtkWidget *proxy,
GtkMenuPositionFunc func)
{
GtkWidget *menu, *item;
+ gboolean last;
menu = gtk_menu_new ();
@@ -710,6 +757,25 @@ show_context_menu (EphyTopicAction *action, GtkWidget *proxy,
g_signal_connect (item, "activate",
G_CALLBACK (remove_activate_cb), proxy);
+ item = gtk_separator_menu_item_new ();
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move _Left"));
+ gtk_widget_set_sensitive (item, get_item_position (proxy, NULL) > 0);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (move_left_activate_cb), proxy);
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move Ri_ght"));
+ get_item_position (proxy, &last);
+ gtk_widget_set_sensitive (item, !last);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_signal_connect (item, "activate",
+ G_CALLBACK (move_right_activate_cb), proxy);
+
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, func, proxy, 3,
gtk_get_current_event_time ());
}