2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-02-27 22:20:19 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpfiledialog.c
|
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-02-27 22:20:19 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-02-27 22:20:19 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-02-27 22:20:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2004-02-27 22:20:19 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-05-14 01:18:35 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpimage.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2004-10-05 06:25:04 +08:00
|
|
|
#include "config/gimpguiconfig.h"
|
2004-02-27 23:43:58 +08:00
|
|
|
|
|
|
|
#include "file/file-utils.h"
|
2009-05-01 15:03:13 +08:00
|
|
|
#include "file/gimp-file.h"
|
2004-02-27 23:43:58 +08:00
|
|
|
|
2006-08-06 05:21:01 +08:00
|
|
|
#include "pdb/gimppdb.h"
|
|
|
|
|
2006-04-29 06:26:51 +08:00
|
|
|
#include "plug-in/gimppluginmanager.h"
|
2006-08-06 05:21:01 +08:00
|
|
|
#include "plug-in/gimppluginprocedure.h"
|
2006-03-31 17:15:08 +08:00
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "gimpfiledialog.h"
|
2004-07-17 05:24:39 +08:00
|
|
|
#include "gimpfileprocview.h"
|
2004-07-18 03:53:05 +08:00
|
|
|
#include "gimphelp-ids.h"
|
2005-09-29 05:20:05 +08:00
|
|
|
#include "gimpprogressbox.h"
|
2004-08-25 01:16:46 +08:00
|
|
|
#include "gimpview.h"
|
2004-08-26 22:20:30 +08:00
|
|
|
#include "gimpviewrendererimagefile.h"
|
2004-07-18 03:53:05 +08:00
|
|
|
#include "gimpthumbbox.h"
|
2006-11-24 22:08:40 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2004-04-16 00:28:26 +08:00
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2009-08-27 03:55:23 +08:00
|
|
|
/* an arbitrary limit to keep the file dialog from becoming too wide */
|
|
|
|
#define MAX_EXTENSIONS 4
|
|
|
|
|
|
|
|
|
2008-05-08 19:30:54 +08:00
|
|
|
struct _GimpFileDialogState
|
|
|
|
{
|
|
|
|
gchar *filter_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-01 23:29:02 +08:00
|
|
|
static void gimp_file_dialog_progress_iface_init (GimpProgressInterface *iface);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2009-05-01 23:29:02 +08:00
|
|
|
static void gimp_file_dialog_destroy (GtkObject *object);
|
|
|
|
static gboolean gimp_file_dialog_delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event);
|
|
|
|
static void gimp_file_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response_id);
|
2004-08-11 02:47:21 +08:00
|
|
|
static GimpProgress *
|
2009-05-01 23:29:02 +08:00
|
|
|
gimp_file_dialog_progress_start (GimpProgress *progress,
|
|
|
|
const gchar *message,
|
|
|
|
gboolean cancelable);
|
|
|
|
static void gimp_file_dialog_progress_end (GimpProgress *progress);
|
|
|
|
static gboolean gimp_file_dialog_progress_is_active (GimpProgress *progress);
|
|
|
|
static void gimp_file_dialog_progress_set_text (GimpProgress *progress,
|
|
|
|
const gchar *message);
|
|
|
|
static void gimp_file_dialog_progress_set_value (GimpProgress *progress,
|
|
|
|
gdouble percentage);
|
|
|
|
static gdouble gimp_file_dialog_progress_get_value (GimpProgress *progress);
|
|
|
|
static void gimp_file_dialog_progress_pulse (GimpProgress *progress);
|
|
|
|
static guint32 gimp_file_dialog_progress_get_window (GimpProgress *progress);
|
|
|
|
|
|
|
|
static void gimp_file_dialog_add_user_dir (GimpFileDialog *dialog,
|
|
|
|
GUserDirectory directory);
|
|
|
|
static void gimp_file_dialog_add_preview (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp);
|
|
|
|
static void gimp_file_dialog_add_filters (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp,
|
2009-08-28 14:19:44 +08:00
|
|
|
GSList *file_procs,
|
|
|
|
GSList *file_procs_all_images);
|
2009-08-28 13:49:17 +08:00
|
|
|
static void gimp_file_dialog_process_procedure (GimpPlugInProcedure
|
|
|
|
*file_proc,
|
|
|
|
GtkFileFilter **filter_out,
|
|
|
|
GtkFileFilter *all);
|
2009-05-01 23:29:02 +08:00
|
|
|
static void gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
GSList *file_procs,
|
|
|
|
const gchar *automatic,
|
|
|
|
const gchar *automatic_help_id);
|
|
|
|
|
|
|
|
static void gimp_file_dialog_selection_changed (GtkFileChooser *chooser,
|
|
|
|
GimpFileDialog *dialog);
|
|
|
|
static void gimp_file_dialog_update_preview (GtkFileChooser *chooser,
|
|
|
|
GimpFileDialog *dialog);
|
|
|
|
|
|
|
|
static void gimp_file_dialog_proc_changed (GimpFileProcView *view,
|
|
|
|
GimpFileDialog *dialog);
|
|
|
|
|
|
|
|
static void gimp_file_dialog_help_func (const gchar *help_id,
|
|
|
|
gpointer help_data);
|
|
|
|
static void gimp_file_dialog_help_clicked (GtkWidget *widget,
|
|
|
|
gpointer dialog);
|
2008-05-08 18:44:05 +08:00
|
|
|
|
|
|
|
static gchar * gimp_file_dialog_pattern_from_extension (const gchar *extension);
|
2009-05-01 23:04:26 +08:00
|
|
|
static gchar * gimp_file_dialog_get_documents_uri (void);
|
2009-05-01 23:29:02 +08:00
|
|
|
static gchar * gimp_file_dialog_get_dirname_from_uri (const gchar *uri);
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpFileDialog, gimp_file_dialog,
|
|
|
|
GTK_TYPE_FILE_CHOOSER_DIALOG,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
|
2006-05-15 17:46:31 +08:00
|
|
|
gimp_file_dialog_progress_iface_init))
|
2005-12-20 06:37:49 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_file_dialog_parent_class
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_class_init (GimpFileDialogClass *klass)
|
|
|
|
{
|
2008-10-22 03:23:44 +08:00
|
|
|
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
|
2004-02-27 22:20:19 +08:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2004-08-11 05:20:38 +08:00
|
|
|
GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
object_class->destroy = gimp_file_dialog_destroy;
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
widget_class->delete_event = gimp_file_dialog_delete_event;
|
2004-08-11 05:20:38 +08:00
|
|
|
|
|
|
|
dialog_class->response = gimp_file_dialog_response;
|
2004-02-27 22:20:19 +08:00
|
|
|
}
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
static void
|
2005-12-20 06:37:49 +08:00
|
|
|
gimp_file_dialog_init (GimpFileDialog *dialog)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_progress_iface_init (GimpProgressInterface *iface)
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
iface->start = gimp_file_dialog_progress_start;
|
|
|
|
iface->end = gimp_file_dialog_progress_end;
|
|
|
|
iface->is_active = gimp_file_dialog_progress_is_active;
|
|
|
|
iface->set_text = gimp_file_dialog_progress_set_text;
|
|
|
|
iface->set_value = gimp_file_dialog_progress_set_value;
|
|
|
|
iface->get_value = gimp_file_dialog_progress_get_value;
|
|
|
|
iface->pulse = gimp_file_dialog_progress_pulse;
|
|
|
|
iface->get_window = gimp_file_dialog_progress_get_window;
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (object);
|
|
|
|
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
|
|
|
|
dialog->progress = NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_file_dialog_delete_event (GtkWidget *widget,
|
|
|
|
GdkEventAny *event)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-08-11 05:20:38 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response_id)
|
|
|
|
{
|
|
|
|
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
|
|
|
|
|
|
|
|
if (response_id != GTK_RESPONSE_OK && file_dialog->busy)
|
|
|
|
{
|
|
|
|
file_dialog->canceled = TRUE;
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (file_dialog->progress &&
|
|
|
|
GIMP_PROGRESS_BOX (file_dialog->progress)->active &&
|
2005-09-29 05:20:05 +08:00
|
|
|
GIMP_PROGRESS_BOX (file_dialog->progress)->cancelable)
|
|
|
|
{
|
|
|
|
gimp_progress_cancel (GIMP_PROGRESS (dialog));
|
|
|
|
}
|
2004-08-11 05:20:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
static GimpProgress *
|
|
|
|
gimp_file_dialog_progress_start (GimpProgress *progress,
|
|
|
|
const gchar *message,
|
|
|
|
gboolean cancelable)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
2008-10-22 03:23:44 +08:00
|
|
|
GimpProgress *retval = NULL;
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
{
|
|
|
|
retval = gimp_progress_start (GIMP_PROGRESS (dialog->progress),
|
|
|
|
message, cancelable);
|
|
|
|
gtk_widget_show (dialog->progress);
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, cancelable);
|
|
|
|
}
|
2007-05-16 16:21:35 +08:00
|
|
|
|
2005-09-29 05:20:05 +08:00
|
|
|
return retval;
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_progress_end (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
{
|
|
|
|
gimp_progress_end (GIMP_PROGRESS (dialog->progress));
|
|
|
|
gtk_widget_hide (dialog->progress);
|
|
|
|
}
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
2004-08-11 18:29:56 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_file_dialog_progress_is_active (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
return gimp_progress_is_active (GIMP_PROGRESS (dialog->progress));
|
|
|
|
|
|
|
|
return FALSE;
|
2004-08-11 18:29:56 +08:00
|
|
|
}
|
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_progress_set_text (GimpProgress *progress,
|
|
|
|
const gchar *message)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
gimp_progress_set_text (GIMP_PROGRESS (dialog->progress), message);
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_progress_set_value (GimpProgress *progress,
|
|
|
|
gdouble percentage)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
gimp_progress_set_value (GIMP_PROGRESS (dialog->progress), percentage);
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble
|
|
|
|
gimp_file_dialog_progress_get_value (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
return gimp_progress_get_value (GIMP_PROGRESS (dialog->progress));
|
|
|
|
|
|
|
|
return 0.0;
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
2005-02-12 22:18:12 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_progress_pulse (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
if (dialog->progress)
|
|
|
|
gimp_progress_pulse (GIMP_PROGRESS (dialog->progress));
|
2005-02-12 22:18:12 +08:00
|
|
|
}
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
static guint32
|
|
|
|
gimp_file_dialog_progress_get_window (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (progress);
|
|
|
|
|
|
|
|
return (guint32) gimp_window_get_native (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
GtkWidget *
|
2009-04-24 13:36:41 +08:00
|
|
|
gimp_file_dialog_new (Gimp *gimp,
|
|
|
|
GimpFileChooserAction action,
|
|
|
|
const gchar *title,
|
|
|
|
const gchar *role,
|
|
|
|
const gchar *stock_id,
|
|
|
|
const gchar *help_id)
|
2004-02-27 22:20:19 +08:00
|
|
|
{
|
2009-08-28 14:19:44 +08:00
|
|
|
GimpFileDialog *dialog = NULL;
|
|
|
|
GSList *file_procs = NULL;
|
|
|
|
GSList *file_procs_all_images = NULL;
|
|
|
|
const gchar *automatic = NULL;
|
|
|
|
const gchar *automatic_help_id = NULL;
|
|
|
|
gboolean local_only = FALSE;
|
|
|
|
GtkFileChooserAction gtk_action = 0;
|
2004-02-27 22:20:19 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (title != NULL, NULL);
|
|
|
|
g_return_val_if_fail (role != NULL, NULL);
|
|
|
|
g_return_val_if_fail (stock_id != NULL, NULL);
|
|
|
|
g_return_val_if_fail (help_id != NULL, NULL);
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
2009-04-24 13:36:41 +08:00
|
|
|
case GIMP_FILE_CHOOSER_ACTION_OPEN:
|
2009-08-28 14:19:44 +08:00
|
|
|
gtk_action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
|
|
|
file_procs = gimp->plug_in_manager->load_procs;
|
|
|
|
file_procs_all_images = NULL;
|
|
|
|
automatic = _("Automatically Detected");
|
|
|
|
automatic_help_id = GIMP_HELP_FILE_OPEN_BY_EXTENSION;
|
2005-07-09 02:27:24 +08:00
|
|
|
|
|
|
|
/* FIXME */
|
2006-04-26 17:13:47 +08:00
|
|
|
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
|
|
|
|
"file-uri-load") == NULL);
|
2004-07-17 05:24:39 +08:00
|
|
|
break;
|
|
|
|
|
2009-04-24 13:36:41 +08:00
|
|
|
case GIMP_FILE_CHOOSER_ACTION_SAVE:
|
2009-04-25 16:51:07 +08:00
|
|
|
case GIMP_FILE_CHOOSER_ACTION_EXPORT:
|
2009-08-28 14:19:44 +08:00
|
|
|
gtk_action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
|
|
|
file_procs = (action == GIMP_FILE_CHOOSER_ACTION_SAVE ?
|
|
|
|
gimp->plug_in_manager->save_procs :
|
|
|
|
gimp->plug_in_manager->export_procs);
|
|
|
|
file_procs_all_images = (action == GIMP_FILE_CHOOSER_ACTION_SAVE ?
|
|
|
|
gimp->plug_in_manager->export_procs :
|
|
|
|
gimp->plug_in_manager->save_procs);
|
|
|
|
automatic = _("By Extension");
|
|
|
|
automatic_help_id = GIMP_HELP_FILE_SAVE_BY_EXTENSION;
|
2005-07-09 02:27:24 +08:00
|
|
|
|
|
|
|
/* FIXME */
|
2006-04-26 17:13:47 +08:00
|
|
|
local_only = (gimp_pdb_lookup_procedure (gimp->pdb,
|
|
|
|
"file-uri-save") == NULL);
|
2004-07-17 05:24:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
dialog = g_object_new (GIMP_TYPE_FILE_DIALOG,
|
2005-12-29 04:02:54 +08:00
|
|
|
"title", title,
|
|
|
|
"role", role,
|
2009-04-24 13:36:41 +08:00
|
|
|
"action", gtk_action,
|
2005-12-29 04:02:54 +08:00
|
|
|
"local-only", local_only,
|
|
|
|
"do-overwrite-confirmation", TRUE,
|
2004-02-27 22:20:19 +08:00
|
|
|
NULL);
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
stock_id, GTK_RESPONSE_OK,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
|
2006-05-08 23:43:21 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
gimp_help_connect (GTK_WIDGET (dialog),
|
2004-07-18 03:53:05 +08:00
|
|
|
gimp_file_dialog_help_func, help_id, dialog);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2004-10-05 06:25:04 +08:00
|
|
|
if (GIMP_GUI_CONFIG (gimp->config)->show_help_button && help_id)
|
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
GtkWidget *action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
|
2004-10-05 06:25:04 +08:00
|
|
|
GtkWidget *button = gtk_button_new_from_stock (GTK_STOCK_HELP);
|
|
|
|
|
|
|
|
gtk_box_pack_end (GTK_BOX (action_area), button, FALSE, TRUE, 0);
|
|
|
|
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (action_area),
|
|
|
|
button, TRUE);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
g_object_set_data_full (G_OBJECT (dialog), "gimp-dialog-help-id",
|
|
|
|
g_strdup (help_id),
|
|
|
|
(GDestroyNotify) g_free);
|
|
|
|
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (gimp_file_dialog_help_clicked),
|
|
|
|
dialog);
|
2005-07-09 02:27:24 +08:00
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (dialog), "gimp-dialog-help-button", button);
|
2004-10-05 06:25:04 +08:00
|
|
|
}
|
|
|
|
|
2007-12-15 04:08:39 +08:00
|
|
|
gimp_file_dialog_add_user_dir (dialog, G_USER_DIRECTORY_PICTURES);
|
|
|
|
gimp_file_dialog_add_user_dir (dialog, G_USER_DIRECTORY_DOCUMENTS);
|
2007-12-14 05:19:44 +08:00
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
gimp_file_dialog_add_preview (dialog, gimp);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2009-08-28 14:19:44 +08:00
|
|
|
gimp_file_dialog_add_filters (dialog,
|
|
|
|
gimp,
|
|
|
|
file_procs,
|
|
|
|
file_procs_all_images);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2004-08-11 05:20:38 +08:00
|
|
|
gimp_file_dialog_add_proc_selection (dialog, gimp, file_procs, automatic,
|
|
|
|
automatic_help_id);
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2005-09-29 05:20:05 +08:00
|
|
|
dialog->progress = gimp_progress_box_new ();
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
|
|
|
dialog->progress, FALSE, FALSE, 0);
|
2004-02-27 23:43:58 +08:00
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
return GTK_WIDGET (dialog);
|
|
|
|
}
|
|
|
|
|
2004-08-11 05:20:38 +08:00
|
|
|
void
|
|
|
|
gimp_file_dialog_set_sensitive (GimpFileDialog *dialog,
|
|
|
|
gboolean sensitive)
|
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
GtkWidget *content_area;
|
|
|
|
GList *children;
|
|
|
|
GList *list;
|
2006-11-14 21:46:43 +08:00
|
|
|
|
2004-08-11 05:20:38 +08:00
|
|
|
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
|
|
|
|
|
2008-10-22 03:23:44 +08:00
|
|
|
/* bail out if we are already destroyed */
|
|
|
|
if (! dialog->progress)
|
|
|
|
return;
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
|
|
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (content_area));
|
2006-11-14 21:46:43 +08:00
|
|
|
|
|
|
|
for (list = children; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
/* skip the last item (the action area) */
|
|
|
|
if (! g_list_next (list))
|
|
|
|
break;
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (list->data, sensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (children);
|
|
|
|
|
2007-05-16 16:21:35 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_CANCEL, sensitive);
|
2006-11-14 21:46:43 +08:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
|
|
|
GTK_RESPONSE_OK, sensitive);
|
2004-08-11 05:20:38 +08:00
|
|
|
|
|
|
|
dialog->busy = ! sensitive;
|
|
|
|
dialog->canceled = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
void
|
2006-04-05 16:38:33 +08:00
|
|
|
gimp_file_dialog_set_file_proc (GimpFileDialog *dialog,
|
|
|
|
GimpPlugInProcedure *file_proc)
|
2004-02-27 22:20:19 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
if (file_proc != dialog->file_proc)
|
|
|
|
gimp_file_proc_view_set_proc (GIMP_FILE_PROC_VIEW (dialog->proc_view),
|
|
|
|
file_proc);
|
2004-02-27 22:20:19 +08:00
|
|
|
}
|
2004-02-27 23:43:58 +08:00
|
|
|
|
2004-03-01 20:27:33 +08:00
|
|
|
void
|
2008-10-05 23:21:02 +08:00
|
|
|
gimp_file_dialog_set_open_image (GimpFileDialog *dialog,
|
|
|
|
GimpImage *image,
|
|
|
|
gboolean open_as_layers)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
|
|
|
|
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
|
|
|
|
|
|
|
|
dialog->image = image;
|
|
|
|
dialog->open_as_layers = open_as_layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
|
2009-05-01 18:22:41 +08:00
|
|
|
Gimp *gimp,
|
2008-10-05 23:21:02 +08:00
|
|
|
GimpImage *image,
|
|
|
|
gboolean save_a_copy,
|
2009-04-25 16:51:07 +08:00
|
|
|
gboolean export,
|
2008-10-05 23:21:02 +08:00
|
|
|
gboolean close_after_saving)
|
2004-03-01 20:27:33 +08:00
|
|
|
{
|
2009-05-01 23:04:26 +08:00
|
|
|
const gchar *dir_uri = NULL;
|
|
|
|
const gchar *name_uri = NULL;
|
2009-05-05 09:00:53 +08:00
|
|
|
const gchar *ext_uri = NULL;
|
2009-05-01 23:04:26 +08:00
|
|
|
gchar *docs_uri = NULL;
|
|
|
|
gchar *dirname = NULL;
|
|
|
|
gchar *basename = NULL;
|
2004-03-01 20:27:33 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2004-03-01 20:27:33 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
docs_uri = gimp_file_dialog_get_documents_uri ();
|
|
|
|
|
2007-01-21 03:38:09 +08:00
|
|
|
dialog->image = image;
|
|
|
|
dialog->save_a_copy = save_a_copy;
|
2009-04-25 16:51:07 +08:00
|
|
|
dialog->export = export;
|
2007-01-21 03:38:09 +08:00
|
|
|
dialog->close_after_saving = close_after_saving;
|
2004-03-01 20:27:33 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
gimp_file_dialog_set_file_proc (dialog, NULL);
|
2004-11-16 21:37:36 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! export)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Priority of default paths for Save:
|
|
|
|
*
|
|
|
|
* 1. Last Save a copy-path (applies only to Save a copy)
|
|
|
|
* 2. Last Save path
|
|
|
|
* 3. Path of source XCF
|
|
|
|
* 4. Path of Import source
|
|
|
|
* 5. Last Save path of any GIMP document
|
|
|
|
* 6. The OS 'Documents' path
|
|
|
|
*/
|
2004-08-23 17:32:06 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (save_a_copy)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_SAVE_A_COPY_URI_KEY);
|
2005-01-14 01:41:48 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! dir_uri)
|
2009-09-01 04:47:18 +08:00
|
|
|
dir_uri = gimp_object_get_name (image);
|
2007-01-14 00:56:30 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
"gimp-image-source-uri");
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (gimp),
|
|
|
|
GIMP_FILE_SAVE_LAST_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
|
|
|
dir_uri = docs_uri;
|
|
|
|
|
|
|
|
|
|
|
|
/* Priority of default basenames for Save:
|
|
|
|
*
|
|
|
|
* 1. Last Save a copy-name (applies only to Save a copy)
|
|
|
|
* 2. Last Save name
|
2009-07-03 04:07:30 +08:00
|
|
|
* 3. Last Export name
|
|
|
|
* 3. The source image path
|
2009-05-01 23:04:26 +08:00
|
|
|
* 3. 'Untitled'
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (save_a_copy)
|
2009-05-17 17:01:28 +08:00
|
|
|
name_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_SAVE_A_COPY_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! name_uri)
|
2009-09-01 04:47:18 +08:00
|
|
|
name_uri = gimp_object_get_name (image);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! name_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
name_uri = g_object_get_data (G_OBJECT (image),
|
2009-09-15 05:23:10 +08:00
|
|
|
GIMP_FILE_EXPORT_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
2009-07-03 04:07:30 +08:00
|
|
|
if (! name_uri)
|
|
|
|
name_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! name_uri)
|
|
|
|
name_uri = gimp_image_get_uri (image); /* Untitled */
|
2009-05-05 09:00:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Priority of default type/extension for Save:
|
|
|
|
*
|
|
|
|
* 1. Type of last Save
|
|
|
|
* 2. .xcf (which we don't explicitly append)
|
|
|
|
*/
|
2009-09-01 04:47:18 +08:00
|
|
|
ext_uri = gimp_object_get_name (image);
|
2009-05-05 09:00:53 +08:00
|
|
|
|
|
|
|
if (! ext_uri)
|
|
|
|
ext_uri = "file:///we/only/care/about/extension.xcf";
|
2006-08-29 17:55:34 +08:00
|
|
|
}
|
2009-05-01 23:04:26 +08:00
|
|
|
else /* if (export) */
|
2006-08-29 17:55:34 +08:00
|
|
|
{
|
2009-05-01 23:04:26 +08:00
|
|
|
/*
|
|
|
|
* Priority of default paths for Export:
|
|
|
|
*
|
|
|
|
* 1. Last Export path
|
|
|
|
* 2. Last Export path of any document
|
|
|
|
* 3. Path of import source
|
|
|
|
* 4. Path of XCF source
|
|
|
|
* 5. Last path of any save to XCF
|
|
|
|
* 6. The OS 'Documents' path
|
|
|
|
*/
|
2006-08-29 17:55:34 +08:00
|
|
|
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_EXPORT_URI_KEY);
|
2005-01-14 01:41:48 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (gimp),
|
|
|
|
GIMP_FILE_EXPORT_LAST_URI_KEY);
|
2009-05-16 06:05:15 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
"gimp-image-source-uri");
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
2009-09-01 04:47:18 +08:00
|
|
|
dir_uri = gimp_object_get_name (image);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
dir_uri = g_object_get_data (G_OBJECT (gimp),
|
|
|
|
GIMP_FILE_SAVE_LAST_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! dir_uri)
|
|
|
|
dir_uri = docs_uri;
|
|
|
|
|
|
|
|
|
|
|
|
/* Priority of default basenames for Export:
|
|
|
|
*
|
|
|
|
* 1. Last Export name
|
|
|
|
* 3. Save URI
|
2009-09-15 05:23:10 +08:00
|
|
|
* 2. Source file name
|
2009-05-01 23:04:26 +08:00
|
|
|
* 3. 'Untitled'
|
|
|
|
*/
|
|
|
|
|
2009-05-17 17:01:28 +08:00
|
|
|
name_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_EXPORT_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! name_uri)
|
2009-09-15 05:23:10 +08:00
|
|
|
name_uri = gimp_object_get_name (image);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! name_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
name_uri = g_object_get_data (G_OBJECT (image),
|
2009-09-15 05:23:10 +08:00
|
|
|
GIMP_FILE_IMPORT_SOURCE_URI_KEY);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
if (! name_uri)
|
|
|
|
name_uri = gimp_image_get_uri (image); /* Untitled */
|
2009-05-05 09:00:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Priority of default type/extension for Export:
|
|
|
|
*
|
|
|
|
* 1. Type of last Export
|
|
|
|
* 3. Type of latest Export of any document
|
|
|
|
* 2. .png
|
|
|
|
*/
|
2009-05-17 17:01:28 +08:00
|
|
|
ext_uri = g_object_get_data (G_OBJECT (image),
|
|
|
|
GIMP_FILE_EXPORT_URI_KEY);
|
2009-05-05 09:00:53 +08:00
|
|
|
|
|
|
|
if (! ext_uri)
|
2009-05-17 17:01:28 +08:00
|
|
|
ext_uri = g_object_get_data (G_OBJECT (gimp),
|
|
|
|
GIMP_FILE_EXPORT_LAST_URI_KEY);
|
2009-05-05 09:00:53 +08:00
|
|
|
|
|
|
|
if (! ext_uri)
|
|
|
|
ext_uri = "file:///we/only/care/about/extension.png";
|
2007-08-10 16:27:11 +08:00
|
|
|
}
|
2006-06-17 17:32:30 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
dirname = gimp_file_dialog_get_dirname_from_uri (dir_uri);
|
2009-05-17 17:01:28 +08:00
|
|
|
|
2009-05-05 09:00:53 +08:00
|
|
|
if (ext_uri)
|
|
|
|
{
|
|
|
|
gchar *uri_new_ext = file_utils_uri_with_new_ext (name_uri,
|
|
|
|
ext_uri);
|
|
|
|
basename = file_utils_uri_display_basename (uri_new_ext);
|
|
|
|
g_free (uri_new_ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
basename = file_utils_uri_display_basename (name_uri);
|
|
|
|
}
|
2007-08-10 16:27:11 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), dirname);
|
2007-08-10 16:27:11 +08:00
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
|
2009-05-01 23:04:26 +08:00
|
|
|
|
|
|
|
g_free (docs_uri);
|
2006-06-17 17:32:30 +08:00
|
|
|
g_free (basename);
|
2009-05-01 23:04:26 +08:00
|
|
|
g_free (dirname);
|
2004-03-01 20:27:33 +08:00
|
|
|
}
|
|
|
|
|
2008-05-08 19:30:54 +08:00
|
|
|
GimpFileDialogState *
|
|
|
|
gimp_file_dialog_get_state (GimpFileDialog *dialog)
|
|
|
|
{
|
|
|
|
GimpFileDialogState *state;
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_FILE_DIALOG (dialog), NULL);
|
|
|
|
|
|
|
|
state = g_slice_new0 (GimpFileDialogState);
|
|
|
|
|
|
|
|
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
state->filter_name = g_strdup (gtk_file_filter_get_name (filter));
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_file_dialog_set_state (GimpFileDialog *dialog,
|
|
|
|
GimpFileDialogState *state)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
|
|
|
|
g_return_if_fail (state != NULL);
|
|
|
|
|
|
|
|
if (state->filter_name)
|
|
|
|
{
|
|
|
|
GSList *filters;
|
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (dialog));
|
|
|
|
|
|
|
|
for (list = filters; list; list = list->next)
|
|
|
|
{
|
|
|
|
GtkFileFilter *filter = GTK_FILE_FILTER (list->data);
|
|
|
|
const gchar *name = gtk_file_filter_get_name (filter);
|
|
|
|
|
|
|
|
if (name && strcmp (state->filter_name, name) == 0)
|
|
|
|
{
|
|
|
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (filters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_file_dialog_state_destroy (GimpFileDialogState *state)
|
|
|
|
{
|
|
|
|
g_return_if_fail (state != NULL);
|
|
|
|
|
|
|
|
g_free (state->filter_name);
|
|
|
|
g_slice_free (GimpFileDialogState, state);
|
|
|
|
}
|
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2007-12-15 04:08:39 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_add_user_dir (GimpFileDialog *dialog,
|
|
|
|
GUserDirectory directory)
|
|
|
|
{
|
|
|
|
const gchar *user_dir = g_get_user_special_dir (directory);
|
|
|
|
|
|
|
|
if (user_dir)
|
|
|
|
gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
|
|
|
|
user_dir, NULL);
|
|
|
|
}
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_add_preview (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
if (gimp->config->thumbnail_size <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
|
|
|
|
|
|
|
|
g_signal_connect (dialog, "selection-changed",
|
|
|
|
G_CALLBACK (gimp_file_dialog_selection_changed),
|
|
|
|
dialog);
|
|
|
|
g_signal_connect (dialog, "update-preview",
|
|
|
|
G_CALLBACK (gimp_file_dialog_update_preview),
|
|
|
|
dialog);
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
dialog->thumb_box = gimp_thumb_box_new (gimp_get_user_context (gimp));
|
2004-07-17 05:24:39 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (dialog->thumb_box), FALSE);
|
|
|
|
gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog),
|
|
|
|
dialog->thumb_box);
|
|
|
|
gtk_widget_show (dialog->thumb_box);
|
|
|
|
|
|
|
|
#ifdef ENABLE_FILE_SYSTEM_ICONS
|
2004-08-26 22:20:30 +08:00
|
|
|
GIMP_VIEW_RENDERER_IMAGEFILE (GIMP_VIEW (GIMP_THUMB_BOX (dialog->thumb_box)->preview)->renderer)->file_system = _gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (dialog));
|
2004-07-17 05:24:39 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-28 14:19:44 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_dialog_add_filters:
|
|
|
|
* @dialog:
|
|
|
|
* @gimp:
|
|
|
|
* @file_procs: The image types that can be chosen from
|
|
|
|
* the drop down
|
|
|
|
* @file_procs_all_images: The additional images types shown when
|
|
|
|
* "All images" is selected
|
|
|
|
*
|
|
|
|
**/
|
2004-07-17 05:24:39 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_add_filters (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp,
|
2009-08-28 14:19:44 +08:00
|
|
|
GSList *file_procs,
|
|
|
|
GSList *file_procs_all_images)
|
2004-07-17 05:24:39 +08:00
|
|
|
{
|
2005-02-08 02:46:03 +08:00
|
|
|
GtkFileFilter *all;
|
2004-07-17 05:24:39 +08:00
|
|
|
GSList *list;
|
|
|
|
|
2005-02-08 02:46:03 +08:00
|
|
|
all = gtk_file_filter_new ();
|
2006-03-04 06:46:01 +08:00
|
|
|
gtk_file_filter_set_name (all, _("All files"));
|
2005-02-08 02:46:03 +08:00
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all);
|
|
|
|
gtk_file_filter_add_pattern (all, "*");
|
|
|
|
|
|
|
|
all = gtk_file_filter_new ();
|
2006-03-04 06:46:01 +08:00
|
|
|
gtk_file_filter_set_name (all, _("All images"));
|
2005-02-08 02:46:03 +08:00
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2009-08-28 14:19:44 +08:00
|
|
|
/* Add the normal file procs */
|
2004-07-17 05:24:39 +08:00
|
|
|
for (list = file_procs; list; list = g_slist_next (list))
|
|
|
|
{
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpPlugInProcedure *file_proc = list->data;
|
2009-08-28 13:49:17 +08:00
|
|
|
GtkFileFilter *filter = NULL;
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2009-08-28 13:49:17 +08:00
|
|
|
gimp_file_dialog_process_procedure (file_proc,
|
|
|
|
&filter,
|
|
|
|
all);
|
|
|
|
if (filter)
|
2004-07-17 05:24:39 +08:00
|
|
|
{
|
2009-08-28 13:49:17 +08:00
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog),
|
|
|
|
filter);
|
|
|
|
g_object_unref (filter);
|
|
|
|
}
|
|
|
|
}
|
2009-08-28 14:19:44 +08:00
|
|
|
|
|
|
|
/* Add the "rest" of the file procs only as filters to
|
|
|
|
* "All images"
|
|
|
|
*/
|
|
|
|
for (list = file_procs_all_images; list; list = g_slist_next (list))
|
|
|
|
{
|
|
|
|
GimpPlugInProcedure *file_proc = list->data;
|
|
|
|
|
|
|
|
gimp_file_dialog_process_procedure (file_proc,
|
|
|
|
NULL,
|
|
|
|
all);
|
|
|
|
}
|
2009-08-28 13:49:17 +08:00
|
|
|
|
|
|
|
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), all);
|
|
|
|
}
|
2004-07-17 05:24:39 +08:00
|
|
|
|
|
|
|
|
2009-08-28 13:49:17 +08:00
|
|
|
/**
|
|
|
|
* gimp_file_dialog_process_procedure:
|
|
|
|
* @file_proc:
|
|
|
|
* @filter_out:
|
|
|
|
* @all:
|
|
|
|
*
|
|
|
|
* Creates a #GtkFileFilter of @file_proc and adds the extensions to
|
|
|
|
* the @all filter. The returned #GtkFileFilter has a normal ref and
|
|
|
|
* must be unreffed when used.
|
|
|
|
**/
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_process_procedure (GimpPlugInProcedure *file_proc,
|
|
|
|
GtkFileFilter **filter_out,
|
|
|
|
GtkFileFilter *all)
|
|
|
|
{
|
|
|
|
GtkFileFilter *filter = NULL;
|
|
|
|
GString *str = NULL;
|
|
|
|
GSList *ext = NULL;
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
if (!file_proc->extensions_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new ();
|
|
|
|
str = g_string_new (gimp_plug_in_procedure_get_label (file_proc));
|
|
|
|
|
|
|
|
/* Take ownership directly so we don't have to mess with a floating
|
|
|
|
* ref
|
|
|
|
*/
|
|
|
|
g_object_ref_sink (filter);
|
|
|
|
|
|
|
|
for (ext = file_proc->extensions_list, i = 0;
|
|
|
|
ext;
|
|
|
|
ext = g_slist_next (ext), i++)
|
|
|
|
{
|
|
|
|
const gchar *extension = ext->data;
|
|
|
|
gchar *pattern;
|
|
|
|
|
|
|
|
pattern = gimp_file_dialog_pattern_from_extension (extension);
|
|
|
|
gtk_file_filter_add_pattern (filter, pattern);
|
|
|
|
gtk_file_filter_add_pattern (all, pattern);
|
|
|
|
g_free (pattern);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2009-08-28 13:49:17 +08:00
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
g_string_append (str, " (");
|
|
|
|
}
|
|
|
|
else if (i <= MAX_EXTENSIONS)
|
|
|
|
{
|
|
|
|
g_string_append (str, ", ");
|
|
|
|
}
|
2004-07-27 08:26:14 +08:00
|
|
|
|
2009-08-28 13:49:17 +08:00
|
|
|
if (i < MAX_EXTENSIONS)
|
|
|
|
{
|
|
|
|
g_string_append (str, "*.");
|
|
|
|
g_string_append (str, extension);
|
|
|
|
}
|
|
|
|
else if (i == MAX_EXTENSIONS)
|
|
|
|
{
|
|
|
|
g_string_append (str, "...");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! ext->next)
|
|
|
|
{
|
|
|
|
g_string_append (str, ")");
|
2004-07-17 05:24:39 +08:00
|
|
|
}
|
|
|
|
}
|
2005-02-08 02:46:03 +08:00
|
|
|
|
2009-08-28 13:49:17 +08:00
|
|
|
gtk_file_filter_set_name (filter, str->str);
|
|
|
|
g_string_free (str, TRUE);
|
|
|
|
|
|
|
|
if (filter_out)
|
|
|
|
*filter_out = g_object_ref (filter);
|
|
|
|
|
|
|
|
g_object_unref (filter);
|
2004-07-17 05:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_add_proc_selection (GimpFileDialog *dialog,
|
|
|
|
Gimp *gimp,
|
|
|
|
GSList *file_procs,
|
2004-07-18 03:53:05 +08:00
|
|
|
const gchar *automatic,
|
2004-08-11 05:20:38 +08:00
|
|
|
const gchar *automatic_help_id)
|
2004-07-17 05:24:39 +08:00
|
|
|
{
|
2004-07-17 21:06:59 +08:00
|
|
|
GtkWidget *scrolled_window;
|
2004-07-17 05:24:39 +08:00
|
|
|
|
|
|
|
dialog->proc_expander = gtk_expander_new_with_mnemonic (NULL);
|
2004-08-11 05:20:38 +08:00
|
|
|
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog),
|
|
|
|
dialog->proc_expander);
|
2004-07-17 05:24:39 +08:00
|
|
|
gtk_widget_show (dialog->proc_expander);
|
|
|
|
|
2004-07-17 21:06:59 +08:00
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
2004-07-17 05:24:39 +08:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2004-07-17 21:06:59 +08:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_SHADOW_IN);
|
|
|
|
gtk_container_add (GTK_CONTAINER (dialog->proc_expander), scrolled_window);
|
|
|
|
gtk_widget_show (scrolled_window);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-07-17 21:06:59 +08:00
|
|
|
gtk_widget_set_size_request (scrolled_window, -1, 200);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-07-18 03:53:05 +08:00
|
|
|
dialog->proc_view = gimp_file_proc_view_new (gimp, file_procs, automatic,
|
|
|
|
automatic_help_id);
|
2004-07-17 21:06:59 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), dialog->proc_view);
|
2004-07-17 05:24:39 +08:00
|
|
|
gtk_widget_show (dialog->proc_view);
|
|
|
|
|
|
|
|
g_signal_connect (dialog->proc_view, "changed",
|
|
|
|
G_CALLBACK (gimp_file_dialog_proc_changed),
|
|
|
|
dialog);
|
|
|
|
|
|
|
|
gimp_file_proc_view_set_proc (GIMP_FILE_PROC_VIEW (dialog->proc_view), NULL);
|
|
|
|
}
|
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
static void
|
2004-04-16 00:28:26 +08:00
|
|
|
gimp_file_dialog_selection_changed (GtkFileChooser *chooser,
|
|
|
|
GimpFileDialog *dialog)
|
2004-02-27 23:43:58 +08:00
|
|
|
{
|
2004-06-22 23:11:35 +08:00
|
|
|
gimp_thumb_box_take_uris (GIMP_THUMB_BOX (dialog->thumb_box),
|
|
|
|
gtk_file_chooser_get_uris (chooser));
|
2004-04-16 00:28:26 +08:00
|
|
|
}
|
2004-02-27 23:43:58 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
static void
|
|
|
|
gimp_file_dialog_update_preview (GtkFileChooser *chooser,
|
|
|
|
GimpFileDialog *dialog)
|
|
|
|
{
|
2007-01-14 00:56:30 +08:00
|
|
|
gimp_thumb_box_take_uri (GIMP_THUMB_BOX (dialog->thumb_box),
|
|
|
|
gtk_file_chooser_get_preview_uri (chooser));
|
2004-02-27 23:43:58 +08:00
|
|
|
}
|
2004-07-17 05:24:39 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_proc_changed (GimpFileProcView *view,
|
|
|
|
GimpFileDialog *dialog)
|
|
|
|
{
|
|
|
|
GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
dialog->file_proc = gimp_file_proc_view_get_proc (view, &name);
|
|
|
|
|
2004-11-15 21:42:22 +08:00
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
gchar *label = g_strdup_printf (_("Select File _Type (%s)"), name);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-11-15 21:42:22 +08:00
|
|
|
gtk_expander_set_label (GTK_EXPANDER (dialog->proc_expander), label);
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-11-15 21:42:22 +08:00
|
|
|
g_free (label);
|
|
|
|
g_free (name);
|
|
|
|
}
|
2004-07-17 05:24:39 +08:00
|
|
|
|
|
|
|
if (gtk_file_chooser_get_action (chooser) == GTK_FILE_CHOOSER_ACTION_SAVE)
|
|
|
|
{
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpPlugInProcedure *proc = dialog->file_proc;
|
2004-07-17 05:24:39 +08:00
|
|
|
|
2004-11-15 21:42:22 +08:00
|
|
|
if (proc && proc->extensions_list)
|
2004-07-17 05:24:39 +08:00
|
|
|
{
|
|
|
|
gchar *uri = gtk_file_chooser_get_uri (chooser);
|
|
|
|
|
|
|
|
if (uri && strlen (uri))
|
|
|
|
{
|
|
|
|
const gchar *last_dot = strrchr (uri, '.');
|
|
|
|
|
2005-08-21 04:34:25 +08:00
|
|
|
/* if the dot is before the last slash, ignore it */
|
|
|
|
if (last_dot && strrchr (uri, '/') > last_dot)
|
|
|
|
last_dot = NULL;
|
|
|
|
|
2004-11-18 19:50:25 +08:00
|
|
|
/* check if the uri has a "meta extension" (e.g. foo.bar.gz)
|
|
|
|
* and try to truncate both extensions away.
|
|
|
|
*/
|
|
|
|
if (last_dot && last_dot != uri)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = view->meta_extensions;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
const gchar *ext = list->data;
|
|
|
|
|
|
|
|
if (! strcmp (ext, last_dot + 1))
|
|
|
|
{
|
|
|
|
const gchar *p = last_dot - 1;
|
|
|
|
|
|
|
|
while (p > uri && *p != '.')
|
|
|
|
p--;
|
|
|
|
|
|
|
|
if (p != uri && *p == '.')
|
|
|
|
{
|
|
|
|
last_dot = p;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-17 05:24:39 +08:00
|
|
|
if (last_dot != uri)
|
|
|
|
{
|
|
|
|
GString *s = g_string_new (uri);
|
|
|
|
gchar *basename;
|
|
|
|
|
|
|
|
if (last_dot)
|
|
|
|
g_string_truncate (s, last_dot - uri);
|
|
|
|
|
|
|
|
g_string_append (s, ".");
|
|
|
|
g_string_append (s, (gchar *) proc->extensions_list->data);
|
|
|
|
|
|
|
|
gtk_file_chooser_set_uri (chooser, s->str);
|
|
|
|
|
2005-10-02 06:43:22 +08:00
|
|
|
basename = file_utils_uri_display_basename (s->str);
|
2004-07-17 05:24:39 +08:00
|
|
|
gtk_file_chooser_set_current_name (chooser, basename);
|
|
|
|
g_free (basename);
|
|
|
|
|
|
|
|
g_string_free (s, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-18 03:53:05 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_help_func (const gchar *help_id,
|
|
|
|
gpointer help_data)
|
|
|
|
{
|
|
|
|
GimpFileDialog *dialog = GIMP_FILE_DIALOG (help_data);
|
|
|
|
GtkWidget *focus;
|
|
|
|
|
|
|
|
focus = gtk_window_get_focus (GTK_WINDOW (dialog));
|
|
|
|
|
|
|
|
if (focus == dialog->proc_view)
|
|
|
|
{
|
|
|
|
gchar *proc_help_id;
|
|
|
|
|
|
|
|
proc_help_id =
|
|
|
|
gimp_file_proc_view_get_help_id (GIMP_FILE_PROC_VIEW (dialog->proc_view));
|
|
|
|
|
|
|
|
gimp_standard_help_func (proc_help_id, NULL);
|
|
|
|
|
|
|
|
g_free (proc_help_id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_standard_help_func (help_id, NULL);
|
|
|
|
}
|
|
|
|
}
|
2004-10-05 06:25:04 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_file_dialog_help_clicked (GtkWidget *widget,
|
|
|
|
gpointer dialog)
|
|
|
|
{
|
|
|
|
gimp_standard_help_func (g_object_get_data (dialog, "gimp-dialog-help-id"),
|
|
|
|
NULL);
|
|
|
|
}
|
2004-10-11 19:57:32 +08:00
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gimp_file_dialog_pattern_from_extension (const gchar *extension)
|
|
|
|
{
|
|
|
|
gchar *pattern;
|
|
|
|
gchar *p;
|
|
|
|
gint len, i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (extension != NULL, NULL);
|
|
|
|
|
|
|
|
/* This function assumes that file extensions are 7bit ASCII. It
|
|
|
|
* could certainly be rewritten to handle UTF-8 if this assumption
|
|
|
|
* turns out to be incorrect.
|
|
|
|
*/
|
|
|
|
|
|
|
|
len = strlen (extension);
|
|
|
|
|
|
|
|
pattern = g_new (gchar, 4 + 4 * len);
|
|
|
|
|
|
|
|
strcpy (pattern, "*.");
|
|
|
|
|
|
|
|
for (i = 0, p = pattern + 2; i < len; i++, p+= 4)
|
|
|
|
{
|
|
|
|
p[0] = '[';
|
|
|
|
p[1] = g_ascii_tolower (extension[i]);
|
|
|
|
p[2] = g_ascii_toupper (extension[i]);
|
|
|
|
p[3] = ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
return pattern;
|
|
|
|
}
|
2009-05-01 23:29:02 +08:00
|
|
|
|
2009-05-01 23:04:26 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_file_dialog_get_documents_uri (void)
|
|
|
|
{
|
|
|
|
gchar *path;
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
/* Make sure it ends in '/' */
|
|
|
|
path = g_build_path ("/",
|
|
|
|
g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
|
|
|
|
"/",
|
|
|
|
NULL);
|
|
|
|
uri = g_filename_to_uri (path, NULL, NULL);
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2009-05-01 23:29:02 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_file_dialog_get_dirname_from_uri (const gchar *uri)
|
|
|
|
{
|
|
|
|
gchar *dirname = NULL;
|
|
|
|
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
dirname = g_path_get_dirname (uri);
|
|
|
|
#else
|
|
|
|
/* g_path_get_dirname() is supposed to work on pathnames, not URIs.
|
|
|
|
*
|
|
|
|
* If uri points to a file on the root of a drive
|
|
|
|
* "file:///d:/foo.png", g_path_get_dirname() would return
|
|
|
|
* "file:///d:". (What we really would want is "file:///d:/".) When
|
|
|
|
* this then is passed inside gtk+ to g_filename_from_uri() we get
|
|
|
|
* "d:" which is not an absolute pathname. This currently causes an
|
|
|
|
* assertion failure in gtk+. This scenario occurs if we have opened
|
|
|
|
* an image from the root of a drive and then do Save As.
|
|
|
|
*
|
|
|
|
* Of course, gtk+ shouldn't assert even if we feed it slighly bogus
|
|
|
|
* data, and that problem should be fixed, too. But to get the
|
|
|
|
* correct default current folder in the filechooser combo box, we
|
|
|
|
* need to pass it the proper URI for an absolute path anyway. So
|
|
|
|
* don't use g_path_get_dirname() on file: URIs.
|
|
|
|
*/
|
|
|
|
if (g_str_has_prefix (uri, "file:///"))
|
|
|
|
{
|
|
|
|
gchar *filepath = g_filename_from_uri (uri, NULL, NULL);
|
|
|
|
gchar *dirpath = NULL;
|
|
|
|
|
|
|
|
if (filepath != NULL)
|
2009-05-07 21:43:48 +08:00
|
|
|
{
|
|
|
|
dirpath = g_path_get_dirname (filepath);
|
|
|
|
g_free (filepath);
|
|
|
|
}
|
2009-05-01 23:29:02 +08:00
|
|
|
|
|
|
|
if (dirpath != NULL)
|
2009-05-07 21:43:48 +08:00
|
|
|
{
|
|
|
|
dirname = g_filename_to_uri (dirpath, NULL, NULL);
|
|
|
|
g_free (dirpath);
|
|
|
|
}
|
2009-05-01 23:29:02 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dirname = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dirname = g_path_get_dirname (uri);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return dirname;
|
|
|
|
}
|