using Gtk;

public class ScrolledText : Window {
	private TextView text_view;
	private ScrolledWindow scroll;

	public ScrolledText () {
		this.title = "Просмотр текстового файла";
		this.window_position = WindowPosition.CENTER;
		this.set_default_size( 500, 400 );

		var toolbar = new Toolbar();

		var open_button = new ToolButton.from_stock( Stock.OPEN );
		toolbar.add( open_button );
		open_button.clicked.connect( on_open_clicked );

		this.text_view = new TextView();
		for (var i = 0; i < 100; ++i) text_view.buffer.text += @"line № $i\n";
		this.text_view.cursor_visible = false;

		scroll = new ScrolledWindow( null, null );
		scroll.set_policy( PolicyType.AUTOMATIC, PolicyType.AUTOMATIC );
		scroll.add( this.text_view );

		var vbox = new VBox( false, 0 );
		vbox.pack_start( toolbar, false, true, 0 );
		vbox.pack_start( scroll, true, true, 0 );
		this.add( vbox );
	}

	private void on_open_clicked() {
		var vadjustment = scroll.get_vadjustment ();
		vadjustment.value = vadjustment.upper;
		scroll.set_vadjustment (vadjustment);
	}

	public static int main (string[] args) {
		Gtk.init( ref args );
		var window = new ScrolledText();
		window.destroy.connect( Gtk.main_quit );
		window.show_all();
		Gtk.main();
		return 0;
	}
}
