[evince/wip/recent-view: 6/12] shell: Allow switching between document and bookshelf
- From: Germán Poó Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/recent-view: 6/12] shell: Allow switching between document and bookshelf
- Date: Mon, 24 Feb 2014 04:05:04 +0000 (UTC)
commit 9a77d912ed29f93a79c353da1356f8755f4d166a
Author: Aakash Goenka <aakash goenka gmail com>
Date: Sun Feb 23 15:37:24 2014 -0800
shell: Allow switching between document and bookshelf
Partly implemented switching between document and bookshelf using a
button.
It seems more natural as we 'toggle' between the bookshelf the
currently open document.
Also fixed sensitivity of the button when Evince is loaded without
a document.
shell/ev-application.c | 3 +-
shell/ev-toolbar.c | 10 ++++++
shell/ev-window.c | 76 ++++++++++++++++++++++++++++-------------------
shell/ev-window.h | 3 +-
4 files changed, 58 insertions(+), 34 deletions(-)
---
diff --git a/shell/ev-application.c b/shell/ev-application.c
index 86ea9f5..5c34dca 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -654,7 +654,8 @@ ev_application_open_window (EvApplication *application,
GdkScreen *screen,
guint32 timestamp)
{
- GtkWidget *new_window = ev_window_new_with_bookshelf ();
+ GtkWidget *new_window = ev_window_new ();
+ ev_window_show_bookshelf (new_window);
#ifdef GDK_WINDOWING_X11
GdkWindow *gdk_window;
#endif
diff --git a/shell/ev-toolbar.c b/shell/ev-toolbar.c
index f9f87e6..aac0a24 100644
--- a/shell/ev-toolbar.c
+++ b/shell/ev-toolbar.c
@@ -158,6 +158,16 @@ ev_toolbar_constructed (GObject *object)
action_group = ev_window_get_main_action_group (ev_toolbar->priv->window);
ui_manager = ev_window_get_ui_manager (ev_toolbar->priv->window);
+ /* Bookshelf */
+ action = gtk_action_group_get_action (action_group, "ViewBookshelf");
+ button = ev_toolbar_create_toggle_button (ev_toolbar, action);
+ tool_item = GTK_WIDGET (gtk_tool_item_new ());
+ gtk_container_add (GTK_CONTAINER (tool_item), button);
+ gtk_widget_show (button);
+ gtk_widget_set_margin_right (tool_item, 12);
+ gtk_container_add (GTK_CONTAINER (ev_toolbar), tool_item);
+ gtk_widget_show (tool_item);
+
/* Navigation */
hbox = ev_toolbar_create_button_group (ev_toolbar);
diff --git a/shell/ev-window.c b/shell/ev-window.c
index c539e8e..003252e 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -429,7 +429,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
gboolean has_pages = FALSE;
gboolean can_find = FALSE;
- if (document) {
+ if (document && !ev_window->priv->bookshelf) {
has_document = TRUE;
has_pages = ev_document_get_n_pages (document) > 0;
info = ev_document_get_info (document);
@@ -504,6 +504,7 @@ ev_window_setup_action_sensitivity (EvWindow *ev_window)
/* Toolbar-specific actions: */
ev_window_set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages);
ev_window_set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages);
+ ev_window_set_action_sensitive (ev_window, HISTORY_ACTION, has_document);
ev_window_update_actions_sensitivity (ev_window);
}
@@ -518,13 +519,16 @@ ev_window_update_actions_sensitivity (EvWindow *ev_window)
gboolean can_find_in_page = FALSE;
gboolean dual_mode = FALSE;
- if (ev_window->priv->document) {
+ if (ev_window->priv->document && !ev_window->priv->bookshelf) {
page = ev_document_model_get_page (ev_window->priv->model);
n_pages = ev_document_get_n_pages (ev_window->priv->document);
has_pages = n_pages > 0;
dual_mode = ev_document_model_get_dual_page (ev_window->priv->model);
}
+ ev_window_set_action_sensitive (ev_window, "ViewBookshelf",
+ ev_window->priv->document ||
+ !ev_window->priv->bookshelf);
can_find_in_page = (ev_window->priv->find_job &&
ev_job_find_has_results (EV_JOB_FIND (ev_window->priv->find_job)));
@@ -1662,12 +1666,11 @@ ev_window_load_job_cb (EvJob *job,
g_assert (job_load->uri);
ev_window_hide_loading_message (ev_window);
+ ev_window_try_swap_out_bookshelf (ev_window);
/* Success! */
if (!ev_job_is_failed (job)) {
- ev_window_try_swap_out_bookshelf (ev_window);
-
ev_document_model_set_document (ev_window->priv->model, document);
#ifdef ENABLE_DBUS
@@ -4717,6 +4720,19 @@ ev_window_cmd_bookmark_activate (GtkAction *action,
ev_document_model_set_page (window->priv->model, page);
}
+static void
+ev_window_cmd_toggle_bookshelf (GtkAction *action,
+ EvWindow *ev_window)
+{
+ if (!ev_window->priv->bookshelf)
+ ev_window_show_bookshelf (ev_window);
+ else {
+ ev_window_try_swap_out_bookshelf (ev_window);
+ ev_window_setup_action_sensitivity (ev_window);
+ }
+ return;
+}
+
static gint
compare_bookmarks (EvBookmark *a,
EvBookmark *b)
@@ -5371,19 +5387,13 @@ find_sidebar_result_activated_cb (EvFindSidebar *find_sidebar,
static void
ev_window_try_swap_out_bookshelf (EvWindow *ev_window)
{
- GtkWidget *widget;
-
- widget = gtk_bin_get_child (GTK_BIN (ev_window->priv->scrolled_window));
-
if (ev_window->priv->bookshelf)
{
- gtk_container_remove (GTK_CONTAINER (ev_window->priv->scrolled_window), widget);
+ gtk_widget_hide (GTK_WIDGET (ev_window->priv->bookshelf));
g_object_unref (ev_window->priv->bookshelf);
ev_window->priv->bookshelf = NULL;
-
- gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
- ev_window->priv->view);
}
+ gtk_widget_show (ev_window->priv->hpaned);
}
static void
@@ -5391,6 +5401,8 @@ bookshelf_item_activated_cb (EvBookshelf *bookshelf,
const char *uri,
EvWindow *ev_window)
{
+ if (ev_window->priv->uri && strcmp (ev_window->priv->uri, uri) == 0)
+ ev_window_try_swap_out_bookshelf (ev_window);
ev_application_open_uri_at_dest (EV_APP, uri,
gtk_window_get_screen (GTK_WINDOW (ev_window)),
NULL, 0, NULL, gtk_get_current_event_time ());
@@ -6127,6 +6139,11 @@ static const GtkActionEntry entries[] = {
{ "ViewAutoscroll", GTK_STOCK_MEDIA_PLAY, N_("Auto_scroll"), NULL, NULL,
G_CALLBACK (ev_window_cmd_view_autoscroll) },
+ /* Bookshelf */
+ { "ViewBookshelf", "view-grid-symbolic", N_("_Bookshelf"), NULL,
+ N_("Toggle between bookshelf and open document"),
+ G_CALLBACK (ev_window_cmd_toggle_bookshelf) },
+
/* Go menu */
{ "GoPreviousPage", "go-up-symbolic", N_("_Previous Page"), "<control>Page_Up",
N_("Go to the previous page"),
@@ -7826,29 +7843,26 @@ ev_window_new (void)
return ev_window;
}
-GtkWidget *
-ev_window_new_with_bookshelf (void)
+void
+ev_window_show_bookshelf (EvWindow *ev_window)
{
- EvWindow *ev_window;
- GtkWidget *widget;
-
- ev_window = EV_WINDOW (ev_window_new ());
-
- widget = gtk_bin_get_child (GTK_BIN (ev_window->priv->scrolled_window));
- gtk_container_remove (GTK_CONTAINER (ev_window->priv->scrolled_window), widget);
-
- ev_window->priv->bookshelf = ev_bookshelf_new ();
+ gtk_widget_hide (ev_window->priv->hpaned);
+ if (!ev_window->priv->bookshelf) {
+ ev_window->priv->bookshelf = ev_bookshelf_new ();
+ g_object_ref (ev_window->priv->bookshelf);
+ g_signal_connect_object (ev_window->priv->bookshelf,
+ "item-activated",
+ G_CALLBACK (bookshelf_item_activated_cb),
+ ev_window, 0);
+ gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box),
+ GTK_WIDGET (ev_window->priv->bookshelf),
+ TRUE, TRUE, 0);
+ }
- g_object_ref (ev_window->priv->bookshelf);
gtk_widget_show (GTK_WIDGET (ev_window->priv->bookshelf));
- gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
- GTK_WIDGET (ev_window->priv->bookshelf));
+ ev_window_setup_action_sensitivity (ev_window);
- g_signal_connect_object (ev_window->priv->bookshelf,
- "item-activated",
- G_CALLBACK (bookshelf_item_activated_cb),
- ev_window, 0);
- return GTK_WIDGET (ev_window);
+ return;
}
const gchar *
diff --git a/shell/ev-window.h b/shell/ev-window.h
index 570f110..aa81d47 100644
--- a/shell/ev-window.h
+++ b/shell/ev-window.h
@@ -70,7 +70,6 @@ struct _EvWindowClass {
GType ev_window_get_type (void) G_GNUC_CONST;
GtkWidget *ev_window_new (void);
-GtkWidget *ev_window_new_with_bookshelf (void);
const char *ev_window_get_uri (EvWindow *ev_window);
void ev_window_open_uri (EvWindow *ev_window,
const char *uri,
@@ -90,7 +89,7 @@ const gchar *ev_window_get_dbus_object_path (EvWindow *ev_win
GtkUIManager *ev_window_get_ui_manager (EvWindow *ev_window);
GtkActionGroup *ev_window_get_main_action_group (EvWindow *ev_window);
GtkActionGroup *ev_window_get_zoom_selector_action_group (EvWindow *ev_window);
-
+void ev_window_show_bookshelf (EvWindow *ev_window);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]