Commit 9252db58 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Fixed File->Revert, which was completely broken before:

2003-05-17  Michael Natterer  <mitch@gimp.org>

	Fixed File->Revert, which was completely broken before:

	* app/gui/file-commands.c (file_revert_confirm_callback): set the
	new image on all GimpContexts which had the old image set.  Unref
	the new image after the displays are reconnected.

	Added some paranoia code for similar future situations (the
	functions below were not broken, but affected by the above bug):

	* app/display/gimpdisplay-handlers.c (gimp_display_disconnect):
	set gdisp->gimage to NULL before unrefing the image.

	* app/widgets/gimpimagedock.c (gimp_image_dock_image_changed):
	unref the gimage pointer returned by g_object_get() only if it is
	non-NULL. Cleanup.
parent 00645531
2003-05-17 Michael Natterer <mitch@gimp.org>
Fixed File->Revert, which was completely broken before:
* app/gui/file-commands.c (file_revert_confirm_callback): set the
new image on all GimpContexts which had the old image set. Unref
the new image after the displays are reconnected.
Added some paranoia code for similar future situations (the
functions below were not broken, but affected by the above bug):
* app/display/gimpdisplay-handlers.c (gimp_display_disconnect):
set gdisp->gimage to NULL before unrefing the image.
* app/widgets/gimpimagedock.c (gimp_image_dock_image_changed):
unref the gimage pointer returned by g_object_get() only if it is
non-NULL. Cleanup.
2003-05-17 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage.c (gimp_image_set_filename): treat the empty
......@@ -426,30 +426,48 @@ file_revert_confirm_callback (GtkWidget *widget,
if (revert)
{
Gimp *gimp;
GimpImage *new_gimage;
const gchar *uri;
GimpPDBStatusType status;
GError *error = NULL;
gimp = old_gimage->gimp;
uri = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (old_gimage->gimp,
uri,
uri,
NULL,
new_gimage = file_open_image (gimp, uri, uri, NULL,
GIMP_RUN_INTERACTIVE,
&status,
&error);
&status, &error);
if (new_gimage)
{
gimp_image_undo_free (new_gimage);
GList *contexts = NULL;
GList *list;
gimp_displays_reconnect (old_gimage->gimp, old_gimage, new_gimage);
/* remember which contexts refer to old_gimage */
for (list = gimp->context_list; list; list = g_list_next (list))
{
GimpContext *context = list->data;
gimp_image_clean_all (new_gimage);
if (gimp_context_get_image (context) == old_gimage)
contexts = g_list_prepend (contexts, list->data);
}
gimp_image_undo_free (new_gimage);
gimp_displays_reconnect (gimp, old_gimage, new_gimage);
gimp_image_clean_all (new_gimage);
gimp_image_flush (new_gimage);
/* set the new_gimage 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_gimage);
g_list_free (contexts);
/* the displays own the image now */
g_object_unref (new_gimage);
}
else if (status != GIMP_PDB_CANCEL)
{
......
......@@ -93,6 +93,8 @@ gimp_display_connect (GimpDisplay *gdisp,
void
gimp_display_disconnect (GimpDisplay *gdisp)
{
GimpImage *gimage;
g_return_if_fail (GIMP_IS_DISPLAY (gdisp));
g_return_if_fail (GIMP_IS_IMAGE (gdisp->gimage));
......@@ -119,8 +121,14 @@ gimp_display_disconnect (GimpDisplay *gdisp)
G_GNUC_FUNCTION, G_OBJECT (gdisp->gimage)->ref_count);
#endif
g_object_unref (gdisp->gimage);
/* set gdisp->gimage to NULL before unrefing because there may be code
* that listenes for image removals and then iterates the display list
* to find a valid display.
*/
gimage = gdisp->gimage;
gdisp->gimage = NULL;
g_object_unref (gimage);
}
......
......@@ -426,30 +426,48 @@ file_revert_confirm_callback (GtkWidget *widget,
if (revert)
{
Gimp *gimp;
GimpImage *new_gimage;
const gchar *uri;
GimpPDBStatusType status;
GError *error = NULL;
gimp = old_gimage->gimp;
uri = gimp_object_get_name (GIMP_OBJECT (old_gimage));
new_gimage = file_open_image (old_gimage->gimp,
uri,
uri,
NULL,
new_gimage = file_open_image (gimp, uri, uri, NULL,
GIMP_RUN_INTERACTIVE,
&status,
&error);
&status, &error);
if (new_gimage)
{
gimp_image_undo_free (new_gimage);
GList *contexts = NULL;
GList *list;
gimp_displays_reconnect (old_gimage->gimp, old_gimage, new_gimage);
/* remember which contexts refer to old_gimage */
for (list = gimp->context_list; list; list = g_list_next (list))
{
GimpContext *context = list->data;
gimp_image_clean_all (new_gimage);
if (gimp_context_get_image (context) == old_gimage)
contexts = g_list_prepend (contexts, list->data);
}
gimp_image_undo_free (new_gimage);
gimp_displays_reconnect (gimp, old_gimage, new_gimage);
gimp_image_clean_all (new_gimage);
gimp_image_flush (new_gimage);
/* set the new_gimage 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_gimage);
g_list_free (contexts);
/* the displays own the image now */
g_object_unref (new_gimage);
}
else if (status != GIMP_PDB_CANCEL)
{
......
......@@ -477,7 +477,8 @@ gimp_image_dock_image_changed (GimpContext *context,
image_dock = GIMP_IMAGE_DOCK (dock);
if (! gimage && image_dock->image_container->num_children > 0)
if (gimage == NULL &&
gimp_container_num_children (image_dock->image_container) > 0)
{
gimage = GIMP_IMAGE (gimp_container_get_child_by_index (image_dock->image_container, 0));
......@@ -494,22 +495,26 @@ gimp_image_dock_image_changed (GimpContext *context,
g_signal_stop_emission_by_name (context, "image_changed");
}
}
else if (image_dock->display_container->num_children > 0)
else if (gimage != NULL &&
gimp_container_num_children (image_dock->display_container) > 0)
{
GimpObject *gdisp;
GimpImage *gdisp_gimage;
gboolean find_display = TRUE;
gdisp = gimp_context_get_display (context);
if (gdisp)
{
GimpImage *gdisp_gimage;
g_object_get (gdisp, "image", &gdisp_gimage, NULL);
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
find_display = FALSE;
if (gdisp_gimage)
{
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
find_display = FALSE;
}
}
if (find_display)
......@@ -520,24 +525,28 @@ gimp_image_dock_image_changed (GimpContext *context,
list;
list = g_list_next (list))
{
GimpImage *gdisp_gimage;
gdisp = GIMP_OBJECT (list->data);
g_object_get (gdisp, "image", &gdisp_gimage, NULL);
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
if (gdisp_gimage)
{
/* this invokes this function recursively but we don't enter
* the if(find_display) branch the second time
*/
gimp_context_set_display (context, gdisp);
/* don't stop signal emission here because the context's
* image was not changed by the recursive call
*/
break;
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
{
/* this invokes this function recursively but we
* don't enter the if(find_display) branch the
* second time
*/
gimp_context_set_display (context, gdisp);
/* don't stop signal emission here because the
* context's image was not changed by the
* recursive call
*/
break;
}
}
}
}
......@@ -557,10 +566,12 @@ gimp_image_dock_auto_clicked (GtkWidget *widget,
if (image_dock->auto_follow_active)
{
if (gimp_context_get_display (dock->dialog_factory->context))
gimp_context_copy_property (dock->dialog_factory->context, dock->context,
gimp_context_copy_property (dock->dialog_factory->context,
dock->context,
GIMP_CONTEXT_PROP_DISPLAY);
else
gimp_context_copy_property (dock->dialog_factory->context, dock->context,
gimp_context_copy_property (dock->dialog_factory->context,
dock->context,
GIMP_CONTEXT_PROP_IMAGE);
}
}
......@@ -477,7 +477,8 @@ gimp_image_dock_image_changed (GimpContext *context,
image_dock = GIMP_IMAGE_DOCK (dock);
if (! gimage && image_dock->image_container->num_children > 0)
if (gimage == NULL &&
gimp_container_num_children (image_dock->image_container) > 0)
{
gimage = GIMP_IMAGE (gimp_container_get_child_by_index (image_dock->image_container, 0));
......@@ -494,22 +495,26 @@ gimp_image_dock_image_changed (GimpContext *context,
g_signal_stop_emission_by_name (context, "image_changed");
}
}
else if (image_dock->display_container->num_children > 0)
else if (gimage != NULL &&
gimp_container_num_children (image_dock->display_container) > 0)
{
GimpObject *gdisp;
GimpImage *gdisp_gimage;
gboolean find_display = TRUE;
gdisp = gimp_context_get_display (context);
if (gdisp)
{
GimpImage *gdisp_gimage;
g_object_get (gdisp, "image", &gdisp_gimage, NULL);
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
find_display = FALSE;
if (gdisp_gimage)
{
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
find_display = FALSE;
}
}
if (find_display)
......@@ -520,24 +525,28 @@ gimp_image_dock_image_changed (GimpContext *context,
list;
list = g_list_next (list))
{
GimpImage *gdisp_gimage;
gdisp = GIMP_OBJECT (list->data);
g_object_get (gdisp, "image", &gdisp_gimage, NULL);
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
if (gdisp_gimage)
{
/* this invokes this function recursively but we don't enter
* the if(find_display) branch the second time
*/
gimp_context_set_display (context, gdisp);
/* don't stop signal emission here because the context's
* image was not changed by the recursive call
*/
break;
g_object_unref (gdisp_gimage);
if (gdisp_gimage == gimage)
{
/* this invokes this function recursively but we
* don't enter the if(find_display) branch the
* second time
*/
gimp_context_set_display (context, gdisp);
/* don't stop signal emission here because the
* context's image was not changed by the
* recursive call
*/
break;
}
}
}
}
......@@ -557,10 +566,12 @@ gimp_image_dock_auto_clicked (GtkWidget *widget,
if (image_dock->auto_follow_active)
{
if (gimp_context_get_display (dock->dialog_factory->context))
gimp_context_copy_property (dock->dialog_factory->context, dock->context,
gimp_context_copy_property (dock->dialog_factory->context,
dock->context,
GIMP_CONTEXT_PROP_DISPLAY);
else
gimp_context_copy_property (dock->dialog_factory->context, dock->context,
gimp_context_copy_property (dock->dialog_factory->context,
dock->context,
GIMP_CONTEXT_PROP_IMAGE);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment