4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
12 #include <libextl/readconfig.h>
13 #include <libextl/extl.h>
14 #include <libtu/minmax.h>
15 #include <ioncore/binding.h>
16 #include <ioncore/conf-bindings.h>
17 #include <ioncore/frame.h>
18 #include <ioncore/saveload.h>
19 #include <ioncore/bindmaps.h>
20 #include <ioncore/ioncore.h>
32 /*{{{ Module information */
35 #include "../version.h"
37 char mod_query_ion_api_version[]=ION_API_VERSION;
46 WBindmap *mod_query_input_bindmap=NULL;
47 WBindmap *mod_query_wedln_bindmap=NULL;
56 ModQueryConfig mod_query_config={
64 * Set module configuration. The following are supported:
66 * \begin{tabularx}{\linewidth}{lX}
67 * \tabhead{Field & Description}
68 * \var{autoshowcompl} & (boolean) Is auto-show-completions enabled?
70 * \var{autoshowcompl_delay} & (integer) auto-show-completions delay
71 * in milliseconds (default: 250). \\
72 * \var{caseicompl} & (boolean) Turn some completions case-insensitive
73 * (default: false). \\
77 void mod_query_set(ExtlTab tab)
79 ModQueryConfig *c=&mod_query_config;
81 extl_table_gets_b(tab, "autoshowcompl", &c->autoshowcompl);
82 extl_table_gets_b(tab, "caseicompl", &c->caseicompl);
84 if(extl_table_gets_i(tab, "autoshowcompl_delay",
85 &c->autoshowcompl_delay)){
86 c->autoshowcompl_delay=maxof(c->autoshowcompl_delay, 0);
91 * Get module configuration. For more information see
92 * \fnref{mod_query.set}.
96 ExtlTab mod_query_get()
98 ModQueryConfig *c=&mod_query_config;
99 ExtlTab tab=extl_create_table();
101 extl_table_sets_b(tab, "autoshowcompl", c->autoshowcompl);
102 extl_table_sets_b(tab, "caseicompl", c->caseicompl);
103 extl_table_sets_i(tab, "autoshowcompl_delay", c->autoshowcompl_delay);
112 /*{{{ Init & deinit */
115 static void load_history()
120 if(!extl_read_savefile("saved_queryhist", &tab))
123 n=extl_table_get_n(tab);
127 if(extl_table_geti_s(tab, i, &s)){
128 mod_query_history_push(s);
133 extl_unref_table(tab);
137 static void save_history()
139 ExtlTab tab=mod_query_history_table();
141 extl_write_savefile("saved_queryhist", tab);
143 extl_unref_table(tab);
147 static bool loaded_ok=FALSE;
149 void mod_query_deinit()
151 mod_query_unregister_exports();
153 if(mod_query_input_bindmap!=NULL){
154 ioncore_free_bindmap("WInput", mod_query_input_bindmap);
155 mod_query_input_bindmap=NULL;
158 if(mod_query_wedln_bindmap!=NULL){
159 ioncore_free_bindmap("WEdln", mod_query_wedln_bindmap);
160 mod_query_wedln_bindmap=NULL;
163 hook_remove(ioncore_snapshot_hook, save_history);
167 bool mod_query_init()
169 if(!mod_query_register_exports())
172 mod_query_input_bindmap=ioncore_alloc_bindmap("WInput", NULL);
173 mod_query_wedln_bindmap=ioncore_alloc_bindmap("WEdln", NULL);
175 if(mod_query_wedln_bindmap==NULL ||
176 mod_query_input_bindmap==NULL){
180 /*ioncore_read_config("cfg_query", NULL, TRUE);*/
186 hook_add(ioncore_snapshot_hook, save_history);