/* * GIMP - The GNU Image Manipulation Program * Copyright (C) 1995 Spencer Kimball and Peter Mattis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (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 * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * Edit Comments - a plugin to solve the embarrassing problem of being * unable to edit comments. Written by Simon Budig */ /* #include "config.h" */ #include #include #include /* #include "libgimp/stdplugins-intl.h" */ #define N_(a) a #define _(a) a /* Some useful macros */ #define PLUG_IN_PROC "plug-in-edit-comment" #define PLUG_IN_BINARY "edit-comment" #define COMMENT_ID "gimp-comment" #define RESPONSE_RESET 1 /* * Function prototypes. */ static void query (void); static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals); static GimpParasite * edit_comment_dialog (gint32 image); /***** Local vars *****/ const GimpPlugInInfo PLUG_IN_INFO = { NULL, /* init */ NULL, /* quit */ query, /* query */ run, /* run */ }; /***** Functions *****/ MAIN () static void query (void) { static const GimpParamDef args[] = { { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, { GIMP_PDB_IMAGE, "image", "Input image" }, { GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" }, { GIMP_PDB_STRING, "comment", "New comment" } }; gimp_install_procedure (PLUG_IN_PROC, N_("Edit image comment"), "Edit the comment of the image.", "Simon Budig", "Simon Budig", "2006-12-16", N_("_Image Comment..."), "*", GIMP_PLUGIN, G_N_ELEMENTS (args), 0, args, NULL); gimp_plugin_menu_register (PLUG_IN_PROC, "/Image"); } static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image; GimpParasite *new_comment = NULL; gint size; run_mode = param[0].data.d_int32; image = param[1].data.d_image; /* INIT_I18N (); */ *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; switch (run_mode) { case GIMP_RUN_INTERACTIVE: new_comment = edit_comment_dialog (image); if (new_comment) gimp_set_data (PLUG_IN_PROC, new_comment->data, new_comment->size); break; case GIMP_RUN_NONINTERACTIVE: if (nparams != 4) status = GIMP_PDB_CALLING_ERROR; else new_comment = gimp_parasite_new (COMMENT_ID, GIMP_PARASITE_PERSISTENT, strlen (param[3].data.d_string) + 1, param[3].data.d_string); break; case GIMP_RUN_WITH_LAST_VALS: size = gimp_get_data_size (PLUG_IN_PROC); if (size > 0) { gchar *new_text = g_new0 (gchar, size); gimp_get_data (PLUG_IN_PROC, new_text); new_comment = gimp_parasite_new (COMMENT_ID, GIMP_PARASITE_PERSISTENT, strlen (new_text) + 1, new_text); g_free (new_text); } break; default: break; } if (new_comment) { if (new_comment->size > 1) gimp_image_parasite_attach (image, new_comment); else gimp_image_parasite_detach (image, COMMENT_ID); gimp_parasite_free (new_comment); } values[0].data.d_status = status; } GimpParasite * edit_comment_dialog (gint32 image) { GtkWidget *dialog, *frame, *scrolled, *view; GtkTextBuffer *buffer; gint dlg_run; GimpParasite *comment; GimpParasite *new_comment = NULL; gchar *new_text; gimp_ui_init (PLUG_IN_BINARY, FALSE); dialog = g_object_new (GIMP_TYPE_DIALOG, "title", _("Edit Image Comment"), "role", PLUG_IN_BINARY, NULL); gimp_dialog_add_buttons (GIMP_DIALOG (dialog), GIMP_STOCK_RESET, RESPONSE_RESET, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), RESPONSE_RESET, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1); gimp_window_set_transient (GTK_WINDOW (dialog)); frame = g_object_new (GIMP_TYPE_FRAME, "label", _("Image Comment"), "border-width", 12, "parent", GTK_DIALOG (dialog)->vbox, "visible", TRUE, NULL); scrolled = g_object_new (GTK_TYPE_SCROLLED_WINDOW, "shadow-type", GTK_SHADOW_IN, "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, "parent", frame, "visible", TRUE, NULL); view = g_object_new (GTK_TYPE_TEXT_VIEW, "parent", scrolled, "visible", TRUE, NULL); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); comment = gimp_image_parasite_find (image, COMMENT_ID); gtk_widget_show (dialog); dlg_run = RESPONSE_RESET; while (dlg_run == RESPONSE_RESET) { gtk_text_buffer_set_text (buffer, comment ? (gchar *) (comment->data) : "", -1); dlg_run = gimp_dialog_run (GIMP_DIALOG (dialog)); switch (dlg_run) { case GTK_RESPONSE_OK: g_object_get (G_OBJECT (buffer), "text", &new_text, NULL); new_comment = gimp_parasite_new (COMMENT_ID, GIMP_PARASITE_PERSISTENT, strlen (new_text) + 1, new_text); break; default: break; } } gtk_widget_destroy (dialog); if (comment) gimp_parasite_free (comment); return new_comment; }