Mercurial > hg > octave-lyh
changeset 14814:61c80e9326a8 gui
Clearing the command history works.
* history-dockwidget: Added method to clear the model.
* main-window: Added new slot to clear the history.
* octave-event.h: Created new event to delete the command history.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 28 Jun 2012 15:46:43 +0200 |
parents | 2de56de8953a |
children | e8eca6031695 |
files | gui/src/history-dockwidget.cc gui/src/history-dockwidget.h gui/src/main-window.cc gui/src/main-window.h gui/src/octave-adapter/octave-event.h |
diffstat | 5 files changed, 42 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/history-dockwidget.cc +++ b/gui/src/history-dockwidget.cc @@ -131,6 +131,12 @@ } void +history_dock_widget::reset_model () +{ + _history_model->setStringList (QStringList ()); +} + +void history_dock_widget::closeEvent (QCloseEvent *event) { emit active_changed (false);
--- a/gui/src/history-dockwidget.h +++ b/gui/src/history-dockwidget.h @@ -40,6 +40,7 @@ public slots: void handle_visibility_changed (bool visible); void request_history_model_update (); + void reset_model (); signals: void information (QString message);
--- a/gui/src/main-window.cc +++ b/gui/src/main-window.cc @@ -45,6 +45,11 @@ void main_window::event_accepted (octave_event *e) { + if (dynamic_cast<octave_clear_history_event*> (e)) + { + // After clearing the history, we need to reset the model. + _history_dock_widget->reset_model (); + } delete e; } @@ -105,6 +110,13 @@ } void +main_window::handle_clear_history_request() +{ + octave_link::instance () + ->post_event (new octave_clear_history_event (*this)); +} + +void main_window::handle_command_double_clicked (QString command) { _terminal->sendText(command); @@ -555,7 +567,6 @@ clear_command_window_action->setEnabled (false); // TODO: Make this work. QAction *clear_command_history = edit_menu->addAction(tr ("Clear Command History")); - clear_command_history->setEnabled (false); // TODO: Make this work. QAction * clear_workspace_action = edit_menu->addAction (tr ("Clear Workspace")); @@ -741,6 +752,9 @@ connect (_debug_quit, SIGNAL (triggered ()), this, SLOT (debug_quit ())); + connect (clear_command_history, SIGNAL (triggered ()), + this, SLOT (handle_clear_history_request ())); + setWindowTitle ("Octave"); setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks); addDockWidget (Qt::LeftDockWidgetArea, _workspace_view);
--- a/gui/src/main-window.h +++ b/gui/src/main-window.h @@ -76,6 +76,7 @@ void handle_save_workspace_request (); void handle_load_workspace_request (); void handle_clear_workspace_request (); + void handle_clear_history_request (); void handle_command_double_clicked (QString command); void new_file (); void open_file ();
--- a/gui/src/octave-adapter/octave-event.h +++ b/gui/src/octave-adapter/octave-event.h @@ -27,6 +27,7 @@ #include "toplev.h" #include "parse.h" #include "debug.h" +#include "cmd-hist.h" #include <readline/readline.h> @@ -231,6 +232,24 @@ std::string _file; }; +class octave_clear_history_event : public octave_event +{ + public: + /** Creates a new octave_clear_history_event. */ + octave_clear_history_event (octave_event_observer& o) + : octave_event (o) + { } + + bool perform () + { + int i; + while ((i = command_history::length ()) > 0) { + command_history::remove (i - 1); + } + return true; + } +}; + class octave_debug_step_into_event : public octave_event { public: