Plugins may need to open a file from the message window without
specifying the line number (e.g. gproject has the feature "find project
file"). In addition to the original behaviour this patch makes it possible
to open files when the message is of the form

filename(:[whatever])*

so for instance

/home/techet/geany/foo.c
/home/techet/geany/foo.c: this the file you were searching for

are both valid and the file is opened when the message is clicked.

Signed-off-by: Jiří Techet <[email protected]>
---
 src/msgwindow.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/src/msgwindow.c b/src/msgwindow.c
index 20a83c0..3e7d002 100644
--- a/src/msgwindow.c
+++ b/src/msgwindow.c
@@ -70,6 +70,7 @@ static void prepare_status_tree_view(void);
 static void prepare_compiler_tree_view(void);
 static GtkWidget *create_message_popup_menu(gint type);
 static void msgwin_parse_grep_line(const gchar *string, gchar **filename, gint *line);
+static void msgwin_parse_filename_line(gchar *string, gchar **filename);
 static gboolean on_msgwin_button_press_event(GtkWidget *widget, GdkEventButton *event,
 																			gpointer user_data);
 static void on_scribble_populate(GtkTextView *textview, GtkMenu *arg1, gpointer user_data);
@@ -1038,6 +1039,19 @@ gboolean msgwin_goto_messages_file_line(guint keyval)
 						gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
 				}
 			}
+			else
+			{
+				/* try to use the string as a file name without line number */
+				g_free(filename);
+				msgwin_parse_filename_line(string, &filename);
+
+				if (g_file_test(filename, G_FILE_TEST_EXISTS))
+				{
+					doc = document_open_file(filename, FALSE, NULL, NULL);
+					if (doc != NULL && ui_is_keyval_enter_or_return(keyval))
+						gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
+				}
+			}
 			g_free(filename);
 		}
 		g_free(string);
@@ -1076,6 +1090,25 @@ static void msgwin_parse_grep_line(const gchar *string, gchar **filename, gint *
 }
 
 
+static void msgwin_parse_filename_line(gchar *string, gchar **filename)
+{
+	gchar **fields;
+
+	*filename = NULL;
+
+	g_return_if_fail(string != NULL);
+
+	fields = g_strsplit_set(string, ":", -1);
+	if (fields[0])
+		*filename = g_strdup(fields[0]);
+
+	if (msgwindow.messages_dir != NULL)
+		make_absolute(filename, msgwindow.messages_dir);
+
+	g_strfreev(fields);
+}
+
+
 static gboolean on_msgwin_button_press_event(GtkWidget *widget, GdkEventButton *event,
 											 gpointer user_data)
 {
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to