]> www.fi.muni.cz Git - evince.git/commitdiff
Fix for bug 308402 - provide templates in Save dialog
authorNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Thu, 23 Jun 2005 14:23:20 +0000 (14:23 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Thu, 23 Jun 2005 14:23:20 +0000 (14:23 +0000)
ChangeLog
shell/ev-application.c
shell/ev-document-types.c
shell/ev-document-types.h
shell/ev-window.c

index 4548cf82c6d1471784c3c84a65591e1719da81d2..5d8952a04328ecd72effc681c97391ac0bf2ea7f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-06-23  Nikolay V. Shmyrev  <nshmyrev@yandex.ru>
+
+       * shell/ev-application.c: (ev_application_open):
+       * shell/ev-document-types.c: (ev_document_types_add_filters),
+       (ev_document_types_add_filters_for_type):
+       * shell/ev-document-types.h:
+       * shell/ev-window.c: (ev_window_cmd_save_as):
+       
+       Suggest basename as template when saving, provide filters
+       for save dialog. It's bug 308402
+
 2005-06-20  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * pdf/ev-poppler.cc:
index 3b162ce0faebbe63fe4e4c5a99fcd1e1f2a3e597..ef478e002feb069c009c3f4ecd4f09d1b39375d6 100644 (file)
@@ -25,6 +25,8 @@
 #endif
 
 #include "ev-application.h"
+#include "ev-utils.h"
+#include "ev-document-types.h"
 
 #include <glib.h>
 #include <glib/gi18n.h>
@@ -117,18 +119,7 @@ ev_application_open (EvApplication *application, GError *err)
 {
        EvWindow *ev_window;
        GtkWidget *chooser;
-       GtkFileFilter *documents_filter;
-       GtkFileFilter *pdf_filter;
-       GtkFileFilter *ps_filter;
-       GtkFileFilter *pixbuf_filter;
-       GtkFileFilter *all_filter;
-       static gchar  *folder = NULL;
-#ifdef ENABLE_DJVU
-       GtkFileFilter *djvu_filter;
-#endif
-#ifdef ENABLE_DVI
-       GtkFileFilter *dvi_filter;
-#endif
+       static char *folder = NULL;
 
        ev_window = ev_application_get_empty_window (application);
 
@@ -141,64 +132,11 @@ ev_application_open (EvApplication *application, GError *err)
                                               NULL);
 
        if (folder) {
-               gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
-                                                    folder);
-       }
-
-       documents_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (documents_filter,
-                                 _("All Documents"));
-       gtk_file_filter_add_mime_type (documents_filter, "application/postscript");
-       gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript");
-       gtk_file_filter_add_mime_type (documents_filter, "image/x-eps");
-       gtk_file_filter_add_mime_type (documents_filter, "application/pdf");
-#ifdef ENABLE_DVI
-       gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi");
-#endif
-       gtk_file_filter_add_pixbuf_formats (documents_filter);
-#ifdef ENABLE_DJVU
-       gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu");
-#endif
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
-
-       ps_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
-       gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
-       gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript");
-       gtk_file_filter_add_mime_type (ps_filter, "image/x-eps");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
-
-       pdf_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
-       gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
-
-#ifdef ENABLE_DVI
-       dvi_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (dvi_filter, _("DVI Documents"));
-       gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter);
-#endif
-
-       pixbuf_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (pixbuf_filter, _("Images"));
-       gtk_file_filter_add_pixbuf_formats (pixbuf_filter);
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter);
-
-#ifdef ENABLE_DJVU
-       djvu_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (djvu_filter, _("Djvu Documents"));
-       gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter);
-#endif 
-       
-       all_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (all_filter, _("All Files"));
-       gtk_file_filter_add_pattern (all_filter, "*");
-
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter);
-       gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
+               gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (chooser),
+                                                        folder);
+       }
 
+       ev_document_types_add_filters (chooser);
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE);
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE);
 
@@ -206,7 +144,11 @@ ev_application_open (EvApplication *application, GError *err)
                GSList *uris;
 
                uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
-               folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser));
+
+               if (folder != NULL)
+                       g_free (folder);
+                               
+               folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
 
                ev_window_open_uri_list (ev_window, uris);
                
index 7133295285ffa796d4eeb1d85e5085ec7709e195..724412fb968e2e808bae1b8fcbae83e4270ea288 100644 (file)
@@ -41,6 +41,7 @@
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
 #include <libgnomevfs/gnome-vfs-file-info.h>
 #include <libgnomevfs/gnome-vfs-ops.h>
