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;
}
Exemple #2
0
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);
}
Exemple #3
0
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");
}