From e5d335763657c0ebf4d464f4bc1d81542220141b Mon Sep 17 00:00:00 2001 From: David Bordoley Date: Sat, 17 May 2003 12:08:43 +0000 Subject: Marco Pesenti Gritti 2003-05-17 David Bordoley Marco Pesenti Gritti * data/ui/epiphany-ui.xml.in: * src/Makefile.am: * src/bookmarks/ephy-bookmark-action.c: (create_tool_item): * src/ephy-notebook.c: (ephy_notebook_class_init), (ephy_notebook_move_page), (move_tab), (notebook_drag_data_received_cb), (ephy_notebook_init), (ephy_notebook_set_page_status), (update_tabs_visibility), (ephy_notebook_insert_page), (ephy_notebook_remove_page), (ephy_notebook_set_page_title): * src/ephy-notebook.h: * src/ephy-tabs-menu.c: (ephy_tabs_menu_class_init), (ephy_tabs_menu_init), (ephy_tabs_menu_clean), (ephy_tabs_menu_finalize_impl), (ephy_tabs_menu_set_property), (ephy_tabs_menu_get_property), (ephy_tabs_menu_new), (ephy_tabs_menu_verb_cb), (ephy_tabs_menu_set_action_accelerator), (ephy_tabs_menu_rebuild), (ephy_tabs_menu_update): * src/ephy-tabs-menu.h: * src/ephy-window.c: (setup_window), (update_tabs_menu_sensitivity), (ephy_window_tabs_changed_cb), (setup_notebook), (ephy_window_init), (ephy_window_finalize), (ephy_window_update_control), (ephy_window_update_all_controls), (ephy_window_notebook_switch_page_cb): * src/ephy-window.h: * src/window-commands.c: (window_cmd_tabs_move_left), (window_cmd_tabs_move_right), (window_cmd_tabs_detach): Implement a list of tabs at the bottom of tabs menu. Add a changed signal to the notebook and use it to update list and sensitivity. --- src/Makefile.am | 2 + src/bookmarks/ephy-bookmark-action.c | 1 + src/ephy-notebook.c | 79 ++++---- src/ephy-notebook.h | 1 + src/ephy-tabs-menu.c | 340 +++++++++++++++++++++++++++++++++++ src/ephy-tabs-menu.h | 61 +++++++ src/ephy-window.c | 130 ++++++-------- src/ephy-window.h | 1 - src/window-commands.c | 11 +- 9 files changed, 514 insertions(+), 112 deletions(-) create mode 100644 src/ephy-tabs-menu.c create mode 100644 src/ephy-tabs-menu.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 285976850..291e55ecc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -68,6 +68,8 @@ epiphany_bin_SOURCES = \ ephy-spinner-action.h \ ephy-tab.c \ ephy-tab.h \ + ephy-tabs-menu.c \ + ephy-tabs-menu.h \ ephy-toolbars-model.c \ ephy-toolbars-model.h \ ephy-window.c \ diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index ebb8565f4..cd08ba66c 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -107,6 +107,7 @@ create_tool_item (EggAction *action) GtkWidget *entry; entry = gtk_entry_new (); + gtk_widget_set_size_request (entry, 120, -1); gtk_widget_show (entry); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); g_object_set_data (G_OBJECT (item), "entry", entry); diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c index 56ee692a9..b772af8f1 100644 --- a/src/ephy-notebook.c +++ b/src/ephy-notebook.c @@ -84,6 +84,7 @@ enum { TAB_DROPPED, TAB_DETACHED, + TABS_CHANGED, LAST_SIGNAL }; @@ -128,8 +129,7 @@ ephy_notebook_class_init (EphyNotebookClass *klass) g_signal_new ("tab_dropped", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EphyNotebookClass, - tab_dropped), + G_STRUCT_OFFSET (EphyNotebookClass, tab_dropped), NULL, NULL, ephy_marshal_VOID__OBJECT_OBJECT_INT, G_TYPE_NONE, @@ -141,8 +141,7 @@ ephy_notebook_class_init (EphyNotebookClass *klass) g_signal_new ("tab_detached", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EphyNotebookClass, - tab_detached), + G_STRUCT_OFFSET (EphyNotebookClass, tab_detached), NULL, NULL, ephy_marshal_VOID__INT_INT_INT, G_TYPE_NONE, @@ -150,7 +149,14 @@ ephy_notebook_class_init (EphyNotebookClass *klass) G_TYPE_INT, G_TYPE_INT, G_TYPE_INT); - + ephy_notebook_signals[TABS_CHANGED] = + g_signal_new ("tabs_changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyNotebookClass, tabs_changed), + NULL, NULL, + ephy_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static gboolean @@ -319,21 +325,29 @@ tab_label_size_request_cb (GtkWidget *window, void ephy_notebook_move_page (EphyNotebook *src, EphyNotebook *dest, - GtkWidget *src_page, gint dest_page) + GtkWidget *src_page, gint dest_page) { GtkWidget *tab_label; - tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (src), src_page); - - /* We don't want gtk to destroy tab and src_page behind our back */ - g_object_ref (G_OBJECT (src_page)); - g_object_ref (G_OBJECT (tab_label)); - ephy_notebook_remove_page (EPHY_NOTEBOOK (src), src_page); - ephy_notebook_insert_page (EPHY_NOTEBOOK (dest), src_page, - dest_page, TRUE); - gtk_notebook_set_tab_label (GTK_NOTEBOOK (dest), src_page, tab_label); - g_object_unref (G_OBJECT (src_page)); - g_object_unref (G_OBJECT (tab_label)); + if (dest == NULL || src == dest) + { + gtk_notebook_reorder_child (GTK_NOTEBOOK (src), src_page, dest_page); + g_signal_emit (G_OBJECT (src), ephy_notebook_signals[TABS_CHANGED], 0); + } + else + { + tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (src), src_page); + + /* We don't want gtk to destroy tab and src_page behind our back */ + g_object_ref (G_OBJECT (src_page)); + g_object_ref (G_OBJECT (tab_label)); + ephy_notebook_remove_page (EPHY_NOTEBOOK (src), src_page); + ephy_notebook_insert_page (EPHY_NOTEBOOK (dest), src_page, + dest_page, TRUE); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (dest), src_page, tab_label); + g_object_unref (G_OBJECT (src_page)); + g_object_unref (G_OBJECT (tab_label)); + } } @@ -385,8 +399,8 @@ move_tab (EphyNotebook *notebook, gint dest_page_num) GtkWidget *cur_page; cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num); - gtk_notebook_reorder_child (GTK_NOTEBOOK (notebook), cur_page, - dest_page_num); + ephy_notebook_move_page (EPHY_NOTEBOOK (notebook), NULL, cur_page, + dest_page_num); /* Reset the list of newly opened tabs when moving tabs. */ g_list_free (notebook->priv->opened_tabs); @@ -602,7 +616,7 @@ notebook_drag_data_received_cb (GtkWidget* widget, GdkDragContext *context, gchar *url = NULL; guint num = 0; gchar **tmp; - + g_signal_stop_emission_by_name (widget, "drag_data_received"); if (selection_data->length <= 0 || selection_data->data == NULL) return; @@ -651,11 +665,11 @@ notebook_drag_data_received_cb (GtkWidget* widget, GdkDragContext *context, * The first url is special: if the drag was to an * existing tab, load it there */ - ephy_embed_load_url (embed, url); + ephy_embed_load_url (embed, url); } else { - tab = ephy_shell_new_tab (ephy_shell, window, + tab = ephy_shell_new_tab (ephy_shell, window, tab, url, EPHY_NEW_TAB_IN_EXISTING_WINDOW | EPHY_NEW_TAB_APPEND_LAST | @@ -706,13 +720,13 @@ ephy_notebook_init (EphyNotebook *notebook) g_signal_connect_after (G_OBJECT (notebook), "switch_page", G_CALLBACK (ephy_notebook_switch_page_cb), NULL); - + /* Set up drag-and-drop target */ g_signal_connect (G_OBJECT(notebook), "drag_data_received", G_CALLBACK(notebook_drag_data_received_cb), NULL); gtk_drag_dest_set (GTK_WIDGET(notebook), GTK_DEST_DEFAULT_MOTION | - GTK_DEST_DEFAULT_DROP, + GTK_DEST_DEFAULT_DROP, url_drag_types,n_url_drag_types, GDK_ACTION_MOVE | GDK_ACTION_COPY); } @@ -756,7 +770,7 @@ ephy_notebook_set_page_status (EphyNotebook *nb, image = g_object_get_data (G_OBJECT (tab), "loading-image"); g_return_if_fail (image != NULL); - + icon = g_object_get_data (G_OBJECT (tab), "icon"); g_return_if_fail (icon != NULL); @@ -902,7 +916,7 @@ update_tabs_visibility (EphyNotebook *nb, gboolean before_inserting) if (before_inserting) tabs_num--; - show_tabs = eel_gconf_get_boolean (CONF_TABS_TABBED) || + show_tabs = eel_gconf_get_boolean (CONF_TABS_TABBED) || gtk_notebook_get_nth_page (GTK_NOTEBOOK (nb), tabs_num) > 0; gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), show_tabs); @@ -910,9 +924,9 @@ update_tabs_visibility (EphyNotebook *nb, gboolean before_inserting) void ephy_notebook_insert_page (EphyNotebook *nb, - GtkWidget *child, - int position, - gboolean jump_to) + GtkWidget *child, + int position, + gboolean jump_to) { GtkWidget *tab_hbox; @@ -949,7 +963,7 @@ ephy_notebook_insert_page (EphyNotebook *nb, /* Set up drag-and-drop target */ g_signal_connect (G_OBJECT(tab_hbox), "drag_data_received", G_CALLBACK(notebook_drag_data_received_cb), child); - gtk_drag_dest_set (tab_hbox, GTK_DEST_DEFAULT_ALL, + gtk_drag_dest_set (tab_hbox, GTK_DEST_DEFAULT_ALL, url_drag_types,n_url_drag_types, GDK_ACTION_MOVE | GDK_ACTION_COPY); @@ -960,6 +974,8 @@ ephy_notebook_insert_page (EphyNotebook *nb, g_object_set_data (G_OBJECT (child), "jump_to", GINT_TO_POINTER (jump_to)); } + + g_signal_emit (G_OBJECT (nb), ephy_notebook_signals[TABS_CHANGED], 0); } static void @@ -1028,6 +1044,7 @@ ephy_notebook_remove_page (EphyNotebook *nb, } gtk_notebook_remove_page (GTK_NOTEBOOK (nb), position); + g_signal_emit (G_OBJECT (nb), ephy_notebook_signals[TABS_CHANGED], 0); update_tabs_visibility (nb, FALSE); } @@ -1046,4 +1063,6 @@ ephy_notebook_set_page_title (EphyNotebook *nb, ebox = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label-ebox")); gtk_tooltips_set_tip (GTK_TOOLTIPS (nb->priv->title_tips), ebox, title, NULL); + + g_signal_emit (G_OBJECT (nb), ephy_notebook_signals[TABS_CHANGED], 0); } diff --git a/src/ephy-notebook.h b/src/ephy-notebook.h index e90aa56b9..9ce55f5b3 100644 --- a/src/ephy-notebook.h +++ b/src/ephy-notebook.h @@ -66,6 +66,7 @@ struct EphyNotebookClass void (* tab_detached) (EphyNotebook *dest, gint cur_page, gint root_x, gint root_y); + void (* tabs_changed) (EphyNotebook *nb); }; diff --git a/src/ephy-tabs-menu.c b/src/ephy-tabs-menu.c new file mode 100644 index 000000000..f8b697eb0 --- /dev/null +++ b/src/ephy-tabs-menu.c @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2003 David Bordoley + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "ephy-tabs-menu.h" +#include "ephy-gobject-misc.h" +#include "ephy-string.h" +#include "egg-menu-merge.h" +#include "ephy-marshal.h" +#include "ephy-shell.h" +#include "ephy-debug.h" + +#include +#include +#include + +#define MAX_LABEL_LENGTH 30 + +/** + * Private data + */ +struct _EphyTabsMenuPrivate +{ + EphyWindow *window; + EggActionGroup *action_group; + guint ui_id; +}; + +typedef struct +{ + EphyWindow *window; + EphyTab *tab; +} TabsData; + +/** + * Private functions, only availble from this file + */ +static void ephy_tabs_menu_class_init (EphyTabsMenuClass *klass); +static void ephy_tabs_menu_init (EphyTabsMenu *wrhm); +static void ephy_tabs_menu_finalize_impl (GObject *o); +static void ephy_tabs_menu_rebuild (EphyTabsMenu *wrhm); +static void ephy_tabs_menu_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void ephy_tabs_menu_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +enum +{ + PROP_0, + PROP_EPHY_WINDOW +}; + +static gpointer g_object_class; + +/** + * EphyTabsMenu object + */ +MAKE_GET_TYPE (ephy_tabs_menu, + "EphyTabsMenu", EphyTabsMenu, + ephy_tabs_menu_class_init, ephy_tabs_menu_init, + G_TYPE_OBJECT); + +static void +ephy_tabs_menu_class_init (EphyTabsMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + G_OBJECT_CLASS (klass)->finalize = ephy_tabs_menu_finalize_impl; + g_object_class = g_type_class_peek_parent (klass); + + object_class->set_property = ephy_tabs_menu_set_property; + object_class->get_property = ephy_tabs_menu_get_property; + + g_object_class_install_property (object_class, + PROP_EPHY_WINDOW, + g_param_spec_object ("EphyWindow", + "EphyWindow", + "Parent window", + EPHY_WINDOW_TYPE, + G_PARAM_READWRITE)); +} + +static void +ephy_tabs_menu_init (EphyTabsMenu *wrhm) +{ + EphyTabsMenuPrivate *p = g_new0 (EphyTabsMenuPrivate, 1); + wrhm->priv = p; + + wrhm->priv->ui_id = -1; + wrhm->priv->action_group = NULL; +} + +static void +ephy_tabs_menu_clean (EphyTabsMenu *wrhm) +{ + EphyTabsMenuPrivate *p = wrhm->priv; + EggMenuMerge *merge = EGG_MENU_MERGE (p->window->ui_merge); + + if (p->ui_id >= 0) + { + egg_menu_merge_remove_ui (merge, p->ui_id); + egg_menu_merge_ensure_update (merge); + } + + if (p->action_group != NULL) + { + egg_menu_merge_remove_action_group (merge, p->action_group); + g_object_unref (p->action_group); + } +} + +static void +ephy_tabs_menu_finalize_impl (GObject *o) +{ + EphyTabsMenu *wrhm = EPHY_TABS_MENU (o); + EphyTabsMenuPrivate *p = wrhm->priv; + + if (p->action_group != NULL) + { + egg_menu_merge_remove_action_group + (EGG_MENU_MERGE (p->window->ui_merge), + p->action_group); + g_object_unref (p->action_group); + } + + g_free (p); + + G_OBJECT_CLASS (g_object_class)->finalize (o); +} + +static void +ephy_tabs_menu_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyTabsMenu *m = EPHY_TABS_MENU (object); + + switch (prop_id) + { + case PROP_EPHY_WINDOW: + m->priv->window = g_value_get_object (value); + ephy_tabs_menu_rebuild (m); + break; + } +} + +static void +ephy_tabs_menu_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyTabsMenu *m = EPHY_TABS_MENU (object); + + switch (prop_id) + { + case PROP_EPHY_WINDOW: + g_value_set_object (value, m->priv->window); + break; + } +} + +EphyTabsMenu * +ephy_tabs_menu_new (EphyWindow *window) +{ + EphyTabsMenu *ret = g_object_new (EPHY_TYPE_TABS_MENU, + "EphyWindow", window, + NULL); + return ret; +} + +static void +ephy_tabs_menu_verb_cb (EggMenuMerge *merge, + TabsData *data) +{ + ephy_window_jump_to_tab (data->window, data->tab); +} + + +/* This code is from EggActionGroup: + * Ideally either EggAction should support setting an accelerator from + * a string or EggActionGroup would support adding single EggActionEntry's + * to an action group. + */ +static void +ephy_tabs_menu_set_action_accelerator (EggActionGroup *action_group, + EggAction *action, + int tab_number) +{ + gchar *accel_path; + gint accel_number; + + g_return_if_fail (tab_number >= 0); + + /* set the accel path for the menu item */ + accel_path = g_strconcat ("/", action_group->name, "/", action->name, NULL); + + /* Only the first ten tabs get accelerators starting from 1 through 0 */ + if (tab_number == 9) + { + accel_number = 0; + } + else + { + accel_number = (tab_number + 1); + } + + if (accel_number < 10) + { + guint accel_key = 0; + GdkModifierType accel_mods; + gchar* accelerator; + + accelerator = g_strdup_printf ("%d", accel_number); + + gtk_accelerator_parse (accelerator, &accel_key, + &accel_mods); + if (accel_key) + gtk_accel_map_add_entry (accel_path, accel_key, accel_mods); + + g_free (accelerator); + } + + action->accel_quark = g_quark_from_string (accel_path); + g_free (accel_path); +} + +static void +ephy_tabs_menu_rebuild (EphyTabsMenu *wrhm) +{ + EphyTabsMenuPrivate *p = wrhm->priv; + GString *xml; + gint i; + GList *tabs; + EggMenuMerge *merge = EGG_MENU_MERGE (p->window->ui_merge); + + LOG ("Rebuilding open tabs menu") + + ephy_tabs_menu_clean (wrhm); + + tabs = ephy_window_get_tabs (p->window); + + xml = g_string_new (NULL); + g_string_append (xml, "" + ""); + + p->action_group = egg_action_group_new ("TabsActions"); + egg_menu_merge_insert_action_group (merge, p->action_group, 0); + + for (i = 0; i < g_list_length (tabs); i++) + { + char *verb = g_strdup_printf ("TabsOpen%d", i); + char *title_s; + const char *title; + xmlChar *label_x; + EphyTab *child; + TabsData *data; + EggAction *action; + + child = g_list_nth_data (tabs, i); + + title = ephy_tab_get_title(child); + title_s = ephy_string_shorten (title, MAX_LABEL_LENGTH); + label_x = xmlEncodeSpecialChars (NULL, title_s); + + data = g_new0 (TabsData, 1); + data->window = wrhm->priv->window; + data->tab = child; + + action = g_object_new (EGG_TYPE_ACTION, + "name", verb, + "label", label_x, + "tooltip", "Hello", + "stock_id", NULL, + NULL); + + g_signal_connect_closure + (action, "activate", + g_cclosure_new (G_CALLBACK (ephy_tabs_menu_verb_cb), + data, + (GClosureNotify)g_free), + FALSE); + + ephy_tabs_menu_set_action_accelerator (p->action_group, action, i); + + egg_action_group_add_action (p->action_group, action); + g_object_unref (action); + + g_string_append (xml, "\n"); + + xmlFree (label_x); + g_free (title_s); + g_free (verb); + } + + g_string_append (xml, ""); + + if (g_list_length (tabs) > 0) + { + GError *error = NULL; + LOG ("Merging ui\n%s",xml->str); + p->ui_id = egg_menu_merge_add_ui_from_string + (merge, xml->str, -1, &error); + } + + g_string_free (xml, TRUE); +} + +void ephy_tabs_menu_update (EphyTabsMenu *wrhm) +{ + ephy_tabs_menu_rebuild (wrhm); +} diff --git a/src/ephy-tabs-menu.h b/src/ephy-tabs-menu.h new file mode 100644 index 000000000..a04329ef6 --- /dev/null +++ b/src/ephy-tabs-menu.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2003 David Bordoley + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef EPHY_TABS_MENU_H +#define EPHY_TABS_MENU_H + +#include "ephy-window.h" + +/* object forward declarations */ + +typedef struct _EphyTabsMenu EphyTabsMenu; +typedef struct _EphyTabsMenuClass EphyTabsMenuClass; +typedef struct _EphyTabsMenuPrivate EphyTabsMenuPrivate; + +/** + * Editor object + */ + +#define EPHY_TYPE_TABS_MENU (ephy_tabs_menu_get_type()) +#define EPHY_TABS_MENU(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_TABS_MENU, EphyTabsMenu)) +#define EPHY_TABS_MENU_CLASS(klass)(G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_TABS_MENU, EphyTabsMenuClass)) +#define EPHY_IS_TABS_MENU(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_TABS_MENU)) +#define EPHY_IS_TABS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_TABS_MENU)) +#define EPHY_TABS_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_TABS_MENU, EphyTabsMenuClass)) + +struct _EphyTabsMenuClass +{ + GObjectClass parent_class; +}; + +/* Remember: fields are public read-only */ +struct _EphyTabsMenu +{ + GObject parent_object; + + EphyTabsMenuPrivate *priv; +}; + +GType ephy_tabs_menu_get_type (void); + +EphyTabsMenu *ephy_tabs_menu_new (EphyWindow *window); + +void ephy_tabs_menu_update (EphyTabsMenu *wrhm); + +#endif + diff --git a/src/ephy-window.c b/src/ephy-window.c index e6e17c12b..6d98032e6 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -36,6 +36,7 @@ #include "toolbar.h" #include "popup-commands.h" #include "ephy-encoding-menu.h" +#include "ephy-tabs-menu.h" #include "ephy-stock-icons.h" #include @@ -261,6 +262,7 @@ struct EphyWindowPrivate EggActionGroup *popups_action_group; EphyFavoritesMenu *fav_menu; EphyEncodingMenu *enc_menu; + EphyTabsMenu *tabs_menu; PPViewToolbar *ppview_toolbar; GtkNotebook *notebook; EphyTab *active_tab; @@ -284,9 +286,8 @@ ephy_window_notebook_switch_page_cb (GtkNotebook *notebook, EphyWindow *window); static void -ephy_window_tab_detached_cb (EphyNotebook *notebook, gint page, - gint x, gint y, gpointer data); - +ephy_window_tab_detached_cb (EphyNotebook *notebook, gint page, + gint x, gint y, gpointer data); static GObjectClass *parent_class = NULL; @@ -330,34 +331,6 @@ ephy_window_class_init (EphyWindowClass *klass) widget_class->show = ephy_window_show; } -static gboolean -ephy_window_key_press_event_cb (GtkWidget *widget, - GdkEventKey *event, - EphyWindow *window) -{ - int page; - - if ((event->state & GDK_Shift_L) || (event->state & GDK_Shift_R)) - return FALSE; - - if ((event->state & GDK_Alt_L) || (event->state & GDK_Alt_R)) - { - page = event->keyval - GDK_0 -1; - - if (page == -1) page = 9; - - if (page>=-1 && page<=9) - { - gtk_notebook_set_current_page - (GTK_NOTEBOOK (window->priv->notebook), - page == -1 ? -1 : page); - return TRUE; - } - } - - return FALSE; -} - static void ephy_window_selection_received_cb (GtkWidget *widget, GtkSelectionData *selection_data, @@ -521,16 +494,52 @@ setup_window (EphyWindow *window) GTK_WIDGET (window->priv->toolbar), FALSE, FALSE, 0); - g_signal_connect(window, - "key-press-event", - G_CALLBACK(ephy_window_key_press_event_cb), - window); g_signal_connect (window, "selection-received", G_CALLBACK (ephy_window_selection_received_cb), window); } +static void +update_tabs_menu_sensitivity (EphyWindow *window) +{ + gboolean prev_tab, next_tab, move_left, move_right, detach; + EggActionGroup *action_group; + EggAction *action; + int current; + int last; + + current = gtk_notebook_get_current_page + (GTK_NOTEBOOK (window->priv->notebook)); + last = gtk_notebook_get_n_pages + (GTK_NOTEBOOK (window->priv->notebook)) - 1; + prev_tab = move_left = (current > 0); + next_tab = move_right = (current < last); + detach = gtk_notebook_get_n_pages + (GTK_NOTEBOOK (window->priv->notebook)) > 1; + + action_group = window->priv->action_group; + action = egg_action_group_get_action (action_group, "TabsPrevious"); + g_object_set (action, "sensitive", prev_tab, NULL); + action = egg_action_group_get_action (action_group, "TabsNext"); + g_object_set (action, "sensitive", next_tab, NULL); + action = egg_action_group_get_action (action_group, "TabsMoveLeft"); + g_object_set (action, "sensitive", move_left, NULL); + action = egg_action_group_get_action (action_group, "TabsMoveRight"); + g_object_set (action, "sensitive", move_right, NULL); + action = egg_action_group_get_action (action_group, "TabsDetach"); + g_object_set (action, "sensitive", detach, NULL); + + ephy_tabs_menu_update (window->priv->tabs_menu); +} + +static void +ephy_window_tabs_changed_cb (EphyNotebook *notebook, EphyWindow *window) +{ + update_tabs_menu_sensitivity (window); + ephy_tabs_menu_update (window->priv->tabs_menu); +} + static GtkNotebook * setup_notebook (EphyWindow *window) { @@ -549,6 +558,9 @@ setup_notebook (EphyWindow *window) g_signal_connect (G_OBJECT (notebook), "tab_detached", G_CALLBACK (ephy_window_tab_detached_cb), NULL); + g_signal_connect (G_OBJECT (notebook), "tabs_changed", + G_CALLBACK (ephy_window_tabs_changed_cb), + window); gtk_widget_show (GTK_WIDGET (notebook)); @@ -571,9 +583,6 @@ ephy_window_init (EphyWindow *window) /* Setup the window and connect verbs */ setup_window (window); - window->priv->fav_menu = ephy_favorites_menu_new (window); - window->priv->enc_menu = ephy_encoding_menu_new (window); - /* Setup window contents */ window->priv->notebook = setup_notebook (window); gtk_box_pack_start (GTK_BOX (window->priv->main_vbox), @@ -588,6 +597,11 @@ ephy_window_init (EphyWindow *window) g_object_ref (ephy_shell); + /* Initializ the menus */ + window->priv->tabs_menu = ephy_tabs_menu_new (window); + window->priv->fav_menu = ephy_favorites_menu_new (window); + window->priv->enc_menu = ephy_encoding_menu_new (window); + /* Once window is fully created, add it to the session list*/ session_add_window (session, window); } @@ -645,6 +659,7 @@ ephy_window_finalize (GObject *object) g_object_unref (window->priv->fav_menu); g_object_unref (window->priv->enc_menu); + g_object_unref (window->priv->tabs_menu); if (window->priv->ppview_toolbar) { @@ -1206,37 +1221,6 @@ update_find_control (EphyWindow *window) } } -static void -update_tabs (EphyWindow *window) -{ - gboolean prev_tab, next_tab, move_left, move_right, detach; - EggActionGroup *action_group; - EggAction *action; - int current; - int last; - - current = gtk_notebook_get_current_page - (GTK_NOTEBOOK (window->priv->notebook)); - last = gtk_notebook_get_n_pages - (GTK_NOTEBOOK (window->priv->notebook)) - 1; - prev_tab = move_left = (current > 0); - next_tab = move_right = (current < last); - detach = gtk_notebook_get_n_pages - (GTK_NOTEBOOK (window->priv->notebook)) > 1; - - action_group = window->priv->action_group; - action = egg_action_group_get_action (action_group, "TabsPrevious"); - g_object_set (action, "sensitive", prev_tab, NULL); - action = egg_action_group_get_action (action_group, "TabsNext"); - g_object_set (action, "sensitive", next_tab, NULL); - action = egg_action_group_get_action (action_group, "TabsMoveLeft"); - g_object_set (action, "sensitive", move_left, NULL); - action = egg_action_group_get_action (action_group, "TabsMoveRight"); - g_object_set (action, "sensitive", move_right, NULL); - action = egg_action_group_get_action (action_group, "TabsDetach"); - g_object_set (action, "sensitive", detach, NULL); -} - static void update_window_visibility (EphyWindow *window) { @@ -1292,9 +1276,6 @@ ephy_window_update_control (EphyWindow *window, switch (control) { - case TabsControl: - update_tabs (window); - break; case StatusbarMessageControl: update_status_message (window); break; @@ -1354,7 +1335,6 @@ ephy_window_update_all_controls (EphyWindow *window) update_security (window); update_find_control (window); update_spinner_control (window); - update_tabs (window); } } @@ -1461,6 +1441,7 @@ ephy_window_notebook_switch_page_cb (GtkNotebook *notebook, /* update window controls */ ephy_window_update_all_controls (window); + update_tabs_menu_sensitivity (window); } static void @@ -1525,7 +1506,7 @@ ephy_window_get_toolbar (EphyWindow *window) return window->priv->toolbar; } -void +static void ephy_window_tab_detached_cb (EphyNotebook *notebook, gint page, gint x, gint y, gpointer data) { @@ -1542,3 +1523,4 @@ ephy_window_tab_detached_cb (EphyNotebook *notebook, gint page, ephy_tab_set_window (tab, window); gtk_widget_show (GTK_WIDGET (window)); } + diff --git a/src/ephy-window.h b/src/ephy-window.h index 5a76383de..807ee5c96 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -62,7 +62,6 @@ typedef enum typedef enum { - TabsControl, NavControl, FindControl, ZoomControl, diff --git a/src/window-commands.c b/src/window-commands.c index 727429106..d42dca547 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -846,10 +846,8 @@ window_cmd_tabs_move_left (EggAction *action, GtkWidget *child; child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page); - gtk_notebook_reorder_child (GTK_NOTEBOOK (notebook), child, page - 1); + ephy_notebook_move_page (EPHY_NOTEBOOK (notebook), NULL, child, page - 1); } - - ephy_window_update_control (window, TabsControl); } void window_cmd_tabs_move_right (EggAction *action, @@ -868,10 +866,8 @@ void window_cmd_tabs_move_right (EggAction *action, GtkWidget *child; child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), page); - gtk_notebook_reorder_child (GTK_NOTEBOOK (notebook), child, page + 1); + ephy_notebook_move_page (EPHY_NOTEBOOK (notebook), NULL, child, page + 1); } - - ephy_window_update_control (window, TabsControl); } void @@ -882,7 +878,8 @@ window_cmd_tabs_detach (EggAction *action, GtkWidget *src_page; EphyWindow *new_win; - if (g_list_length (ephy_window_get_tabs (window)) <= 1) { + if (g_list_length (ephy_window_get_tabs (window)) <= 1) + { return; } -- cgit v1.2.3