2003-11-08 01:29:02 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2000-02-26 11:41:06 +08:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
1999-03-14 07:03:11 +08:00
|
|
|
*
|
2003-11-21 23:53:57 +08:00
|
|
|
* gimpfileentry.c
|
2004-02-28 06:25:37 +08:00
|
|
|
* Copyright (C) 1999-2004 Michael Natterer <mitch@gimp.org>
|
1999-03-14 07:03:11 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-03-14 07:03:11 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2003-11-08 01:29:02 +08:00
|
|
|
*
|
|
|
|
* This library 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
|
1999-03-14 07:03:11 +08:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
1999-03-14 07:03:11 +08:00
|
|
|
*/
|
2001-01-25 06:36:18 +08:00
|
|
|
|
1999-03-14 07:03:11 +08:00
|
|
|
#include "config.h"
|
1999-05-29 05:56:04 +08:00
|
|
|
|
1999-03-14 07:03:11 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-05-26 05:17:07 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
2006-06-09 15:12:33 +08:00
|
|
|
#undef GIMP_DISABLE_DEPRECATED
|
2003-11-21 23:53:57 +08:00
|
|
|
#include "gimpfileentry.h"
|
2006-06-09 15:12:33 +08:00
|
|
|
|
2006-05-24 15:36:48 +08:00
|
|
|
#include "gimphelpui.h"
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
|
2010-07-06 00:01:28 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpfileentry
|
|
|
|
* @title: GimpFileEntry
|
|
|
|
* @short_description: Widget for entering a filename.
|
|
|
|
* @see_also: #GimpPathEditor
|
|
|
|
*
|
|
|
|
* This widget is used to enter filenames or directories.
|
|
|
|
*
|
|
|
|
* There is a #GtkEntry for entering the filename manually and a "..."
|
2010-07-06 01:04:15 +08:00
|
|
|
* button which will pop up a #GtkFileChooserDialog.
|
2010-07-06 00:01:28 +08:00
|
|
|
*
|
2010-07-06 01:04:15 +08:00
|
|
|
* You can restrict the #GimpFileEntry to directories. In this
|
2010-07-06 00:01:28 +08:00
|
|
|
* case the filename listbox of the #GtkFileChooser dialog will be
|
2010-07-06 01:04:15 +08:00
|
|
|
* set to directory mode.
|
2010-07-06 00:01:28 +08:00
|
|
|
*
|
|
|
|
* If you specify @check_valid as #TRUE in gimp_file_entry_new() the
|
|
|
|
* entered filename will be checked for validity and a pixmap will be
|
|
|
|
* shown which indicates if the file exists or not.
|
|
|
|
*
|
|
|
|
* Whenever the user changes the filename, the "filename_changed"
|
|
|
|
* signal will be emitted.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
1999-11-20 22:27:07 +08:00
|
|
|
enum
|
|
|
|
{
|
1999-06-18 03:13:08 +08:00
|
|
|
FILENAME_CHANGED,
|
1999-03-14 07:03:11 +08:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2010-10-15 08:25:51 +08:00
|
|
|
static void gimp_file_entry_dispose (GObject *object);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static void gimp_file_entry_entry_activate (GtkWidget *widget,
|
|
|
|
GimpFileEntry *entry);
|
|
|
|
static gint gimp_file_entry_entry_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpFileEntry *entry);
|
|
|
|
static void gimp_file_entry_browse_clicked (GtkWidget *widget,
|
|
|
|
GimpFileEntry *entry);
|
|
|
|
static void gimp_file_entry_check_filename (GimpFileEntry *entry);
|
2001-09-21 18:47:19 +08:00
|
|
|
|
|
|
|
|
2011-07-28 01:53:34 +08:00
|
|
|
G_DEFINE_TYPE (GimpFileEntry, gimp_file_entry, GTK_TYPE_BOX)
|
2001-09-21 18:47:19 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
#define parent_class gimp_file_entry_parent_class
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2005-12-21 04:35:23 +08:00
|
|
|
static guint gimp_file_entry_signals[LAST_SIGNAL] = { 0 };
|
1999-03-14 07:03:11 +08:00
|
|
|
|
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
|
|
|
|
1999-03-14 07:03:11 +08:00
|
|
|
static void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_class_init (GimpFileEntryClass *klass)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2010-10-15 08:25:51 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-12-18 21:29:16 +08:00
|
|
|
/**
|
|
|
|
* GimpFileEntry::filename-changed:
|
|
|
|
*
|
|
|
|
* This signal is emitted whenever the user changes the filename.
|
|
|
|
**/
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_signals[FILENAME_CHANGED] =
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_new ("filename-changed",
|
2006-04-12 18:53:28 +08:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GimpFileEntryClass, filename_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
1999-06-18 03:13:08 +08:00
|
|
|
|
2010-10-15 08:25:51 +08:00
|
|
|
object_class->dispose = gimp_file_entry_dispose;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
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
|
|
|
klass->filename_changed = NULL;
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_init (GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2006-05-24 15:36:48 +08:00
|
|
|
GtkWidget *image;
|
|
|
|
|
2004-02-24 22:35:08 +08:00
|
|
|
entry->title = NULL;
|
|
|
|
entry->file_dialog = NULL;
|
|
|
|
entry->check_valid = FALSE;
|
|
|
|
entry->file_exists = NULL;
|
2003-11-21 23:53:57 +08:00
|
|
|
|
2011-07-28 01:53:34 +08:00
|
|
|
gtk_orientable_set_orientation (GTK_ORIENTABLE (entry),
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gtk_box_set_spacing (GTK_BOX (entry), 4);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (entry), FALSE);
|
|
|
|
|
2006-05-24 15:36:48 +08:00
|
|
|
entry->browse_button = gtk_button_new ();
|
2003-11-21 23:53:57 +08:00
|
|
|
gtk_box_pack_end (GTK_BOX (entry), entry->browse_button, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (entry->browse_button);
|
|
|
|
|
2006-05-24 15:36:48 +08:00
|
|
|
image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_container_add (GTK_CONTAINER (entry->browse_button), image);
|
|
|
|
gtk_widget_show (image);
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_signal_connect (entry->browse_button, "clicked",
|
|
|
|
G_CALLBACK (gimp_file_entry_browse_clicked),
|
|
|
|
entry);
|
|
|
|
|
|
|
|
entry->entry = gtk_entry_new ();
|
|
|
|
gtk_box_pack_end (GTK_BOX (entry), entry->entry, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (entry->entry);
|
|
|
|
|
|
|
|
g_signal_connect (entry->entry, "activate",
|
|
|
|
G_CALLBACK (gimp_file_entry_entry_activate),
|
|
|
|
entry);
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (entry->entry, "focus-out-event",
|
2003-11-21 23:53:57 +08:00
|
|
|
G_CALLBACK (gimp_file_entry_entry_focus_out),
|
|
|
|
entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2001-08-05 04:38:54 +08:00
|
|
|
static void
|
2010-10-15 08:25:51 +08:00
|
|
|
gimp_file_entry_dispose (GObject *object)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2003-11-21 23:53:57 +08:00
|
|
|
GimpFileEntry *entry = GIMP_FILE_ENTRY (object);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2004-02-24 22:35:08 +08:00
|
|
|
if (entry->file_dialog)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-02-24 22:35:08 +08:00
|
|
|
gtk_widget_destroy (entry->file_dialog);
|
|
|
|
entry->file_dialog = NULL;
|
2001-08-05 04:38:54 +08:00
|
|
|
}
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
if (entry->title)
|
2001-08-05 04:38:54 +08:00
|
|
|
{
|
2003-11-21 23:53:57 +08:00
|
|
|
g_free (entry->title);
|
|
|
|
entry->title = NULL;
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2010-10-15 08:25:51 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2000-02-09 05:59:31 +08:00
|
|
|
/**
|
2003-11-21 23:53:57 +08:00
|
|
|
* gimp_file_entry_new:
|
2010-07-06 01:04:15 +08:00
|
|
|
* @title: The title of the #GimpFileEntry dialog.
|
2003-11-21 23:53:57 +08:00
|
|
|
* @filename: The initial filename.
|
|
|
|
* @dir_only: %TRUE if the file entry should accept directories only.
|
2003-02-07 05:17:12 +08:00
|
|
|
* @check_valid: %TRUE if the widget should check if the entered file
|
2000-02-09 05:59:31 +08:00
|
|
|
* really exists.
|
|
|
|
*
|
2006-06-09 15:12:33 +08:00
|
|
|
* You should use #GtkFileChooserButton instead.
|
2000-02-09 05:59:31 +08:00
|
|
|
*
|
2003-11-21 23:53:57 +08:00
|
|
|
* Returns: A pointer to the new #GimpFileEntry widget.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
1999-11-20 22:27:07 +08:00
|
|
|
GtkWidget *
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_new (const gchar *title,
|
|
|
|
const gchar *filename,
|
|
|
|
gboolean dir_only,
|
|
|
|
gboolean check_valid)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2003-11-21 23:53:57 +08:00
|
|
|
GimpFileEntry *entry;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
entry = g_object_new (GIMP_TYPE_FILE_ENTRY, NULL);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
entry->title = g_strdup (title);
|
|
|
|
entry->dir_only = dir_only;
|
|
|
|
entry->check_valid = check_valid;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2006-05-24 15:36:48 +08:00
|
|
|
gimp_help_set_help_data (entry->browse_button,
|
|
|
|
dir_only ?
|
|
|
|
_("Open a file selector to browse your folders") :
|
|
|
|
_("Open a file selector to browse your files"),
|
|
|
|
NULL);
|
|
|
|
|
2001-08-05 04:38:54 +08:00
|
|
|
if (check_valid)
|
|
|
|
{
|
2003-11-21 23:53:57 +08:00
|
|
|
entry->file_exists = gtk_image_new_from_stock (GTK_STOCK_NO,
|
|
|
|
GTK_ICON_SIZE_BUTTON);
|
|
|
|
gtk_box_pack_start (GTK_BOX (entry), entry->file_exists, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (entry->file_exists);
|
2001-08-05 04:38:54 +08:00
|
|
|
}
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_set_filename (entry, filename);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
return GTK_WIDGET (entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2000-02-09 05:59:31 +08:00
|
|
|
/**
|
2003-11-21 23:53:57 +08:00
|
|
|
* gimp_file_entry_get_filename:
|
|
|
|
* @entry: The file entry you want to know the filename from.
|
2000-02-09 05:59:31 +08:00
|
|
|
*
|
|
|
|
* Note that you have to g_free() the returned string.
|
|
|
|
*
|
|
|
|
* Returns: The file or directory the user has entered.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
1999-11-20 22:27:07 +08:00
|
|
|
gchar *
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_get_filename (GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *utf8;
|
|
|
|
gchar *filename;
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_FILE_ENTRY (entry), NULL);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
utf8 = gtk_editable_get_chars (GTK_EDITABLE (entry->entry), 0, -1);
|
|
|
|
|
|
|
|
filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
g_free (utf8);
|
|
|
|
|
|
|
|
return filename;
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2000-02-09 05:59:31 +08:00
|
|
|
/**
|
2003-11-21 23:53:57 +08:00
|
|
|
* gimp_file_entry_set_filename:
|
|
|
|
* @entry: The file entry you want to set the filename for.
|
2000-02-09 05:59:31 +08:00
|
|
|
* @filename: The new filename.
|
|
|
|
*
|
2003-11-21 23:53:57 +08:00
|
|
|
* If you specified @check_valid as %TRUE in gimp_file_entry_new()
|
|
|
|
* the #GimpFileEntry will immediately check the validity of the file
|
2000-02-09 05:59:31 +08:00
|
|
|
* name.
|
2003-11-21 23:53:57 +08:00
|
|
|
**/
|
1999-03-14 07:03:11 +08:00
|
|
|
void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_set_filename (GimpFileEntry *entry,
|
|
|
|
const gchar *filename)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *utf8;
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_return_if_fail (GIMP_IS_FILE_ENTRY (entry));
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
if (filename)
|
|
|
|
utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
|
|
|
else
|
|
|
|
utf8 = g_strdup ("");
|
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry->entry), utf8);
|
|
|
|
g_free (utf8);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
|
|
|
/* update everything
|
|
|
|
*/
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_entry_activate (entry->entry, entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_entry_activate (GtkWidget *widget,
|
|
|
|
GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *utf8;
|
2003-11-18 02:29:59 +08:00
|
|
|
gchar *filename;
|
|
|
|
gint len;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
|
|
|
/* filenames still need more sanity checking
|
|
|
|
* (erase double G_DIR_SEPARATORS, ...)
|
|
|
|
*/
|
2004-01-29 05:53:50 +08:00
|
|
|
utf8 = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
|
|
|
|
utf8 = g_strstrip (utf8);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
while (((len = strlen (utf8)) > 1) &&
|
2006-04-12 18:53:28 +08:00
|
|
|
(utf8[len - 1] == G_DIR_SEPARATOR))
|
2004-01-29 05:53:50 +08:00
|
|
|
utf8[len - 1] = '\0';
|
|
|
|
|
|
|
|
filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, NULL);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_signal_handlers_block_by_func (entry->entry,
|
|
|
|
gimp_file_entry_entry_activate,
|
|
|
|
entry);
|
2004-01-29 05:53:50 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry->entry), utf8);
|
2003-11-21 23:53:57 +08:00
|
|
|
g_signal_handlers_unblock_by_func (entry->entry,
|
|
|
|
gimp_file_entry_entry_activate,
|
|
|
|
entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-02-24 22:35:08 +08:00
|
|
|
if (entry->file_dialog)
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (entry->file_dialog),
|
|
|
|
filename);
|
2004-01-29 05:53:50 +08:00
|
|
|
|
1999-03-14 07:03:11 +08:00
|
|
|
g_free (filename);
|
2004-01-29 05:53:50 +08:00
|
|
|
g_free (utf8);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_check_filename (entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gtk_editable_set_position (GTK_EDITABLE (entry->entry), -1);
|
1999-05-19 01:33:39 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_signal_emit (entry, gimp_file_entry_signals[FILENAME_CHANGED], 0);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2000-08-10 01:04:16 +08:00
|
|
|
static gboolean
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_entry_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_entry_activate (widget, entry);
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2001-08-14 21:49:21 +08:00
|
|
|
return FALSE;
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
/* local callback of gimp_file_entry_browse_clicked() */
|
1999-03-14 07:03:11 +08:00
|
|
|
static void
|
2004-04-16 00:28:26 +08:00
|
|
|
gimp_file_entry_chooser_response (GtkWidget *dialog,
|
2003-11-21 23:53:57 +08:00
|
|
|
gint response_id,
|
|
|
|
GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2003-11-18 02:29:59 +08:00
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
gchar *filename;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_set_filename (entry, filename);
|
2004-04-16 00:28:26 +08:00
|
|
|
g_free (filename);
|
2003-11-18 02:29:59 +08:00
|
|
|
}
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gtk_widget_hide (dialog);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_browse_clicked (GtkWidget *widget,
|
|
|
|
GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
GtkFileChooser *chooser;
|
|
|
|
gchar *utf8;
|
|
|
|
gchar *filename;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
utf8 = gtk_editable_get_chars (GTK_EDITABLE (entry->entry), 0, -1);
|
|
|
|
filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, NULL);
|
|
|
|
g_free (utf8);
|
2003-11-08 01:29:02 +08:00
|
|
|
|
2004-02-24 22:35:08 +08:00
|
|
|
if (! entry->file_dialog)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
const gchar *title = entry->title;
|
|
|
|
|
|
|
|
if (! title)
|
2001-11-22 02:50:50 +08:00
|
|
|
{
|
2004-04-16 00:28:26 +08:00
|
|
|
if (entry->dir_only)
|
|
|
|
title = _("Select Folder");
|
|
|
|
else
|
|
|
|
title = _("Select File");
|
2001-11-22 02:50:50 +08:00
|
|
|
}
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
entry->file_dialog =
|
|
|
|
gtk_file_chooser_dialog_new (title, NULL,
|
|
|
|
entry->dir_only ?
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER :
|
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
2003-11-18 02:29:59 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
|
|
|
|
|
|
|
NULL);
|
1999-12-31 04:16:58 +08:00
|
|
|
|
2006-04-12 18:53:28 +08:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (entry->file_dialog),
|
2005-02-10 19:00:46 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
chooser = GTK_FILE_CHOOSER (entry->file_dialog);
|
2003-11-18 02:29:59 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_window_set_position (GTK_WINDOW (chooser), GTK_WIN_POS_MOUSE);
|
|
|
|
gtk_window_set_role (GTK_WINDOW (chooser),
|
|
|
|
"gimp-file-entry-file-dialog");
|
|
|
|
|
|
|
|
g_signal_connect (chooser, "response",
|
|
|
|
G_CALLBACK (gimp_file_entry_chooser_response),
|
2003-11-21 23:53:57 +08:00
|
|
|
entry);
|
2005-05-27 21:05:26 +08:00
|
|
|
g_signal_connect (chooser, "delete-event",
|
2003-11-18 02:29:59 +08:00
|
|
|
G_CALLBACK (gtk_true),
|
|
|
|
NULL);
|
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
g_signal_connect_swapped (entry, "unmap",
|
2001-07-31 19:33:13 +08:00
|
|
|
G_CALLBACK (gtk_widget_hide),
|
2004-04-16 00:28:26 +08:00
|
|
|
chooser);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chooser = GTK_FILE_CHOOSER (entry->file_dialog);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_file_chooser_set_filename (chooser, filename);
|
2000-02-12 21:07:59 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
g_free (filename);
|
2003-11-10 06:05:37 +08:00
|
|
|
|
2004-04-16 00:28:26 +08:00
|
|
|
gtk_window_set_screen (GTK_WINDOW (chooser), gtk_widget_get_screen (widget));
|
|
|
|
gtk_window_present (GTK_WINDOW (chooser));
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-11-21 23:53:57 +08:00
|
|
|
gimp_file_entry_check_filename (GimpFileEntry *entry)
|
1999-03-14 07:03:11 +08:00
|
|
|
{
|
2004-01-29 05:53:50 +08:00
|
|
|
gchar *utf8;
|
2002-02-18 22:34:50 +08:00
|
|
|
gchar *filename;
|
|
|
|
gboolean exists;
|
1999-03-14 07:03:11 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
if (! entry->check_valid || ! entry->file_exists)
|
1999-03-14 07:03:11 +08:00
|
|
|
return;
|
|
|
|
|
2004-01-29 05:53:50 +08:00
|
|
|
utf8 = gtk_editable_get_chars (GTK_EDITABLE (entry->entry), 0, -1);
|
|
|
|
filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, NULL);
|
|
|
|
g_free (utf8);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
if (entry->dir_only)
|
2002-02-18 22:34:50 +08:00
|
|
|
exists = g_file_test (filename, G_FILE_TEST_IS_DIR);
|
2000-04-20 23:48:00 +08:00
|
|
|
else
|
2002-02-18 22:34:50 +08:00
|
|
|
exists = g_file_test (filename, G_FILE_TEST_IS_REGULAR);
|
2000-02-18 21:59:18 +08:00
|
|
|
|
1999-11-07 02:19:41 +08:00
|
|
|
g_free (filename);
|
2002-02-18 22:34:50 +08:00
|
|
|
|
2003-11-21 23:53:57 +08:00
|
|
|
gtk_image_set_from_stock (GTK_IMAGE (entry->file_exists),
|
2003-11-08 01:29:02 +08:00
|
|
|
exists ? GTK_STOCK_YES : GTK_STOCK_NO,
|
2002-02-18 22:34:50 +08:00
|
|
|
GTK_ICON_SIZE_BUTTON);
|
1999-03-14 07:03:11 +08:00
|
|
|
}
|