4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
9 #include <libextl/readconfig.h>
10 #include <libextl/extl.h>
11 #include <libtu/minmax.h>
12 #include <ioncore/binding.h>
13 #include <ioncore/conf-bindings.h>
14 #include <ioncore/frame.h>
15 #include <ioncore/saveload.h>
16 #include <ioncore/bindmaps.h>
17 #include <ioncore/ioncore.h>
29 /*{{{ Module information */
32 #include "../version.h"
34 char mod_query_ion_api_version
[]=NOTION_API_VERSION
;
43 WBindmap
*mod_query_input_bindmap
=NULL
;
44 WBindmap
*mod_query_wedln_bindmap
=NULL
;
53 ModQueryConfig mod_query_config
={
62 * Set module configuration. The following are supported:
64 * \begin{tabularx}{\linewidth}{lX}
65 * \tabhead{Field & Description}
66 * \var{autoshowcompl} & (boolean) Is auto-show-completions enabled?
68 * \var{autoshowcompl_delay} & (integer) auto-show-completions delay
69 * in milliseconds (default: 250). \\
70 * \var{caseicompl} & (boolean) Turn some completions case-insensitive
71 * (default: false). \\
72 * \var{substrcompl} & (boolean) Complete on sub-strings in some cases
73 * (default: ftrue). \\
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
);
83 extl_table_gets_b(tab
, "substrcompl", &c
->substrcompl
);
85 if(extl_table_gets_i(tab
, "autoshowcompl_delay",
86 &c
->autoshowcompl_delay
)){
87 c
->autoshowcompl_delay
=maxof(c
->autoshowcompl_delay
, 0);
92 * Get module configuration. For more information see
93 * \fnref{mod_query.set}.
97 ExtlTab
mod_query_get()
99 ModQueryConfig
*c
=&mod_query_config
;
100 ExtlTab tab
=extl_create_table();
102 extl_table_sets_b(tab
, "autoshowcompl", c
->autoshowcompl
);
103 extl_table_sets_i(tab
, "autoshowcompl_delay", c
->autoshowcompl_delay
);
104 extl_table_sets_b(tab
, "caseicompl", c
->caseicompl
);
105 extl_table_sets_b(tab
, "substrcompl", c
->substrcompl
);
114 /*{{{ Init & deinit */
117 static void load_history()
122 if(!extl_read_savefile("saved_queryhist", &tab
))
125 n
=extl_table_get_n(tab
);
129 if(extl_table_geti_s(tab
, i
, &s
)){
130 mod_query_history_push(s
);
135 extl_unref_table(tab
);
139 static void save_history()
141 ExtlTab tab
=mod_query_history_table();
143 extl_write_savefile("saved_queryhist", tab
);
145 extl_unref_table(tab
);
149 static bool loaded_ok
=FALSE
;
151 void mod_query_deinit()
153 mod_query_unregister_exports();
155 if(mod_query_input_bindmap
!=NULL
){
156 ioncore_free_bindmap("WInput", mod_query_input_bindmap
);
157 mod_query_input_bindmap
=NULL
;
160 if(mod_query_wedln_bindmap
!=NULL
){
161 ioncore_free_bindmap("WEdln", mod_query_wedln_bindmap
);
162 mod_query_wedln_bindmap
=NULL
;
165 hook_remove(ioncore_snapshot_hook
, save_history
);
169 bool mod_query_init()
171 if(!mod_query_register_exports())
174 mod_query_input_bindmap
=ioncore_alloc_bindmap("WInput", NULL
);
175 mod_query_wedln_bindmap
=ioncore_alloc_bindmap("WEdln", NULL
);
177 if(mod_query_wedln_bindmap
==NULL
||
178 mod_query_input_bindmap
==NULL
){
182 /*ioncore_read_config("cfg_query", NULL, TRUE);*/
188 hook_add(ioncore_snapshot_hook
, save_history
);