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
This commit is contained in:
Colomban Wendling 2011-03-05 22:46:32 +00:00
parent 676f8e6d76
commit 67cd5dbd13
5 changed files with 109 additions and 2 deletions

View File

@ -6607,7 +6607,7 @@ Match braces</property>
<child> <child>
<widget class="GtkTable" id="table14"> <widget class="GtkTable" id="table14">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">3</property> <property name="n_rows">4</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="row_spacing">3</property> <property name="row_spacing">3</property>
@ -6762,6 +6762,56 @@ Match braces</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkLabel" id="label250">
<property name="visible">True</property>
<property name="label" translatable="yes">Symbol list update frequency:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_symbol_update_freq">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">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.</property>
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
<property name="digits">0</property>
<property name="numeric">True</property>
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">250 0 10000 10 100 0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>

View File

@ -83,6 +83,9 @@ static GtkAccelGroup *snippet_accel_group = NULL;
/* holds word under the mouse or keyboard cursor */ /* holds word under the mouse or keyboard cursor */
static gchar current_word[GEANY_MAX_WORD_LENGTH]; 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. */ /* Initialised in keyfile.c. */
GeanyEditorPrefs editor_prefs; 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, static gboolean on_editor_notify(G_GNUC_UNUSED GObject *object, GeanyEditor *editor,
SCNotification *nt, G_GNUC_UNUSED gpointer data) 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 */ /* handle special fold cases, e.g. #1923350 */
fold_changed(sci, nt->line, nt->foldLevelNow, nt->foldLevelPrev); 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; break;
case SCN_CHARADDED: case SCN_CHARADDED:

View File

@ -146,6 +146,7 @@ typedef struct GeanyEditorPrefs
gint show_virtual_space; gint show_virtual_space;
/* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */ /* This setting may be overridden when a project is opened. Use @c editor_get_prefs(). */
gboolean long_line_enabled; gboolean long_line_enabled;
gint autocompletion_update_freq;
} }
GeanyEditorPrefs; GeanyEditorPrefs;

View File

@ -2710,6 +2710,9 @@ create_prefs_dialog (void)
GtkWidget *spin_symbollistheight; GtkWidget *spin_symbollistheight;
GtkObject *spin_autocompletion_max_entries_adj; GtkObject *spin_autocompletion_max_entries_adj;
GtkWidget *spin_autocompletion_max_entries; GtkWidget *spin_autocompletion_max_entries;
GtkWidget *label250;
GtkObject *spin_symbol_update_freq_adj;
GtkWidget *spin_symbol_update_freq;
GtkWidget *label177; GtkWidget *label177;
GtkWidget *frame38; GtkWidget *frame38;
GtkWidget *alignment42; GtkWidget *alignment42;
@ -3974,7 +3977,7 @@ create_prefs_dialog (void)
gtk_widget_show (check_completion_drops_rest_of_word); 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); 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_widget_show (table14);
gtk_box_pack_start (GTK_BOX (vbox19), table14, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox19), table14, FALSE, FALSE, 0);
gtk_table_set_row_spacings (GTK_TABLE (table14), 3); 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_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); 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 (_("<b>Completions</b>")); label177 = gtk_label_new (_("<b>Completions</b>"));
gtk_widget_show (label177); gtk_widget_show (label177);
gtk_frame_set_label_widget (GTK_FRAME (frame18), 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_symbol_complete_chars, "spin_symbol_complete_chars");
GLADE_HOOKUP_OBJECT (prefs_dialog, spin_symbollistheight, "spin_symbollistheight"); 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, 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, label177, "label177");
GLADE_HOOKUP_OBJECT (prefs_dialog, frame38, "frame38"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame38, "frame38");
GLADE_HOOKUP_OBJECT (prefs_dialog, alignment42, "alignment42"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment42, "alignment42");

View File

@ -83,6 +83,7 @@
#define GEANY_DEFAULT_FONT_EDITOR "Monospace 10" #define GEANY_DEFAULT_FONT_EDITOR "Monospace 10"
#define GEANY_TOGGLE_MARK "~ " #define GEANY_TOGGLE_MARK "~ "
#define GEANY_MAX_AUTOCOMPLETE_WORDS 30 #define GEANY_MAX_AUTOCOMPLETE_WORDS 30
#define GEANY_MAX_SYMBOLS_UPDATE_FREQ 250
static gchar *scribble_text = NULL; 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, stash_group_add_spin_button_integer(group, (gint*)&editor_prefs.autocompletion_max_entries,
"autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS, "autocompletion_max_entries", GEANY_MAX_AUTOCOMPLETE_WORDS,
"spin_autocompletion_max_entries"); "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, stash_group_add_string(group, &editor_prefs.color_scheme,
"color_scheme", NULL); "color_scheme", NULL);