[Samples] Setup ApplicationOutput for catching events

This commit is contained in:
cra0zy 2018-01-21 00:40:47 +01:00
parent 31e120a9de
commit 69716243b9
4 changed files with 57 additions and 7 deletions

View File

@ -0,0 +1,43 @@
using System;
using System.Diagnostics;
using Gtk;
namespace Samples
{
static class ApplicationOutput
{
public static Widget Widget { get; set; }
private static ScrolledWindow _scrolledWindow;
private static TextView _textView;
static ApplicationOutput()
{
var vbox = new VBox();
var labelTitle = new Label();
labelTitle.Text = "Application Output:";
labelTitle.Margin = 4;
labelTitle.Xalign = 0f;
vbox.PackStart(labelTitle, false, true, 0);
_scrolledWindow = new ScrolledWindow();
_textView = new TextView();
_scrolledWindow.Child = _textView;
vbox.PackStart(_scrolledWindow, true, true, 0);
Widget = vbox;
}
public static void WriteLine(object o, string e)
{
WriteLine("[" + Environment.TickCount + "] " + o.GetType().ToString() + ": " + e);
}
public static void WriteLine(string line)
{
var enditer = _textView.Buffer.EndIter;
_textView.Buffer.Insert(ref enditer, line + Environment.NewLine);
_textView.ScrollToIter(enditer, 0, false, 0, 0);
}
}
}

View File

@ -7,7 +7,6 @@ namespace Samples
class MainWindow : Window class MainWindow : Window
{ {
private HeaderBar _headerBar; private HeaderBar _headerBar;
private HPaned _panned;
private TreeView _treeView; private TreeView _treeView;
private Box _boxContent; private Box _boxContent;
private TreeStore _store; private TreeStore _store;
@ -30,17 +29,24 @@ namespace Samples
Titlebar = _headerBar; Titlebar = _headerBar;
_panned = new HPaned(); var hpanned = new HPaned();
_panned.Position = 200; hpanned.Position = 200;
_treeView = new TreeView(); _treeView = new TreeView();
_treeView.HeadersVisible = false; _treeView.HeadersVisible = false;
_panned.Pack1(_treeView, false, true); hpanned.Pack1(_treeView, false, true);
var vpanned = new VPaned();
vpanned.Position = 400;
_boxContent = new Box(Orientation.Vertical, 0); _boxContent = new Box(Orientation.Vertical, 0);
_panned.Pack2(_boxContent, true, true); vpanned.Pack1(_boxContent, true, true);
Child = _panned; vpanned.Pack2(ApplicationOutput.Widget, false, true);
hpanned.Pack2(vpanned, true, true);
Child = hpanned;
// Fill up data // Fill up data
FillUpTreeView(); FillUpTreeView();

View File

@ -6,7 +6,6 @@ namespace Samples
class Program class Program
{ {
public static Application App; public static Application App;
public static Window Win; public static Window Win;
[STAThread] [STAThread]

View File

@ -10,6 +10,8 @@ namespace Samples
{ {
var btn = new Button("Click Me"); var btn = new Button("Click Me");
PackStart(btn, true, true, 0); PackStart(btn, true, true, 0);
btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked");
} }
} }
} }