From 852a4dbb5092059fc6c6bde362e0b39fd9e561f2 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 25 Sep 2007 12:39:41 +0000 Subject: [PATCH] Fix bug when using Navigate backwards after using the keyboard to set the cursor position on the current word. Add symbols_goto_tag(). Replace navqueue_append() with navqueue_goto_line(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1900 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 ++++++++++ src/callbacks.c | 39 ++++++--------------------------------- src/keybindings.c | 7 +++---- src/navqueue.c | 13 ++++++------- src/navqueue.h | 5 +---- src/symbols.c | 32 +++++++++++++++++++++++++++++++- src/symbols.h | 4 ++-- src/treeviews.c | 3 +-- 8 files changed, 60 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28569db3c..3b8056318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-09-25 Nick Treleaven + + * src/keybindings.c, src/navqueue.c, src/navqueue.h, src/treeviews.c, + src/callbacks.c, src/symbols.c, src/symbols.h: + Fix bug when using Navigate backwards after using the keyboard to + set the cursor position on the current word. + Add symbols_goto_tag(). + Replace navqueue_append() with navqueue_goto_line(). + + 2007-09-24 Nick Treleaven * src/keybindings.c, src/editor.c, src/editor.h: diff --git a/src/callbacks.c b/src/callbacks.c index b847760f0..79d119245 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1054,41 +1054,14 @@ void on_goto_tag_activate (GtkMenuItem *menuitem, gpointer user_data) { - const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t; - gint type; - TMTag *tmtag; + gboolean definition = (menuitem == + GTK_MENU_ITEM(lookup_widget(app->popup_menu, "goto_tag_definition1"))); + document *doc = document_get_current(); - // goto tag definition: all except prototypes / forward declarations / externs - if (menuitem == GTK_MENU_ITEM(lookup_widget(app->popup_menu, "goto_tag_definition1"))) - type = tm_tag_max_t - forward_types; - else - type = forward_types; + g_return_if_fail(doc); - tmtag = symbols_find_in_workspace(editor_info.current_word, type); - if (tmtag != NULL) - { - gint old_idx = document_get_cur_idx(); // get idx before switching the file - - if (utils_goto_file_line( - tmtag->atts.entry.file->work_object.file_name, - TRUE, tmtag->atts.entry.line)) - { - // first add old file as old position - if (doc_list[old_idx].tm_file) - navqueue_new_position(doc_list[old_idx].tm_file->file_name, - sci_get_line_from_position(doc_list[old_idx].sci, editor_info.click_pos) + 1); - - navqueue_new_position(tmtag->atts.entry.file->work_object.file_name, - tmtag->atts.entry.line); - return; - } - } - // if we are here, there was no match and we are beeping ;-) - utils_beep(); - if (type == forward_types) - ui_set_statusbar(_("Forward declaration \"%s\" not found."), editor_info.current_word); - else - ui_set_statusbar(_("Definition of \"%s\" not found."), editor_info.current_word); + sci_set_current_position(doc->sci, editor_info.click_pos, FALSE); + symbols_goto_tag(editor_info.current_word, definition); } diff --git a/src/keybindings.c b/src/keybindings.c index 8cc7247f9..ba7128d2b 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -42,6 +42,7 @@ #include "build.h" #include "tools.h" #include "navqueue.h" +#include "symbols.h" const gboolean swap_alt_tab_order = FALSE; @@ -942,12 +943,10 @@ static void cb_func_current_word(guint key_id) on_find_usage1_activate(NULL, NULL); break; case GEANY_KEYS_POPUP_GOTOTAGDEFINITION: - on_goto_tag_activate(GTK_MENU_ITEM(lookup_widget(app->popup_menu, - "goto_tag_definition1")), NULL); + symbols_goto_tag(editor_info.current_word, TRUE); break; case GEANY_KEYS_POPUP_GOTOTAGDECLARATION: - on_goto_tag_activate(GTK_MENU_ITEM(lookup_widget(app->popup_menu, - "goto_tag_declaration1")), NULL); + symbols_goto_tag(editor_info.current_word, FALSE); break; case GEANY_KEYS_POPUP_CONTEXTACTION: on_context_action1_activate(GTK_MENU_ITEM(lookup_widget(app->popup_menu, diff --git a/src/navqueue.c b/src/navqueue.c index 09629196f..15114ec75 100644 --- a/src/navqueue.c +++ b/src/navqueue.c @@ -106,7 +106,7 @@ queue_pos_matches(guint queue_pos, const gchar *fname, gint line) } -void navqueue_new_position(gchar *tm_filename, gint line) +static void add_new_position(gchar *tm_filename, gint line) { filepos *npos; guint i; @@ -135,12 +135,13 @@ void navqueue_new_position(gchar *tm_filename, gint line) /* Adds the current document position to the queue before adding the new position. * line is counted with 1 as the first line, not 0. */ -gboolean navqueue_append(gint new_idx, gint line) +gboolean navqueue_goto_line(gint new_idx, gint line) { gint old_idx = document_get_cur_idx(); g_return_val_if_fail(DOC_IDX_VALID(old_idx), FALSE); g_return_val_if_fail(DOC_IDX_VALID(new_idx), FALSE); + g_return_val_if_fail(doc_list[new_idx].tm_file, FALSE); g_return_val_if_fail(line >= 1, FALSE); // first add old file as old position @@ -148,13 +149,11 @@ gboolean navqueue_append(gint new_idx, gint line) { gint cur_line = sci_get_current_line(doc_list[old_idx].sci, -1); - navqueue_new_position(doc_list[old_idx].tm_file->file_name, cur_line + 1); + add_new_position(doc_list[old_idx].tm_file->file_name, cur_line + 1); } - g_return_val_if_fail(doc_list[new_idx].tm_file, FALSE); - - navqueue_new_position(doc_list[new_idx].tm_file->file_name, line); - return TRUE; + add_new_position(doc_list[new_idx].tm_file->file_name, line); + return utils_goto_line(new_idx, line); } diff --git a/src/navqueue.h b/src/navqueue.h index e693fac16..cf2fb1198 100644 --- a/src/navqueue.h +++ b/src/navqueue.h @@ -30,10 +30,7 @@ void navqueue_init(); void navqueue_free(); -void navqueue_new_position(gchar *tm_filename, gint line); - -gboolean navqueue_append(gint new_idx, gint line); - +gboolean navqueue_goto_line(gint new_idx, gint line); void navqueue_go_back(); diff --git a/src/symbols.c b/src/symbols.c index 97cfdfecd..5838cab3b 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -43,6 +43,8 @@ #include "msgwindow.h" #include "treeviews.h" #include "main.h" +#include "navqueue.h" +#include "ui_utils.h" const guint TM_GLOBAL_TYPE_MASK = @@ -255,7 +257,7 @@ symbols_find_tm_tag(const GPtrArray *tags, const gchar *tag_name) } -TMTag *symbols_find_in_workspace(const gchar *tag_name, gint type) +static TMTag *find_workspace_tag(const gchar *tag_name, gint type) { guint j; const GPtrArray *tags; @@ -1035,3 +1037,31 @@ static void load_user_tags(filetype_id ft_id) } +gboolean symbols_goto_tag(const gchar *name, gboolean definition) +{ + const gint forward_types = tm_tag_prototype_t | tm_tag_externvar_t; + gint type; + TMTag *tmtag; + + // goto tag definition: all except prototypes / forward declarations / externs + type = (definition) ? tm_tag_max_t - forward_types : forward_types; + + tmtag = find_workspace_tag(name, type); + if (tmtag != NULL) + { + gint new_idx = document_find_by_filename( + tmtag->atts.entry.file->work_object.file_name, TRUE); + + if (navqueue_goto_line(new_idx, tmtag->atts.entry.line)) + return TRUE; + } + // if we are here, there was no match and we are beeping ;-) + utils_beep(); + if (type == forward_types) + ui_set_statusbar(_("Forward declaration \"%s\" not found."), name); + else + ui_set_statusbar(_("Definition of \"%s\" not found."), name); + return FALSE; +} + + diff --git a/src/symbols.h b/src/symbols.h index 7a7a9e5cf..670a76487 100644 --- a/src/symbols.h +++ b/src/symbols.h @@ -38,8 +38,6 @@ const GList *symbols_get_tag_list(gint idx, guint tag_types); GString *symbols_get_macro_list(); -TMTag *symbols_find_in_workspace(const gchar *tag_name, gint type); - const gchar **symbols_get_html_entities(); void symbols_finalize(); @@ -50,4 +48,6 @@ gint symbols_generate_global_tags(gint argc, gchar **argv); void symbols_show_load_tags_dialog(); +gboolean symbols_goto_tag(const gchar *name, gboolean definition); + #endif diff --git a/src/treeviews.c b/src/treeviews.c index 90d3faa44..de03e5481 100644 --- a/src/treeviews.c +++ b/src/treeviews.c @@ -544,8 +544,7 @@ static gboolean on_taglist_tree_selection_changed(GtkTreeSelection *selection) { gint idx = document_get_cur_idx(); - navqueue_append(idx, line); - utils_goto_line(idx, line); + navqueue_goto_line(idx, line); } } return FALSE;