From e07a1a8387ec021cabd965ac4a7b1406369fa6c7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 17 Jun 2006 21:08:47 +0000 Subject: [PATCH] Add keybindings for Find Usage, Go to definition/declaration, based on the current cursor position. Also ensure null termination in utils_find_current_word git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@456 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 ++++--- src/keybindings.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ src/keybindings.h | 3 +++ src/utils.c | 2 +- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a904a792..0f1b5ad7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,9 +4,13 @@ doc/geany.docbook: Made Duplicate Line command duplicate selection if present. * src/highlighting.c: Fixed styling for unmatched braces. - * src/keybindings.c, src/keybindings.h, doc/geany.docbook: - Set default keybindings for switch page left/right; also group - toggle sidebar keybinding with toggle messages. + * src/keybindings.h, doc/geany.docbook: + Group toggle sidebar keybinding with toggle messages. + * src/keybindings.c: Set keyboard shortcuts for switching tab pages. + * src/keybindings.c, src/keybindings.h: + Add keybindings for Find Usage, Go to definition/declaration, + based on the current cursor position. + * src/utils.c: Ensure null termination in utils_find_current_word. 2006-06-16 Enrico Troeger diff --git a/src/keybindings.c b/src/keybindings.c index a08678ba7..0973f61ee 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -84,7 +84,11 @@ static void cb_func_edit_autocomplete(void); static void cb_func_edit_calltip(void); static void cb_func_edit_macrolist(void); static void cb_func_edit_suppresscompletion(void); +static void cb_func_popup_findusage(void); +static void cb_func_popup_gototagdefinition(void); +static void cb_func_popup_gototagdeclaration(void); +void keybindings_call_popup_item(int menuitemkey); void keybindings_add_accels(); @@ -139,6 +143,12 @@ void keybindings_init(void) keys[GEANY_KEYS_EDIT_CALLTIP] = fill(cb_func_edit_calltip, GDK_space, GDK_MOD1_MASK, "edit_calltip", _("Show calltip")); keys[GEANY_KEYS_EDIT_MACROLIST] = fill(cb_func_edit_macrolist, GDK_Return, GDK_CONTROL_MASK, "edit_macrolist", _("Show macro list")); keys[GEANY_KEYS_EDIT_SUPPRESSCOMPLETION] = fill(cb_func_edit_suppresscompletion, GDK_space, GDK_SHIFT_MASK, "edit_suppresscompletion", _("Suppress auto completion")); + keys[GEANY_KEYS_POPUP_FINDUSAGE] = fill(cb_func_popup_findusage, + 0, 0, "popup_findusage", _("Find Usage")); + keys[GEANY_KEYS_POPUP_GOTOTAGDEFINITION] = fill(cb_func_popup_gototagdefinition, + 0, 0, "popup_gototagdefinition", _("Go to tag definition")); + keys[GEANY_KEYS_POPUP_GOTOTAGDECLARATION] = fill(cb_func_popup_gototagdeclaration, + 0, 0, "popup_gototagdeclaration", _("Go to tag declaration")); // now load user defined keys if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_KEEP_COMMENTS, NULL)) @@ -170,6 +180,13 @@ void keybindings_init(void) "activate", accel_group, keys[(gkey)]->key, keys[(gkey)]->mods, \ GTK_ACCEL_VISIBLE) +#define GEANY_ADD_POPUP_ACCEL(gkey, wid) \ + if (keys[(gkey)]->key != 0) \ + gtk_widget_add_accelerator( \ + lookup_widget(app->popup_menu, G_STRINGIFY(wid)), \ + "activate", accel_group, keys[(gkey)]->key, keys[(gkey)]->mods, \ + GTK_ACCEL_VISIBLE) + void keybindings_add_accels() { GtkAccelGroup *accel_group = gtk_accel_group_new(); @@ -192,6 +209,10 @@ void keybindings_add_accels() GEANY_ADD_ACCEL(GEANY_KEYS_MENU_FOLDALL, menu_fold_all1); GEANY_ADD_ACCEL(GEANY_KEYS_MENU_UNFOLDALL, menu_unfold_all1); + GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_POPUP_FINDUSAGE, find_usage1); + GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_POPUP_GOTOTAGDEFINITION, goto_tag_definition1); + GEANY_ADD_POPUP_ACCEL(GEANY_KEYS_POPUP_GOTOTAGDECLARATION, goto_tag_declaration1); + // the build menu items are set if the build menus are created gtk_window_add_accel_group(GTK_WINDOW(app->window), accel_group); @@ -453,6 +474,54 @@ static void cb_func_reloadtaglist(void) document_update_tag_list(idx, TRUE); } + +static void cb_func_popup_findusage(void) +{ + keybindings_call_popup_item(GEANY_KEYS_POPUP_FINDUSAGE); +} + + +static void cb_func_popup_gototagdefinition(void) +{ + keybindings_call_popup_item(GEANY_KEYS_POPUP_GOTOTAGDEFINITION); +} + + +static void cb_func_popup_gototagdeclaration(void) +{ + keybindings_call_popup_item(GEANY_KEYS_POPUP_GOTOTAGDECLARATION); +} + + +void keybindings_call_popup_item(int menuitemkey) +{ + gint idx = document_get_cur_idx(); + gint pos = sci_get_current_position(doc_list[idx].sci); + gchar current_word[128]; + + utils_find_current_word(doc_list[idx].sci, pos, + current_word, sizeof current_word); + + if (*current_word == 0) + utils_beep(); + else + switch (menuitemkey) + { + case GEANY_KEYS_POPUP_FINDUSAGE: + 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); + break; + case GEANY_KEYS_POPUP_GOTOTAGDECLARATION: + on_goto_tag_activate(GTK_MENU_ITEM(lookup_widget(app->popup_menu, + "goto_tag_declaration1")), NULL); + break; + } +} + + static void cb_func_switch_editor(void) { gint idx = document_get_cur_idx(); diff --git a/src/keybindings.h b/src/keybindings.h index 8e56d2274..85d93ea32 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -82,6 +82,9 @@ enum GEANY_KEYS_EDIT_CALLTIP, GEANY_KEYS_EDIT_MACROLIST, GEANY_KEYS_EDIT_SUPPRESSCOMPLETION, + GEANY_KEYS_POPUP_FINDUSAGE, + GEANY_KEYS_POPUP_GOTOTAGDEFINITION, + GEANY_KEYS_POPUP_GOTOTAGDECLARATION, GEANY_MAX_KEYS }; diff --git a/src/utils.c b/src/utils.c index 66b5a4f32..94362522b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1066,7 +1066,7 @@ void utils_find_current_word(ScintillaObject *sci, gint pos, gchar *word, size_t chunk[endword] = '\0'; - strncpy(word, chunk + startword, MIN(endword - startword + 1, wordlen)); + g_strlcpy(word, chunk + startword, wordlen); //ensure null terminated g_free(chunk); }