# HG changeset patch # User John W. Eaton # Date 1347302237 14400 # Node ID 9d0cdd49054b527bea7cf1ef0ec31ddb3b6d723e # Parent b49d707fe9d7bf8f676e8f0469abe443491ff3d5 keep history in gui widget at bottom when new items are added * history-docwidget.cc (history_dock_widget::event_accepted): New static variable, scroll_window. Set to true when an item is added to the list. If no items are added, check to see whether window should be positioned at the bottom. diff -r b49d707fe9d7 -r 9d0cdd49054b libgui/src/history-dockwidget.cc --- a/libgui/src/history-dockwidget.cc Mon Sep 10 00:49:59 2012 -0600 +++ b/libgui/src/history-dockwidget.cc Mon Sep 10 14:37:17 2012 -0400 @@ -28,6 +28,8 @@ #include "cmd-hist.h" +#include "error.h" + #include "history-dockwidget.h" history_dock_widget::history_dock_widget (QWidget * parent) @@ -40,6 +42,8 @@ void history_dock_widget::event_accepted (octave_event *e) { + static bool scroll_window = false; + if (dynamic_cast (e)) { // Determine the client's (our) history length and the one of the server. @@ -61,15 +65,21 @@ _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 -- how to make the widget scroll to the bottom when an - // item is added, but leave it alone if the user has moved it - // somewhere other than the bottom of the list? The following - // doesn't seem to work. It forces to the widget to always scroll - // to the bottom, even if no items are added. - // - // _history_list_view->scrollToBottom (); + scroll_window = true; + } + else if (scroll_window) + { + scroll_window = false; + + _history_list_view->scrollToBottom (); + } } // Post a new update event in a given time. This prevents flooding the