~torios-dev/+junk/torios-binary

« back to all changes in this revision

Viewing changes to text/flpad.fld

  • Committer: Israel Dahl
  • Date: 2019-03-03 16:32:41 UTC
  • Revision ID: israeldahl@gmail.com-20190303163241-57z0sbzjxkf373um
add a bunch of comments :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
 
121
121
class Fl_Syntax_Text_Editor {open : {public Fl_Text_Editor}
122
122
} {
 
123
  decl {Fl_Printer *printer} {public global
 
124
  }
123
125
  decl {int inotify_fd;} {public local
124
126
  }
125
127
  decl {int inotify_wd;} {public local
126
128
  }
127
 
  Function {Fl_Syntax_Text_Editor(int x, int y, int w, int h, const char* label = 0):Fl_Text_Editor(x,y,w,h,label)} {open
128
 
  } {
 
129
  Function {Fl_Syntax_Text_Editor(int x, int y, int w, int h, const char* label = 0):Fl_Text_Editor(x,y,w,h,label)} {} {
129
130
    code {IGNORE_SYNTAX_CASE = false;
130
131
SPACES             = false;
131
132
RELEASE            = false;
134
135
changed            = 0;
135
136
loading            = 0;
136
137
filename           = "";
 
138
 
 
139
//the buffer to hold just the file's text
137
140
textbuffer         = new Fl_Text_Buffer();
138
141
this->resize(x,y,w,h);
 
142
//set textbuffer to be the buffer in this widget
139
143
this->buffer(textbuffer);
140
144
 
 
145
// create a basic style text
141
146
char *style = new char[textbuffer->length() + 1];
142
147
char *text = textbuffer->text();
143
 
 
 
148
//set it to plain .a.k.a. 'A'
144
149
memset(style, 'A', textbuffer->length());
 
150
 
 
151
// this is the buffer for the syntax highlighting
145
152
stylebuffer = new Fl_Text_Buffer(textbuffer->length());
146
153
style[textbuffer->length()] = '\\0';
147
 
 
 
154
//get the actual syntax highlighter setup
148
155
init_highlight();
149
 
 
 
156
//set the highlighter text in the style buffer
150
157
stylebuffer->text(style);
151
158
 
 
159
//don't need these anymore
152
160
delete[] style;
153
161
free(text);
154
162
 
 
163
//make it flat so it looks nicer
155
164
box(FL_FLAT_BOX);
156
165
 
157
 
theme_editor(FOREGROUND_TEXT,BACKGROUND_TEXT,SELECTION_TEXT,FONT_TEXT,SIZE_TEXT,LINE_NUMBERS);
 
166
//make this editor have the right font, line numbers, and colors
 
167
theme_editor(
 
168
             FOREGROUND_TEXT,
 
169
             BACKGROUND_TEXT,
 
170
             SELECTION_TEXT,
 
171
             FONT_TEXT,
 
172
             SIZE_TEXT,
 
173
             LINE_NUMBERS
 
174
            );
158
175
 
 
176
//whenever the buffer is modified run this function
159
177
textbuffer->add_modify_callback(changed_cb,(void *)this);
160
 
/*if(!take_focus())
161
 
{
162
 
  trace("Failed to take focus for Text Editor");
163
 
}
164
 
*/
165
 
 
166
 
 
 
178
//setup the printer for this widget
 
179
printer = new Fl_Printer();
 
180
//make it so typing happens here (instead of the tab or something un-helpful)
167
181
Fl::focus(this);} {}
168
182
  }
169
183
  Function {~Fl_Syntax_Text_Editor()} {} {
170
184
    code {buffer(0);
171
185
textbuffer->remove_modify_callback(style_update, this);
172
186
textbuffer->remove_modify_callback(changed_cb, this);
 
187
 
 
188
delete printer;
 
189
delete textbuffer;
 
190
delete stylebuffer;
 
191
 
173
192
if(rm_inotify())
174
193
{
175
194
  trace("problem removing inotify watch");
211
230
  } {
212
231
    code {Fl_Syntax_Text_Editor * o = (Fl_Syntax_Text_Editor *)v;
213
232
std::string f = o->filename;
 
233
o->changed = 0;
 
234
 
214
235
if ((nInserted || nDeleted) && !o->loading)
215
236
{
216
237
  o->changed = 1;
217
238
}
 
239
 
218
240
((UI *)(o->parent()->user_data()))->set_title(o->parent());} {}
219
241
  }
220
 
  Function {enter_kf(int, Fl_Text_Editor *e)} {open return_type {static int}
 
242
  Function {enter_kf(int, Fl_Text_Editor *e)} {return_type {static int}
221
243
  } {
222
 
    code {kill_selection(e);
 
244
    code {//Basically I copied the original code from the text editor source
 
245
kill_selection(e);
 
246
 
 
247
//I changed this to my widget
223
248
Fl_Syntax_Text_Editor* E = (Fl_Syntax_Text_Editor*)e;
 
249
 
 
250
//I use the space counter function
224
251
std::string SPACES = E->count_spaces();
225
 
std::string t = "\\n";
226
 
t+=SPACES;
 
252
// instead of just adding a newline like in the original, I also add the spaces
 
253
std::string t  = "\\n";
 
254
            t += SPACES;
 
255
//put it in
227
256
e->insert(t.c_str());
 
257
//put the cursor right there
228
258
e->show_insert_position();
 
259
//make it changed
229
260
e->set_changed();
230
 
if (e->when()&FL_WHEN_CHANGED) e->do_callback();
 
261
//do the callback if needed
 
262
if (e->when()&FL_WHEN_CHANGED)
 
263
{
 
264
  e->do_callback();
 
265
}
 
266
//return 'it worked' this is like the boolean 'true' here
231
267
return 1;} {}
232
268
  }
233
 
  Function {file_string()} {open return_type {std::string}
 
269
  Function {file_string()} {return_type {std::string}
234
270
  } {
235
 
    code {if(filename.compare("")==0){return "";}
 
271
    code {// turn a file into a string
 
272
 
 
273
//no file sent in... return emptyness
 
274
if( (filename.compare("")==0) || (!test_file(filename)) )
 
275
{
 
276
   return "";
 
277
}
 
278
 
 
279
//make our input file stream, and put the file into it
236
280
std::ifstream t(filename);
 
281
//make our return string
237
282
std::string str;
238
283
 
239
 
t.seekg(0, std::ios::end);   
 
284
//set position to end
 
285
t.seekg(0, std::ios::end);
 
286
//make the string a nice size
240
287
str.reserve(t.tellg());
 
288
//set position back to start
241
289
t.seekg(0, std::ios::beg);
242
 
 
 
290
//now use the iterators to assign the entire file to the string
243
291
str.assign((std::istreambuf_iterator<char>(t)),
244
292
            std::istreambuf_iterator<char>());
 
293
//voila ca cest tres bein!
245
294
return str;} {}
246
295
  }
247
296
  Function {get_styletable(Fl_Text_Display::Style_Table_Entry &styles,int which)} {open
248
297
  } {
249
 
    code {int font = FONT_TEXT;
 
298
    code {// this function does all the repetative styletable work,
 
299
// and keeps it organized in one place
 
300
 
 
301
//get the current font
 
302
int font = FONT_TEXT;
 
303
//usually (unless they chose a bold/italic font) bold is next one up
250
304
int bold = font + 1;
 
305
// usually (unless they chose a bold/italic font) italic is next one up
251
306
int ital = bold + 1;
 
307
 
 
308
//this is in case I need to debug
252
309
std::string whichtype="Plain";
 
310
 
253
311
switch(which)
254
312
{
255
313
  case 0:
 
314
  // the format:  COLOR        font   NORMAL SIZE
256
315
    styles={ FOREGROUND_TEXT, font, FL_NORMAL_SIZE }; // A - Plain
257
316
    whichtype="Plain";
258
317
    break;
286
345
    break;
287
346
  case 8:
288
347
    styles={ SPECIAL_TEXT, font, FL_NORMAL_SIZE }; // I - special
 
348
    whichtype="special";
289
349
    break;
290
350
  case 9:
291
351
    styles={ BROKEN_TEXT, font, FL_NORMAL_SIZE }; // J - Broken :(
 
352
    whichtype="broken";
292
353
    break;
293
354
}
294
 
styletable[which] = styles; //  set} {}
 
355
//trace(whichtype);
 
356
styletable[which] = styles; //  set} {selected
 
357
    }
295
358
  }
296
359
  Function {handle(int event)} {open protected return_type int
297
360
  } {
350
413
  } {
351
414
    code {return count_lines(0,length(), false);} {}
352
415
  }
353
 
  Function {modify_cb(int pos=0, int nInserted=0, int nDeleted=0, int unused=0, const char * nada=NULL)} {return_type void
 
416
  Function {modify_cb(int pos=0, int nInserted=0, int nDeleted=0, int unused=0, const char * nada=NULL)} {open return_type void
354
417
  } {
355
 
    code {if(stylebuffer->selected()!=0)
 
418
    code {//if it is a selection change just return
 
419
if(stylebuffer->selected() != 0)
356
420
{
357
421
   stylebuffer->unselect();
358
422
   return;
359
423
}
360
424
 
361
425
std::string thisLine;
362
 
if ( (HIGHLIGHT_PLAIN==0)&& (STYLE_HEADER.compare("")==0) )
 
426
 
 
427
if ( (HIGHLIGHT_PLAIN==0) && (STYLE_HEADER.compare("")==0) )
363
428
{
364
429
  char *style = new char[textbuffer->length() + 1];
365
430
  memset(style, 'A', textbuffer->length());
369
434
else
370
435
{
371
436
  char* buf = this->textbuffer->text();
 
437
 
372
438
  if(buf == NULL)
 
439
  {
373
440
    return;
 
441
  }
 
442
 
374
443
  std::string out(buf);
375
444
  std::string res = style_line(out);
376
445
  char* RES = const_cast <char*> (res.c_str());
 
446
 
377
447
  if (RES == NULL)
 
448
  {
378
449
    return;
 
450
  }
 
451
 
379
452
  stylebuffer->text(RES);
380
453
}
 
454
 
381
455
redisplay_range(0,textbuffer->length());} {}
382
456
  }
383
 
  Function {refresh()} {} {
 
457
  Function {refresh()} {open
 
458
  } {
384
459
    code {set_syntax();
385
460
modify_cb(0,0,0,0,NULL);
386
461
redisplay_range(0,textbuffer->length());
474
549
       (tmp != ' ')
475
550
      )
476
551
    {
477
 
      ret+='A';
 
552
      ret += 'A';
478
553
    }
479
554
    else
480
555
    {
481
 
      ret+=tmp;
 
556
      ret += tmp;
482
557
    }
483
558
    
484
559
  }
485
560
  return ret;
486
 
  //trace("error processing text:"+thisLine);
487
561
}
488
562
else
489
563
{
490
564
  std::string line = lexertk::helper::style_line(generator);
491
565
  if(line.compare("")==0)
492
566
  {
493
 
    //trace("adding newline!");
494
 
    line="\\n";
 
567
    line = "\\n";
495
568
  }
496
569
  return line;
497
570
}
 
571
 
 
572
// this should never happen....
498
573
return "A";} {}
499
574
  }
500
575
  Function {style_update(int pos=0, int nInserted=0, int nDeleted=0, int unused=0, const char * nada=NULL, void *cbArg = NULL)} {return_type {static void}
519
594
    code {textbuffer->tab_distance(dist);
520
595
stylebuffer->tab_distance(dist);} {}
521
596
  }
522
 
  Function {theme_editor(unsigned int FG,unsigned int BG, unsigned int selection, int font, int size,int linenum )} {} {
 
597
  Function {theme_editor(unsigned int FG,unsigned int BG, unsigned int selection, int font, int size,int linenum )} {open
 
598
  } {
523
599
    code {textcolor(FG);
524
600
cursor_color(FG);
525
601
color(BG);
528
604
selection_color(selection);
529
605
linenumber_width(linenum);
530
606
linenumber_size(size);
531
 
///renew highlighter
 
607
 
 
608
///renew syntax highlighting
532
609
update_styletable();
 
610
//make the syntax highlighter colors
533
611
modify_cb();
 
612
//make the tab distance the correct one
534
613
tab_distance(TAB_DISTANCE);
 
614
//redo the syntax highlighting to make sure tabs are correct
535
615
modify_cb();} {}
536
616
  }
537
617
  Function {update_styletable()} {} {
569
649
  }
570
650
  Function {use_spaces()} {} {
571
651
    code {remove_key_binding(FL_Enter,FL_TEXT_EDITOR_ANY_STATE);
 
652
 
 
653
// this will either use default enter function
 
654
// OR it will use the function tat adds the right amount of spaces for indention
572
655
if(SPACES)
573
656
{
574
657
//use my function
664
747
}
665
748
return false;} {}
666
749
  }
 
750
  Function {pages()} {open return_type int
 
751
  } {
 
752
    code {wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
 
753
WRAPPED = !WRAPPED;
 
754
int f = textsize();
 
755
int l = line_count();
 
756
int tot = f * l;
 
757
word_wrap();
 
758
 
 
759
if ( tot < 1)
 
760
{
 
761
  return 0;
 
762
}
 
763
int w, h;
 
764
printer->printable_rect(&w, &h);
 
765
 
 
766
 
 
767
if (tot < h)
 
768
  return 1;
 
769
 
 
770
int total = tot / h;
 
771
std::cout<<"total pages:"<<total<<std::endl;
 
772
return total;} {}
 
773
  }
 
774
  Function {print_text()} {open
 
775
  } {
 
776
    code {int font            = textfont();
 
777
int size            = textsize();
 
778
int start, end;
 
779
int w,h;
 
780
printer->printable_rect(&w,&h);
 
781
UI* ui = ((UI*)(parent()->parent()->parent()->user_data()));
 
782
std::string labl = gettext("Printing Page \#: ");
 
783
if (printer->start_job(0, &start, &end) == 0)
 
784
{
 
785
  if(end == start)
 
786
  {
 
787
    print_page(w, h, font, size, start);
 
788
    return;
 
789
  }
 
790
//show progress
 
791
  start -= 1;
 
792
  int inc = 100 / (end/start);
 
793
  ui->progress_window()->show();
 
794
  int p_val = 0;
 
795
  ui->progress->value(p_val);
 
796
  std::cout<<"start:"<<start<<" end:"<<end<<std::endl;
 
797
  for (int i = start; i < end; i++)
 
798
  {
 
799
    std::cout<<"printing:"<<i<<std::endl;
 
800
    print_page(w, h, font, size, i);
 
801
    p_val += inc;
 
802
    std::string num = labl + convert(i);
 
803
    ui->progress->value(p_val);
 
804
    ui->progress->copy_label(num.c_str());
 
805
  }
 
806
 
 
807
  ui->progress_window()->hide();
 
808
  std::cout<<"done"<<std::endl;
 
809
  printer->end_job();
 
810
}} {}
 
811
  }
 
812
  Function {print_page(int w, int h, int font, int size, int page_num)} {open
 
813
  } {
 
814
    code {std::cout<<"printing:"<<page_num<<" w="<<w<<" h="<<h<<std::endl;
 
815
int x = 0;
 
816
int y = 0;
 
817
 
 
818
printer->start_page();
 
819
 
 
820
fl_color(FL_BLACK);
 
821
fl_rect(x,y,w,h);
 
822
fl_font(font, size);
 
823
fl_draw( page(page_num).c_str(), x, y, w, h, FL_ALIGN_WRAP );
 
824
 
 
825
printer->end_page();} {}
 
826
  }
 
827
  Function {word_wrap()} {open
 
828
  } {
 
829
    code {if(WRAPPED)
 
830
{
 
831
  WRAPPED=false;
 
832
  wrap_mode(Fl_Text_Display::WRAP_NONE, 0);
 
833
  WORD_WRAP=0;
 
834
}
 
835
else
 
836
{
 
837
  WRAPPED=true;
 
838
  wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
 
839
  WORD_WRAP=1;
 
840
}} {}
 
841
  }
 
842
  Function {page(int num)} {open return_type {std::string}
 
843
  } {
 
844
    code {int lines = lines_per_page();
 
845
int start = lines * num;
 
846
 
 
847
int end = start + lines;
 
848
 
 
849
const char* text = textbuffer->text_range(start, end);
 
850
std::cout<<"page:"<<num<<" start:"<<start<<" text:"<<text<<std::endl;
 
851
if(text == NULL)
 
852
{
 
853
  return "";
 
854
}
 
855
 
 
856
std::string t = text;
 
857
return t;} {}
 
858
  }
 
859
  Function {lines_per_page()} {open return_type int
 
860
  } {
 
861
    code {return (line_count() / pages());} {}
 
862
  }
667
863
}
668
864
 
669
865
class UI {open
693
889
      }
694
890
    }
695
891
  }
696
 
  Function {details_window()} {} {
 
892
  Function {details_window()} {open
 
893
  } {
697
894
    Fl_Window {} {open
698
895
      xywh {383 174 195 195} type Double hide
699
896
    } {
717
914
        xywh {100 65 85 25} box FLAT_BOX
718
915
        code0 {o->value(char_count());}
719
916
      }
 
917
      Fl_Value_Output {} {
 
918
        label {Pages:}
 
919
        xywh {100 90 85 25} box FLAT_BOX
 
920
        code0 {o->value(page_count());}
 
921
      }
720
922
    }
721
923
  }
722
924
  Function {make_popup(Fl_Widget *o)} {} {
821
1023
  } {
822
1024
    Fl_Window win {
823
1025
      label flpad open
824
 
      xywh {777 124 520 545} type Double color 47
 
1026
      xywh {238 155 520 545} type Double color 47 hide
825
1027
      code1 {o->size_range(o->w(), o->h(), 0, 0);}
826
 
      code2 {make_icon(o);} xclass flpad visible
 
1028
      code2 {make_icon(o);} xclass flpad
827
1029
    } {
828
1030
      Fl_Group buttons {open
829
1031
        xywh {0 25 520 30} box FLAT_BOX color 48
889
1091
          code0 {o->image(settings_image);}
890
1092
        }
891
1093
        Fl_Button print_button {
892
 
          callback {print_cb();} selected
 
1094
          callback {print_cb();}
893
1095
          tooltip Print xywh {310 27 25 25} box FLAT_BOX labelfont 1
894
1096
          code0 {o->image(color_print_image);}
895
1097
        }
1255
1457
      }
1256
1458
    }
1257
1459
  }
1258
 
  Function {add_recent(std::string filename)} {open return_type bool
 
1460
  Function {add_recent(std::string filename)} {return_type bool
1259
1461
  } {
1260
1462
    code {if(filename.compare("")==0)
1261
1463
{
1304
1506
  }
1305
1507
  Function {add_tab(bool LOAD=true, bool NEW = true)} {open
1306
1508
  } {
1307
 
    code {int y = menu->y()+tabs->y()+add_button->y();
 
1509
    code {int y = menu->y() + tabs->y() + add_button->y();
1308
1510
int h = tabs->h();
1309
1511
int w = tabs->w();
1310
1512
int x = tabs->x();
 
1513
 
1311
1514
tabs->client_area(x,y,w,h);
 
1515
 
1312
1516
Fl_Group* o = new Fl_Group(x, y, w, h);
1313
1517
o->copy_label("Untitled");
1314
1518
 
1315
1519
Fl_Syntax_Text_Editor* te = new Fl_Syntax_Text_Editor(x,y,w,h);
 
1520
 
1316
1521
te->user_data(o);
1317
1522
 
1318
1523
if(INDENT_NEW_LINES>0)
1342
1547
tabs->value(o);
1343
1548
 
1344
1549
if(LOAD)
 
1550
{
1345
1551
  open_file(NEW);
 
1552
}
1346
1553
else
 
1554
{
1347
1555
  te->filename="";
 
1556
}
1348
1557
 
1349
1558
refresh_all();} {}
1350
1559
  }
1351
 
  Function {button_style(int style=0)} {open
1352
 
  } {
 
1560
  Function {button_style(int style=0)} {} {
1353
1561
    code {if(style==0)
1354
1562
{
1355
1563
  open_button->image(open_image);
1388
1596
cut_button->redraw();
1389
1597
print_button->redraw();} {}
1390
1598
  }
1391
 
  Function {change_theme(unsigned int FG,unsigned int BG, unsigned int selection, int font, int size, int line)} {open
1392
 
  } {
1393
 
    code {FOREGROUND_TEXT=FG;
1394
 
BACKGROUND_TEXT=BG;
1395
 
SELECTION_TEXT=selection;
1396
 
FONT_TEXT=font;
1397
 
SIZE_TEXT=size;
1398
 
LINE_NUMBERS=line;
 
1599
  Function {change_theme(unsigned int FG,unsigned int BG, unsigned int selection, int font, int size, int line)} {} {
 
1600
    code {FOREGROUND_TEXT = FG;
 
1601
BACKGROUND_TEXT = BG;
 
1602
SELECTION_TEXT  = selection;
 
1603
FONT_TEXT       = font;
 
1604
SIZE_TEXT       = size;
 
1605
LINE_NUMBERS    = line;
 
1606
 
1399
1607
if(tabs==NULL)
 
1608
{
1400
1609
  return;
1401
 
for(int i = 0; i < tabs->children();i++)
 
1610
}
 
1611
 
 
1612
for(int i = 0; i < tabs->children(); i++)
1402
1613
{
1403
1614
  Fl_Group* tab = tabs->child(i)->as_group();
1404
1615
  Fl_Syntax_Text_Editor * e = (Fl_Syntax_Text_Editor *)tab->child(0);
 
1616
 
1405
1617
  e->theme_editor(FG,BG,selection,font,size,line);
1406
1618
}} {}
1407
1619
  }
1449
1661
 
1450
1662
return E->size();} {}
1451
1663
  }
1452
 
  Function {check_save()} {return_type int
 
1664
  Function {check_save()} {open return_type int
1453
1665
  } {
1454
1666
    code {Fl_Syntax_Text_Editor * E = current_editor();
1455
1667
if(E==NULL)
1457
1669
  return 1;
1458
1670
}
1459
1671
if (!E->changed)
 
1672
{
1460
1673
  return 1;
 
1674
}
 
1675
 
1461
1676
int r = ask("The current file has not been saved.\\n" "Would you like to save it now?", "Save", "Cancel","Discard");
1462
 
if (r == 1) {
 
1677
if (r == 1)
 
1678
{
1463
1679
  save_cb(); // Save the file...
1464
1680
  return !E->changed;
1465
1681
}
 
1682
 
1466
1683
return (r == 2) ? 1 : 0;} {}
1467
1684
  }
1468
1685
  Function {choose_a_color(Fl_Widget *o)} {return_type {unsigned int}
1625
1842
tExt->redraw();
1626
1843
bg->redraw();} {}
1627
1844
  }
1628
 
  Function {copy_cb()} {open
1629
 
  } {
 
1845
  Function {copy_cb()} {} {
1630
1846
    code {Fl_Syntax_Text_Editor * textor = current_editor();
1631
1847
if(textor==NULL)
1632
1848
  return;
1664
1880
  return;
1665
1881
Fl_Text_Editor::kf_cut(0,textor);} {}
1666
1882
  }
1667
 
  Function {default_theme()} {open
1668
 
  } {
 
1883
  Function {default_theme()} {} {
1669
1884
    code {FOREGROUND_TEXT = FL_FOREGROUND_COLOR;
1670
1885
BACKGROUND_TEXT = FL_BACKGROUND2_COLOR;
1671
1886
SELECTION_TEXT  = 80;
1694
1909
  }
1695
1910
  Function {dnd_file(const char* items, bool NEW=true)} {} {
1696
1911
    code {if(items==NULL)
 
1912
{
1697
1913
  return;
 
1914
}
 
1915
 
1698
1916
std::string tmp = items;
 
1917
 
1699
1918
std::vector<std::string> V = dnd_vec(tmp);
1700
 
for( std::vector<std::string>::iterator itr = V.begin();
1701
 
                                        itr!=V.end();
1702
 
                                      ++itr)
 
1919
std::vector<std::string>::iterator itr;
 
1920
 
 
1921
for( itr = V.begin();
 
1922
     itr!=V.end();
 
1923
   ++itr)
1703
1924
{
1704
1925
  std::string s = *itr;
1705
1926
  std::string txt = *itr;
1706
1927
 
1707
1928
  unsigned int URI = s.find("file:///");
1708
 
  if(URI==0)
 
1929
 
 
1930
  if(URI == 0)
1709
1931
  {
1710
1932
    s = s.substr(7,std::string::npos);
1711
1933
  }
 
1934
 
1712
1935
  URI = s.find("\\n");
1713
 
  if(URI<s.length())
 
1936
 
 
1937
  if(URI < s.length())
1714
1938
  {
1715
 
    s=s.substr(0,URI);
 
1939
    s = s.substr(0,URI);
1716
1940
  }
 
1941
 
1717
1942
  char *ch = strdup(s.c_str());
1718
1943
  fl_decode_uri(ch);
1719
 
  s=ch;
 
1944
  s = ch;
1720
1945
 
1721
1946
  if(test_file(s))
1722
1947
  {
1723
 
    load_file(s,-1,NEW);
 
1948
    load_file(s,NEW);
1724
1949
  }
1725
1950
  else
1726
1951
  {
1727
1952
    Fl_Syntax_Text_Editor * E = current_editor();
1728
1953
 
1729
 
    if(E==NULL)
 
1954
    if(E == NULL)
1730
1955
    {
1731
1956
      return;
1732
1957
    }
 
1958
 
1733
1959
    Fl_Text_Buffer * buff = E->buffer();
1734
1960
    int pos = E->insert_position();
1735
1961
    buff->insert(pos, txt.c_str());
1880
2106
fname+="/flpad/flpad.config";
1881
2107
return fname;} {}
1882
2108
  }
1883
 
  Function {get_preferences()} {open
1884
 
  } {
 
2109
  Function {get_preferences()} {} {
1885
2110
    code {std::string fname=get_filename();
1886
2111
if(fname.compare("")==0)
1887
2112
{
2016
2241
  trace(fname+" does not exist yet");
2017
2242
}} {}
2018
2243
  }
2019
 
  Function {get_recent()} {open return_type bool
 
2244
  Function {get_recent()} {return_type bool
2020
2245
  } {
2021
2246
    code {std::string out=get_flpad_home_dir("recent");
2022
2247
 
2131
2356
  Function {handle_menu(Fl_Widget *w, void *v)} {return_type {static void}
2132
2357
  } {
2133
2358
    code {if(!w || !v)
 
2359
{
2134
2360
  return;
2135
 
Fl_Syntax_Text_Editor* T = ((Fl_Syntax_Text_Editor*)w->user_data());
 
2361
}
 
2362
 
 
2363
Fl_Syntax_Text_Editor* T = ((Fl_Syntax_Text_Editor*) w->user_data());
2136
2364
UI* ui = ((UI*)T->user_data());
 
2365
 
2137
2366
switch(static_cast<int>(reinterpret_cast<long>(v)))
2138
2367
{
2139
2368
  case 1: //COPY
2192
2421
  return;
2193
2422
Fl_Text_Editor::kf_insert(0,textor);} {}
2194
2423
  }
2195
 
  Function {line_count()} {open return_type int
 
2424
  Function {line_count()} {return_type int
2196
2425
  } {
2197
2426
    code {Fl_Syntax_Text_Editor* E = current_editor();
2198
2427
 
2203
2432
 
2204
2433
return E->line_count();} {}
2205
2434
  }
2206
 
  Function {load_file(std::string newfile, int ipos,bool NEW=true)} {open
 
2435
  Function {load_file(std::string newfile, bool NEW=true)} {open
2207
2436
  } {
2208
2437
    code {//todo 
2209
2438
//if(pick_tab(newfile)){return;}
2220
2449
  return;
2221
2450
}
2222
2451
 
 
2452
E->changed = 0;
2223
2453
int r = E->textbuffer->loadfile(newfile.c_str());
 
2454
 
2224
2455
if (r)
2225
2456
{
2226
2457
  fl_alert("Error reading from file \\'%s\\':\\n%s.", newfile.c_str(), strerror(errno));
2235
2466
  E->textbuffer->call_modify_callbacks();
2236
2467
  E->set_syntax();
2237
2468
  E->loading = 0;
 
2469
  E->changed = 0;
2238
2470
  set_title(tabs->value());
2239
 
  std::string tmp = "Documents/"+E->filename;
2240
 
  menu->add(tmp.c_str(),0,choose_doc,this,0);
 
2471
 
 
2472
  std::string tmp = "Documents/" + E->filename;
 
2473
 
 
2474
  menu->add(tmp.c_str(), 0, choose_doc, this, 0);
2241
2475
  menu->redraw();
2242
2476
}} {}
2243
2477
  }
2275
2509
}
2276
2510
theme_button->redraw();} {}
2277
2511
  }
2278
 
  Function {new_cb()} {} {
 
2512
  Function {new_cb()} {open
 
2513
  } {
2279
2514
    code {Fl_Syntax_Text_Editor * textor = current_editor();
 
2515
 
2280
2516
if( (!check_save()) && (textor!=NULL) )
 
2517
{
2281
2518
  return;
 
2519
}
 
2520
 
2282
2521
if (textor==NULL)
2283
2522
{
2284
2523
  add_tab();
2285
2524
  return;
2286
2525
}
 
2526
 
2287
2527
if(textor->filename.compare("Untitled")!=0)
2288
2528
{
2289
2529
  add_tab(true,false);
2290
2530
  return;
2291
2531
}
 
2532
 
2292
2533
textor->filename="";
 
2534
 
2293
2535
Fl_Text_Buffer * buff = textor->buffer();
 
2536
 
2294
2537
buff->select(0, buff->length());
2295
2538
buff->remove_selection();
2296
2539
textor->changed = 0;
2297
2540
buff->call_modify_callbacks();
 
2541
 
2298
2542
if (!check_save())
 
2543
{
2299
2544
  return;
 
2545
}
 
2546
 
2300
2547
textor->filename="";
2301
2548
buff->select(0, buff->length());
2302
2549
buff->remove_selection();
2303
2550
textor->changed = 0;
2304
2551
buff->call_modify_callbacks();} {}
2305
2552
  }
2306
 
  Function {open_cb()} {open
2307
 
  } {
 
2553
  Function {open_cb()} {} {
2308
2554
    code {Fl_Syntax_Text_Editor * E = current_editor();
2309
2555
if(E==NULL)
2310
2556
{
2322
2568
  Function {open_file(bool NEW=true)} {open
2323
2569
  } {
2324
2570
    code {Fl_Syntax_Text_Editor * E = current_editor();
2325
 
//std::string newf="";
2326
 
std::string init="";
2327
 
if(E!=NULL)
 
2571
 
 
2572
std::string init = "";
 
2573
 
 
2574
if(E != NULL)
2328
2575
{
2329
 
  init= E->filename;
 
2576
  init = E->filename;
2330
2577
}
 
2578
 
2331
2579
std::string newfile = file_chooser("*", init.c_str(), "Open File?");
2332
2580
 
2333
 
if(newfile.compare("")!=0)
 
2581
if(newfile.compare("") != 0)
2334
2582
{
2335
 
  load_file(newfile.c_str(), -1,NEW);
 
2583
  load_file(newfile.c_str(), NEW);
2336
2584
}} {}
2337
2585
  }
2338
2586
  Function {paste_cb()} {} {
2395
2643
  return;
2396
2644
}
2397
2645
 
2398
 
print_text(E);} {}
2399
 
  }
2400
 
  Function {print_text(Fl_Syntax_Text_Editor* editor)} {} {
2401
 
    code {Fl_Printer *printer = new Fl_Printer();
2402
 
int font            = editor->textfont();
2403
 
int size            = editor->textsize();
2404
 
//Pages vector?
2405
 
if (printer->start_job(1) == 0)
2406
 
{
2407
 
  print_page(printer,font,size);
2408
 
  printer->end_job();
2409
 
}
2410
 
 
2411
 
delete printer;} {}
2412
 
  }
2413
 
  Function {print_page(Fl_Printer *printer, int font, int size)} {open
2414
 
  } {
2415
 
    code {int x = 0;
2416
 
int y = 0;
2417
 
int w,h;
2418
 
printer->start_page();
2419
 
printer->printable_rect(&w,&h);
2420
 
fl_color(FL_BLACK);
2421
 
fl_rect(x,y,w,h);
2422
 
fl_font(font, size);
2423
 
//TODO figure out how much text fits on a page....
2424
 
//fl_draw();
2425
 
printer->end_page();} {}
 
2646
E->print_text();} {}
2426
2647
  }
2427
2648
  Function {quit_cb()} {} {
2428
2649
    code {Fl_Syntax_Text_Editor * E = current_editor();
2433
2654
}
2434
2655
exit(0);} {}
2435
2656
  }
2436
 
  Function {_recent_CB()} {open
2437
 
  } {
 
2657
  Function {_recent_CB()} {} {
2438
2658
    code {char item[500];
2439
2659
 
2440
2660
if(menu->item_pathname(item, (sizeof(item)-1) )!=0)
2465
2685
{
2466
2686
  unsigned int sizer = tag.length();
2467
2687
  std::string tmp    = str_item.erase(0,sizer);
2468
 
  load_file(tmp,0,newfile);
 
2688
  load_file(tmp, newfile);
2469
2689
}} {}
2470
2690
  }
2471
2691
  Function {replace_cb()} {} {
2472
2692
    code {Fl_Syntax_Text_Editor * E = current_editor();
2473
 
if(E!=NULL)
2474
 
  make_replace()->show();} {}
 
2693
 
 
2694
if(E != NULL)
 
2695
{
 
2696
  make_replace()->show();
 
2697
}} {}
2475
2698
  }
2476
 
  Function {recent_CB(Fl_Widget*w, void*data)} {open return_type {static void}
 
2699
  Function {recent_CB(Fl_Widget*w, void*data)} {return_type {static void}
2477
2700
  } {
2478
2701
    code {UI *o=(UI *)data;
2479
2702
o->_recent_CB();} {}
2480
2703
  }
2481
 
  Function {replace_all_strings(std::string str, const std::string& old, const std::string& new_s, int &counter)} {open return_type {std::string}
 
2704
  Function {replace_all_strings(std::string str, const std::string& old, const std::string& new_s, int &counter)} {return_type {std::string}
2482
2705
  } {
2483
2706
    code {if(!old.empty())
2484
2707
{
2485
 
  size_t pos = str.find(old);
 
2708
  size_t  pos = str.find(old);
2486
2709
  while ((pos = str.find(old, pos)) != std::string::npos)
2487
2710
  {
2488
2711
    counter++;
2489
 
    str=str.replace(pos, old.length(), new_s);
 
2712
 
 
2713
    str  = str.replace(pos, old.length(), new_s);
2490
2714
    pos += new_s.length();
2491
2715
  }
2492
2716
}
 
2717
 
2493
2718
return str;} {}
2494
2719
  }
2495
2720
  Function {replace2_cb()} {} {
2584
2809
o->size(width,height);
2585
2810
o->redraw();} {}
2586
2811
  }
2587
 
  Function {refresh_all()} {open
2588
 
  } {
 
2812
  Function {refresh_all()} {} {
2589
2813
    code {change_theme(FOREGROUND_TEXT,BACKGROUND_TEXT,SELECTION_TEXT,FONT_TEXT,SIZE_TEXT,LINE_NUMBERS);} {}
2590
2814
  }
2591
2815
  Function {save_cb(void)} {} {
2665
2889
  ((Fl_Widget *)(textor->user_data()))->labelcolor(NORMAL_COLOR);
2666
2890
}} {}
2667
2891
  }
2668
 
  Function {set_title(Fl_Widget* g)} {} {
 
2892
  Function {set_title(Fl_Widget* g)} {open
 
2893
  } {
2669
2894
    code {if(g==NULL)
2670
2895
  return;
2671
2896
Fl_Group* gg = (Fl_Group*)g;
2680
2905
//Is the file name empty???  set it to Untitled!!
2681
2906
if (fname.compare("")==0)
2682
2907
{
2683
 
  title="Untitled";
 
2908
  title = "Untitled";
2684
2909
}
2685
2910
else
2686
2911
{
2687
2912
// get JUST the filename (remove the path... similare to fl_filename_name()
2688
2913
  unsigned int slash = fname.rfind('/');
 
2914
 
2689
2915
  \#ifdef WIN32
2690
 
  if (slash>fname.length())
2691
 
    slash =fname.rfind('\\\\');
 
2916
  if (slash > fname.length())
 
2917
  {
 
2918
    slash = fname.rfind('\\\\');
 
2919
  }
2692
2920
  \#endif
2693
 
  if (slash <fname.length())
 
2921
 
 
2922
  if (slash < fname.length())
2694
2923
  {
2695
2924
    //FILENAME ONLY
2696
 
    title=fname.substr(slash+1,std::string::npos);
 
2925
    title = fname.substr(slash+1,std::string::npos);
2697
2926
    //PATH to file ONLY
2698
 
    full = fname.substr(0,slash);
 
2927
    full  = fname.substr(0,slash);
2699
2928
  }
2700
2929
  else
2701
 
    title=fname;
2702
 
    
 
2930
  {
 
2931
    title = fname;
 
2932
  }
2703
2933
}
2704
2934
textor->refresh();
 
2935
 
 
2936
/*
2705
2937
//Has this been changed at all??
2706
2938
if (textor->changed)
2707
2939
{
2708
 
  title+=" (modified)";
 
2940
  title += " (modified)";
2709
2941
}
 
2942
*/
 
2943
 
2710
2944
std::string Ti = title;
2711
2945
 
2712
2946
if(full.compare("")!=0)
2767
3001
if (x.empty()) return 0;
2768
3002
return std::count( x.begin(), std::unique( x.begin(), x.end() ), ' ' ) + !std::isspace( *s.rbegin() );} {}
2769
3003
  }
2770
 
  Function {wordwrap()} {} {
 
3004
  Function {wordwrap()} {open
 
3005
  } {
2771
3006
    code {Fl_Syntax_Text_Editor * E = current_editor();
2772
3007
std::string fname="";
2773
3008
if(E==NULL)
2774
3009
{
2775
3010
  return;
2776
3011
}
2777
 
if(E->WRAPPED)
 
3012
E->word_wrap();} {}
 
3013
  }
 
3014
  Function {page_count()} {open return_type int
 
3015
  } {
 
3016
    code {Fl_Syntax_Text_Editor* E = current_editor();
 
3017
 
 
3018
if(E == NULL)
2778
3019
{
2779
 
  E->WRAPPED=false;
2780
 
  E->wrap_mode(Fl_Text_Display::WRAP_NONE, 0);
2781
 
  WORD_WRAP=0;
 
3020
  return 0;
2782
3021
}
2783
 
else
2784
 
{
2785
 
  E->WRAPPED=true;
2786
 
  E->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
2787
 
  WORD_WRAP=1;
2788
 
}} {}
 
3022
return E->pages();} {}
 
3023
  }
 
3024
  Function {progress_window()} {open
 
3025
  } {
 
3026
    Fl_Window {} {
 
3027
      label {Printer Progress} open
 
3028
      xywh {297 305 440 140} type Double hide
 
3029
    } {
 
3030
      Fl_Progress progress {
 
3031
        xywh {40 80 355 30} box FLAT_BOX color 38 selection_color 71
 
3032
      }
 
3033
    }
2789
3034
  }
2790
3035
}
2791
3036
 
2908
3153
return make_vec(LINE,",");} {}
2909
3154
}
2910
3155
 
 
3156
Function {convert(int num)} {open return_type {std::string}
 
3157
} {
 
3158
  code {std::string number;
 
3159
std::stringstream out;
 
3160
out << num;
 
3161
number = out.str();
 
3162
return number;} {}
 
3163
}
 
3164
 
2911
3165
Function {convert(std::string num, int default_value=0)} {return_type {unsigned int}
2912
3166
} {
2913
3167
  code {unsigned int NUM = default_value;