]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Set points_set to TRUE so that selections don't disappear after a zoom
[evince.git] / shell / ev-window.c
index 9c74f3970fd45443ba53630e9fc860c9a01ae43e..722c8716eb958da7975a223ecb150f9cd72bf155 100644 (file)
@@ -94,6 +94,8 @@
 
 #include <string.h>
 
 
 #include <string.h>
 
+char *xdg_user_dir_lookup (char *type);
+
 typedef enum {
        PAGE_MODE_DOCUMENT,
        PAGE_MODE_PASSWORD
 typedef enum {
        PAGE_MODE_DOCUMENT,
        PAGE_MODE_PASSWORD
@@ -698,6 +700,9 @@ ev_window_add_history (EvWindow *window, gint page, EvLink *link)
        EvLink *real_link;
        EvLinkAction *action;
        EvLinkDest *dest;
        EvLink *real_link;
        EvLinkAction *action;
        EvLinkDest *dest;
+
+       if (window->priv->history == NULL)
+               return;
        
        if (link) {
                action = g_object_ref (ev_link_get_action (link));
        
        if (link) {
                action = g_object_ref (ev_link_get_action (link));
@@ -842,7 +847,7 @@ setup_sidebar_from_metadata (EvWindow *window, EvDocument *document)
                } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
                        ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
                } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
                } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
                        ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
                } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
-                       ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
+                       ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
                }
                g_value_unset (&sidebar_page);
        } else if (document && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
                }
                g_value_unset (&sidebar_page);
        } else if (document && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
@@ -898,8 +903,14 @@ setup_size_from_metadata (EvWindow *window)
         if (window->priv->page_cache &&
            ev_metadata_manager_get (uri, "window_width_ratio", &width_ratio, FALSE) &&
            ev_metadata_manager_get (uri, "window_height_ratio", &height_ratio, FALSE)) {
         if (window->priv->page_cache &&
            ev_metadata_manager_get (uri, "window_width_ratio", &width_ratio, FALSE) &&
            ev_metadata_manager_get (uri, "window_height_ratio", &height_ratio, FALSE)) {
+               
                gint document_width;
                gint document_height;
                gint document_width;
                gint document_height;
+               
+               GdkScreen *screen;
+               
+               gint request_width;
+               gint request_height;
 
                ev_page_cache_get_max_width (window->priv->page_cache, 
                                             0, 1.0,
 
                ev_page_cache_get_max_width (window->priv->page_cache, 
                                             0, 1.0,
@@ -908,9 +919,19 @@ setup_size_from_metadata (EvWindow *window)
                                             0, 1.0,
                                             &document_height);                 
                
                                             0, 1.0,
                                             &document_height);                 
                
+               request_width = g_value_get_double (&width_ratio) * document_width;
+               request_height = g_value_get_double (&height_ratio) * document_height;
+               
+               screen = gtk_window_get_screen (GTK_WINDOW (window));
+               
+               if (screen) {
+                       request_width = MIN (request_width, gdk_screen_get_width (screen));
+                       request_height = MIN (request_width, gdk_screen_get_height (screen));
+               }
+                               
                gtk_window_resize (GTK_WINDOW (window),
                gtk_window_resize (GTK_WINDOW (window),
-                                  g_value_get_double (&width_ratio) * document_width,
-                                  g_value_get_double (&height_ratio) * document_height);
+                                  request_width,
+                                  request_height);
                g_value_unset (&width_ratio);
                g_value_unset (&height_ratio);
        }
                g_value_unset (&width_ratio);
                g_value_unset (&height_ratio);
        }
@@ -1035,22 +1056,14 @@ ev_window_set_icon_from_thumbnail (EvJobThumbnail *job,
        ev_window_clear_thumbnail_job (ev_window);
 }
 
        ev_window_clear_thumbnail_job (ev_window);
 }
 
-static void
+static gboolean
 ev_window_setup_document (EvWindow *ev_window)
 {
        const EvDocumentInfo *info;
 ev_window_setup_document (EvWindow *ev_window)
 {
        const EvDocumentInfo *info;
-       EvDocument *document;
-       EvView *view = EV_VIEW (ev_window->priv->view);
+       EvDocument *document = ev_window->priv->document;
        EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
        GtkAction *action;
        EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
        GtkAction *action;
-
-       document = ev_window->priv->document;
-       ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
-       g_signal_connect (ev_window->priv->page_cache, "page-changed",
-                         G_CALLBACK (page_changed_cb), ev_window);
-       g_signal_connect (ev_window->priv->page_cache, "history-changed",
-                         G_CALLBACK (history_changed_cb), ev_window);
-
+       
        if (EV_IS_DOCUMENT_FIND (document)) {
                g_signal_connect_object (G_OBJECT (document),
                                         "find_changed",
        if (EV_IS_DOCUMENT_FIND (document)) {
                g_signal_connect_object (G_OBJECT (document),
                                         "find_changed",
@@ -1079,16 +1092,12 @@ ev_window_setup_document (EvWindow *ev_window)
                g_object_unref (rc);
        }
 
                g_object_unref (rc);
        }
 
-       ev_sidebar_set_document (sidebar, document);
-
-       if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
-               ev_view_set_document (view, document);
-       }
        ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
        ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
-
        ev_window_title_set_document (ev_window->priv->title, document);
        ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
 
        ev_window_title_set_document (ev_window->priv->title, document);
        ev_window_title_set_uri (ev_window->priv->title, ev_window->priv->uri);
 
+       ev_sidebar_set_document (sidebar, document);
+
        action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
        ev_page_action_set_document (EV_PAGE_ACTION (action), document);
        ev_window_setup_action_sensitivity (ev_window);
        action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
        ev_page_action_set_document (EV_PAGE_ACTION (action), document);
        ev_window_setup_action_sensitivity (ev_window);
@@ -1104,12 +1113,36 @@ ev_window_setup_document (EvWindow *ev_window)
                                                   ev_window->priv->document);
        }
        
                                                   ev_window->priv->document);
        }
        
