editor.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #ifndef BDE_EDITOR_H
  17. #define BDE_EDITOR_H
  18. #include "editbox.h"
  19. #include "dialogline.h"
  20. #include "statusline.h"
  21. #include "inputline.h"
  22. #include "speller.h"
  23. class Menubar;
  24. class Scrollbar;
  25. class Editor : public Dispatcher, public EditBoxErrorListener {
  26. public:
  27. enum scrollbar_pos_t { scrlbrNone, scrlbrLeft, scrlbrRight };
  28. protected:
  29. EditBox wedit;
  30. DialogLine dialog;
  31. StatusLine status;
  32. Menubar *menubar;
  33. Scrollbar *scrollbar;
  34. Speller speller;
  35. SpellerWnd *spellerwnd;
  36. u8string filename;
  37. u8string encoding;
  38. u8string default_encoding;
  39. bool new_flag; // is this a new file?
  40. u8string backup_suffix;
  41. u8string speller_encoding;
  42. u8string speller_cmd;
  43. u8string external_editor;
  44. unistring last_searched_string; // for the "search next" command.
  45. bool finished; // exec() quits when this flag is set.
  46. static Editor *global_instance; // for use by the SIGHUP handler.
  47. #ifdef HAVE_CURS_SET
  48. bool big_cursor;
  49. #endif
  50. scrollbar_pos_t scrollbar_pos;
  51. bool syntax_auto_detection;
  52. //
  53. bool query_filename(const char *label, u8string &qry_filename,
  54. u8string &qry_encoding, int history_set = 0,
  55. InputLine::CompleteType complete = InputLine::cmpltAll);
  56. void show_kbd_error(const char *msg);
  57. public:
  58. HAS_ACTIONS_MAP(Editor, Dispatcher);
  59. HAS_BINDINGS_MAP(Editor, Dispatcher);
  60. Editor();
  61. virtual ~Editor() {}
  62. static Editor *get_global_instance() {
  63. return global_instance;
  64. }
  65. //
  66. // Setters / Getters
  67. //
  68. const char *get_encoding() const { return encoding.c_str(); }
  69. const char *get_default_encoding() const { return default_encoding.c_str(); }
  70. const char *get_filename() const { return filename.c_str(); }
  71. const char *get_backup_suffix() const { return backup_suffix.c_str(); }
  72. const char *get_speller_encoding() const { return speller_encoding.c_str(); }
  73. const char *get_speller_cmd() const { return speller_cmd.c_str(); }
  74. void set_encoding(const char *s);
  75. void set_default_encoding(const char *s) { default_encoding = u8string(s); }
  76. void set_filename(const char *s) { filename = u8string(s); }
  77. void set_backup_suffix(const char *s) { backup_suffix = u8string(s); }
  78. void set_speller_encoding(const char *s) { speller_encoding = u8string(s); }
  79. void set_speller_cmd(const char *s) { speller_cmd = u8string(s); }
  80. u8string get_external_editor();
  81. void set_external_editor(const char *cmd);
  82. bool is_new() const { return new_flag; }
  83. bool is_untitled() const { return filename.empty(); }
  84. void set_new(bool value) { new_flag = value; }
  85. bool is_speller_loaded() const { return speller.is_loaded(); }
  86. bool in_spelling() const { return spellerwnd != NULL; }
  87. void set_scrollbar_pos(scrollbar_pos_t);
  88. scrollbar_pos_t get_scrollbar_pos() const { return scrollbar_pos; }
  89. void adjust_speller_cmd();
  90. void set_theme(const char *theme);
  91. INTERACTIVE void set_default_theme();
  92. const char *get_theme_name();
  93. //
  94. // Methods to access EditBox. These are used to set
  95. // command-line options.
  96. //
  97. void set_tab_width(int width) { wedit.set_tab_width(width); }
  98. void set_justification_column(int column)
  99. { wedit.set_justification_column(column); }
  100. void toggle_auto_indent() { wedit.toggle_auto_indent(); }
  101. void toggle_auto_justify() { wedit.toggle_auto_justify(); }
  102. void toggle_formatting_marks() { wedit.toggle_formatting_marks(); }
  103. void go_to_line(int line) { wedit.move_absolute_line(line - 1); }
  104. void set_wrap_type(EditBox::WrapType value) { wedit.set_wrap_type(value); }
  105. void set_dir_algo(diralgo_t value) { wedit.set_dir_algo(value); }
  106. void set_scroll_step(int value) { wedit.set_scroll_step(value); }
  107. void set_smart_typing(bool value) { wedit.set_smart_typing(value); }
  108. void set_rfc2646_trailing_space(bool value)
  109. { wedit.set_rfc2646_trailing_space(value); }
  110. void set_maqaf_display(EditBox::maqaf_display_t disp)
  111. { wedit.set_maqaf_display(disp); }
  112. void set_rtl_nsm_display(EditBox::rtl_nsm_display_t disp)
  113. { wedit.set_rtl_nsm_display(disp); }
  114. void set_undo_size_limit(size_t limit)
  115. { wedit.set_undo_size_limit(limit); }
  116. void set_key_for_key_undo(bool value)
  117. { wedit.set_key_for_key_undo(value); }
  118. void set_read_only(bool value)
  119. { wedit.set_read_only(value); }
  120. void set_non_interactive_text_width(int cols)
  121. { wedit.set_non_interactive_text_width(cols); }
  122. void enable_bidi(bool value) { wedit.enable_bidi(value); }
  123. void log2vis(const char *options);
  124. bool get_syntax_auto_detection()
  125. { return syntax_auto_detection; }
  126. void set_syntax_auto_detection(bool value);
  127. void set_underline(bool value) { wedit.set_underline(value); }
  128. void set_visual_cursor_movement(bool value)
  129. { wedit.set_visual_cursor_movement(value); }
  130. //
  131. // Interactive commands
  132. //
  133. INTERACTIVE void show_character_info();
  134. INTERACTIVE void show_character_code();
  135. INTERACTIVE void refresh_and_center();
  136. INTERACTIVE void describe_key();
  137. INTERACTIVE void toggle_cursor_position_report();
  138. bool is_cursor_position_report() const;
  139. INTERACTIVE void quit();
  140. INTERACTIVE void layout_windows();
  141. INTERACTIVE void menu();
  142. INTERACTIVE void help();
  143. void show_help_topic(const char *topic);
  144. INTERACTIVE void save_file();
  145. INTERACTIVE void save_file_as();
  146. INTERACTIVE void load_file();
  147. INTERACTIVE void insert_file();
  148. INTERACTIVE void write_selection_to_file();
  149. INTERACTIVE void change_tab_width();
  150. INTERACTIVE void change_justification_column();
  151. INTERACTIVE void insert_unicode_char();
  152. INTERACTIVE void go_to_line();
  153. INTERACTIVE void search_forward();
  154. INTERACTIVE void search_forward_next();
  155. INTERACTIVE void change_directory();
  156. INTERACTIVE void toggle_arabic_shaping();
  157. INTERACTIVE void toggle_graphical_boxes();
  158. INTERACTIVE void change_scroll_step();
  159. void menu_set_encoding(bool default_encoding);
  160. INTERACTIVE void menu_set_scrollbar_none();
  161. INTERACTIVE void menu_set_scrollbar_left();
  162. INTERACTIVE void menu_set_scrollbar_right();
  163. INTERACTIVE void load_unload_speller();
  164. INTERACTIVE void spell_check_all();
  165. INTERACTIVE void spell_check_forward();
  166. INTERACTIVE void spell_check_word();
  167. void spell_check(Speller::splRng range);
  168. #ifdef HAVE_CURS_SET
  169. INTERACTIVE void toggle_big_cursor();
  170. #endif
  171. INTERACTIVE void toggle_syntax_auto_detection();
  172. INTERACTIVE void external_edit_prompt();
  173. INTERACTIVE void external_edit_no_prompt();
  174. void external_edit(bool prompt);
  175. //
  176. // Misc
  177. //
  178. void exec();
  179. void emergency_save();
  180. void show_file_io_error(const char *msg, const char *filename);
  181. bool load_file(const char *filename, const char *specified_encoding);
  182. bool save_file(const char *filename, const char *specified_encoding);
  183. bool write_selection_to_file(const char *filename,
  184. const char *specified_encoding);
  185. bool insert_file(const char *raw_filename, const char *encoding);
  186. void search_forward(const unistring &search);
  187. void refresh(bool soft = false);
  188. void update_terminal(bool soft = false);
  189. void show_hint(const char *msg);
  190. void detect_syntax();
  191. #ifdef HAVE_CURS_SET
  192. bool is_big_cursor() const { return big_cursor; }
  193. void set_big_cursor(bool value) {
  194. big_cursor = value;
  195. curs_set(value ? 2 : 1);
  196. }
  197. #endif
  198. // EditBoxErrorListener implementation
  199. virtual void on_read_only_error(unichar ch);
  200. virtual void on_no_selection_error();
  201. virtual void on_no_alt_kbd_error();
  202. virtual void on_no_translation_table_error();
  203. virtual void on_cant_display_nsm_error();
  204. };
  205. #endif