[epiphany] window-commands: switch pages using the EphyNotebook API
- From: Xan Lopez <xan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] window-commands: switch pages using the EphyNotebook API
- Date: Mon, 16 Apr 2012 13:54:01 +0000 (UTC)
commit 6e45bec38cc6696c2cc789403082368fcdbcd68f
Author: Xan Lopez <xan igalia com>
Date: Mon Apr 16 14:03:19 2012 +0200
window-commands: switch pages using the EphyNotebook API
The signal we were using does not work when the tabs bar is hidden,
and we'll want the shortcuts to work in that state. Add new
EphyNotebooks methods that do the right thing and use them.
src/ephy-notebook.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/ephy-notebook.h | 4 +++
src/window-commands.c | 14 ++++------
3 files changed, 73 insertions(+), 9 deletions(-)
---
diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c
index 22465ad..5614ca7 100644
--- a/src/ephy-notebook.c
+++ b/src/ephy-notebook.c
@@ -396,7 +396,6 @@ static void
update_tabs_visibility (EphyNotebook *nb,
gboolean before_inserting)
{
- EphyNotebookPrivate *priv = nb->priv;
EphyEmbedShellMode mode;
gboolean show_tabs;
guint num;
@@ -777,3 +776,66 @@ ephy_notebook_remove (GtkContainer *container,
update_tabs_visibility (notebook, FALSE);
}
+
+/**
+ * ephy_notebook_next_page:
+ * @notebook: an #EphyNotebook
+ *
+ * Advances to the next page in the @notebook. Note that unlike
+ * gtk_notebook_next_page() this method will wrap around if
+ * #GtkSettings:gtk-keynav-wrap-around is set.
+ **/
+void
+ephy_notebook_next_page (EphyNotebook *notebook)
+{
+ gint current_page, n_pages;
+
+ g_return_if_fail (EPHY_IS_NOTEBOOK (notebook));
+
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+
+ if (current_page < n_pages - 1)
+ gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
+ else {
+ gboolean wrap_around;
+
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+ "gtk-keynav-wrap-around", &wrap_around,
+ NULL);
+
+ if (wrap_around)
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
+ }
+}
+
+/**
+ * ephy_notebook_prev_page:
+ * @notebook: an #EphyNotebook
+ *
+ * Advances to the previous page in the @notebook. Note that unlike
+ * gtk_notebook_next_page() this method will wrap around if
+ * #GtkSettings:gtk-keynav-wrap-around is set.
+ **/
+void
+ephy_notebook_prev_page (EphyNotebook *notebook)
+{
+ gint current_page;
+
+ g_return_if_fail (EPHY_IS_NOTEBOOK (notebook));
+
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+
+ if (current_page > 0)
+ gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
+ else {
+ gboolean wrap_around;
+
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+ "gtk-keynav-wrap-around", &wrap_around,
+ NULL);
+
+ if (wrap_around)
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), -1);
+ }
+}
diff --git a/src/ephy-notebook.h b/src/ephy-notebook.h
index 19e07ed..609b0f9 100644
--- a/src/ephy-notebook.h
+++ b/src/ephy-notebook.h
@@ -71,6 +71,10 @@ int ephy_notebook_add_tab (EphyNotebook *nb,
void ephy_notebook_set_show_tabs (EphyNotebook *nb,
gboolean show_tabs);
+void ephy_notebook_next_page (EphyNotebook *notebook);
+
+void ephy_notebook_prev_page (EphyNotebook *notebook);
+
G_END_DECLS
#endif /* EPHY_NOTEBOOK_H */
diff --git a/src/window-commands.c b/src/window-commands.c
index 1443e5d..e32bd5b 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1244,26 +1244,24 @@ void
window_cmd_tabs_next (GtkAction *action,
EphyWindow *window)
{
- GtkNotebook *nb;
- gboolean handled;
+ GtkWidget *nb;
- nb = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ nb = ephy_window_get_notebook (window);
g_return_if_fail (nb != NULL);
- g_signal_emit_by_name (nb, "change-current-page", 1, &handled);
+ ephy_notebook_next_page (EPHY_NOTEBOOK (nb));
}
void
window_cmd_tabs_previous (GtkAction *action,
EphyWindow *window)
{
- GtkNotebook *nb;
- gboolean handled;
+ GtkWidget *nb;
- nb = GTK_NOTEBOOK (ephy_window_get_notebook (window));
+ nb = ephy_window_get_notebook (window);
g_return_if_fail (nb != NULL);
- g_signal_emit_by_name (nb, "change-current-page", -1, &handled);
+ ephy_notebook_prev_page (EPHY_NOTEBOOK (nb));
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]