]> www.fi.muni.cz Git - evince.git/commitdiff
Expose api to print a range (with dialog). Make private _print use it.
authorMarco Pesenti Gritti <mpg@redhat.com>
Mon, 16 May 2005 09:07:43 +0000 (09:07 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Mon, 16 May 2005 09:07:43 +0000 (09:07 +0000)
2005-05-16  Marco Pesenti Gritti  <mpg@redhat.com>

        * shell/ev-window.c: (ev_window_print), (ev_window_print_range):
        * shell/ev-window.h:

        Expose api to print a range (with dialog). Make private _print use
        it.

        * shell/ev-sidebar-links.c: (print_section_cb), (button_press_cb),
        (ev_sidebar_links_construct):

        Show a print context menu on linkx, it prints the selected
        section.

ChangeLog
shell/ev-sidebar-links.c
shell/ev-window.c
shell/ev-window.h

index c6a56c9bdcca9965fa022c0f486367980cfd369f..5055917acd555a8e918e4cef574021309c829c75 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2005-05-16  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * shell/ev-window.c: (ev_window_print), (ev_window_print_range):
+       * shell/ev-window.h:
+
+       Expose api to print a range (with dialog). Make private _print use
+       it.
+
+       * shell/ev-sidebar-links.c: (print_section_cb), (button_press_cb),
+       (ev_sidebar_links_construct):
+
+       Show a print context menu on linkx, it prints the selected
+       section.
+
 2005-05-15  Carlos Garcia Campos <carlosgc@gnome.org>
 
        * shell/ev-sidebar.c: make the drop down menu as width as the toggle
index 80eb610b4a1d2699a1f3564991612676aed0917c..93959b37ab60444963ff94fd7520b7aabb50b7a3 100644 (file)
@@ -222,6 +222,85 @@ create_loading_model (void)
        return retval;
 }
 
+static void
+print_section_cb (GtkWidget *menuitem, EvSidebarLinks *sidebar)
+{
+       GtkWidget *window;
+       GtkTreeSelection *selection;
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+
+       selection = gtk_tree_view_get_selection
+               (GTK_TREE_VIEW (sidebar->priv->tree_view));
+
+       if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+               EvLink *link;
+               int first_page, last_page;
+
+               gtk_tree_model_get (model, &iter,
+                                   EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+                                   -1);
+               first_page = ev_link_get_page (link) + 1;
+
+               if (gtk_tree_model_iter_next (model, &iter)) {
+                       gtk_tree_model_get (model, &iter,
+                                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
+                                           -1);
+                       last_page = ev_link_get_page (link);
+               } else {
+                       last_page = -1;
+               }
+       
+               window = gtk_widget_get_toplevel (GTK_WIDGET (sidebar));
+               if (EV_IS_WINDOW (window)) {
+                       ev_window_print_range (EV_WINDOW (window),
+                                              first_page, last_page);
+               }
+       }
+}
+
+static gboolean
+button_press_cb (GtkWidget *treeview,
+                 GdkEventButton *event,
+                 EvSidebarLinks *sidebar)
+{
+       GtkTreePath *path = NULL;
+
+       if (event->button == 3) {
+               if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview),
+                                                  event->x,
+                                                  event->y,
+                                                  &path,
+                                                  NULL, NULL, NULL)) {
+                       GtkWidget *menu;
+                       GtkWidget *item;
+
+                       gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview),
+                                                 path, NULL, FALSE);
+
+                       menu = gtk_menu_new ();
+                       item = gtk_image_menu_item_new_from_stock
+                                                       (GTK_STOCK_PRINT, NULL);
+                       gtk_label_set_label (GTK_LABEL (GTK_BIN (item)->child),
+                                            _("Print..."));
+                       gtk_widget_show (item);
+                       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+                       g_signal_connect (item, "activate",
+                                         G_CALLBACK (print_section_cb), sidebar);
+
+                       gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 2,
+                                       gtk_get_current_event_time ());
+
+                       gtk_tree_path_free (path);
+
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+
 static void
 ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links)
 {
@@ -274,7 +353,10 @@ ev_sidebar_links_construct (EvSidebarLinks *ev_sidebar_links)
                                                 (GtkTreeCellDataFunc) links_page_num_func,
                                                 ev_sidebar_links, NULL);
 
-       
+       g_signal_connect (GTK_TREE_VIEW (priv->tree_view),
+                         "button_press_event",
+                         G_CALLBACK (button_press_cb),
+                         ev_sidebar_links);
 }
 
 static void
index 085f60ab9a9e9d98ca043e311273f8b6fb26ba92..f1b41602fa17dd3953f17ea5ee0e5d759ff336bb 100644 (file)
@@ -1070,23 +1070,38 @@ using_postscript_printer (GnomePrintConfig *config)
 }
 
 static void
-ev_window_print (EvWindow *ev_window)
+ev_window_print (EvWindow *window)
+{
+       EvPageCache *page_cache;
+       int last_page;
+
+       page_cache = ev_document_get_page_cache (window->priv->document);
+       last_page = ev_page_cache_get_n_pages (page_cache);
+
+       ev_window_print_range (window, 1, -1);
+}
+
+void
+ev_window_print_range (EvWindow *ev_window, int first_page, int last_page)
 {
        GnomePrintConfig *config;
        GnomePrintJob *job;
        GtkWidget *print_dialog;
-       EvPageCache *page_cache;
        gchar *pages_label;
        EvPrintJob *print_job = NULL;
+       EvPageCache *page_cache;
 
         g_return_if_fail (EV_IS_WINDOW (ev_window));
        g_return_if_fail (ev_window->priv->document != NULL);
 
+       page_cache = ev_document_get_page_cache (ev_window->priv->document);
+       if (last_page == -1) {
+               last_page = ev_page_cache_get_n_pages (page_cache);
+       }
+
        config = gnome_print_config_default ();
        job = gnome_print_job_new (config);
 
-       page_cache = ev_document_get_page_cache (ev_window->priv->document);
-
        print_dialog = gnome_print_dialog_new (job, (guchar *) _("Print"),
                                               (GNOME_PRINT_DIALOG_RANGE |
                                                GNOME_PRINT_DIALOG_COPIES));
@@ -1095,8 +1110,7 @@ ev_window_print (EvWindow *ev_window)
        gnome_print_dialog_construct_range_page (GNOME_PRINT_DIALOG (print_dialog),
                                                 GNOME_PRINT_RANGE_ALL |
                                                 GNOME_PRINT_RANGE_RANGE,
-                                                1,
-                                                ev_page_cache_get_n_pages (page_cache),
+                                                first_page, last_page,
                                                 NULL, (const guchar *)pages_label);
        g_free (pages_label);
                                                 
index d6085a8bd2d783ec7bbe35c92c8a85c4e916c4e8..fe2c2793bc88013ff221892496e62034df6f9943 100644 (file)
@@ -56,6 +56,9 @@ void          ev_window_open          (EvWindow       *ev_window,
 void           ev_window_open_page     (EvWindow       *ev_window,
                                         int             page);
 gboolean       ev_window_is_empty      (const EvWindow *ev_window);
+void           ev_window_print_range   (EvWindow       *ev_window,
+                                        int             first_page,
+                                        int             last_page);
 
 G_END_DECLS