Revision: 727 Author: ntrel Date: 2006-08-15 14:00:43 -0700 (Tue, 15 Aug 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=727&view=rev
Log Message: ----------- Return to showing calltips after successful autocompletion; Use separate functions for html and tag autocompletion
Modified Paths: -------------- trunk/ChangeLog trunk/src/keybindings.c trunk/src/sci_cb.c trunk/src/sci_cb.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-08-15 19:41:12 UTC (rev 726) +++ trunk/ChangeLog 2006-08-15 21:00:43 UTC (rev 727) @@ -2,6 +2,9 @@
* tagmanager/c.c: Backported calltips workspace support for C-like user files from Anjuta. + * src/keybindings.c, src/sci_cb.c, src/sci_cb.h: + Return to showing calltips after successful autocompletion. + Use separate functions for html and tag autocompletion.
2006-08-15 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/src/keybindings.c =================================================================== --- trunk/src/keybindings.c 2006-08-15 19:41:12 UTC (rev 726) +++ trunk/src/keybindings.c 2006-08-15 21:00:43 UTC (rev 727) @@ -724,8 +724,7 @@ { gint idx = document_get_cur_idx(); if (idx == -1 || ! doc_list[idx].is_valid) return; - sci_cb_start_auto_complete(doc_list[idx].sci, - sci_get_current_position(doc_list[idx].sci), idx, TRUE); + sci_cb_start_auto_complete(idx, sci_get_current_position(doc_list[idx].sci), TRUE); }
static void cb_func_edit_calltip(void)
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2006-08-15 19:41:12 UTC (rev 726) +++ trunk/src/sci_cb.c 2006-08-15 21:00:43 UTC (rev 727) @@ -32,6 +32,12 @@ #include "sciwrappers.h" #include "utils.h"
+static struct +{ + gchar *text; + gboolean set; +} calltip = {NULL, FALSE}; + static gchar indent[100];
@@ -157,6 +163,9 @@ { SSM(sci, SCI_CALLTIPCANCEL, 0, 0); } + g_free(calltip.text); + calltip.text = NULL; + calltip.set = FALSE; break; } case ' ': @@ -176,7 +185,7 @@ if (doc_list[idx].use_auto_indention) sci_cb_close_block(sci, pos - 1); break; } - default: sci_cb_start_auto_complete(sci, pos, idx, FALSE); + default: sci_cb_start_auto_complete(idx, pos, FALSE); } break; } @@ -198,6 +207,22 @@ } break; } + case SCN_AUTOCSELECTION: + { + // now that autocomplete is finishing, reshow calltips if they were showing + if (calltip.set) + { + gint pos = sci_get_current_position(sci); + SSM(sci, SCI_CALLTIPSHOW, pos, (sptr_t) calltip.text); + // now autocompletion has been cancelled, so do it manually + sci_set_selection_start(sci, nt->lParam); + sci_set_selection_end(sci, pos); + sci_replace_sel(sci, ""); // clear root of word + SSM(sci, SCI_INSERTTEXT, nt->lParam, (sptr_t) nt->text); + sci_goto_pos(sci, nt->lParam + strlen(nt->text), FALSE); + } + break; + } /* case SCN_STYLENEEDED: { geany_debug("style"); @@ -393,30 +418,97 @@ tags = tm_workspace_find(word, tm_tag_max_t, NULL, FALSE, doc_list[idx].file_type->lang); if (tags->len == 1 && TM_TAG(tags->pdata[0])->atts.entry.arglist) { - gchar *calltip; tag = TM_TAG(tags->pdata[0]); + g_free(calltip.text); // free the old calltip + calltip.set = TRUE; if (tag->atts.entry.var_type) - calltip = g_strconcat(tag->atts.entry.var_type, " ", tag->name, + calltip.text = g_strconcat(tag->atts.entry.var_type, " ", tag->name, " ", tag->atts.entry.arglist, NULL); else - calltip = g_strconcat(tag->name, " ", tag->atts.entry.arglist, NULL); + calltip.text = g_strconcat(tag->name, " ", tag->atts.entry.arglist, NULL);
- utils_wrap_string(calltip, -1); - SSM(sci, SCI_CALLTIPSHOW, orig_pos, (sptr_t) calltip); - g_free(calltip); + utils_wrap_string(calltip.text, -1); + SSM(sci, SCI_CALLTIPSHOW, orig_pos, (sptr_t) calltip.text); }
return TRUE; }
-gboolean sci_cb_start_auto_complete(ScintillaObject *sci, gint pos, gint idx, gboolean force) +static void show_autocomplete(ScintillaObject *sci, gint rootlen, const gchar *words) { + // store whether a calltip is showing, so we can reshow it after autocompletion + calltip.set = SSM(sci, SCI_CALLTIPACTIVE, 0, 0); + SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words); +} + + +static gboolean +autocomplete_html(ScintillaObject *sci, const gchar *root, gsize rootlen) +{ // HTML entities auto completion + guint i, j = 0; + GString *words; + + if (*root != '&') return FALSE; + if (html_entities == NULL) return FALSE; + + words = g_string_sized_new(500); + for (i = 0; ; i++) + { + if (html_entities[i] == NULL) break; + else if (html_entities[i][0] == '#') continue; + + if (! strncmp(html_entities[i], root, rootlen)) + { + if (j++ > 0) g_string_append_c(words, ' '); + g_string_append(words, html_entities[i]); + } + } + if (words->len > 0) show_autocomplete(sci, rootlen, words->str); + g_string_free(words, TRUE); + return TRUE; +} + + +static gboolean +autocomplete_tags(gint idx, gchar *root, gsize rootlen) +{ // PHP, LaTeX, C and C++ tag autocompletion + TMTagAttrType attrs[] = { tm_tag_attr_name_t, 0 }; + const GPtrArray *tags; + ScintillaObject *sci; + + if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) + return FALSE; + sci = doc_list[idx].sci; + + tags = tm_workspace_find(root, tm_tag_max_t, attrs, TRUE, doc_list[idx].file_type->lang); + if (NULL != tags && tags->len > 0) + { + GString *words = g_string_sized_new(150); + guint j; + + for (j = 0; ((j < tags->len) && (j < GEANY_MAX_AUTOCOMPLETE_WORDS)); ++j) + { + if (j > 0) g_string_append_c(words, ' '); + g_string_append(words, ((TMTag *) tags->pdata[j])->name); + } + show_autocomplete(sci, rootlen, words->str); + //geany_debug("string size: %d", words->len); + g_string_free(words, TRUE); + } + return TRUE; +} + + +gboolean sci_cb_start_auto_complete(gint idx, gint pos, gboolean force) +{ gint line, line_start, line_len, line_pos, current, rootlen, startword, lexer, style; gchar *linebuf, *root; - const GPtrArray *tags; + ScintillaObject *sci; + gboolean ret = FALSE;
- if (sci == NULL) return FALSE; + if (idx < 0 || ! doc_list[idx].is_valid || doc_list[idx].sci == NULL) return FALSE; + sci = doc_list[idx].sci;
line = sci_get_line_from_position(sci, pos); line_start = sci_get_position_from_line(sci, line); @@ -442,68 +534,17 @@ root = linebuf + startword; rootlen = current - startword;
- if (*root == '&' && lexer == SCLEX_HTML) - { // HTML entities auto completion - guint i, j = 0; - GString *words; - - if (html_entities == NULL) return FALSE; - - words = g_string_sized_new(500); - for (i = 0; ; i++) - { - if (html_entities[i] == NULL) break; - else if (html_entities[i][0] == '#') continue; - - if (! strncmp(html_entities[i], root, rootlen)) - { - if (j++ > 0) g_string_append_c(words, ' '); - g_string_append(words, html_entities[i]); - } - } - if (words->len > 0) SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words->str); - g_string_free(words, TRUE); + if (lexer == SCLEX_HTML) + ret = autocomplete_html(sci, root, rootlen); + else + { + // force is set when called by keyboard shortcut, otherwise start at the 4th char + if (force || rootlen >= 4) + ret = autocomplete_tags(idx, root, rootlen); } - else - { // PHP, LaTeX, C and C++ tag autocompletion - gint i = 0; - TMTagAttrType attrs[] = { tm_tag_attr_name_t, 0 };
- if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) - { - g_free(linebuf); - return FALSE; - } - - if (! force) - { // force is set when called by keyboard shortcut, otherwise start after at third char - /// TODO g_ascii_isspace is not the best choise because it allows öprin... - while ((line_pos - i >= 0) && ! g_ascii_isspace(linebuf[line_pos - i])) i++; - if (i < 4) - { // go home if typed less than 4 chars - g_free(linebuf); - return FALSE; - } - } - - tags = tm_workspace_find(root, tm_tag_max_t, attrs, TRUE, doc_list[idx].file_type->lang); - if (NULL != tags && tags->len > 0) - { - GString *words = g_string_sized_new(150); - guint j; - - for (j = 0; ((j < tags->len) && (j < GEANY_MAX_AUTOCOMPLETE_WORDS)); ++j) - { - if (j > 0) g_string_append_c(words, ' '); - g_string_append(words, ((TMTag *) tags->pdata[j])->name); - } - SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words->str); - //geany_debug("string size: %d", words->len); - g_string_free(words, TRUE); - } - } g_free(linebuf); - return TRUE; + return ret; }
Modified: trunk/src/sci_cb.h =================================================================== --- trunk/src/sci_cb.h 2006-08-15 19:41:12 UTC (rev 726) +++ trunk/src/sci_cb.h 2006-08-15 21:00:43 UTC (rev 727) @@ -29,7 +29,7 @@ // callback func called by all editors when a signals arises void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer user_data);
-gboolean sci_cb_start_auto_complete(ScintillaObject *sci, gint pos, gint idx, gboolean force); +gboolean sci_cb_start_auto_complete(gint idx, gint pos, gboolean force);
void sci_cb_get_indent(ScintillaObject *sci, gint pos, gboolean use_this_line);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.