]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-window.c
Updated Japanese translation.
[evince.git] / shell / ev-window.c
index 2d69097069cee0eb1489f7dafe323074bfbaadf5..89d18d997863c792ca245cf7ebd2140f681f0b63 100644 (file)
@@ -56,7 +56,6 @@
 #include "ev-document-fonts.h"
 #include "ev-document-images.h"
 #include "ev-document-links.h"
-#include "ev-document-thumbnails.h"
 #include "ev-document-annotations.h"
 #include "ev-document-type-builtins.h"
 #include "ev-document-misc.h"
@@ -1310,8 +1309,7 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window)
        gint rotation;
        EvDocument *document = ev_window->priv->document;
 
-       if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
-           ev_document_get_n_pages (document) <= 0 ||
+       if (ev_document_get_n_pages (document) <= 0 ||
            !ev_document_check_dimensions (document)) {
                return;
        }
@@ -3366,6 +3364,91 @@ ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
        ev_document_fc_mutex_unlock ();
 }
 
+static void
+document_modified_confirmation_dialog_response (GtkDialog *dialog,
+                                               gint       response,
+                                               EvWindow  *ev_window)
+{
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+
+       switch (response) {
+       case GTK_RESPONSE_YES:
+               ev_window_cmd_save_as (NULL, ev_window);
+               break;
+       case GTK_RESPONSE_NO:
+               gtk_widget_destroy (GTK_WIDGET (ev_window));
+               break;
+       case GTK_RESPONSE_CANCEL:
+       default:
+               break;
+       }
+}
+
+static gboolean
+ev_window_check_document_modified (EvWindow *ev_window)
+{
+       EvDocument  *document = ev_window->priv->document;
+       GtkWidget   *dialog;
+       gchar       *text, *markup;
+       const gchar *secondary_text;
+
+       if (!document)
+               return FALSE;
+
+       if (EV_IS_DOCUMENT_FORMS (document) &&
+           ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
+               secondary_text = _("Document contains form fields that have been filled out. "
+                                  "If you don't save a copy, changes will be permanently lost.");
+       } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
+                  ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
+               secondary_text = _("Document contains new or modified annotations. "
+                                  "If you don't save a copy, changes will be permanently lost.");
+       } else {
+               return FALSE;
+       }
+
+
+       text = g_markup_printf_escaped (_("Save a copy of document ā€œ%sā€ before closing?"),
+                                       gtk_window_get_title (GTK_WINDOW (ev_window)));
+
+       dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
+                                        GTK_DIALOG_MODAL,
+                                        GTK_MESSAGE_QUESTION,
+                                        GTK_BUTTONS_NONE,
+                                        NULL);
+
+       markup = g_strdup_printf ("<b>%s</b>", text);
+       g_free (text);
+
+       gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
+       g_free (markup);
+
+       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                                                 "%s", secondary_text);
+
+       gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                               _("Close _without Saving"),
+                               GTK_RESPONSE_NO,
+                               GTK_STOCK_CANCEL,
+                               GTK_RESPONSE_CANCEL,
+                               _("Save a _Copy"),
+                               GTK_RESPONSE_YES,
+                               NULL);
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+        gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+                                                 GTK_RESPONSE_YES,
+                                                 GTK_RESPONSE_NO,
+                                                 GTK_RESPONSE_CANCEL,
+                                                 -1);
+
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (document_modified_confirmation_dialog_response),
+                         ev_window);
+       gtk_widget_show (dialog);
+
+       return TRUE;
+}
+
 static void
 print_jobs_confirmation_dialog_response (GtkDialog *dialog,
                                         gint       response,
@@ -3397,31 +3480,18 @@ print_jobs_confirmation_dialog_response (GtkDialog *dialog,
        }
 }
 
