2018-01-25 23:13:36 +00:00
|
|
|
// This is free and unencumbered software released into the public domain.
|
|
|
|
// Happy coding!!! - GtkSharp Team
|
|
|
|
|
2018-01-20 23:40:47 +00:00
|
|
|
using System;
|
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
namespace Samples
|
|
|
|
{
|
|
|
|
static class ApplicationOutput
|
|
|
|
{
|
2018-01-21 18:54:58 +00:00
|
|
|
private static readonly ScrolledWindow _scrolledWindow;
|
|
|
|
private static readonly TextView _textView;
|
2018-01-20 23:40:47 +00:00
|
|
|
|
|
|
|
static ApplicationOutput()
|
|
|
|
{
|
|
|
|
var vbox = new VBox();
|
|
|
|
|
2018-01-21 18:54:58 +00:00
|
|
|
var labelTitle = new Label
|
|
|
|
{
|
|
|
|
Text = "Application Output:",
|
|
|
|
Margin = 4,
|
|
|
|
Xalign = 0f
|
|
|
|
};
|
2018-01-20 23:40:47 +00:00
|
|
|
vbox.PackStart(labelTitle, false, true, 0);
|
|
|
|
|
|
|
|
_scrolledWindow = new ScrolledWindow();
|
|
|
|
_textView = new TextView();
|
|
|
|
_scrolledWindow.Child = _textView;
|
|
|
|
vbox.PackStart(_scrolledWindow, true, true, 0);
|
|
|
|
|
|
|
|
Widget = vbox;
|
2018-01-21 18:54:58 +00:00
|
|
|
|
|
|
|
_textView.SizeAllocated += TextView_SizeAllocated;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Widget Widget { get; set; }
|
|
|
|
|
|
|
|
private static void TextView_SizeAllocated(object o, SizeAllocatedArgs args)
|
|
|
|
{
|
|
|
|
_textView.ScrollToIter(_textView.Buffer.EndIter, 0, false, 0, 0);
|
2018-01-20 23:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void WriteLine(object o, string e)
|
|
|
|
{
|
2018-01-21 18:54:58 +00:00
|
|
|
WriteLine("[" + Environment.TickCount + "] " + o.GetType() + ": " + e);
|
2018-01-20 23:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void WriteLine(string line)
|
|
|
|
{
|
|
|
|
var enditer = _textView.Buffer.EndIter;
|
2018-01-21 18:54:58 +00:00
|
|
|
if (_textView.Buffer.Text.Length > 0)
|
|
|
|
line = Environment.NewLine + line;
|
|
|
|
_textView.Buffer.Insert(ref enditer, line);
|
|
|
|
|
2018-01-20 23:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|