SF.net SVN: geany:[4489] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Wed Dec 9 16:57:05 UTC 2009


Revision: 4489
          http://geany.svn.sourceforge.net/geany/?rev=4489&view=rev
Author:   ntrel
Date:     2009-12-09 16:57:05 +0000 (Wed, 09 Dec 2009)

Log Message:
-----------
Refactor msgwin_goto_compiler_file_line().

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/msgwindow.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-12-09 13:28:37 UTC (rev 4488)
+++ trunk/ChangeLog	2009-12-09 16:57:05 UTC (rev 4489)
@@ -8,6 +8,8 @@
    the parsed filename doesn't exist. (This can happen when we receive
    build messages in the wrong order - after the 'Leaving directory'
    messages).
+ * src/msgwindow.c:
+   Refactor msgwin_goto_compiler_file_line().
 
 
 2009-12-08  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>

Modified: trunk/src/msgwindow.c
===================================================================
--- trunk/src/msgwindow.c	2009-12-09 13:28:37 UTC (rev 4488)
+++ trunk/src/msgwindow.c	2009-12-09 16:57:05 UTC (rev 4489)
@@ -575,13 +575,66 @@
 }
 
 
+static gboolean goto_compiler_file_line(const gchar *filename, gint line)
+{
+	if (!filename || line <= -1)
+		return FALSE;
+
+	/* If the path doesn't exist, try the current document.
+	 * This happens when we receive build messages in the wrong order - after the
+	 * 'Leaving directory' messages */
+	if (!g_file_test(filename, G_FILE_TEST_EXISTS))
+	{
+		gchar *cur_dir = utils_get_current_file_dir_utf8();
+		gchar *name;
+
+		if (cur_dir)
+		{
+			/* we let the user know we couldn't find the parsed filename from the message window */
+			setptr(cur_dir, utils_get_locale_from_utf8(cur_dir));
+			name = g_path_get_basename(filename);
+			setptr(name, g_build_path(G_DIR_SEPARATOR_S, cur_dir, name, NULL));
+			g_free(cur_dir);
+
+			if (g_file_test(name, G_FILE_TEST_EXISTS))
+			{
+				ui_set_statusbar(FALSE, _("Could not find file '%s' - trying the current document path."),
+					filename);
+				filename = name;
+			}
+			else
+				g_free(name);
+		}
+	}
+
+	{
+		gchar *utf8_filename = utils_get_utf8_from_locale(filename);
+		GeanyDocument *doc = document_find_by_filename(utf8_filename);
+		GeanyDocument *old_doc = document_get_current();
+
+		g_free(utf8_filename);
+
+		if (doc == NULL)	/* file not already open */
+			doc = document_open_file(filename, FALSE, NULL, NULL);
+
+		if (doc != NULL)
+		{
+			if (! doc->changed)	/* if modified, line may be wrong */
+				editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1);
+
+			return navqueue_goto_line(old_doc, doc, line);
+		}
+	}
+	return FALSE;
+}
+
+
 gboolean msgwin_goto_compiler_file_line()
 {
 	GtkTreeIter iter;
 	GtkTreeModel *model;
 	GtkTreeSelection *selection;
 	gchar *string;
-	gboolean ret = FALSE;
 	GdkColor *color;
 
 	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow.tree_compiler));
@@ -603,66 +656,21 @@
 			gint line;
 			gchar *filename, *dir;
 			GtkTreePath *path;
-			/* save the beginning of the string to use when free'ing it after it was stripped */
-			gchar *string_start = string;
+			gboolean ret;
 
 			path = gtk_tree_model_get_path(model, &iter);
 			find_prev_build_dir(path, model, &dir);
 			gtk_tree_path_free(path);
 			msgwin_parse_compiler_error_line(string, dir, &filename, &line);
+			g_free(string);
 			g_free(dir);
 
-			/* If the path doesn't exist, try the current document.
-			 * This happens when we receive build messages in the wrong order - after the
-			 * 'Leaving directory' messages */
-			if (!g_file_test(filename, G_FILE_TEST_EXISTS))
-			{
-				gchar *cur_dir = utils_get_current_file_dir_utf8();
-				gchar *name;
-
-				if (cur_dir)
-				{
-					/* we let the user know we couldn't find the parsed filename from the message window */
-					setptr(cur_dir, utils_get_locale_from_utf8(cur_dir));
-					name = g_path_get_basename(filename);
-					setptr(name, g_build_path(G_DIR_SEPARATOR_S, cur_dir, name, NULL));
-					g_free(cur_dir);
-
-					if (g_file_test(name, G_FILE_TEST_EXISTS))
-					{
-						ui_set_statusbar(FALSE, _("Could not find file '%s' - trying the current document path."),
-							filename);
-						filename = name;
-					}
-					else
-						g_free(name);
-				}
-			}
-
-			if (filename != NULL && line > -1)
-			{
-				gchar *utf8_filename = utils_get_utf8_from_locale(filename);
-				GeanyDocument *doc = document_find_by_filename(utf8_filename);
-				GeanyDocument *old_doc = document_get_current();
-
-				g_free(utf8_filename);
-
-				if (doc == NULL)	/* file not already open */
-					doc = document_open_file(filename, FALSE, NULL, NULL);
-
-				if (doc != NULL)
-				{
-					if (! doc->changed)	/* if modified, line may be wrong */
-						editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1);
-
-					ret = navqueue_goto_line(old_doc, doc, line);
-				}
-			}
+			ret = goto_compiler_file_line(filename, line);
 			g_free(filename);
-			g_free(string_start);
+			return ret;
 		}
 	}
-	return ret;
+	return FALSE;
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list