# HG changeset patch # User John W. Eaton # Date 1347635667 14400 # Node ID 24b5348d38e7096b233e65f6bb470924304b402a # Parent f9ee3befcd6be0577e9df2bbbc1c49d95481302c merge event_accepted and event_reject into a single function * history-dockwidget.cc, history-dockwidget.h (history_dock_widget::handle_event): New function from merging history_dock_widget::event_accepted and history_dock_widget::event_reject into single fucntion with argument. * file-editor-tab.cc, file-editor-tab.h (file_editor_tab::handle_event): Likewise. * main-window.cc, main-window.h (main_window::handle_event): Likewise. * octave-event-observer.h (octave_event_observer::handle_event): New pure virtual function. (octave_event_observer::event_accepted, octave_event_observer::event_reject): Delete. * octave_link.cc, octave-link.h (octave_link::handle_event): Likewise. * workspace-model.cc, workspace-model.h (workspace_model::handle_event): Likewise. * octave-link.cc (octave_link::do_process_events): Call octave_event::handle_event with the return value from octave_event::perform instead of calling octave_event::accept and octave_event::reject. * octave-event.h (octave_event:handle_event): New function. (octave_event::accept, octave_event::reject): Delete. diff --git a/libgui/src/history-dockwidget.cc b/libgui/src/history-dockwidget.cc --- a/libgui/src/history-dockwidget.cc +++ b/libgui/src/history-dockwidget.cc @@ -40,56 +40,58 @@ } void -history_dock_widget::event_accepted (octave_event *e) +history_dock_widget::handle_event (octave_event *e, bool accept) { static bool scroll_window = false; - if (dynamic_cast (e)) + if (accept) { - // Determine the client's (our) history length and the one of the server. - int clientHistoryLength = _history_model->rowCount (); - int serverHistoryLength = command_history::length (); - - // If were behind the server, iterate through all new entries and add - // them to our history. - if (clientHistoryLength < serverHistoryLength) + if (dynamic_cast (e)) { - int elts_to_add = serverHistoryLength - clientHistoryLength; + // Determine the client's (our) history length and the one of the server. + int clientHistoryLength = _history_model->rowCount (); + int serverHistoryLength = command_history::length (); - _history_model->insertRows (clientHistoryLength, elts_to_add); - - for (int i = clientHistoryLength; i < serverHistoryLength; i++) + // If were behind the server, iterate through all new entries and add + // them to our history. + if (clientHistoryLength < serverHistoryLength) { - std::string entry = command_history::get_entry (i); + int elts_to_add = serverHistoryLength - clientHistoryLength; + + _history_model->insertRows (clientHistoryLength, elts_to_add); - _history_model->setData (_history_model->index (i), - QString::fromStdString (entry)); - } + for (int i = clientHistoryLength; i < serverHistoryLength; i++) + { + std::string entry = command_history::get_entry (i); + + _history_model->setData (_history_model->index (i), + QString::fromStdString (entry)); + } - // FIXME -- does this behavior make sense? Calling - // _history_list_view->scrollToBottom () here doesn't seem to - // have any effect. Instead, we need to request that action - // and wait until the next event occurs in which no items - // are added to the history list. + // FIXME -- does this behavior make sense? Calling + // _history_list_view->scrollToBottom () here doesn't seem to + // have any effect. Instead, we need to request that action + // and wait until the next event occurs in which no items + // are added to the history list. - scroll_window = true; - } - else if (scroll_window) - { - scroll_window = false; + scroll_window = true; + } + else if (scroll_window) + { + scroll_window = false; - _history_list_view->scrollToBottom (); + _history_list_view->scrollToBottom (); + } } - } - // Post a new update event in a given time. This prevents flooding the - // event queue. - _update_history_model_timer.start (); -} - -void -history_dock_widget::event_reject (octave_event *e) -{ + // Post a new update event in a given time. This prevents flooding the + // event queue. + _update_history_model_timer.start (); + } + else + { + // octave_event::perform failed to handle event. + } } void diff --git a/libgui/src/history-dockwidget.h b/libgui/src/history-dockwidget.h --- a/libgui/src/history-dockwidget.h +++ b/libgui/src/history-dockwidget.h @@ -39,8 +39,7 @@ public: history_dock_widget (QWidget *parent = 0); - void event_accepted (octave_event *e); - void event_reject (octave_event *e); + void handle_event (octave_event *e, bool accept); public slots: void handle_visibility_changed (bool visible); diff --git a/libgui/src/m-editor/file-editor-tab.cc b/libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -116,41 +116,42 @@ } void -file_editor_tab::event_accepted (octave_event *e) +file_editor_tab::handle_event (octave_event *e, bool accept) { - if (dynamic_cast (e)) - { - // File was run successfully. - } - - if (octave_add_breakpoint_event *abe - = dynamic_cast (e)) - { - // TODO: Check file. - _edit_area->markerAdd (abe->get_line (), breakpoint); - } - - if (octave_remove_breakpoint_event *rbe - = dynamic_cast (e)) + if (accept) { - // TODO: Check file. - _edit_area->markerDelete (rbe->get_line (), breakpoint); + if (dynamic_cast (e)) + { + // File was run successfully. + } + + if (octave_add_breakpoint_event *abe + = dynamic_cast (e)) + { + // TODO: Check file. + _edit_area->markerAdd (abe->get_line (), breakpoint); + } + + if (octave_remove_breakpoint_event *rbe + = dynamic_cast (e)) + { + // TODO: Check file. + _edit_area->markerDelete (rbe->get_line (), breakpoint); + } + + if (octave_remove_all_breakpoints_event *rabe + = dynamic_cast (e)) + { + Q_UNUSED (rabe); + _edit_area->markerDeleteAll (breakpoint); + } } - - if (octave_remove_all_breakpoints_event *rabe - = dynamic_cast (e)) + else { - Q_UNUSED (rabe); - _edit_area->markerDeleteAll (breakpoint); - } -} - -void -file_editor_tab::event_reject (octave_event *e) -{ - if (dynamic_cast (e)) - { - // Running file failed. + if (dynamic_cast (e)) + { + // Running file failed. + } } } diff --git a/libgui/src/m-editor/file-editor-tab.h b/libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -37,8 +37,7 @@ file_editor_tab (file_editor *fileEditor); bool copy_available (); - void event_accepted (octave_event *e); - void event_reject (octave_event *e); + void handle_event (octave_event *e, bool accept); public slots: void update_window_title(bool modified); diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -54,18 +54,20 @@ } void -main_window::event_accepted (octave_event *e) +main_window::handle_event (octave_event *e, bool accept) { - if (dynamic_cast (e)) + if (accept) { - // After clearing the history, we need to reset the model. - _history_dock_widget->reset_model (); + if (dynamic_cast (e)) + { + // After clearing the history, we need to reset the model. + _history_dock_widget->reset_model (); + } } -} - -void -main_window::event_reject (octave_event *e) -{ + else + { + // octave_event::perform failed to process event. + } } void diff --git a/libgui/src/main-window.h b/libgui/src/main-window.h --- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -65,8 +65,7 @@ main_window (QWidget * parent = 0); ~main_window (); - void event_accepted (octave_event *e); - void event_reject (octave_event *e); + void handle_event (octave_event *e, bool accept); QTerminal *get_terminal_view () { return _terminal; } history_dock_widget *get_history_dock_widget () diff --git a/libgui/src/octave-adapter/octave-event-observer.h b/libgui/src/octave-adapter/octave-event-observer.h --- a/libgui/src/octave-adapter/octave-event-observer.h +++ b/libgui/src/octave-adapter/octave-event-observer.h @@ -36,16 +36,11 @@ virtual ~octave_event_observer () { } /** - * This will be called when an event has been accepted. Operations - * in this routine will be processed in the octave thread. + * This will be called after the octave_event::perform function + * has processed an event. ACCEPT will be true if the event was + * successfully handled and false otherwise. */ - virtual void event_accepted (octave_event *e) = 0; - - /** - * This will be called when an event has been rejected. Operations - * in this routine will be processed in the octave thread. - */ - virtual void event_reject (octave_event *e) = 0; + virtual void handle_event (octave_event *e, bool accept) = 0; }; #include "octave-event.h" diff --git a/libgui/src/octave-adapter/octave-event.h b/libgui/src/octave-adapter/octave-event.h --- a/libgui/src/octave-adapter/octave-event.h +++ b/libgui/src/octave-adapter/octave-event.h @@ -59,18 +59,14 @@ virtual bool perform () = 0; /** - * Accepts this event. This allows the event observer to react properly - * onto the event. + * Pass the event on to the class that posted the event. ACCEPT + * will be true if the perform function was successful, and false + * otherwise. */ - void accept () - { _octave_event_observer.event_accepted (this); } - - /** - * Rejects this event. This allows the event observer to react properly - * onto the event. - */ - void reject () - { _octave_event_observer.event_reject (this); } + void handle_event (bool accept) + { + _octave_event_observer.handle_event (this, accept); + } protected: void call_octave_function (const std::string& name); diff --git a/libgui/src/octave-adapter/octave-link.cc b/libgui/src/octave-adapter/octave-link.cc --- a/libgui/src/octave-adapter/octave-link.cc +++ b/libgui/src/octave-adapter/octave-link.cc @@ -116,10 +116,9 @@ event_queue.pop (); - if (e->perform ()) - e->accept (); - else - e->reject (); + bool status = e->perform (); + + e->handle_event (status); delete e; } @@ -159,12 +158,7 @@ } void -octave_link::event_accepted (octave_event *e) -{ -} - -void -octave_link::event_reject (octave_event *e) +octave_link::handle_event (octave_event *, bool) { } diff --git a/libgui/src/octave-adapter/octave-link.h b/libgui/src/octave-adapter/octave-link.h --- a/libgui/src/octave-adapter/octave-link.h +++ b/libgui/src/octave-adapter/octave-link.h @@ -150,8 +150,7 @@ std::string do_last_working_directory (void); - void event_accepted (octave_event *e); - void event_reject (octave_event *e); + void handle_event (octave_event *e, bool accept); }; #endif // OCTAVELINK_H diff --git a/libgui/src/workspace-model.cc b/libgui/src/workspace-model.cc --- a/libgui/src/workspace-model.cc +++ b/libgui/src/workspace-model.cc @@ -67,62 +67,64 @@ } void -workspace_model::event_accepted (octave_event *e) +workspace_model::handle_event (octave_event *e, bool accept) { - if (dynamic_cast (e)) + if (accept) { - std::list < symbol_table::symbol_record > symbolTable = symbol_table::all_variables (); + if (dynamic_cast (e)) + { + std::list < symbol_table::symbol_record > symbolTable = symbol_table::all_variables (); - _symbol_information.clear (); - for (std::list < symbol_table::symbol_record > ::iterator iterator = symbolTable.begin (); - iterator != symbolTable.end (); iterator++) - _symbol_information.push_back (symbol_information (*iterator)); + _symbol_information.clear (); + for (std::list < symbol_table::symbol_record > ::iterator iterator = symbolTable.begin (); + iterator != symbolTable.end (); iterator++) + _symbol_information.push_back (symbol_information (*iterator)); - beginResetModel(); - top_level_item (0)->delete_child_items (); - top_level_item (1)->delete_child_items (); - top_level_item (2)->delete_child_items (); + beginResetModel(); + top_level_item (0)->delete_child_items (); + top_level_item (1)->delete_child_items (); + top_level_item (2)->delete_child_items (); - foreach (const symbol_information& s, _symbol_information) - { - tree_item *child = new tree_item (); + foreach (const symbol_information& s, _symbol_information) + { + tree_item *child = new tree_item (); - child->set_data (0, s.symbol ()); - child->set_data (1, s.class_name ()); - child->set_data (2, s.dimension ()); - child->set_data (3, s.value ()); + child->set_data (0, s.symbol ()); + child->set_data (1, s.class_name ()); + child->set_data (2, s.dimension ()); + child->set_data (3, s.value ()); - switch (s.scope ()) - { - case symbol_information::local: - top_level_item (0)->add_child (child); - break; + switch (s.scope ()) + { + case symbol_information::local: + top_level_item (0)->add_child (child); + break; - case symbol_information::global: - top_level_item (1)->add_child (child); - break; + case symbol_information::global: + top_level_item (1)->add_child (child); + break; + + case symbol_information::persistent: + top_level_item (2)->add_child (child); + break; - case symbol_information::persistent: - top_level_item (2)->add_child (child); - break; + default: + break; + } + } - default: - break; - } + endResetModel(); + emit model_changed(); } - endResetModel(); - emit model_changed(); + // Post a new event in a given time. + // This prevents flooding the event queue when no events are being processed. + _update_workspace_model_timer.start (); } - - // Post a new event in a given time. - // This prevents flooding the event queue when no events are being processed. - _update_workspace_model_timer.start (); -} - -void -workspace_model::event_reject (octave_event *e) -{ + else + { + // octave_event::perform failed to process event. + } } QModelIndex diff --git a/libgui/src/workspace-model.h b/libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h +++ b/libgui/src/workspace-model.h @@ -120,8 +120,7 @@ workspace_model (QObject *parent = 0); ~workspace_model (); - void event_accepted (octave_event *e); - void event_reject (octave_event *e); + void handle_event (octave_event *e, bool accept); QVariant data (const QModelIndex &index, int role) const; Qt::ItemFlags flags (const QModelIndex &index) const;