Mercurial > hg > octave-lyh
comparison libgui/src/history-dockwidget.cc @ 15340: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 | 117966ca93be |
children | 501a9cc2c68f |
comparison
equal
deleted
inserted
replaced
15339:b49d707fe9d7 | 15340:9d0cdd49054b |
---|---|
26 | 26 |
27 #include <QVBoxLayout> | 27 #include <QVBoxLayout> |
28 | 28 |
29 #include "cmd-hist.h" | 29 #include "cmd-hist.h" |
30 | 30 |
31 #include "error.h" | |
32 | |
31 #include "history-dockwidget.h" | 33 #include "history-dockwidget.h" |
32 | 34 |
33 history_dock_widget::history_dock_widget (QWidget * parent) | 35 history_dock_widget::history_dock_widget (QWidget * parent) |
34 : QDockWidget (parent), octave_event_observer () | 36 : QDockWidget (parent), octave_event_observer () |
35 { | 37 { |
38 } | 40 } |
39 | 41 |
40 void | 42 void |
41 history_dock_widget::event_accepted (octave_event *e) | 43 history_dock_widget::event_accepted (octave_event *e) |
42 { | 44 { |
45 static bool scroll_window = false; | |
46 | |
43 if (dynamic_cast <octave_update_history_event*> (e)) | 47 if (dynamic_cast <octave_update_history_event*> (e)) |
44 { | 48 { |
45 // Determine the client's (our) history length and the one of the server. | 49 // Determine the client's (our) history length and the one of the server. |
46 int clientHistoryLength = _history_model->rowCount (); | 50 int clientHistoryLength = _history_model->rowCount (); |
47 int serverHistoryLength = command_history::length (); | 51 int serverHistoryLength = command_history::length (); |
59 std::string entry = command_history::get_entry (i); | 63 std::string entry = command_history::get_entry (i); |
60 | 64 |
61 _history_model->setData (_history_model->index (i), | 65 _history_model->setData (_history_model->index (i), |
62 QString::fromStdString (entry)); | 66 QString::fromStdString (entry)); |
63 } | 67 } |
68 | |
69 // FIXME -- does this behavior make sense? Calling | |
70 // _history_list_view->scrollToBottom () here doesn't seem to | |
71 // have any effect. Instead, we need to request that action | |
72 // and wait until the next event occurs in which no items | |
73 // are added to the history list. | |
74 | |
75 scroll_window = true; | |
64 } | 76 } |
77 else if (scroll_window) | |
78 { | |
79 scroll_window = false; | |
65 | 80 |
66 // FIXME -- how to make the widget scroll to the bottom when an | 81 _history_list_view->scrollToBottom (); |
67 // item is added, but leave it alone if the user has moved it | 82 } |
68 // somewhere other than the bottom of the list? The following | |
69 // doesn't seem to work. It forces to the widget to always scroll | |
70 // to the bottom, even if no items are added. | |
71 // | |
72 // _history_list_view->scrollToBottom (); | |
73 } | 83 } |
74 | 84 |
75 // Post a new update event in a given time. This prevents flooding the | 85 // Post a new update event in a given time. This prevents flooding the |
76 // event queue. | 86 // event queue. |
77 _update_history_model_timer.start (); | 87 _update_history_model_timer.start (); |