[epiphany/wip/exalm/tabs: 23/37] tmp
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/tabs: 23/37] tmp
- Date: Sun, 13 Sep 2020 00:04:33 +0000 (UTC)
commit f7e7a509678cb898341630ad686d3d79a1404564
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sat Sep 5 19:48:25 2020 +0500
tmp
org.gnome.Epiphany.json | 3 +-
src/ephy-action-bar.c | 26 +-
src/ephy-action-bar.h | 3 -
src/ephy-header-bar.c | 1 -
src/ephy-location-controller.c | 35 +-
src/ephy-lockdown.c | 11 -
src/ephy-notebook.c | 1164 ----------------------------------------
src/ephy-notebook.h | 60 ---
src/ephy-page-row.c | 28 +-
src/ephy-page-row.h | 8 +-
src/ephy-pages-popover.c | 274 ----------
src/ephy-pages-popover.h | 41 --
src/ephy-pages-view.c | 170 +++---
src/ephy-pages-view.h | 8 +-
src/ephy-session.c | 175 +++---
src/ephy-shell.c | 11 +-
src/ephy-suggestion-model.c | 15 +-
src/ephy-tab-view.c | 438 +++++++++++++++
src/ephy-tab-view.h | 77 +++
src/ephy-window.c | 446 +++++++--------
src/ephy-window.h | 3 +-
src/meson.build | 3 +-
src/window-commands.c | 248 +--------
src/window-commands.h | 15 -
24 files changed, 955 insertions(+), 2308 deletions(-)
---
diff --git a/org.gnome.Epiphany.json b/org.gnome.Epiphany.json
index 3418351a6..3ee5d0f07 100644
--- a/org.gnome.Epiphany.json
+++ b/org.gnome.Epiphany.json
@@ -43,7 +43,8 @@
"sources" : [
{
"type" : "git",
- "url" : "https://gitlab.gnome.org/GNOME/libhandy.git"
+ "url" : "https://gitlab.gnome.org/exalm/libhandy.git",
+ "branch" : "tabs"
}
]
},
diff --git a/src/ephy-action-bar.c b/src/ephy-action-bar.c
index c28ce6bac..ddda1fe71 100644
--- a/src/ephy-action-bar.c
+++ b/src/ephy-action-bar.c
@@ -21,9 +21,9 @@
#include "ephy-action-bar.h"
#include "ephy-pages-button.h"
-#include "ephy-pages-popover.h"
#include "ephy-settings.h"
#include "ephy-shell.h"
+#include "ephy-tab-view.h"
enum {
PROP_0,
@@ -40,7 +40,6 @@ struct _EphyActionBar {
EphyActionBarStart *action_bar_start;
EphyActionBarEnd *action_bar_end;
EphyPagesButton *pages_button;
- GtkNotebook *notebook;
};
G_DEFINE_TYPE (EphyActionBar, ephy_action_bar, GTK_TYPE_REVEALER)
@@ -58,15 +57,6 @@ sync_chromes_visibility (EphyActionBar *action_bar)
chrome & EPHY_WINDOW_CHROME_BOOKMARKS);
}
-static void
-update_pages_button (EphyActionBar *action_bar)
-{
- int n_pages;
-
- n_pages = gtk_notebook_get_n_pages (action_bar->notebook);
- ephy_pages_button_set_n_pages (action_bar->pages_button, n_pages);
-}
-
static void
ephy_action_bar_set_property (GObject *object,
guint property_id,
@@ -125,24 +115,22 @@ static void
ephy_action_bar_constructed (GObject *object)
{
EphyActionBar *action_bar = EPHY_ACTION_BAR (object);
+ EphyTabView *view;
G_OBJECT_CLASS (ephy_action_bar_parent_class)->constructed (object);
- action_bar->notebook = GTK_NOTEBOOK (ephy_window_get_notebook (action_bar->window));
- update_pages_button (action_bar);
+ view = ephy_window_get_tab_view (action_bar->window);
g_signal_connect_object (action_bar->window, "notify::chrome",
G_CALLBACK (sync_chromes_visibility), action_bar,
G_CONNECT_SWAPPED);
- g_signal_connect_object (action_bar->notebook, "page-added",
- G_CALLBACK (update_pages_button), action_bar,
- G_CONNECT_SWAPPED);
- g_signal_connect_object (action_bar->notebook, "page-removed",
- G_CALLBACK (update_pages_button), action_bar,
- G_CONNECT_SWAPPED);
g_signal_connect_object (DZL_APPLICATION_WINDOW (action_bar->window), "notify::titlebar-animation",
G_CALLBACK (titlebar_animation_changed), action_bar,
G_CONNECT_SWAPPED);
+
+ g_object_bind_property (view, "n-pages",
+ action_bar->pages_button, "n-pages",
+ G_BINDING_SYNC_CREATE);
}
static void
diff --git a/src/ephy-action-bar.h b/src/ephy-action-bar.h
index da94137af..390e92007 100644
--- a/src/ephy-action-bar.h
+++ b/src/ephy-action-bar.h
@@ -26,7 +26,6 @@
#include "ephy-action-bar-end.h"
#include "ephy-action-bar-start.h"
#include "ephy-adaptive-mode.h"
-#include "ephy-notebook.h"
#include "ephy-window.h"
G_BEGIN_DECLS
@@ -38,8 +37,6 @@ G_DECLARE_FINAL_TYPE (EphyActionBar, ephy_action_bar, EPHY, ACTION_BAR, GtkRevea
EphyActionBar *ephy_action_bar_new (EphyWindow *window);
EphyActionBarStart *ephy_action_bar_get_action_bar_start (EphyActionBar *action_bar);
EphyActionBarEnd *ephy_action_bar_get_action_bar_end (EphyActionBar *action_bar);
-void ephy_action_bar_set_notebook (EphyActionBar *action_bar,
- EphyNotebook *notebook);
void ephy_action_bar_set_adaptive_mode (EphyActionBar *action_bar,
EphyAdaptiveMode adaptive_mode);
diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c
index 8a5f2e661..efb58959f 100644
--- a/src/ephy-header-bar.c
+++ b/src/ephy-header-bar.c
@@ -29,7 +29,6 @@
#include "ephy-file-helpers.h"
#include "ephy-flatpak-utils.h"
#include "ephy-location-entry.h"
-#include "ephy-notebook.h"
#include "ephy-settings.h"
#include "ephy-shell.h"
#include "ephy-title-box.h"
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index 01175c445..f9eaa6b1d 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -147,15 +147,14 @@ entry_activate_cb (GtkEntry *entry,
return;
if (g_str_has_prefix (content, "ephy-tab://")) {
- GtkWidget *notebook = ephy_window_get_notebook (controller->window);
+ EphyTabView *tab_view = ephy_window_get_tab_view (controller->window);
GtkWidget *tab;
EphyWebView *webview;
- gint current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
g_auto (GStrv) split = g_strsplit (content + strlen ("ephy-tab://"), "@", -1);
g_assert (g_strv_length (split) == 2);
- tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), current);
+ tab = ephy_tab_view_get_selected_page (tab_view);
webview = ephy_embed_get_web_view (EPHY_EMBED (tab));
if (atoi (split[1]) != 0) {
@@ -169,15 +168,15 @@ entry_activate_cb (GtkEntry *entry,
windows = gtk_application_get_windows (GTK_APPLICATION (application));
window = g_list_nth_data (windows, atoi (split[1]));
- notebook = ephy_window_get_notebook (window);
+ tab_view = ephy_window_get_tab_view (window);
gtk_window_present (GTK_WINDOW (window));
}
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), atoi (split[0]));
+ ephy_tab_view_select_nth_page (tab_view, atoi (split[0]));
if (ephy_web_view_is_overview (webview))
- g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", tab);
+ ephy_tab_view_close (tab_view, tab);
return;
}
@@ -295,10 +294,7 @@ focus_out_event_cb (GtkWidget *entry,
}
static void
-switch_page_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint page_num,
- EphyLocationController *controller)
+notify_selected_index_cb (EphyLocationController *controller)
{
if (controller->sync_address_is_blocked == TRUE) {
controller->sync_address_is_blocked = FALSE;
@@ -343,15 +339,17 @@ ephy_location_controller_constructed (GObject *object)
EphyHistoryService *history_service;
EphyBookmarksManager *bookmarks_manager;
EphySuggestionModel *model;
- GtkWidget *notebook, *widget, *reader_mode, *entry;
+ EphyTabView *tab_view;
+ GtkWidget *widget, *reader_mode, *entry;
G_OBJECT_CLASS (ephy_location_controller_parent_class)->constructed (object);
- notebook = ephy_window_get_notebook (controller->window);
+ tab_view = ephy_window_get_tab_view (controller->window);
widget = GTK_WIDGET (controller->title_widget);
- g_signal_connect (notebook, "switch-page",
- G_CALLBACK (switch_page_cb), controller);
+ g_signal_connect_object (tab_view, "notify::selected-index",
+ G_CALLBACK (notify_selected_index_cb), controller,
+ G_CONNECT_SWAPPED);
sync_address (controller, NULL, widget);
g_signal_connect_object (controller, "notify::address",
@@ -446,14 +444,9 @@ static void
ephy_location_controller_dispose (GObject *object)
{
EphyLocationController *controller = EPHY_LOCATION_CONTROLLER (object);
- GtkWidget *notebook;
- notebook = ephy_window_get_notebook (controller->window);
-
- if (notebook == NULL ||
- controller->title_widget == NULL) {
+ if (controller->title_widget == NULL)
return;
- }
g_clear_object (&controller->longpress_gesture);
@@ -463,8 +456,6 @@ ephy_location_controller_dispose (GObject *object)
g_signal_handlers_disconnect_matched (controller->title_widget, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, controller);
}
- g_signal_handlers_disconnect_matched (notebook, G_SIGNAL_MATCH_DATA,
- 0, 0, NULL, NULL, controller);
controller->title_widget = NULL;
G_OBJECT_CLASS (ephy_location_controller_parent_class)->dispose (object);
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index 43f311386..19d35af5f 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -111,10 +111,6 @@ static const BindAction popup_actions[] = {
{ EPHY_PREFS_LOCKDOWN_FULLSCREEN, "open-link-in-new-window", "enabled" }
};
-static const BindAction tab_actions[] = {
- { EPHY_PREFS_LOCKDOWN_FULLSCREEN, "detach", "enabled" }
-};
-
static const BindAction toolbar_actions[] = {
{ EPHY_PREFS_LOCKDOWN_HISTORY, "navigation-back", "enabled" },
{ EPHY_PREFS_LOCKDOWN_HISTORY, "navigation-forward", "enabled" }
@@ -226,13 +222,6 @@ window_added_cb (GtkApplication *application,
window_actions,
G_N_ELEMENTS (window_actions));
- action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
- "tab");
- bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
- action_group,
- tab_actions,
- G_N_ELEMENTS (tab_actions));
-
action_group = gtk_widget_get_action_group (GTK_WIDGET (window),
"toolbar");
bind_settings_and_actions (EPHY_SETTINGS_LOCKDOWN,
diff --git a/src/ephy-page-row.c b/src/ephy-page-row.c
index adacca81a..299b1b68c 100644
--- a/src/ephy-page-row.c
+++ b/src/ephy-page-row.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "ephy-desktop-utils.h"
+#include "ephy-embed.h"
#include "ephy-embed-utils.h"
#include "ephy-page-row.h"
#include "ephy-web-view.h"
@@ -42,6 +43,8 @@ struct _EphyPageRow {
GtkSpinner *spinner;
GtkLabel *title;
GtkButton *close_button;
+
+ HdyTabPage *page;
};
static guint signals[LAST_SIGNAL];
@@ -157,23 +160,22 @@ sync_favicon (EphyWebView *view,
}
EphyPageRow *
-ephy_page_row_new (EphyNotebook *notebook,
- gint position)
+ephy_page_row_new (HdyTabPage *page)
{
EphyPageRow *self;
GtkWidget *embed;
- GtkWidget *tab_label;
- EphyWebView *view;
+// GtkWidget *tab_label;
+// EphyWebView *view;
- g_assert (notebook != NULL);
- g_assert (position >= 0);
+ g_assert (HDY_IS_TAB_PAGE (page));
self = g_object_new (EPHY_TYPE_PAGE_ROW, NULL);
+ self->page = page;
- embed = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), position);
+ embed = hdy_tab_page_get_content (page);
g_assert (EPHY_IS_EMBED (embed));
-
+/*
tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), embed);
view = ephy_embed_get_web_view (EPHY_EMBED (embed));
@@ -186,7 +188,7 @@ ephy_page_row_new (EphyNotebook *notebook,
sync_load_status (view, NULL, self);
g_signal_connect_object (view, "load-changed",
G_CALLBACK (load_changed_cb), self, 0);
-
+*/
return self;
}
@@ -221,3 +223,11 @@ ephy_page_row_set_adaptive_mode (EphyPageRow *self,
break;
}
}
+
+HdyTabPage *
+ephy_page_row_get_page (EphyPageRow *self)
+{
+ g_assert (EPHY_IS_PAGE_ROW (self));
+
+ return self->page;
+}
diff --git a/src/ephy-page-row.h b/src/ephy-page-row.h
index 337a7ba92..53fd3a1cb 100644
--- a/src/ephy-page-row.h
+++ b/src/ephy-page-row.h
@@ -21,9 +21,8 @@
#pragma once
-#include <gtk/gtk.h>
+#include <handy.h>
#include "ephy-adaptive-mode.h"
-#include "ephy-notebook.h"
G_BEGIN_DECLS
@@ -31,10 +30,11 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EphyPageRow, ephy_page_row, EPHY, PAGE_ROW, GtkListBoxRow)
-EphyPageRow *ephy_page_row_new (EphyNotebook *notebook,
- int position);
+EphyPageRow *ephy_page_row_new (HdyTabPage *page);
void ephy_page_row_set_adaptive_mode (EphyPageRow *self,
EphyAdaptiveMode adaptive_mode);
+HdyTabPage *ephy_page_row_get_page (EphyPageRow *self);
+
G_END_DECLS
diff --git a/src/ephy-pages-view.c b/src/ephy-pages-view.c
index 13485f816..53200cedd 100644
--- a/src/ephy-pages-view.c
+++ b/src/ephy-pages-view.c
@@ -24,7 +24,6 @@
#include "ephy-pages-view.h"
-#include "ephy-notebook.h"
#include "ephy-page-row.h"
#include "ephy-window.h"
@@ -33,127 +32,86 @@ struct _EphyPagesView {
GtkListBox *list_box;
- GListStore *list_store;
- EphyNotebook *notebook;
+ GListModel *model;
+ EphyTabView *tab_view;
EphyAdaptiveMode adaptive_mode;
};
G_DEFINE_TYPE (EphyPagesView, ephy_pages_view, GTK_TYPE_SCROLLED_WINDOW)
static void
-drop_notebook (EphyPagesView *self)
+drop_tab_view (EphyPagesView *self)
{
- self->notebook = NULL;
- g_list_store_remove_all (self->list_store);
+ self->tab_view = NULL;
}
static void
-release_notebook (EphyPagesView *self)
+release_tab_view (EphyPagesView *self)
{
- if (self->notebook) {
- g_object_weak_unref (G_OBJECT (self->notebook), (GWeakNotify)drop_notebook, self);
- drop_notebook (self);
+ if (self->tab_view) {
+ g_object_weak_unref (G_OBJECT (self->tab_view), (GWeakNotify)drop_tab_view, self);
+ drop_tab_view (self);
}
}
-static GtkWidget *
-create_row (gpointer item,
- gpointer user_data)
-{
- return GTK_WIDGET (g_object_ref (G_OBJECT (item)));
-}
-
-static void
-row_activated_cb (EphyPagesView *self,
- GtkListBoxRow *row)
-{
- gint new_page;
- EphyWindow *window;
- GApplication *application;
-
- g_assert (EPHY_IS_PAGES_VIEW (self));
- g_assert (!row || GTK_IS_LIST_BOX_ROW (row));
-
- application = g_application_get_default ();
- window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
-
- if (!row)
- return;
-
- new_page = gtk_list_box_row_get_index (row);
-
- gtk_notebook_set_current_page (GTK_NOTEBOOK (self->notebook), new_page);
- ephy_window_close_pages_view (window);
-}
-
static void
row_closed_cb (EphyPagesView *self,
EphyPageRow *row)
{
- GtkWindow *window;
- GtkWidget *embed;
- EphyEmbedShell *shell;
+ HdyTabPage *page;
g_assert (EPHY_IS_PAGES_VIEW (self));
g_assert (EPHY_IS_PAGE_ROW (row));
- shell = ephy_embed_shell_get_default ();
- window = gtk_application_get_active_window (GTK_APPLICATION (shell));
+ page = ephy_page_row_get_page (row);
- embed = gtk_notebook_get_nth_page (GTK_NOTEBOOK (self->notebook),
- gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (row)));
- g_signal_emit_by_name (self->notebook,
- "tab-close-request",
- embed, window);
+ hdy_tab_view_close_page (ephy_tab_view_get_tab_view (self->tab_view), page);
}
-
static void
-current_page_changed (EphyPagesView *self)
+row_activated_cb (EphyPagesView *self,
+ EphyPageRow *row)
{
- GtkListBoxRow *current_row, *new_row;
- gint current_page;
+ EphyWindow *window;
+ GApplication *application;
+ HdyTabPage *page;
g_assert (EPHY_IS_PAGES_VIEW (self));
+ g_assert (EPHY_IS_PAGE_ROW (row));
- current_row = gtk_list_box_get_selected_row (self->list_box);
- current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (self->notebook));
- if (current_row && gtk_list_box_row_get_index (current_row) == current_page)
- return;
+ application = g_application_get_default ();
+ window = EPHY_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (application)));
+ page = ephy_page_row_get_page (EPHY_PAGE_ROW (row));
- new_row = gtk_list_box_get_row_at_index (self->list_box, current_page);
- gtk_list_box_select_row (self->list_box, new_row);
+ hdy_tab_view_set_selected_page (ephy_tab_view_get_tab_view (self->tab_view), page);
+ ephy_window_close_pages_view (window);
}
-static void
-items_changed_cb (EphyPagesView *self,
- gint position,
- gint removed,
- gint added,
- GMenuModel *menu_model)
+static GtkWidget *
+create_row (HdyTabPage *page,
+ EphyPagesView *self)
{
- g_autofree EphyPageRow **items = g_new (EphyPageRow *, added);
+ EphyPageRow *row = ephy_page_row_new (page);
- for (int i = 0; i < added; i++) {
- items[i] = ephy_page_row_new (self->notebook, position + i);
- ephy_page_row_set_adaptive_mode (EPHY_PAGE_ROW (items[i]),
- EPHY_ADAPTIVE_MODE_NARROW);
- g_signal_connect_swapped (items[i], "closed", G_CALLBACK (row_closed_cb), self);
- }
+ ephy_page_row_set_adaptive_mode (row, EPHY_ADAPTIVE_MODE_NARROW);
+ g_signal_connect_swapped (row, "closed", G_CALLBACK (row_closed_cb), self);
- g_list_store_splice (self->list_store, position, removed, (gpointer)items, added);
+ gtk_widget_show (GTK_WIDGET (row));
- current_page_changed (self);
+ return GTK_WIDGET (row);
}
static void
-ephy_pages_view_finalize (GObject *object)
+selected_page_changed_cb (HdyTabView *tab_view,
+ GParamSpec *pspec,
+ EphyPagesView *self)
{
- EphyPagesView *self = EPHY_PAGES_VIEW (object);
-
- g_object_unref (self->list_store);
+ HdyTabPage *page = hdy_tab_view_get_selected_page (tab_view);
+ gint position = hdy_tab_view_get_page_position (tab_view, page);
+ GtkListBoxRow *row;
- G_OBJECT_CLASS (ephy_pages_view_parent_class)->finalize (object);
+ row = gtk_list_box_get_row_at_index (self->list_box, position);
+ gtk_list_box_select_row (self->list_box, row);
}
static void
@@ -161,7 +119,7 @@ ephy_pages_view_dispose (GObject *object)
{
EphyPagesView *self = EPHY_PAGES_VIEW (object);
- release_notebook (self);
+ release_tab_view (self);
G_OBJECT_CLASS (ephy_pages_view_parent_class)->dispose (object);
}
@@ -173,7 +131,6 @@ ephy_pages_view_class_init (EphyPagesViewClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = ephy_pages_view_dispose;
- object_class->finalize = ephy_pages_view_finalize;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/pages-view.ui");
gtk_widget_class_bind_template_child (widget_class, EphyPagesView, list_box);
@@ -207,14 +164,6 @@ ephy_pages_view_init (EphyPagesView *self)
gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (self->list_box, separator_header, NULL, NULL);
-
- self->list_store = g_list_store_new (EPHY_TYPE_PAGE_ROW);
-
- gtk_list_box_bind_model (self->list_box,
- G_LIST_MODEL (self->list_store),
- create_row,
- NULL,
- NULL);
}
EphyPagesView *
@@ -223,39 +172,40 @@ ephy_pages_view_new (void)
return g_object_new (EPHY_TYPE_PAGES_VIEW, NULL);
}
-EphyNotebook *
-ephy_pages_view_get_notebook (EphyPagesView *self)
+EphyTabView *
+ephy_pages_view_get_tab_view (EphyPagesView *self)
{
g_assert (EPHY_IS_PAGES_VIEW (self));
- return self->notebook;
+ return self->tab_view;
}
void
-ephy_pages_view_set_notebook (EphyPagesView *self,
- EphyNotebook *notebook)
+ephy_pages_view_set_tab_view (EphyPagesView *self,
+ EphyTabView *tab_view)
{
- GMenu *pages_menu;
-
g_assert (EPHY_IS_PAGES_VIEW (self));
- if (self->notebook)
- release_notebook (self);
+ if (self->tab_view)
+ release_tab_view (self);
- if (!notebook)
+ if (!tab_view)
return;
- g_object_weak_ref (G_OBJECT (notebook), (GWeakNotify)drop_notebook, self);
- self->notebook = notebook;
- pages_menu = ephy_notebook_get_pages_menu (EPHY_NOTEBOOK (notebook));
+ g_object_weak_ref (G_OBJECT (tab_view), (GWeakNotify)drop_tab_view, self);
+ self->tab_view = tab_view;
+
+ self->model = hdy_tab_view_get_pages (ephy_tab_view_get_tab_view (tab_view));
- items_changed_cb (self, 0, 0,
- g_menu_model_get_n_items (G_MENU_MODEL (pages_menu)),
- G_MENU_MODEL (pages_menu));
+ gtk_list_box_bind_model (self->list_box,
+ self->model,
+ (GtkListBoxCreateWidgetFunc)create_row,
+ self,
+ NULL);
- g_signal_connect_object (pages_menu,
- "items-changed",
- G_CALLBACK (items_changed_cb),
+ g_signal_connect_object (ephy_tab_view_get_tab_view (tab_view),
+ "notify::selected-page",
+ G_CALLBACK (selected_page_changed_cb),
self,
- G_CONNECT_SWAPPED);
+ 0);
}
diff --git a/src/ephy-pages-view.h b/src/ephy-pages-view.h
index fe8cd91ce..47f137b44 100644
--- a/src/ephy-pages-view.h
+++ b/src/ephy-pages-view.h
@@ -23,7 +23,7 @@
#include <gtk/gtk.h>
#include "ephy-adaptive-mode.h"
-#include "ephy-notebook.h"
+#include "ephy-tab-view.h"
G_BEGIN_DECLS
@@ -33,8 +33,8 @@ G_DECLARE_FINAL_TYPE (EphyPagesView, ephy_pages_view, EPHY, PAGES_VIEW, GtkScrol
EphyPagesView *ephy_pages_view_new (void);
-EphyNotebook *ephy_pages_view_get_notebook (EphyPagesView *view);
-void ephy_pages_view_set_notebook (EphyPagesView *view,
- EphyNotebook *notebook);
+EphyTabView *ephy_pages_view_get_tab_view (EphyPagesView *view);
+void ephy_pages_view_set_tab_view (EphyPagesView *view,
+ EphyTabView *tab_view);
G_END_DECLS
diff --git a/src/ephy-session.c b/src/ephy-session.c
index cd7f71c8f..4ac82f507 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -32,11 +32,12 @@
#include "ephy-file-helpers.h"
#include "ephy-gui.h"
#include "ephy-link.h"
-#include "ephy-notebook.h"
+#include "ephy-tab-view.h"
#include "ephy-prefs.h"
#include "ephy-settings.h"
#include "ephy-shell.h"
#include "ephy-string.h"
+#include "ephy-tab-view.h"
#include "ephy-window.h"
#include <glib/gi18n.h>
@@ -45,12 +46,12 @@
#include <libxml/xmlwriter.h>
typedef struct {
- EphyNotebook *notebook;
+ EphyTabView *tab_view;
gint ref_count;
-} NotebookTracker;
+} TabViewTracker;
typedef struct {
- NotebookTracker *notebook_tracker;
+ TabViewTracker *tab_view_tracker;
int position;
char *url;
WebKitWebViewSessionState *state;
@@ -132,35 +133,35 @@ load_changed_cb (WebKitWebView *view,
}
static void
-notebook_tracker_set_notebook (NotebookTracker *tracker,
- EphyNotebook *notebook)
+tab_view_tracker_set_tab_view (TabViewTracker *tracker,
+ EphyTabView *tab_view)
{
- if (tracker->notebook == notebook) {
+ if (tracker->tab_view == tab_view) {
return;
}
- if (tracker->notebook) {
- g_object_remove_weak_pointer (G_OBJECT (tracker->notebook), (gpointer *)&tracker->notebook);
+ if (tracker->tab_view) {
+ g_object_remove_weak_pointer (G_OBJECT (tracker->tab_view), (gpointer *)&tracker->tab_view);
}
- tracker->notebook = notebook;
- if (tracker->notebook) {
- g_object_add_weak_pointer (G_OBJECT (tracker->notebook), (gpointer *)&tracker->notebook);
+ tracker->tab_view = tab_view;
+ if (tracker->tab_view) {
+ g_object_add_weak_pointer (G_OBJECT (tracker->tab_view), (gpointer *)&tracker->tab_view);
}
}
-static NotebookTracker *
-notebook_tracker_new (EphyNotebook *notebook)
+static TabViewTracker *
+tab_view_tracker_new (EphyTabView *tab_view)
{
- NotebookTracker *tracker = g_new0 (NotebookTracker, 1);
+ TabViewTracker *tracker = g_new0 (TabViewTracker, 1);
tracker->ref_count = 1;
- notebook_tracker_set_notebook (tracker, notebook);
+ tab_view_tracker_set_tab_view (tracker, tab_view);
return tracker;
}
-static NotebookTracker *
-notebook_tracker_ref (NotebookTracker *tracker)
+static TabViewTracker *
+tab_view_tracker_ref (TabViewTracker *tracker)
{
g_atomic_int_inc (&tracker->ref_count);
@@ -168,57 +169,57 @@ notebook_tracker_ref (NotebookTracker *tracker)
}
static void
-notebook_tracker_unref (NotebookTracker *tracker)
+tab_view_tracker_unref (TabViewTracker *tracker)
{
if (!g_atomic_int_dec_and_test (&tracker->ref_count))
return;
- notebook_tracker_set_notebook (tracker, NULL);
+ tab_view_tracker_set_tab_view (tracker, NULL);
g_free (tracker);
}
-static EphyNotebook *
-closed_tab_get_notebook (ClosedTab *tab)
+static EphyTabView *
+closed_tab_get_tab_view (ClosedTab *tab)
{
- return tab->notebook_tracker->notebook;
+ return tab->tab_view_tracker->tab_view;
}
static int
-compare_func (ClosedTab *iter,
- EphyNotebook *notebook)
+compare_func (ClosedTab *iter,
+ EphyTabView *tab_view)
{
- return GTK_NOTEBOOK (closed_tab_get_notebook (iter)) - GTK_NOTEBOOK (notebook);
+ return (gpointer)closed_tab_get_tab_view (iter) - (gpointer)tab_view;
}
-static NotebookTracker *
-ephy_session_ref_or_create_notebook_tracker (EphySession *session,
- EphyNotebook *notebook)
+static TabViewTracker *
+ephy_session_ref_or_create_tab_view_tracker (EphySession *session,
+ EphyTabView *tab_view)
{
- GList *item = g_queue_find_custom (session->closed_tabs, notebook, (GCompareFunc)compare_func);
- return item ? notebook_tracker_ref (((ClosedTab *)item->data)->notebook_tracker) : notebook_tracker_new
(notebook);
+ GList *item = g_queue_find_custom (session->closed_tabs, tab_view, (GCompareFunc)compare_func);
+ return item ? tab_view_tracker_ref (((ClosedTab *)item->data)->tab_view_tracker) : tab_view_tracker_new
(tab_view);
}
static void
closed_tab_free (ClosedTab *tab)
{
g_free (tab->url);
- notebook_tracker_unref (tab->notebook_tracker);
+ tab_view_tracker_unref (tab->tab_view_tracker);
webkit_web_view_session_state_unref (tab->state);
g_free (tab);
}
static ClosedTab *
-closed_tab_new (EphyWebView *web_view,
- int position,
- NotebookTracker *notebook_tracker)
+closed_tab_new (EphyWebView *web_view,
+ int position,
+ TabViewTracker *tab_view_tracker)
{
ClosedTab *tab = g_new0 (ClosedTab, 1);
tab->url = g_strdup (ephy_web_view_get_address (web_view));
tab->position = position;
/* Takes the ownership of the tracker */
- tab->notebook_tracker = notebook_tracker;
+ tab->tab_view_tracker = tab_view_tracker;
tab->state = webkit_web_view_get_session_state (WEBKIT_WEB_VIEW (web_view));
return tab;
@@ -233,7 +234,7 @@ ephy_session_undo_close_tab (EphySession *session)
WebKitBackForwardListItem *item;
ClosedTab *tab;
EphyWindow *window;
- EphyNotebook *notebook;
+ EphyTabView *tab_view;
EphyNewTabFlags flags = EPHY_NEW_TAB_JUMP;
g_assert (EPHY_IS_SESSION (session));
@@ -243,12 +244,12 @@ ephy_session_undo_close_tab (EphySession *session)
return;
LOG ("UNDO CLOSE TAB: %s", tab->url);
- notebook = closed_tab_get_notebook (tab);
- if (notebook) {
+ tab_view = closed_tab_get_tab_view (tab);
+ if (tab_view) {
if (tab->position > 0) {
/* Append in the n-th position. */
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook),
- tab->position - 1));
+ embed = EPHY_EMBED (ephy_tab_view_get_nth_page (tab_view,
+ tab->position - 1));
flags |= EPHY_NEW_TAB_APPEND_AFTER;
} else {
/* Just prepend in the first position. */
@@ -256,7 +257,7 @@ ephy_session_undo_close_tab (EphySession *session)
flags |= EPHY_NEW_TAB_FIRST;
}
- window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (notebook)));
+ window = EPHY_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab_view)));
new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
window, embed,
flags);
@@ -264,8 +265,8 @@ ephy_session_undo_close_tab (EphySession *session)
window = ephy_window_new ();
new_tab = ephy_shell_new_tab (ephy_shell_get_default (),
window, NULL, flags);
- notebook_tracker_set_notebook (tab->notebook_tracker,
- EPHY_NOTEBOOK (ephy_window_get_notebook (window)));
+ tab_view_tracker_set_tab_view (tab->tab_view_tracker,
+ ephy_window_get_tab_view (window));
}
web_view = WEBKIT_WEB_VIEW (ephy_embed_get_web_view (new_tab));
@@ -288,10 +289,10 @@ ephy_session_undo_close_tab (EphySession *session)
}
static void
-ephy_session_tab_closed (EphySession *session,
- EphyNotebook *notebook,
- EphyEmbed *embed,
- gint position)
+ephy_session_tab_closed (EphySession *session,
+ EphyTabView *tab_view,
+ EphyEmbed *embed,
+ gint position)
{
EphyWebView *view;
WebKitWebView *wk_view;
@@ -306,7 +307,7 @@ ephy_session_tab_closed (EphySession *session,
}
tab = closed_tab_new (view, position,
- ephy_session_ref_or_create_notebook_tracker (session, notebook));
+ ephy_session_ref_or_create_tab_view_tracker (session, tab_view));
g_queue_push_head (session->closed_tabs, tab);
if (g_queue_get_length (session->closed_tabs) == 1)
@@ -325,33 +326,38 @@ ephy_session_get_can_undo_tab_closed (EphySession *session)
}
static void
-notebook_page_added_cb (GtkWidget *notebook,
- EphyEmbed *embed,
+tab_view_page_added_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
guint position,
EphySession *session)
{
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+
g_signal_connect (ephy_embed_get_web_view (embed), "load-changed",
G_CALLBACK (load_changed_cb), session);
}
static void
-notebook_page_removed_cb (GtkWidget *notebook,
- EphyEmbed *embed,
- guint position,
+tab_view_page_removed_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
+ gint position,
EphySession *session)
{
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+ EphyTabView *ephy_tab_view = EPHY_TAB_VIEW (g_object_get_data (G_OBJECT (tab_view), "ephy-tab-view"));
+
ephy_session_save (session);
g_signal_handlers_disconnect_by_func
(ephy_embed_get_web_view (embed), G_CALLBACK (load_changed_cb),
session);
- ephy_session_tab_closed (session, EPHY_NOTEBOOK (notebook), embed, position);
+ ephy_session_tab_closed (session, ephy_tab_view, embed, position);
}
static void
-notebook_page_reordered_cb (GtkWidget *notebook,
- GtkWidget *tab,
+tab_view_page_reordered_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
guint position,
EphySession *session)
{
@@ -359,10 +365,9 @@ notebook_page_reordered_cb (GtkWidget *notebook,
}
static void
-notebook_switch_page_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint page_num,
- EphySession *session)
+tab_view_notify_selected_page_cb (HdyTabView *tab_view,
+ GParamSpec *pspec,
+ EphySession *session)
{
ephy_session_save (session);
}
@@ -386,8 +391,8 @@ window_added_cb (GtkApplication *application,
GtkWindow *window,
EphySession *session)
{
- GtkWidget *notebook;
EphyWindow *ephy_window;
+ HdyTabView *tab_view;
ephy_session_save (session);
@@ -396,15 +401,15 @@ window_added_cb (GtkApplication *application,
ephy_window = EPHY_WINDOW (window);
- notebook = ephy_window_get_notebook (ephy_window);
- g_signal_connect (notebook, "page-added",
- G_CALLBACK (notebook_page_added_cb), session);
- g_signal_connect (notebook, "page-removed",
- G_CALLBACK (notebook_page_removed_cb), session);
- g_signal_connect (notebook, "page-reordered",
- G_CALLBACK (notebook_page_reordered_cb), session);
- g_signal_connect_after (notebook, "switch-page",
- G_CALLBACK (notebook_switch_page_cb), session);
+ tab_view = ephy_tab_view_get_tab_view (ephy_window_get_tab_view (ephy_window));
+ g_signal_connect (tab_view, "page-added",
+ G_CALLBACK (tab_view_page_added_cb), session);
+ g_signal_connect (tab_view, "page-removed",
+ G_CALLBACK (tab_view_page_removed_cb), session);
+ g_signal_connect (tab_view, "page-reordered",
+ G_CALLBACK (tab_view_page_reordered_cb), session);
+ g_signal_connect_after (tab_view, "notify::selected-page",
+ G_CALLBACK (tab_view_notify_selected_page_cb), session);
/* Set unique identifier as role, so that on restore, the WM can
* place the window on the right workspace
@@ -563,7 +568,7 @@ typedef struct {
static SessionTab *
session_tab_new (EphyEmbed *embed,
EphySession *session,
- GtkNotebook *notebook)
+ EphyTabView *tab_view)
{
SessionTab *session_tab;
const char *address;
@@ -592,7 +597,7 @@ session_tab_new (EphyEmbed *embed,
session_tab->crashed = (error_page == EPHY_WEB_VIEW_ERROR_PAGE_CRASH ||
error_page == EPHY_WEB_VIEW_ERROR_PROCESS_CRASH);
session_tab->state = webkit_web_view_get_session_state (WEBKIT_WEB_VIEW (web_view));
- session_tab->pinned = ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), embed);
+ session_tab->pinned = ephy_tab_view_get_is_pinned (tab_view, GTK_WIDGET (embed));
return session_tab;
}
@@ -613,7 +618,7 @@ session_window_new (EphyWindow *window,
{
SessionWindow *session_window;
GList *tabs, *l;
- GtkNotebook *notebook;
+ EphyTabView *tab_view;
tabs = ephy_embed_container_get_children (EPHY_EMBED_CONTAINER (window));
/* Do not save an empty EphyWindow.
@@ -626,18 +631,18 @@ session_window_new (EphyWindow *window,
session_window = g_new0 (SessionWindow, 1);
get_window_geometry (window, session_window);
session_window->role = g_strdup (gtk_window_get_role (GTK_WINDOW (window)));
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ tab_view = ephy_window_get_tab_view (window);
for (l = tabs; l != NULL; l = l->next) {
SessionTab *tab;
- tab = session_tab_new (EPHY_EMBED (l->data), session, notebook);
+ tab = session_tab_new (EPHY_EMBED (l->data), session, tab_view);
session_window->tabs = g_list_prepend (session_window->tabs, tab);
}
g_list_free (tabs);
session_window->tabs = g_list_reverse (session_window->tabs);
- session_window->active_tab = gtk_notebook_get_current_page (notebook);
+ session_window->active_tab = ephy_tab_view_get_selected_index (tab_view);
return session_window;
}
@@ -1184,7 +1189,7 @@ session_parse_embed (SessionParserContext *context,
const gchar **names,
const gchar **values)
{
- GtkWidget *notebook;
+ HdyTabView *tab_view;
const char *url = NULL;
const char *title = NULL;
const char *history = NULL;
@@ -1201,7 +1206,7 @@ session_parse_embed (SessionParserContext *context,
return;
}
- notebook = ephy_window_get_notebook (context->window);
+ tab_view = ephy_tab_view_get_tab_view (ephy_window_get_tab_view (context->window));
for (i = 0; names[i]; i++) {
if (strcmp (names[i], "url") == 0) {
@@ -1251,7 +1256,11 @@ session_parse_embed (SessionParserContext *context,
context->window, NULL, flags,
0);
- ephy_notebook_tab_set_pinned (EPHY_NOTEBOOK (notebook), GTK_WIDGET (embed), is_pin);
+ // TODO this is not good, we should use insert_pinned() instead, as pinning
+ // causes a reordering
+ hdy_tab_view_set_page_pinned (tab_view,
+ hdy_tab_view_get_page (tab_view, GTK_WIDGET (embed)),
+ is_pin);
web_view = ephy_embed_get_web_view (embed);
if (history) {
@@ -1327,7 +1336,7 @@ session_end_element (GMarkupParseContext *ctx,
SessionParserContext *context = (SessionParserContext *)user_data;
if (strcmp (element_name, "window") == 0) {
- GtkWidget *notebook;
+ EphyTabView *tab_view;
EphyEmbedShell *shell = ephy_embed_shell_get_default ();
if (!context->window) {
@@ -1337,8 +1346,8 @@ session_end_element (GMarkupParseContext *ctx,
return;
}
- notebook = ephy_window_get_notebook (context->window);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), context->active_tab);
+ tab_view = ephy_window_get_tab_view (context->window);
+ ephy_tab_view_select_nth_page (tab_view, context->active_tab);
if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) != EPHY_EMBED_SHELL_MODE_TEST) {
EphyEmbed *active_child;
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 77fb76d4c..5ef24a9dd 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -912,23 +912,22 @@ webkit_notification_clicked_cb (WebKitNotification *notification,
for (guint win_idx = 0; win_idx < g_list_length (windows); win_idx++) {
EphyWindow *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
int n_pages;
window = EPHY_WINDOW (g_list_nth_data (windows, win_idx));
-
- notebook = ephy_window_get_notebook (window);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+ tab_view = ephy_window_get_tab_view (window);
+ n_pages = ephy_tab_view_get_n_pages (tab_view);
for (int i = 0; i < n_pages; i++) {
EphyEmbed *embed;
WebKitWebView *webview;
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
+ embed = EPHY_EMBED (ephy_tab_view_get_nth_page (tab_view, i));
webview = WEBKIT_WEB_VIEW (ephy_embed_get_web_view (embed));
if (webview == notification_webview) {
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), i);
+ ephy_tab_view_select_page (tab_view, GTK_WIDGET (embed));
gtk_window_present (GTK_WINDOW (window));
return;
}
diff --git a/src/ephy-suggestion-model.c b/src/ephy-suggestion-model.c
index 106b39c8b..c91e53823 100644
--- a/src/ephy-suggestion-model.c
+++ b/src/ephy-suggestion-model.c
@@ -433,10 +433,9 @@ add_tabs (EphySuggestionModel *self,
GApplication *application;
EphyEmbedShell *shell;
EphyWindow *window;
- GtkWidget *notebook;
+ EphyTabView *tab_view;
GList *windows;
- gint n_pages;
- gint current;
+ gint n_pages, selected;
guint added = 0;
shell = ephy_embed_shell_get_default ();
@@ -446,9 +445,9 @@ add_tabs (EphySuggestionModel *self,
for (guint win_idx = 0; win_idx < g_list_length (windows); win_idx++) {
window = EPHY_WINDOW (g_list_nth_data (windows, win_idx));
- notebook = ephy_window_get_notebook (window);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- current = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ tab_view = ephy_window_get_tab_view (window);
+ n_pages = ephy_tab_view_get_n_pages (tab_view);
+ selected = ephy_tab_view_get_selected_index (tab_view);
for (int i = 0; i < n_pages; i++) {
EphyEmbed *embed;
@@ -464,10 +463,10 @@ add_tabs (EphySuggestionModel *self,
g_autofree gchar *display_address_casefold = NULL;
g_autofree gchar *query_casefold = NULL;
- if (win_idx == 0 && i == current)
+ if (win_idx == 0 && i == selected)
continue;
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
+ embed = EPHY_EMBED (ephy_tab_view_get_nth_page (tab_view, i));
webview = ephy_embed_get_web_view (embed);
display_address = ephy_web_view_get_display_address (webview);
url = ephy_web_view_get_address (webview);
diff --git a/src/ephy-tab-view.c b/src/ephy-tab-view.c
new file mode 100644
index 000000000..37dfb4ff6
--- /dev/null
+++ b/src/ephy-tab-view.c
@@ -0,0 +1,438 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2019 Alexander Mikhaylenko <exalm7659 gmail com>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ephy-tab-view.h"
+
+#include "ephy-embed-utils.h"
+
+struct _EphyTabView {
+ GtkBin parent_instance;
+
+ HdyTabView *tab_view;
+ HdyTabPage *current_page;
+};
+
+G_DEFINE_TYPE (EphyTabView, ephy_tab_view, GTK_TYPE_BIN)
+
+enum {
+ PROP_0,
+ PROP_N_PAGES,
+ PROP_SELECTED_INDEX,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS];
+
+static void
+notify_n_pages_cb (EphyTabView *self)
+{
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_N_PAGES]);
+}
+
+static void
+notify_selected_page_cb (EphyTabView *self)
+{
+ HdyTabPage *page = hdy_tab_view_get_selected_page (self->tab_view);
+
+ hdy_tab_page_set_needs_attention (page, FALSE);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_INDEX]);
+}
+
+static void
+secondary_icon_activated_cb (EphyTabView *self,
+ HdyTabPage *page)
+{
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+ EphyWebView *view = ephy_embed_get_web_view (embed);
+ gboolean muted = webkit_web_view_get_is_muted (WEBKIT_WEB_VIEW (view));
+
+ webkit_web_view_set_is_muted (WEBKIT_WEB_VIEW (view), !muted);
+}
+
+static void
+setup_menu_cb (EphyTabView *self,
+ HdyTabPage *page)
+{
+ self->current_page = page;
+}
+
+static HdyTabPage *
+get_current_page (EphyTabView *self)
+{
+ if (self->current_page)
+ return self->current_page;
+
+ return hdy_tab_view_get_selected_page (self->tab_view);
+}
+
+static void
+ephy_tab_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyTabView *self = EPHY_TAB_VIEW (object);
+
+ switch (prop_id) {
+ case PROP_N_PAGES:
+ g_value_set_int (value, ephy_tab_view_get_n_pages (self));
+ break;
+
+ case PROP_SELECTED_INDEX:
+ g_value_set_int (value, ephy_tab_view_get_selected_index (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_tab_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyTabView *self = EPHY_TAB_VIEW (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_tab_view_class_init (EphyTabViewClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = ephy_tab_view_get_property;
+ object_class->set_property = ephy_tab_view_set_property;
+
+ properties[PROP_N_PAGES] =
+ g_param_spec_int ("n-pages",
+ "Number of pages",
+ "The number of pages in the tab view",
+ 0,
+ G_MAXINT,
+ 0,
+ (G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY));
+
+ properties[PROP_SELECTED_INDEX] =
+ g_param_spec_int ("selected-index",
+ "Selected index",
+ "The index of the currently selected page",
+ 0,
+ G_MAXINT,
+ 0,
+ (G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_EXPLICIT_NOTIFY));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+}
+
+static void
+ephy_tab_view_init (EphyTabView *self)
+{
+ self->tab_view = HDY_TAB_VIEW (hdy_tab_view_new ());
+ gtk_widget_show (GTK_WIDGET (self->tab_view));
+
+ g_object_set_data (G_OBJECT (self->tab_view), "ephy-tab-view", self);
+
+ gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->tab_view));
+
+ g_signal_connect_object (self->tab_view,
+ "notify::n-pages",
+ G_CALLBACK (notify_n_pages_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (self->tab_view,
+ "notify::selected-page",
+ G_CALLBACK (notify_selected_page_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (self->tab_view,
+ "setup-menu",
+ G_CALLBACK (setup_menu_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (self->tab_view,
+ "secondary-icon-activated",
+ G_CALLBACK (secondary_icon_activated_cb),
+ self,
+ G_CONNECT_SWAPPED);
+}
+
+EphyTabView *
+ephy_tab_view_new (void)
+{
+ return g_object_new (EPHY_TYPE_TAB_VIEW, NULL);
+}
+
+void
+ephy_tab_view_next (EphyTabView *self)
+{
+ hdy_tab_view_select_next_page (self->tab_view);
+}
+
+void
+ephy_tab_view_pin (EphyTabView *self)
+{
+ hdy_tab_view_set_page_pinned (self->tab_view, get_current_page (self), TRUE);
+}
+
+void
+ephy_tab_view_unpin (EphyTabView *self)
+{
+ hdy_tab_view_set_page_pinned (self->tab_view, get_current_page (self), FALSE);
+}
+
+void
+ephy_tab_view_close (EphyTabView *self,
+ GtkWidget *widget)
+{
+ HdyTabPage *page = hdy_tab_view_get_page (self->tab_view, widget);
+
+ hdy_tab_view_close_page (self->tab_view, page);
+}
+
+void
+ephy_tab_view_close_selected (EphyTabView *self)
+{
+ hdy_tab_view_close_page (self->tab_view, get_current_page (self));
+}
+
+void
+ephy_tab_view_close_left (EphyTabView *self)
+{
+ hdy_tab_view_close_pages_before (self->tab_view, get_current_page (self));
+}
+
+void
+ephy_tab_view_close_right (EphyTabView *self)
+{
+ hdy_tab_view_close_pages_after (self->tab_view, get_current_page (self));
+}
+
+void
+ephy_tab_view_close_other (EphyTabView *self)
+{
+ hdy_tab_view_close_other_pages (self->tab_view, get_current_page (self));
+}
+
+void
+ephy_tab_view_foreach (EphyTabView *self,
+ GtkCallback callback,
+ gpointer user_data)
+{
+ gint i, n;
+
+ n = hdy_tab_view_get_n_pages (self->tab_view);
+
+ for (i = 0; i < n; i++) {
+ HdyTabPage *page = hdy_tab_view_get_nth_page (self->tab_view, i);
+
+ callback (hdy_tab_page_get_content (page), user_data);
+ }
+}
+
+gint
+ephy_tab_view_get_n_pages (EphyTabView *self)
+{
+ return hdy_tab_view_get_n_pages (self->tab_view);
+}
+
+gint
+ephy_tab_view_get_selected_index (EphyTabView *self)
+{
+ HdyTabPage *page = hdy_tab_view_get_selected_page (self->tab_view);
+
+ return hdy_tab_view_get_page_position (self->tab_view, page);
+}
+
+GtkWidget *
+ephy_tab_view_get_nth_page (EphyTabView *self,
+ gint index)
+{
+ HdyTabPage *page = hdy_tab_view_get_nth_page (self->tab_view, index);
+
+ return hdy_tab_page_get_content (page);
+}
+
+void
+ephy_tab_view_select_nth_page (EphyTabView *self,
+ gint index)
+{
+ HdyTabPage *page = hdy_tab_view_get_nth_page (self->tab_view, index);
+
+ hdy_tab_view_set_selected_page (self->tab_view, page);
+}
+
+gboolean
+ephy_tab_view_select_page (EphyTabView *self,
+ GtkWidget *widget)
+{
+ HdyTabPage *page = hdy_tab_view_get_page (self->tab_view, widget);
+
+ if (page)
+ hdy_tab_view_set_selected_page (self->tab_view, page);
+
+ return page != NULL;
+}
+
+GtkWidget *
+ephy_tab_view_get_selected_page (EphyTabView *self)
+{
+ HdyTabPage *page = hdy_tab_view_get_selected_page (self->tab_view);
+
+ return hdy_tab_page_get_content (page);
+}
+
+HdyTabView *
+ephy_tab_view_get_tab_view (EphyTabView *self)
+{
+ return self->tab_view;
+}
+
+GList *
+ephy_tab_view_get_pages (EphyTabView *self)
+{
+ GList *list = NULL;
+ gint i, n;
+
+ n = hdy_tab_view_get_n_pages (self->tab_view);
+
+ for (i = 0; i < n; i++) {
+ HdyTabPage *page = hdy_tab_view_get_nth_page (self->tab_view, i);
+ GtkWidget *content = hdy_tab_page_get_content (page);
+
+ list = g_list_prepend (list, content);
+ }
+
+ return g_list_reverse (list);
+}
+
+gboolean
+ephy_tab_view_get_is_pinned (EphyTabView *self,
+ GtkWidget *widget)
+{
+ HdyTabPage *page = hdy_tab_view_get_page (self->tab_view, widget);
+
+ return hdy_tab_page_get_pinned (page);
+}
+
+static void
+update_title_cb (HdyTabPage *page)
+{
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+ EphyWebView *view = ephy_embed_get_web_view (embed);
+ const gchar *title = ephy_embed_get_title (embed);
+ const gchar *address;
+
+ if (!ephy_embed_has_load_pending (embed) &&
+ !hdy_tab_page_get_selected (page) &&
+ hdy_tab_page_get_pinned (page))
+ hdy_tab_page_set_needs_attention (page, TRUE);
+
+ if (title && strlen (title)) {
+ hdy_tab_page_set_title (page, title);
+
+ return;
+ }
+
+ address = ephy_web_view_get_display_address (view);
+
+ if (ephy_web_view_is_loading (view) &&
+ !ephy_embed_utils_is_no_show_address (address))
+ hdy_tab_page_set_title (page, address);
+}
+
+static void
+update_secondary_icon_cb (HdyTabPage *page)
+{
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+ EphyWebView *view = ephy_embed_get_web_view (embed);
+ GIcon *icon = NULL;
+
+ if (webkit_web_view_is_playing_audio (WEBKIT_WEB_VIEW (view))) {
+ if (webkit_web_view_get_is_muted (WEBKIT_WEB_VIEW (view)))
+ icon = G_ICON (g_themed_icon_new ("audio-volume-muted-symbolic"));
+ else
+ icon = G_ICON (g_themed_icon_new ("audio-volume-high-symbolic"));
+ }
+
+ hdy_tab_page_set_secondary_icon (page, icon);
+}
+
+gint
+ephy_tab_view_add_tab (EphyTabView *self,
+ EphyEmbed *embed,
+ gint position,
+ gboolean jump_to)
+{
+ HdyTabPage *page;
+ EphyWebView *view;
+
+ if (position < 0)
+ page = hdy_tab_view_append (self->tab_view, GTK_WIDGET (embed));
+ else
+ page = hdy_tab_view_insert (self->tab_view, GTK_WIDGET (embed), position);
+
+ if (jump_to)
+ hdy_tab_view_set_selected_page (self->tab_view, page);
+
+ view = ephy_embed_get_web_view (embed);
+
+ hdy_tab_page_set_secondary_icon_activatable (page, TRUE);
+
+ g_object_bind_property (view, "is-loading", page, "loading", G_BINDING_SYNC_CREATE);
+ g_object_bind_property (view, "icon", page, "icon", G_BINDING_SYNC_CREATE);
+
+ g_signal_connect_object (embed, "notify::title",
+ G_CALLBACK (update_title_cb), page,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (view, "notify::display-address",
+ G_CALLBACK (update_title_cb), page,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (view, "notify::is-playing-audio",
+ G_CALLBACK (update_secondary_icon_cb), page,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (view, "notify::is-muted",
+ G_CALLBACK (update_secondary_icon_cb), page,
+ G_CONNECT_SWAPPED);
+
+ update_title_cb (page);
+ update_secondary_icon_cb (page);
+
+ return hdy_tab_view_get_page_position (self->tab_view, page);
+}
+
+GtkWidget *
+ephy_tab_view_get_current_page (EphyTabView *self)
+{
+ return hdy_tab_page_get_content (get_current_page (self));
+}
diff --git a/src/ephy-tab-view.h b/src/ephy-tab-view.h
new file mode 100644
index 000000000..13fa1e0be
--- /dev/null
+++ b/src/ephy-tab-view.h
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 2; indent-pages-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2020 Alexander Mikhaylenko <exalm7659 gmail com>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <handy.h>
+#include "ephy-embed.h"
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_TAB_VIEW (ephy_tab_view_get_type())
+
+G_DECLARE_FINAL_TYPE (EphyTabView, ephy_tab_view, EPHY, TAB_VIEW, GtkBin)
+
+EphyTabView *ephy_tab_view_new (void);
+
+void ephy_tab_view_next (EphyTabView *self);
+
+void ephy_tab_view_pin (EphyTabView *self);
+void ephy_tab_view_unpin (EphyTabView *self);
+
+void ephy_tab_view_close (EphyTabView *self,
+ GtkWidget *widget);
+void ephy_tab_view_close_selected (EphyTabView *self);
+void ephy_tab_view_close_left (EphyTabView *self);
+void ephy_tab_view_close_right (EphyTabView *self);
+void ephy_tab_view_close_other (EphyTabView *self);
+
+void ephy_tab_view_foreach (EphyTabView *self,
+ GtkCallback callback,
+ gpointer user_data);
+
+gint ephy_tab_view_get_n_pages (EphyTabView *self);
+gint ephy_tab_view_get_selected_index (EphyTabView *self);
+
+GtkWidget *ephy_tab_view_get_nth_page (EphyTabView *self,
+ gint index);
+void ephy_tab_view_select_nth_page (EphyTabView *self,
+ gint index);
+
+gboolean ephy_tab_view_select_page (EphyTabView *self,
+ GtkWidget *widget);
+
+GtkWidget *ephy_tab_view_get_selected_page (EphyTabView *self);
+
+HdyTabView *ephy_tab_view_get_tab_view (EphyTabView *self);
+
+GList *ephy_tab_view_get_pages (EphyTabView *self);
+
+gboolean ephy_tab_view_get_is_pinned (EphyTabView *self,
+ GtkWidget *widget);
+
+gint ephy_tab_view_add_tab (EphyTabView *self,
+ EphyEmbed *embed,
+ gint position,
+ gboolean jump_to);
+
+GtkWidget *ephy_tab_view_get_current_page (EphyTabView *self);
+
+G_END_DECLS
diff --git a/src/ephy-window.c b/src/ephy-window.c
index d6adfb24e..b7b4290a5 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -44,7 +44,6 @@
#include "ephy-link.h"
#include "ephy-location-entry.h"
#include "ephy-mouse-gesture-controller.h"
-#include "ephy-notebook.h"
#include "ephy-pages-view.h"
#include "ephy-permissions-manager.h"
#include "ephy-prefs.h"
@@ -129,10 +128,6 @@ const struct {
{ "toolbar.combined-stop-reload", { NULL } },
/* Tabs */
- { "tab.previous", { "<Primary>Page_Up", "<Primary>KP_9", "<shift><Primary>Tab", NULL } },
- { "tab.next", { "<Primary>Page_Down", "<Primary>KP_3", "<Primary>Tab", NULL } },
- { "tab.move-left", { "<shift><Primary>Page_Up", NULL } },
- { "tab.move-right", { "<shift><Primary>Page_Down", NULL } },
{ "tab.duplicate", { "<shift><Primary>K", NULL } },
{ "tab.close", { "<Primary>W", NULL } },
{ "tab.pin", { NULL } }
@@ -154,7 +149,9 @@ struct _EphyWindow {
EphyPagesView *pages_view;
EphyBookmarksManager *bookmarks_manager;
GHashTable *action_labels;
- GtkNotebook *notebook;
+ EphyTabView *tab_view;
+ HdyTabBar *tab_bar;
+ GtkRevealer *tab_bar_revealer;
GtkWidget *action_bar;
EphyEmbed *active_embed;
EphyWindowChrome chrome;
@@ -215,23 +212,18 @@ impl_add_child (EphyEmbedContainer *container,
{
EphyWindow *window = EPHY_WINDOW (container);
- g_assert (!window->is_popup || gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook)) < 1);
+ g_assert (!window->is_popup || ephy_tab_view_get_n_pages (window->tab_view) < 1);
- return ephy_notebook_add_tab (EPHY_NOTEBOOK (window->notebook),
- child, position, jump_to);
+ return ephy_tab_view_add_tab (window->tab_view, child, position, jump_to);
}
static void
impl_set_active_child (EphyEmbedContainer *container,
EphyEmbed *child)
{
- int page;
- EphyWindow *window;
-
- window = EPHY_WINDOW (container);
+ EphyWindow *window = EPHY_WINDOW (container);
- page = gtk_notebook_page_num (window->notebook, GTK_WIDGET (child));
- gtk_notebook_set_current_page (window->notebook, page);
+ ephy_tab_view_select_page (window->tab_view, GTK_WIDGET (child));
}
static GtkWidget *
@@ -301,12 +293,9 @@ static void
impl_remove_child (EphyEmbedContainer *container,
EphyEmbed *child)
{
- EphyWindow *window;
+ EphyWindow *window = EPHY_WINDOW (container);
- window = EPHY_WINDOW (container);
- g_signal_emit_by_name (window->notebook,
- "tab-close-request",
- child, window);
+ ephy_tab_view_close (window->tab_view, GTK_WIDGET (child));
}
static EphyEmbed *
@@ -320,7 +309,7 @@ impl_get_children (EphyEmbedContainer *container)
{
EphyWindow *window = EPHY_WINDOW (container);
- return gtk_container_get_children (GTK_CONTAINER (window->notebook));
+ return ephy_tab_view_get_pages (window->tab_view);
}
static gboolean
@@ -334,7 +323,7 @@ impl_get_n_children (EphyEmbedContainer *container)
{
EphyWindow *window = EPHY_WINDOW (container);
- return gtk_notebook_get_n_pages (window->notebook);
+ return ephy_tab_view_get_n_pages (window->tab_view);
}
static void
@@ -438,8 +427,8 @@ sync_chromes_visibility (EphyWindow *window)
show_tabsbar = (window->chrome & EPHY_WINDOW_CHROME_TABSBAR);
- ephy_notebook_set_tabs_allowed (EPHY_NOTEBOOK (window->notebook),
- show_tabsbar && !(window->is_popup || window->is_fullscreen));
+ gtk_widget_set_visible (GTK_WIDGET (window->tab_bar),
+ show_tabsbar && !(window->is_popup || window->is_fullscreen));
}
static void
@@ -512,7 +501,6 @@ update_adaptive_mode (EphyWindow *window)
{
EphyHeaderBar *header_bar = EPHY_HEADER_BAR (ephy_window_get_header_bar (window));
EphyActionBar *action_bar = EPHY_ACTION_BAR (window->action_bar);
- EphyNotebook *notebook = EPHY_NOTEBOOK (window->notebook);
gboolean is_narrow, is_mobile_landscape;
EphyAdaptiveMode adaptive_mode;
gint width, height;
@@ -545,7 +533,9 @@ update_adaptive_mode (EphyWindow *window)
EPHY_ADAPTIVE_MODE_NORMAL;
ephy_header_bar_set_adaptive_mode (header_bar, adaptive_mode);
ephy_action_bar_set_adaptive_mode (action_bar, adaptive_mode);
- ephy_notebook_set_adaptive_mode (notebook, adaptive_mode);
+
+ gtk_revealer_set_reveal_child (window->tab_bar_revealer,
+ adaptive_mode == EPHY_ADAPTIVE_MODE_NORMAL);
/* When switching to desktop sizes, drop the tabs view and go back
* to the main view.
@@ -867,24 +857,17 @@ static const GActionEntry window_entries [] = {
{ "content", window_cmd_go_content },
{ "tabs-view", window_cmd_go_tabs_view },
- { "show-tab", window_cmd_show_tab, "u", "uint32 0", window_cmd_change_show_tab_state },
-
/* Toggle actions */
{ "browse-with-caret", NULL, NULL, "false", window_cmd_change_browse_with_caret_state },
{ "fullscreen", NULL, NULL, "false", window_cmd_change_fullscreen_state },
};
static const GActionEntry tab_entries [] = {
- { "previous", window_cmd_tabs_previous },
- { "next", window_cmd_tabs_next },
{ "duplicate", window_cmd_tabs_duplicate },
- { "detach", window_cmd_tabs_detach },
{ "close", window_cmd_tabs_close },
{ "close-tab", window_cmd_tabs_close },
{ "close-left", window_cmd_tabs_close_left },
{ "close-right", window_cmd_tabs_close_right },
- { "move-left", window_cmd_tabs_move_left },
- { "move-right", window_cmd_tabs_move_right },
{ "close-others", window_cmd_tabs_close_others },
{ "reload", window_cmd_tabs_reload },
{ "reopen", window_cmd_tabs_reopen_closed_tab },
@@ -2578,7 +2561,7 @@ tab_accels_item_activate (GSimpleAction *action,
tab_number = atoi (action_name + strlen ("accel-"));
- gtk_notebook_set_current_page (EPHY_WINDOW (user_data)->notebook, tab_number);
+ ephy_tab_view_select_nth_page (EPHY_WINDOW (user_data)->tab_view, tab_number);
}
static void
@@ -2592,7 +2575,7 @@ tab_accels_update (EphyWindow *window)
action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
actions = g_action_group_list_actions (action_group);
- n_pages = gtk_notebook_get_n_pages (window->notebook);
+ n_pages = ephy_tab_view_get_n_pages (window->tab_view);
for (i = 0; actions[i] != NULL; i++) {
if (strstr (actions[i], "accel-") != NULL) {
GAction *action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
@@ -2610,7 +2593,9 @@ static void
accel_cb_tabs_next (GtkWidget *widget,
gpointer user_data)
{
- window_cmd_tabs_next (NULL, NULL, user_data);
+ EphyWindow *window = EPHY_WINDOW (user_data);
+
+ ephy_tab_view_next (ephy_window_get_tab_view (window));
}
#define TAB_ACCELS_N 10
@@ -2673,105 +2658,56 @@ setup_tab_accels (EphyWindow *window)
NULL);
}
-static gboolean
-show_notebook_popup_menu (GtkNotebook *notebook,
- EphyWindow *window,
- GdkEventButton *event)
+static void
+tab_view_setup_menu_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
+ EphyWindow *window)
{
- GtkWidget *menu, *tab, *tab_label;
- GMenu *menu_model;
- GtkBuilder *builder;
GActionGroup *action_group;
GAction *action;
+ int n_pages;
+ int n_pinned_pages;
+ int position;
+ gboolean pinned;
- builder = gtk_builder_new_from_resource ("/org/gnome/epiphany/gtk/notebook-context-menu.ui");
-
- menu_model = G_MENU (gtk_builder_get_object (builder, "notebook-menu"));
- menu = gtk_menu_new_from_model (G_MENU_MODEL (menu_model));
- gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (window->active_embed), NULL);
+ if (page) {
+ n_pages = hdy_tab_view_get_n_pages (tab_view);
+ n_pinned_pages = hdy_tab_view_get_n_pinned_pages (tab_view);
+ position = hdy_tab_view_get_page_position (tab_view, page);
+ pinned = hdy_tab_page_get_pinned (page);
+ }
action_group = gtk_widget_get_action_group (GTK_WIDGET (window), "tab");
- if (event != NULL) {
- int n_pages;
- int page_num;
- gboolean pinned;
-
- tab = GTK_WIDGET (window->active_embed);
- n_pages = gtk_notebook_get_n_pages (notebook);
- page_num = gtk_notebook_page_num (notebook, tab);
- pinned = ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), EPHY_EMBED (tab));
-
- /* enable/disable close others/left/right */
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "close-left");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (page_num > 0) && !pinned);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "close-right");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (page_num < n_pages - 1) && !pinned);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "close-others");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (n_pages > 1) && !pinned);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "reload-all");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), n_pages > 1);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "pin");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !pinned);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "unpin");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), pinned);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
- "close-tab");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !pinned);
-
- gtk_menu_popup_at_pointer (GTK_MENU (menu), (GdkEvent *)event);
- } else {
- tab = GTK_WIDGET (window->active_embed);
- tab_label = gtk_notebook_get_tab_label (notebook, tab);
-
- /* Not tested, because I don't know how to trigger this code. */
- gtk_menu_popup_at_widget (GTK_MENU (menu),
- tab_label,
- GDK_GRAVITY_SOUTH_WEST,
- GDK_GRAVITY_NORTH_WEST,
- NULL);
- gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
- }
+ /* enable/disable close others/left/right */
+ /* If there's no page, enable all actions so that we don't interfere with hotkeys */
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "close-left");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || position > n_pinned_pages);
- g_object_unref (builder);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "close-right");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || (position < n_pages - 1 && !pinned));
- return TRUE;
-}
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "close-others");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || (n_pages > n_pinned_pages + 1 && !pinned));
-static gboolean
-notebook_button_press_cb (GtkNotebook *notebook,
- GdkEventButton *event,
- EphyWindow *window)
-{
- if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
- return show_notebook_popup_menu (notebook, window, event);
- }
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "reload-all");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || n_pages > 1);
- return FALSE;
-}
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "pin");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || !pinned);
-static gboolean
-notebook_popup_menu_cb (GtkNotebook *notebook,
- EphyWindow *window)
-{
- /* Only respond if the notebook is the actual focus */
- if (EPHY_IS_NOTEBOOK (gtk_window_get_focus (GTK_WINDOW (window)))) {
- return show_notebook_popup_menu (notebook, window, NULL);
- }
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "unpin");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || pinned);
- return FALSE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group),
+ "close-tab");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !page || !pinned);
}
static gboolean
@@ -2803,7 +2739,7 @@ download_only_load_cb (EphyWebView *view,
if (ephy_web_view_get_document_type (view) == EPHY_WEB_VIEW_DOCUMENT_PDF)
return;
- if (gtk_notebook_get_n_pages (window->notebook) == 1) {
+ if (ephy_tab_view_get_n_pages (window->tab_view) == 1) {
ephy_web_view_load_homepage (view);
return;
}
@@ -2843,14 +2779,19 @@ reader_mode_cb (EphyWebView *view,
}
static void
-notebook_page_added_cb (EphyNotebook *notebook,
- EphyEmbed *embed,
- guint position,
- EphyWindow *window)
+tab_view_page_added_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
+ gint position,
+ EphyWindow *window)
{
- LOG ("page-added notebook %p embed %p position %u\n", notebook, embed, position);
+ GtkWidget *content = hdy_tab_page_get_content (page);
+ EphyEmbed *embed;
- g_assert (EPHY_IS_EMBED (embed));
+ LOG ("page-added tab view %p embed %p position %d\n", tab_view, embed, position);
+
+ g_assert (EPHY_IS_EMBED (content));
+
+ embed = EPHY_EMBED (content);
g_signal_connect_object (ephy_embed_get_web_view (embed), "download-only-load",
G_CALLBACK (download_only_load_cb), window, G_CONNECT_AFTER);
@@ -2867,24 +2808,25 @@ notebook_page_added_cb (EphyNotebook *notebook,
}
static void
-notebook_page_removed_cb (EphyNotebook *notebook,
- EphyEmbed *embed,
- guint position,
- EphyWindow *window)
+tab_view_page_removed_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
+ gint position,
+ EphyWindow *window)
{
- LOG ("page-removed notebook %p embed %p position %u\n", notebook, embed, position);
+ GtkWidget *content = hdy_tab_page_get_content (page);
+ LOG ("page-removed tab view %p embed %p position %d\n", tab_view, content, position);
if (window->closing)
return;
- g_assert (EPHY_IS_EMBED (embed));
+ g_assert (EPHY_IS_EMBED (content));
g_signal_handlers_disconnect_by_func
- (ephy_embed_get_web_view (embed), G_CALLBACK (download_only_load_cb), window);
+ (ephy_embed_get_web_view (EPHY_EMBED (content)), G_CALLBACK (download_only_load_cb), window);
tab_accels_update (window);
- if (gtk_notebook_get_n_pages (window->notebook) == 0) {
+ if (ephy_tab_view_get_n_pages (window->tab_view) == 0) {
EphyShell *shell = ephy_shell_get_default ();
GList *windows = gtk_application_get_windows (GTK_APPLICATION (shell));
@@ -2925,7 +2867,7 @@ ephy_window_close_tab (EphyWindow *window,
if (mode != EPHY_EMBED_SHELL_MODE_AUTOMATION)
keep_window_open = g_settings_get_boolean (EPHY_SETTINGS_UI, EPHY_PREFS_UI_KEEP_WINDOW_OPEN);
- if (keep_window_open && gtk_notebook_get_n_pages (window->notebook) == 1) {
+ if (keep_window_open && ephy_tab_view_get_n_pages (window->tab_view) == 1) {
EphyWebView *view = ephy_embed_get_web_view (tab);
if (ephy_web_view_get_is_blank (view) || ephy_web_view_is_overview (view))
@@ -2946,26 +2888,30 @@ ephy_window_close_tab (EphyWindow *window,
* Beware: window->closing could be true now, after destroying the
* tab, even if it wasn't at the start of this function.
*/
- if (!window->closing && gtk_notebook_get_n_pages (window->notebook) == 0)
+ if (!window->closing && ephy_tab_view_get_n_pages (window->tab_view) == 0)
gtk_widget_destroy (GTK_WIDGET (window));
}
typedef struct {
EphyWindow *window;
EphyEmbed *embed;
+ HdyTabPage *page;
guint id;
} TabHasModifiedFormsData;
static TabHasModifiedFormsData *
tab_has_modified_forms_data_new (EphyWindow *window,
- EphyEmbed *embed)
+ EphyEmbed *embed,
+ HdyTabPage *page)
{
TabHasModifiedFormsData *data = g_new (TabHasModifiedFormsData, 1);
data->window = window;
data->embed = embed;
+ data->page = page;
data->id = 0;
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&data->window);
g_object_add_weak_pointer (G_OBJECT (embed), (gpointer *)&data->embed);
+ g_object_add_weak_pointer (G_OBJECT (page), (gpointer *)&data->page);
return data;
}
@@ -2974,6 +2920,7 @@ tab_has_modified_forms_data_free (TabHasModifiedFormsData *data)
{
g_clear_weak_pointer (&data->window);
g_clear_weak_pointer (&data->embed);
+ g_clear_weak_pointer (&data->page);
g_clear_handle_id (&data->id, g_source_remove);
g_clear_pointer (&data, g_free);
}
@@ -2994,9 +2941,14 @@ tab_has_modified_forms_cb (EphyWebView *view,
if (data->id != 0 &&
data->window != NULL &&
- data->embed != NULL &&
- (!has_modified_forms || confirm_close_with_modified_forms (data->window))) {
- ephy_window_close_tab (data->window, data->embed);
+ data->embed != NULL) {
+ HdyTabView *tab_view = ephy_tab_view_get_tab_view (data->window->tab_view);
+
+ if (!has_modified_forms || confirm_close_with_modified_forms (data->window)) {
+ ephy_tab_view_close (data->window->tab_view, GTK_WIDGET (data->embed));
+ hdy_tab_view_close_page_finish (tab_view, data->page, TRUE);
+ } else
+ hdy_tab_view_close_page_finish (tab_view, data->page, FALSE);
}
data->id = 0;
@@ -3013,8 +2965,12 @@ tab_has_modified_forms_timeout_cb (TabHasModifiedFormsData *data)
* ephy_window_close_tab().
*/
data->id = 0;
- if (data->window != NULL && data->embed != NULL)
- ephy_window_close_tab (data->window, data->embed);
+ if (data->window != NULL && data->embed != NULL) {
+ HdyTabView *tab_view = ephy_tab_view_get_tab_view (data->window->tab_view);
+
+ ephy_tab_view_close (data->window->tab_view, GTK_WIDGET (data->embed));
+ hdy_tab_view_close_page_finish (tab_view, data->page, TRUE);
+ }
return G_SOURCE_REMOVE;
}
@@ -3040,15 +2996,18 @@ run_downloads_in_background (EphyWindow *window,
gtk_widget_hide (GTK_WIDGET (window));
}
-static void
-notebook_page_close_request_cb (EphyNotebook *notebook,
- EphyEmbed *embed,
- EphyWindow *window)
+static gboolean
+tab_view_close_page_cb (HdyTabView *tab_view,
+ HdyTabPage *page,
+ EphyWindow *window)
{
- if (gtk_notebook_get_n_pages (window->notebook) == 1) {
+ EphyEmbed *embed = EPHY_EMBED (hdy_tab_page_get_content (page));
+
+ if (ephy_tab_view_get_n_pages (window->tab_view) == 1) {
if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
EPHY_PREFS_LOCKDOWN_QUIT)) {
- return;
+ hdy_tab_view_close_page_finish (tab_view, page, FALSE);
+ return GDK_EVENT_STOP;
}
if (ephy_embed_shell_get_mode (ephy_embed_shell_get_default ()) == EPHY_EMBED_SHELL_MODE_AUTOMATION) {
@@ -3063,7 +3022,8 @@ notebook_page_close_request_cb (EphyNotebook *notebook,
if (ephy_downloads_manager_has_active_downloads (manager)) {
GList *list = ephy_downloads_manager_get_downloads (manager);
run_downloads_in_background (window, g_list_length (list));
- return;
+ hdy_tab_view_close_page_finish (tab_view, page, FALSE);
+ return GDK_EVENT_STOP;
}
}
}
@@ -3078,23 +3038,23 @@ notebook_page_close_request_cb (EphyNotebook *notebook,
* also be caused by a network process hang!) We'll assume the process has
* been hung if there's no response after one second.
*/
- data = tab_has_modified_forms_data_new (window, embed);
+ data = tab_has_modified_forms_data_new (window, embed, page);
data->id = g_timeout_add_seconds (1, (GSourceFunc)tab_has_modified_forms_timeout_cb, data);
ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed),
NULL,
(GAsyncReadyCallback)tab_has_modified_forms_cb,
data);
+ return GDK_EVENT_STOP;
} else {
ephy_window_close_tab (window, embed);
}
+
+ return GDK_EVENT_PROPAGATE;
}
-static GtkWidget *
-notebook_create_window_cb (GtkNotebook *notebook,
- GtkWidget *page,
- int x,
- int y,
- EphyWindow *window)
+static HdyTabView *
+tab_view_create_window_cb (HdyTabView *tab_view,
+ EphyWindow *window)
{
EphyWindow *new_window;
@@ -3103,24 +3063,7 @@ notebook_create_window_cb (GtkNotebook *notebook,
new_window->present_on_insert = TRUE;
new_window->present_on_insert_user_time = gtk_get_current_event_time ();
- return ephy_window_get_notebook (new_window);
-}
-
-static EphyEmbed *
-real_get_active_tab (EphyWindow *window,
- int page_num)
-{
- GtkWidget *embed;
-
- if (page_num == -1) {
- page_num = gtk_notebook_get_current_page (window->notebook);
- }
-
- embed = gtk_notebook_get_nth_page (window->notebook, page_num);
-
- g_assert (EPHY_IS_EMBED (embed));
-
- return EPHY_EMBED (embed);
+ return ephy_tab_view_get_tab_view (new_window->tab_view);
}
void
@@ -3143,81 +3086,85 @@ ephy_window_update_entry_focus (EphyWindow *window,
}
static void
-notebook_switch_page_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint page_num,
- EphyWindow *window)
+tab_view_notify_selected_page_cb (EphyWindow *window)
{
EphyEmbed *embed;
- GActionGroup *group;
- GAction *action;
EphyWebView *view;
-
- LOG ("switch-page notebook %p position %u\n", notebook, page_num);
+ int page_num;
if (window->closing)
return;
+ page_num = ephy_tab_view_get_selected_index (window->tab_view);
+
+ LOG ("switch-page tab view %p position %d\n", window->tab_view, page_num);
+
/* get the new tab */
- embed = real_get_active_tab (window, page_num);
+
+ embed = EPHY_EMBED (ephy_tab_view_get_nth_page (window->tab_view, page_num));
view = ephy_embed_get_web_view (embed);
/* update new tab */
ephy_window_set_active_tab (window, embed);
- /* update notebook menu */
- group = gtk_widget_get_action_group (GTK_WIDGET (window), "win");
- action = g_action_map_lookup_action (G_ACTION_MAP (group), "show-tab");
- g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_uint32 (page_num));
-
update_reader_mode (window, view);
ephy_window_update_entry_focus (window, view);
}
static void
-notebook_page_reordered_cb (GtkNotebook *notebook,
- GtkWidget *child,
- guint page_num,
- gpointer user_data)
+tab_view_page_reordered_cb (EphyWindow *window)
{
- EphyWindow *window = EPHY_WINDOW (user_data);
-
window->last_opened_embed = NULL;
}
-static GtkNotebook *
-setup_notebook (EphyWindow *window)
+static EphyTabView *
+setup_tab_view (EphyWindow *window)
{
- GtkNotebook *notebook;
+ EphyTabView *tab_view = ephy_tab_view_new ();
+ HdyTabView *view = ephy_tab_view_get_tab_view (tab_view);
+ g_autoptr (GtkBuilder) builder = NULL;
- notebook = GTK_NOTEBOOK (g_object_new (EPHY_TYPE_NOTEBOOK, NULL));
-
- g_signal_connect_after (notebook, "switch-page",
- G_CALLBACK (notebook_switch_page_cb),
- window);
- g_signal_connect (notebook, "create-window",
- G_CALLBACK (notebook_create_window_cb),
- window);
-
- g_signal_connect (notebook, "popup-menu",
- G_CALLBACK (notebook_popup_menu_cb), window);
- g_signal_connect (notebook, "button-press-event",
- G_CALLBACK (notebook_button_press_cb), window);
+ builder = gtk_builder_new_from_resource ("/org/gnome/epiphany/gtk/notebook-context-menu.ui");
- g_signal_connect (notebook, "page-added",
- G_CALLBACK (notebook_page_added_cb), window);
- g_signal_connect (notebook, "page-removed",
- G_CALLBACK (notebook_page_removed_cb), window);
- g_signal_connect (notebook, "tab-close-request",
- G_CALLBACK (notebook_page_close_request_cb), window);
- g_signal_connect (notebook, "page-reordered",
- G_CALLBACK (notebook_page_reordered_cb), window);
+ hdy_tab_view_set_menu_model (view, G_MENU_MODEL (gtk_builder_get_object (builder, "notebook-menu")));
+
+ g_signal_connect_object (view, "notify::selected-page",
+ G_CALLBACK (tab_view_notify_selected_page_cb),
+ window,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (view, "create-window",
+ G_CALLBACK (tab_view_create_window_cb),
+ window,
+ 0);
+ g_signal_connect_object (view, "setup-menu",
+ G_CALLBACK (tab_view_setup_menu_cb),
+ window,
+ 0);
+ g_signal_connect_object (view, "close-page",
+ G_CALLBACK (tab_view_close_page_cb),
+ window,
+ 0);
+
+ g_signal_connect_object (view, "page-added",
+ G_CALLBACK (tab_view_page_added_cb),
+ window,
+ 0);
+ g_signal_connect_object (view, "page-removed",
+ G_CALLBACK (tab_view_page_removed_cb),
+ window,
+ 0);
+ g_signal_connect_object (view, "page-reordered",
+ G_CALLBACK (tab_view_page_reordered_cb),
+ window,
+ G_CONNECT_SWAPPED);
+/*
g_signal_connect_swapped (notebook, "open-link",
G_CALLBACK (ephy_link_open), window);
-
- return notebook;
+*/
+ return tab_view;
}
static void
@@ -3810,11 +3757,15 @@ ephy_window_constructed (GObject *object)
/* Setup tab accels */
setup_tab_accels (window);
- window->notebook = setup_notebook (window);
+ window->tab_view = setup_tab_view (window);
+ window->tab_bar = hdy_tab_bar_new ();
+ window->tab_bar_revealer = GTK_REVEALER (gtk_revealer_new ());
window->main_deck = hdy_deck_new ();
window->pages_view = ephy_pages_view_new ();
- ephy_pages_view_set_notebook (window->pages_view, EPHY_NOTEBOOK (window->notebook));
+ gtk_revealer_set_transition_type (window->tab_bar_revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
+ hdy_tab_bar_set_view (window->tab_bar, ephy_tab_view_get_tab_view (window->tab_view));
+ ephy_pages_view_set_tab_view (window->pages_view, window->tab_view);
shell = ephy_shell_get_default ();
mode = ephy_embed_shell_get_mode (EPHY_EMBED_SHELL (shell));
@@ -3836,7 +3787,9 @@ ephy_window_constructed (GObject *object)
!ephy_profile_dir_is_web_application ())
add_default_browser_question (box);
- gtk_box_pack_start (box, GTK_WIDGET (window->notebook), TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (window->tab_bar_revealer), GTK_WIDGET (window->tab_bar));
+ gtk_box_pack_start (box, GTK_WIDGET (window->tab_bar_revealer), FALSE, TRUE, 0);
+ gtk_box_pack_start (box, GTK_WIDGET (window->tab_view), TRUE, TRUE, 0);
gtk_box_pack_start (box, GTK_WIDGET (window->action_bar), FALSE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (window->main_deck), GTK_WIDGET (box));
gtk_container_add (GTK_CONTAINER (window->main_deck), GTK_WIDGET (window->pages_view));
@@ -3844,7 +3797,9 @@ ephy_window_constructed (GObject *object)
gtk_widget_show_all (GTK_WIDGET (window->pages_view));
gtk_widget_show (GTK_WIDGET (window->main_deck));
gtk_widget_show (GTK_WIDGET (box));
- gtk_widget_show (GTK_WIDGET (window->notebook));
+ gtk_widget_show (GTK_WIDGET (window->tab_view));
+ gtk_widget_show (GTK_WIDGET (window->tab_bar));
+ gtk_widget_show (GTK_WIDGET (window->tab_bar_revealer));
hdy_deck_set_visible_child (HDY_DECK (window->main_deck), GTK_WIDGET (box));
hdy_deck_set_can_swipe_back (HDY_DECK (window->main_deck), TRUE);
@@ -3994,19 +3949,19 @@ ephy_window_new (void)
}
/**
- * ephy_window_get_notebook:
+ * ephy_window_get_tab_view:
* @window: an #EphyWindow
*
- * Returns the #GtkNotebook used by this window.
+ * Returns the #EphyTabView used by this window.
*
- * Return value: (transfer none): the @window's #GtkNotebook
+ * Return value: (transfer none): the @window's #EphyTabView
**/
-GtkWidget *
-ephy_window_get_notebook (EphyWindow *window)
+EphyTabView *
+ephy_window_get_tab_view (EphyWindow *window)
{
g_assert (EPHY_IS_WINDOW (window));
- return GTK_WIDGET (window->notebook);
+ return window->tab_view;
}
/**
@@ -4325,7 +4280,7 @@ ephy_window_check_modified_forms (EphyWindow *window)
data = g_new0 (ModifiedFormsData, 1);
data->window = window;
data->cancellable = g_cancellable_new ();
- data->embeds_to_check = gtk_notebook_get_n_pages (window->notebook);
+ data->embeds_to_check = ephy_tab_view_get_n_pages (window->tab_view);
tabs = impl_get_children (EPHY_EMBED_CONTAINER (window));
for (l = tabs; l != NULL; l = l->next) {
@@ -4375,7 +4330,7 @@ ephy_window_close (EphyWindow *window)
if (!window->force_close &&
g_settings_get_boolean (EPHY_SETTINGS_MAIN,
EPHY_PREFS_WARN_ON_CLOSE_UNSUBMITTED_DATA) &&
- gtk_notebook_get_n_pages (window->notebook) > 0) {
+ ephy_tab_view_get_n_pages (window->tab_view) > 0) {
ephy_window_check_modified_forms (window);
/* stop window close */
return FALSE;
@@ -4383,7 +4338,7 @@ ephy_window_close (EphyWindow *window)
session = ephy_shell_get_session (ephy_shell_get_default ());
if (ephy_shell_get_n_windows (ephy_shell_get_default ()) > 1 &&
- gtk_notebook_get_n_pages (window->notebook) > 1 &&
+ ephy_tab_view_get_n_pages (window->tab_view) > 1 &&
!ephy_session_is_closing (session) &&
!confirm_close_with_multiple_tabs (window)) {
/* stop window close */
@@ -4432,25 +4387,16 @@ int
ephy_window_get_position_for_new_embed (EphyWindow *window,
EphyEmbed *embed)
{
- GtkWidget *notebook = ephy_window_get_notebook (window);
+ HdyTabView *view = ephy_tab_view_get_tab_view (window->tab_view);
+ HdyTabPage *page;
int position;
if (embed == window->last_opened_embed)
return window->last_opened_pos++;
- position = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), GTK_WIDGET (embed)) + 1;
-
- /* Loop through all pages and skip all pinned tabs */
- do {
- GtkWidget *page;
-
- page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), position);
- if (!page)
- break;
-
- if (!ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), EPHY_EMBED (page)))
- break;
- } while (++position < gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)));
+ page = hdy_tab_view_get_page (view, GTK_WIDGET (embed));
+ position = hdy_tab_view_get_page_position (view, page) + 1;
+ position = MAX (position, hdy_tab_view_get_n_pinned_pages (view));
if (window->last_opened_embed)
g_object_remove_weak_pointer (G_OBJECT (window->last_opened_embed), (gpointer
*)&window->last_opened_embed);
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 01c272846..893dfed69 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -24,6 +24,7 @@
#include "ephy-embed.h"
#include "ephy-embed-event.h"
#include "ephy-location-controller.h"
+#include "ephy-tab-view.h"
#include "ephy-web-view.h"
#include <gtk/gtk.h>
@@ -46,7 +47,7 @@ typedef enum
EphyWindow *ephy_window_new (void);
-GtkWidget *ephy_window_get_notebook (EphyWindow *window);
+EphyTabView *ephy_window_get_tab_view (EphyWindow *window);
void ephy_window_open_pages_view (EphyWindow *window);
void ephy_window_close_pages_view (EphyWindow *window);
diff --git a/src/meson.build b/src/meson.build
index c25d88eff..a8aabbbe1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -32,14 +32,13 @@ libephymain_sources = [
'ephy-location-controller.c',
'ephy-lockdown.c',
'ephy-mouse-gesture-controller.c',
- 'ephy-notebook.c',
'ephy-page-row.c',
'ephy-pages-button.c',
- 'ephy-pages-popover.c',
'ephy-pages-view.c',
'ephy-session.c',
'ephy-shell.c',
'ephy-suggestion-model.c',
+ 'ephy-tab-view.c',
'ephy-tab-header-bar.c',
'ephy-tab-label.c',
'ephy-window.c',
diff --git a/src/window-commands.c b/src/window-commands.c
index fd4dafcfa..177bb749d 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -46,13 +46,13 @@
#include "ephy-history-dialog.h"
#include "ephy-link.h"
#include "ephy-location-entry.h"
-#include "ephy-notebook.h"
#include "ephy-password-import.h"
#include "ephy-prefs.h"
#include "ephy-session.h"
#include "ephy-settings.h"
#include "ephy-shell.h"
#include "ephy-string.h"
+#include "ephy-tab-view.h"
#include "ephy-view-source-handler.h"
#include "ephy-web-app-utils.h"
#include "ephy-zoom.h"
@@ -2640,80 +2640,21 @@ window_cmd_change_fullscreen_state (GSimpleAction *action,
g_simple_action_set_state (action, g_variant_new_boolean (active));
}
-void
-window_cmd_tabs_previous (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GtkWidget *nb;
-
- nb = ephy_window_get_notebook (EPHY_WINDOW (user_data));
- g_assert (nb != NULL);
-
- ephy_notebook_prev_page (EPHY_NOTEBOOK (nb));
-}
-
-void
-window_cmd_tabs_next (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GtkWidget *nb;
-
- nb = ephy_window_get_notebook (EPHY_WINDOW (user_data));
- g_assert (nb != NULL);
-
- ephy_notebook_next_page (EPHY_NOTEBOOK (nb));
-}
-
-void
-window_cmd_tabs_move_left (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GtkWidget *child;
- GtkNotebook *notebook;
- int page;
-
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
- page = gtk_notebook_get_current_page (notebook);
- if (page < 1)
- return;
-
- child = gtk_notebook_get_nth_page (notebook, page);
- gtk_notebook_reorder_child (notebook, child, page - 1);
-}
-
-void window_cmd_tabs_move_right (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- GtkWidget *child;
- GtkNotebook *notebook;
- int page, n_pages;
-
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
- page = gtk_notebook_get_current_page (notebook);
- n_pages = gtk_notebook_get_n_pages (notebook) - 1;
- if (page > n_pages - 1)
- return;
-
- child = gtk_notebook_get_nth_page (notebook, page);
- gtk_notebook_reorder_child (notebook, child, page + 1);
-}
-
void
window_cmd_tabs_duplicate (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
+ EphyTabView *tab_view;
EphyEmbed *embed, *new_embed;
WebKitWebView *view, *new_view;
WebKitWebViewSessionState *session_state;
WebKitBackForwardList *bf_list;
WebKitBackForwardListItem *item;
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (user_data));
+ tab_view = ephy_window_get_tab_view (EPHY_WINDOW (user_data));
+ embed = EPHY_EMBED (ephy_tab_view_get_current_page (tab_view));
+
view = WEBKIT_WEB_VIEW (ephy_embed_get_web_view (embed));
session_state = webkit_web_view_get_session_state (view);
@@ -2735,56 +2676,23 @@ window_cmd_tabs_duplicate (GSimpleAction *action,
ephy_web_view_load_url (EPHY_WEB_VIEW (new_view), webkit_web_view_get_uri (view));
}
-void
-window_cmd_tabs_detach (GSimpleAction *action,
- GVariant *variant,
- gpointer user_data)
-{
- EphyEmbed *embed;
- GtkNotebook *notebook;
- EphyWindow *new_window;
-
- notebook = GTK_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (user_data)));
- if (gtk_notebook_get_n_pages (notebook) <= 1)
- return;
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (user_data));
-
- g_object_ref_sink (embed);
- gtk_notebook_remove_page (notebook, gtk_notebook_page_num (notebook, GTK_WIDGET (embed)));
-
- new_window = ephy_window_new ();
- ephy_embed_container_add_child (EPHY_EMBED_CONTAINER (new_window), embed, 0, FALSE);
- g_object_unref (embed);
-
- gtk_window_present_with_time (GTK_WINDOW (new_window), gtk_get_current_event_time ());
-}
-
void
window_cmd_tabs_close (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
EphyWindow *window = user_data;
- GtkWidget *notebook;
- EphyEmbed *embed;
- gboolean pinned;
+ EphyTabView *tab_view;
- notebook = ephy_window_get_notebook (window);
+ tab_view = ephy_window_get_tab_view (window);
if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
EPHY_PREFS_LOCKDOWN_QUIT) &&
- gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) == 1) {
+ ephy_tab_view_get_n_pages (tab_view) <= 1) {
return;
}
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
- g_assert (embed != NULL);
-
- pinned = ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), embed);
-
- if (!pinned)
- g_signal_emit_by_name (notebook, "tab-close-request", embed);
+ ephy_tab_view_close_selected (tab_view);
}
void
@@ -2793,27 +2701,8 @@ window_cmd_tabs_close_left (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = user_data;
- GtkWidget *notebook;
- EphyEmbed *embed;
- int current_page_no;
- GSList *pages_to_close = NULL;
-
- notebook = ephy_window_get_notebook (window);
- current_page_no = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-
- for (int i = 0; i < current_page_no; i++) {
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
-
- if (!ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), embed))
- pages_to_close = g_slist_prepend (pages_to_close, embed);
- }
- for (GSList *l = pages_to_close; l != NULL; l = l->next) {
- g_assert (l->data != NULL);
- g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", l->data);
- }
-
- g_slist_free (pages_to_close);
+ ephy_tab_view_close_left (ephy_window_get_tab_view (window));
}
void
@@ -2822,28 +2711,8 @@ window_cmd_tabs_close_right (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = user_data;
- GtkWidget *notebook;
- EphyEmbed *embed;
- int n_pages, current_page_no;
- GSList *pages_to_close = NULL;
-
- notebook = ephy_window_get_notebook (window);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- current_page_no = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
-
- for (int i = current_page_no + 1; i < n_pages; i++) {
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
-
- if (!ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), embed))
- pages_to_close = g_slist_prepend (pages_to_close, embed);
- }
- for (GSList *l = pages_to_close; l != NULL; l = l->next) {
- g_assert (l->data != NULL);
- g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", l->data);
- }
-
- g_slist_free (pages_to_close);
+ ephy_tab_view_close_right (ephy_window_get_tab_view (window));
}
void
@@ -2852,30 +2721,8 @@ window_cmd_tabs_close_others (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = user_data;
- GtkWidget *notebook;
- EphyEmbed *embed;
- int n_pages, current_page;
- GSList *pages_to_close = NULL;
-
- notebook = ephy_window_get_notebook (window);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- for (int i = 0; i < n_pages; i++) {
- if (i != current_page) {
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
-
- if (!ephy_notebook_tab_is_pinned (EPHY_NOTEBOOK (notebook), embed))
- pages_to_close = g_slist_prepend (pages_to_close, embed);
- }
- }
-
- for (GSList *l = pages_to_close; l != NULL; l = l->next) {
- g_assert (l->data != NULL);
- g_signal_emit_by_name (GTK_NOTEBOOK (notebook), "tab-close-request", l->data);
- }
-
- g_slist_free (pages_to_close);
+ ephy_tab_view_close_other (ephy_window_get_tab_view (window));
}
void
@@ -2887,7 +2734,7 @@ window_cmd_tabs_reload (GSimpleAction *action,
EphyEmbed *embed;
WebKitWebView *view;
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
+ embed = EPHY_EMBED (ephy_tab_view_get_current_page (ephy_window_get_tab_view (window)));
g_assert (embed != NULL);
gtk_widget_grab_focus (GTK_WIDGET (embed));
@@ -2896,26 +2743,26 @@ window_cmd_tabs_reload (GSimpleAction *action,
webkit_web_view_reload (view);
}
+static void
+reload_cb (GtkWidget *widget,
+ gpointer user_data)
+{
+ EphyEmbed *embed = EPHY_EMBED (widget);
+ WebKitWebView *view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
+
+ webkit_web_view_reload (view);
+}
+
void
window_cmd_tabs_reload_all_tabs (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
EphyWindow *window = user_data;
- EphyEmbed *embed;
- WebKitWebView *view;
- GtkWidget *notebook;
- int n_pages;
-
- notebook = ephy_window_get_notebook (window);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- for (int i = 0; i < n_pages; i++) {
- embed = EPHY_EMBED (gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), i));
-
- view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
- webkit_web_view_reload (view);
- }
+ ephy_tab_view_foreach (ephy_window_get_tab_view (window),
+ reload_cb,
+ NULL);
}
void
@@ -2929,31 +2776,6 @@ window_cmd_tabs_reopen_closed_tab (GSimpleAction *action,
ephy_session_undo_close_tab (session);
}
-void
-window_cmd_show_tab (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
-{
- EphyWindow *window = EPHY_WINDOW (user_data);
- GtkWidget *notebook;
- guint32 tab_num;
-
- g_assert (g_variant_is_of_type (parameter, G_VARIANT_TYPE_UINT32));
- tab_num = g_variant_get_uint32 (parameter);
-
- notebook = ephy_window_get_notebook (window);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_num);
- g_simple_action_set_state (action, parameter);
-}
-
-void
-window_cmd_change_show_tab_state (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
-{
- /* This page intentionally left blank. */
-}
-
void
window_cmd_toggle_reader_mode (GSimpleAction *action,
GVariant *parameter,
@@ -3066,15 +2888,8 @@ window_cmd_tabs_pin (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = EPHY_WINDOW (user_data);
- EphyEmbed *embed;
- EphyNotebook *notebook;
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
- g_assert (embed != NULL);
- notebook = EPHY_NOTEBOOK (ephy_window_get_notebook (window));
-
- ephy_notebook_tab_set_pinned (notebook, GTK_WIDGET (embed), TRUE);
+ ephy_tab_view_pin (ephy_window_get_tab_view (window));
}
void
@@ -3083,13 +2898,6 @@ window_cmd_tabs_unpin (GSimpleAction *action,
gpointer user_data)
{
EphyWindow *window = EPHY_WINDOW (user_data);
- EphyEmbed *embed;
- EphyNotebook *notebook;
-
- embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
- g_assert (embed != NULL);
-
- notebook = EPHY_NOTEBOOK (ephy_window_get_notebook (window));
- ephy_notebook_tab_set_pinned (notebook, GTK_WIDGET (embed), FALSE);
+ ephy_tab_view_unpin (ephy_window_get_tab_view (window));
}
diff --git a/src/window-commands.h b/src/window-commands.h
index ca80dcf63..0959df2a1 100644
--- a/src/window-commands.h
+++ b/src/window-commands.h
@@ -176,24 +176,9 @@ void window_cmd_change_browse_with_caret_state (GSimpleAction *action,
void window_cmd_change_fullscreen_state (GSimpleAction *action,
GVariant *state,
gpointer user_data);
-void window_cmd_tabs_previous (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-void window_cmd_tabs_next (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-void window_cmd_tabs_move_left (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-void window_cmd_tabs_move_right (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
void window_cmd_tabs_duplicate (GSimpleAction *action,
GVariant *state,
gpointer user_data);
-void window_cmd_tabs_detach (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
void window_cmd_tabs_close (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]