+#include <gtk/gtkfilechooserdialog.h>
 
 typedef struct _EvDocumentType EvDocumentType;
 struct _EvDocumentType
@@ -213,3 +214,154 @@ ev_document_type_lookup (const char *uri, gchar **mime_type, GError **error)
 
        return type;
 }
+
+void 
+ev_document_types_add_filters (GtkWidget *chooser)
+{
+       GtkFileFilter *documents_filter;
+       GtkFileFilter *pdf_filter;
+       GtkFileFilter *ps_filter;
+       GtkFileFilter *pixbuf_filter;
+       GtkFileFilter *all_filter;
+#ifdef ENABLE_DJVU
+       GtkFileFilter *djvu_filter;
+#endif
+#ifdef ENABLE_DVI
+       GtkFileFilter *dvi_filter;
+#endif
+
+       documents_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (documents_filter,
+                                 _("All Documents"));
+       gtk_file_filter_add_mime_type (documents_filter, "application/postscript");
+       gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript");
+       gtk_file_filter_add_mime_type (documents_filter, "image/x-eps");
+       gtk_file_filter_add_mime_type (documents_filter, "application/pdf");
+#ifdef ENABLE_DVI
+       gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi");
+#endif
+       gtk_file_filter_add_pixbuf_formats (documents_filter);
+#ifdef ENABLE_DJVU
+       gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu");
+#endif
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
+
+       ps_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
+       gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
+       gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript");
+       gtk_file_filter_add_mime_type (ps_filter, "image/x-eps");
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
+
+       pdf_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
+       gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
+
+#ifdef ENABLE_DVI
+       dvi_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (dvi_filter, _("DVI Documents"));
+       gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi");
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter);
+#endif
+
+       pixbuf_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (pixbuf_filter, _("Images"));
+       gtk_file_filter_add_pixbuf_formats (pixbuf_filter);
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter);
+
+#ifdef ENABLE_DJVU
+       djvu_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (djvu_filter, _("Djvu Documents"));
+       gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu");
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter);
+#endif 
+       
+       all_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (all_filter, _("All Files"));
+       gtk_file_filter_add_pattern (all_filter, "*");
+
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter);
+       gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
+}
+
+void 
+ev_document_types_add_filters_for_type (GtkWidget *chooser, GType type)
+{
+       GtkFileFilter *documents_filter;
+       GtkFileFilter *pdf_filter;
+       GtkFileFilter *ps_filter;
+       GtkFileFilter *pixbuf_filter;
+       GtkFileFilter *all_filter;
+#ifdef ENABLE_DJVU
+       GtkFileFilter *djvu_filter;
+#endif
+#ifdef ENABLE_DVI
+       GtkFileFilter *dvi_filter;
+#endif
+       GtkFileFilter *default_filter;
+
+       documents_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (documents_filter,
+                                 _("All Documents"));
+       gtk_file_filter_add_mime_type (documents_filter, "application/postscript");
+       gtk_file_filter_add_mime_type (documents_filter, "application/x-gzpostscript");
+       gtk_file_filter_add_mime_type (documents_filter, "image/x-eps");
+       gtk_file_filter_add_mime_type (documents_filter, "application/pdf");
+#ifdef ENABLE_DVI
+       gtk_file_filter_add_mime_type (documents_filter, "application/x-dvi");
+#endif
+       gtk_file_filter_add_pixbuf_formats (documents_filter);
+#ifdef ENABLE_DJVU
+       gtk_file_filter_add_mime_type (documents_filter, "image/vnd.djvu");
+#endif
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), documents_filter);
+
+       if (type == PS_TYPE_DOCUMENT) {
+               ps_filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (ps_filter, _("PostScript Documents"));
+               gtk_file_filter_add_mime_type (ps_filter, "application/postscript");
+               gtk_file_filter_add_mime_type (ps_filter, "application/x-gzpostscript");
+               gtk_file_filter_add_mime_type (ps_filter, "image/x-eps");
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), ps_filter);
+               default_filter = ps_filter;
+       } else if (type == PDF_TYPE_DOCUMENT) {
+               pdf_filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
+               gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pdf_filter);
+               default_filter = pdf_filter;
+#ifdef ENABLE_DVI
+       } else if (type == DVI_TYPE_DOCUMENT) {
+               dvi_filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (dvi_filter, _("DVI Documents"));
+               gtk_file_filter_add_mime_type (dvi_filter, "application/x-dvi");
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), dvi_filter);
+               default_filter = dvi_filter;
+#endif
+       } else if (type == PIXBUF_TYPE_DOCUMENT) {
+               pixbuf_filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (pixbuf_filter, _("Images"));
+               gtk_file_filter_add_pixbuf_formats (pixbuf_filter);
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), pixbuf_filter);
+               default_filter = pixbuf_filter;
+#ifdef ENABLE_DJVU
+       } else if (type == DJVU_TYPE_DOCUMENT) {
+               djvu_filter = gtk_file_filter_new ();
+               gtk_file_filter_set_name (djvu_filter, _("Djvu Documents"));
+               gtk_file_filter_add_mime_type (djvu_filter, "image/vnd.djvu");
+               gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), djvu_filter);
+               default_filter = djvu_filter;
+#endif 
+       } else {
+               default_filter = documents_filter;
+       }
+
+       all_filter = gtk_file_filter_new ();
+       gtk_file_filter_set_name (all_filter, _("All Files"));
+       gtk_file_filter_add_pattern (all_filter, "*");
+
+       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), all_filter);
+       gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), default_filter);
+}
+
index 86eb100efe8348c686cbf069611916f09daf08f0..b5d75ddce4803654f0f4f8af9c216649ffe2649a 100644 (file)
@@ -22,6 +22,7 @@
 #define EV_DOCUMENT_TYPES_H
 
 #include "ev-document.h"
