From 69716243b943843da9279cefe2c8ed6567b847df Mon Sep 17 00:00:00 2001 From: cra0zy Date: Sun, 21 Jan 2018 00:40:47 +0100 Subject: [PATCH] [Samples] Setup ApplicationOutput for catching events --- Source/Samples/ApplicationOutput.cs | 43 +++++++++++++++++++ Source/Samples/MainWindow.cs | 18 +++++--- Source/Samples/Program.cs | 1 - .../Sections/Widgets/ButtonCategory.cs | 2 + 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 Source/Samples/ApplicationOutput.cs diff --git a/Source/Samples/ApplicationOutput.cs b/Source/Samples/ApplicationOutput.cs new file mode 100644 index 000000000..78ed06efd --- /dev/null +++ b/Source/Samples/ApplicationOutput.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Source/Samples/MainWindow.cs b/Source/Samples/MainWindow.cs index 5ded3d31d..63f1e4d78 100644 --- a/Source/Samples/MainWindow.cs +++ b/Source/Samples/MainWindow.cs @@ -7,7 +7,6 @@ namespace Samples class MainWindow : Window { private HeaderBar _headerBar; - private HPaned _panned; private TreeView _treeView; private Box _boxContent; private TreeStore _store; @@ -30,17 +29,24 @@ namespace Samples Titlebar = _headerBar; - _panned = new HPaned(); - _panned.Position = 200; + var hpanned = new HPaned(); + hpanned.Position = 200; _treeView = new TreeView(); _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); - _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 FillUpTreeView(); diff --git a/Source/Samples/Program.cs b/Source/Samples/Program.cs index 64b2282d8..447cd1953 100644 --- a/Source/Samples/Program.cs +++ b/Source/Samples/Program.cs @@ -6,7 +6,6 @@ namespace Samples class Program { public static Application App; - public static Window Win; [STAThread] diff --git a/Source/Samples/Sections/Widgets/ButtonCategory.cs b/Source/Samples/Sections/Widgets/ButtonCategory.cs index 9c1b2014d..004279d2d 100644 --- a/Source/Samples/Sections/Widgets/ButtonCategory.cs +++ b/Source/Samples/Sections/Widgets/ButtonCategory.cs @@ -10,6 +10,8 @@ namespace Samples { var btn = new Button("Click Me"); PackStart(btn, true, true, 0); + + btn.Clicked += (sender, e) => ApplicationOutput.WriteLine(sender, "Clicked"); } } } \ No newline at end of file