121
121
class Fl_Syntax_Text_Editor {open : {public Fl_Text_Editor}
123
decl {Fl_Printer *printer} {public global
123
125
decl {int inotify_fd;} {public local
125
127
decl {int inotify_wd;} {public local
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
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;
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);
145
// create a basic style text
141
146
char *style = new char[textbuffer->length() + 1];
142
147
char *text = textbuffer->text();
148
//set it to plain .a.k.a. 'A'
144
149
memset(style, 'A', textbuffer->length());
151
// this is the buffer for the syntax highlighting
145
152
stylebuffer = new Fl_Text_Buffer(textbuffer->length());
146
153
style[textbuffer->length()] = '\\0';
154
//get the actual syntax highlighter setup
148
155
init_highlight();
156
//set the highlighter text in the style buffer
150
157
stylebuffer->text(style);
159
//don't need these anymore
163
//make it flat so it looks nicer
155
164
box(FL_FLAT_BOX);
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
176
//whenever the buffer is modified run this function
159
177
textbuffer->add_modify_callback(changed_cb,(void *)this);
162
trace("Failed to take focus for Text Editor");
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);} {}
169
183
Function {~Fl_Syntax_Text_Editor()} {} {
171
185
textbuffer->remove_modify_callback(style_update, this);
172
186
textbuffer->remove_modify_callback(changed_cb, this);
175
194
trace("problem removing inotify watch");
212
231
code {Fl_Syntax_Text_Editor * o = (Fl_Syntax_Text_Editor *)v;
213
232
std::string f = o->filename;
214
235
if ((nInserted || nDeleted) && !o->loading)
218
240
((UI *)(o->parent()->user_data()))->set_title(o->parent());} {}
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}
222
code {kill_selection(e);
244
code {//Basically I copied the original code from the text editor source
247
//I changed this to my widget
223
248
Fl_Syntax_Text_Editor* E = (Fl_Syntax_Text_Editor*)e;
250
//I use the space counter function
224
251
std::string SPACES = E->count_spaces();
225
std::string t = "\\n";
252
// instead of just adding a newline like in the original, I also add the spaces
253
std::string t = "\\n";
227
256
e->insert(t.c_str());
257
//put the cursor right there
228
258
e->show_insert_position();
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)
266
//return 'it worked' this is like the boolean 'true' here
233
Function {file_string()} {open return_type {std::string}
269
Function {file_string()} {return_type {std::string}
235
code {if(filename.compare("")==0){return "";}
271
code {// turn a file into a string
273
//no file sent in... return emptyness
274
if( (filename.compare("")==0) || (!test_file(filename)) )
279
//make our input file stream, and put the file into it
236
280
std::ifstream t(filename);
281
//make our return string
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);
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!
247
296
Function {get_styletable(Fl_Text_Display::Style_Table_Entry &styles,int which)} {open
249
code {int font = FONT_TEXT;
298
code {// this function does all the repetative styletable work,
299
// and keeps it organized in one place
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;
308
//this is in case I need to debug
252
309
std::string whichtype="Plain";
314
// the format: COLOR font NORMAL SIZE
256
315
styles={ FOREGROUND_TEXT, font, FL_NORMAL_SIZE }; // A - Plain
257
316
whichtype="Plain";
288
347
styles={ SPECIAL_TEXT, font, FL_NORMAL_SIZE }; // I - special
291
351
styles={ BROKEN_TEXT, font, FL_NORMAL_SIZE }; // J - Broken :(
294
styletable[which] = styles; // set} {}
356
styletable[which] = styles; // set} {selected
296
359
Function {handle(int event)} {open protected return_type int
351
414
code {return count_lines(0,length(), false);} {}
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
355
code {if(stylebuffer->selected()!=0)
418
code {//if it is a selection change just return
419
if(stylebuffer->selected() != 0)
357
421
stylebuffer->unselect();
361
425
std::string thisLine;
362
if ( (HIGHLIGHT_PLAIN==0)&& (STYLE_HEADER.compare("")==0) )
427
if ( (HIGHLIGHT_PLAIN==0) && (STYLE_HEADER.compare("")==0) )
364
429
char *style = new char[textbuffer->length() + 1];
365
430
memset(style, 'A', textbuffer->length());
371
436
char* buf = this->textbuffer->text();
374
443
std::string out(buf);
375
444
std::string res = style_line(out);
376
445
char* RES = const_cast <char*> (res.c_str());
379
452
stylebuffer->text(RES);
381
455
redisplay_range(0,textbuffer->length());} {}
383
Function {refresh()} {} {
457
Function {refresh()} {open
384
459
code {set_syntax();
385
460
modify_cb(0,0,0,0,NULL);
386
461
redisplay_range(0,textbuffer->length());
486
//trace("error processing text:"+thisLine);
490
564
std::string line = lexertk::helper::style_line(generator);
491
565
if(line.compare("")==0)
493
//trace("adding newline!");
572
// this should never happen....
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);} {}
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
523
599
code {textcolor(FG);
524
600
cursor_color(FG);
528
604
selection_color(selection);
529
605
linenumber_width(linenum);
530
606
linenumber_size(size);
608
///renew syntax highlighting
532
609
update_styletable();
610
//make the syntax highlighter colors
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
537
617
Function {update_styletable()} {} {
665
748
return false;} {}
750
Function {pages()} {open return_type int
752
code {wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
755
int l = line_count();
764
printer->printable_rect(&w, &h);
771
std::cout<<"total pages:"<<total<<std::endl;
774
Function {print_text()} {open
776
code {int font = textfont();
777
int size = textsize();
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)
787
print_page(w, h, font, size, start);
792
int inc = 100 / (end/start);
793
ui->progress_window()->show();
795
ui->progress->value(p_val);
796
std::cout<<"start:"<<start<<" end:"<<end<<std::endl;
797
for (int i = start; i < end; i++)
799
std::cout<<"printing:"<<i<<std::endl;
800
print_page(w, h, font, size, i);
802
std::string num = labl + convert(i);
803
ui->progress->value(p_val);
804
ui->progress->copy_label(num.c_str());
807
ui->progress_window()->hide();
808
std::cout<<"done"<<std::endl;
812
Function {print_page(int w, int h, int font, int size, int page_num)} {open
814
code {std::cout<<"printing:"<<page_num<<" w="<<w<<" h="<<h<<std::endl;
818
printer->start_page();
823
fl_draw( page(page_num).c_str(), x, y, w, h, FL_ALIGN_WRAP );
825
printer->end_page();} {}
827
Function {word_wrap()} {open
832
wrap_mode(Fl_Text_Display::WRAP_NONE, 0);
838
wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
842
Function {page(int num)} {open return_type {std::string}
844
code {int lines = lines_per_page();
845
int start = lines * num;
847
int end = start + lines;
849
const char* text = textbuffer->text_range(start, end);
850
std::cout<<"page:"<<num<<" start:"<<start<<" text:"<<text<<std::endl;
856
std::string t = text;
859
Function {lines_per_page()} {open return_type int
861
code {return (line_count() / pages());} {}
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
828
1030
Fl_Group buttons {open
829
1031
xywh {0 25 520 30} box FLAT_BOX color 48
1305
1507
Function {add_tab(bool LOAD=true, bool NEW = true)} {open
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();
1311
1514
tabs->client_area(x,y,w,h);
1312
1516
Fl_Group* o = new Fl_Group(x, y, w, h);
1313
1517
o->copy_label("Untitled");
1315
1519
Fl_Syntax_Text_Editor* te = new Fl_Syntax_Text_Editor(x,y,w,h);
1316
1521
te->user_data(o);
1318
1523
if(INDENT_NEW_LINES>0)
1388
1596
cut_button->redraw();
1389
1597
print_button->redraw();} {}
1391
Function {change_theme(unsigned int FG,unsigned int BG, unsigned int selection, int font, int size, int line)} {open
1393
code {FOREGROUND_TEXT=FG;
1395
SELECTION_TEXT=selection;
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;
1605
LINE_NUMBERS = line;
1401
for(int i = 0; i < tabs->children();i++)
1612
for(int i = 0; i < tabs->children(); i++)
1403
1614
Fl_Group* tab = tabs->child(i)->as_group();
1404
1615
Fl_Syntax_Text_Editor * e = (Fl_Syntax_Text_Editor *)tab->child(0);
1405
1617
e->theme_editor(FG,BG,selection,font,size,line);
1695
1910
Function {dnd_file(const char* items, bool NEW=true)} {} {
1696
1911
code {if(items==NULL)
1698
1916
std::string tmp = items;
1699
1918
std::vector<std::string> V = dnd_vec(tmp);
1700
for( std::vector<std::string>::iterator itr = V.begin();
1919
std::vector<std::string>::iterator itr;
1921
for( itr = V.begin();
1704
1925
std::string s = *itr;
1705
1926
std::string txt = *itr;
1707
1928
unsigned int URI = s.find("file:///");
1710
1932
s = s.substr(7,std::string::npos);
1712
1935
URI = s.find("\\n");
1937
if(URI < s.length())
1939
s = s.substr(0,URI);
1717
1942
char *ch = strdup(s.c_str());
1718
1943
fl_decode_uri(ch);
1721
1946
if(test_file(s))
1723
load_file(s,-1,NEW);
1727
1952
Fl_Syntax_Text_Editor * E = current_editor();
1733
1959
Fl_Text_Buffer * buff = E->buffer();
1734
1960
int pos = E->insert_position();
1735
1961
buff->insert(pos, txt.c_str());
2235
2466
E->textbuffer->call_modify_callbacks();
2236
2467
E->set_syntax();
2237
2468
E->loading = 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);
2472
std::string tmp = "Documents/" + E->filename;
2474
menu->add(tmp.c_str(), 0, choose_doc, this, 0);
2241
2475
menu->redraw();
2276
2510
theme_button->redraw();} {}
2278
Function {new_cb()} {} {
2512
Function {new_cb()} {open
2279
2514
code {Fl_Syntax_Text_Editor * textor = current_editor();
2280
2516
if( (!check_save()) && (textor!=NULL) )
2282
2521
if (textor==NULL)
2287
2527
if(textor->filename.compare("Untitled")!=0)
2289
2529
add_tab(true,false);
2292
2533
textor->filename="";
2293
2535
Fl_Text_Buffer * buff = textor->buffer();
2294
2537
buff->select(0, buff->length());
2295
2538
buff->remove_selection();
2296
2539
textor->changed = 0;
2297
2540
buff->call_modify_callbacks();
2298
2542
if (!check_save())
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();} {}
2306
Function {open_cb()} {open
2553
Function {open_cb()} {} {
2308
2554
code {Fl_Syntax_Text_Editor * E = current_editor();
2322
2568
Function {open_file(bool NEW=true)} {open
2324
2570
code {Fl_Syntax_Text_Editor * E = current_editor();
2325
//std::string newf="";
2326
std::string init="";
2572
std::string init = "";
2331
2579
std::string newfile = file_chooser("*", init.c_str(), "Open File?");
2333
if(newfile.compare("")!=0)
2581
if(newfile.compare("") != 0)
2335
load_file(newfile.c_str(), -1,NEW);
2583
load_file(newfile.c_str(), NEW);
2338
2586
Function {paste_cb()} {} {
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();
2405
if (printer->start_job(1) == 0)
2407
print_page(printer,font,size);
2413
Function {print_page(Fl_Printer *printer, int font, int size)} {open
2418
printer->start_page();
2419
printer->printable_rect(&w,&h);
2422
fl_font(font, size);
2423
//TODO figure out how much text fits on a page....
2425
printer->end_page();} {}
2646
E->print_text();} {}
2427
2648
Function {quit_cb()} {} {
2428
2649
code {Fl_Syntax_Text_Editor * E = current_editor();
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);
2471
2691
Function {replace_cb()} {} {
2472
2692
code {Fl_Syntax_Text_Editor * E = current_editor();
2474
make_replace()->show();} {}
2696
make_replace()->show();
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}
2478
2701
code {UI *o=(UI *)data;
2479
2702
o->_recent_CB();} {}
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}
2483
2706
code {if(!old.empty())
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)
2489
str=str.replace(pos, old.length(), new_s);
2713
str = str.replace(pos, old.length(), new_s);
2490
2714
pos += new_s.length();
2493
2718
return str;} {}
2495
2720
Function {replace2_cb()} {} {
2680
2905
//Is the file name empty??? set it to Untitled!!
2681
2906
if (fname.compare("")==0)
2687
2912
// get JUST the filename (remove the path... similare to fl_filename_name()
2688
2913
unsigned int slash = fname.rfind('/');
2690
if (slash>fname.length())
2691
slash =fname.rfind('\\\\');
2916
if (slash > fname.length())
2918
slash = fname.rfind('\\\\');
2693
if (slash <fname.length())
2922
if (slash < fname.length())
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);
2704
2934
textor->refresh();
2705
2937
//Has this been changed at all??
2706
2938
if (textor->changed)
2708
title+=" (modified)";
2940
title += " (modified)";
2710
2944
std::string Ti = title;
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() );} {}
2770
Function {wordwrap()} {} {
3004
Function {wordwrap()} {open
2771
3006
code {Fl_Syntax_Text_Editor * E = current_editor();
2772
3007
std::string fname="";
3014
Function {page_count()} {open return_type int
3016
code {Fl_Syntax_Text_Editor* E = current_editor();
2780
E->wrap_mode(Fl_Text_Display::WRAP_NONE, 0);
2786
E->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0);
3022
return E->pages();} {}
3024
Function {progress_window()} {open
3027
label {Printer Progress} open
3028
xywh {297 305 440 140} type Double hide
3030
Fl_Progress progress {
3031
xywh {40 80 355 30} box FLAT_BOX color 38 selection_color 71