changeset 15341:9d0cdd49054b

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.
author John W. Eaton <jwe@octave.org>
date Mon, 10 Sep 2012 14:37:17 -0400
parents b49d707fe9d7
children 95504932d422
files libgui/src/history-dockwidget.cc
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/history-dockwidget.cc
+++ b/libgui/src/history-dockwidget.cc
@@ -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 <octave_update_history_event*> (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