From 07fed71027585bb07a0952ca2c5e6ab2f90f8e68 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 23 Jul 2011 14:58:50 -0700 Subject: Fix issue with deleted guides and gtk warnings. (bzr r10496) --- src/sp-guide.cpp | 61 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 033e1db1f..0b1888340 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -475,40 +475,43 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) using Geom::X; using Geom::Y; - SPNamedView *namedview = sp_document_namedview(guide->document, NULL); - if (!namedview) { + char *descr = 0; + if ( !guide->document ) { // Guide has probably been deleted and no longer has an attached namedview. - return g_strdup_printf(_("Deleted")); - } - GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], - namedview->getDefaultMetric()); - GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], - namedview->getDefaultMetric()); - - gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); - gchar *descr; - - if ( are_near(guide->normal_to_line, component_vectors[X]) || - are_near(guide->normal_to_line, -component_vectors[X]) ) { - descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); - } else if ( are_near(guide->normal_to_line, component_vectors[Y]) || - are_near(guide->normal_to_line, -component_vectors[Y]) ) { - descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); + descr = g_strdup_printf(_("Deleted")); } else { - double const radians = guide->angle(); - double const degrees = Geom::rad_to_deg(radians); - int const degrees_int = (int) round(degrees); - descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"), - degrees_int, position_string_x->str, position_string_y->str); - } + SPNamedView *namedview = sp_document_namedview(guide->document, NULL); + + GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], + namedview->getDefaultMetric()); + GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], + namedview->getDefaultMetric()); - g_string_free(position_string_x, TRUE); - g_string_free(position_string_y, TRUE); + gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); - if (verbose) { - descr = g_strconcat(descr, shortcuts, NULL); + if ( are_near(guide->normal_to_line, component_vectors[X]) || + are_near(guide->normal_to_line, -component_vectors[X]) ) { + descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); + } else if ( are_near(guide->normal_to_line, component_vectors[Y]) || + are_near(guide->normal_to_line, -component_vectors[Y]) ) { + descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); + } else { + double const radians = guide->angle(); + double const degrees = Geom::rad_to_deg(radians); + int const degrees_int = (int) round(degrees); + descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"), + degrees_int, position_string_x->str, position_string_y->str); + } + + g_string_free(position_string_x, TRUE); + g_string_free(position_string_y, TRUE); + + if (verbose) { + descr = g_strconcat(descr, shortcuts, NULL); + } + g_free(shortcuts); } - g_free(shortcuts); + return descr; } -- cgit v1.2.3