2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-04-28 23:11:29 +08:00
|
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-04-28 23:11:29 +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
|
2001-04-28 23:11:29 +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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-04-28 23:11:29 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-04-28 23:11:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs-types.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2001-07-06 00:21:36 +08:00
|
|
|
#include "core/gimp.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2006-11-04 01:12:27 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
|
|
|
#include "core/gimplayer.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2001-12-01 08:14:14 +08:00
|
|
|
|
2001-10-25 21:30:01 +08:00
|
|
|
#include "file/file-open.h"
|
2009-05-01 15:03:13 +08:00
|
|
|
#include "file/gimp-file.h"
|
2001-10-25 21:30:01 +08:00
|
|
|
|
2004-02-27 22:20:19 +08:00
|
|
|
#include "widgets/gimpfiledialog.h"
|
2003-08-21 23:54:47 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2015-09-01 02:57:37 +08:00
|
|
|
#include "widgets/gimpopendialog.h"
|
2014-05-03 02:20:46 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2001-11-28 03:27:55 +08:00
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
#include "file-open-dialog.h"
|
2001-07-05 03:31:35 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
2001-07-10 01:58:56 +08:00
|
|
|
/* local function prototypes */
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
static void file_open_dialog_response (GtkWidget *dialog,
|
2006-11-04 01:12:27 +08:00
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp);
|
2015-09-10 03:04:18 +08:00
|
|
|
static GimpImage *file_open_dialog_open_image (GtkWidget *dialog,
|
2006-11-04 01:12:27 +08:00
|
|
|
Gimp *gimp,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file,
|
2006-11-04 01:12:27 +08:00
|
|
|
GimpPlugInProcedure *load_proc);
|
2015-09-10 03:04:18 +08:00
|
|
|
static gboolean file_open_dialog_open_layers (GtkWidget *dialog,
|
2006-11-04 01:12:27 +08:00
|
|
|
GimpImage *image,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file,
|
2006-11-04 01:12:27 +08:00
|
|
|
GimpPlugInProcedure *load_proc);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-09-14 00:01:52 +08:00
|
|
|
GtkWidget *
|
|
|
|
file_open_dialog_new (Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2008-05-08 19:30:54 +08:00
|
|
|
GtkWidget *dialog;
|
2001-08-15 00:33:28 +08:00
|
|
|
|
2004-09-14 00:37:01 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
|
2015-09-01 02:57:37 +08:00
|
|
|
dialog = gimp_open_dialog_new (gimp);
|
2004-02-27 23:43:58 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
|
2004-02-27 22:20:19 +08:00
|
|
|
|
2015-09-01 19:49:59 +08:00
|
|
|
gimp_file_dialog_load_state (GIMP_FILE_DIALOG (dialog),
|
|
|
|
"gimp-file-open-dialog-state");
|
2008-05-08 19:30:54 +08:00
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (file_open_dialog_response),
|
2003-11-18 02:29:59 +08:00
|
|
|
gimp);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-02-27 23:43:58 +08:00
|
|
|
return dialog;
|
2002-05-03 20:45:22 +08:00
|
|
|
}
|
|
|
|
|
2004-09-14 00:01:52 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-04-28 23:11:29 +08:00
|
|
|
static void
|
2015-09-10 03:04:18 +08:00
|
|
|
file_open_dialog_response (GtkWidget *dialog,
|
2004-02-27 23:43:58 +08:00
|
|
|
gint response_id,
|
|
|
|
Gimp *gimp)
|
2001-04-28 23:11:29 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
GimpFileDialog *file_dialog = GIMP_FILE_DIALOG (dialog);
|
|
|
|
GimpOpenDialog *open_dialog = GIMP_OPEN_DIALOG (dialog);
|
2014-07-07 06:46:25 +08:00
|
|
|
GSList *files;
|
2004-08-11 05:20:38 +08:00
|
|
|
GSList *list;
|
|
|
|
gboolean success = FALSE;
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2015-09-01 19:49:59 +08:00
|
|
|
gimp_file_dialog_save_state (GIMP_FILE_DIALOG (dialog),
|
|
|
|
"gimp-file-open-dialog-state");
|
2008-05-08 19:30:54 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id != GTK_RESPONSE_OK)
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
if (! file_dialog->busy)
|
|
|
|
gtk_widget_destroy (dialog);
|
2004-08-11 05:20:38 +08:00
|
|
|
|
2003-11-18 02:29:59 +08:00
|
|
|
return;
|
|
|
|
}
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-25 05:27:11 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog));
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
if (files)
|
|
|
|
g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
|
|
|
|
g_object_ref (files->data),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
2008-07-30 22:53:09 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_file_dialog_set_sensitive (file_dialog, FALSE);
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2010-06-24 02:17:37 +08:00
|
|
|
/* When we are going to open new image windows, unset the transient
|
|
|
|
* window. We don't need it since we will use gdk_window_raise() to
|
|
|
|
* keep the dialog on top. And if we don't do it, then the dialog
|
|
|
|
* will pull the image window it was invoked from on top of all the
|
|
|
|
* new opened image windows, and we don't want that to happen.
|
|
|
|
*/
|
2015-09-10 03:04:18 +08:00
|
|
|
if (! open_dialog->open_as_layers)
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), NULL);
|
2010-06-24 02:17:37 +08:00
|
|
|
|
2019-01-03 23:46:00 +08:00
|
|
|
if (file_dialog->image)
|
|
|
|
g_object_ref (file_dialog->image);
|
|
|
|
|
2014-07-26 21:24:52 +08:00
|
|
|
for (list = files; list; list = g_slist_next (list))
|
2004-02-28 00:28:55 +08:00
|
|
|
{
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file = list->data;
|
2005-02-13 00:04:11 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (open_dialog->open_as_layers)
|
2005-02-13 00:04:11 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
if (! file_dialog->image)
|
2008-10-05 23:21:02 +08:00
|
|
|
{
|
2019-04-21 02:30:43 +08:00
|
|
|
gimp_open_dialog_set_image (
|
|
|
|
open_dialog,
|
|
|
|
file_open_dialog_open_image (dialog,
|
|
|
|
gimp,
|
|
|
|
file,
|
|
|
|
file_dialog->file_proc),
|
|
|
|
TRUE);
|
2008-10-05 23:21:02 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_dialog->image)
|
2019-01-03 23:46:00 +08:00
|
|
|
{
|
|
|
|
g_object_ref (file_dialog->image);
|
|
|
|
success = TRUE;
|
|
|
|
}
|
2008-10-05 23:21:02 +08:00
|
|
|
}
|
2015-09-10 03:04:18 +08:00
|
|
|
else if (file_open_dialog_open_layers (dialog,
|
|
|
|
file_dialog->image,
|
2014-07-07 06:46:25 +08:00
|
|
|
file,
|
2015-09-10 03:04:18 +08:00
|
|
|
file_dialog->file_proc))
|
2004-02-28 00:28:55 +08:00
|
|
|
{
|
2005-02-13 00:04:11 +08:00
|
|
|
success = TRUE;
|
2004-09-21 20:08:30 +08:00
|
|
|
}
|
2005-02-13 00:04:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_open_dialog_open_image (dialog,
|
2005-02-13 00:04:11 +08:00
|
|
|
gimp,
|
2014-07-07 06:46:25 +08:00
|
|
|
file,
|
2015-09-10 03:04:18 +08:00
|
|
|
file_dialog->file_proc))
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2005-02-13 00:04:11 +08:00
|
|
|
success = TRUE;
|
|
|
|
|
2010-06-24 01:57:34 +08:00
|
|
|
/* Make the dialog stay on top of all images we open if
|
|
|
|
* we open say 10 at once
|
|
|
|
*/
|
2015-09-10 03:04:18 +08:00
|
|
|
gdk_window_raise (gtk_widget_get_window (dialog));
|
2004-02-28 00:28:55 +08:00
|
|
|
}
|
2004-04-16 00:28:26 +08:00
|
|
|
}
|
2002-04-14 22:38:55 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
if (file_dialog->canceled)
|
2004-08-11 05:20:38 +08:00
|
|
|
break;
|
2001-11-09 09:04:46 +08:00
|
|
|
}
|
2001-04-28 23:11:29 +08:00
|
|
|
|
2004-08-11 02:47:21 +08:00
|
|
|
if (success)
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2019-01-03 23:46:00 +08:00
|
|
|
if (file_dialog->image)
|
|
|
|
{
|
|
|
|
if (open_dialog->open_as_layers)
|
|
|
|
gimp_image_flush (file_dialog->image);
|
|
|
|
|
|
|
|
g_object_unref (file_dialog->image);
|
|
|
|
}
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
2008-05-08 19:30:54 +08:00
|
|
|
}
|
2008-06-30 17:03:31 +08:00
|
|
|
else
|
|
|
|
{
|
2019-01-03 23:46:00 +08:00
|
|
|
if (file_dialog->image)
|
|
|
|
g_object_unref (file_dialog->image);
|
|
|
|
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_file_dialog_set_sensitive (file_dialog, TRUE);
|
2008-06-30 17:03:31 +08:00
|
|
|
}
|
2004-04-16 00:28:26 +08:00
|
|
|
|
2014-07-07 06:46:25 +08:00
|
|
|
g_slist_free_full (files, (GDestroyNotify) g_object_unref);
|
2002-04-18 09:18:24 +08:00
|
|
|
}
|
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
static GimpImage *
|
2015-09-10 03:04:18 +08:00
|
|
|
file_open_dialog_open_image (GtkWidget *dialog,
|
2006-04-05 16:38:33 +08:00
|
|
|
Gimp *gimp,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file,
|
2006-04-05 16:38:33 +08:00
|
|
|
GimpPlugInProcedure *load_proc)
|
2002-04-18 09:18:24 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2003-03-05 19:25:59 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = file_open_with_proc_and_display (gimp,
|
|
|
|
gimp_get_user_context (gimp),
|
2015-09-10 03:04:18 +08:00
|
|
|
GIMP_PROGRESS (dialog),
|
2019-09-11 06:21:03 +08:00
|
|
|
file, FALSE,
|
2006-03-29 01:08:36 +08:00
|
|
|
load_proc,
|
2018-04-29 23:27:47 +08:00
|
|
|
G_OBJECT (gimp_widget_get_monitor (dialog)),
|
2007-04-17 23:54:01 +08:00
|
|
|
&status, &error);
|
2002-04-18 09:18:24 +08:00
|
|
|
|
2019-04-13 00:22:06 +08:00
|
|
|
if (! image && status != GIMP_PDB_SUCCESS && status != GIMP_PDB_CANCEL)
|
2003-03-05 19:25:59 +08:00
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_message (gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
|
2014-07-07 06:46:25 +08:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2003-03-05 19:25:59 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2004-02-28 00:28:55 +08:00
|
|
|
|
2008-10-05 23:21:02 +08:00
|
|
|
return image;
|
2001-04-28 23:11:29 +08:00
|
|
|
}
|
2004-09-21 20:08:30 +08:00
|
|
|
|
|
|
|
static gboolean
|
2015-09-10 03:04:18 +08:00
|
|
|
file_open_dialog_open_layers (GtkWidget *dialog,
|
2006-11-04 01:12:27 +08:00
|
|
|
GimpImage *image,
|
2014-07-07 06:46:25 +08:00
|
|
|
GFile *file,
|
2006-11-04 01:12:27 +08:00
|
|
|
GimpPlugInProcedure *load_proc)
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2006-11-04 01:12:27 +08:00
|
|
|
GList *new_layers;
|
2004-09-21 20:08:30 +08:00
|
|
|
GimpPDBStatusType status;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2006-11-04 01:12:27 +08:00
|
|
|
new_layers = file_open_layers (image->gimp,
|
|
|
|
gimp_get_user_context (image->gimp),
|
2015-09-10 03:04:18 +08:00
|
|
|
GIMP_PROGRESS (dialog),
|
2006-11-04 01:12:27 +08:00
|
|
|
image, FALSE,
|
2014-07-07 06:46:25 +08:00
|
|
|
file, GIMP_RUN_INTERACTIVE, load_proc,
|
2006-11-04 01:12:27 +08:00
|
|
|
&status, &error);
|
2004-09-21 20:08:30 +08:00
|
|
|
|
2006-11-04 01:12:27 +08:00
|
|
|
if (new_layers)
|
2004-09-21 20:08:30 +08:00
|
|
|
{
|
2009-08-04 04:30:36 +08:00
|
|
|
gimp_image_add_layers (image, new_layers,
|
|
|
|
GIMP_IMAGE_ACTIVE_PARENT, -1,
|
2006-11-04 03:59:30 +08:00
|
|
|
0, 0,
|
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
|
|
|
_("Open layers"));
|
2004-09-21 20:08:30 +08:00
|
|
|
|
2006-11-04 01:12:27 +08:00
|
|
|
g_list_free (new_layers);
|
2004-09-21 20:08:30 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2015-09-10 03:04:18 +08:00
|
|
|
gimp_message (image->gimp, G_OBJECT (dialog), GIMP_MESSAGE_ERROR,
|
2014-07-07 06:46:25 +08:00
|
|
|
_("Opening '%s' failed:\n\n%s"),
|
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2004-09-21 20:08:30 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|