PageRenderTime 35ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/fltk-1.3.0/test/editor.cxx

#
C++ | 817 lines | 594 code | 122 blank | 101 comment | 144 complexity | 15fbd8bfabbf7e57a6bc8baa1c729c99 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0
  1. //
  2. // "$Id: editor.cxx 8602 2011-04-18 11:29:30Z manolo $"
  3. //
  4. // A simple text editor program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // This program is described in Chapter 4 of the FLTK Programmer's Guide.
  7. //
  8. // Copyright 1998-2010 by Bill Spitzak and others.
  9. //
  10. // This library is free software; you can redistribute it and/or
  11. // modify it under the terms of the GNU Library General Public
  12. // License as published by the Free Software Foundation; either
  13. // version 2 of the License, or (at your option) any later version.
  14. //
  15. // This library is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. // Library General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Library General Public
  21. // License along with this library; if not, write to the Free Software
  22. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  23. // USA.
  24. //
  25. // Please report all bugs and problems on the following page:
  26. //
  27. // http://www.fltk.org/str.php
  28. //
  29. //
  30. // Include necessary headers...
  31. //
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <ctype.h>
  36. #include <errno.h>
  37. #ifdef __MWERKS__
  38. # define FL_DLL
  39. #endif
  40. #include <FL/Fl.H>
  41. #include <FL/Fl_Group.H>
  42. #include <FL/Fl_Double_Window.H>
  43. #include <FL/fl_ask.H>
  44. #include <FL/Fl_Native_File_Chooser.H>
  45. #include <FL/Fl_Menu_Bar.H>
  46. #include <FL/Fl_Input.H>
  47. #include <FL/Fl_Button.H>
  48. #include <FL/Fl_Return_Button.H>
  49. #include <FL/Fl_Text_Buffer.H>
  50. #include <FL/Fl_Text_Editor.H>
  51. #include <FL/filename.H>
  52. int changed = 0;
  53. char filename[FL_PATH_MAX] = "";
  54. char title[FL_PATH_MAX];
  55. Fl_Text_Buffer *textbuf = 0;
  56. // Syntax highlighting stuff...
  57. #define TS 14 // default editor textsize
  58. Fl_Text_Buffer *stylebuf = 0;
  59. Fl_Text_Display::Style_Table_Entry
  60. styletable[] = { // Style table
  61. { FL_BLACK, FL_COURIER, TS }, // A - Plain
  62. { FL_DARK_GREEN, FL_HELVETICA_ITALIC, TS }, // B - Line comments
  63. { FL_DARK_GREEN, FL_HELVETICA_ITALIC, TS }, // C - Block comments
  64. { FL_BLUE, FL_COURIER, TS }, // D - Strings
  65. { FL_DARK_RED, FL_COURIER, TS }, // E - Directives
  66. { FL_DARK_RED, FL_COURIER_BOLD, TS }, // F - Types
  67. { FL_BLUE, FL_COURIER_BOLD, TS }, // G - Keywords
  68. };
  69. const char *code_keywords[] = { // List of known C/C++ keywords...
  70. "and",
  71. "and_eq",
  72. "asm",
  73. "bitand",
  74. "bitor",
  75. "break",
  76. "case",
  77. "catch",
  78. "compl",
  79. "continue",
  80. "default",
  81. "delete",
  82. "do",
  83. "else",
  84. "false",
  85. "for",
  86. "goto",
  87. "if",
  88. "new",
  89. "not",
  90. "not_eq",
  91. "operator",
  92. "or",
  93. "or_eq",
  94. "return",
  95. "switch",
  96. "template",
  97. "this",
  98. "throw",
  99. "true",
  100. "try",
  101. "while",
  102. "xor",
  103. "xor_eq"
  104. };
  105. const char *code_types[] = { // List of known C/C++ types...
  106. "auto",
  107. "bool",
  108. "char",
  109. "class",
  110. "const",
  111. "const_cast",
  112. "double",
  113. "dynamic_cast",
  114. "enum",
  115. "explicit",
  116. "extern",
  117. "float",
  118. "friend",
  119. "inline",
  120. "int",
  121. "long",
  122. "mutable",
  123. "namespace",
  124. "private",
  125. "protected",
  126. "public",
  127. "register",
  128. "short",
  129. "signed",
  130. "sizeof",
  131. "static",
  132. "static_cast",
  133. "struct",
  134. "template",
  135. "typedef",
  136. "typename",
  137. "union",
  138. "unsigned",
  139. "virtual",
  140. "void",
  141. "volatile"
  142. };
  143. //
  144. // 'compare_keywords()' - Compare two keywords...
  145. //
  146. extern "C" {
  147. int
  148. compare_keywords(const void *a,
  149. const void *b) {
  150. return (strcmp(*((const char **)a), *((const char **)b)));
  151. }
  152. }
  153. //
  154. // 'style_parse()' - Parse text and produce style data.
  155. //
  156. void
  157. style_parse(const char *text,
  158. char *style,
  159. int length) {
  160. char current;
  161. int col;
  162. int last;
  163. char buf[255],
  164. *bufptr;
  165. const char *temp;
  166. // Style letters:
  167. //
  168. // A - Plain
  169. // B - Line comments
  170. // C - Block comments
  171. // D - Strings
  172. // E - Directives
  173. // F - Types
  174. // G - Keywords
  175. for (current = *style, col = 0, last = 0; length > 0; length --, text ++) {
  176. if (current == 'B' || current == 'F' || current == 'G') current = 'A';
  177. if (current == 'A') {
  178. // Check for directives, comments, strings, and keywords...
  179. if (col == 0 && *text == '#') {
  180. // Set style to directive
  181. current = 'E';
  182. } else if (strncmp(text, "//", 2) == 0) {
  183. current = 'B';
  184. for (; length > 0 && *text != '\n'; length --, text ++) *style++ = 'B';
  185. if (length == 0) break;
  186. } else if (strncmp(text, "/*", 2) == 0) {
  187. current = 'C';
  188. } else if (strncmp(text, "\\\"", 2) == 0) {
  189. // Quoted quote...
  190. *style++ = current;
  191. *style++ = current;
  192. text ++;
  193. length --;
  194. col += 2;
  195. continue;
  196. } else if (*text == '\"') {
  197. current = 'D';
  198. } else if (!last && (islower((*text)&255) || *text == '_')) {
  199. // Might be a keyword...
  200. for (temp = text, bufptr = buf;
  201. (islower((*temp)&255) || *temp == '_') && bufptr < (buf + sizeof(buf) - 1);
  202. *bufptr++ = *temp++);
  203. if (!islower((*temp)&255) && *temp != '_') {
  204. *bufptr = '\0';
  205. bufptr = buf;
  206. if (bsearch(&bufptr, code_types,
  207. sizeof(code_types) / sizeof(code_types[0]),
  208. sizeof(code_types[0]), compare_keywords)) {
  209. while (text < temp) {
  210. *style++ = 'F';
  211. text ++;
  212. length --;
  213. col ++;
  214. }
  215. text --;
  216. length ++;
  217. last = 1;
  218. continue;
  219. } else if (bsearch(&bufptr, code_keywords,
  220. sizeof(code_keywords) / sizeof(code_keywords[0]),
  221. sizeof(code_keywords[0]), compare_keywords)) {
  222. while (text < temp) {
  223. *style++ = 'G';
  224. text ++;
  225. length --;
  226. col ++;
  227. }
  228. text --;
  229. length ++;
  230. last = 1;
  231. continue;
  232. }
  233. }
  234. }
  235. } else if (current == 'C' && strncmp(text, "*/", 2) == 0) {
  236. // Close a C comment...
  237. *style++ = current;
  238. *style++ = current;
  239. text ++;
  240. length --;
  241. current = 'A';
  242. col += 2;
  243. continue;
  244. } else if (current == 'D') {
  245. // Continuing in string...
  246. if (strncmp(text, "\\\"", 2) == 0) {
  247. // Quoted end quote...
  248. *style++ = current;
  249. *style++ = current;
  250. text ++;
  251. length --;
  252. col += 2;
  253. continue;
  254. } else if (*text == '\"') {
  255. // End quote...
  256. *style++ = current;
  257. col ++;
  258. current = 'A';
  259. continue;
  260. }
  261. }
  262. // Copy style info...
  263. if (current == 'A' && (*text == '{' || *text == '}')) *style++ = 'G';
  264. else *style++ = current;
  265. col ++;
  266. last = isalnum((*text)&255) || *text == '_' || *text == '.';
  267. if (*text == '\n') {
  268. // Reset column and possibly reset the style
  269. col = 0;
  270. if (current == 'B' || current == 'E') current = 'A';
  271. }
  272. }
  273. }
  274. //
  275. // 'style_init()' - Initialize the style buffer...
  276. //
  277. void
  278. style_init(void) {
  279. char *style = new char[textbuf->length() + 1];
  280. char *text = textbuf->text();
  281. memset(style, 'A', textbuf->length());
  282. style[textbuf->length()] = '\0';
  283. if (!stylebuf) stylebuf = new Fl_Text_Buffer(textbuf->length());
  284. style_parse(text, style, textbuf->length());
  285. stylebuf->text(style);
  286. delete[] style;
  287. free(text);
  288. }
  289. //
  290. // 'style_unfinished_cb()' - Update unfinished styles.
  291. //
  292. void
  293. style_unfinished_cb(int, void*) {
  294. }
  295. //
  296. // 'style_update()' - Update the style buffer...
  297. //
  298. void
  299. style_update(int pos, // I - Position of update
  300. int nInserted, // I - Number of inserted chars
  301. int nDeleted, // I - Number of deleted chars
  302. int /*nRestyled*/, // I - Number of restyled chars
  303. const char * /*deletedText*/,// I - Text that was deleted
  304. void *cbArg) { // I - Callback data
  305. int start, // Start of text
  306. end; // End of text
  307. char last, // Last style on line
  308. *style, // Style data
  309. *text; // Text data
  310. // If this is just a selection change, just unselect the style buffer...
  311. if (nInserted == 0 && nDeleted == 0) {
  312. stylebuf->unselect();
  313. return;
  314. }
  315. // Track changes in the text buffer...
  316. if (nInserted > 0) {
  317. // Insert characters into the style buffer...
  318. style = new char[nInserted + 1];
  319. memset(style, 'A', nInserted);
  320. style[nInserted] = '\0';
  321. stylebuf->replace(pos, pos + nDeleted, style);
  322. delete[] style;
  323. } else {
  324. // Just delete characters in the style buffer...
  325. stylebuf->remove(pos, pos + nDeleted);
  326. }
  327. // Select the area that was just updated to avoid unnecessary
  328. // callbacks...
  329. stylebuf->select(pos, pos + nInserted - nDeleted);
  330. // Re-parse the changed region; we do this by parsing from the
  331. // beginning of the previous line of the changed region to the end of
  332. // the line of the changed region... Then we check the last
  333. // style character and keep updating if we have a multi-line
  334. // comment character...
  335. start = textbuf->line_start(pos);
  336. // if (start > 0) start = textbuf->line_start(start - 1);
  337. end = textbuf->line_end(pos + nInserted);
  338. text = textbuf->text_range(start, end);
  339. style = stylebuf->text_range(start, end);
  340. if (start==end)
  341. last = 0;
  342. else
  343. last = style[end - start - 1];
  344. // printf("start = %d, end = %d, text = \"%s\", style = \"%s\", last='%c'...\n",
  345. // start, end, text, style, last);
  346. style_parse(text, style, end - start);
  347. // printf("new style = \"%s\", new last='%c'...\n",
  348. // style, style[end - start - 1]);
  349. stylebuf->replace(start, end, style);
  350. ((Fl_Text_Editor *)cbArg)->redisplay_range(start, end);
  351. if (start==end || last != style[end - start - 1]) {
  352. // printf("Recalculate the rest of the buffer style\n");
  353. // Either the user deleted some text, or the last character
  354. // on the line changed styles, so reparse the
  355. // remainder of the buffer...
  356. free(text);
  357. free(style);
  358. end = textbuf->length();
  359. text = textbuf->text_range(start, end);
  360. style = stylebuf->text_range(start, end);
  361. style_parse(text, style, end - start);
  362. stylebuf->replace(start, end, style);
  363. ((Fl_Text_Editor *)cbArg)->redisplay_range(start, end);
  364. }
  365. free(text);
  366. free(style);
  367. }
  368. // Editor window functions and class...
  369. void save_cb();
  370. void saveas_cb();
  371. void find2_cb(Fl_Widget*, void*);
  372. void replall_cb(Fl_Widget*, void*);
  373. void replace2_cb(Fl_Widget*, void*);
  374. void replcan_cb(Fl_Widget*, void*);
  375. class EditorWindow : public Fl_Double_Window {
  376. public:
  377. EditorWindow(int w, int h, const char* t);
  378. ~EditorWindow();
  379. Fl_Window *replace_dlg;
  380. Fl_Input *replace_find;
  381. Fl_Input *replace_with;
  382. Fl_Button *replace_all;
  383. Fl_Return_Button *replace_next;
  384. Fl_Button *replace_cancel;
  385. Fl_Text_Editor *editor;
  386. char search[256];
  387. };
  388. EditorWindow::EditorWindow(int w, int h, const char* t) : Fl_Double_Window(w, h, t) {
  389. replace_dlg = new Fl_Window(300, 105, "Replace");
  390. replace_find = new Fl_Input(80, 10, 210, 25, "Find:");
  391. replace_find->align(FL_ALIGN_LEFT);
  392. replace_with = new Fl_Input(80, 40, 210, 25, "Replace:");
  393. replace_with->align(FL_ALIGN_LEFT);
  394. replace_all = new Fl_Button(10, 70, 90, 25, "Replace All");
  395. replace_all->callback((Fl_Callback *)replall_cb, this);
  396. replace_next = new Fl_Return_Button(105, 70, 120, 25, "Replace Next");
  397. replace_next->callback((Fl_Callback *)replace2_cb, this);
  398. replace_cancel = new Fl_Button(230, 70, 60, 25, "Cancel");
  399. replace_cancel->callback((Fl_Callback *)replcan_cb, this);
  400. replace_dlg->end();
  401. replace_dlg->set_non_modal();
  402. editor = 0;
  403. *search = (char)0;
  404. }
  405. EditorWindow::~EditorWindow() {
  406. delete replace_dlg;
  407. }
  408. int check_save(void) {
  409. if (!changed) return 1;
  410. int r = fl_choice("The current file has not been saved.\n"
  411. "Would you like to save it now?",
  412. "Cancel", "Save", "Don't Save");
  413. if (r == 1) {
  414. save_cb(); // Save the file...
  415. return !changed;
  416. }
  417. return (r == 2) ? 1 : 0;
  418. }
  419. int loading = 0;
  420. void load_file(const char *newfile, int ipos) {
  421. loading = 1;
  422. int insert = (ipos != -1);
  423. changed = insert;
  424. if (!insert) strcpy(filename, "");
  425. int r;
  426. if (!insert) r = textbuf->loadfile(newfile);
  427. else r = textbuf->insertfile(newfile, ipos);
  428. changed = changed || textbuf->input_file_was_transcoded;
  429. if (r)
  430. fl_alert("Error reading from file \'%s\':\n%s.", newfile, strerror(errno));
  431. else
  432. if (!insert) strcpy(filename, newfile);
  433. loading = 0;
  434. textbuf->call_modify_callbacks();
  435. }
  436. void save_file(const char *newfile) {
  437. if (textbuf->savefile(newfile))
  438. fl_alert("Error writing to file \'%s\':\n%s.", newfile, strerror(errno));
  439. else
  440. strcpy(filename, newfile);
  441. changed = 0;
  442. textbuf->call_modify_callbacks();
  443. }
  444. void copy_cb(Fl_Widget*, void* v) {
  445. EditorWindow* e = (EditorWindow*)v;
  446. Fl_Text_Editor::kf_copy(0, e->editor);
  447. }
  448. void cut_cb(Fl_Widget*, void* v) {
  449. EditorWindow* e = (EditorWindow*)v;
  450. Fl_Text_Editor::kf_cut(0, e->editor);
  451. }
  452. void delete_cb(Fl_Widget*, void*) {
  453. textbuf->remove_selection();
  454. }
  455. void find_cb(Fl_Widget* w, void* v) {
  456. EditorWindow* e = (EditorWindow*)v;
  457. const char *val;
  458. val = fl_input("Search String:", e->search);
  459. if (val != NULL) {
  460. // User entered a string - go find it!
  461. strcpy(e->search, val);
  462. find2_cb(w, v);
  463. }
  464. }
  465. void find2_cb(Fl_Widget* w, void* v) {
  466. EditorWindow* e = (EditorWindow*)v;
  467. if (e->search[0] == '\0') {
  468. // Search string is blank; get a new one...
  469. find_cb(w, v);
  470. return;
  471. }
  472. int pos = e->editor->insert_position();
  473. int found = textbuf->search_forward(pos, e->search, &pos);
  474. if (found) {
  475. // Found a match; select and update the position...
  476. textbuf->select(pos, pos+strlen(e->search));
  477. e->editor->insert_position(pos+strlen(e->search));
  478. e->editor->show_insert_position();
  479. }
  480. else fl_alert("No occurrences of \'%s\' found!", e->search);
  481. }
  482. void set_title(Fl_Window* w) {
  483. if (filename[0] == '\0') strcpy(title, "Untitled");
  484. else {
  485. char *slash;
  486. slash = strrchr(filename, '/');
  487. #ifdef WIN32
  488. if (slash == NULL) slash = strrchr(filename, '\\');
  489. #endif
  490. if (slash != NULL) strcpy(title, slash + 1);
  491. else strcpy(title, filename);
  492. }
  493. if (changed) strcat(title, " (modified)");
  494. w->label(title);
  495. }
  496. void changed_cb(int, int nInserted, int nDeleted,int, const char*, void* v) {
  497. if ((nInserted || nDeleted) && !loading) changed = 1;
  498. EditorWindow *w = (EditorWindow *)v;
  499. set_title(w);
  500. if (loading) w->editor->show_insert_position();
  501. }
  502. void new_cb(Fl_Widget*, void*) {
  503. if (!check_save()) return;
  504. filename[0] = '\0';
  505. textbuf->select(0, textbuf->length());
  506. textbuf->remove_selection();
  507. changed = 0;
  508. textbuf->call_modify_callbacks();
  509. }
  510. void open_cb(Fl_Widget*, void*) {
  511. if (!check_save()) return;
  512. Fl_Native_File_Chooser fnfc;
  513. fnfc.title("Open file");
  514. fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
  515. if ( fnfc.show() ) return;
  516. load_file(fnfc.filename(), -1);
  517. }
  518. void insert_cb(Fl_Widget*, void *v) {
  519. Fl_Native_File_Chooser fnfc;
  520. fnfc.title("Insert file");
  521. fnfc.type(Fl_Native_File_Chooser::BROWSE_FILE);
  522. if ( fnfc.show() ) return;
  523. EditorWindow *w = (EditorWindow *)v;
  524. load_file(fnfc.filename(), w->editor->insert_position());
  525. }
  526. void paste_cb(Fl_Widget*, void* v) {
  527. EditorWindow* e = (EditorWindow*)v;
  528. Fl_Text_Editor::kf_paste(0, e->editor);
  529. }
  530. int num_windows = 0;
  531. void close_cb(Fl_Widget*, void* v) {
  532. EditorWindow* w = (EditorWindow*)v;
  533. if (num_windows == 1) {
  534. if (!check_save())
  535. return;
  536. }
  537. w->hide();
  538. w->editor->buffer(0);
  539. textbuf->remove_modify_callback(style_update, w->editor);
  540. textbuf->remove_modify_callback(changed_cb, w);
  541. Fl::delete_widget(w);
  542. num_windows--;
  543. if (!num_windows) exit(0);
  544. }
  545. void quit_cb(Fl_Widget*, void*) {
  546. if (changed && !check_save())
  547. return;
  548. exit(0);
  549. }
  550. void replace_cb(Fl_Widget*, void* v) {
  551. EditorWindow* e = (EditorWindow*)v;
  552. e->replace_dlg->show();
  553. }
  554. void replace2_cb(Fl_Widget*, void* v) {
  555. EditorWindow* e = (EditorWindow*)v;
  556. const char *find = e->replace_find->value();
  557. const char *replace = e->replace_with->value();
  558. if (find[0] == '\0') {
  559. // Search string is blank; get a new one...
  560. e->replace_dlg->show();
  561. return;
  562. }
  563. e->replace_dlg->hide();
  564. int pos = e->editor->insert_position();
  565. int found = textbuf->search_forward(pos, find, &pos);
  566. if (found) {
  567. // Found a match; update the position and replace text...
  568. textbuf->select(pos, pos+strlen(find));
  569. textbuf->remove_selection();
  570. textbuf->insert(pos, replace);
  571. textbuf->select(pos, pos+strlen(replace));
  572. e->editor->insert_position(pos+strlen(replace));
  573. e->editor->show_insert_position();
  574. }
  575. else fl_alert("No occurrences of \'%s\' found!", find);
  576. }
  577. void replall_cb(Fl_Widget*, void* v) {
  578. EditorWindow* e = (EditorWindow*)v;
  579. const char *find = e->replace_find->value();
  580. const char *replace = e->replace_with->value();
  581. find = e->replace_find->value();
  582. if (find[0] == '\0') {
  583. // Search string is blank; get a new one...
  584. e->replace_dlg->show();
  585. return;
  586. }
  587. e->replace_dlg->hide();
  588. e->editor->insert_position(0);
  589. int times = 0;
  590. // Loop through the whole string
  591. for (int found = 1; found;) {
  592. int pos = e->editor->insert_position();
  593. found = textbuf->search_forward(pos, find, &pos);
  594. if (found) {
  595. // Found a match; update the position and replace text...
  596. textbuf->select(pos, pos+strlen(find));
  597. textbuf->remove_selection();
  598. textbuf->insert(pos, replace);
  599. e->editor->insert_position(pos+strlen(replace));
  600. e->editor->show_insert_position();
  601. times++;
  602. }
  603. }
  604. if (times) fl_message("Replaced %d occurrences.", times);
  605. else fl_alert("No occurrences of \'%s\' found!", find);
  606. }
  607. void replcan_cb(Fl_Widget*, void* v) {
  608. EditorWindow* e = (EditorWindow*)v;
  609. e->replace_dlg->hide();
  610. }
  611. void save_cb() {
  612. if (filename[0] == '\0') {
  613. // No filename - get one!
  614. saveas_cb();
  615. return;
  616. }
  617. else save_file(filename);
  618. }
  619. void saveas_cb() {
  620. Fl_Native_File_Chooser fnfc;
  621. fnfc.title("Save File As?");
  622. fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
  623. if ( fnfc.show() ) return;
  624. save_file(fnfc.filename());
  625. }
  626. Fl_Window* new_view();
  627. void view_cb(Fl_Widget*, void*) {
  628. Fl_Window* w = new_view();
  629. w->show();
  630. }
  631. Fl_Menu_Item menuitems[] = {
  632. { "&File", 0, 0, 0, FL_SUBMENU },
  633. { "&New File", 0, (Fl_Callback *)new_cb },
  634. { "&Open File...", FL_COMMAND + 'o', (Fl_Callback *)open_cb },
  635. { "&Insert File...", FL_COMMAND + 'i', (Fl_Callback *)insert_cb, 0, FL_MENU_DIVIDER },
  636. { "&Save File", FL_COMMAND + 's', (Fl_Callback *)save_cb },
  637. { "Save File &As...", FL_COMMAND + FL_SHIFT + 's', (Fl_Callback *)saveas_cb, 0, FL_MENU_DIVIDER },
  638. { "New &View", FL_ALT
  639. #ifdef __APPLE__
  640. + FL_COMMAND
  641. #endif
  642. + 'v', (Fl_Callback *)view_cb, 0 },
  643. { "&Close View", FL_COMMAND + 'w', (Fl_Callback *)close_cb, 0, FL_MENU_DIVIDER },
  644. { "E&xit", FL_COMMAND + 'q', (Fl_Callback *)quit_cb, 0 },
  645. { 0 },
  646. { "&Edit", 0, 0, 0, FL_SUBMENU },
  647. { "Cu&t", FL_COMMAND + 'x', (Fl_Callback *)cut_cb },
  648. { "&Copy", FL_COMMAND + 'c', (Fl_Callback *)copy_cb },
  649. { "&Paste", FL_COMMAND + 'v', (Fl_Callback *)paste_cb },
  650. { "&Delete", 0, (Fl_Callback *)delete_cb },
  651. { 0 },
  652. { "&Search", 0, 0, 0, FL_SUBMENU },
  653. { "&Find...", FL_COMMAND + 'f', (Fl_Callback *)find_cb },
  654. { "F&ind Again", FL_COMMAND + 'g', find2_cb },
  655. { "&Replace...", FL_COMMAND + 'r', replace_cb },
  656. { "Re&place Again", FL_COMMAND + 't', replace2_cb },
  657. { 0 },
  658. { 0 }
  659. };
  660. Fl_Window* new_view() {
  661. EditorWindow* w = new EditorWindow(660, 400, title);
  662. w->begin();
  663. Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 660, 30);
  664. m->copy(menuitems, w);
  665. w->editor = new Fl_Text_Editor(0, 30, 660, 370);
  666. w->editor->textfont(FL_COURIER);
  667. w->editor->textsize(TS);
  668. //w->editor->wrap_mode(Fl_Text_Editor::WRAP_AT_BOUNDS, 250);
  669. w->editor->buffer(textbuf);
  670. w->editor->highlight_data(stylebuf, styletable,
  671. sizeof(styletable) / sizeof(styletable[0]),
  672. 'A', style_unfinished_cb, 0);
  673. textbuf->text();
  674. style_init();
  675. w->end();
  676. w->resizable(w->editor);
  677. w->callback((Fl_Callback *)close_cb, w);
  678. textbuf->add_modify_callback(style_update, w->editor);
  679. textbuf->add_modify_callback(changed_cb, w);
  680. textbuf->call_modify_callbacks();
  681. num_windows++;
  682. return w;
  683. }
  684. int main(int argc, char **argv) {
  685. textbuf = new Fl_Text_Buffer;
  686. //textbuf->transcoding_warning_action = NULL;
  687. style_init();
  688. Fl_Window* window = new_view();
  689. window->show(1, argv);
  690. if (argc > 1) load_file(argv[1], -1);
  691. return Fl::run();
  692. }
  693. //
  694. // End of "$Id: editor.cxx 8602 2011-04-18 11:29:30Z manolo $".
  695. //