comparison liboctave/util/cmd-edit.cc @ 16539:8ea8df0747e9

make undo button and menu item work for command window * main-window.h, main-window.cc (main_window::handle_undo_request, main_window::command_window_undo_callback): New functions. (main_window::construct_edit_menu): Connect _undo_action::triggered to main_window::handle_undo_request. * cmd-edit.h, cmd-edit.cc (command_window::redisplay, command_window::do_redisplay, command_window::undo, command_window::do_undo, gnu_readline::do_redisplay, gnu_readline::do_undo): New functions. * oct-rl-edit.h, oct-rl-edit.c (octave_rl_do_undo): New function.
author John W. Eaton <jwe@octave.org>
date Thu, 18 Apr 2013 03:19:48 -0400
parents 106a38d7b396
children d5ae5aa80d42
comparison
equal deleted inserted replaced
16538:8e180eac78d0 16539:8ea8df0747e9
84 84
85 void do_set_output_stream (FILE *f); 85 void do_set_output_stream (FILE *f);
86 86
87 FILE *do_get_output_stream (void); 87 FILE *do_get_output_stream (void);
88 88
89 void do_redisplay (void);
90
89 int do_terminal_rows (void); 91 int do_terminal_rows (void);
90 92
91 int do_terminal_cols (void); 93 int do_terminal_cols (void);
92 94
93 void do_clear_screen (bool skip_redisplay); 95 void do_clear_screen (bool skip_redisplay);
140 void do_insert_text (const std::string& text); 142 void do_insert_text (const std::string& text);
141 143
142 void do_newline (void); 144 void do_newline (void);
143 145
144 void do_accept_line (void); 146 void do_accept_line (void);
147
148 bool do_undo (void);
145 149
146 void do_clear_undo_list (void); 150 void do_clear_undo_list (void);
147 151
148 void set_startup_hook (startup_hook_fcn f); 152 void set_startup_hook (startup_hook_fcn f);
149 153
288 292
289 FILE * 293 FILE *
290 gnu_readline::do_get_output_stream (void) 294 gnu_readline::do_get_output_stream (void)
291 { 295 {
292 return ::octave_rl_get_output_stream (); 296 return ::octave_rl_get_output_stream ();
297 }
298
299 void
300 gnu_readline::do_redisplay (void)
301 {
302 ::octave_rl_redisplay ();
293 } 303 }
294 304
295 // GNU readline handles SIGWINCH, so these values have a good chance 305 // GNU readline handles SIGWINCH, so these values have a good chance
296 // of being correct even if the window changes size (they may be 306 // of being correct even if the window changes size (they may be
297 // wrong if, for example, the luser changes the window size while the 307 // wrong if, for example, the luser changes the window size while the
528 gnu_readline::do_accept_line (void) 538 gnu_readline::do_accept_line (void)
529 { 539 {
530 command_accept_line (1, '\n'); 540 command_accept_line (1, '\n');
531 } 541 }
532 542
543 bool
544 gnu_readline::do_undo (void)
545 {
546 return ::octave_rl_do_undo ();
547 }
548
533 void 549 void
534 gnu_readline::do_clear_undo_list () 550 gnu_readline::do_clear_undo_list ()
535 { 551 {
536 ::octave_rl_clear_undo_list (); 552 ::octave_rl_clear_undo_list ();
537 } 553 }
959 { 975 {
960 return (instance_ok ()) 976 return (instance_ok ())
961 ? instance->do_get_output_stream () : 0; 977 ? instance->do_get_output_stream () : 0;
962 } 978 }
963 979
980 void
981 command_editor::redisplay (void)
982 {
983 if (instance_ok ())
984 instance->do_redisplay ();
985 }
986
964 int 987 int
965 command_editor::terminal_rows (void) 988 command_editor::terminal_rows (void)
966 { 989 {
967 return (instance_ok ()) 990 return (instance_ok ())
968 ? instance->do_terminal_rows () : -1; 991 ? instance->do_terminal_rows () : -1;
1173 void 1196 void
1174 command_editor::accept_line (void) 1197 command_editor::accept_line (void)
1175 { 1198 {
1176 if (instance_ok ()) 1199 if (instance_ok ())
1177 instance->do_accept_line (); 1200 instance->do_accept_line ();
1201 }
1202
1203 bool
1204 command_editor::undo (void)
1205 {
1206 return instance_ok () ? instance->do_undo () : false;
1178 } 1207 }
1179 1208
1180 void 1209 void
1181 command_editor::clear_undo_list (void) 1210 command_editor::clear_undo_list (void)
1182 { 1211 {