+       info = ev_page_cache_get_info (ev_window->priv->page_cache);
+       update_document_mode (ev_window, info->mode);
+
+       return FALSE;
+}
+
+static void
+ev_window_set_document (EvWindow *ev_window, EvDocument *document)
+{
+       EvView *view = EV_VIEW (ev_window->priv->view);
+
+       if (ev_window->priv->document)
+               g_object_unref (ev_window->priv->document);
+       ev_window->priv->document = g_object_ref (document);
+       
+       ev_window->priv->page_cache = ev_page_cache_get (ev_window->priv->document);
+       g_signal_connect (ev_window->priv->page_cache, "page-changed",
+                         G_CALLBACK (page_changed_cb), ev_window);
+       g_signal_connect (ev_window->priv->page_cache, "history-changed",
+                         G_CALLBACK (history_changed_cb), ev_window);
+
        setup_size_from_metadata (ev_window);
        setup_size_from_metadata (ev_window);
-       setup_document_from_metadata (ev_window);
        setup_sidebar_from_metadata (ev_window, document);
        setup_sidebar_from_metadata (ev_window, document);
+       setup_document_from_metadata (ev_window);
 
 
-       info = ev_page_cache_get_info (ev_window->priv->page_cache);
-       update_document_mode (ev_window, info->mode);
+       if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
+               ev_view_set_document (view, document);
+       }
+
+       g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window);
 }
 
 static void
 }
 
 static void
@@ -1255,17 +1288,16 @@ ev_window_load_job_cb  (EvJobLoad *job,
 
        /* Success! */
        if (job->error == NULL) {
 
        /* Success! */
        if (job->error == NULL) {
-               if (ev_window->priv->document)
-                       g_object_unref (ev_window->priv->document);
-               ev_window->priv->document = g_object_ref (document);
+               ev_window_set_document (ev_window, document);
+               
+               if (job->mode != EV_WINDOW_MODE_PREVIEW) {
+                       setup_view_from_metadata (ev_window);
+               }
 
                if (!ev_window->priv->unlink_temp_file) {
 
                if (!ev_window->priv->unlink_temp_file) {
-                       setup_view_from_metadata (ev_window);
                        ev_window_add_recent (ev_window, ev_window->priv->uri);
                }
 
                        ev_window_add_recent (ev_window, ev_window->priv->uri);
                }
 
-               ev_window_setup_document (ev_window);
-
                if (job->dest) {
                        EvLink *link;
                        EvLinkAction *link_action;
                if (job->dest) {
                        EvLink *link;
                        EvLinkAction *link_action;
@@ -1491,6 +1523,13 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *window)
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
                                          window->priv->uri);
        }
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (chooser),
                                          window->priv->uri);
        }
+       else {
+               char *folder;
+               folder = xdg_user_dir_lookup ("DOCUMENTS");
+               gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
+                                                    folder);
+               free (folder);
+       }
        
        g_signal_connect (chooser, "response",
                          G_CALLBACK (file_open_dialog_response_cb),
        
        g_signal_connect (chooser, "response",
                          G_CALLBACK (file_open_dialog_response_cb),
@@ -1920,6 +1959,7 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        GtkWidget *fc;
        gchar *base_name;
        gchar *file_name;
        GtkWidget *fc;
        gchar *base_name;
        gchar *file_name;
+       gchar *folder;
 
        fc = gtk_file_chooser_dialog_new (
                _("Save a Copy"),
 
        fc = gtk_file_chooser_dialog_new (
                _("Save a Copy"),
@@ -1934,10 +1974,13 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (fc), TRUE);    
        file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
        base_name = g_path_get_basename (file_name);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER (fc), TRUE);    
        file_name = gnome_vfs_format_uri_for_display (ev_window->priv->uri);
        base_name = g_path_get_basename (file_name);
+        folder = xdg_user_dir_lookup ("DOCUMENTS");
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), base_name);
+        gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (fc), folder);
        g_free (file_name);
        g_free (base_name);
        g_free (file_name);
        g_free (base_name);
-
+        free (folder);
+        
        g_signal_connect (fc, "response",
                          G_CALLBACK (file_save_dialog_response_cb),
                          ev_window);
        g_signal_connect (fc, "response",
                          G_CALLBACK (file_save_dialog_response_cb),
                          ev_window);