# HG changeset patch # User Jacob Dawid # Date 1340891203 -7200 # Node ID 61c80e9326a834e8bc2117645e9451af1820f6ce # Parent 2de56de8953ade0cb4de751b29c9e0064a76a3b3 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. diff --git a/gui/src/history-dockwidget.cc b/gui/src/history-dockwidget.cc --- 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); diff --git a/gui/src/history-dockwidget.h b/gui/src/history-dockwidget.h --- 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); diff --git a/gui/src/main-window.cc b/gui/src/main-window.cc --- 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 (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); diff --git a/gui/src/main-window.h b/gui/src/main-window.h --- 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 (); diff --git a/gui/src/octave-adapter/octave-event.h b/gui/src/octave-adapter/octave-event.h --- 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 @@ -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: