From dc53501ce9ddf0811044dbff38e7181235d744ea Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Wed, 6 Jan 2016 15:07:41 +0100 Subject: [PATCH] app: add gimp_plug_in_manager_get_file_procedures() for the file dialogs Change GimpFileDialog's file-procs properties to enum GimpFileProcedureGroup and get them via the newly added API. Set properties common to all dialogs in the parent class. --- app/plug-in/gimppluginmanager-file.c | 30 +++++++++++++++++++++- app/plug-in/gimppluginmanager-file.h | 3 +++ app/plug-in/plug-in-enums.c | 2 ++ app/plug-in/plug-in-enums.h | 1 + app/widgets/gimpexportdialog.c | 35 ++++++++++---------------- app/widgets/gimpfiledialog.c | 35 +++++++++++++++++--------- app/widgets/gimpopendialog.c | 37 ++++++++++------------------ app/widgets/gimpopendialog.h | 2 ++ app/widgets/gimpsavedialog.c | 35 ++++++++++---------------- 9 files changed, 100 insertions(+), 80 deletions(-) diff --git a/app/plug-in/gimppluginmanager-file.c b/app/plug-in/gimppluginmanager-file.c index 84fd4aa22a..7d4a2810c3 100644 --- a/app/plug-in/gimppluginmanager-file.c +++ b/app/plug-in/gimppluginmanager-file.c @@ -236,6 +236,31 @@ gimp_plug_in_manager_register_thumb_loader (GimpPlugInManager *manager, return TRUE; } +GSList * +gimp_plug_in_manager_get_file_procedures (GimpPlugInManager *manager, + GimpFileProcedureGroup group) +{ + g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL); + + switch (group) + { + case GIMP_FILE_PROCEDURE_GROUP_NONE: + return NULL; + + case GIMP_FILE_PROCEDURE_GROUP_OPEN: + return manager->load_procs; + + case GIMP_FILE_PROCEDURE_GROUP_SAVE: + return manager->save_procs; + + case GIMP_FILE_PROCEDURE_GROUP_EXPORT: + return manager->export_procs; + + default: + g_return_val_if_reached (NULL); + } +} + GimpPlugInProcedure * gimp_plug_in_manager_file_procedure_find (GimpPlugInManager *manager, GimpFileProcedureGroup group, @@ -337,7 +362,7 @@ gimp_plug_in_manager_file_procedure_find_by_mime_type (GimpPlugInManager *m /* private functions */ -gboolean +static gboolean file_procedure_in_group (GimpPlugInProcedure *file_proc, GimpFileProcedureGroup group) { @@ -353,6 +378,9 @@ file_procedure_in_group (GimpPlugInProcedure *file_proc, switch (group) { + case GIMP_FILE_PROCEDURE_GROUP_NONE: + return FALSE; + case GIMP_FILE_PROCEDURE_GROUP_SAVE: /* Only .xcf shall pass */ return is_xcf_save || is_filter; diff --git a/app/plug-in/gimppluginmanager-file.h b/app/plug-in/gimppluginmanager-file.h index aa08980490..d3101eaf5a 100644 --- a/app/plug-in/gimppluginmanager-file.h +++ b/app/plug-in/gimppluginmanager-file.h @@ -42,6 +42,9 @@ gboolean gimp_plug_in_manager_register_thumb_loader (GimpPlugInManager *manage const gchar *load_proc, const gchar *thumb_proc); +GSList * gimp_plug_in_manager_get_file_procedures (GimpPlugInManager *manager, + GimpFileProcedureGroup group); + GimpPlugInProcedure * gimp_plug_in_manager_file_procedure_find (GimpPlugInManager *manager, GimpFileProcedureGroup group, diff --git a/app/plug-in/plug-in-enums.c b/app/plug-in/plug-in-enums.c index 6c264e98b8..fbde936ac2 100644 --- a/app/plug-in/plug-in-enums.c +++ b/app/plug-in/plug-in-enums.c @@ -83,6 +83,7 @@ gimp_file_procedure_group_get_type (void) { static const GEnumValue values[] = { + { GIMP_FILE_PROCEDURE_GROUP_NONE, "GIMP_FILE_PROCEDURE_GROUP_NONE", "none" }, { GIMP_FILE_PROCEDURE_GROUP_ANY, "GIMP_FILE_PROCEDURE_GROUP_ANY", "any" }, { GIMP_FILE_PROCEDURE_GROUP_OPEN, "GIMP_FILE_PROCEDURE_GROUP_OPEN", "open" }, { GIMP_FILE_PROCEDURE_GROUP_SAVE, "GIMP_FILE_PROCEDURE_GROUP_SAVE", "save" }, @@ -92,6 +93,7 @@ gimp_file_procedure_group_get_type (void) static const GimpEnumDesc descs[] = { + { GIMP_FILE_PROCEDURE_GROUP_NONE, "GIMP_FILE_PROCEDURE_GROUP_NONE", NULL }, { GIMP_FILE_PROCEDURE_GROUP_ANY, "GIMP_FILE_PROCEDURE_GROUP_ANY", NULL }, { GIMP_FILE_PROCEDURE_GROUP_OPEN, "GIMP_FILE_PROCEDURE_GROUP_OPEN", NULL }, { GIMP_FILE_PROCEDURE_GROUP_SAVE, "GIMP_FILE_PROCEDURE_GROUP_SAVE", NULL }, diff --git a/app/plug-in/plug-in-enums.h b/app/plug-in/plug-in-enums.h index 82626b1075..e201eb2ee4 100644 --- a/app/plug-in/plug-in-enums.h +++ b/app/plug-in/plug-in-enums.h @@ -53,6 +53,7 @@ GType gimp_file_procedure_group_get_type (void) G_GNUC_CONST; typedef enum /*< pdb-skip >*/ { + GIMP_FILE_PROCEDURE_GROUP_NONE, GIMP_FILE_PROCEDURE_GROUP_ANY, GIMP_FILE_PROCEDURE_GROUP_OPEN, GIMP_FILE_PROCEDURE_GROUP_SAVE, diff --git a/app/widgets/gimpexportdialog.c b/app/widgets/gimpexportdialog.c index ba8c68cc13..50eee75cad 100644 --- a/app/widgets/gimpexportdialog.c +++ b/app/widgets/gimpexportdialog.c @@ -34,10 +34,7 @@ #include "file/gimp-file.h" -#include "plug-in/gimppluginmanager.h" - #include "gimpexportdialog.h" -#include "gimpfiledialog.h" #include "gimphelp-ids.h" #include "gimp-intl.h" @@ -65,29 +62,23 @@ gimp_export_dialog_init (GimpExportDialog *dialog) GtkWidget * gimp_export_dialog_new (Gimp *gimp) { - GimpExportDialog *dialog; - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - dialog = g_object_new (GIMP_TYPE_EXPORT_DIALOG, - "gimp", gimp, - "title", _("Export Image"), - "role", "gimp-file-export", - "help-id", GIMP_HELP_FILE_EXPORT_AS, - "stock-id", _("_Export"), + return g_object_new (GIMP_TYPE_EXPORT_DIALOG, + "gimp", gimp, + "title", _("Export Image"), + "role", "gimp-file-export", + "help-id", GIMP_HELP_FILE_EXPORT_AS, + "stock-id", _("_Export"), - "automatic-label", _("By Extension"), - "automatic-help-id", GIMP_HELP_FILE_SAVE_BY_EXTENSION, + "automatic-label", _("By Extension"), + "automatic-help-id", GIMP_HELP_FILE_SAVE_BY_EXTENSION, - "action", GTK_FILE_CHOOSER_ACTION_SAVE, - "file-procs", gimp->plug_in_manager->export_procs, - "file-procs-all-images", gimp->plug_in_manager->save_procs, - "file-filter-label", _("All export images"), - "local-only", FALSE, - "do-overwrite-confirmation", TRUE, - NULL); - - return GTK_WIDGET (dialog); + "action", GTK_FILE_CHOOSER_ACTION_SAVE, + "file-procs", GIMP_FILE_PROCEDURE_GROUP_EXPORT, + "file-procs-all-images", GIMP_FILE_PROCEDURE_GROUP_SAVE, + "file-filter-label", _("All export images"), + NULL); } void diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index ba1977fc25..47bf4f60a5 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -39,6 +39,7 @@ #include "pdb/gimppdb.h" +#include "plug-in/gimppluginmanager-file.h" #include "plug-in/gimppluginprocedure.h" #include "gimpfiledialog.h" @@ -213,22 +214,26 @@ gimp_file_dialog_class_init (GimpFileDialogClass *klass) G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_FILE_PROCS, - g_param_spec_pointer ("file-procs", - NULL, NULL, - GIMP_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_enum ("file-procs", + NULL, NULL, + GIMP_TYPE_FILE_PROCEDURE_GROUP, + GIMP_FILE_PROCEDURE_GROUP_NONE, + GIMP_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY)); g_object_class_install_property (object_class, PROP_FILE_PROCS_ALL_IMAGES, - g_param_spec_pointer ("file-procs-all-images", - NULL, NULL, - GIMP_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY)); + g_param_spec_enum ("file-procs-all-images", + NULL, NULL, + GIMP_TYPE_FILE_PROCEDURE_GROUP, + GIMP_FILE_PROCEDURE_GROUP_NONE, + GIMP_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY)); } static void gimp_file_dialog_init (GimpFileDialog *dialog) { - dialog->stock_id = GTK_STOCK_OK; + dialog->stock_id = GTK_STOCK_OK; } static void @@ -273,10 +278,14 @@ gimp_file_dialog_set_property (GObject *object, dialog->file_filter_label = g_value_dup_string (value); break; case PROP_FILE_PROCS: - dialog->file_procs = g_value_get_pointer (value); + dialog->file_procs = + gimp_plug_in_manager_get_file_procedures (dialog->gimp->plug_in_manager, + g_value_get_enum (value)); break; case PROP_FILE_PROCS_ALL_IMAGES: - dialog->file_procs_all_images = g_value_get_pointer (value); + dialog->file_procs_all_images = + gimp_plug_in_manager_get_file_procedures (dialog->gimp->plug_in_manager, + g_value_get_enum (value)); break; default: @@ -325,6 +334,10 @@ gimp_file_dialog_constructed (GObject *object) GTK_RESPONSE_CANCEL, -1); + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (object), FALSE); + gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (object), + TRUE); + if (dialog->help_id) { gimp_help_connect (GTK_WIDGET (dialog), diff --git a/app/widgets/gimpopendialog.c b/app/widgets/gimpopendialog.c index 346b44043c..c436083d37 100644 --- a/app/widgets/gimpopendialog.c +++ b/app/widgets/gimpopendialog.c @@ -20,8 +20,6 @@ #include "config.h" -#include - #include #include @@ -33,9 +31,6 @@ #include "core/gimp.h" #include "core/gimpimage.h" -#include "plug-in/gimppluginmanager.h" - -#include "gimpfiledialog.h" #include "gimphelp-ids.h" #include "gimpopendialog.h" @@ -64,29 +59,23 @@ gimp_open_dialog_init (GimpOpenDialog *dialog) GtkWidget * gimp_open_dialog_new (Gimp *gimp) { - GimpOpenDialog *dialog; - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - dialog = g_object_new (GIMP_TYPE_OPEN_DIALOG, - "gimp", gimp, - "title", _("Open Image"), - "role", "gimp-file-open", - "help-id", GIMP_HELP_FILE_OPEN, - "stock-id", GTK_STOCK_OPEN, + return g_object_new (GIMP_TYPE_OPEN_DIALOG, + "gimp", gimp, + "title", _("Open Image"), + "role", "gimp-file-open", + "help-id", GIMP_HELP_FILE_OPEN, + "stock-id", GTK_STOCK_OPEN, - "automatic-label", _("Automatically Detected"), - "automatic-help-id", GIMP_HELP_FILE_OPEN_BY_EXTENSION, + "automatic-label", _("Automatically Detected"), + "automatic-help-id", GIMP_HELP_FILE_OPEN_BY_EXTENSION, - "action", GTK_FILE_CHOOSER_ACTION_OPEN, - "file-procs", gimp->plug_in_manager->load_procs, - "file-procs-all-images", NULL, - "file-filter-label", NULL, - "local-only", FALSE, - "do-overwrite-confirmation", TRUE, - NULL); - - return GTK_WIDGET (dialog); + "action", GTK_FILE_CHOOSER_ACTION_OPEN, + "file-procs", GIMP_FILE_PROCEDURE_GROUP_OPEN, + "file-procs-all-images", GIMP_FILE_PROCEDURE_GROUP_NONE, + "file-filter-label", NULL, + NULL); } void diff --git a/app/widgets/gimpopendialog.h b/app/widgets/gimpopendialog.h index 7b35d41db8..c8b0bf0c01 100644 --- a/app/widgets/gimpopendialog.h +++ b/app/widgets/gimpopendialog.h @@ -21,6 +21,8 @@ #ifndef __GIMP_OPEN_DIALOG_H__ #define __GIMP_OPEN_DIALOG_H__ +#include "gimpfiledialog.h" + G_BEGIN_DECLS #define GIMP_TYPE_OPEN_DIALOG (gimp_open_dialog_get_type ()) diff --git a/app/widgets/gimpsavedialog.c b/app/widgets/gimpsavedialog.c index 3083a56858..4effe46e8a 100644 --- a/app/widgets/gimpsavedialog.c +++ b/app/widgets/gimpsavedialog.c @@ -35,9 +35,6 @@ #include "file/gimp-file.h" -#include "plug-in/gimppluginmanager.h" - -#include "gimpfiledialog.h" #include "gimphelp-ids.h" #include "gimpsavedialog.h" @@ -134,29 +131,23 @@ gimp_save_dialog_load_state (GimpFileDialog *dialog, GtkWidget * gimp_save_dialog_new (Gimp *gimp) { - GimpSaveDialog *dialog; - g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); - dialog = g_object_new (GIMP_TYPE_SAVE_DIALOG, - "gimp", gimp, - "title", _("Save Image"), - "role", "gimp-file-save", - "help-id", GIMP_HELP_FILE_SAVE, - "stock-id", GTK_STOCK_SAVE, + return g_object_new (GIMP_TYPE_SAVE_DIALOG, + "gimp", gimp, + "title", _("Save Image"), + "role", "gimp-file-save", + "help-id", GIMP_HELP_FILE_SAVE, + "stock-id", GTK_STOCK_SAVE, - "automatic-label", _("By Extension"), - "automatic-help-id", GIMP_HELP_FILE_SAVE_BY_EXTENSION, + "automatic-label", _("By Extension"), + "automatic-help-id", GIMP_HELP_FILE_SAVE_BY_EXTENSION, - "action", GTK_FILE_CHOOSER_ACTION_SAVE, - "file-procs", gimp->plug_in_manager->save_procs, - "file-procs-all-images", gimp->plug_in_manager->export_procs, - "file-filter-label", _("All XCF images"), - "local-only", FALSE, - "do-overwrite-confirmation", TRUE, - NULL); - - return GTK_WIDGET (dialog); + "action", GTK_FILE_CHOOSER_ACTION_SAVE, + "file-procs", GIMP_FILE_PROCEDURE_GROUP_SAVE, + "file-procs-all-images", GIMP_FILE_PROCEDURE_GROUP_EXPORT, + "file-filter-label", _("All XCF images"), + NULL); } void