-static void
-ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
+static gboolean
+ev_window_check_print_queue (EvWindow *ev_window)
 {
        GtkWidget *dialog;
        gchar     *text, *markup;
        gint       n_print_jobs;
 
-       if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
-               gint current_page;
-
-               /* Save current page */
-               current_page = ev_view_presentation_get_current_page (
-                       EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
-               ev_document_model_set_page (ev_window->priv->model, current_page);
-       }
-
-       /* TODO: warn about form fields, and annots not saved */
-
        n_print_jobs = ev_window->priv->print_queue ?
                g_queue_get_length (ev_window->priv->print_queue) : 0;
-       
-       if (n_print_jobs == 0) {
-               gtk_widget_destroy (GTK_WIDGET (ev_window));
-               return;
-       }
+
+       if (n_print_jobs == 0)
+               return FALSE;
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
                                         GTK_DIALOG_MODAL,
@@ -3452,7 +3522,7 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s",
                                                  _("If you close the window, pending print "
                                                    "jobs will not be printed."));
-       
+
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
                                _("Cancel _print and Close"),
                                GTK_RESPONSE_NO,
@@ -3472,6 +3542,36 @@ ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
                          G_CALLBACK (print_jobs_confirmation_dialog_response),
                          ev_window);
        gtk_widget_show (dialog);
+
+       return TRUE;
+}
+
+static gboolean
+ev_window_close (EvWindow *ev_window)
+{
+       if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
+               gint current_page;
+
+               /* Save current page */
+               current_page = ev_view_presentation_get_current_page (
+                       EV_VIEW_PRESENTATION (ev_window->priv->presentation_view));
+               ev_document_model_set_page (ev_window->priv->model, current_page);
+       }
+
+       if (ev_window_check_document_modified (ev_window))
+               return FALSE;
+
+       if (ev_window_check_print_queue (ev_window))
+               return FALSE;
+
+       return TRUE;
+}
+
+static void
+ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
+{
+       if (ev_window_close (ev_window))
+               gtk_widget_destroy (GTK_WIDGET (ev_window));
 }
 
 static void
@@ -4756,17 +4856,23 @@ ev_window_update_find_status_message (EvWindow *ev_window)
                return;
        
        if (ev_job_is_finished (ev_window->priv->find_job)) {
-               gint n_results;
-
-               n_results = ev_job_find_get_n_results (EV_JOB_FIND (ev_window->priv->find_job),
-                                                      ev_document_model_get_page (ev_window->priv->model));
-               /* TRANS: Sometimes this could be better translated as
-                                     "%d hit(s) on this page".  Therefore this string
-                                     contains plural cases. */
-               message = g_strdup_printf (ngettext ("%d found on this page",
-                                                    "%d found on this page",
-                                                    n_results),
-                                          n_results);
+               EvJobFind *job_find = EV_JOB_FIND (ev_window->priv->find_job);
+
+               if (ev_job_find_has_results (job_find)) {
+                       gint n_results;
+
+                       n_results = ev_job_find_get_n_results (job_find,
+                                                              ev_document_model_get_page (ev_window->priv->model));
+                       /* TRANS: Sometimes this could be better translated as
+                          "%d hit(s) on this page".  Therefore this string
+                          contains plural cases. */
+                       message = g_strdup_printf (ngettext ("%d found on this page",
+                                                            "%d found on this page",
+                                                            n_results),
+                                                  n_results);
+               } else {
+                       message = g_strdup (_("Not found"));
+               }
        } else {
                gdouble percent;
 
@@ -5257,6 +5363,13 @@ ev_window_key_press_event (GtkWidget   *widget,
        return handled;
 }
 
+static gboolean
+ev_window_delete_event (GtkWidget   *widget,
+                       GdkEventAny *event)
+{
+       return !ev_window_close (EV_WINDOW (widget));
+}
+
 static void
 ev_window_class_init (EvWindowClass *ev_window_class)
 {
@@ -5266,6 +5379,7 @@ ev_window_class_init (EvWindowClass *ev_window_class)
        g_object_class->dispose = ev_window_dispose;
        g_object_class->finalize = ev_window_finalize;
 
+       widget_class->delete_event = ev_window_delete_event;
        widget_class->key_press_event = ev_window_key_press_event;
        widget_class->screen_changed = ev_window_screen_changed;
        widget_class->window_state_event = ev_window_state_event;