2 * msgwindow.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2010 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2010 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Message window functions (status, compiler, messages windows).
26 * Also compiler error message parsing and grep file and line parsing.
34 #include "callbacks.h"
38 #include "filetypes.h"
44 #include "msgwindow.h"
45 #include "keybindings.h"
51 #include <gdk/gdkkeysyms.h>
54 /* used for parse_file_line */
57 const gchar
*string
; /* line data */
58 const gchar
*pattern
; /* pattern to split the error message into some fields */
59 guint min_fields
; /* used to detect errors after parsing */
60 guint line_idx
; /* idx of the field where the line is */
61 gint file_idx
; /* idx of the field where the filename is or -1 */
65 MessageWindow msgwindow
;
68 static void prepare_msg_tree_view(void);
69 static void prepare_status_tree_view(void);
70 static void prepare_compiler_tree_view(void);
71 static GtkWidget
*create_message_popup_menu(gint type
);
72 static void msgwin_parse_grep_line(const gchar
*string
, gchar
**filename
, gint
*line
);
73 static gboolean
on_msgwin_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
,
75 static void on_scribble_populate(GtkTextView
*textview
, GtkMenu
*arg1
, gpointer user_data
);
78 void msgwin_show_hide_tabs(void)
80 ui_widget_show_hide(gtk_widget_get_parent(msgwindow
.tree_status
), interface_prefs
.msgwin_status_visible
);
81 ui_widget_show_hide(gtk_widget_get_parent(msgwindow
.tree_compiler
), interface_prefs
.msgwin_compiler_visible
);
82 ui_widget_show_hide(gtk_widget_get_parent(msgwindow
.tree_msg
), interface_prefs
.msgwin_messages_visible
);
83 ui_widget_show_hide(gtk_widget_get_parent(msgwindow
.scribble
), interface_prefs
.msgwin_scribble_visible
);
87 void msgwin_init(void)
89 msgwindow
.notebook
= ui_lookup_widget(main_widgets
.window
, "notebook_info");
90 msgwindow
.tree_status
= ui_lookup_widget(main_widgets
.window
, "treeview3");
91 msgwindow
.tree_msg
= ui_lookup_widget(main_widgets
.window
, "treeview4");
92 msgwindow
.tree_compiler
= ui_lookup_widget(main_widgets
.window
, "treeview5");
93 msgwindow
.scribble
= ui_lookup_widget(main_widgets
.window
, "textview_scribble");
94 msgwindow
.find_in_files_dir
= NULL
;
96 prepare_status_tree_view();
97 prepare_msg_tree_view();
98 prepare_compiler_tree_view();
99 msgwindow
.popup_status_menu
= create_message_popup_menu(MSG_STATUS
);
100 msgwindow
.popup_msg_menu
= create_message_popup_menu(MSG_MESSAGE
);
101 msgwindow
.popup_compiler_menu
= create_message_popup_menu(MSG_COMPILER
);
103 ui_widget_modify_font_from_string(msgwindow
.scribble
, interface_prefs
.msgwin_font
);
104 g_signal_connect(msgwindow
.scribble
, "populate-popup", G_CALLBACK(on_scribble_populate
), NULL
);
108 void msgwin_finalize(void)
110 g_free(msgwindow
.find_in_files_dir
);
114 static gboolean
on_msgwin_key_press_event(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
116 if (ui_is_keyval_enter_or_return(event
->keyval
) || event
->keyval
== GDK_space
)
118 switch (GPOINTER_TO_INT(data
))
121 { /* single click in the compiler treeview */
122 msgwin_goto_compiler_file_line(event
->keyval
);
126 { /* single click in the message treeview (results of 'Find usage') */
127 msgwin_goto_messages_file_line(event
->keyval
);
136 /* does some preparing things to the status message list widget */
137 static void prepare_status_tree_view(void)
139 GtkCellRenderer
*renderer
;
140 GtkTreeViewColumn
*column
;
142 msgwindow
.store_status
= gtk_list_store_new(1, G_TYPE_STRING
);
143 gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow
.tree_status
), GTK_TREE_MODEL(msgwindow
.store_status
));
144 g_object_unref(msgwindow
.store_status
);
146 renderer
= gtk_cell_renderer_text_new();
147 column
= gtk_tree_view_column_new_with_attributes(_("Status messages"), renderer
, "text", 0, NULL
);
148 gtk_tree_view_append_column(GTK_TREE_VIEW(msgwindow
.tree_status
), column
);
150 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow
.tree_status
), FALSE
);
152 ui_widget_modify_font_from_string(msgwindow
.tree_status
, interface_prefs
.msgwin_font
);
154 g_signal_connect(msgwindow
.tree_status
, "button-press-event",
155 G_CALLBACK(on_msgwin_button_press_event
), GINT_TO_POINTER(MSG_STATUS
));
159 /* does some preparing things to the message list widget
160 * (currently used for showing results of 'Find usage') */
161 static void prepare_msg_tree_view(void)
163 GtkCellRenderer
*renderer
;
164 GtkTreeViewColumn
*column
;
165 GtkTreeSelection
*selection
;
167 /* line, doc, fg, str */
168 msgwindow
.store_msg
= gtk_list_store_new(4, G_TYPE_INT
, G_TYPE_POINTER
,
169 GDK_TYPE_COLOR
, G_TYPE_STRING
);
170 gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow
.tree_msg
), GTK_TREE_MODEL(msgwindow
.store_msg
));
171 g_object_unref(msgwindow
.store_msg
);
173 renderer
= gtk_cell_renderer_text_new();
174 column
= gtk_tree_view_column_new_with_attributes(NULL
, renderer
,
175 "foreground-gdk", 2, "text", 3, NULL
);
176 gtk_tree_view_append_column(GTK_TREE_VIEW(msgwindow
.tree_msg
), column
);
178 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow
.tree_msg
), FALSE
);
180 ui_widget_modify_font_from_string(msgwindow
.tree_msg
, interface_prefs
.msgwin_font
);
182 /* use button-release-event so the selection has changed
183 * (connect_after button-press-event doesn't work) */
184 g_signal_connect(msgwindow
.tree_msg
, "button-release-event",
185 G_CALLBACK(on_msgwin_button_press_event
), GINT_TO_POINTER(MSG_MESSAGE
));
186 g_signal_connect(msgwindow
.tree_msg
, "key-press-event",
187 G_CALLBACK(on_msgwin_key_press_event
), GINT_TO_POINTER(MSG_MESSAGE
));
189 /* selection handling */
190 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow
.tree_msg
));
191 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_SINGLE
);
192 /*g_signal_connect(selection, "changed",G_CALLBACK(on_msg_tree_selection_changed), NULL);*/
196 /* does some preparing things to the compiler list widget */
197 static void prepare_compiler_tree_view(void)
199 GtkCellRenderer
*renderer
;
200 GtkTreeViewColumn
*column
;
201 GtkTreeSelection
*selection
;
203 msgwindow
.store_compiler
= gtk_list_store_new(2, GDK_TYPE_COLOR
, G_TYPE_STRING
);
204 gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow
.tree_compiler
), GTK_TREE_MODEL(msgwindow
.store_compiler
));
205 g_object_unref(msgwindow
.store_compiler
);
207 renderer
= gtk_cell_renderer_text_new();
208 column
= gtk_tree_view_column_new_with_attributes(NULL
, renderer
, "foreground-gdk", 0, "text", 1, NULL
);
209 gtk_tree_view_append_column(GTK_TREE_VIEW(msgwindow
.tree_compiler
), column
);
211 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow
.tree_compiler
), FALSE
);
213 ui_widget_modify_font_from_string(msgwindow
.tree_compiler
, interface_prefs
.msgwin_font
);
215 /* use button-release-event so the selection has changed
216 * (connect_after button-press-event doesn't work) */
217 g_signal_connect(msgwindow
.tree_compiler
, "button-release-event",
218 G_CALLBACK(on_msgwin_button_press_event
), GINT_TO_POINTER(MSG_COMPILER
));
219 g_signal_connect(msgwindow
.tree_compiler
, "key-press-event",
220 G_CALLBACK(on_msgwin_key_press_event
), GINT_TO_POINTER(MSG_COMPILER
));
222 /* selection handling */
223 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow
.tree_compiler
));
224 gtk_tree_selection_set_mode(selection
, GTK_SELECTION_SINGLE
);
225 /*g_signal_connect(selection, "changed", G_CALLBACK(on_msg_tree_selection_changed), NULL);*/
229 static const GdkColor color_error
= {0, 65535, 0, 0};
231 static const GdkColor
*get_color(gint msg_color
)
233 static const GdkColor dark_red
= {0, 65535 / 2, 0, 0};
234 static const GdkColor blue
= {0, 0, 0, 0xD000}; /* not too bright ;-) */
238 case COLOR_RED
: return &color_error
;
239 case COLOR_DARK_RED
: return &dark_red
;
240 case COLOR_BLUE
: return &blue
;
241 default: return NULL
;
247 * Adds a new message in the compiler tab treeview in the messages window.
249 * @param msg_color A color to be used for the text. It must be an element of #MsgColors.
250 * @param format @c printf()-style format string.
251 * @param ... Arguments for the @c format string.
253 void msgwin_compiler_add(gint msg_color
, const gchar
*format
, ...)
258 va_start(args
, format
);
259 string
= g_strdup_vprintf(format
, args
);
261 msgwin_compiler_add_string(msg_color
, string
);
266 void msgwin_compiler_add_string(gint msg_color
, const gchar
*msg
)
270 const GdkColor
*color
= get_color(msg_color
);
272 gtk_list_store_append(msgwindow
.store_compiler
, &iter
);
273 gtk_list_store_set(msgwindow
.store_compiler
, &iter
, 0, color
, 1, msg
, -1);
275 if (ui_prefs
.msgwindow_visible
)
277 path
= gtk_tree_model_get_path(
278 gtk_tree_view_get_model(GTK_TREE_VIEW(msgwindow
.tree_compiler
)), &iter
);
279 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(msgwindow
.tree_compiler
), path
, NULL
, TRUE
, 0.5, 0.5);
280 gtk_tree_path_free(path
);
283 /* calling build_menu_update for every build message would be overkill, TODO really should call it once when all done */
284 gtk_widget_set_sensitive(build_get_menu_items(-1)->menu_item
[GBG_FIXED
][GBF_NEXT_ERROR
], TRUE
);
285 gtk_widget_set_sensitive(build_get_menu_items(-1)->menu_item
[GBG_FIXED
][GBF_PREV_ERROR
], TRUE
);
289 void msgwin_show_hide(gboolean show
)
291 ui_prefs
.msgwindow_visible
= show
;
292 ignore_callback
= TRUE
;
293 gtk_check_menu_item_set_active(
294 GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets
.window
, "menu_show_messages_window1")),
296 ignore_callback
= FALSE
;
297 ui_widget_show_hide(ui_lookup_widget(main_widgets
.window
, "scrolledwindow1"), show
);
298 /* set the input focus back to the editor */
299 keybindings_send_command(GEANY_KEY_GROUP_FOCUS
, GEANY_KEYS_FOCUS_EDITOR
);
304 * Adds a new message in the messages tab treeview in the messages window.
305 * If @a line and @a doc are set, clicking on this line jumps into the file which is specified
306 * by @a doc into the line specified with @a line.
308 * @param msg_color A color to be used for the text. It must be an element of #MsgColors.
309 * @param line The document's line where the message belongs to. Set to @c -1 to ignore.
310 * @param doc The document. Set to @c NULL to ignore.
311 * @param format @c printf()-style format string.
312 * @param ... Arguments for the @c format string.
316 void msgwin_msg_add(gint msg_color
, gint line
, GeanyDocument
*doc
, const gchar
*format
, ...)
321 va_start(args
, format
);
322 string
= g_strdup_vprintf(format
, args
);
325 msgwin_msg_add_string(msg_color
, line
, doc
, string
);
330 /* adds string to the msg treeview */
331 void msgwin_msg_add_string(gint msg_color
, gint line
, GeanyDocument
*doc
, const gchar
*string
)
334 const GdkColor
*color
= get_color(msg_color
);
338 if (! ui_prefs
.msgwindow_visible
) msgwin_show_hide(TRUE
);
340 /* work around a strange problem when adding very long lines(greater than 4000 bytes)
341 * cut the string to a maximum of 1024 bytes and discard the rest */
342 /* TODO: find the real cause for the display problem / if it is GtkTreeView file a bug report */
343 len
= strlen(string
);
345 tmp
= g_strndup(string
, 1024);
347 tmp
= g_strdup(string
);
349 gtk_list_store_append(msgwindow
.store_msg
, &iter
);
350 gtk_list_store_set(msgwindow
.store_msg
, &iter
, 0, line
, 1, doc
, 2, color
, 3, tmp
, -1);
357 * Logs a status message *without* setting the status bar.
358 * (Use ui_set_statusbar() to display text on the statusbar)
360 * @param format @c printf()-style format string.
361 * @param ... Arguments for the @c format string.
363 void msgwin_status_add(const gchar
*format
, ...)
367 gchar
*statusmsg
, *time_str
;
370 va_start(args
, format
);
371 string
= g_strdup_vprintf(format
, args
);
374 /* add a timestamp to status messages */
375 time_str
= utils_get_current_time_string();
376 statusmsg
= g_strconcat(time_str
, ": ", string
, NULL
);
380 /* add message to Status window */
381 gtk_list_store_append(msgwindow
.store_status
, &iter
);
382 gtk_list_store_set(msgwindow
.store_status
, &iter
, 0, statusmsg
, -1);
385 if (G_LIKELY(main_status
.main_window_realized
))
387 GtkTreePath
*path
= gtk_tree_model_get_path(gtk_tree_view_get_model(GTK_TREE_VIEW(msgwindow
.tree_status
)), &iter
);
389 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(msgwindow
.tree_status
), path
, NULL
, FALSE
, 0.0, 0.0);
390 if (prefs
.switch_to_status
)
391 gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow
.notebook
), MSG_STATUS
);
392 gtk_tree_path_free(path
);
398 on_message_treeview_clear_activate (GtkMenuItem
*menuitem
,
401 gint tabnum
= GPOINTER_TO_INT(user_data
);
403 msgwin_clear_tab(tabnum
);
408 on_compiler_treeview_copy_activate (GtkMenuItem
*menuitem
,
411 GtkWidget
*tv
= NULL
;
412 GtkTreeSelection
*selection
;
417 switch (GPOINTER_TO_INT(user_data
))
420 tv
= msgwindow
.tree_status
;
425 tv
= msgwindow
.tree_compiler
;
429 tv
= msgwindow
.tree_msg
;
433 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tv
));
435 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
))
439 gtk_tree_model_get(model
, &iter
, str_idx
, &string
, -1);
442 gtk_clipboard_set_text(gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE
)),
450 static void on_compiler_treeview_copy_all_activate(GtkMenuItem
*menuitem
, gpointer user_data
)
452 GtkListStore
*store
= msgwindow
.store_compiler
;
454 GString
*str
= g_string_new("");
458 switch (GPOINTER_TO_INT(user_data
))
461 store
= msgwindow
.store_status
;
470 store
= msgwindow
.store_msg
;
475 /* walk through the list and copy every line into a string */
476 valid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store
), &iter
);
481 gtk_tree_model_get(GTK_TREE_MODEL(store
), &iter
, str_idx
, &line
, -1);
484 g_string_append(str
, line
);
485 g_string_append_c(str
, '\n');
489 valid
= gtk_tree_model_iter_next(GTK_TREE_MODEL(store
), &iter
);
492 /* copy the string into the clipboard */
495 gtk_clipboard_set_text(
496 gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE
)),
500 g_string_free(str
, TRUE
);
505 on_hide_message_window (GtkMenuItem
*menuitem
,
508 msgwin_show_hide(FALSE
);
512 static GtkWidget
*create_message_popup_menu(gint type
)
514 GtkWidget
*message_popup_menu
, *clear
, *copy
, *image
;
516 message_popup_menu
= gtk_menu_new();
518 clear
= gtk_image_menu_item_new_from_stock("gtk-clear", NULL
);
519 gtk_widget_show(clear
);
520 gtk_container_add(GTK_CONTAINER(message_popup_menu
), clear
);
521 g_signal_connect(clear
, "activate",
522 G_CALLBACK(on_message_treeview_clear_activate
), GINT_TO_POINTER(type
));
524 copy
= gtk_image_menu_item_new_from_stock("gtk-copy", NULL
);
525 gtk_widget_show(copy
);
526 gtk_container_add(GTK_CONTAINER(message_popup_menu
), copy
);
527 g_signal_connect(copy
, "activate",
528 G_CALLBACK(on_compiler_treeview_copy_activate
), GINT_TO_POINTER(type
));
530 copy
= gtk_image_menu_item_new_with_mnemonic(_("Copy _All"));
531 gtk_widget_show(copy
);
532 gtk_container_add(GTK_CONTAINER(message_popup_menu
), copy
);
533 image
= gtk_image_new_from_stock("gtk-copy", GTK_ICON_SIZE_MENU
);
534 gtk_widget_show(image
);
535 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(copy
), image
);
536 g_signal_connect(copy
, "activate",
537 G_CALLBACK(on_compiler_treeview_copy_all_activate
), GINT_TO_POINTER(type
));
539 msgwin_menu_add_common_items(GTK_MENU(message_popup_menu
));
541 return message_popup_menu
;
545 static void on_scribble_populate(GtkTextView
*textview
, GtkMenu
*arg1
, gpointer user_data
)
547 msgwin_menu_add_common_items(arg1
);
551 /* Menu items that should be on all message window popup menus */
552 void msgwin_menu_add_common_items(GtkMenu
*menu
)
556 item
= gtk_separator_menu_item_new();
557 gtk_widget_show(item
);
558 gtk_container_add(GTK_CONTAINER(menu
), item
);
560 item
= gtk_menu_item_new_with_mnemonic(_("_Hide Message Window"));
561 gtk_widget_show(item
);
562 gtk_container_add(GTK_CONTAINER(menu
), item
);
563 g_signal_connect(item
, "activate", G_CALLBACK(on_hide_message_window
), NULL
);
567 /* look back up from the current path and find the directory we came from */
569 find_prev_build_dir(GtkTreePath
*cur
, GtkTreeModel
*model
, gchar
**prefix
)
574 while (gtk_tree_path_prev(cur
))
576 if (gtk_tree_model_get_iter(model
, &iter
, cur
))
579 gtk_tree_model_get(model
, &iter
, 1, &string
, -1);
580 if (string
!= NULL
&& build_parse_make_dir(string
, prefix
))
593 static gboolean
goto_compiler_file_line(const gchar
*filename
, gint line
, guint keyval
)
595 if (!filename
|| line
<= -1)
598 /* If the path doesn't exist, try the current document.
599 * This happens when we receive build messages in the wrong order - after the
600 * 'Leaving directory' messages */
601 if (!g_file_test(filename
, G_FILE_TEST_EXISTS
))
603 gchar
*cur_dir
= utils_get_current_file_dir_utf8();
608 /* we let the user know we couldn't find the parsed filename from the message window */
609 setptr(cur_dir
, utils_get_locale_from_utf8(cur_dir
));
610 name
= g_path_get_basename(filename
);
611 setptr(name
, g_build_path(G_DIR_SEPARATOR_S
, cur_dir
, name
, NULL
));
614 if (g_file_test(name
, G_FILE_TEST_EXISTS
))
616 ui_set_statusbar(FALSE
, _("Could not find file '%s' - trying the current document path."),
626 gchar
*utf8_filename
= utils_get_utf8_from_locale(filename
);
627 GeanyDocument
*doc
= document_find_by_filename(utf8_filename
);
628 GeanyDocument
*old_doc
= document_get_current();
630 g_free(utf8_filename
);
632 if (doc
== NULL
) /* file not already open */
633 doc
= document_open_file(filename
, FALSE
, NULL
, NULL
);
639 if (! doc
->changed
&& editor_prefs
.use_indicators
) /* if modified, line may be wrong */
640 editor_indicator_set_on_line(doc
->editor
, GEANY_INDICATOR_ERROR
, line
- 1);
642 ret
= navqueue_goto_line(old_doc
, doc
, line
);
643 if (ret
&& ui_is_keyval_enter_or_return(keyval
))
644 gtk_widget_grab_focus(GTK_WIDGET(doc
->editor
->sci
));
653 gboolean
msgwin_goto_compiler_file_line(guint keyval
)
657 GtkTreeSelection
*selection
;
661 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow
.tree_compiler
));
662 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
))
664 /* if the item is not coloured red, it's not an error line */
665 gtk_tree_model_get(model
, &iter
, 0, &color
, -1);
666 if (color
== NULL
|| ! gdk_color_equal(color
, &color_error
))
669 gdk_color_free(color
);
672 gdk_color_free(color
);
674 gtk_tree_model_get(model
, &iter
, 1, &string
, -1);
678 gchar
*filename
, *dir
;
682 path
= gtk_tree_model_get_path(model
, &iter
);
683 find_prev_build_dir(path
, model
, &dir
);
684 gtk_tree_path_free(path
);
685 msgwin_parse_compiler_error_line(string
, dir
, &filename
, &line
);
689 ret
= goto_compiler_file_line(filename
, line
, keyval
);
698 static void make_absolute(gchar
**filename
, const gchar
*dir
)
700 guint skip_dot_slash
= 0; /* number of characters to skip at the beginning of the filename */
702 if (*filename
== NULL
)
705 /* skip some characters at the beginning of the filename, at the moment only "./"
706 * can be extended if other "trash" is known */
707 if (strncmp(*filename
, "./", 2) == 0)
711 if (! utils_is_absolute_path(*filename
))
712 setptr(*filename
, g_strconcat(dir
, G_DIR_SEPARATOR_S
,
713 *filename
+ skip_dot_slash
, NULL
));
717 /* try to parse the file and line number where the error occured described in line
718 * and when something useful is found, it stores the line number in *line and the
719 * relevant file with the error in *filename.
720 * *line will be -1 if no error was found in string.
721 * *filename must be freed unless it is NULL. */
722 static void parse_file_line(ParseData
*data
, gchar
**filename
, gint
*line
)
730 g_return_if_fail(data
->string
!= NULL
);
732 fields
= g_strsplit_set(data
->string
, data
->pattern
, data
->min_fields
);
735 if (g_strv_length(fields
) < data
->min_fields
)
741 *line
= strtol(fields
[data
->line_idx
], &end
, 10);
743 /* if the line could not be read, line is 0 and an error occurred, so we leave */
744 if (fields
[data
->line_idx
] == end
)
750 /* let's stop here if there is no filename in the error message */
751 if (data
->file_idx
== -1)
753 /* we have no filename in the error message, so take the current one and hope it's correct */
754 GeanyDocument
*doc
= document_get_current();
756 *filename
= g_strdup(doc
->file_name
);
761 *filename
= g_strdup(fields
[data
->file_idx
]);
766 static void parse_compiler_error_line(const gchar
*string
,
767 gchar
**filename
, gint
*line
)
769 ParseData data
= {NULL
, NULL
, 0, 0, 0};
771 data
.string
= string
;
773 switch (build_info
.file_type_id
)
775 case GEANY_FILETYPES_PHP
:
777 /* Parse error: parse error, unexpected T_CASE in brace_bug.php on line 3
778 * Parse error: syntax error, unexpected T_LNUMBER, expecting T_FUNCTION in bob.php on line 16 */
779 gchar
*tmp
= strstr(string
, " in ");
792 data
.min_fields
= 11;
798 case GEANY_FILETYPES_PERL
:
800 /* syntax error at test.pl line 7, near "{ */
807 /* the error output of python and tcl equals */
808 case GEANY_FILETYPES_TCL
:
809 case GEANY_FILETYPES_PYTHON
:
811 /* File "HyperArch.py", line 37, in ?
812 * (file "clrdial.tcl" line 12) */
813 data
.pattern
= " \"";
819 case GEANY_FILETYPES_BASIC
:
820 case GEANY_FILETYPES_PASCAL
:
821 case GEANY_FILETYPES_CS
:
823 /* getdrive.bas(52) error 18: Syntax error in '? GetAllDrives'
824 * bandit.pas(149,3) Fatal: Syntax error, ";" expected but "ELSE" found */
831 case GEANY_FILETYPES_D
:
833 /* GNU D compiler front-end, gdc
834 * gantry.d:18: variable gantry.main.c reference to auto class must be auto
835 * warning - gantry.d:20: statement is not reachable
836 * Digital Mars dmd compiler
837 * warning - pi.d(118): implicit conversion of expression (digit) of type int ...
838 * gantry.d(18): variable gantry.main.c reference to auto class must be auto */
839 if (strncmp(string
, "warning - ", 10) == 0)
841 data
.pattern
= " (:";
855 case GEANY_FILETYPES_FERITE
:
857 /* Error: Parse Error: on line 5 in "/tmp/hello.fe"
858 * Error: Compile Error: on line 24, in /test/class.fe */
859 if (strncmp(string
, "Error: Compile Error", 20) == 0)
868 data
.pattern
= " \"";
869 data
.min_fields
= 10;
875 case GEANY_FILETYPES_HTML
:
877 /* line 78 column 7 - Warning: <table> missing '>' for end of tag */
884 /* All GNU gcc-like error messages */
885 case GEANY_FILETYPES_C
:
886 case GEANY_FILETYPES_CPP
:
887 case GEANY_FILETYPES_RUBY
:
888 case GEANY_FILETYPES_JAVA
:
889 /* only gcc is supported, I don't know any other C(++) compilers and their error messages
890 * empty.h:4: Warnung: type defaults to `int' in declaration of `foo'
891 * empty.c:21: error: conflicting types for `foo'
892 * Only parse file and line, so that linker errors will also work (with -g) */
893 case GEANY_FILETYPES_F77
:
894 case GEANY_FILETYPES_FORTRAN
:
895 case GEANY_FILETYPES_LATEX
:
896 /* ./kommtechnik_2b.tex:18: Emergency stop. */
897 case GEANY_FILETYPES_MAKE
: /* Assume makefile is building with gcc */
898 case GEANY_FILETYPES_NONE
:
899 default: /* The default is a GNU gcc type error */
901 if (build_info
.file_type_id
== GEANY_FILETYPES_JAVA
&&
902 strncmp(string
, "[javac]", 7) == 0)
905 * [javac] <Full Path to File + extension>:<line n°>: <error> */
912 /* don't accidently find libtool versions x:y:x and think it is a file name */
913 if (strstr(string
, "libtool --mode=link") == NULL
)
924 if (data
.pattern
!= NULL
)
925 parse_file_line(&data
, filename
, line
);
929 /* try to parse the file and line number where the error occured described in string
930 * and when something useful is found, it stores the line number in *line and the
931 * relevant file with the error in *filename.
932 * *line will be -1 if no error was found in string.
933 * *filename must be freed unless it is NULL. */
934 void msgwin_parse_compiler_error_line(const gchar
*string
, const gchar
*dir
,
935 gchar
**filename
, gint
*line
)
938 gchar
*trimmed_string
;
943 if (G_UNLIKELY(string
== NULL
))
947 dir
= build_info
.dir
;
948 g_return_if_fail(dir
!= NULL
);
950 trimmed_string
= g_strdup(string
);
951 g_strchug(trimmed_string
); /* remove possible leading whitespace */
953 ft
= filetypes
[build_info
.file_type_id
];
955 /* try parsing with a custom regex */
956 if (!filetypes_parse_error_message(ft
, trimmed_string
, filename
, line
))
958 /* fallback to default old-style parsing */
959 parse_compiler_error_line(trimmed_string
, filename
, line
);
961 make_absolute(filename
, dir
);
962 g_free(trimmed_string
);
966 gboolean
msgwin_goto_messages_file_line(guint keyval
)
970 GtkTreeSelection
*selection
;
971 gboolean ret
= FALSE
;
973 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow
.tree_msg
));
974 if (gtk_tree_selection_get_selected(selection
, &model
, &iter
))
979 GeanyDocument
*old_doc
= document_get_current();
981 gtk_tree_model_get(model
, &iter
, 0, &line
, 1, &doc
, 3, &string
, -1);
982 /* doc may have been closed, so check doc->index: */
983 if (line
>= 0 && DOC_VALID(doc
))
985 ret
= navqueue_goto_line(old_doc
, doc
, line
);
986 if (ret
&& ui_is_keyval_enter_or_return(keyval
))
987 gtk_widget_grab_focus(GTK_WIDGET(doc
->editor
->sci
));
989 else if (line
< 0 && string
!= NULL
)
992 msgwin_parse_grep_line(string
, &filename
, &line
);
993 if (filename
!= NULL
&& line
> -1)
995 /* use document_open_file to find an already open file, or open it in place */
996 doc
= document_open_file(filename
, FALSE
, NULL
, NULL
);
999 ret
= navqueue_goto_line(old_doc
, doc
, line
);
1000 if (ret
&& ui_is_keyval_enter_or_return(keyval
))
1001 gtk_widget_grab_focus(GTK_WIDGET(doc
->editor
->sci
));
1012 /* Try to parse the file and line number for string and when something useful is
1013 * found, store the line number in *line and the relevant file with the error in
1015 * *line will be -1 if no error was found in string.
1016 * *filename must be freed unless NULL. */
1017 static void msgwin_parse_grep_line(const gchar
*string
, gchar
**filename
, gint
*line
)
1024 if (string
== NULL
|| msgwindow
.find_in_files_dir
== NULL
)
1027 /* conflict:3:conflicting types for `foo' */
1028 data
.string
= string
;
1030 data
.min_fields
= 3;
1034 parse_file_line(&data
, filename
, line
);
1035 make_absolute(filename
, msgwindow
.find_in_files_dir
);
1039 static gboolean
on_msgwin_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
,
1042 /* user_data might be NULL, GPOINTER_TO_INT returns 0 if called with NULL */
1044 if (event
->button
== 1)
1046 switch (GPOINTER_TO_INT(user_data
))
1049 { /* single click in the compiler treeview */
1050 msgwin_goto_compiler_file_line(0);
1054 { /* single click in the message treeview (results of 'Find usage') */
1055 msgwin_goto_messages_file_line(0);
1061 if (event
->button
== 3)
1062 { /* popupmenu to hide or clear the active treeview */
1063 switch (GPOINTER_TO_INT(user_data
))
1067 gtk_menu_popup(GTK_MENU(msgwindow
.popup_status_menu
), NULL
, NULL
, NULL
, NULL
,
1068 event
->button
, event
->time
);
1073 gtk_menu_popup(GTK_MENU(msgwindow
.popup_msg_menu
), NULL
, NULL
, NULL
, NULL
,
1074 event
->button
, event
->time
);
1079 gtk_menu_popup(GTK_MENU(msgwindow
.popup_compiler_menu
), NULL
, NULL
, NULL
, NULL
,
1080 event
->button
, event
->time
);
1090 * Switches to the given notebook tab of the messages window and shows the messages window
1091 * if it was previously hidden and @a show is set to @c TRUE.
1093 * @param tabnum An index of a tab in the messages window. Valid values are all elements of
1094 * #MessageWindowTabNum.
1095 * @param show Whether to show the messages window at all if it was hidden before.
1099 void msgwin_switch_tab(gint tabnum
, gboolean show
)
1101 GtkWidget
*widget
= NULL
; /* widget to focus */
1105 case MSG_SCRATCH
: widget
= msgwindow
.scribble
; break;
1106 case MSG_COMPILER
: widget
= msgwindow
.tree_compiler
; break;
1107 case MSG_STATUS
: widget
= msgwindow
.tree_status
; break;
1108 case MSG_MESSAGE
: widget
= msgwindow
.tree_msg
; break;
1110 case MSG_VTE
: widget
= (vte_info
.have_vte
) ? vc
->vte
: NULL
; break;
1115 /* the msgwin must be visible before we switch to the VTE page so that
1116 * the font settings are applied on realization */
1118 msgwin_show_hide(TRUE
);
1119 gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow
.notebook
), tabnum
);
1121 gtk_widget_grab_focus(widget
);
1126 * Removes all messages from a tab specified by @a tabnum in the messages window.
1128 * @param tabnum An index of a tab in the messages window which should be cleared.
1129 * Valid values are @c MSG_STATUS, @c MSG_COMPILER and @c MSG_MESSAGE.
1133 void msgwin_clear_tab(gint tabnum
)
1135 GtkListStore
*store
= NULL
;
1140 store
= msgwindow
.store_msg
;
1144 gtk_list_store_clear(msgwindow
.store_compiler
);
1145 build_menu_update(NULL
); /* update next error items */
1148 case MSG_STATUS
: store
= msgwindow
.store_status
; break;
1153 gtk_list_store_clear(store
);