1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/*
* ion/mod_query/main.c
*
* Copyright (c) Tuomo Valkonen 1999-2007.
*
* See the included file LICENSE for details.
*/
#include <libextl/readconfig.h>
#include <libextl/extl.h>
#include <libtu/minmax.h>
#include <ioncore/binding.h>
#include <ioncore/conf-bindings.h>
#include <ioncore/frame.h>
#include <ioncore/saveload.h>
#include <ioncore/bindmaps.h>
#include <ioncore/ioncore.h>
#include "query.h"
#include "edln.h"
#include "wedln.h"
#include "input.h"
#include "complete.h"
#include "history.h"
#include "exports.h"
#include "main.h"
/*{{{ Module information */
#include "../version.h"
char mod_query_ion_api_version[]=NOTION_API_VERSION;
/*}}}*/
/*{{{ Bindmaps */
WBindmap *mod_query_input_bindmap=NULL;
WBindmap *mod_query_wedln_bindmap=NULL;
/*}}}*/
/*{{{ Set & get */
ModQueryConfig mod_query_config={
250,
TRUE,
TRUE
};
/*EXTL_DOC
* Set module configuration. The following are supported:
*
* \begin{tabularx}{\linewidth}{lX}
* \tabhead{Field & Description}
* \var{autoshowcompl} & (boolean) Is auto-show-completions enabled?
* (default: true). \\
* \var{autoshowcompl_delay} & (integer) auto-show-completions delay
* in milliseconds (default: 250). \\
* \var{caseicompl} & (boolean) Turn some completions case-insensitive
* (default: true). \\
* \end{tabularx}
*/
EXTL_EXPORT
void mod_query_set(ExtlTab tab)
{
ModQueryConfig *c=&mod_query_config;
extl_table_gets_b(tab, "autoshowcompl", &c->autoshowcompl);
extl_table_gets_b(tab, "caseicompl", &c->caseicompl);
if(extl_table_gets_i(tab, "autoshowcompl_delay",
&c->autoshowcompl_delay)){
c->autoshowcompl_delay=MAXOF(c->autoshowcompl_delay, 0);
}
}
/*EXTL_DOC
* Get module configuration. For more information see
* \fnref{mod_query.set}.
*/
EXTL_SAFE
EXTL_EXPORT
ExtlTab mod_query_get()
{
ModQueryConfig *c=&mod_query_config;
ExtlTab tab=extl_create_table();
extl_table_sets_b(tab, "autoshowcompl", c->autoshowcompl);
extl_table_sets_b(tab, "caseicompl", c->caseicompl);
extl_table_sets_i(tab, "autoshowcompl_delay", c->autoshowcompl_delay);
return tab;
}
/*}}}*/
/*{{{ Init & deinit */
static void load_history()
{
ExtlTab tab;
int i, n;
if(!extl_read_savefile("saved_queryhist", &tab))
return;
n=extl_table_get_n(tab);
for(i=n; i>=1; i--){
char *s=NULL;
if(extl_table_geti_s(tab, i, &s)){
mod_query_history_push(s);
free(s);
}
}
extl_unref_table(tab);
}
static void save_history()
{
ExtlTab tab=mod_query_history_table();
extl_write_savefile("saved_queryhist", tab);
extl_unref_table(tab);
}
static bool loaded_ok=FALSE;
void mod_query_deinit()
{
mod_query_unregister_exports();
if(mod_query_input_bindmap!=NULL){
ioncore_free_bindmap("WInput", mod_query_input_bindmap);
mod_query_input_bindmap=NULL;
}
if(mod_query_wedln_bindmap!=NULL){
ioncore_free_bindmap("WEdln", mod_query_wedln_bindmap);
mod_query_wedln_bindmap=NULL;
}
hook_remove(ioncore_snapshot_hook, save_history);
}
bool mod_query_init()
{
if(!mod_query_register_exports())
goto err;
mod_query_input_bindmap=ioncore_alloc_bindmap("WInput", NULL);
mod_query_wedln_bindmap=ioncore_alloc_bindmap("WEdln", NULL);
if(mod_query_wedln_bindmap==NULL ||
mod_query_input_bindmap==NULL){
goto err;
}
/*ioncore_read_config("cfg_query", NULL, TRUE);*/
load_history();
loaded_ok=TRUE;
hook_add(ioncore_snapshot_hook, save_history);
return TRUE;
err:
mod_query_deinit();
return FALSE;
}
/*}}}*/
|