46
50
int text_do_suggest_select(SpaceText *st, ARegion *ar)
48
SuggItem *item, *first, *last, *sel;
52
SuggItem *item, *first, *last /* , *sel */ /* UNUSED */;
50
54
int l, x, y, w, h, i;
52
short mval[2] = {0, 0};
54
if(!st || !st->text) return 0;
55
if(!texttool_text_is_active(st->text)) return 0;
58
if (!st || !st->text) return 0;
59
if (!texttool_text_is_active(st->text)) return 0;
57
61
first = texttool_suggest_first();
58
62
last = texttool_suggest_last();
59
sel = texttool_suggest_selected();
63
/* sel = texttool_suggest_selected(); */ /* UNUSED */
60
64
top = texttool_suggest_top();
65
69
/* Count the visible lines to the cursor */
66
for(tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
70
for (tmp = st->text->curl, l = -st->top; tmp; tmp = tmp->prev, l++) ;
69
73
text_update_character_width(st);
72
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
75
if (st->showlinenrs) {
76
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET + TEXTXLOC - 4;
75
x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
79
x = st->cwidth * (st->text->curc - st->left) + TXT_OFFSET - 4;
77
y = ar->winy - st->lheight*l - 2;
81
y = ar->winy - st->lheight * l - 2;
79
w = SUGG_LIST_WIDTH*st->cwidth + 20;
80
h = SUGG_LIST_SIZE*st->lheight + 8;
83
w = SUGG_LIST_WIDTH * st->cwidth + 20;
84
h = SUGG_LIST_SIZE * st->lheight + 8;
82
86
// XXX getmouseco_areawin(mval);
84
if(mval[0]<x || x+w<mval[0] || mval[1]<y-h || y<mval[1])
88
if (mval[0] < x || x + w < mval[0] || mval[1] < y - h || y < mval[1])
87
91
/* Work out which of the items is at the top of the visible list */
88
for(i=0, item=first; i<*top && item->next; i++, item=item->next);
92
for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
90
94
/* Work out the target item index in the visible list */
91
tgti = (y-mval[1]-4) / st->lheight;
92
if(tgti<0 || tgti>SUGG_LIST_SIZE)
95
tgti = (y - mval[1] - 4) / st->lheight;
96
if (tgti < 0 || tgti > SUGG_LIST_SIZE)
95
for(i=tgti; i>0 && item->next; i--, item=item->next);
99
for (i = tgti; i > 0 && item->next; i--, item = item->next) ;
97
101
texttool_suggest_select(item);
101
void text_pop_suggest_list()
105
void text_pop_suggest_list(void)
103
107
SuggItem *item, *sel;
106
item= texttool_suggest_first();
107
sel= texttool_suggest_selected();
108
top= texttool_suggest_top();
110
item = texttool_suggest_first();
111
sel = texttool_suggest_selected();
112
top = texttool_suggest_top();
111
while(item && item != sel) {
115
while (item && item != sel) {
115
if(i > *top+SUGG_LIST_SIZE-1)
116
*top= i-SUGG_LIST_SIZE+1;
119
if (i > *top + SUGG_LIST_SIZE - 1)
120
*top = i - SUGG_LIST_SIZE + 1;
121
125
static void get_suggest_prefix(Text *text, int offset)
182
186
#define LR_SHIFTKEY 0
183
187
#define LR_ALTKEY 0
184
188
#define LR_CTRLKEY 0
185
#define LR_COMMANDKEY 0
188
static int doc_scroll= 0;
192
static int doc_scroll = 0;
190
short do_texttools(SpaceText *st, char ascii, unsigned short evnt, short val)
194
static short UNUSED_FUNCTION(do_texttools) (SpaceText * st, char ascii, unsigned short evnt, short val)
192
ARegion *ar= NULL; // XXX
194
int draw=0, tools=0, swallow=0, scroll=1;
195
if(!texttool_text_is_active(st->text)) return 0;
196
if(!st->text || st->text->id.lib) return 0;
196
ARegion *ar = NULL; // XXX
198
int draw = 0, tools = 0, swallow = 0, scroll = 1;
199
if (!texttool_text_is_active(st->text)) return 0;
200
if (!st->text || st->text->id.lib) return 0;
198
if(st->doplugins && texttool_text_is_active(st->text)) {
199
if(texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
200
if(texttool_docs_get()) tools |= TOOL_DOCUMENT;
202
if (st->doplugins && texttool_text_is_active(st->text)) {
203
if (texttool_suggest_first()) tools |= TOOL_SUGG_LIST;
204
if (texttool_docs_get()) tools |= TOOL_DOCUMENT;
204
if(tools & TOOL_SUGG_LIST) {
205
if((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
208
if (tools & TOOL_SUGG_LIST) {
209
if ((ascii != '_' && ascii != '*' && ispunct(ascii)) || text_check_whitespace(ascii)) {
206
210
confirm_suggestion(st->text, 0);
207
text_update_line_edited(st->text, st->text->curl);
211
text_update_line_edited(st->text->curl);
209
else if((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
213
else if ((st->overwrite && txt_replace_char(st->text, ascii)) || txt_add_char(st->text, ascii)) {
210
214
get_suggest_prefix(st->text, 0);
211
215
text_pop_suggest_list();
216
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
220
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
219
else if(val==1 && evnt) {
223
else if (val == 1 && evnt) {
222
if(text_do_suggest_select(st, ar))
226
if (text_do_suggest_select(st, ar))
225
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
226
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
229
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
230
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
230
234
case MIDDLEMOUSE:
231
if(text_do_suggest_select(st, ar)) {
235
if (text_do_suggest_select(st, ar)) {
232
236
confirm_suggestion(st->text, 0);
233
text_update_line_edited(st->text, st->text->curl);
237
text_update_line_edited(st->text->curl);
237
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
238
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
241
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
242
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
244
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear();
245
else if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
246
else draw= swallow= 0;
248
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear();
249
else if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
250
else draw = swallow = 0;
249
if(tools & TOOL_SUGG_LIST) {
253
if (tools & TOOL_SUGG_LIST) {
250
254
confirm_suggestion(st->text, 0);
251
text_update_line_edited(st->text, st->text->curl);
255
text_update_line_edited(st->text->curl);
255
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
259
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
257
261
case LEFTARROWKEY:
258
262
case BACKSPACEKEY:
259
if(tools & TOOL_SUGG_LIST) {
263
if (tools & TOOL_SUGG_LIST) {
261
265
texttool_suggest_clear();
263
267
/* Work out which char we are about to delete/pass */
264
if(st->text->curl && st->text->curc > 0) {
265
char ch= st->text->curl->line[st->text->curc-1];
266
if((ch=='_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
268
if (st->text->curl && st->text->curc > 0) {
269
char ch = st->text->curl->line[st->text->curc - 1];
270
if ((ch == '_' || !ispunct(ch)) && !text_check_whitespace(ch)) {
267
271
get_suggest_prefix(st->text, -1);
268
272
text_pop_suggest_list();
295
299
texttool_suggest_clear();
298
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0;
302
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0;
300
304
case PAGEDOWNKEY:
301
scroll= SUGG_LIST_SIZE-1;
305
scroll = SUGG_LIST_SIZE - 1;
302
306
case WHEELDOWNMOUSE:
303
307
case DOWNARROWKEY:
304
if(tools & TOOL_DOCUMENT) {
308
if (tools & TOOL_DOCUMENT) {
310
else if(tools & TOOL_SUGG_LIST) {
314
else if (tools & TOOL_SUGG_LIST) {
311
315
SuggItem *sel = texttool_suggest_selected();
313
317
texttool_suggest_select(texttool_suggest_first());
315
else while(sel && sel!=texttool_suggest_last() && sel->next && scroll--) {
316
texttool_suggest_select(sel->next);
320
while (sel && sel != texttool_suggest_last() && sel->next && scroll--) {
321
texttool_suggest_select(sel->next);
319
325
text_pop_suggest_list();
325
scroll= SUGG_LIST_SIZE-1;
331
scroll = SUGG_LIST_SIZE - 1;
326
332
case WHEELUPMOUSE:
328
if(tools & TOOL_DOCUMENT) {
329
if(doc_scroll>0) doc_scroll--;
334
if (tools & TOOL_DOCUMENT) {
335
if (doc_scroll > 0) doc_scroll--;
334
else if(tools & TOOL_SUGG_LIST) {
340
else if (tools & TOOL_SUGG_LIST) {
335
341
SuggItem *sel = texttool_suggest_selected();
336
while(sel && sel!=texttool_suggest_first() && sel->prev && scroll--) {
342
while (sel && sel != texttool_suggest_first() && sel->prev && scroll--) {
337
343
texttool_suggest_select(sel->prev);
340
346
text_pop_suggest_list();
345
351
case RIGHTSHIFTKEY:
346
352
case LEFTSHIFTKEY:
349
if(tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw= 1;
350
if(tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll= 0, draw= 1;
355
if (tools & TOOL_SUGG_LIST) texttool_suggest_clear(), draw = 1;
356
if (tools & TOOL_DOCUMENT) texttool_docs_clear(), doc_scroll = 0, draw = 1;
355
{}; // XXX redraw_alltext();
361
// XXX redraw_alltext();
361
#ifndef DISABLE_PYTHON
362
/* Run text plugin scripts if enabled */
363
if(st->doplugins && event && val) {
364
if(BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
369
/* Run text plugin scripts if enabled */
370
if (st->doplugins && event && val)
372
if (BPY_menu_do_shortcut(PYMENU_TEXTPLUGIN, event, qual)) {
370
; // XXX redraw_alltext();
378
; // XXX redraw_alltext();
373
short do_textmarkers(SpaceText *st, char ascii, unsigned short evnt, short val)
381
static short UNUSED_FUNCTION(do_textmarkers) (SpaceText * st, char ascii, unsigned short evnt, short val)
376
384
TextMarker *marker, *mrk, *nxt;
377
int c, s, draw=0, swallow=0;
381
if(!text || text->id.lib || text->curl != text->sell) return 0;
383
marker= txt_find_marker(text, text->sell, text->selc, 0, 0);
384
if(marker && (marker->start > text->curc || marker->end < text->curc))
385
int c, s, draw = 0, swallow = 0;
389
if (!text || text->id.lib || text->curl != text->sell) return 0;
391
marker = txt_find_marker(text, text->sell, text->selc, 0, 0);
392
if (marker && (marker->start > text->curc || marker->end < text->curc))
388
396
/* Find the next temporary marker */
390
int lineno= txt_get_span(text->lines.first, text->curl);
391
TextMarker *mrk= text->markers.first;
393
if(!marker && (mrk->flags & TMARK_TEMP)) marker= mrk;
394
if((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno==lineno && mrk->end > text->curc))) {
397
if (evnt == TABKEY) {
398
int lineno = txt_get_span(text->lines.first, text->curl);
399
mrk = text->markers.first;
401
if (!marker && (mrk->flags & TMARK_TEMP)) marker = mrk;
402
if ((mrk->flags & TMARK_TEMP) && (mrk->lineno > lineno || (mrk->lineno == lineno && mrk->end > text->curc))) {
401
409
txt_move_to(text, marker->lineno, marker->start, 0);
402
410
txt_move_to(text, marker->lineno, marker->end, 1);
403
411
// XXX text_update_cursor_moved(C);
404
412
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
413
evnt = ascii = val = 0;
410
else if(evnt==ESCKEY) {
411
if(txt_clear_markers(text, 0, TMARK_TEMP)) swallow= 1;
412
else if(txt_clear_markers(text, 0, 0)) swallow= 1;
418
else if (evnt == ESCKEY) {
419
if (txt_clear_markers(text, 0, TMARK_TEMP)) swallow = 1;
420
else if (txt_clear_markers(text, 0, 0)) swallow = 1;
422
evnt = ascii = val = 0;
417
if(!swallow) return 0;
425
if (!swallow) return 0;
421
if(marker->flags & TMARK_EDITALL) {
422
c= text->curc-marker->start;
423
s= text->selc-marker->start;
424
if(s<0 || s>marker->end-marker->start) return 0;
429
if (marker->flags & TMARK_EDITALL) {
430
c = text->curc - marker->start;
431
s = text->selc - marker->start;
432
if (s < 0 || s > marker->end - marker->start) return 0;
426
mrk= txt_next_marker(text, marker);
428
nxt=txt_next_marker(text, mrk); /* mrk may become invalid */
429
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
430
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
432
if(txt_replace_char(text, ascii))
433
text_update_line_edited(st->text, st->text->curl);
434
mrk = txt_next_marker(text, marker);
436
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
437
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
438
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
440
if (txt_replace_char(text, ascii))
441
text_update_line_edited(st->text->curl);
436
if(txt_add_char(text, ascii)) {
437
text_update_line_edited(st->text, st->text->curl);
444
if (txt_add_char(text, ascii)) {
445
text_update_line_edited(st->text->curl);
441
if(mrk==marker || mrk==nxt) break;
449
if (mrk == marker || mrk == nxt) break;
450
458
case BACKSPACEKEY:
451
if(marker->flags & TMARK_EDITALL) {
452
c= text->curc-marker->start;
453
s= text->selc-marker->start;
454
if(s<0 || s>marker->end-marker->start) return 0;
459
if (marker->flags & TMARK_EDITALL) {
460
c = text->curc - marker->start;
461
s = text->selc - marker->start;
462
if (s < 0 || s > marker->end - marker->start) return 0;
456
mrk= txt_next_marker(text, marker);
458
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
459
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
460
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
464
mrk = txt_next_marker(text, marker);
466
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
467
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
468
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
461
469
txt_backspace_char(text);
462
text_update_line_edited(st->text, st->text->curl);
463
if(mrk==marker || mrk==nxt) break;
470
text_update_line_edited(st->text->curl);
471
if (mrk == marker || mrk == nxt) break;
471
if(marker->flags & TMARK_EDITALL) {
472
c= text->curc-marker->start;
473
s= text->selc-marker->start;
474
if(s<0 || s>marker->end-marker->start) return 0;
479
if (marker->flags & TMARK_EDITALL) {
480
c = text->curc - marker->start;
481
s = text->selc - marker->start;
482
if (s < 0 || s > marker->end - marker->start) return 0;
476
mrk= txt_next_marker(text, marker);
478
nxt= txt_next_marker(text, mrk); /* mrk may become invalid */
479
txt_move_to(text, mrk->lineno, mrk->start+c, 0);
480
if(s!=c) txt_move_to(text, mrk->lineno, mrk->start+s, 1);
484
mrk = txt_next_marker(text, marker);
486
nxt = txt_next_marker(text, mrk); /* mrk may become invalid */
487
txt_move_to(text, mrk->lineno, mrk->start + c, 0);
488
if (s != c) txt_move_to(text, mrk->lineno, mrk->start + s, 1);
481
489
txt_delete_char(text);
482
text_update_line_edited(st->text, st->text->curl);
483
if(mrk==marker || mrk==nxt) break;
490
text_update_line_edited(st->text->curl);
491
if (mrk == marker || mrk == nxt) break;
491
if(qual & LR_SHIFTKEY) {
493
if(!nxt) nxt= text->markers.last;
499
if (qual & LR_SHIFTKEY) {
501
if (!nxt) nxt = text->markers.last;
497
if(!nxt) nxt= text->markers.first;
505
if (!nxt) nxt = text->markers.first;
499
if(marker->flags & TMARK_TEMP) {
500
if(nxt==marker) nxt= NULL;
507
if (marker->flags & TMARK_TEMP) {
508
if (nxt == marker) nxt = NULL;
501
509
BLI_freelinkN(&text->markers, marker);
505
513
txt_move_to(text, mrk->lineno, mrk->start, 0);
506
514
txt_move_to(text, mrk->lineno, mrk->end, 1);
507
515
// XXX text_update_cursor_moved(C);
508
516
// XXX WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
514
522
/* Events that should clear markers */
515
case UKEY: if(!(qual & LR_ALTKEY)) break;
516
case ZKEY: if(evnt==ZKEY && !(qual & LR_CTRLKEY)) break;
523
case UKEY: if (!(qual & LR_ALTKEY)) break;
524
case ZKEY: if (evnt == ZKEY && !(qual & LR_CTRLKEY)) break;
519
if(marker->flags & (TMARK_EDITALL | TMARK_TEMP))
527
if (marker->flags & (TMARK_EDITALL | TMARK_TEMP))
520
528
txt_clear_markers(text, marker->group, 0);
522
530
BLI_freelinkN(&text->markers, marker);
526
534
case RIGHTMOUSE: /* Marker context menu? */
529
537
case FKEY: /* Allow find */
530
if(qual & LR_SHIFTKEY) swallow= 1;
538
if (qual & LR_SHIFTKEY) swallow = 1;
534
if(qual!=0 && qual!=LR_SHIFTKEY)
535
swallow= 1; /* Swallow all other shortcut events */
542
if (qual != 0 && qual != LR_SHIFTKEY)
543
swallow = 1; /* Swallow all other shortcut events */
540
{}; // XXX redraw_alltext();
548
// XXX redraw_alltext();