diff --git a/UICatalog/Scenarios/Notepad.cs b/UICatalog/Scenarios/Notepad.cs index b3cacf96c..7f5169080 100644 --- a/UICatalog/Scenarios/Notepad.cs +++ b/UICatalog/Scenarios/Notepad.cs @@ -1,30 +1,29 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; using Terminal.Gui; -using static UICatalog.Scenario; namespace UICatalog.Scenarios { - [ScenarioMetadata (Name: "Notepad", Description: "Multi tab text editor uising the TabView control.")] + [ScenarioMetadata (Name: "Notepad", Description: "Multi-tab text editor uising the TabView control.")] [ScenarioCategory ("Controls"), ScenarioCategory ("TabView")] public class Notepad : Scenario { - TabView tabView; - Label lblStatus; private int numbeOfNewTabs = 1; + // Don't create a Window, just return the top-level view + public override void Init (Toplevel top, ColorScheme colorScheme) + { + Application.Init (); + + Top = top; + if (Top == null) { + Top = Application.Top; + } + Top.ColorScheme = Colors.Base; + } + public override void Setup () { - Win.Title = this.GetName (); - Win.Y = 1; // menu - Win.Height = Dim.Fill (1); // status bar - Top.LayoutSubviews (); - var menu = new MenuBar (new MenuBarItem [] { new MenuBarItem ("_File", new MenuItem [] { new MenuItem ("_New", "", () => New()), @@ -39,16 +38,17 @@ namespace UICatalog.Scenarios { tabView = new TabView () { X = 0, - Y = 0, + Y = 1, Width = Dim.Fill (), Height = Dim.Fill (1), }; - tabView.Style.ShowBorder = false; + tabView.Style.ShowBorder = true; tabView.ApplyStyleChanges (); - Win.Add (tabView); + Top.Add (tabView); + var lenStatusItem = new StatusItem (Key.CharMask, "Len: ", null); var statusBar = new StatusBar (new StatusItem [] { new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Quit()), @@ -58,26 +58,16 @@ namespace UICatalog.Scenarios { new StatusItem(Key.CtrlMask | Key.S, "~^S~ Save", () => Save()), new StatusItem(Key.CtrlMask | Key.W, "~^W~ Close", () => Close()), + lenStatusItem, }); - Win.Add (lblStatus = new Label ("Len:") { - Y = Pos.Bottom (tabView), - Width = Dim.Fill (), - TextAlignment = TextAlignment.Right - }); - - tabView.SelectedTabChanged += (s, e) => UpdateStatus (e.NewTab); + tabView.SelectedTabChanged += (s, e) => lenStatusItem.Title = $"Len:{(e.NewTab?.View?.Text?.Length ?? 0)}"; Top.Add (statusBar); New (); } - private void UpdateStatus (TabView.Tab newTab) - { - lblStatus.Text = $"Len:{(newTab?.View?.Text?.Length ?? 0)}"; - } - private void New () { Open ("", null, $"new {numbeOfNewTabs++}"); @@ -109,12 +99,10 @@ namespace UICatalog.Scenarios { // close and dispose the tab tabView.RemoveTab (tab); tab.View.Dispose (); - } private void Open () { - var open = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = true }; Application.Run (open); @@ -130,7 +118,6 @@ namespace UICatalog.Scenarios { Open (File.ReadAllText (path), new FileInfo (path), Path.GetFileName (path)); } } - } /// @@ -140,7 +127,6 @@ namespace UICatalog.Scenarios { /// File that was read or null if a new blank document private void Open (string initialText, FileInfo fileInfo, string tabName) { - var textView = new TextView () { X = 0, Y = 0, @@ -188,7 +174,7 @@ namespace UICatalog.Scenarios { } tab.Save (); - + tabView.SetNeedsDisplay (); } public bool SaveAs () @@ -207,14 +193,13 @@ namespace UICatalog.Scenarios { } tab.File = new FileInfo (fd.FilePath.ToString ()); + tab.Text = fd.FileName.ToString (); tab.Save (); return true; } private class OpenedFile : TabView.Tab { - - public FileInfo File { get; set; } ///