Commit a16aaca7 authored by Michael Terry's avatar Michael Terry

Fix autoscrolling in progress window; initial patch by Erik Entrich

parent 802acc75
...@@ -89,6 +89,9 @@ public abstract class AssistantOperation : Assistant ...@@ -89,6 +89,9 @@ public abstract class AssistantOperation : Assistant
int saved_x; int saved_x;
int saved_y; int saved_y;
const int LOGS_LINES_TO_KEEP = 10000;
bool adjustment_at_end = true;
construct construct
{ {
add_custom_config_pages(); add_custom_config_pages();
...@@ -168,7 +171,6 @@ public abstract class AssistantOperation : Assistant ...@@ -168,7 +171,6 @@ public abstract class AssistantOperation : Assistant
string log_line = prefix + " " + file.get_parse_name(); string log_line = prefix + " " + file.get_parse_name();
bool adjustment_at_end = false;
Gtk.Adjustment adjust = progress_scroll.get_vadjustment(); Gtk.Adjustment adjust = progress_scroll.get_vadjustment();
if (adjust.value >= adjust.upper - adjust.page_size || if (adjust.value >= adjust.upper - adjust.page_size ||
adjust.page_size == 0 || // means never been set, means not realized adjust.page_size == 0 || // means never been set, means not realized
...@@ -178,19 +180,18 @@ public abstract class AssistantOperation : Assistant ...@@ -178,19 +180,18 @@ public abstract class AssistantOperation : Assistant
var buffer = progress_text.buffer; var buffer = progress_text.buffer;
if (buffer.get_char_count() > 0) if (buffer.get_char_count() > 0)
log_line = "\n" + log_line; log_line = "\n" + log_line;
if (buffer.get_line_count() >= 100 && adjustment_at_end) {
// If we're watching text scroll by, save memory by only keeping last 100 lines
Gtk.TextIter start, line100;
buffer.get_start_iter(out start);
buffer.get_iter_at_line(out line100, buffer.get_line_count() - 100);
buffer.delete(ref start, ref line100);
}
Gtk.TextIter iter; Gtk.TextIter iter;
buffer.get_end_iter(out iter); buffer.get_end_iter(out iter);
buffer.insert_text(ref iter, log_line, (int)log_line.length); buffer.insert_text(ref iter, log_line, (int)log_line.length);
if (adjustment_at_end)
adjust.value = adjust.upper; if (buffer.get_line_count() >= LOGS_LINES_TO_KEEP && adjustment_at_end) {
// If we're watching text scroll by, don't keep everything in memory
Gtk.TextIter start, cutoff;
buffer.get_start_iter(out start);
buffer.get_iter_at_line(out cutoff, buffer.get_line_count() - LOGS_LINES_TO_KEEP);
buffer.delete(ref start, ref cutoff);
}
} }
protected void set_secondary_label(string text) protected void set_secondary_label(string text)
...@@ -203,6 +204,25 @@ public abstract class AssistantOperation : Assistant ...@@ -203,6 +204,25 @@ public abstract class AssistantOperation : Assistant
secondary_label.hide(); secondary_label.hide();
} }
void update_autoscroll()
{
if (adjustment_at_end)
{
Gtk.Adjustment adjust = progress_scroll.get_vadjustment();
adjust.value = adjust.upper - adjust.page_size;
}
}
bool stop_autoscroll()
{
Gtk.Adjustment adjust = progress_scroll.get_vadjustment();
if (adjust.value < adjust.upper - adjust.page_size)
adjustment_at_end = false;
return false;
}
protected virtual Gtk.Widget make_progress_page() protected virtual Gtk.Widget make_progress_page()
{ {
var page = new Gtk.Grid(); var page = new Gtk.Grid();
...@@ -238,7 +258,11 @@ public abstract class AssistantOperation : Assistant ...@@ -238,7 +258,11 @@ public abstract class AssistantOperation : Assistant
progress_text = new Gtk.TextView(); progress_text = new Gtk.TextView();
progress_text.editable = false; progress_text.editable = false;
progress_text.size_allocate.connect(update_autoscroll);
progress_scroll = new Gtk.ScrolledWindow(null, null); progress_scroll = new Gtk.ScrolledWindow(null, null);
progress_scroll.scroll_event.connect(stop_autoscroll);
((Gtk.Range)progress_scroll.get_vscrollbar()).change_value.connect(stop_autoscroll);
progress_scroll.expand = true;
progress_scroll.child = progress_text; progress_scroll.child = progress_text;
progress_scroll.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC; progress_scroll.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
progress_scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; progress_scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment