Commit 3440d1d1 authored by Albert Gräf's avatar Albert Gräf Committed by Gabriela Bittencourt
Browse files

Add some autocomplete options to the gui preferences.

The autcomplete option globally enables or disables autocompletion.

The autocomplete_prefix option only matches object name prefixes,
instead of looking for the text anywhere in an object name. So, e.g.,
typing "me" lists "metro", but not "timer" as possible completions if
this option is enabled.

Both options are currently disabled by default.

TODO: French translations.
parent 533ebff2
Pipeline #3737 canceled with stage
......@@ -442,6 +442,18 @@ select {
name="autopatch_yoffset_value"
data-i18n="[title]prefs.gui.autopatch_yoffset_tt">
<br/><br/>
<span data-i18n="prefs.gui.autocomplete.autocomplete_title"></span>
<br/>
<label data-i18n="[title]prefs.gui.autocomplete.autocomplete_tt">
<input type="checkbox" id="autocomplete" name="autocomplete">
<span data-i18n="prefs.gui.autocomplete.autocomplete"></span>
</label>
<br/>
<label data-i18n="[title]prefs.gui.autocomplete.autocomplete_prefix_tt">
<input type="checkbox" id="autocomplete_prefix" name="autocomplete_prefix">
<span data-i18n="prefs.gui.autocomplete.autocomplete_prefix"></span>
</label>
<br/><br/>
<span data-i18n="prefs.gui.browser.browser_title"></span>
<br/>
<label data-i18n="[title]prefs.gui.browser.browser_doc_tt">
......@@ -792,6 +804,8 @@ function apply(save_prefs) {
get_bool_elem("show_grid"),
document.getElementById("grid_size").value,
get_bool_elem("save_zoom"),
get_bool_elem("autocomplete"),
get_bool_elem("autocomplete_prefix"),
get_bool_elem("browser_doc"),
get_bool_elem("browser_path"),
get_bool_elem("browser_init"),
......@@ -801,7 +815,9 @@ function apply(save_prefs) {
// help browser accordingly.
pdgui.update_browser(
get_bool_elem("browser_doc"),
get_bool_elem("browser_path")
get_bool_elem("browser_path"),
get_bool_elem("autocomplete"),
get_bool_elem("autocomplete_prefix")
);
// Update the grid on all open windows.
pdgui.update_grid(get_bool_elem("show_grid"),
......@@ -1054,8 +1070,9 @@ function autopatch_yoffset_toggle(checked) {
document.getElementById("autopatch_yoffset").checked = checked;
}
function gui_prefs_callback(name, show_grid, grid_size, save_zoom, browser_doc,
browser_path, browser_init, autopatch_yoffset) {
function gui_prefs_callback(name, show_grid, grid_size, save_zoom,
autocomplete, autocomplete_prefix,
browser_doc, browser_path, browser_init, autopatch_yoffset) {
var s = document.getElementById("gui_preset");
// ag: scan the css subdir for user-defined styles
......@@ -1088,6 +1105,8 @@ function gui_prefs_callback(name, show_grid, grid_size, save_zoom, browser_doc,
document.getElementById("grid_size").value = grid_size;
grid_toggle(!!show_grid);
document.getElementById("save_zoom").checked = !!save_zoom;
document.getElementById("autocomplete").checked = !!autocomplete;
document.getElementById("autocomplete_prefix").checked = !!autocomplete_prefix;
document.getElementById("browser_doc").checked = !!browser_doc;
document.getElementById("browser_path").checked = !!browser_path;
document.getElementById("browser_init").checked = !!browser_init;
......
......@@ -439,6 +439,13 @@
"save_zoom": "Speichern/Laden der Vergrößerung im Patch",
"save_zoom_tt": "Speichere die aktuelle Vergrößerung mit dem Patch und stelle diese beim Laden des Patches wieder her"
},
"autocomplete": {
"autocomplete_title": "Autovervollständigungs-Einstellungen",
"autocomplete": "Autovervollständigung von Objekt-Namen und Argumenten (experimentell)",
"autocomplete_tt": "Schlägt bei der Eingabe Vervollständigungen von Objekt-Namen und Argumenten vor",
"autocomplete_prefix": "Vervollständigung per Objektnamens-Präfix",
"autocomplete_prefix_tt": "Vervollständigung nur per Objektnamens-Präfix (statt Übereinstimmung irgendwo im Objektnamen)"
},
"browser": {
"browser_title": "Hilfe-Browser-Einstellungen (WARNUNG: Änderungen können Startup-Zeiten beeinflussen!)",
"browser_doc": "Hilfe-Browser durchsucht nur den doc-Ordner",
......
......@@ -439,6 +439,13 @@
"save_zoom": "save/load zoom level with patch",
"save_zoom_tt": "Save the current zoom level with the patch and restore it when reloading the patch"
},
"autocomplete": {
"autocomplete_title": "Auto-completion settings",
"autocomplete": "auto-complete object names and arguments (experimental)",
"autocomplete_tt": "Offers completions for object names and arguments as you type",
"autocomplete_prefix": "match completions by object name prefix",
"autocomplete_prefix_tt": "Only list completions whose prefix matches (rather than matches anywhere in object names)"
},
"browser": {
"browser_title": "Help browser settings (WARNING: changing these may affect startup times!)",
"browser_doc": "help browser only searches the doc folder",
......
......@@ -439,6 +439,13 @@
"save_zoom": "Sauver/Charger niveau zoom avec patch",
"save_zoom_tt": "Enregistrer le niveau de zoom actuel avec le patch et le restaurer lors du chargement du patch"
},
"autocomplete": {
"autocomplete_title": "Auto-completion settings",
"autocomplete": "auto-complete object names and arguments (experimental)",
"autocomplete_tt": "Offers completions for object names and arguments as you type",
"autocomplete_prefix": "match completions by object name prefix",
"autocomplete_prefix_tt": "Only list completions whose prefix matches (rather than matches anywhere in object names)"
},
"browser": {
"browser_title": "Paramètres du navigateur d'Aide (AVERTISSEMENT: les modifier peut affecter les temps de démarrage!)",
"browser_doc": "Le navigateur d'Aide recherche uniquement dans le dossier 'doc'",
......
......@@ -894,12 +894,15 @@ var canvas_events = (function() {
let obj = document.getElementById(textbox().getAttribute("tag")+"gobj");
// find obj class and remove word "selected"
let obj_class = obj.getAttribute("class").toString().split(" ").slice(0,1).toString();
pdgui.index_obj_completion(obj_class, fudi_msg);
// GB: every 50 changes in completion_index, make sure to save the alterations on json file
// in case of unexpected quit or crash of purr data, it will be lost only few changes
if (changes_in_completion_index===0 || ++changes_in_completion_index > 50) {
pdgui.write_completion_index();
changes_in_completion_index = 1;
if (pdgui.autocomplete_enabled()) {
pdgui.index_obj_completion(obj_class, fudi_msg);
// GB: save every 50 changes, so that we don't loose too
// much data in case purr-data unexpectedly quits or crashes
if (changes_in_completion_index===0 ||
++changes_in_completion_index > 50) {
pdgui.write_completion_index();
changes_in_completion_index = 1;
}
}
}
}
......
......@@ -3,8 +3,13 @@
var pwd;
var lib_dir;
var help_path, browser_doc, browser_path, browser_init;
var autocomplete, autocomplete_prefix;
var pd_engine_id;
exports.autocomplete_enabled = function() {
return autocomplete;
}
exports.set_pwd = function(pwd_string) {
pwd = pwd_string;
}
......@@ -27,17 +32,28 @@ exports.set_pd_engine_id = function (id) {
exports.defunkify_windows_path = defunkify_windows_path;
function gui_set_browser_config(doc_flag, path_flag, init_flag, helppath) {
function gui_set_browser_config(doc_flag, path_flag, init_flag,
ac_flag, ac_prefix_flag,
helppath) {
// post("gui_set_browser_config: " + helppath.join(":"));
browser_doc = doc_flag;
browser_path = path_flag;
browser_init = init_flag;
help_path = helppath;
// AG: This should ideally be in its own separate callback, but for the
// time being we really need the tie-in with the help browser here, so
// that the completion index can be loaded first, and then be updated with
// data from the help index when make_index() gets called. Also note that
// in order to keep things simple, we build the autocompletion index even
// if autcompletion is disabled, so that the index is ready to go if the
// user decides to enable it later.
autocomplete = ac_flag;
autocomplete_prefix = ac_prefix_flag;
make_completion_index();
// AG: Start building the keyword index for dialog_search.html. We do this
// here so that we can be sure that lib_dir and help_path are known already.
// (This may also be deferred until the browser is launched for the first
// time, depending on the value of browser_init.)
make_completion_index(); // GB: TODO - change this line to be called in a separated function on the c side
if (browser_init == 1) make_index();
}
......@@ -469,9 +485,11 @@ function rebuild_index()
}
// this is called from the gui tab of the prefs dialog
function update_browser(doc_flag, path_flag)
function update_browser(doc_flag, path_flag, ac_flag, ac_prefix_flag)
{
var changed = false;
autocomplete = ac_flag;
autocomplete_prefix = ac_prefix_flag;
doc_flag = doc_flag?1:0;
path_flag = path_flag?1:0;
if (browser_doc !== doc_flag) {
......@@ -522,10 +540,14 @@ function obj_exact_match(title) {
}
function search_obj(title) {
if (!autocomplete) return [];
// GB approaches: search objects that *contains* search _word_ (1st line) or patches that *begins with* _word_ (2nd line)
// either should skip the result 'message' and 'text' thus messages and comments are not created the same way objects are
return completion_index.search({$and: [{"title": "'\"" + title + "\""}, {"title": "!\"message\"" }, {"title": "!\"text\"" }]});
// return completion_index.search({$and: [{"title": "^\"" + title + "\""}, {"title": "!\"message\"" }, {"title": "!\"text\"" }]});
if (!autocomplete_prefix) {
return completion_index.search({$and: [{"title": "'\"" + title + "\""}, {"title": "!\"message\"" }, {"title": "!\"text\"" }]});
} else {
return completion_index.search({$and: [{"title": "^\"" + title + "\""}, {"title": "!\"message\"" }, {"title": "!\"text\"" }]});
}
}
function arg_exact_match(title, arg) {
......@@ -533,6 +555,7 @@ function arg_exact_match(title, arg) {
}
function search_arg(title, arg) {
if (!autocomplete) return [];
// for the arguments, we are only interested on the obj that match exactly the 'title', so we return only the args from this obj
let results = completion_index.search({$and: [{"title": "=\"" + title + "\""}, {"args.text": "^\"" + arg + "\""}]});
return (results.length > 0) ? results[0].matches : [];
......@@ -6632,10 +6655,13 @@ function gui_midi_properties(gfxstub, sys_indevs, sys_outdevs,
}
}
function gui_gui_properties(dummy, name, show_grid, grid_size, save_zoom, browser_doc, browser_path,
browser_init, autopatch_yoffset) {
function gui_gui_properties(dummy, name, show_grid, grid_size, save_zoom,
autocomplete, autocomplete_prefix,
browser_doc, browser_path, browser_init,
autopatch_yoffset) {
if (dialogwin["prefs"] !== null) {
dialogwin["prefs"].window.gui_prefs_callback(name, show_grid, grid_size, save_zoom,
dialogwin["prefs"].window.gui_prefs_callback(name, show_grid, grid_size,
save_zoom, autocomplete, autocomplete_prefix,
browser_doc, browser_path, browser_init, autopatch_yoffset);
}
}
......
......@@ -80,7 +80,9 @@ static void glob_perf(t_pd *dummy, float f)
sys_perf = (f != 0);
}
extern int sys_snaptogrid, sys_gridsize, sys_zoom, sys_browser_doc, sys_browser_path, sys_browser_init,
extern int sys_snaptogrid, sys_gridsize, sys_zoom,
sys_autocomplete, sys_autocomplete_prefix,
sys_browser_doc, sys_browser_path, sys_browser_init,
sys_autopatch_yoffset;
extern t_symbol *sys_gui_preset;
static void glob_gui_prefs(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
......@@ -89,6 +91,8 @@ static void glob_gui_prefs(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
sys_snaptogrid = !!atom_getintarg(0, argc--, argv++);
sys_gridsize = atom_getintarg(0, argc--, argv++);
sys_zoom = !!atom_getintarg(0, argc--, argv++);
sys_autocomplete = !!atom_getintarg(0, argc--, argv++);
sys_autocomplete_prefix = !!atom_getintarg(0, argc--, argv++);
sys_browser_doc = !!atom_getintarg(0, argc--, argv++);
sys_browser_path = !!atom_getintarg(0, argc--, argv++);
sys_browser_init = !!atom_getintarg(0, argc--, argv++);
......@@ -98,12 +102,14 @@ static void glob_gui_prefs(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
/* just the gui-preset, the save-zoom toggle and various help browser options for now */
static void glob_gui_properties(t_pd *dummy)
{
gui_vmess("gui_gui_properties", "xsiiiiiii",
gui_vmess("gui_gui_properties", "xsiiiiiiiii",
dummy,
sys_gui_preset->s_name,
sys_snaptogrid,
sys_gridsize,
sys_zoom,
sys_autocomplete,
sys_autocomplete_prefix,
sys_browser_doc,
sys_browser_path,
sys_browser_init,
......
......@@ -42,8 +42,9 @@
#define snprintf sprintf_s
#endif
int sys_defeatrt, sys_autopatch_yoffset, sys_snaptogrid = 1, sys_gridsize = 10, sys_zoom, sys_browser_doc = 1,
sys_browser_path, sys_browser_init;
int sys_defeatrt, sys_autopatch_yoffset, sys_snaptogrid = 1, sys_gridsize = 10,
sys_zoom, sys_autocomplete, sys_autocomplete_prefix,
sys_browser_doc = 1, sys_browser_path, sys_browser_init;
t_symbol *sys_flags = &s_;
void sys_doflags( void);
......@@ -676,6 +677,10 @@ void sys_loadpreferences( void)
sscanf(prefbuf, "%d", &sys_gridsize);
if (sys_getpreference("savezoom", prefbuf, MAXPDSTRING))
sscanf(prefbuf, "%d", &sys_zoom);
if (sys_getpreference("autocomplete", prefbuf, MAXPDSTRING))
sscanf(prefbuf, "%d", &sys_autocomplete);
if (sys_getpreference("autocomplete_prefix", prefbuf, MAXPDSTRING))
sscanf(prefbuf, "%d", &sys_autocomplete_prefix);
if (sys_getpreference("browser_doc", prefbuf, MAXPDSTRING))
sscanf(prefbuf, "%d", &sys_browser_doc);
if (sys_getpreference("browser_path", prefbuf, MAXPDSTRING))
......@@ -827,6 +832,10 @@ void glob_savepreferences(t_pd *dummy)
sys_putpreference("gridsize", buf1);
sprintf(buf1, "%d", sys_zoom);
sys_putpreference("savezoom", buf1);
sprintf(buf1, "%d", sys_autocomplete);
sys_putpreference("autocomplete", buf1);
sprintf(buf1, "%d", sys_autocomplete_prefix);
sys_putpreference("autocomplete_prefix", buf1);
sprintf(buf1, "%d", sys_browser_doc);
sys_putpreference("browser_doc", buf1);
sprintf(buf1, "%d", sys_browser_path);
......
......@@ -331,6 +331,7 @@ void glob_forward_files_from_secondary_instance(void)
extern void glob_recent_files(t_pd *dummy);
extern int sys_browser_doc, sys_browser_path, sys_browser_init;
extern int sys_autocomplete, sys_autocomplete_prefix;
/* this is called from main() in s_entry.c */
int sys_main(int argc, char **argv)
......@@ -411,8 +412,9 @@ int sys_main(int argc, char **argv)
glob_recent_files(0);
/* AG: send the browser config; this must come *after* gui_set_lib_dir
so that the lib_dir is available when help indexing starts */
gui_start_vmess("gui_set_browser_config", "iii",
sys_browser_doc, sys_browser_path, sys_browser_init);
gui_start_vmess("gui_set_browser_config", "iiiii",
sys_browser_doc, sys_browser_path, sys_browser_init,
sys_autocomplete, sys_autocomplete_prefix);
gui_start_array();
for (nl = sys_helppath; nl; nl = nl->nl_next)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment