~ubuntu-branches/debian/sid/geany-plugins/sid

« back to all changes in this revision

Viewing changes to geanylua/glspi_app.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-07-10 22:56:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090710225641-xc1126t7pq0jmpos
Tags: upstream-0.17.1
ImportĀ upstreamĀ versionĀ 0.17.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * glspi_app.c - This file is part of the Lua scripting plugin for the Geany IDE
 
4
 * See the file "geanylua.c" for copyright information.
 
5
 */
 
6
 
 
7
#include <sys/stat.h>
 
8
#include <stdlib.h>
 
9
#include <errno.h>
 
10
 
 
11
 
 
12
#define NEED_FAIL_ARG_TYPE
 
13
#include "glspi.h"
 
14
 
 
15
 
 
16
static gint glspi_pluginver(lua_State* L)
 
17
{
 
18
        lua_pushfstring(L, _(
 
19
"%s %s: %s\n"
 
20
"Copyright (c) 2007-2008 "PLUGIN_AUTHOR", et al.\n"
 
21
"Compiled on "__DATE__" at "__TIME__" for Geany API version %d\n"
 
22
"Released under version 2 of the GNU General Public License.\n"
 
23
        ),
 
24
                        PLUGIN_NAME, PLUGIN_VER, PLUGIN_DESC, MY_GEANY_API_VER);
 
25
        return 1;
 
26
}
 
27
 
 
28
 
 
29
static gint glspi_tools(lua_State* L)
 
30
{
 
31
        lua_newtable(L);
 
32
        SetTableStr("browser", geany_data->tool_prefs->browser_cmd);
 
33
        SetTableStr("make",    geany_data->tool_prefs->make_cmd);
 
34
        SetTableStr("term",    geany_data->tool_prefs->term_cmd);
 
35
        SetTableStr("grep",    geany_data->tool_prefs->grep_cmd);
 
36
        SetTableStr("action",  geany_data->tool_prefs->context_action_cmd);
 
37
        return 1;
 
38
}
 
39
 
 
40
 
 
41
static gint glspi_template(lua_State* L)
 
42
{
 
43
        lua_newtable(L);
 
44
        SetTableStr("developer", geany_data->template_prefs->developer);
 
45
        SetTableStr("company",   geany_data->template_prefs->company);
 
46
        SetTableStr("mail",      geany_data->template_prefs->mail);
 
47
        SetTableStr("initial",   geany_data->template_prefs->initials);
 
48
        SetTableStr("version",   geany_data->template_prefs->version);
 
49
        return 1;
 
50
}
 
51
 
 
52
 
 
53
 
 
54
static gint glspi_project(lua_State* L)
 
55
{
 
56
        GeanyProject *project = geany->app->project;
 
57
        
 
58
        if (project) {
 
59
                lua_newtable(L);
 
60
                SetTableStr("name", project->name);
 
61
                SetTableStr("desc", project->description);
 
62
                SetTableStr("file", project->file_name);
 
63
                SetTableStr("base", project->base_path);
 
64
                SetTableStr("exec", project->run_cmd);
 
65
                if (project->file_patterns && *project->file_patterns) {
 
66
                        gchar *tmp=g_strjoinv(";", project->file_patterns);
 
67
                        SetTableStr("mask", tmp);
 
68
                        g_free(tmp);
 
69
                }
 
70
                return 1;
 
71
        } else {
 
72
                return 0;
 
73
        }
 
74
}
 
75
 
 
76
static gchar *glspi_script_dir = NULL;
 
77
 
 
78
static gint glspi_appinfo(lua_State* L)
 
79
{
 
80
        GeanyApp *app = geany->app;
 
81
        
 
82
        lua_newtable(L);
 
83
        SetTableBool("debug", app->debug_mode);
 
84
        SetTableStr("configdir", app->configdir);
 
85
        SetTableStr("datadir", app->datadir);
 
86
        SetTableStr("docdir", app->docdir);
 
87
        SetTableStr("scriptdir", glspi_script_dir);
 
88
        lua_pushstring(L,"template");
 
89
        glspi_template(L);
 
90
        lua_rawset(L,1);
 
91
 
 
92
        lua_pushstring(L,"tools");
 
93
        glspi_tools(L);
 
94
        lua_rawset(L,1);
 
95
 
 
96
        if (app->project) {
 
97
                lua_pushstring(L,"project");
 
98
                glspi_project(L);
 
99
                lua_rawset(L,1);
 
100
        }
 
101
        return 1;
 
102
}
 
103
 
 
104
 
 
105
 
 
106
#ifndef G_OS_WIN32
 
107
 
 
108
#define CLIPBOARD gtk_clipboard_get(GDK_SELECTION_PRIMARY)
 
109
 
 
110
static gint glspi_xsel(lua_State* L)
 
111
{
 
112
        if (lua_gettop(L)>0) {
 
113
                if (lua_isstring(L,1)) {
 
114
                        guint len;
 
115
                        const gchar*txt=lua_tolstring(L,1,&len);
 
116
                        gtk_clipboard_set_text(CLIPBOARD,txt,len);
 
117
                } else {
 
118
                        FAIL_STRING_ARG(1);
 
119
                }
 
120
                return 0;
 
121
        } else {
 
122
                gchar *txt=gtk_clipboard_wait_for_text(CLIPBOARD);
 
123
                if (txt) {
 
124
                        lua_pushstring(L,txt);
 
125
                        g_free(txt);
 
126
                } else {
 
127
                        lua_pushstring(L,"");
 
128
                }
 
129
                return 1;
 
130
        }
 
131
}
 
132
 
 
133
#else
 
134
static gint glspi_xsel(lua_State* L) { return 0; }
 
135
#endif
 
136
 
 
137
 
 
138
 
 
139
 
 
140
static gint glspi_signal(lua_State* L) {
 
141
        const gchar*widname,*signame;
 
142
        GtkWidget*w;
 
143
        GType typeid;
 
144
        guint sigid;
 
145
        if ((lua_gettop(L)<2)||!lua_isstring(L,2) ) {   return FAIL_STRING_ARG(2); }
 
146
        if (!lua_isstring(L,1) ) {      return FAIL_STRING_ARG(1); }
 
147
        widname=lua_tostring(L,1);
 
148
        signame=lua_tostring(L,2);
 
149
        w=ui_lookup_widget(main_widgets->window, widname);
 
150
        if (!w) {
 
151
                lua_pushfstring(L, _("Error in module \"%s\" at function %s():\n"
 
152
                        "widget \"%s\"  not found for argument #1.\n "),
 
153
                        LUA_MODULE_NAME, &__FUNCTION__[6], widname);
 
154
                        lua_error(L);
 
155
                return 0;
 
156
        }
 
157
        typeid=G_OBJECT_TYPE(w);
 
158
        sigid=g_signal_lookup(signame,typeid);
 
159
        if (!sigid) {
 
160
                lua_pushfstring(L, _("Error in module \"%s\" at function %s() argument #2:\n"
 
161
                        "widget \"%s\" has no signal named \"%s\".\n "),
 
162
                        LUA_MODULE_NAME, &__FUNCTION__[6], widname, signame);
 
163
                        lua_error(L);
 
164
                return 0;
 
165
        }
 
166
 
 
167
        g_signal_emit(w, sigid, 0);
 
168
        return 0;
 
169
}
 
170
 
 
171
 
 
172
 
 
173
 
 
174
#ifdef G_OS_WIN32
 
175
#define lstat stat
 
176
#define realpath(src,dst) _fullpath((dst),(src),_MAX_PATH)
 
177
#include <io.h>
 
178
#else
 
179
#include <unistd.h>
 
180
#endif
 
181
 
 
182
typedef int (*statfunc) (const char *fn, struct stat *st);
 
183
 
 
184
static gint glspi_stat(lua_State* L)
 
185
{
 
186
        statfunc sf=stat;
 
187
        const gchar*fn=NULL;
 
188
        struct stat st;
 
189
        if (lua_gettop(L)<1) { return FAIL_STRING_ARG(1); }
 
190
        if (lua_gettop(L)>=2) {
 
191
                if (!lua_isboolean(L,2)) { return FAIL_BOOL_ARG(2); }
 
192
                sf=lua_toboolean(L,2)?lstat:stat;
 
193
        }
 
194
        if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
195
        fn=lua_tostring(L,1);
 
196
        if (sf(fn,&st)==0) {
 
197
                gchar *ft=NULL;
 
198
                switch ( st.st_mode & S_IFMT) {
 
199
                        case S_IFBLK:ft="b"; break;
 
200
                        case S_IFCHR:ft="c"; break;
 
201
                        case S_IFDIR:ft="d"; break;
 
202
                        case S_IFIFO:ft="f"; break;
 
203
                        case S_IFREG:ft="r"; break;
 
204
#ifndef G_OS_WIN32
 
205
                        case S_IFLNK:ft="l"; break;
 
206
                        case S_IFSOCK:ft="s"; break;
 
207
#endif
 
208
                }
 
209
                lua_newtable(L);
 
210
                SetTableNum("size",st.st_size);
 
211
                SetTableNum("time",st.st_mtime);
 
212
                SetTableStr("type",ft);
 
213
                SetTableBool("read", (access(fn,R_OK)==0));
 
214
                SetTableBool("write", (access(fn,W_OK)==0));
 
215
                SetTableBool("exec", (access(fn,X_OK)==0));
 
216
                return 1;
 
217
        }
 
218
        lua_pushnil(L);
 
219
        lua_pushstring(L, strerror(errno));
 
220
        return 2;
 
221
}
 
222
 
 
223
 
 
224
static gint glspi_basename(lua_State* L)
 
225
{
 
226
        if (lua_gettop(L)>=1) {
 
227
                gchar *bn=NULL;
 
228
                const gchar *fn=NULL;
 
229
                if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
230
                fn=lua_tostring(L,1);
 
231
                bn=g_path_get_basename(fn);
 
232
                lua_pushstring(L,bn);
 
233
                g_free(bn);
 
234
                return 1;
 
235
        }
 
236
        return 0;
 
237
}
 
238
 
 
239
 
 
240
static gint glspi_dirname(lua_State* L)
 
241
{
 
242
        if (lua_gettop(L)>=1) {
 
243
                gchar *dn=NULL;
 
244
                const gchar *fn=NULL;
 
245
                if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
246
                fn=lua_tostring(L,1);
 
247
                dn=g_path_get_dirname(fn);
 
248
                lua_pushstring(L,dn);
 
249
                g_free(dn);
 
250
                return 1;
 
251
        }
 
252
        return 0;
 
253
}
 
254
 
 
255
 
 
256
 
 
257
 
 
258
static gint glspi_fullpath(lua_State* L)
 
259
{
 
260
        if (lua_gettop(L)>=1) {
 
261
                gchar *rp=NULL;
 
262
                const gchar *fn=NULL;
 
263
                if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
264
                fn=lua_tostring(L,1);
 
265
                rp=realpath(fn,NULL);
 
266
                if (rp) {
 
267
                        lua_pushstring(L,rp);
 
268
                        free(rp);
 
269
                        return 1;
 
270
                }
 
271
        }
 
272
        return 0;
 
273
}
 
274
 
 
275
 
 
276
 
 
277
static gint dirlist_closure(lua_State *L)
 
278
{
 
279
        GDir*dir=lua_touserdata(L,lua_upvalueindex(1));
 
280
        const gchar*entry=g_dir_read_name(dir);
 
281
        if (entry) {
 
282
                lua_pushstring(L,entry);
 
283
                return 1;
 
284
        } else {
 
285
                g_dir_close(dir);
 
286
                return 0;
 
287
        }
 
288
}
 
289
 
 
290
 
 
291
 
 
292
static gint glspi_dirlist(lua_State* L)
 
293
{
 
294
        GDir*dir=NULL;
 
295
        const gchar*dn=".";
 
296
        GError*err=NULL;
 
297
        if (lua_gettop(L)>=1) {
 
298
                if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
299
                dn=lua_tostring(L,1);
 
300
        }
 
301
        dir=g_dir_open(dn,0,&err);
 
302
        if (dir) {
 
303
                lua_pushlightuserdata(L,dir);
 
304
                lua_pushcclosure(L,&dirlist_closure,1);
 
305
                return 1;
 
306
        } else {
 
307
                lua_pushfstring(L, "Error in module \"%s\" at function %s() argument #2\n%s",
 
308
                LUA_MODULE_NAME, &__FUNCTION__[6],err?err->message:"Error reading directory."
 
309
                );
 
310
                if (err) {g_error_free(err);}
 
311
                lua_error(L);
 
312
                return 0;
 
313
        }
 
314
        return 0;
 
315
}
 
316
 
 
317
 
 
318
 
 
319
static gint glspi_wkdir(lua_State* L)
 
320
{
 
321
        if (lua_gettop(L)== 0 ) {
 
322
                gchar*wd=getcwd(NULL,0);
 
323
                if (wd) {
 
324
                        lua_pushstring(L,wd);
 
325
                        free(wd);
 
326
                        return 1;
 
327
                } else { return 0; }
 
328
        } else {
 
329
                if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
 
330
                if ( chdir(lua_tostring(L,1)) == 0 ) {
 
331
                        lua_pushboolean(L,TRUE);
 
332
                        return 1;
 
333
                } else {
 
334
                        lua_pushboolean(L,FALSE);
 
335
                        lua_pushstring(L, strerror(errno));
 
336
                        return 2;
 
337
                }
 
338
        }
 
339
}
 
340
 
 
341
 
 
342
#include "glspi_keycmd.h"
 
343
 
 
344
static GHashTable*key_cmd_hash=NULL;
 
345
 
 
346
static void glspi_init_key_cmd_hash(void)
 
347
{
 
348
        gint i;
 
349
        key_cmd_hash=g_hash_table_new(g_str_hash,g_str_equal);
 
350
        for (i=0;key_cmd_hash_entries[i].name; i++) {
 
351
                g_hash_table_insert(
 
352
                        key_cmd_hash,key_cmd_hash_entries[i].name,&key_cmd_hash_entries[i]);
 
353
        }
 
354
}
 
355
 
 
356
 
 
357
static void glspi_free_key_cmd_hash(void) {
 
358
        if (key_cmd_hash) {
 
359
                g_hash_table_destroy(key_cmd_hash);
 
360
                key_cmd_hash=NULL;
 
361
        }
 
362
}
 
363
 
 
364
void glspi_set_key_cmd_hash(gboolean create) {
 
365
        if (create) {
 
366
                glspi_init_key_cmd_hash ();
 
367
        } else {
 
368
                glspi_free_key_cmd_hash();
 
369
        }
 
370
}
 
371
 
 
372
 
 
373
 
 
374
#define lookup_key_cmd_str(cmd) g_hash_table_lookup(key_cmd_hash,cmd);
 
375
 
 
376
 
 
377
static gint glspi_keycmd(lua_State* L)
 
378
{
 
379
        KeyCmdHashEntry*he=NULL;
 
380
        if (lua_gettop(L)<1) {return FAIL_STRING_ARG(1); }
 
381
        if (lua_isstring(L,1)) {
 
382
                gchar cmdbuf[64];
 
383
                gchar *cmdname;
 
384
                gint i;
 
385
                memset(cmdbuf,'\0', sizeof(cmdbuf));
 
386
                strncpy(cmdbuf,lua_tostring(L,1),sizeof(cmdbuf)-1);
 
387
                for (i=0;cmdbuf[i];i++) {cmdbuf[i]=g_ascii_toupper(cmdbuf[i]);}
 
388
                cmdname=cmdbuf;
 
389
                if (strncmp(cmdname,"GEANY_",6)==0) {
 
390
                        cmdname+=6;
 
391
                        if (strncmp(cmdname,"KEYS_",5)==0) {
 
392
                                cmdname+=5;
 
393
                        }
 
394
                }
 
395
                he=lookup_key_cmd_str(cmdname);
 
396
        } else { return FAIL_STRING_ARG(1); }
 
397
        if ( !he ) {
 
398
                lua_pushfstring(
 
399
                        L, _( "Error in module \"%s\" at function %s():\n"
 
400
                                                "unknown command \"%s\" given for argument #1.\n"),
 
401
                                                 LUA_MODULE_NAME, &__FUNCTION__[6], lua_tostring(L,1));
 
402
                lua_error(L);
 
403
                return 0;
 
404
        }
 
405
        keybindings_send_command(he->group, he->key_id);
 
406
        return 0;
 
407
}
 
408
 
 
409
 
 
410
static gint glspi_launch(lua_State* L)
 
411
{
 
412
        gint argc=lua_gettop(L);
 
413
        gint i;
 
414
        gchar **argv=NULL;
 
415
        gboolean rv;
 
416
        GError *err=NULL;
 
417
        if (argc==0) { return FAIL_STRING_ARG(1); }
 
418
        for (i=1;i<=argc;i++) {
 
419
                if (!lua_isstring(L,i)) { return FAIL_STRING_ARG(i); }
 
420
        }
 
421
        argv=g_malloc0(sizeof(gchar *)*argc+1);
 
422
        for (i=0;i<argc;i++) {
 
423
                argv[i]=(g_strdup(lua_tostring(L,i+1)));
 
424
        }
 
425
        rv=g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &err);
 
426
        g_strfreev(argv);
 
427
        lua_pushboolean(L,rv);
 
428
        if (rv) { return 1; }
 
429
  lua_pushstring(L,err->message);
 
430
        g_error_free(err);
 
431
        return 2;
 
432
}
 
433
 
 
434
 
 
435
static guint My_Shift_L=0;
 
436
static guint My_Shift_R=0;
 
437
static guint My_Control_L=0;
 
438
static guint My_Control_R=0;
 
439
static guint My_Alt_L=0;
 
440
static guint My_Alt_R=0;
 
441
 
 
442
 
 
443
#ifndef G_OS_WIN32
 
444
 
 
445
#include <X11/Xlib.h>
 
446
#include <X11/keysym.h>
 
447
#include <sys/time.h>
 
448
 
 
449
 
 
450
#define IsShift ( (My_Shift_L == ev->xkey.keycode) || (My_Shift_R == ev->xkey.keycode) )
 
451
 
 
452
#define IsCtrl ( (My_Control_L == ev->xkey.keycode) || (My_Control_R == ev->xkey.keycode) )
 
453
#define IsAlt ( (My_Alt_L == ev->xkey.keycode) || (My_Alt_R == ev->xkey.keycode) )
 
454
 
 
455
#define IsCtrlAlt ( IsCtrl || IsAlt )
 
456
 
 
457
typedef struct _KeyGrabData {
 
458
gchar *prompt;
 
459
GdkKeymapKey km;
 
460
} _KeyGrabData;
 
461
 
 
462
 
 
463
static GdkFilterReturn keygrab_cb(GdkXEvent *xevent, GdkEvent *event, gpointer data)
 
464
{
 
465
        XEvent*ev = (XEvent*) xevent;
 
466
        GdkKeymapKey *km = (GdkKeymapKey*) data;
 
467
        switch (ev->type) {
 
468
                case KeyPress:{
 
469
                        if (IsShift) {
 
470
                                km->level=1;
 
471
                        } else {
 
472
                                if (!IsCtrlAlt) km->group=1; /* Flag to know we have keydown before keyup */
 
473
                        }
 
474
                        return GDK_FILTER_REMOVE;
 
475
                }
 
476
                case KeyRelease:{
 
477
                        if (IsShift) {
 
478
                                km->level=0;
 
479
                        } else {
 
480
                                if ((km->group==1)&&(!IsCtrlAlt)) { /* OK, we already got our keydown  */
 
481
                                        km->group=2;
 
482
                                        km->level=(ev->xkey.state & ShiftMask)?1:0;
 
483
                                        km->keycode=ev->xkey.keycode;
 
484
                                }
 
485
                        }
 
486
                        return GDK_FILTER_REMOVE;
 
487
                }
 
488
                default:{}
 
489
        }
 
490
        return GDK_FILTER_CONTINUE;
 
491
}
 
492
 
 
493
static void dosleep(void)
 
494
{
 
495
        struct timespec req, rem;
 
496
        req.tv_sec=0;
 
497
        req.tv_nsec=1000;
 
498
        nanosleep(&req, &rem);
 
499
}
 
500
 
 
501
#else
 
502
#include <windows.h>
 
503
#define dosleep() Sleep(1)
 
504
 
 
505
#define IsShift ( (My_Shift_L == msg->wParam) || (My_Shift_R == msg->wParam) )
 
506
 
 
507
#define IsCtrl ( (My_Control_L == msg->wParam) || (My_Control_R == msg->wParam) )
 
508
#define IsAlt ( (My_Alt_L == msg->wParam) || (My_Alt_R == msg->wParam) )
 
509
 
 
510
#define IsCtrlAlt ( IsCtrl || IsAlt )
 
511
 
 
512
 
 
513
static GdkFilterReturn keygrab_cb(GdkXEvent *xevent, GdkEvent *event, gpointer data)
 
514
{
 
515
        MSG*msg = (MSG*) xevent;
 
516
        GdkKeymapKey *km = (GdkKeymapKey*) data;
 
517
        switch (msg->message) {
 
518
                case WM_KEYDOWN:{
 
519
                        if (IsShift) {
 
520
                                km->level=1;
 
521
                        } else {
 
522
                                if (!IsCtrlAlt) km->group=1; /* Flag to know we have keydown before keyup */
 
523
                        }
 
524
                        return GDK_FILTER_REMOVE;
 
525
                }
 
526
                case WM_KEYUP:{
 
527
                        if (IsShift) {
 
528
                                km->level=0;
 
529
                        } else {
 
530
                                if ((km->group==1)&&(!IsCtrlAlt)) { /* OK, we already got our keydown  */
 
531
                                        km->group=2;
 
532
                                        km->level=HIBYTE(GetKeyState(VK_SHIFT))?1:0;
 
533
                                        km->keycode=msg->wParam;
 
534
                                }
 
535
                        }
 
536
                        return GDK_FILTER_REMOVE;
 
537
                }
 
538
                default:{}
 
539
        }
 
540
        return GDK_FILTER_CONTINUE;
 
541
}
 
