static void ephy_notebook_remove (GtkContainer *container, GtkWidget *tab_widget) { GtkNotebook *gnotebook = GTK_NOTEBOOK (container); EphyNotebook *notebook = EPHY_NOTEBOOK (container); int position, curr; if (!EPHY_IS_EMBED (tab_widget)) return; /* Remove the page from the focused pages list */ notebook->focused_pages = g_list_remove (notebook->focused_pages, tab_widget); position = gtk_notebook_page_num (gnotebook, tab_widget); curr = gtk_notebook_get_current_page (gnotebook); if (position == curr) { smart_tab_switching_on_closure (notebook, tab_widget); } GTK_CONTAINER_CLASS (ephy_notebook_parent_class)->remove (container, tab_widget); update_tabs_visibility (notebook, FALSE); }
static void ephy_notebook_constructed (GObject *object) { EphyNotebook *notebook = EPHY_NOTEBOOK (object); GtkWidget *hbox; GtkWidget *button; EphyPagesPopover *popover; G_OBJECT_CLASS (ephy_notebook_parent_class)->constructed (object); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), hbox, GTK_PACK_END); gtk_widget_show (hbox); button = gtk_menu_button_new (); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); /* Translators: tooltip for the tab switcher menu button */ gtk_widget_set_tooltip_text (button, _("View open tabs")); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); gtk_widget_show (button); notebook->tab_menu = g_menu_new (); /* Remove this when popover menus become scrollable. */ gtk_menu_button_set_use_popover (GTK_MENU_BUTTON (button), TRUE); popover = ephy_pages_popover_new (GTK_WIDGET (button)); ephy_pages_popover_set_notebook (popover, notebook); gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), GTK_WIDGET (popover)); }
/* FIXME remove when gtknotebook's func for this becomes public, bug #.... */ static EphyNotebook * find_notebook_at_pointer (gint abs_x, gint abs_y) { GdkWindow *win_at_pointer, *toplevel_win; gpointer toplevel = NULL; gint x, y; /* FIXME multi-head */ win_at_pointer = gdk_window_at_pointer (&x, &y); if (win_at_pointer == NULL) { /* We are outside all windows containing a notebook */ return NULL; } toplevel_win = gdk_window_get_toplevel (win_at_pointer); /* get the GtkWidget which owns the toplevel GdkWindow */ gdk_window_get_user_data (toplevel_win, &toplevel); /* toplevel should be an EphyWindow */ if (toplevel != NULL && EPHY_IS_WINDOW (toplevel)) { return EPHY_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (toplevel))); } return NULL; }
static gboolean button_press_event_cb (GtkWidget *widget, GdkEventButton *event, EphyWindow *window) { gint tab_number; EphyEmbed *embed; if (event->button != 2 || event->type != GDK_BUTTON_PRESS) return FALSE; /* I wish this wasn't so gash and copy-pasty... Connecting * to button-press-event on the tab doesn't ever get called.*/ tab_number = find_tab_num_at_pos (EPHY_NOTEBOOK (widget), event->x_root, event->y_root); if (tab_number < 0) return FALSE; embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (widget), tab_number)); if (embed == NULL) return FALSE; ephy_embed_container_remove_child (EPHY_EMBED_CONTAINER (window), embed); return TRUE; }
static void ephy_notebook_page_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num) { if (GTK_NOTEBOOK_CLASS (ephy_notebook_parent_class)->page_reordered != NULL) GTK_NOTEBOOK_CLASS (ephy_notebook_parent_class)->page_reordered (notebook, child, page_num); ephy_notebook_rebuild_tab_menu (EPHY_NOTEBOOK (notebook)); }
static void ephy_notebook_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { EphyNotebook *notebook = EPHY_NOTEBOOK (object); switch (prop_id) { case PROP_TABS_ALLOWED: ephy_notebook_set_tabs_allowed (notebook, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
static void notebook_page_removed_cb (GtkWidget *notebook, EphyEmbed *embed, guint position, EphySession *session) { ephy_session_save (session, SESSION_STATE); #ifdef HAVE_WEBKIT2 g_signal_handlers_disconnect_by_func (ephy_embed_get_web_view (embed), G_CALLBACK (load_changed_cb), session); #else g_signal_handlers_disconnect_by_func (ephy_embed_get_web_view (embed), G_CALLBACK (load_status_notify_cb), session); #endif ephy_session_tab_closed (session, EPHY_NOTEBOOK (notebook), embed, position); }
static void ephy_notebook_finalize (GObject *object) { EphyNotebook *notebook = EPHY_NOTEBOOK (object); g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_UI, expand_tabs_changed_cb, notebook); g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_UI, position_changed_cb, notebook); g_signal_handlers_disconnect_by_func (EPHY_SETTINGS_UI, show_tabs_changed_cb, notebook); g_list_free (notebook->focused_pages); G_OBJECT_CLASS (ephy_notebook_parent_class)->finalize (object); }
static void ephy_notebook_switch_page_cb (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) { EphyNotebook *nb = EPHY_NOTEBOOK (notebook); GtkWidget *child; child = gtk_notebook_get_nth_page (notebook, page_num); if (!ephy_web_view_is_in_auth_dialog (ephy_embed_get_web_view (EPHY_EMBED (child)))) gtk_widget_grab_focus (child); /* Remove the old page, we dont want to grow unnecessarily * the list */ if (nb->focused_pages) { nb->focused_pages = g_list_remove (nb->focused_pages, child); } nb->focused_pages = g_list_append (nb->focused_pages, child); }
static int ephy_notebook_insert_page (GtkNotebook *gnotebook, GtkWidget *tab_widget, GtkWidget *tab_label, GtkWidget *menu_label, int position) { EphyNotebook *notebook = EPHY_NOTEBOOK (gnotebook); /* Destroy passed-in tab label */ if (tab_label != NULL) { g_object_ref_sink (tab_label); g_object_unref (tab_label); } g_assert (EPHY_IS_EMBED (tab_widget)); tab_label = build_tab_label (notebook, EPHY_EMBED (tab_widget)); update_tabs_visibility (notebook, TRUE); position = GTK_NOTEBOOK_CLASS (ephy_notebook_parent_class)->insert_page (gnotebook, tab_widget, tab_label, menu_label, position); gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE); gtk_notebook_set_tab_detachable (gnotebook, tab_widget, TRUE); gtk_container_child_set (GTK_CONTAINER (gnotebook), GTK_WIDGET (tab_widget), "tab-expand", g_settings_get_boolean (EPHY_SETTINGS_UI, EPHY_PREFS_UI_EXPAND_TABS_BAR), NULL); return position; }
void ephy_session_undo_close_tab (EphySession *session) { EphySessionPrivate *priv; EphyEmbed *embed, *new_tab; ClosedTab *tab; #ifndef HAVE_WEBKIT2 WebKitWebBackForwardList *dest; GList *i; #endif EphyNewTabFlags flags = EPHY_NEW_TAB_OPEN_PAGE | EPHY_NEW_TAB_PRESENT_WINDOW | EPHY_NEW_TAB_JUMP | EPHY_NEW_TAB_DONT_COPY_HISTORY; g_return_if_fail (EPHY_IS_SESSION (session)); priv = session->priv; tab = g_queue_pop_head (priv->closed_tabs); if (tab == NULL) return; LOG ("UNDO CLOSE TAB: %s", tab->url); if (*tab->parent_location != NULL) { GtkWidget *window; flags |= EPHY_NEW_TAB_IN_EXISTING_WINDOW; if (tab->position > 0) { /* Append in the n-th position. */ embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (*tab->parent_location), tab->position - 1)); flags |= EPHY_NEW_TAB_APPEND_AFTER; } else { /* Just prepend in the first position. */ embed = NULL; flags |= EPHY_NEW_TAB_FIRST; } window = gtk_widget_get_toplevel (GTK_WIDGET (*tab->parent_location)); new_tab = ephy_shell_new_tab (ephy_shell_get_default (), EPHY_WINDOW (window), embed, tab->url, flags); post_restore_cleanup (priv->closed_tabs, tab, FALSE); } else { EphyNotebook *notebook; flags |= EPHY_NEW_TAB_IN_NEW_WINDOW; new_tab = ephy_shell_new_tab (ephy_shell_get_default (), NULL, NULL, tab->url, flags); /* FIXME: This makes the assumption that the notebook is the parent of the returned EphyEmbed. */ notebook = EPHY_NOTEBOOK (gtk_widget_get_parent (GTK_WIDGET (new_tab))); *tab->parent_location = notebook; post_restore_cleanup (priv->closed_tabs, tab, TRUE); } /* This is deficient: we need to recreate the whole * BackForward list. Also, WebKit2 doesn't have this API. */ #ifndef HAVE_WEBKIT2 dest = webkit_web_view_get_back_forward_list (EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (new_tab)); for (i = tab->bflist; i; i = i->next) { LOG ("ADDING TO BF: %s", webkit_web_history_item_get_title ((WebKitWebHistoryItem*) i->data)); webkit_web_back_forward_list_add_item (dest, webkit_web_history_item_copy ((WebKitWebHistoryItem*) i->data)); } #endif closed_tab_free (tab); if (g_queue_is_empty (priv->closed_tabs)) g_object_notify (G_OBJECT (session), "can-undo-tab-closed"); }