2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2002-03-08 00:27:45 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpdataeditor.c
|
2004-09-26 19:26:37 +00:00
|
|
|
* Copyright (C) 2002-2004 Michael Natterer <mitch@gimp.org>
|
2002-03-08 00:27:45 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2002-03-08 00:27:45 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-03-08 00:27:45 +00: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-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-03-08 00:27:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-03-29 19:19:01 +02:00
|
|
|
#include <gegl.h>
|
2002-03-08 00:27:45 +00:00
|
|
|
#include <gtk/gtk.h>
|
2005-08-08 01:04:26 +00:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2003-10-11 16:50:35 +00:00
|
|
|
#include "core/gimpcontainer.h"
|
2005-10-25 21:38:00 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2002-03-08 00:27:45 +00:00
|
|
|
#include "core/gimpdata.h"
|
2003-10-11 16:50:35 +00:00
|
|
|
#include "core/gimpdatafactory.h"
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
#include "gimpdataeditor.h"
|
2003-10-11 16:50:35 +00:00
|
|
|
#include "gimpdocked.h"
|
2003-01-10 17:55:53 +00:00
|
|
|
#include "gimpmenufactory.h"
|
2007-05-25 11:42:28 +00:00
|
|
|
#include "gimpsessioninfo-aux.h"
|
2004-10-24 20:38:35 +00:00
|
|
|
#include "gimpuimanager.h"
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
|
2007-03-17 18:20:19 +00:00
|
|
|
#define DEFAULT_MINIMAL_HEIGHT 96
|
|
|
|
|
|
|
|
|
2004-09-26 19:26:37 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2004-09-26 19:41:56 +00:00
|
|
|
PROP_DATA_FACTORY,
|
2006-08-29 21:44:51 +00:00
|
|
|
PROP_CONTEXT,
|
2004-09-26 19:41:56 +00:00
|
|
|
PROP_DATA
|
2004-09-26 19:26:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
static void gimp_data_editor_docked_iface_init (GimpDockedInterface *iface);
|
2004-09-26 18:41:29 +00:00
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
static void gimp_data_editor_constructed (GObject *object);
|
|
|
|
static void gimp_data_editor_dispose (GObject *object);
|
2004-09-26 19:26:37 +00:00
|
|
|
static void gimp_data_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-09-26 19:41:56 +00:00
|
|
|
static void gimp_data_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-09-26 18:41:29 +00:00
|
|
|
|
2007-03-17 18:20:19 +00:00
|
|
|
static void gimp_data_editor_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style);
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
static void gimp_data_editor_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context);
|
2003-10-11 16:50:35 +00:00
|
|
|
static void gimp_data_editor_set_aux_info (GimpDocked *docked,
|
|
|
|
GList *aux_info);
|
|
|
|
static GList * gimp_data_editor_get_aux_info (GimpDocked *docked);
|
2005-04-16 20:48:33 +00:00
|
|
|
static gchar * gimp_data_editor_get_title (GimpDocked *docked);
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
static void gimp_data_editor_real_set_data (GimpDataEditor *editor,
|
|
|
|
GimpData *data);
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
static void gimp_data_editor_data_changed (GimpContext *context,
|
|
|
|
GimpData *data,
|
|
|
|
GimpDataEditor *editor);
|
2005-08-08 01:04:26 +00:00
|
|
|
static gboolean gimp_data_editor_name_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDataEditor *editor);
|
2002-03-08 00:27:45 +00:00
|
|
|
static void gimp_data_editor_name_activate (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor);
|
|
|
|
static gboolean gimp_data_editor_name_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpDataEditor *editor);
|
|
|
|
|
|
|
|
static void gimp_data_editor_data_name_changed (GimpObject *object,
|
|
|
|
GimpDataEditor *editor);
|
|
|
|
|
|
|
|
static void gimp_data_editor_save_clicked (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor);
|
|
|
|
static void gimp_data_editor_revert_clicked (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor);
|
2003-11-11 19:00:42 +00:00
|
|
|
static void gimp_data_editor_save_dirty (GimpDataEditor *editor);
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpDataEditor, gimp_data_editor, GIMP_TYPE_EDITOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
|
2006-05-15 09:46:31 +00:00
|
|
|
gimp_data_editor_docked_iface_init))
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
#define parent_class gimp_data_editor_parent_class
|
|
|
|
|
|
|
|
static GimpDockedInterface *parent_docked_iface = NULL;
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_class_init (GimpDataEditorClass *klass)
|
|
|
|
{
|
2007-03-17 18:20:19 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
object_class->constructed = gimp_data_editor_constructed;
|
|
|
|
object_class->dispose = gimp_data_editor_dispose;
|
2004-09-26 19:26:37 +00:00
|
|
|
object_class->set_property = gimp_data_editor_set_property;
|
2004-09-26 19:41:56 +00:00
|
|
|
object_class->get_property = gimp_data_editor_get_property;
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2007-03-17 18:20:19 +00:00
|
|
|
widget_class->style_set = gimp_data_editor_style_set;
|
|
|
|
|
2004-09-26 19:26:37 +00:00
|
|
|
klass->set_data = gimp_data_editor_real_set_data;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_DATA_FACTORY,
|
|
|
|
g_param_spec_object ("data-factory",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_DATA_FACTORY,
|
2006-01-18 20:29:40 +00:00
|
|
|
GIMP_PARAM_READWRITE |
|
2004-09-26 19:26:37 +00:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2004-09-26 19:41:56 +00:00
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_CONTEXT,
|
|
|
|
g_param_spec_object ("context",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_CONTEXT,
|
2010-04-11 16:17:27 +02:00
|
|
|
GIMP_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2006-08-29 21:44:51 +00:00
|
|
|
|
2004-09-26 19:41:56 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_DATA,
|
|
|
|
g_param_spec_object ("data",
|
|
|
|
NULL, NULL,
|
|
|
|
GIMP_TYPE_DATA,
|
2006-01-18 20:29:40 +00:00
|
|
|
GIMP_PARAM_READWRITE));
|
2007-03-17 18:20:19 +00:00
|
|
|
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_int ("minimal-height",
|
|
|
|
NULL, NULL,
|
|
|
|
32,
|
|
|
|
G_MAXINT,
|
|
|
|
DEFAULT_MINIMAL_HEIGHT,
|
|
|
|
GIMP_PARAM_READABLE));
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
static void
|
|
|
|
gimp_data_editor_docked_iface_init (GimpDockedInterface *iface)
|
|
|
|
{
|
|
|
|
parent_docked_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
if (! parent_docked_iface)
|
|
|
|
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
|
|
|
|
|
|
|
|
iface->set_context = gimp_data_editor_set_context;
|
|
|
|
iface->set_aux_info = gimp_data_editor_set_aux_info;
|
|
|
|
iface->get_aux_info = gimp_data_editor_get_aux_info;
|
|
|
|
iface->get_title = gimp_data_editor_get_title;
|
|
|
|
}
|
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_init (GimpDataEditor *editor)
|
|
|
|
{
|
2003-10-11 16:50:35 +00:00
|
|
|
editor->data_factory = NULL;
|
2006-08-29 21:44:51 +00:00
|
|
|
editor->context = NULL;
|
2003-03-10 14:07:22 +00:00
|
|
|
editor->data = NULL;
|
|
|
|
editor->data_editable = FALSE;
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
editor->name_entry = gtk_entry_new ();
|
2004-09-26 19:26:37 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (editor), editor->name_entry, FALSE, FALSE, 0);
|
2002-03-08 00:27:45 +00:00
|
|
|
gtk_widget_show (editor->name_entry);
|
|
|
|
|
2006-11-01 02:20:42 +00:00
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (editor->name_entry), FALSE);
|
2005-04-16 21:53:12 +00:00
|
|
|
|
2005-08-08 01:04:26 +00:00
|
|
|
g_signal_connect (editor->name_entry, "key-press-event",
|
2006-04-12 12:49:29 +00:00
|
|
|
G_CALLBACK (gimp_data_editor_name_key_press),
|
2005-08-08 01:04:26 +00:00
|
|
|
editor);
|
2003-01-05 22:07:10 +00:00
|
|
|
g_signal_connect (editor->name_entry, "activate",
|
2006-04-12 12:49:29 +00:00
|
|
|
G_CALLBACK (gimp_data_editor_name_activate),
|
2002-03-08 00:27:45 +00:00
|
|
|
editor);
|
2005-05-27 16:51:39 +00:00
|
|
|
g_signal_connect (editor->name_entry, "focus-out-event",
|
2006-04-12 12:49:29 +00:00
|
|
|
G_CALLBACK (gimp_data_editor_name_focus_out),
|
2002-03-08 00:27:45 +00:00
|
|
|
editor);
|
2004-10-24 20:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-01-14 09:38:11 +01:00
|
|
|
gimp_data_editor_constructed (GObject *object)
|
2004-10-24 20:38:35 +00:00
|
|
|
{
|
2011-01-14 09:38:11 +01:00
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
|
2004-10-24 20:38:35 +00:00
|
|
|
|
2012-11-12 21:51:22 +01:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
g_assert (GIMP_IS_DATA_FACTORY (editor->data_factory));
|
2010-04-11 16:17:27 +02:00
|
|
|
g_assert (GIMP_IS_CONTEXT (editor->context));
|
2005-10-25 22:05:20 +00:00
|
|
|
|
|
|
|
gimp_data_editor_set_edit_active (editor, TRUE);
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
editor->save_button =
|
2002-03-08 00:27:45 +00:00
|
|
|
gimp_editor_add_button (GIMP_EDITOR (editor),
|
icons: Bug 759904
patch: replace "document-save" by "gimp-save" (or GIMP_STOCK_SAVE) and "document-save-as" by "gimp-save-as" (or GIMP_STOCK_SAVE_AS)
gimp/plug-ins/gimpressionist/presets.c: gtk_image_new_from_icon_name ("document-save",
gimp/libgimp/gimpexport.c: gtk_image_new_from_icon_name ("document-save",
gimp/app/actions/tool-options-actions.c: { "tool-options-save-preset-menu", "document-save",
gimp/app/actions/vectors-actions.c: { "vectors-export", "document-save",
gimp/app/actions/error-console-actions.c: { "error-console-save-all", "document-save-as",
gimp/app/actions/error-console-actions.c: { "error-console-save-selection", "document-save-as",
gimp/gimp/app/actions/gradient-editor-actions.c: { "gradient-editor-save-left-color", "document-save",
gimp/app/actions/gradient-editor-actions.c: { "gradient-editor-save-right-color", "document-save",
gimp/gimp/app/actions/gradients-actions.c: { "gradients-save-as-pov", "document-save-as",
gimp/gimp/app/widgets/gimptooloptionseditor.c: gimp_editor_add_button (GIMP_EDITOR (editor), "document-save",
gimp/app/widgets/gimpdevicestatus.c: gimp_editor_add_button (GIMP_EDITOR (status), "document-save",
gimp/app/widgets/gimpsettingsbox.c: "document-save",
gimp/app/widgets/gimpsettingseditor.c: "document-save",
gimp/gimp/app/widgets/gimpdataeditor.c: "document-save",
gimp/app/dialogs/preferences-dialog.c: button = prefs_button_add ("document-save",
gimp/app/dialogs/preferences-dialog.c: button = prefs_button_add ("document-save",
gimp/app/dialogs/preferences-dialog.c: button = prefs_button_add ("document-save",
gimp/app/dialogs/preferences-dialog.c: button = prefs_button_add ("document-save",
2016-06-05 21:53:34 +02:00
|
|
|
GIMP_STOCK_SAVE,
|
2002-03-08 00:27:45 +00:00
|
|
|
_("Save"), NULL,
|
|
|
|
G_CALLBACK (gimp_data_editor_save_clicked),
|
|
|
|
NULL,
|
|
|
|
editor);
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
editor->revert_button =
|
2002-03-08 00:27:45 +00:00
|
|
|
gimp_editor_add_button (GIMP_EDITOR (editor),
|
icons: Bug 759904
patch: replace "window-close" by "gimp-quit" (or GIMP_STOCK_QUIT)
gimp/app/actions/dock-actions.c: { "dock-close", "window-close",
gimp/app/actions/view-actions.c: { "view-close", "window-close",
gimp/app/actions/dockable-actions.c: { "dockable-close-tab", "window-close",
patch: replace "gtk-directory" by "gimp-file-manager" (or GIMP_STOCK_FILE_MANAGER)
gimp/libgimpwidgets/gimpfileentry.c: image = gtk_image_new_from_icon_name ("gtk-directory", GTK_ICON_SIZE_BUTTON);
gimp/app/actions/palettes-actions.c: { "palettes-show-in-file-manager", "gtk-directory",
gimp/app/actions/mypaint-brushes-actions.c: { "mypaint-brushes-show-in-file-manager", "gtk-directory",
gimp/app/actions/dynamics-actions.c: { "dynamics-show-in-file-manager", "gtk-directory",
gimp/app/actions/tool-presets-actions.c: { "tool-presets-show-in-file-manager", "gtk-directory",
gimp/app/actions/patterns-actions.c: { "patterns-show-in-file-manager", "gtk-directory",
gimp/app/actions/documents-actions.c: { "documents-show-in-file-manager", "gtk-directory",
gimp/app/actions/brushes-actions.c: { "brushes-show-in-file-manager", "gtk-directory",
gimp/app/actions/gradients-actions.c: { "gradients-show-in-file-manager", "gtk-directory",
add
gimp-rivert
patch
gimpicons.c
gimpicons.h
patch: replace "document-revert" by "gimp-revert" (or GIMP_STOCK_REVERT)
gimp/app/actions/tool-options-actions.c: { "tool-options-restore-preset-menu", "document-revert",
gimp/app/actions/tool-presets-actions.c: { "tool-presets-restore", "document-revert",
gimp/app/actions/gradient-editor-actions.c: { "gradient-editor-load-left-color", "document-revert",
gimp/app/actions/gradient-editor-actions.c: { "gradient-editor-load-right-color", "document-revert",
gimp/app/widgets/gimptooloptionseditor.c: gimp_editor_add_button (GIMP_EDITOR (editor), "document-revert",
gimp/app/widgets/gimpdataeditor.c: "document-revert",
2016-06-06 20:08:15 +02:00
|
|
|
GIMP_STOCK_REVERT,
|
2002-03-08 00:27:45 +00:00
|
|
|
_("Revert"), NULL,
|
|
|
|
G_CALLBACK (gimp_data_editor_revert_clicked),
|
|
|
|
NULL,
|
|
|
|
editor);
|
2011-09-24 00:55:37 +02:00
|
|
|
/* Hide because revert buttons are not yet implemented */
|
|
|
|
gtk_widget_hide (editor->revert_button);
|
2011-01-14 09:38:11 +01:00
|
|
|
}
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
static void
|
|
|
|
gimp_data_editor_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
|
|
|
|
|
|
|
|
if (editor->data)
|
|
|
|
{
|
|
|
|
/* Save dirty data before we clear out */
|
|
|
|
gimp_data_editor_save_dirty (editor);
|
|
|
|
gimp_data_editor_set_data (editor, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (editor->context)
|
|
|
|
gimp_docked_set_context (GIMP_DOCKED (editor), NULL);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2003-10-11 16:50:35 +00:00
|
|
|
}
|
|
|
|
|
2004-09-26 19:26:37 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DATA_FACTORY:
|
|
|
|
editor->data_factory = g_value_get_object (value);
|
|
|
|
break;
|
2006-08-29 21:44:51 +00:00
|
|
|
case PROP_CONTEXT:
|
|
|
|
gimp_docked_set_context (GIMP_DOCKED (object),
|
|
|
|
g_value_get_object (value));
|
|
|
|
break;
|
2004-09-26 19:41:56 +00:00
|
|
|
case PROP_DATA:
|
2006-08-29 21:44:51 +00:00
|
|
|
gimp_data_editor_set_data (editor, g_value_get_object (value));
|
2004-09-26 19:41:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_DATA_FACTORY:
|
|
|
|
g_value_set_object (value, editor->data_factory);
|
|
|
|
break;
|
2006-08-29 21:44:51 +00:00
|
|
|
case PROP_CONTEXT:
|
|
|
|
g_value_set_object (value, editor->context);
|
|
|
|
break;
|
2004-09-26 19:41:56 +00:00
|
|
|
case PROP_DATA:
|
|
|
|
g_value_set_object (value, editor->data);
|
|
|
|
break;
|
2004-09-26 19:26:37 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-17 18:20:19 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (widget);
|
|
|
|
gint minimal_height;
|
|
|
|
|
2008-03-29 23:43:39 +00:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
|
2007-03-17 18:20:19 +00:00
|
|
|
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"minimal-height", &minimal_height,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (editor->view)
|
|
|
|
gtk_widget_set_size_request (editor->view, -1, minimal_height);
|
|
|
|
}
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
|
|
|
|
|
|
|
|
if (context == editor->context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (parent_docked_iface->set_context)
|
|
|
|
parent_docked_iface->set_context (docked, context);
|
|
|
|
|
|
|
|
if (editor->context)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (editor->context,
|
|
|
|
gimp_data_editor_data_changed,
|
|
|
|
editor);
|
|
|
|
|
|
|
|
g_object_unref (editor->context);
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->context = context;
|
|
|
|
|
|
|
|
if (editor->context)
|
|
|
|
{
|
|
|
|
GType data_type;
|
|
|
|
GimpData *data;
|
|
|
|
|
|
|
|
g_object_ref (editor->context);
|
|
|
|
|
2012-10-07 00:17:48 +02:00
|
|
|
data_type = gimp_data_factory_get_data_type (editor->data_factory);
|
2006-08-29 21:44:51 +00:00
|
|
|
data = GIMP_DATA (gimp_context_get_by_type (editor->context, data_type));
|
|
|
|
|
|
|
|
g_signal_connect (editor->context,
|
|
|
|
gimp_context_type_to_signal_name (data_type),
|
|
|
|
G_CALLBACK (gimp_data_editor_data_changed),
|
|
|
|
editor);
|
|
|
|
|
|
|
|
gimp_data_editor_data_changed (editor->context, data, editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
#define AUX_INFO_EDIT_ACTIVE "edit-active"
|
2003-10-18 17:10:36 +00:00
|
|
|
#define AUX_INFO_CURRENT_DATA "current-data"
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_set_aux_info (GimpDocked *docked,
|
|
|
|
GList *aux_info)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
|
|
|
|
GList *list;
|
|
|
|
|
2005-06-04 22:49:53 +00:00
|
|
|
parent_docked_iface->set_aux_info (docked, aux_info);
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
for (list = aux_info; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpSessionInfoAux *aux = list->data;
|
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
if (! strcmp (aux->name, AUX_INFO_EDIT_ACTIVE))
|
|
|
|
{
|
|
|
|
gboolean edit_active;
|
|
|
|
|
|
|
|
edit_active = ! g_ascii_strcasecmp (aux->value, "true");
|
|
|
|
|
|
|
|
gimp_data_editor_set_edit_active (editor, edit_active);
|
|
|
|
}
|
|
|
|
else if (! strcmp (aux->name, AUX_INFO_CURRENT_DATA))
|
2003-10-11 16:50:35 +00:00
|
|
|
{
|
2005-10-25 22:05:20 +00:00
|
|
|
if (! editor->edit_active)
|
|
|
|
{
|
|
|
|
GimpData *data;
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
data = (GimpData *)
|
2008-12-19 21:58:17 +00:00
|
|
|
gimp_container_get_child_by_name (gimp_data_factory_get_container (editor->data_factory),
|
2005-10-25 22:05:20 +00:00
|
|
|
aux->value);
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
if (data)
|
|
|
|
gimp_data_editor_set_data (editor, data);
|
|
|
|
}
|
2003-10-11 16:50:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
gimp_data_editor_get_aux_info (GimpDocked *docked)
|
|
|
|
{
|
2005-10-25 22:05:20 +00:00
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
|
|
|
|
GList *aux_info;
|
|
|
|
GimpSessionInfoAux *aux;
|
2005-06-04 22:49:53 +00:00
|
|
|
|
|
|
|
aux_info = parent_docked_iface->get_aux_info (docked);
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2005-10-25 22:05:20 +00:00
|
|
|
aux = gimp_session_info_aux_new (AUX_INFO_EDIT_ACTIVE,
|
|
|
|
editor->edit_active ? "true" : "false");
|
|
|
|
aux_info = g_list_append (aux_info, aux);
|
|
|
|
|
2003-10-11 16:50:35 +00:00
|
|
|
if (editor->data)
|
|
|
|
{
|
2005-10-25 22:05:20 +00:00
|
|
|
const gchar *value;
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2009-08-31 22:47:18 +02:00
|
|
|
value = gimp_object_get_name (editor->data);
|
2003-10-11 16:50:35 +00:00
|
|
|
|
2003-10-18 17:10:36 +00:00
|
|
|
aux = gimp_session_info_aux_new (AUX_INFO_CURRENT_DATA, value);
|
2003-10-11 16:50:35 +00:00
|
|
|
aux_info = g_list_append (aux_info, aux);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aux_info;
|
|
|
|
}
|
|
|
|
|
2005-04-16 20:48:33 +00:00
|
|
|
static gchar *
|
|
|
|
gimp_data_editor_get_title (GimpDocked *docked)
|
|
|
|
{
|
|
|
|
GimpDataEditor *editor = GIMP_DATA_EDITOR (docked);
|
|
|
|
GimpDataEditorClass *editor_class = GIMP_DATA_EDITOR_GET_CLASS (editor);
|
|
|
|
|
|
|
|
if (editor->data_editable)
|
|
|
|
return g_strdup (editor_class->title);
|
|
|
|
else
|
|
|
|
return g_strdup_printf (_("%s (read only)"), editor_class->title);
|
|
|
|
}
|
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_real_set_data (GimpDataEditor *editor,
|
|
|
|
GimpData *data)
|
|
|
|
{
|
2005-04-16 20:48:33 +00:00
|
|
|
gboolean editable;
|
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
if (editor->data)
|
|
|
|
{
|
2003-01-05 22:07:10 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (editor->data,
|
2002-03-08 00:27:45 +00:00
|
|
|
gimp_data_editor_data_name_changed,
|
|
|
|
editor);
|
|
|
|
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_unref (editor->data);
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
editor->data = data;
|
|
|
|
|
|
|
|
if (editor->data)
|
|
|
|
{
|
2003-01-05 22:07:10 +00:00
|
|
|
g_object_ref (editor->data);
|
2002-03-08 00:27:45 +00:00
|
|
|
|
2005-05-27 16:51:39 +00:00
|
|
|
g_signal_connect (editor->data, "name-changed",
|
2002-03-08 00:27:45 +00:00
|
|
|
G_CALLBACK (gimp_data_editor_data_name_changed),
|
|
|
|
editor);
|
|
|
|
|
2002-03-10 15:05:58 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
|
2009-08-31 22:47:18 +02:00
|
|
|
gimp_object_get_name (editor->data));
|
2002-03-10 15:05:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->name_entry), "");
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 18:48:38 +01:00
|
|
|
editable = (editor->data && gimp_data_is_writable (editor->data));
|
2005-04-16 20:48:33 +00:00
|
|
|
|
|
|
|
if (editor->data_editable != editable)
|
|
|
|
{
|
|
|
|
editor->data_editable = editable;
|
2003-03-10 14:07:22 +00:00
|
|
|
|
2006-11-01 02:20:42 +00:00
|
|
|
gtk_editable_set_editable (GTK_EDITABLE (editor->name_entry), editable);
|
2005-04-16 20:48:33 +00:00
|
|
|
gimp_docked_title_changed (GIMP_DOCKED (editor));
|
|
|
|
}
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_data_editor_set_data (GimpDataEditor *editor,
|
|
|
|
GimpData *data)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DATA_EDITOR (editor));
|
2003-03-21 11:47:37 +00:00
|
|
|
g_return_if_fail (data == NULL || GIMP_IS_DATA (data));
|
2003-10-11 16:50:35 +00:00
|
|
|
g_return_if_fail (data == NULL ||
|
|
|
|
g_type_is_a (G_TYPE_FROM_INSTANCE (data),
|
2012-10-07 00:17:48 +02:00
|
|
|
gimp_data_factory_get_data_type (editor->data_factory)));
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
if (editor->data != data)
|
2004-09-26 19:41:56 +00:00
|
|
|
{
|
|
|
|
GIMP_DATA_EDITOR_GET_CLASS (editor)->set_data (editor, data);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (editor), "data");
|
2004-10-24 20:38:35 +00:00
|
|
|
|
2011-04-09 19:51:51 +02:00
|
|
|
if (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)))
|
|
|
|
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor)),
|
|
|
|
gimp_editor_get_popup_data (GIMP_EDITOR (editor)));
|
2004-09-26 19:41:56 +00:00
|
|
|
}
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpData *
|
|
|
|
gimp_data_editor_get_data (GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_EDITOR (editor), NULL);
|
|
|
|
|
|
|
|
return editor->data;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:38:00 +00:00
|
|
|
void
|
|
|
|
gimp_data_editor_set_edit_active (GimpDataEditor *editor,
|
|
|
|
gboolean edit_active)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_DATA_EDITOR (editor));
|
|
|
|
|
|
|
|
if (editor->edit_active != edit_active)
|
|
|
|
{
|
|
|
|
editor->edit_active = edit_active;
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
if (editor->edit_active && editor->context)
|
2005-10-25 21:38:00 +00:00
|
|
|
{
|
|
|
|
GType data_type;
|
|
|
|
GimpData *data;
|
|
|
|
|
2012-10-07 00:17:48 +02:00
|
|
|
data_type = gimp_data_factory_get_data_type (editor->data_factory);
|
2006-08-29 21:44:51 +00:00
|
|
|
data = GIMP_DATA (gimp_context_get_by_type (editor->context,
|
|
|
|
data_type));
|
2005-10-25 21:38:00 +00:00
|
|
|
|
|
|
|
gimp_data_editor_set_data (editor, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_data_editor_get_edit_active (GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_DATA_EDITOR (editor), FALSE);
|
|
|
|
|
|
|
|
return editor->edit_active;
|
|
|
|
}
|
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_data_changed (GimpContext *context,
|
|
|
|
GimpData *data,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
if (editor->edit_active)
|
|
|
|
gimp_data_editor_set_data (editor, data);
|
|
|
|
}
|
|
|
|
|
2005-08-08 01:04:26 +00:00
|
|
|
static gboolean
|
|
|
|
gimp_data_editor_name_key_press (GtkWidget *widget,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
2011-03-29 15:27:25 +02:00
|
|
|
if (kevent->keyval == GDK_KEY_Escape)
|
2005-08-08 01:04:26 +00:00
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
|
2009-08-31 22:47:18 +02:00
|
|
|
gimp_object_get_name (editor->data));
|
2005-08-08 01:04:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-08 00:27:45 +00:00
|
|
|
static void
|
|
|
|
gimp_data_editor_name_activate (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
if (editor->data)
|
2006-05-30 11:56:42 +00:00
|
|
|
{
|
|
|
|
gchar *new_name;
|
|
|
|
|
|
|
|
new_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (widget)));
|
|
|
|
new_name = g_strstrip (new_name);
|
|
|
|
|
2015-02-24 19:07:39 +01:00
|
|
|
if (strlen (new_name) &&
|
|
|
|
g_strcmp0 (new_name, gimp_object_get_name (editor->data)))
|
2006-05-30 11:56:42 +00:00
|
|
|
{
|
|
|
|
gimp_object_take_name (GIMP_OBJECT (editor->data), new_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (widget),
|
2009-08-31 22:47:18 +02:00
|
|
|
gimp_object_get_name (editor->data));
|
2006-05-30 11:56:42 +00:00
|
|
|
g_free (new_name);
|
|
|
|
}
|
|
|
|
}
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_data_editor_name_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
gimp_data_editor_name_activate (widget, editor);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_data_name_changed (GimpObject *object,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (editor->name_entry),
|
2006-04-12 12:49:29 +00:00
|
|
|
gimp_object_get_name (object));
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_save_clicked (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor)
|
2003-11-11 19:00:42 +00:00
|
|
|
{
|
|
|
|
gimp_data_editor_save_dirty (editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_revert_clicked (GtkWidget *widget,
|
|
|
|
GimpDataEditor *editor)
|
|
|
|
{
|
|
|
|
g_print ("TODO: implement revert\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_data_editor_save_dirty (GimpDataEditor *editor)
|
2002-03-08 00:27:45 +00:00
|
|
|
{
|
2004-01-28 21:53:50 +00:00
|
|
|
GimpData *data = editor->data;
|
2003-11-11 23:50:03 +00:00
|
|
|
|
2009-10-31 18:48:38 +01:00
|
|
|
if (data &&
|
|
|
|
gimp_data_is_dirty (data) &&
|
|
|
|
gimp_data_is_writable (data))
|
2006-10-09 18:49:15 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (! gimp_data_factory_data_save_single (editor->data_factory, data,
|
|
|
|
&error))
|
|
|
|
{
|
2009-10-31 18:48:38 +01:00
|
|
|
gimp_message_literal (gimp_data_factory_get_gimp (editor->data_factory),
|
|
|
|
G_OBJECT (editor),
|
2013-09-15 04:59:20 +12:00
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
error->message);
|
2006-10-09 18:49:15 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
}
|
2002-03-08 00:27:45 +00:00
|
|
|
}
|