From 6a9c283cb9a774b7ce09a5836324c6af6eb083cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 16 Jul 2006 22:02:31 +0000 Subject: [PATCH] Moved HTML entities from sci_cb.h to data/html_entities.tags. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@571 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 ++ Makefile.am | 2 + data/html_entities.tags | 95 +++++++++++++++++++++++++++++++++++++++++ src/callbacks.c | 1 + src/highlighting.c | 8 ++++ src/main.c | 10 +++-- src/sci_cb.c | 20 +++++---- src/sci_cb.h | 13 ++---- src/utils.c | 18 ++++++++ 9 files changed, 148 insertions(+), 22 deletions(-) create mode 100644 data/html_entities.tags diff --git a/ChangeLog b/ChangeLog index a70324c12..d3e0e9eb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,9 @@ * src/utils.c: Simplified locale detection and little speed up. * src/main.c, src/document.c, src/geany.h: Removed code for alternative scrolling(it was not better). + * src/sci_cb.c, src/callbacks.c, src/utils.c, src/highlighting.c, + src/main.c, data/html_entities.tags, Makefile.am: + Moved HTML entities from sci_cb.h to data/html_entities.tags. 2006-07-16 Nick Treleaven diff --git a/Makefile.am b/Makefile.am index 11b31a966..77ed0deba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,6 +11,7 @@ EXTRA_DIST = \ data/global.tags \ data/php.tags \ data/latex.tags \ + data/html_entities.tags \ data/filetypes.* uninstall-local: @@ -31,6 +32,7 @@ install-data-local: $(INSTALL_DATA) data/global.tags $(DESTDIR)$(pkgdatadir); \ $(INSTALL_DATA) data/php.tags $(DESTDIR)$(pkgdatadir); \ $(INSTALL_DATA) data/latex.tags $(DESTDIR)$(pkgdatadir); \ + $(INSTALL_DATA) data/html_entities.tags $(DESTDIR)$(pkgdatadir); \ $(INSTALL_DATA) COPYING $(DESTDIR)$(pkgdatadir)/GPL-2; \ for file in $(srcdir)/data/*; do \ if test -f $$file; then \ diff --git a/data/html_entities.tags b/data/html_entities.tags new file mode 100644 index 000000000..2771cecc6 --- /dev/null +++ b/data/html_entities.tags @@ -0,0 +1,95 @@ +# each of the following lines represent a html entity +# used in HTML and PHP files when typing &... +Á +Â +æ +Æ +À +α +& +å +Å +Ã +ä +Ä +• +ç +Ç +¢ +© +¤ +° +÷ +É +ê +Ê +è +È +∅ +ë +Ë +€ +½ +¼ +¾ +> +Í +î +Î +ì +Ì +∞ +∈ +ï +Ï +∗ +< +µ +− +  +ñ +Ñ +ó +Ó +ô +Ô +ò +Ò +ω +Ω +ª +º +ø +Ø +õ +Õ +ö +Ö +¶ +π +± +£ +∏ +∝ +" +® +§ +∑ +¹ +² +³ +ß +× +™ +ú +Ú +û +Û +ù +Ù +¨ +ü +Ü +ý +¥ +ÿ diff --git a/src/callbacks.c b/src/callbacks.c index 3398a9d5a..e65a68134 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -123,6 +123,7 @@ gint destroyapp(GtkWidget *widget, gpointer gdata) styleset_free_styles(); templates_free_templates(); tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace)); + g_strfreev(html_entities); g_free(app->configdir); g_free(app->search_text); g_free(app->editor_font); diff --git a/src/highlighting.c b/src/highlighting.c index 56eb29636..43546175c 100644 --- a/src/highlighting.c +++ b/src/highlighting.c @@ -25,12 +25,14 @@ #include "SciLexer.h" #include "geany.h" #include "highlighting.h" +#include "sci_cb.h" #include "utils.h" static style_set *types[GEANY_MAX_FILE_TYPES] = { NULL }; static gboolean global_c_tags_loaded = FALSE; static gboolean global_php_tags_loaded = FALSE; +static gboolean global_html_tags_loaded = FALSE; static gboolean global_latex_tags_loaded = FALSE; @@ -785,6 +787,12 @@ static void styleset_php_init(void) tm_workspace_load_global_tags(GEANY_DATA_DIR G_DIR_SEPARATOR_S "php.tags", 6); global_php_tags_loaded = TRUE; } + // load global tags file for HTML entities autocompletion + if (! app->ignore_global_tags && ! global_html_tags_loaded) + { + html_entities = utils_read_file_in_array(GEANY_DATA_DIR G_DIR_SEPARATOR_S "html_entities.tags"); + global_html_tags_loaded = TRUE; + } g_key_file_free(config); g_key_file_free(config_home); diff --git a/src/main.c b/src/main.c index afeaf7e7d..9a30de531 100644 --- a/src/main.c +++ b/src/main.c @@ -48,6 +48,7 @@ #include "treeviews.h" #include "notebook.h" #include "keybindings.h" +#include "sci_cb.h" #ifdef HAVE_VTE # include "vte.h" @@ -225,10 +226,11 @@ static void main_init(void) #ifdef HAVE_VTE app->lib_vte = lib_vte; #endif - app->ignore_global_tags = ignore_global_tags; - app->tm_workspace = tm_get_workspace(); - app->recent_queue = g_queue_new(); - app->opening_session_files = FALSE; + app->ignore_global_tags = ignore_global_tags; + app->tm_workspace = tm_get_workspace(); + app->recent_queue = g_queue_new(); + app->opening_session_files = FALSE; + html_entities = NULL; app->window = create_window1(); app->new_file_menu = gtk_menu_new(); diff --git a/src/sci_cb.c b/src/sci_cb.c index 246ef8f8a..ded5fbe0d 100644 --- a/src/sci_cb.c +++ b/src/sci_cb.c @@ -438,21 +438,25 @@ gboolean sci_cb_start_auto_complete(ScintillaObject *sci, gint pos, gint idx, gb if (*root == '&' && lexer == SCLEX_HTML) { // HTML entities auto completion - gchar **ents = g_strsplit(sci_cb_html_entities, " ", 0); - guint i, j = 0, ents_len = g_strv_length(ents); - GString *words = g_string_sized_new(60); + guint i, j = 0; + GString *words; - for (i = 0; i < ents_len; i++) + if (html_entities == NULL) return FALSE; + + words = g_string_sized_new(500); + for (i = 0; ; i++) { - if (! strncmp(ents[i], root, rootlen)) + 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, ents[i]); + g_string_append(words, html_entities[i]); } } - SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words->str); + if (words->len > 0) SSM(sci, SCI_AUTOCSHOW, rootlen, (sptr_t) words->str); g_string_free(words, TRUE); - g_strfreev(ents); } else { // PHP, LaTeX, C and C++ tag autocompletion diff --git a/src/sci_cb.h b/src/sci_cb.h index 328496904..4bd98eb04 100644 --- a/src/sci_cb.h +++ b/src/sci_cb.h @@ -23,6 +23,9 @@ #define GEANY_SCI_CB_H 1 +gchar **html_entities; + + // callback func called by all editors when a signals arises void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer user_data); @@ -52,14 +55,4 @@ void sci_cb_auto_table(ScintillaObject *sci, gint pos); void sci_cb_auto_close_bracket(ScintillaObject *sci, gint pos, gchar c); -#define sci_cb_html_entities "  " & < > Ü™ € • ∞ ∝ ∗\ - − ∑ ∏ ∈ ∅ π Ω ω α ÿ ý\ - ÷ ø ù ú û ü ä å æ ç\ - è ê ë ì î ï ñ ò ó ô\ - õ ö ¢ £ ¤ ¥ § ¨ © ª ® °\ - ± ² ³ ¾ À Á Â Ã Ä Å\ - Æ Ç È É Ê ½ ¼ º ¹ ¶\ - µ Ë Ì Í Î Ï Ñ Ò Ó Ô\ - Õ Ö × Ø Ù Ú Û" - #endif diff --git a/src/utils.c b/src/utils.c index b6b1d225b..b7ab5aa31 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2517,3 +2517,21 @@ void utils_update_toolbar_items(void) utils_widget_show_hide(lookup_widget(app->window, "separatortoolitem9"), app->pref_toolbar_show_undo); } + +gchar **utils_read_file_in_array(const gchar *filename) +{ + gchar **result = NULL; + gchar *data; + + if (filename == NULL) return NULL; + + g_file_get_contents(filename, &data, NULL, NULL); + + if (data != NULL) + { + result = g_strsplit_set(data, "\r\n", -1); + } + + return result; +} +