diff --git a/ChangeLog b/ChangeLog index a5a57c76d1..c4681ae2f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,49 @@ +2006-06-16 Michael Natterer + + Allow plug-ins to register in , , and + : + + * app/pdb/gimppluginprocedure.c + (gimp_plug_in_procedure_add_menu_path): added the argument type + checks for the new locations. Factored out duplicated code. + + * app/menus/menus.c (menus_init): add the "plug-in" action + group to the resp. UI managers. + + * app/menus/plug-in-menus.c (plug_in_menus_menu_path_added): + support them here too. + + * app/widgets/gimpimageeditor.[ch] + * app/widgets/gimpitemtreeview.[ch]: added get_image() functions. + + * app/actions/plug-in-commands.c: added new utility functions + which collect plug-in arguments from GimpImageEditor and + GimpItemTreeView widgets. + + * menus/channels-menu.xml + * menus/colormap-editor-menu.xml + * menus/layers-menu.xml + * menus/vectors-menu.xml: added separators. + + * menus/image-menu.xml.in: added a "Colormap" placeholder in + Colors/Map + + * plug-ins/common/colormap-remap.c (query): register a menu + entry in and moved the existing one to the + "Colormap" placeholder. Also register an icon to make this + menu item clearly distinct from the others in that menu. + + Unrelated: + + * plug-ins/common/colormap-remap.c (run): cleaned up quite a + bit. Fixed last-vals code and simplified map handling. + + (remap_swap): removed, folded into run(). + + (remap_dialog): use the passed map to initialize the dialog so it + starts with the last-vals. Tweaked layout to have 16 columns + and simplified cell renderer creation. + 2006-06-16 Manish Singh * app/errors.c diff --git a/app/actions/plug-in-commands.c b/app/actions/plug-in-commands.c index 9efc1954e8..4e2a31304a 100644 --- a/app/actions/plug-in-commands.c +++ b/app/actions/plug-in-commands.c @@ -46,6 +46,8 @@ #include "widgets/gimpdatafactoryview.h" #include "widgets/gimpfontview.h" #include "widgets/gimphelp-ids.h" +#include "widgets/gimpimageeditor.h" +#include "widgets/gimpitemtreeview.h" #include "widgets/gimpmessagebox.h" #include "widgets/gimpmessagedialog.h" @@ -59,17 +61,26 @@ /* local function prototypes */ -static gint plug_in_collect_data_args (GtkAction *action, - GimpObject *object, - GValueArray *args, - gint n_args); -static gint plug_in_collect_image_args (GtkAction *action, - GimpDisplay *display, - GValueArray *args, - gint n_args); -static void plug_in_reset_all_response (GtkWidget *dialog, - gint response_id, - Gimp *gimp); +static gint plug_in_collect_data_args (GtkAction *action, + GimpObject *object, + GValueArray *args, + gint n_args); +static gint plug_in_collect_image_args (GtkAction *action, + GimpImage *image, + GValueArray *args, + gint n_args); +static gint plug_in_collect_item_args (GtkAction *action, + GimpImage *image, + GimpItem *item, + GValueArray *args, + gint n_args); +static gint plug_in_collect_drawable_args (GtkAction *action, + GimpImage *image, + GValueArray *args, + gint n_args); +static void plug_in_reset_all_response (GtkWidget *dialog, + gint response_id, + Gimp *gimp); /* public functions */ @@ -117,12 +128,45 @@ plug_in_run_cmd_callback (GtkAction *action, n_args = plug_in_collect_data_args (action, object, args, n_args); } + else if (GIMP_IS_IMAGE_EDITOR (data)) + { + GimpImageEditor *editor = GIMP_IMAGE_EDITOR (data); + GimpImage *image; + + image = gimp_image_editor_get_image (editor); + + n_args = plug_in_collect_image_args (action, image, + args, n_args); + } + else if (GIMP_IS_ITEM_TREE_VIEW (data)) + { + GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data); + GimpImage *image; + GimpItem *item; + + image = gimp_item_tree_view_get_image (view); + + if (image) + item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (image); + else + item = NULL; + + n_args = plug_in_collect_item_args (action, image, item, + args, n_args); + } else { + GimpImage *image; + display = action_data_get_display (data); - n_args = plug_in_collect_image_args (action, display, - args, n_args); + if (display) + image = display->image; + else + image = NULL; + + n_args = plug_in_collect_drawable_args (action, image, + args, n_args); } break; @@ -261,24 +305,81 @@ plug_in_collect_data_args (GtkAction *action, static gint plug_in_collect_image_args (GtkAction *action, - GimpDisplay *display, + GimpImage *image, GValueArray *args, gint n_args) { if (args->n_values > n_args && GIMP_VALUE_HOLDS_IMAGE_ID (&args->values[n_args])) { - if (display) + if (image) { - gimp_value_set_image (&args->values[n_args], display->image); + gimp_value_set_image (&args->values[n_args], image); + n_args++; + } + else + { + g_warning ("Uh-oh, no active image for the plug-in!"); + return -1; + } + } + + return n_args; +} + +static gint +plug_in_collect_item_args (GtkAction *action, + GimpImage *image, + GimpItem *item, + GValueArray *args, + gint n_args) +{ + if (args->n_values > n_args && + GIMP_VALUE_HOLDS_IMAGE_ID (&args->values[n_args])) + { + if (image) + { + gimp_value_set_image (&args->values[n_args], image); + n_args++; + + if (args->n_values > n_args && + GIMP_VALUE_HOLDS_ITEM_ID (&args->values[n_args])) + { + if (item) + { + gimp_value_set_item (&args->values[n_args], item); + n_args++; + } + else + { + g_warning ("Uh-oh, no active item for the plug-in!"); + return -1; + } + } + } + } + + return n_args; +} + +static gint +plug_in_collect_drawable_args (GtkAction *action, + GimpImage *image, + GValueArray *args, + gint n_args) +{ + if (args->n_values > n_args && + GIMP_VALUE_HOLDS_IMAGE_ID (&args->values[n_args])) + { + if (image) + { + gimp_value_set_image (&args->values[n_args], image); n_args++; if (args->n_values > n_args && GIMP_VALUE_HOLDS_DRAWABLE_ID (&args->values[n_args])) { - GimpDrawable *drawable; - - drawable = gimp_image_active_drawable (display->image); + GimpDrawable *drawable = gimp_image_active_drawable (image); if (drawable) { diff --git a/app/menus/menus.c b/app/menus/menus.c index a565c4b6b9..853253b8fe 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -157,23 +157,26 @@ menus_init (Gimp *gimp, gimp_menu_factory_manager_register (global_menu_factory, "", "layers", + "plug-in", NULL, "/layers-popup", - "layers-menu.xml", NULL, + "layers-menu.xml", plug_in_menus_setup, NULL); gimp_menu_factory_manager_register (global_menu_factory, "", "channels", + "plug-in", NULL, "/channels-popup", - "channels-menu.xml", NULL, + "channels-menu.xml", plug_in_menus_setup, NULL); gimp_menu_factory_manager_register (global_menu_factory, "", "vectors", + "plug-in", NULL, "/vectors-popup", - "vectors-menu.xml", NULL, + "vectors-menu.xml", plug_in_menus_setup, NULL); gimp_menu_factory_manager_register (global_menu_factory, "", @@ -283,9 +286,10 @@ menus_init (Gimp *gimp, gimp_menu_factory_manager_register (global_menu_factory, "", "colormap-editor", + "plug-in", NULL, "/colormap-editor-popup", - "colormap-editor-menu.xml", NULL, + "colormap-editor-menu.xml", plug_in_menus_setup, NULL); gimp_menu_factory_manager_register (global_menu_factory, "", diff --git a/app/menus/plug-in-menus.c b/app/menus/plug-in-menus.c index 832713bce1..ff349575e9 100644 --- a/app/menus/plug-in-menus.c +++ b/app/menus/plug-in-menus.c @@ -304,6 +304,26 @@ plug_in_menus_menu_path_added (GimpPlugInProcedure *plug_in_proc, plug_in_menus_add_proc (manager, "/toolbox-menubar", plug_in_proc, menu_path); } + else if (! strcmp (manager->name, "")) + { + plug_in_menus_add_proc (manager, "/layers-popup", + plug_in_proc, menu_path); + } + else if (! strcmp (manager->name, "")) + { + plug_in_menus_add_proc (manager, "/channels-popup", + plug_in_proc, menu_path); + } + else if (! strcmp (manager->name, "")) + { + plug_in_menus_add_proc (manager, "/vectors-popup", + plug_in_proc, menu_path); + } + else if (! strcmp (manager->name, "")) + { + plug_in_menus_add_proc (manager, "/colormap-editor-popup", + plug_in_proc, menu_path); + } else if (! strcmp (manager->name, "")) { plug_in_menus_add_proc (manager, "/brushes-popup", diff --git a/app/pdb/gimppluginprocedure.c b/app/pdb/gimppluginprocedure.c index cb79377918..ca6dcb244e 100644 --- a/app/pdb/gimppluginprocedure.c +++ b/app/pdb/gimppluginprocedure.c @@ -297,6 +297,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, GimpProcedure *procedure; gchar *basename = NULL; gchar *prefix; + const gchar *required = NULL; gchar *p; g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE); @@ -317,16 +318,40 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, if ((procedure->num_args < 1) || ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install %s procedure \"%s\" " - "which does not take the standard %s Plug-In " - "arguments.\n" - "(INT32)", - basename, gimp_filename_to_utf8 (proc->prog), - prefix, GIMP_OBJECT (proc)->name, prefix); + required = "INT32"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0 || + strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 3) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]) || + ! GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[2])) + { + required = "INT32, IMAGE, DRAWABLE"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 3) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]) || + ! GIMP_IS_PARAM_SPEC_VECTORS_ID (procedure->args[2])) + { + required = "INT32, IMAGE, VECTORS"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 2) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1])) + { + required = "INT32, IMAGE"; goto failure; } } @@ -337,32 +362,14 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, ! G_IS_PARAM_SPEC_STRING (procedure->args[1]) || ! G_IS_PARAM_SPEC_STRING (procedure->args[2])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not take the standard Plug-In " - "arguments.\n" - "(INT32, STRING, STRING)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "INT32, STRING, STRING"; goto failure; } if ((procedure->num_values < 1) || ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->values[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not return the standard Plug-In " - "values.\n" - "(IMAGE)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "IMAGE"; goto failure; } } @@ -375,16 +382,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, ! G_IS_PARAM_SPEC_STRING (procedure->args[3]) || ! G_IS_PARAM_SPEC_STRING (procedure->args[4])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not take the standard Plug-In " - "arguments.\n" - "(INT32, IMAGE, DRAWABLE, STRING, STRING)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "INT32, IMAGE, DRAWABLE, STRING, STRING"; goto failure; } } @@ -398,16 +396,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, if ((procedure->num_args < 1) || ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install %s procedure \"%s\" " - "which does not take the standard %s Plug-In " - "arguments.\n" - "(INT32)", - basename, gimp_filename_to_utf8 (proc->prog), - prefix, GIMP_OBJECT (proc)->name, prefix); + required = "INT32"; goto failure; } } @@ -420,9 +409,10 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, "attempted to install procedure \"%s\" " "in the invalid menu location \"%s\".\n" "Use either \"\", \"\", " - "\"\", \"\", \"\", " - "\"\", \"\", \"\" or " - "\"\".", + "\"\", \"\", \"\", " + "\"\", \"\", \"\", " + "\"\", \"\", \"\", " + "\"\" or \"\".", basename, gimp_filename_to_utf8 (proc->prog), GIMP_OBJECT (proc)->name, menu_path); @@ -458,6 +448,21 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, return TRUE; failure: + if (required) + { + basename = g_filename_display_basename (proc->prog); + + g_set_error (error, 0, 0, + "Plug-In \"%s\"\n(%s)\n\n" + "attempted to install %s procedure \"%s\" " + "which does not take the standard %s Plug-In " + "arguments.\n" + "(%s)", + basename, gimp_filename_to_utf8 (proc->prog), + prefix, GIMP_OBJECT (proc)->name, prefix, + required); + } + g_free (prefix); g_free (basename); diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index cb79377918..ca6dcb244e 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -297,6 +297,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, GimpProcedure *procedure; gchar *basename = NULL; gchar *prefix; + const gchar *required = NULL; gchar *p; g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE); @@ -317,16 +318,40 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, if ((procedure->num_args < 1) || ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install %s procedure \"%s\" " - "which does not take the standard %s Plug-In " - "arguments.\n" - "(INT32)", - basename, gimp_filename_to_utf8 (proc->prog), - prefix, GIMP_OBJECT (proc)->name, prefix); + required = "INT32"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0 || + strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 3) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]) || + ! GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[2])) + { + required = "INT32, IMAGE, DRAWABLE"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 3) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1]) || + ! GIMP_IS_PARAM_SPEC_VECTORS_ID (procedure->args[2])) + { + required = "INT32, IMAGE, VECTORS"; + goto failure; + } + } + else if (strcmp (prefix, "") == 0) + { + if ((procedure->num_args < 2) || + ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) || + ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[1])) + { + required = "INT32, IMAGE"; goto failure; } } @@ -337,32 +362,14 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, ! G_IS_PARAM_SPEC_STRING (procedure->args[1]) || ! G_IS_PARAM_SPEC_STRING (procedure->args[2])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not take the standard Plug-In " - "arguments.\n" - "(INT32, STRING, STRING)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "INT32, STRING, STRING"; goto failure; } if ((procedure->num_values < 1) || ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->values[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not return the standard Plug-In " - "values.\n" - "(IMAGE)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "IMAGE"; goto failure; } } @@ -375,16 +382,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, ! G_IS_PARAM_SPEC_STRING (procedure->args[3]) || ! G_IS_PARAM_SPEC_STRING (procedure->args[4])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install procedure \"%s\" " - "which does not take the standard Plug-In " - "arguments.\n" - "(INT32, IMAGE, DRAWABLE, STRING, STRING)", - basename, gimp_filename_to_utf8 (proc->prog), - GIMP_OBJECT (proc)->name); + required = "INT32, IMAGE, DRAWABLE, STRING, STRING"; goto failure; } } @@ -398,16 +396,7 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, if ((procedure->num_args < 1) || ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0])) { - basename = g_filename_display_basename (proc->prog); - - g_set_error (error, 0, 0, - "Plug-In \"%s\"\n(%s)\n\n" - "attempted to install %s procedure \"%s\" " - "which does not take the standard %s Plug-In " - "arguments.\n" - "(INT32)", - basename, gimp_filename_to_utf8 (proc->prog), - prefix, GIMP_OBJECT (proc)->name, prefix); + required = "INT32"; goto failure; } } @@ -420,9 +409,10 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, "attempted to install procedure \"%s\" " "in the invalid menu location \"%s\".\n" "Use either \"\", \"\", " - "\"\", \"\", \"\", " - "\"\", \"\", \"\" or " - "\"\".", + "\"\", \"\", \"\", " + "\"\", \"\", \"\", " + "\"\", \"\", \"\", " + "\"\" or \"\".", basename, gimp_filename_to_utf8 (proc->prog), GIMP_OBJECT (proc)->name, menu_path); @@ -458,6 +448,21 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure *proc, return TRUE; failure: + if (required) + { + basename = g_filename_display_basename (proc->prog); + + g_set_error (error, 0, 0, + "Plug-In \"%s\"\n(%s)\n\n" + "attempted to install %s procedure \"%s\" " + "which does not take the standard %s Plug-In " + "arguments.\n" + "(%s)", + basename, gimp_filename_to_utf8 (proc->prog), + prefix, GIMP_OBJECT (proc)->name, prefix, + required); + } + g_free (prefix); g_free (basename); diff --git a/app/widgets/gimpimageeditor.c b/app/widgets/gimpimageeditor.c index f003e4525f..ddf26eae29 100644 --- a/app/widgets/gimpimageeditor.c +++ b/app/widgets/gimpimageeditor.c @@ -148,6 +148,14 @@ gimp_image_editor_set_image (GimpImageEditor *editor, } } +GimpImage * +gimp_image_editor_get_image (GimpImageEditor *editor) +{ + g_return_val_if_fail (GIMP_IS_IMAGE_EDITOR (editor), NULL); + + return editor->image; +} + /* private functions */ diff --git a/app/widgets/gimpimageeditor.h b/app/widgets/gimpimageeditor.h index 038a0650bd..3e1c99b3e8 100644 --- a/app/widgets/gimpimageeditor.h +++ b/app/widgets/gimpimageeditor.h @@ -51,10 +51,11 @@ struct _GimpImageEditorClass }; -GType gimp_image_editor_get_type (void) G_GNUC_CONST; +GType gimp_image_editor_get_type (void) G_GNUC_CONST; -void gimp_image_editor_set_image (GimpImageEditor *editor, - GimpImage *image); +void gimp_image_editor_set_image (GimpImageEditor *editor, + GimpImage *image); +GimpImage * gimp_image_editor_get_image (GimpImageEditor *editor); #endif /* __GIMP_IMAGE_EDITOR_H__ */ diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c index a819acd486..844e837912 100644 --- a/app/widgets/gimpitemtreeview.c +++ b/app/widgets/gimpitemtreeview.c @@ -477,6 +477,14 @@ gimp_item_tree_view_set_image (GimpItemTreeView *view, gimp_ui_manager_update (GIMP_EDITOR (view)->ui_manager, view); } +GimpImage * +gimp_item_tree_view_get_image (GimpItemTreeView *view) +{ + g_return_val_if_fail (GIMP_IS_ITEM_TREE_VIEW (view), NULL); + + return view->image; +} + static void gimp_item_tree_view_real_set_image (GimpItemTreeView *view, GimpImage *image) diff --git a/app/widgets/gimpitemtreeview.h b/app/widgets/gimpitemtreeview.h index a5fc31f315..cea4c89bc1 100644 --- a/app/widgets/gimpitemtreeview.h +++ b/app/widgets/gimpitemtreeview.h @@ -115,18 +115,19 @@ struct _GimpItemTreeViewClass }; -GType gimp_item_tree_view_get_type (void) G_GNUC_CONST; +GType gimp_item_tree_view_get_type (void) G_GNUC_CONST; -GtkWidget * gimp_item_tree_view_new (GType view_type, - gint view_size, - gint view_border_width, - GimpImage *image, - GimpMenuFactory *menu_facotry, - const gchar *menu_identifier, - const gchar *ui_identifier); +GtkWidget * gimp_item_tree_view_new (GType view_type, + gint view_size, + gint view_border_width, + GimpImage *image, + GimpMenuFactory *menu_facotry, + const gchar *menu_identifier, + const gchar *ui_identifier); -void gimp_item_tree_view_set_image (GimpItemTreeView *view, - GimpImage *image); +void gimp_item_tree_view_set_image (GimpItemTreeView *view, + GimpImage *image); +GimpImage * gimp_item_tree_view_get_image (GimpItemTreeView *view); #endif /* __GIMP_ITEM_TREE_VIEW_H__ */ diff --git a/menus/channels-menu.xml b/menus/channels-menu.xml index e4139c250a..a31b0b9fc4 100644 --- a/menus/channels-menu.xml +++ b/menus/channels-menu.xml @@ -15,5 +15,6 @@ + diff --git a/menus/colormap-editor-menu.xml b/menus/colormap-editor-menu.xml index 014c662c9a..9085c0a2cf 100644 --- a/menus/colormap-editor-menu.xml +++ b/menus/colormap-editor-menu.xml @@ -6,5 +6,6 @@ + diff --git a/menus/colormap-menu.xml b/menus/colormap-menu.xml index 014c662c9a..9085c0a2cf 100644 --- a/menus/colormap-menu.xml +++ b/menus/colormap-menu.xml @@ -6,5 +6,6 @@ + diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in index 7621345217..22481f236d 100644 --- a/menus/image-menu.xml.in +++ b/menus/image-menu.xml.in @@ -467,7 +467,10 @@ - + + + + diff --git a/menus/layers-menu.xml b/menus/layers-menu.xml index e9a5a4d299..21d867e92d 100644 --- a/menus/layers-menu.xml +++ b/menus/layers-menu.xml @@ -42,5 +42,6 @@ + diff --git a/menus/vectors-menu.xml b/menus/vectors-menu.xml index 2f8ec7c644..3c128f9a5b 100644 --- a/menus/vectors-menu.xml +++ b/menus/vectors-menu.xml @@ -24,5 +24,6 @@ + diff --git a/plug-ins/common/colormap-remap.c b/plug-ins/common/colormap-remap.c index 12120917de..08ee0ef61e 100644 --- a/plug-ins/common/colormap-remap.c +++ b/plug-ins/common/colormap-remap.c @@ -53,15 +53,9 @@ static void run (const gchar *name, GimpParam **return_vals); static gboolean remap (gint32 image_ID, - gboolean is_non_interactive, gint num_colors, guchar *map); -static gboolean remap_swap (gint32 image_ID, - guchar *map, - guchar index1, - guchar index2); - static gboolean remap_dialog (gint32 image_ID, guchar *map); @@ -92,7 +86,7 @@ query (void) static const GimpParamDef swap_args[] = { - { GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" }, + { GIMP_PDB_INT32, "run-mode", "Non-interactive" }, { GIMP_PDB_IMAGE, "image", "Input image" }, { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" }, { GIMP_PDB_INT8, "index1", "First index in the colormap" }, @@ -107,13 +101,17 @@ query (void) "Mukund Sivaraman ", "Mukund Sivaraman ", "14th June 2006", - N_("_Rearrange Colormap..."), + N_("R_earrange Colormap..."), "INDEXED*", GIMP_PLUGIN, G_N_ELEMENTS (remap_args), 0, remap_args, NULL); - gimp_plugin_menu_register (PLUG_IN_PROC_REMAP, "/Colors/Map"); + gimp_plugin_menu_register (PLUG_IN_PROC_REMAP, "/Colors/Map/Colormap"); + gimp_plugin_menu_register (PLUG_IN_PROC_REMAP, ""); + gimp_plugin_icon_register (PLUG_IN_PROC_REMAP, + GIMP_ICON_TYPE_STOCK_ID, + (const guchar *) GIMP_STOCK_COLORMAP); gimp_install_procedure (PLUG_IN_PROC_SWAP, N_("Swap two colors in the colormap"), @@ -141,10 +139,7 @@ run (const gchar *name, gint32 image_ID; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpRunMode run_mode; - guchar ui_map[256]; - gint num_colors = 256; - gboolean is_non_interactive = FALSE; - guchar *map = ui_map; + guchar map[256]; gint i; INIT_I18N (); @@ -159,109 +154,108 @@ run (const gchar *name, image_ID = param[1].data.d_image; + for (i = 0; i < 256; i++) + map[i] = i; + if (strcmp (name, PLUG_IN_PROC_REMAP) == 0) { - /* Make sure that the drawable is indexed */ - if (gimp_image_base_type (image_ID) == GIMP_INDEXED) + /* Make sure that the image is indexed */ + if (gimp_image_base_type (image_ID) != GIMP_INDEXED) + status = GIMP_PDB_EXECUTION_ERROR; + + if (status == GIMP_PDB_SUCCESS) { - for (i = 0; i < 256; i++) - ui_map[i] = i; + gint n_cols; + + g_free (gimp_image_get_colormap (image_ID, &n_cols)); switch (run_mode) { - case GIMP_RUN_INTERACTIVE: - if (! remap_dialog (image_ID, ui_map)) - status = GIMP_PDB_EXECUTION_ERROR; - break; + case GIMP_RUN_INTERACTIVE: + gimp_get_data (PLUG_IN_PROC_REMAP, map); - case GIMP_RUN_NONINTERACTIVE: - is_non_interactive = TRUE; - num_colors = param[3].data.d_int32; - map = (guchar *) param[4].data.d_int8array; - break; + if (! remap_dialog (image_ID, map)) + status = GIMP_PDB_CANCEL; + break; - case GIMP_RUN_WITH_LAST_VALS: - gimp_get_data (PLUG_IN_PROC_REMAP, &ui_map); - if (ui_map == NULL) - status = GIMP_PDB_EXECUTION_ERROR; - break; + case GIMP_RUN_NONINTERACTIVE: + if (nparams != 5) + status = GIMP_PDB_CALLING_ERROR; + + if (status == GIMP_PDB_SUCCESS) + { + if (n_cols != param[3].data.d_int32) + status = GIMP_PDB_CALLING_ERROR; + + if (status == GIMP_PDB_SUCCESS) + { + for (i = 0; i < n_cols; i++) + map[i] = (guchar) param[4].data.d_int8array[i]; + } + } + break; + + case GIMP_RUN_WITH_LAST_VALS: + gimp_get_data (PLUG_IN_PROC_REMAP, map); + break; } if (status == GIMP_PDB_SUCCESS) { - if (! remap (image_ID, is_non_interactive, num_colors, map)) - { - status = GIMP_PDB_EXECUTION_ERROR; - } - else if (run_mode != GIMP_RUN_WITH_LAST_VALS) - { - if (map == ui_map) - { - gimp_set_data (PLUG_IN_PROC_REMAP, - &ui_map, sizeof (ui_map)); - } - else - { - for (i = 0; i < num_colors; i++) - ui_map[i] = map[i]; + if (! remap (image_ID, n_cols, map)) + status = GIMP_PDB_EXECUTION_ERROR; - gimp_set_data (PLUG_IN_PROC_REMAP, - &ui_map, sizeof (ui_map)); - } - } + if (status == GIMP_PDB_SUCCESS) + { + if (run_mode == GIMP_RUN_INTERACTIVE) + gimp_set_data (PLUG_IN_PROC_REMAP, map, sizeof (map)); - if (run_mode != GIMP_RUN_NONINTERACTIVE) - gimp_displays_flush (); + if (run_mode != GIMP_RUN_NONINTERACTIVE) + gimp_displays_flush (); + } } } - else - { - status = GIMP_PDB_EXECUTION_ERROR; - } } else if (strcmp (name, PLUG_IN_PROC_SWAP) == 0) { - /* Make sure that the drawable is indexed */ - if (gimp_image_base_type (image_ID) == GIMP_INDEXED) + /* Make sure that the image is indexed */ + if (gimp_image_base_type (image_ID) != GIMP_INDEXED) + status = GIMP_PDB_EXECUTION_ERROR; + + if (status == GIMP_PDB_SUCCESS) { - for (i = 0; i < 256; i++) - ui_map[i] = i; - - if (run_mode == GIMP_RUN_INTERACTIVE) - { - status = GIMP_PDB_EXECUTION_ERROR; - } - else if (run_mode == GIMP_RUN_WITH_LAST_VALS) - { - gimp_get_data (PLUG_IN_PROC_REMAP, &ui_map); - - if (ui_map == NULL) - status = GIMP_PDB_EXECUTION_ERROR; - else if (! remap (image_ID, FALSE, 256, ui_map)) - status = GIMP_PDB_EXECUTION_ERROR; - } - else + if (run_mode == GIMP_RUN_NONINTERACTIVE && nparams == 5) { guchar index1 = param[3].data.d_int8; guchar index2 = param[4].data.d_int8; + gint n_cols; - if (! remap_swap (image_ID, ui_map, index1, index2)) + g_free (gimp_image_get_colormap (image_ID, &n_cols)); + + if (index1 >= n_cols || index2 >= n_cols) status = GIMP_PDB_CALLING_ERROR; - if (! remap (image_ID, FALSE, 256, ui_map)) - status = GIMP_PDB_EXECUTION_ERROR; - else - gimp_set_data (PLUG_IN_PROC_SWAP, &ui_map, sizeof (ui_map)); + if (status == GIMP_PDB_SUCCESS) + { + guchar tmp; + + tmp = map[index1]; + map[index1] = map[index2]; + map[index2] = tmp; + + if (! remap (image_ID, n_cols, map)) + status = GIMP_PDB_EXECUTION_ERROR; + } + } + else + { + status = GIMP_PDB_CALLING_ERROR; } - } - else - { - status = GIMP_PDB_EXECUTION_ERROR; } } else { - status = GIMP_PDB_EXECUTION_ERROR; + status = GIMP_PDB_CALLING_ERROR; } values[0].data.d_status = status; @@ -269,10 +263,9 @@ run (const gchar *name, static gboolean -remap (gint32 image_ID, - gboolean is_non_interactive, - gint num_colors, - guchar *map) +remap (gint32 image_ID, + gint num_colors, + guchar *map) { guchar *cmap, *new_cmap; guchar *new_cmap_i; @@ -290,7 +283,7 @@ remap (gint32 image_ID, g_return_val_if_fail (cmap != NULL, FALSE); g_return_val_if_fail (ncols > 0, FALSE); - if (is_non_interactive && (num_colors != ncols)) + if (num_colors != ncols) { g_message (_("Invalid remap array was passed to remap function")); return FALSE; @@ -416,28 +409,6 @@ remap (gint32 image_ID, } -static gboolean -remap_swap (gint32 image_ID, - guchar *map, - guchar index1, - guchar index2) -{ - gint ncols; - guchar tmp; - - g_free (gimp_image_get_colormap (image_ID, &ncols)); - - g_return_val_if_fail (ncols > 0, FALSE); - g_return_val_if_fail (index1 < ncols, FALSE); - g_return_val_if_fail (index2 < ncols, FALSE); - - tmp = map[index1]; - map[index1] = map[index2]; - map[index2] = tmp; - - return TRUE; -} - enum { COLOR_INDEX, @@ -452,21 +423,15 @@ remap_dialog (gint32 image_ID, { GtkWidget *dialog; GtkWidget *vbox; + GtkWidget *label; GtkWidget *iconview; GtkListStore *store; - gboolean run; + GtkCellRenderer *renderer; + GtkTreeIter iter; guchar *cmap; gint ncols, i; - GtkTreeIter iter; - GtkCellRenderer *renderer; - GtkWidget *label; - PangoAttrList *pango_attr_list; - PangoAttribute *pango_attr; gboolean valid; - - cmap = gimp_image_get_colormap (image_ID, &ncols); - - g_return_val_if_fail (cmap != NULL, FALSE); + gboolean run; gimp_ui_init (PLUG_IN_BINARY, FALSE); @@ -496,22 +461,27 @@ remap_dialog (gint32 image_ID, gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC, -1); - gtk_container_add (GTK_CONTAINER (vbox), label); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); store = gtk_list_store_new (NUM_COLS, G_TYPE_INT, G_TYPE_STRING, GIMP_TYPE_RGB); + cmap = gimp_image_get_colormap (image_ID, &ncols); + for (i = 0; i < ncols; i++) { GimpRGB color; - gchar *text = g_strdup_printf ("%d", i); + gint index = map[i]; + gchar *text = g_strdup_printf ("%d", index); gimp_rgb_set_uchar (&color, - cmap[(i * 3)], cmap[(i * 3) + 1], cmap[(i * 3) + 2]); + cmap[index * 3], + cmap[index * 3 + 1], + cmap[index * 3 + 2]); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, - COLOR_INDEX, i, + COLOR_INDEX, index, COLOR_INDEX_TEXT, text, COLOR_RGB, &color, -1); @@ -519,6 +489,8 @@ remap_dialog (gint32 image_ID, g_free (text); } + g_free (cmap); + iconview = gtk_icon_view_new_with_model (GTK_TREE_MODEL (store)); g_object_unref (store); @@ -528,16 +500,20 @@ remap_dialog (gint32 image_ID, GTK_SELECTION_SINGLE); gtk_icon_view_set_orientation (GTK_ICON_VIEW (iconview), GTK_ORIENTATION_VERTICAL); - gtk_icon_view_set_columns (GTK_ICON_VIEW (iconview), 24); - gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (iconview), 1); - gtk_icon_view_set_column_spacing (GTK_ICON_VIEW (iconview), 1); + gtk_icon_view_set_columns (GTK_ICON_VIEW (iconview), 16); + gtk_icon_view_set_row_spacing (GTK_ICON_VIEW (iconview), 0); + gtk_icon_view_set_column_spacing (GTK_ICON_VIEW (iconview), 0); gtk_icon_view_set_reorderable (GTK_ICON_VIEW (iconview), TRUE); renderer = gimp_cell_renderer_color_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (iconview), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (iconview), renderer, - "color", COLOR_RGB, - NULL); + "color", COLOR_RGB, + NULL); + + g_object_set (renderer, + "width", 24, + NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (iconview), renderer, TRUE); @@ -545,26 +521,16 @@ remap_dialog (gint32 image_ID, "text", COLOR_INDEX_TEXT, NULL); - pango_attr_list = pango_attr_list_new (); - - pango_attr = pango_attr_size_new (5000); - pango_attr->start_index = 0; - pango_attr->end_index = -1; - pango_attr_list_insert (pango_attr_list, pango_attr); - g_object_set (renderer, - "attributes", pango_attr_list, - "xalign", 0.5, + "size-points", 6.0, + "xalign", 0.5, + "ypad", 0, NULL); - pango_attr_list_unref (pango_attr_list); - gtk_widget_show_all (dialog); run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); - i = 0; for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter); @@ -573,15 +539,13 @@ remap_dialog (gint32 image_ID, { gint index; - gtk_tree_model_get (GTK_TREE_MODEL (store), - &iter, COLOR_INDEX, &index, -1); + gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, + COLOR_INDEX, &index, + -1); map[i++] = index; } gtk_widget_destroy (dialog); - g_free (cmap); - return run; } -