...
|
...
|
@@ -146,9 +146,17 @@
|
146
|
146
|
#define COLOR_SELNORMAL(re) re->theme.color_selnormal
|
147
|
147
|
#define COLOR_CURLINE(re) re->theme.color_curline
|
148
|
148
|
|
|
149
|
+typedef enum typeprintout_t {
|
|
150
|
+ printoutView=0,
|
|
151
|
+ printoutCopy,
|
|
152
|
+ printoutHelp,
|
|
153
|
+ printoutManpage
|
|
154
|
+} typeprintout_t;
|
|
155
|
+
|
149
|
156
|
typedef struct printout_t {
|
150
|
157
|
reui_t *ui;
|
151
|
158
|
redata_t *data;
|
|
159
|
+ typeprintout_t type;
|
152
|
160
|
int originline;
|
153
|
161
|
int origincol;
|
154
|
162
|
int showonlyn;
|
...
|
...
|
@@ -287,7 +295,7 @@ int re_selectbuf_resize(re_t *re,long size);
|
287
|
295
|
int re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces);
|
288
|
296
|
int re_selectbuf_replace(re_t *re,char *newdata);
|
289
|
297
|
int re_clipget(re_t *re);
|
290
|
|
-int re_addprint(re_t *re);
|
|
298
|
+int re_addprint(re_t *re, typeprintout_t typeprintout);
|
291
|
299
|
int re_delprint(re_t *re, int nprint);
|
292
|
300
|
int re_rtrim(re_t *re, long curpos, int *trimmed);
|
293
|
301
|
long re_getmatchingbracket(re_t *re,long posini, char originalchar, char *matchingchar);
|
...
|
...
|
@@ -1375,6 +1383,8 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":"");
|
1375
|
1383
|
re->command="";
|
1376
|
1384
|
re->command_first_key='q';
|
1377
|
1385
|
re->headerdirty=1;
|
|
1386
|
+ } else if(event->key.keysym.sym==SDLK_F1 && (SDL_GetModState()&(KMOD_CTRL|KMOD_SHIFT|KMOD_ALT))==0) {
|
|
1387
|
+ re_addprint(re,printoutHelp);
|
1378
|
1388
|
} else if(event->key.keysym.sym==SDLK_F2 || (event->key.keysym.sym==SDLK_s && (SDL_GetModState()&KMOD_CTRL)!=0)) {
|
1379
|
1389
|
char *errormsg=NULL;
|
1380
|
1390
|
if(redata_save(re->data,re->filename,&errormsg)!=-1)
|
...
|
...
|
@@ -1482,7 +1492,7 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":"");
|
1482
|
1492
|
if(re->quirk_duplicates)
|
1483
|
1493
|
re->ignorenkeys++;
|
1484
|
1494
|
} else if(/*re->selactive &&*/ event->key.keysym.sym==SDLK_p && (SDL_GetModState()&KMOD_CTRL)!=0) {
|
1485
|
|
- re_addprint(re);
|
|
1495
|
+ re_addprint(re,printoutView);
|
1486
|
1496
|
} else if(event->key.keysym.sym==SDLK_n && (SDL_GetModState()&KMOD_CTRL)!=0) {
|
1487
|
1497
|
re->showlinenumbers=1-re->showlinenumbers;
|
1488
|
1498
|
re_setuidata(re);
|
...
|
...
|
@@ -2225,7 +2235,7 @@ re_clipget(re_t *re)
|
2225
|
2235
|
|
2226
|
2236
|
|
2227
|
2237
|
int
|
2228
|
|
-re_addprint(re_t *re)
|
|
2238
|
+re_addprint(re_t *re, typeprintout_t typeprintout)
|
2229
|
2239
|
{
|
2230
|
2240
|
int i;
|
2231
|
2241
|
if(re==NULL)
|
...
|
...
|
@@ -2248,39 +2258,115 @@ re_addprint(re_t *re)
|
2248
|
2258
|
/* setup window */
|
2249
|
2259
|
if((re->prints[i].ui=reui_init(DEFAULTFONTHEIGHT*re->fontheightpercent/100,re->ui))==NULL)
|
2250
|
2260
|
return(-1); /* couldn't init window */
|
2251
|
|
-#if 0
|
2252
|
|
-/* option A: printouts are immutable */
|
2253
|
|
- if((re->prints[i].data=redata_init(redata_highlighter_register,NULL))==NULL) {
|
2254
|
|
- reui_free(re->prints[i].ui),re->prints[i].ui=NULL;
|
2255
|
|
- return(-1); /* couldn't init data store */
|
2256
|
|
- }
|
2257
|
|
- re->usedprints++;
|
2258
|
|
- /* copy contents (and set clipboard contents and unselect)*/
|
2259
|
|
- if(re->selactive) {
|
2260
|
|
- long frompos,topos;
|
2261
|
|
- int coldone;
|
2262
|
|
- if(redata_linecol2pos(re->data,re->sellinefrom,re->selcolfrom,&frompos,NULL)==0
|
2263
|
|
- && redata_linecol2pos(re->data,re->sellineto,re->selcolto,&topos,&coldone)==0) {
|
2264
|
|
- re_selectbuf_fill(re,frompos,topos-frompos,re->selcolto-coldone);
|
2265
|
|
- redata_op_add(re->prints[i].data,0,re->selectbuf,strlen(re->selectbuf),NULL);
|
2266
|
|
- SDL_SetClipboardText(re->selectbuf);
|
2267
|
|
- re_sel_toggle(re);
|
|
2261
|
+ if(typeprintout==printoutHelp
|
|
2262
|
+ || typeprintout==printoutManpage
|
|
2263
|
+ || typeprintout==printoutCopy) {
|
|
2264
|
+ /* inmutable printout */
|
|
2265
|
+ if((re->prints[i].data=redata_init(redata_highlighter_register,NULL))==NULL) {
|
|
2266
|
+ reui_free(re->prints[i].ui),re->prints[i].ui=NULL;
|
|
2267
|
+ return(-1); /* couldn't init data store */
|
|
2268
|
+ }
|
|
2269
|
+ re->usedprints++;
|
|
2270
|
+ if(typeprintout==printoutCopy) {
|
|
2271
|
+ /* copy contents (and set clipboard contents and unselect)*/
|
|
2272
|
+ if(re->selactive) {
|
|
2273
|
+ long frompos,topos;
|
|
2274
|
+ int coldone;
|
|
2275
|
+ if(redata_linecol2pos(re->data,re->sellinefrom,re->selcolfrom,&frompos,NULL)==0
|
|
2276
|
+ && redata_linecol2pos(re->data,re->sellineto,re->selcolto,&topos,&coldone)==0) {
|
|
2277
|
+ re_selectbuf_fill(re,frompos,topos-frompos,re->selcolto-coldone);
|
|
2278
|
+ redata_op_add(re->prints[i].data,0,re->selectbuf,strlen(re->selectbuf),NULL);
|
|
2279
|
+ SDL_SetClipboardText(re->selectbuf);
|
|
2280
|
+ re_sel_toggle(re);
|
|
2281
|
+ re->contentsdirty=1;
|
|
2282
|
+ }
|
|
2283
|
+ } else {
|
|
2284
|
+ re_selectbuf_fill(re,0,redata_getused(re->data),0);
|
|
2285
|
+ redata_op_add(re->prints[i].data,0,re->selectbuf,strlen(re->selectbuf),NULL);
|
|
2286
|
+ SDL_SetClipboardText(re->selectbuf);
|
|
2287
|
+ re->contentsdirty=1;
|
|
2288
|
+ }
|
|
2289
|
+ } else if(typeprintout==printoutHelp) {
|
|
2290
|
+ static char helptext[]={"\
|
|
2291
|
+Recenteditor help\n\
|
|
2292
|
+=================\n\
|
|
2293
|
+\n\
|
|
2294
|
+ F1 - Open a printout with this help\n\
|
|
2295
|
+ Shift+F1 - (TODO) Update hints with functions definitions of all open editors\n\
|
|
2296
|
+ Control+F1 - (TODO) Open manpage of word under the cursor in a printout\n\
|
|
2297
|
+ F2 - Save\n\
|
|
2298
|
+\n\
|
|
2299
|
+ Cursor keys - Move cursor\n\
|
|
2300
|
+ PageUp/PageDn - Scroll one page up/down\n\
|
|
2301
|
+ Shift+Cursor - Select\n\
|
|
2302
|
+ Mousewheel - Scroll\n\
|
|
2303
|
+ Mouse click - Change cursor position\n\
|
|
2304
|
+ Click and hold on status bar to open function list\n\
|
|
2305
|
+ Control+Click - Search function body of function name under the mouse\n\
|
|
2306
|
+ Tab key - Insert 8 spaces\n\
|
|
2307
|
+ Control+Tab key - Insert TAB character\n\
|
|
2308
|
+ Alt+Left/Right - Change indentation of selection\n\
|
|
2309
|
+ Control+PgUp/PgDn - Go to the beginning/end of the document\n\
|
|
2310
|
+ Home/End - Go to the start/end of the line\n\
|
|
2311
|
+ Control+'0' - Set default font size\n\
|
|
2312
|
+ Shift+Ctrl+'0' - Set default color permutation\n\
|
|
2313
|
+ Control+C - Copy selection to clipboard. Will deselect current selection.\n\
|
|
2314
|
+ Control+K+Command - Block command, see below\n\
|
|
2315
|
+ Control+L - Search next (requires a previous search with Control+Q+F)\n\
|
|
2316
|
+ Control+N - Show/hide line numbers\n\
|
|
2317
|
+ Control+P - Open printout window with current file or selection\n\
|
|
2318
|
+ Control+Q+Command - Editing command, see below\n\
|
|
2319
|
+ Control+S - Save\n\
|
|
2320
|
+ Control+X - Cut selection into clipboard\n\
|
|
2321
|
+ Control+V - Paste clipboard into current cursor position\n\
|
|
2322
|
+ Control+Z - Undo\n\
|
|
2323
|
+ Control+'+'/'-' - Iterates between font sizes\n\
|
|
2324
|
+ Shift+Ctrl+'+'/'-' - Iterates between color permutations\n\
|
|
2325
|
+\n\
|
|
2326
|
+\n\
|
|
2327
|
+Editing commands (Control+Q+Command)\n\
|
|
2328
|
+------------------------------------\n\
|
|
2329
|
+\n\
|
|
2330
|
+ Control+Q+L - Go to line number\n\
|
|
2331
|
+ Control+Q+F - Find\n\
|
|
2332
|
+ Control+Q+A - Search and replace\n\
|
|
2333
|
+\n\
|
|
2334
|
+\n\
|
|
2335
|
+Block commands (Control+K+Command)\n\
|
|
2336
|
+----------------------------------\n\
|
|
2337
|
+\n\
|
|
2338
|
+ Control+K+Q - Close editor (exit program -- don\'t ask, it is a legacy key combo)\n\
|
|
2339
|
+ Control+K+H - Show/hide selection\n\
|
|
2340
|
+ Control+K+B - Set start of selection to cursor position\n\
|
|
2341
|
+ Control+K+K - Set end of selection to cursor position\n\
|
|
2342
|
+ Control+K+Y - Delete selection\n\
|
|
2343
|
+ Control+K+C - Copy selection to current cursor position (doesn\'t use clipboard)\n\
|
|
2344
|
+ Control+K+V - Move selection to current cursor position (doesn\'t use clipboard)\n\
|
|
2345
|
+\n\
|
|
2346
|
+\n\
|
|
2347
|
+Printout window\n\
|
|
2348
|
+---------------\n\
|
|
2349
|
+\n\
|
|
2350
|
+ Cursor/PageUp/PageDown - Scroll printout\n\
|
|
2351
|
+ Mousewheel - Scroll printout\n\
|
|
2352
|
+"};
|
|
2353
|
+ reui_title(re->prints[i].ui,"help");
|
|
2354
|
+ redata_op_add(re->prints[i].data,0,helptext,sizeof(helptext)-1,NULL);
|
2268
|
2355
|
re->contentsdirty=1;
|
2269
|
2356
|
}
|
2270
|
2357
|
} else {
|
2271
|
|
- re_selectbuf_fill(re,0,redata_getused(re->data),0);
|
2272
|
|
- redata_op_add(re->prints[i].data,0,re->selectbuf,strlen(re->selectbuf),NULL);
|
2273
|
|
- SDL_SetClipboardText(re->selectbuf);
|
2274
|
|
- re->contentsdirty=1;
|
2275
|
|
- }
|
2276
|
|
-#else
|
2277
|
|
-/* option B: printouts are a window into a fixed place of the file */
|
2278
|
|
- re->prints[i].data=NULL;
|
2279
|
|
- re->prints[i].originline=(re->selactive)?re->sellinefrom:0;
|
2280
|
|
- re->prints[i].origincol=0;
|
2281
|
|
- re->prints[i].showonlyn=0 /* (re->selactive)?re->sellineto-re->sellinefrom+1:0 */ ;
|
2282
|
|
- re->usedprints++;
|
2283
|
|
-#endif
|
|
2358
|
+ char mytitle[256];
|
|
2359
|
+ snprintf(mytitle,sizeof(mytitle),"view %s",re->filename);
|
|
2360
|
+ mytitle[sizeof(mytitle)-1]='\0';
|
|
2361
|
+ reui_title(re->prints[i].ui,mytitle);
|
|
2362
|
+ /* printout is a window into a fixed place of the file */
|
|
2363
|
+ re->prints[i].data=NULL;
|
|
2364
|
+ re->prints[i].originline=(re->selactive)?re->sellinefrom:0;
|
|
2365
|
+ re->prints[i].origincol=0;
|
|
2366
|
+ re->prints[i].showonlyn=0 /* (re->selactive)?re->sellineto-re->sellinefrom+1:0 */ ;
|
|
2367
|
+ re->usedprints++;
|
|
2368
|
+ }
|
|
2369
|
+ re->prints[i].type=typeprintout;
|
2284
|
2370
|
re->prints[i].dirty=1;
|
2285
|
2371
|
return(0);
|
2286
|
2372
|
}
|
...
|
...
|
@@ -2485,6 +2571,7 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2485
|
2571
|
{
|
2486
|
2572
|
reui_t *ui;
|
2487
|
2573
|
redata_t *data;
|
|
2574
|
+ char *bgcolor;
|
2488
|
2575
|
int x0,y0,w,h;
|
2489
|
2576
|
int originline,origincol;
|
2490
|
2577
|
int curline,curcol;
|
...
|
...
|
@@ -2523,7 +2610,9 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2523
|
2610
|
maxcol=re->maxcol;
|
2524
|
2611
|
maxrow=re->maxrow;
|
2525
|
2612
|
showonlyn=0;
|
2526
|
|
- flaglineno=(printout==NULL)?re->showlinenumbers:0;
|
|
2613
|
+ flaglineno=(printout==NULL)?re->showlinenumbers:
|
|
2614
|
+ (printout->type==printoutHelp)?0:
|
|
2615
|
+ 1;
|
2527
|
2616
|
linenosize=linenowidth=0;
|
2528
|
2617
|
if(printout==NULL && re->viewonly==1) {
|
2529
|
2618
|
memset(&fakeprintout,0,sizeof(printout_t));
|
...
|
...
|
@@ -2544,7 +2633,6 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2544
|
2633
|
maxcol=w/ui->fontwidth-1;
|
2545
|
2634
|
maxrow=h/ui->fontheight-1;
|
2546
|
2635
|
showonlyn=printout->showonlyn;
|
2547
|
|
- flaglineno=1;
|
2548
|
2636
|
}
|
2549
|
2637
|
if(flaglineno) {
|
2550
|
2638
|
linenosize=6;
|
...
|
...
|
@@ -2556,7 +2644,10 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2556
|
2644
|
}
|
2557
|
2645
|
if(redata_linecol2pos(data,curline,curcol,&cursorpos,NULL)!=0)
|
2558
|
2646
|
return(0); /* error obtaining position */
|
2559
|
|
- reui_fill(ui,x0-linenowidth,y0,w,h,COLOR_BACKGROUND(re));
|
|
2647
|
+ bgcolor=(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage))
|
|
2648
|
+ ?COLOR_PRINTOUTSTRIPE(re)
|
|
2649
|
+ :COLOR_BACKGROUND(re);
|
|
2650
|
+ reui_fill(ui,x0-linenowidth,y0,w,h,bgcolor);
|
2560
|
2651
|
row=curline-originline;
|
2561
|
2652
|
pos=cursorpos;
|
2562
|
2653
|
/* get position/row/col of character at top left of screen */
|
...
|
...
|
@@ -2570,6 +2661,8 @@ re_drawcontents(re_t *re, printout_t *printout)
|
2570
|
2661
|
/* highlight current line (in printouts, highlight alternating lines) */
|
2571
|
2662
|
if(printout==NULL) {
|
2572
|
2663
|
reui_fill(ui,x0-linenowidth,y0+(curline-originline)*ui->fontheight,w,ui->fontheight+1,COLOR_PRINTOUTSTRIPE(re));
|
|
2664
|
+ } else if(printout!=NULL && (printout->type==printoutHelp || printout->type==printoutManpage)) {
|
|
2665
|
+ ; /* help bgcolor already filled */
|
2573
|
2666
|
} else {
|
2574
|
2667
|
for(y=y0+((printout->data==NULL)?1:(printout->originline%2))*ui->fontheight;y<(y0+h);y+=ui->fontheight*2)
|
2575
|
2668
|
reui_fill(ui,x0-linenowidth,y,w,ui->fontheight+1,COLOR_PRINTOUTSTRIPE(re));
|