The attached patch allows you to open several images, assign keyboard shortcuts to them, and these shortcuts will persist, so that if you assigned '1','2','3' to the first, second, and third image, you could continue to switch between the first, second, and third opened image with 1, 2, and 3. Because of the caveat below, this is currently no better than associating the actions directly with display IDs, rather than associating the actions with indices into the list of displays. Caveats : *Currently implemented in a hackish way *Does not cope properly with closing images -- it breaks all the actions following and including the closed image.. So say you closed image #3, and you had already opened a 4th and 5th, the actions for 3, 4, and 5 would break. I'm unclear as to the exact cause of this. Does anyone here know?
Index: app/actions/windows-actions.c =================================================================== --- app/actions/windows-actions.c (revision 26398) +++ app/actions/windows-actions.c (working copy) @@ -171,21 +171,114 @@ windows_actions_image_notify (display, NULL, group); } +static int windows_display_get_index (GimpDisplay *display) +{ + gint index = gimp_container_get_child_index (display->gimp->displays, GIMP_OBJECT (display)); +/* gint nchildren = gimp_container_num_children (display->gimp->displays);*/ + return index; + +} + +static GimpDisplay *windows_display_get_nth (GimpContainer *displays, gint index) +{ + gint nchildren = gimp_container_num_children (displays); + + if (index >= nchildren) + return NULL; + + return GIMP_DISPLAY (gimp_container_get_child_by_index (displays, index)); +} + +static void windows_display_update_action (GimpActionGroup *group, GimpAction *action, GimpDisplay *display) +{ + const gchar *uri; + gchar *filename; + gchar *basename; + gchar *escaped; + gchar *title; + + if (display == NULL) + { + g_object_set (action, + "viewable", NULL); + return; + } + + uri = gimp_image_get_uri (display->image); + + filename = file_utils_uri_display_name (uri); + basename = file_utils_uri_display_basename (uri); + + escaped = gimp_escape_uline (basename); + g_free (basename); + + title = g_strdup_printf ("[%d] %s-%d.%d", GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action), "index")), + escaped, + gimp_image_get_ID (display->image), + display->instance); + g_free (escaped); + + g_object_set (action, + "label", title, + "tooltip", filename, + "viewable", display->image, + "context", gimp_get_user_context (group->gimp), + NULL); + + g_free (filename); + g_free (title); +} + + static void windows_actions_display_remove (GimpContainer *container, GimpDisplay *display, GimpActionGroup *group) { GtkAction *action; + gint index = windows_display_get_index (display); + gint num_children = gimp_container_num_children (display->gimp->displays); gchar *action_name = g_strdup_printf ("windows-display-%04d", - gimp_display_get_ID (display)); + num_children); + /* Step unu complete! (always remove the highest numbered action) */ + + /* find the relevant index by looping through the ActionGroup, finding the action with matching 'display' data-item */ + + if (index == -1) + { + /* nun index will always be -1 when a display is being removed -- by the time this function is reached, it is no longer in the active displays list */ + g_warning ("index == -1!"); + return; + } + g_warning ("WAdr:Index == %d Nch == %d", index, num_children); action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); + /* Step du: adjust all following actions when an action is removed. */ + if (action) - gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action); + { + gint i; + g_free (action_name); + + for (i = index; i < num_children-1; i++ ) + { + GimpAction *action2; + gint nextindex; + action_name = g_strdup_printf ("windows-display-%04d", i + 1); + /* XXX move all index/display object_data back one slot */ + action2 = (GimpAction *) gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); + nextindex = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action2), "index")); - g_free (action_name); + action_name = g_strdup_printf ("windows-display-%04d", i); + action2 = (GimpAction *) gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); + g_object_set_data (G_OBJECT (action2), "index", GINT_TO_POINTER (nextindex)); + windows_display_update_action (group, action2, + windows_display_get_nth (display->gimp->displays, MIN(i, num_children - 1))); + /* FIX the above -- and update_action should show [indices] rather than display ID */ + } + gtk_action_group_remove_action (GTK_ACTION_GROUP (group), action); + } } static void @@ -196,15 +289,18 @@ if (display->image) { GtkAction *action; + gint index = gimp_container_get_child_index (display->gimp->displays, GIMP_OBJECT (display)); gchar *action_name = g_strdup_printf ("windows-display-%04d", - gimp_display_get_ID (display)); + index + 1); + g_warning ("WAin: Index == %d", index); action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); if (! action) { GimpActionEntry entry; + g_warning ("WAin: action %s not found", action_name); entry.name = action_name; entry.stock_id = GIMP_STOCK_IMAGE; @@ -219,40 +315,15 @@ action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name); - g_object_set_data (G_OBJECT (action), "display", display); + if (! action) + g_warning ("WAin: action %s STILL! not found", action_name); + + g_object_set_data (G_OBJECT (action), "display", display->gimp); + g_object_set_data (G_OBJECT (action), "index", GINT_TO_POINTER (index)); } - { - const gchar *uri; - gchar *filename; - gchar *basename; - gchar *escaped; - gchar *title; + windows_display_update_action (group, (GimpAction *) (action), display); - uri = gimp_image_get_uri (display->image); - - filename = file_utils_uri_display_name (uri); - basename = file_utils_uri_display_basename (uri); - - escaped = gimp_escape_uline (basename); - g_free (basename); - - title = g_strdup_printf ("%s-%d.%d", escaped, - gimp_image_get_ID (display->image), - display->instance); - g_free (escaped); - - g_object_set (action, - "label", title, - "tooltip", filename, - "viewable", display->image, - "context", gimp_get_user_context (group->gimp), - NULL); - - g_free (filename); - g_free (title); - } - g_free (action_name); } else Index: app/actions/windows-commands.c =================================================================== --- app/actions/windows-commands.c (revision 26398) +++ app/actions/windows-commands.c (working copy) @@ -25,6 +25,7 @@ #include "actions-types.h" #include "core/gimpcontainer.h" +#include "core/gimp.h" #include "widgets/gimpdialogfactory.h" #include "widgets/gimpsessioninfo.h" @@ -49,8 +50,15 @@ windows_show_display_cmd_callback (GtkAction *action, gpointer data) { + gint index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (action), "index")); GimpDisplay *display = g_object_get_data (G_OBJECT (action), "display"); + gint nchildren = gimp_container_num_children (display->gimp->displays); + if (index >= nchildren) + return; + + display = GIMP_DISPLAY (gimp_container_get_child_by_index (display->gimp->displays, index)); + gtk_window_present (GTK_WINDOW (display->shell)); }
_______________________________________________ Gimp-developer mailing list Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer