From: Nickolay V. Shmyrev Date: Thu, 23 Jun 2005 14:23:20 +0000 (+0000) Subject: Fix for bug 308402 - provide templates in Save dialog X-Git-Tag: EVINCE_0_3_3~214 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=be84d325e18241a7e33ffa07cfce58bb8b54794b;p=evince.git Fix for bug 308402 - provide templates in Save dialog --- diff --git a/ChangeLog b/ChangeLog index 4548cf82..5d8952a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-06-23 Nikolay V. Shmyrev + + * 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 * pdf/ev-poppler.cc: diff --git a/shell/ev-application.c b/shell/ev-application.c index 3b162ce0..ef478e00 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -25,6 +25,8 @@ #endif #include "ev-application.h" +#include "ev-utils.h" +#include "ev-document-types.h" #include #include @@ -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); diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index 71332952..724412fb 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -41,6 +41,7 @@ #include #include #include +#include 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); +} + diff --git a/shell/ev-document-types.h b/shell/ev-document-types.h index 86eb100e..b5d75ddc 100644 --- a/shell/ev-document-types.h +++ b/shell/ev-document-types.h @@ -22,6 +22,7 @@ #define EV_DOCUMENT_TYPES_H #include "ev-document.h" +#include 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 diff --git a/shell/ev-window.c b/shell/ev-window.c index 29141d22..07aaa37d 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -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 #include @@ -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); }