+#include <gtk/gtk.h>
 
 G_BEGIN_DECLS
 
@@ -29,6 +30,9 @@ GType ev_document_type_lookup (const char  *uri,
                               gchar       **mime_type,
                               GError      **error);
 
+void ev_document_types_add_filters         (GtkWidget *chooser);
+void ev_document_types_add_filters_for_type (GtkWidget *chooser, GType type);
+
 G_END_DECLS
 
 #endif
index 29141d224a588b9b73dcc2d95400be296efefc43..07aaa37dd8044cc0d9cccd7f32ab99934b2384a7 100644 (file)
@@ -43,6 +43,7 @@
 #include "ev-document-fonts.h"
 #include "ev-document-find.h"
 #include "ev-document-security.h"
+#include "ev-document-types.h"
 #include "ev-job-queue.h"
 #include "ev-jobs.h"
 #include "ev-statusbar.h"
@@ -59,6 +60,7 @@
 #include "ev-application.h"
 #include "ev-stock-icons.h"
 #include "ev-file-helpers.h"
+
 #include <poppler.h>
 
 #include <glib/gi18n.h>
@@ -1088,8 +1090,11 @@ static void
 ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
 {
        GtkWidget *fc;
-       GtkFileFilter *pdf_filter, *all_filter;
-       gchar *uri = NULL;
+
+       gchar *uri;
+       gchar *basename;
+       static char* folder = NULL;
+
        gboolean success;
 
        fc = gtk_file_chooser_dialog_new (
@@ -1100,18 +1105,17 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
                NULL);
        gtk_window_set_modal (GTK_WINDOW (fc), TRUE);
 
-       pdf_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (pdf_filter, _("PDF Documents"));
-       gtk_file_filter_add_mime_type (pdf_filter, "application/pdf");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
-
-       all_filter = gtk_file_filter_new ();
-       gtk_file_filter_set_name (all_filter, _("All Files"));
-       gtk_file_filter_add_pattern (all_filter, "*");
-       gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (fc), all_filter);
-       gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (fc), pdf_filter);
-
+       ev_document_types_add_filters_for_type (fc, G_TYPE_FROM_INSTANCE (ev_window->priv->document));
        gtk_dialog_set_default_response (GTK_DIALOG (fc), GTK_RESPONSE_OK);
+       
+       if (folder) {
+               gtk_file_chooser_set_current_folder_uri(GTK_FILE_CHOOSER (fc), 
+                                                       folder);
+       }
+       
+       basename = g_path_get_basename (ev_window->priv->uri);
+       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (fc), basename);
+       g_free (basename);
 
        gtk_widget_show (fc);
 
@@ -1133,6 +1137,12 @@ ev_window_cmd_save_as (GtkAction *action, EvWindow *ev_window)
                else
                        save_error_dialog (GTK_WINDOW (fc), uri);
        }
+
+       if (folder != NULL)
+               g_free (folder);
+                               
+       folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (fc));
+
        gtk_widget_destroy (fc);
 }