From 67cd5dbd134ff07c640d68784454c20177be5d60 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Sat, 5 Mar 2011 22:46:32 +0000 Subject: [PATCH] Add possibility to update symbol list in IDLE time Enabled by default, using a minimal delay of 250ms between two updates. Also add a preference to configure this in Geany's UI, under Preferences -> Editor -> Completion. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5557 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- geany.glade | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- src/editor.c | 32 ++++++++++++++++++++++++++++++ src/editor.h | 1 + src/interface.c | 23 +++++++++++++++++++++- src/keyfile.c | 3 +++ 5 files changed, 109 insertions(+), 2 deletions(-) diff --git a/geany.glade b/geany.glade index c3b24f96..18650ac3 100644 --- a/geany.glade +++ b/geany.glade @@ -6607,7 +6607,7 @@ Match braces True - 3 + 4 2 False 3 @@ -6762,6 +6762,56 @@ Match braces + + + + True + Symbol list update frequency: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + Minimal delay (in milliseconds) between two automatic updates of the symbol list. Note that a too short delay may have performance impact, espcially with large files. A delay of 0 disables real-time updates. + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 250 0 10000 10 100 0 + + + 1 + 2 + 3 + 4 + + + 0 diff --git a/src/editor.c b/src/editor.c index 22f9ec58..7a9d7603 100644 --- a/src/editor.c +++ b/src/editor.c @@ -83,6 +83,9 @@ static GtkAccelGroup *snippet_accel_group = NULL; /* holds word under the mouse or keyboard cursor */ static gchar current_word[GEANY_MAX_WORD_LENGTH]; +/* whether there is a tag list update pending */ +static gboolean document_tags_update_pending = FALSE; + /* Initialised in keyfile.c. */ GeanyEditorPrefs editor_prefs; @@ -991,6 +994,29 @@ void editor_sci_notify_cb(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint sc } +static gboolean on_document_update_tags_idle(gpointer data) +{ + GeanyDocument *doc = data; + + if (!main_status.quitting && DOC_VALID(doc)) + document_update_tag_list(doc, TRUE); + + document_tags_update_pending = FALSE; + return FALSE; +} + + +static void request_tag_list_update(GeanyDocument *doc) +{ + if (!document_tags_update_pending) + { + document_tags_update_pending = TRUE; + g_timeout_add_full(G_PRIORITY_LOW, editor_prefs.autocompletion_update_freq, + on_document_update_tags_idle, doc, NULL); + } +} + + static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *editor, SCNotification *nt, G_GNUC_UNUSED gpointer data) { @@ -1052,6 +1078,12 @@ static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *edi /* handle special fold cases, e.g. #1923350 */ fold_changed(sci, nt->line, nt->foldLevelNow, nt->foldLevelPrev); } + if (editor_prefs.autocompletion_update_freq > 0 && + (nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) && + filetype_has_tags(doc->file_type)) + { + request_tag_list_update(doc); + } break; case SCN_CHARADDED: diff --git a/src/editor.h b/src/editor.h index 5372519a..e76133f0 100644 --- a/src/editor.h +++ b/src/editor.h @@ -146,6 +146,7 @@ typedef struct GeanyEditorPrefs gint show_virtual_space; /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */ gboolean long_line_enabled; + gint autocompletion_update_freq; } GeanyEditorPrefs; diff --git a/src/interface.c b/src/interface.c index 2ad1c1e0..f927447c 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2710,6 +2710,9 @@ create_prefs_dialog (void) GtkWidget *spin_symbollistheight; GtkObject *spin_autocompletion_max_entries_adj; GtkWidget *spin_autocompletion_max_entries; + GtkWidget *label250; + GtkObject *spin_symbol_update_freq_adj; + GtkWidget *spin_symbol_update_freq; GtkWidget *label177; GtkWidget *frame38; GtkWidget *alignment42; @@ -3974,7 +3977,7 @@ create_prefs_dialog (void) gtk_widget_show (check_completion_drops_rest_of_word); gtk_box_pack_start (GTK_BOX (vbox19), check_completion_drops_rest_of_word, FALSE, FALSE, 0); - table14 = gtk_table_new (3, 2, FALSE); + table14 = gtk_table_new (4, 2, FALSE); gtk_widget_show (table14); gtk_box_pack_start (GTK_BOX (vbox19), table14, FALSE, FALSE, 0); gtk_table_set_row_spacings (GTK_TABLE (table14), 3); @@ -4028,6 +4031,22 @@ create_prefs_dialog (void) gtk_tooltips_set_tip (tooltips, spin_autocompletion_max_entries, _("Maximum number of entries to display in the autocompletion list"), NULL); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_autocompletion_max_entries), TRUE); + label250 = gtk_label_new (_("Symbol list update frequency:")); + gtk_widget_show (label250); + gtk_table_attach (GTK_TABLE (table14), label250, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label250), 0, 0.5); + + spin_symbol_update_freq_adj = gtk_adjustment_new (250, 0, 10000, 10, 100, 0); + spin_symbol_update_freq = gtk_spin_button_new (GTK_ADJUSTMENT (spin_symbol_update_freq_adj), 1, 0); + gtk_widget_show (spin_symbol_update_freq); + gtk_table_attach (GTK_TABLE (table14), spin_symbol_update_freq, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, spin_symbol_update_freq, _("Minimal delay (in milliseconds) between two automatic updates of the symbol list. Note that a too short delay may have performance impact, espcially with large files. A delay of 0 disables real-time updates."), NULL); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_symbol_update_freq), TRUE); + label177 = gtk_label_new (_("Completions")); gtk_widget_show (label177); gtk_frame_set_label_widget (GTK_FRAME (frame18), label177); @@ -5216,6 +5235,8 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, spin_symbol_complete_chars, "spin_symbol_complete_chars"); GLADE_HOOKUP_OBJECT (prefs_dialog, spin_symbollistheight, "spin_symbollistheight"); GLADE_HOOKUP_OBJECT (prefs_dialog, spin_autocompletion_max_entries, "spin_autocompletion_max_entries"); + GLADE_HOOKUP_OBJECT (prefs_dialog, label250, "label250"); + GLADE_HOOKUP_OBJECT (prefs_dialog, spin_symbol_update_freq, "spin_symbol_update_freq"); GLADE_HOOKUP_OBJECT (prefs_dialog, label177, "label177"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame38, "frame38"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment42, "alignment42"); diff --git a/src/keyfile.c b/src/keyfile.c index b8101a87..3dcb56e0 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -83,6 +83,7 @@ #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10" #define GEANY_TOGGLE_MARK "~ " #define GEANY_MAX_AUTOCOMPLETE_WORDS 30 +#define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250 static gchar *scribble_text = NULL; @@ -165,6 +166,8 @@ static void init_pref_groups(void) stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_max_entries, "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS, "spin_autocompletion_max_entries"); + stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_update_freq, + "autocompletion_update_freq", GEANY_MAX_SYMBOLS_UPDATE_FREQ, "spin_symbol_update_freq"); stash_group_add_string(group, &editor_prefs.color_scheme, "color_scheme", NULL);