542
 
 
543
 
 
544
#endif
 
545
 
 
546
 
 
547
#include <gdk/gdkkeysyms.h>
 
548
static gint init_key(guint keyval){
 
549
        GdkKeymapKey *kmk=NULL;
 
550
        gint n_keys=0;
 
551
        gint rv=0;
 
552
        if (gdk_keymap_get_entries_for_keyval(NULL,keyval,&kmk,&n_keys)) {
 
553
                rv=kmk[0].keycode;
 
554
                g_free(kmk);
 
555
        }
 
556
        return rv;
 
557
}
 
558
 
 
559
#define InitKey(code,value) if (!code) { code=init_key(value); }
 
560
 
 
561
static gint glspi_keygrab(lua_State* L)
 
562
{
 
563
        GeanyDocument*doc=NULL;
 
564
        const gchar*prompt=NULL;
 
565
        GdkKeymapKey km={0,0,0};
 
566
        km.keycode=0;
 
567
        km.group=0; /* Note: we hijack this field to use as a flag for first keydown. */
 
568
        km.level=0;
 
569
        InitKey(My_Shift_L, GDK_Shift_L);
 
570
        InitKey(My_Shift_R, GDK_Shift_R);
 
571
        InitKey(My_Control_L, GDK_Control_L);
 
572
        InitKey(My_Control_R, GDK_Control_R);
 
573
        InitKey(My_Alt_L, GDK_Alt_L);
 
574
        InitKey(My_Alt_R, GDK_Alt_R);
 
575
        if (lua_gettop(L)>0) {
 
576
                if (!lua_isstring(L,1)) {return FAIL_STRING_ARG(1); }
 
577
                prompt=lua_tostring(L,1);
 
578
                doc=document_get_current();
 
579
        }
 
580
 
 
581
        if (prompt && doc && doc->is_valid ) {
 
582
                gint fvl=scintilla_send_message(doc->editor->sci,SCI_GETFIRSTVISIBLELINE, 0,0);
 
583
                gint pos=sci_get_position_from_line(doc->editor->sci, fvl+1);
 
584
                scintilla_send_message(doc->editor->sci,SCI_CALLTIPSHOW,pos+3, (gint)prompt);
 
585
        }
 
586
        gdk_window_add_filter(main_widgets->window->window, keygrab_cb, &km);
 
587
        do {
 
588
                while (gtk_events_pending()) {
 
589
                        if (km.group==2) { break; }
 
590
                        gtk_main_iteration();
 
591
                }
 
592
                if (km.group==2) { break; }
 
593
                dosleep();
 
594
        } while (km.group!=2);
 
595
 
 
596
        gdk_window_remove_filter(main_widgets->window->window, keygrab_cb, &km);
 
597
        if (prompt && doc && doc->is_valid) {
 
598
        sci_send_command(doc->editor->sci, SCI_CALLTIPCANCEL);
 
599
        }
 
600
        km.group=0; /* reset the hijacked flag before passing to GDK */
 
601
        lua_pushstring(L, gdk_keyval_name(gdk_keymap_lookup_key(NULL, &km)));
 
602
 
 
603
        return 1;
 
604
}
 
605
 
 
606
 
 
607
 
 
608
static const struct luaL_reg glspi_app_funcs[] = {
 
609
        {"pluginver", glspi_pluginver},
 
610
        {"appinfo",   glspi_appinfo},
 
611
        {"xsel",      glspi_xsel},
 
612
        {"signal",    glspi_signal},
 
613
        {"stat",      glspi_stat},
 
614
        {"basename",  glspi_basename},
 
615
        {"dirname",   glspi_dirname},
 
616
        {"fullpath",  glspi_fullpath},
 
617
        {"dirlist",   glspi_dirlist},
 
618
        {"wkdir",     glspi_wkdir},
 
619
        {"keycmd",    glspi_keycmd},
 
620
        {"launch",    glspi_launch},
 
621
        {"keygrab",   glspi_keygrab},
 
622
        {NULL,NULL}
 
623
};
 
624
 
 
625
void glspi_init_app_funcs(lua_State *L, gchar*script_dir) {
 
626
        glspi_script_dir = script_dir;
 
627
        luaL_register(L, NULL,glspi_app_funcs);
 
628
}
 
629