app: avoid inadvertent calls to image actions on file -> revert

When reverting, we load a new image into the old image's existing
displays, and replace all references to the old image by the new image
in all GimpContext instances. We used to first update the displays and
then the contexts, which would shortly produce an inconsistent state
where the contexts were out of sync. When updating the displays with
the new image, we sometimes call menu update functions which would
then use that old image from the context when they should use the new
one, and thus triggered callbacks as if the user had activated a menu
(like image -> precision). To fix this, update the contexts before the
displays. It is also more logical to first update model objects and
then view objects.
This commit is contained in:
Michael Natterer 2012-12-09 22:44:33 +01:00
parent 4b85c9e2d8
commit b348678890
1 changed files with 12 additions and 8 deletions

View File

@ -204,7 +204,7 @@ gimp_displays_reconnect (Gimp *gimp,
g_return_if_fail (GIMP_IS_IMAGE (old));
g_return_if_fail (GIMP_IS_IMAGE (new));
/* remember which contexts refer to old_image */
/* check which contexts refer to old_image */
for (list = gimp->context_list; list; list = g_list_next (list))
{
GimpContext *context = list->data;
@ -213,6 +213,17 @@ gimp_displays_reconnect (Gimp *gimp,
contexts = g_list_prepend (contexts, list->data);
}
/* set the new_image on the remembered contexts (in reverse order,
* since older contexts are usually the parents of newer
* ones). Also, update the contexts before the displays, or we
* might run into menu update functions that would see an
* inconsistent state (display = new, context = old), and thus
* inadvertently call actions as if the user had selected a menu
* item.
*/
g_list_foreach (contexts, (GFunc) gimp_context_set_image, new);
g_list_free (contexts);
for (list = gimp_get_display_iter (gimp);
list;
list = g_list_next (list))
@ -222,13 +233,6 @@ gimp_displays_reconnect (Gimp *gimp,
if (gimp_display_get_image (display) == old)
gimp_display_set_image (display, new);
}
/* set the new_image on the remembered contexts (in reverse
* order, since older contexts are usually the parents of
* newer ones)
*/
g_list_foreach (contexts, (GFunc) gimp_context_set_image, new);
g_list_free (contexts);
}
gint