diff --git a/README.md b/README.md index c515d76c..e849f6ff 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ You can add new code to `MyDialog.cs` but avoid making any changes to `MyDialog. For example in `MyDialog.cs` after `InitializeComponent()` add the following: ```csharp -button1.Accept += ()=>MessageBox.Query("Hello","Hello World","Ok"); +button1.Accepting += ()=>MessageBox.Query("Hello","Hello World","Ok"); ``` Now when run clicking the button will trigger a message box. @@ -171,7 +171,7 @@ italics are experimental and require passing the `-e` flag when starting applica - [x] Container views (e.g. TabView) - [ ] To OS clipboard (e.g. open one Designer.cs View and copy to another) - [x] Retain PosRelative mappings in pasted views (e.g. `A` LeftOf `B`) -- [x] Move views to subviews +- [x] Move views to SubViews - [x] With mouse - [ ] With keyboard - [ ] Read and present xmldoc comments when editing properties diff --git a/Showcase/Menu.Designer.cs b/Showcase/Menu.Designer.cs new file mode 100644 index 00000000..e66b9d4d --- /dev/null +++ b/Showcase/Menu.Designer.cs @@ -0,0 +1,303 @@ + +//------------------------------------------------------------------------------ + +// +// This code was generated by: +// TerminalGuiDesigner v2.0.0.0 +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ----------------------------------------------------------------------------- +namespace Showcase { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; + + + public partial class Menu : Terminal.Gui.Window { + + private Terminal.Gui.MenuBar menuBar; + + private Terminal.Gui.MenuBarItem fileF9Menu; + + private Terminal.Gui.MenuBarItem newMenu; + + private Terminal.Gui.MenuItem projectMenuItem; + + private Terminal.Gui.MenuItem repositoryMenuItem; + + private Terminal.Gui.MenuItem fileMenuItem; + + private Terminal.Gui.MenuItem projectFromExistingCodeMenuItem; + + private Terminal.Gui.MenuItem spellCheckerConfigurationForSelectedItemMenuItem; + + private Terminal.Gui.MenuBarItem openMenu; + + private Terminal.Gui.MenuItem projectSolutionMenuItem; + + private Terminal.Gui.MenuItem folderMenuItem; + + private Terminal.Gui.MenuItem workspaceMenuItem; + + private Terminal.Gui.MenuItem cMakeMenuItem; + + private Terminal.Gui.MenuItem fileMenuItem2; + + private Terminal.Gui.MenuItem cloneRepositoryMenuItem; + + private Terminal.Gui.MenuItem startWindowMenuItem; + + private Terminal.Gui.MenuItem closeMenuItem; + + private Terminal.Gui.MenuItem closeSolutionMenuItem; + + private Terminal.Gui.MenuItem startLiveShareSessionMenuItem; + + private Terminal.Gui.MenuItem joinLiveShareSessionMenuItem; + + private Terminal.Gui.MenuItem saveMenucsMenuItem; + + private Terminal.Gui.MenuItem saveMenucsAsMenuItem; + + private Terminal.Gui.MenuItem saveAllMenuItem; + + private Terminal.Gui.MenuItem pageSetupMenuItem; + + private Terminal.Gui.MenuItem printMenuItem; + + private Terminal.Gui.MenuItem accountSettingsMenuItem; + + private Terminal.Gui.MenuBarItem recentFilesMenu; + + private Terminal.Gui.MenuItem file1csMenuItem; + + private Terminal.Gui.MenuItem file2csMenuItem; + + private Terminal.Gui.MenuBarItem recentProjectsAndSolutionsMenu; + + private Terminal.Gui.MenuItem terminalGuislnMenuItem; + + private Terminal.Gui.MenuItem terminalGuiDesignerslnMenuItem; + + private Terminal.Gui.MenuBarItem moveMenucsIntoMenu; + + private Terminal.Gui.MenuItem solutionItemsMenuItem; + + private Terminal.Gui.MenuItem unitTestsMenuItem; + + private Terminal.Gui.MenuItem showcaseMenuItem; + + private Terminal.Gui.MenuItem exitMenuItem; + + private Terminal.Gui.MenuBarItem editMenu; + + private Terminal.Gui.MenuBarItem goToMenu; + + private Terminal.Gui.MenuItem goToLineMenuItem; + + private void InitializeComponent() { + this.menuBar = new Terminal.Gui.MenuBar(); + this.Width = Dim.Fill(0); + this.Height = Dim.Fill(0); + this.X = 0; + this.Y = 0; + this.Visible = true; + this.Arrangement = Terminal.Gui.ViewArrangement.Overlapped; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.Modal = false; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = ""; + this.menuBar.Width = Dim.Fill(0); + this.menuBar.Height = 1; + this.menuBar.X = 0; + this.menuBar.Y = 0; + this.menuBar.Visible = true; + this.menuBar.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.menuBar.CanFocus = false; + this.menuBar.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.menuBar.Data = "menuBar"; + this.menuBar.TextAlignment = Terminal.Gui.Alignment.Start; + this.fileF9Menu = new Terminal.Gui.MenuBarItem(); + this.fileF9Menu.Title = "_File (F9)"; + this.newMenu = new Terminal.Gui.MenuBarItem(); + this.newMenu.Title = "New"; + this.projectMenuItem = new Terminal.Gui.MenuItem(); + this.projectMenuItem.Title = "Project..."; + this.projectMenuItem.Data = "projectMenuItem"; + this.projectMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1342177358u)); + this.repositoryMenuItem = new Terminal.Gui.MenuItem(); + this.repositoryMenuItem.Title = "Repository..."; + this.repositoryMenuItem.Data = "repositoryMenuItem"; + this.fileMenuItem = new Terminal.Gui.MenuItem(); + this.fileMenuItem.Title = "File..."; + this.fileMenuItem.Data = "fileMenuItem"; + this.projectFromExistingCodeMenuItem = new Terminal.Gui.MenuItem(); + this.projectFromExistingCodeMenuItem.Title = "Project From Existing Code..."; + this.projectFromExistingCodeMenuItem.Data = "projectFromExistingCodeMenuItem"; + this.spellCheckerConfigurationForSelectedItemMenuItem = new Terminal.Gui.MenuItem(); + this.spellCheckerConfigurationForSelectedItemMenuItem.Title = "Spell Checker Configuration for Selected Item"; + this.spellCheckerConfigurationForSelectedItemMenuItem.Data = "spellCheckerConfigurationForSelectedItemMenuItem"; + this.newMenu.Children = new Terminal.Gui.MenuItem[] { + this.projectMenuItem, + this.repositoryMenuItem, + this.fileMenuItem, + this.projectFromExistingCodeMenuItem, + null, + this.spellCheckerConfigurationForSelectedItemMenuItem}; + this.openMenu = new Terminal.Gui.MenuBarItem(); + this.openMenu.Title = "Open"; + this.projectSolutionMenuItem = new Terminal.Gui.MenuItem(); + this.projectSolutionMenuItem.Title = "Project/Solution..."; + this.projectSolutionMenuItem.Data = "projectSolutionMenuItem"; + this.projectSolutionMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1342177359u)); + this.folderMenuItem = new Terminal.Gui.MenuItem(); + this.folderMenuItem.Title = "Folder..."; + this.folderMenuItem.Data = "folderMenuItem"; + this.folderMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(3489661007u)); + this.workspaceMenuItem = new Terminal.Gui.MenuItem(); + this.workspaceMenuItem.Title = "Workspace..."; + this.workspaceMenuItem.Data = "workspaceMenuItem"; + this.cMakeMenuItem = new Terminal.Gui.MenuItem(); + this.cMakeMenuItem.Title = "CMake..."; + this.cMakeMenuItem.Data = "cMakeMenuItem"; + this.fileMenuItem2 = new Terminal.Gui.MenuItem(); + this.fileMenuItem2.Title = "File..."; + this.fileMenuItem2.Data = "fileMenuItem2"; + this.fileMenuItem2.ShortcutKey = ((Terminal.Gui.KeyCode)(1073741903u)); + this.openMenu.Children = new Terminal.Gui.MenuItem[] { + this.projectSolutionMenuItem, + this.folderMenuItem, + this.workspaceMenuItem, + this.cMakeMenuItem, + null, + this.fileMenuItem2}; + this.cloneRepositoryMenuItem = new Terminal.Gui.MenuItem(); + this.cloneRepositoryMenuItem.Title = "Clone Repository..."; + this.cloneRepositoryMenuItem.Data = "cloneRepositoryMenuItem"; + this.startWindowMenuItem = new Terminal.Gui.MenuItem(); + this.startWindowMenuItem.Title = "Start Window"; + this.startWindowMenuItem.Data = "startWindowMenuItem"; + this.closeMenuItem = new Terminal.Gui.MenuItem(); + this.closeMenuItem.Title = "Close"; + this.closeMenuItem.Data = "closeMenuItem"; + this.closeSolutionMenuItem = new Terminal.Gui.MenuItem(); + this.closeSolutionMenuItem.Title = "Close Solution"; + this.closeSolutionMenuItem.Data = "closeSolutionMenuItem"; + this.startLiveShareSessionMenuItem = new Terminal.Gui.MenuItem(); + this.startLiveShareSessionMenuItem.Title = "Start Live Share Session"; + this.startLiveShareSessionMenuItem.Data = "startLiveShareSessionMenuItem"; + this.joinLiveShareSessionMenuItem = new Terminal.Gui.MenuItem(); + this.joinLiveShareSessionMenuItem.Title = "Join Live Share Session..."; + this.joinLiveShareSessionMenuItem.Data = "joinLiveShareSessionMenuItem"; + this.saveMenucsMenuItem = new Terminal.Gui.MenuItem(); + this.saveMenucsMenuItem.Title = "Save Menu.cs"; + this.saveMenucsMenuItem.Data = "saveMenucsMenuItem"; + this.saveMenucsMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1073741907u)); + this.saveMenucsAsMenuItem = new Terminal.Gui.MenuItem(); + this.saveMenucsAsMenuItem.Title = "Save Menu.cs As..."; + this.saveMenucsAsMenuItem.Data = "saveMenucsAsMenuItem"; + this.saveAllMenuItem = new Terminal.Gui.MenuItem(); + this.saveAllMenuItem.Title = "Save All"; + this.saveAllMenuItem.Data = "saveAllMenuItem"; + this.saveAllMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1342177363u)); + this.pageSetupMenuItem = new Terminal.Gui.MenuItem(); + this.pageSetupMenuItem.Title = "Page Setup..."; + this.pageSetupMenuItem.Data = "pageSetupMenuItem"; + this.printMenuItem = new Terminal.Gui.MenuItem(); + this.printMenuItem.Title = "Print..."; + this.printMenuItem.Data = "printMenuItem"; + this.printMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1073741904u)); + this.accountSettingsMenuItem = new Terminal.Gui.MenuItem(); + this.accountSettingsMenuItem.Title = "Account Settings..."; + this.accountSettingsMenuItem.Data = "accountSettingsMenuItem"; + this.recentFilesMenu = new Terminal.Gui.MenuBarItem(); + this.recentFilesMenu.Title = "Recent Files"; + this.file1csMenuItem = new Terminal.Gui.MenuItem(); + this.file1csMenuItem.Title = "File 1.cs"; + this.file1csMenuItem.Data = "file1csMenuItem"; + this.file2csMenuItem = new Terminal.Gui.MenuItem(); + this.file2csMenuItem.Title = "File 2.cs"; + this.file2csMenuItem.Data = "file2csMenuItem"; + this.recentFilesMenu.Children = new Terminal.Gui.MenuItem[] { + this.file1csMenuItem, + this.file2csMenuItem}; + this.recentProjectsAndSolutionsMenu = new Terminal.Gui.MenuBarItem(); + this.recentProjectsAndSolutionsMenu.Title = "Recent Projects and Solutions"; + this.terminalGuislnMenuItem = new Terminal.Gui.MenuItem(); + this.terminalGuislnMenuItem.Title = "Terminal.Gui.sln"; + this.terminalGuislnMenuItem.Data = "terminalGuislnMenuItem"; + this.terminalGuiDesignerslnMenuItem = new Terminal.Gui.MenuItem(); + this.terminalGuiDesignerslnMenuItem.Title = "TerminalGuiDesigner.sln"; + this.terminalGuiDesignerslnMenuItem.Data = "terminalGuiDesignerslnMenuItem"; + this.recentProjectsAndSolutionsMenu.Children = new Terminal.Gui.MenuItem[] { + this.terminalGuislnMenuItem, + this.terminalGuiDesignerslnMenuItem}; + this.moveMenucsIntoMenu = new Terminal.Gui.MenuBarItem(); + this.moveMenucsIntoMenu.Title = "Move Menu.cs into"; + this.solutionItemsMenuItem = new Terminal.Gui.MenuItem(); + this.solutionItemsMenuItem.Title = "1 Solution Items"; + this.solutionItemsMenuItem.Data = "solutionItemsMenuItem"; + this.unitTestsMenuItem = new Terminal.Gui.MenuItem(); + this.unitTestsMenuItem.Title = "2 UnitTests"; + this.unitTestsMenuItem.Data = "unitTestsMenuItem"; + this.showcaseMenuItem = new Terminal.Gui.MenuItem(); + this.showcaseMenuItem.Title = "3 Showcase"; + this.showcaseMenuItem.Data = "showcaseMenuItem"; + this.moveMenucsIntoMenu.Children = new Terminal.Gui.MenuItem[] { + this.solutionItemsMenuItem, + this.unitTestsMenuItem, + this.showcaseMenuItem}; + this.exitMenuItem = new Terminal.Gui.MenuItem(); + this.exitMenuItem.Title = "Exit"; + this.exitMenuItem.Data = "exitMenuItem"; + this.fileF9Menu.Children = new Terminal.Gui.MenuItem[] { + this.newMenu, + this.openMenu, + this.cloneRepositoryMenuItem, + this.startWindowMenuItem, + null, + this.closeMenuItem, + this.closeSolutionMenuItem, + null, + this.startLiveShareSessionMenuItem, + this.joinLiveShareSessionMenuItem, + null, + this.saveMenucsMenuItem, + this.saveMenucsAsMenuItem, + this.saveAllMenuItem, + null, + this.pageSetupMenuItem, + this.printMenuItem, + null, + this.accountSettingsMenuItem, + null, + this.recentFilesMenu, + this.recentProjectsAndSolutionsMenu, + null, + this.moveMenucsIntoMenu, + null, + this.exitMenuItem}; + this.editMenu = new Terminal.Gui.MenuBarItem(); + this.editMenu.Title = "Edit"; + this.goToMenu = new Terminal.Gui.MenuBarItem(); + this.goToMenu.Title = "Go To"; + this.goToLineMenuItem = new Terminal.Gui.MenuItem(); + this.goToLineMenuItem.Title = "Go To Line..."; + this.goToLineMenuItem.Data = "goToLineMenuItem"; + this.goToLineMenuItem.ShortcutKey = ((Terminal.Gui.KeyCode)(1073741895u)); + this.goToMenu.Children = new Terminal.Gui.MenuItem[] { + this.goToLineMenuItem}; + this.editMenu.Children = new Terminal.Gui.MenuItem[] { + this.goToMenu}; + this.menuBar.Menus = new Terminal.Gui.MenuBarItem[] { + this.fileF9Menu, + this.editMenu}; + this.Add(this.menuBar); + } + } +} diff --git a/Showcase/Menu.cs b/Showcase/Menu.cs new file mode 100644 index 00000000..cbac1d06 --- /dev/null +++ b/Showcase/Menu.cs @@ -0,0 +1,20 @@ + +//------------------------------------------------------------------------------ + +// +// This code was generated by: +// TerminalGuiDesigner v2.0.0.0 +// You can make changes to this file and they will not be overwritten when saving. +// +// ----------------------------------------------------------------------------- +namespace Showcase { + using Terminal.Gui; + + + public partial class Menu { + + public Menu() { + InitializeComponent(); + } + } +} diff --git a/Showcase/NumericUpDown.Designer.cs b/Showcase/NumericUpDown.Designer.cs index 5afbe074..bec4f4b7 100644 --- a/Showcase/NumericUpDown.Designer.cs +++ b/Showcase/NumericUpDown.Designer.cs @@ -65,15 +65,19 @@ private void InitializeComponent() { this.Y = 0; this.Visible = true; this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.Modal = false; this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = ""; + this.Title = "Numeric Up Down Controls"; this.lblInt.Width = Dim.Auto(); this.lblInt.Height = 1; this.lblInt.X = 0; this.lblInt.Y = 0; this.lblInt.Visible = true; this.lblInt.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblInt.CanFocus = true; + this.lblInt.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblInt.Data = "lblInt"; this.lblInt.Text = "Int:"; this.lblInt.TextAlignment = Terminal.Gui.Alignment.Start; @@ -84,6 +88,8 @@ private void InitializeComponent() { this.numericUpDownInt.Y = 0; this.numericUpDownInt.Visible = true; this.numericUpDownInt.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDownInt.CanFocus = true; + this.numericUpDownInt.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDownInt.Data = "numericUpDownInt"; this.numericUpDownInt.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDownInt.Value = 1; @@ -95,6 +101,8 @@ private void InitializeComponent() { this.lblInt64.Y = 1; this.lblInt64.Visible = true; this.lblInt64.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblInt64.CanFocus = true; + this.lblInt64.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblInt64.Data = "lblInt64"; this.lblInt64.Text = "Int64:"; this.lblInt64.TextAlignment = Terminal.Gui.Alignment.Start; @@ -105,6 +113,8 @@ private void InitializeComponent() { this.numericUpDownInt64.Y = 1; this.numericUpDownInt64.Visible = true; this.numericUpDownInt64.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDownInt64.CanFocus = true; + this.numericUpDownInt64.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDownInt64.Data = "numericUpDownInt64"; this.numericUpDownInt64.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDownInt64.Value = 8943589458974; @@ -116,6 +126,8 @@ private void InitializeComponent() { this.label3.Y = 2; this.label3.Visible = true; this.label3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label3.CanFocus = true; + this.label3.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label3.Data = "label3"; this.label3.Text = "Double:"; this.label3.TextAlignment = Terminal.Gui.Alignment.Start; @@ -126,6 +138,8 @@ private void InitializeComponent() { this.numericUpDown2.Y = 2; this.numericUpDown2.Visible = true; this.numericUpDown2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDown2.CanFocus = true; + this.numericUpDown2.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDown2.Data = "numericUpDown2"; this.numericUpDown2.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDown2.Value = 32.3D; @@ -137,6 +151,8 @@ private void InitializeComponent() { this.label6.Y = 3; this.label6.Visible = true; this.label6.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label6.CanFocus = true; + this.label6.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label6.Data = "label6"; this.label6.Text = "Single:"; this.label6.TextAlignment = Terminal.Gui.Alignment.Start; @@ -147,6 +163,8 @@ private void InitializeComponent() { this.numericUpDownSingle.Y = 3; this.numericUpDownSingle.Visible = true; this.numericUpDownSingle.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDownSingle.CanFocus = true; + this.numericUpDownSingle.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDownSingle.Data = "numericUpDownSingle"; this.numericUpDownSingle.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDownSingle.Value = 1F; @@ -158,6 +176,8 @@ private void InitializeComponent() { this.label.Y = 4; this.label.Visible = true; this.label.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label.CanFocus = true; + this.label.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label.Data = "label"; this.label.Text = "Decimal:"; this.label.TextAlignment = Terminal.Gui.Alignment.Start; @@ -168,6 +188,8 @@ private void InitializeComponent() { this.numericUpDownDecimal.Y = 4; this.numericUpDownDecimal.Visible = true; this.numericUpDownDecimal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDownDecimal.CanFocus = true; + this.numericUpDownDecimal.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDownDecimal.Data = "numericUpDownDecimal"; this.numericUpDownDecimal.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDownDecimal.Value = 0.00000000001m; @@ -179,6 +201,8 @@ private void InitializeComponent() { this.label4.Y = 7; this.label4.Visible = true; this.label4.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label4.CanFocus = true; + this.label4.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label4.Data = "label4"; this.label4.Text = "Single:"; this.label4.TextAlignment = Terminal.Gui.Alignment.Start; @@ -189,6 +213,8 @@ private void InitializeComponent() { this.numericUpDown3.Y = 7; this.numericUpDown3.Visible = true; this.numericUpDown3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.numericUpDown3.CanFocus = true; + this.numericUpDown3.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.numericUpDown3.Data = "numericUpDown3"; this.numericUpDown3.TextAlignment = Terminal.Gui.Alignment.Start; this.numericUpDown3.Value = float.PositiveInfinity; @@ -200,6 +226,8 @@ private void InitializeComponent() { this.label5.Y = 7; this.label5.Visible = true; this.label5.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label5.CanFocus = true; + this.label5.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label5.Data = "label5"; this.label5.Text = "(Supports infinitiy!?)"; this.label5.TextAlignment = Terminal.Gui.Alignment.Start; diff --git a/Showcase/Showcase.csproj b/Showcase/Showcase.csproj index 41aa7203..273199f7 100644 --- a/Showcase/Showcase.csproj +++ b/Showcase/Showcase.csproj @@ -8,7 +8,7 @@ - + diff --git a/Showcase/Slider.Designer.cs b/Showcase/Slider.Designer.cs index 7ad8e1f7..db1bd361 100644 --- a/Showcase/Slider.Designer.cs +++ b/Showcase/Slider.Designer.cs @@ -31,7 +31,13 @@ public partial class Slider : Terminal.Gui.Window { private Terminal.Gui.Slider slider3; + private Terminal.Gui.Line line; + + private Terminal.Gui.Slider slider4; + private void InitializeComponent() { + this.slider4 = new Terminal.Gui.Slider(); + this.line = new Terminal.Gui.Line(); this.slider3 = new Terminal.Gui.Slider(); this.lblStringSliderThin = new Terminal.Gui.Label(); this.slider2 = new Terminal.Gui.Slider(); @@ -44,15 +50,19 @@ private void InitializeComponent() { this.Y = 0; this.Visible = true; this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.Modal = false; this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = ""; + this.Title = "Sliders"; this.label.Width = Dim.Auto(); this.label.Height = 1; this.label.X = 0; this.label.Y = 0; this.label.Visible = true; this.label.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label.CanFocus = true; + this.label.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label.Data = "label"; this.label.Text = "Int Slider (0 to 1):"; this.label.TextAlignment = Terminal.Gui.Alignment.Start; @@ -63,12 +73,14 @@ private void InitializeComponent() { this.slider1.Y = 0; this.slider1.Visible = true; this.slider1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.slider1.CanFocus = true; + this.slider1.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.slider1.Options = new System.Collections.Generic.List>(new Terminal.Gui.SliderOption[] { new Terminal.Gui.SliderOption("0", new System.Text.Rune('0'), 0), new Terminal.Gui.SliderOption("1", new System.Text.Rune('1'), 1)}); this.slider1.Orientation = Terminal.Gui.Orientation.Horizontal; this.slider1.RangeAllowSingle = false; - this.slider1.AllowEmpty = false; + this.slider1.AllowEmpty = true; this.slider1.MinimumInnerSpacing = 1; this.slider1.LegendsOrientation = Terminal.Gui.Orientation.Horizontal; this.slider1.ShowLegends = true; @@ -83,6 +95,8 @@ private void InitializeComponent() { this.lblStringSlider.Y = 2; this.lblStringSlider.Visible = true; this.lblStringSlider.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblStringSlider.CanFocus = true; + this.lblStringSlider.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblStringSlider.Data = "lblStringSlider"; this.lblStringSlider.Text = "String Slider (Wide):"; this.lblStringSlider.TextAlignment = Terminal.Gui.Alignment.Start; @@ -93,6 +107,8 @@ private void InitializeComponent() { this.slider2.Y = 2; this.slider2.Visible = true; this.slider2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.slider2.CanFocus = true; + this.slider2.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.slider2.Options = new System.Collections.Generic.List>(new Terminal.Gui.SliderOption[] { new Terminal.Gui.SliderOption("Fish", new System.Text.Rune('F'), "Fish"), new Terminal.Gui.SliderOption("Cat", new System.Text.Rune('C'), "Cat"), @@ -114,6 +130,8 @@ private void InitializeComponent() { this.lblStringSliderThin.Y = 4; this.lblStringSliderThin.Visible = true; this.lblStringSliderThin.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblStringSliderThin.CanFocus = true; + this.lblStringSliderThin.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblStringSliderThin.Data = "lblStringSliderThin"; this.lblStringSliderThin.Text = "String Slider (Thin):"; this.lblStringSliderThin.TextAlignment = Terminal.Gui.Alignment.Start; @@ -124,6 +142,8 @@ private void InitializeComponent() { this.slider3.Y = 4; this.slider3.Visible = true; this.slider3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.slider3.CanFocus = true; + this.slider3.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.slider3.Options = new System.Collections.Generic.List>(new Terminal.Gui.SliderOption[] { new Terminal.Gui.SliderOption("Fish", new System.Text.Rune('F'), "Fish"), new Terminal.Gui.SliderOption("Cat", new System.Text.Rune('C'), "Cat"), @@ -139,6 +159,39 @@ private void InitializeComponent() { this.slider3.Data = "slider3"; this.slider3.TextAlignment = Terminal.Gui.Alignment.Start; this.Add(this.slider3); + this.line.Width = Dim.Fill(-1); + this.line.Height = 1; + this.line.X = -1; + this.line.Y = 6; + this.line.Visible = true; + this.line.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.line.CanFocus = true; + this.line.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.line.Data = "line"; + this.line.Text = ""; + this.line.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.line); + this.slider4.Width = 5; + this.slider4.Height = Dim.Auto(); + this.slider4.X = 16; + this.slider4.Y = 9; + this.slider4.Visible = true; + this.slider4.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.slider4.CanFocus = true; + this.slider4.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.slider4.Options = new System.Collections.Generic.List>(new Terminal.Gui.SliderOption[] { + new Terminal.Gui.SliderOption("Zero", new System.Text.Rune('0'), 0D)}); + this.slider4.Orientation = Terminal.Gui.Orientation.Horizontal; + this.slider4.RangeAllowSingle = false; + this.slider4.AllowEmpty = false; + this.slider4.MinimumInnerSpacing = 1; + this.slider4.LegendsOrientation = Terminal.Gui.Orientation.Horizontal; + this.slider4.ShowLegends = true; + this.slider4.ShowEndSpacing = false; + this.slider4.Type = Terminal.Gui.SliderType.Single; + this.slider4.Data = "slider4"; + this.slider4.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.slider4); } } } diff --git a/src/ArrayExtensions.cs b/src/ArrayExtensions.cs index 9b8cea42..799afc4d 100644 --- a/src/ArrayExtensions.cs +++ b/src/ArrayExtensions.cs @@ -31,6 +31,12 @@ public static class ArrayExtensions return toReturn; } + /// + /// Converts an enumerable to a + /// + /// + /// + /// public static IListDataSource ToListDataSource(this IEnumerable enumerable) { // Get the type of the elements @@ -46,7 +52,8 @@ public static IListDataSource ToListDataSource(this IEnumerable enumerable) // Create an instance of ListWrapper var listWrapperType = typeof(ListWrapper<>).MakeGenericType(elementType); - return (IListDataSource)Activator.CreateInstance(listWrapperType, list); + return (IListDataSource)(Activator.CreateInstance(listWrapperType, list) + ?? throw new Exception("CreateInstance inexplicably returned null")); } } diff --git a/src/ContextMenuExtensions.cs b/src/ContextMenuExtensions.cs new file mode 100644 index 00000000..c920da5e --- /dev/null +++ b/src/ContextMenuExtensions.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terminal.Gui; + +namespace TerminalGuiDesigner; + +internal static class ContextMenuExtensions +{ + public static void SetMenuItems(this ContextMenu menu, MenuBarItem? value) + { + var prop = typeof(ContextMenu).GetProperty(nameof(ContextMenu.MenuItems)) + ?? throw new Exception($"Expected property {nameof(ContextMenu.MenuItems)} did not exist on {nameof(ContextMenu)}"); + prop.SetValue(menu,value); + } +} + diff --git a/src/Design.cs b/src/Design.cs index a789ef8b..fe30f68f 100644 --- a/src/Design.cs +++ b/src/Design.cs @@ -44,8 +44,6 @@ public class Design typeof(LineView), typeof(ListView), typeof(MenuBar), - typeof(ScrollBarView), - typeof(ScrollView), typeof(TableView), typeof(TabView), typeof(TreeView), @@ -168,10 +166,6 @@ public void CreateSubControlDesigns() /// A new wrapper wrapping . public Design CreateSubControlDesign(string name, View subView) { - // all views can be focused so that they can be edited - // or deleted etc - subView.CanFocus = true; - if (subView is TableView tv && tv.Table != null && tv.GetDataTable().Rows.Count == 0) { var dt = tv.GetDataTable(); @@ -215,14 +209,12 @@ public Design CreateSubControlDesign(string name, View subView) { // prevent control from responding to events txt.MouseClick += (s, e) => this.SuppressNativeClickEvents(s, e); - txt.KeyDown += this.SuppressNativeKeyboardEvents; } if (subView is TextField tf) { // prevent control from responding to events tf.MouseClick += (s,e)=>this.SuppressNativeClickEvents(s,e); - tf.KeyDown += SuppressNativeKeyboardEvents; } if (subView.GetType().IsGenericType(typeof(Slider<>))) @@ -466,7 +458,7 @@ public IEnumerable GetSiblings() yield break; } - foreach (var v in this.View.SuperView.Subviews) + foreach (var v in this.View.SuperView.SubViews) { if (v == this.View) { @@ -626,7 +618,7 @@ private void CreateSubControlDesigns(View view) } } - private void SuppressNativeClickEvents(object? sender, MouseEventEventArgs obj, bool alsoSuppressClick = false) + private void SuppressNativeClickEvents(object? sender, MouseEventArgs obj, bool alsoSuppressClick = false) { if (alsoSuppressClick) { @@ -635,25 +627,10 @@ private void SuppressNativeClickEvents(object? sender, MouseEventEventArgs obj, else { // Suppress everything except single click (selection) - obj.Handled = obj.MouseEvent.Flags != MouseFlags.Button1Clicked; + obj.Handled = obj.Flags != MouseFlags.Button1Clicked; } } - private void SuppressNativeKeyboardEvents(object? sender, Key e) - { - if (sender == null) - { - return; - } - - if (e == Key.Tab || e == Key.Tab.WithShift || e == Key.Esc || e == Application.QuitKey) - { - e.Handled = false; - return; - } - - e.Handled = true; - } private void RegisterCheckboxDesignTimeChanges(CheckBox cb) { @@ -662,7 +639,7 @@ private void RegisterCheckboxDesignTimeChanges(CheckBox cb) cb.KeyBindings.Remove(Key.Space); cb.MouseClick += (s, e) => { - if (e.MouseEvent.Flags.HasFlag(MouseFlags.Button1Clicked)) + if (e.Flags.HasFlag(MouseFlags.Button1Clicked)) { e.Handled = true; cb.SetFocus(); @@ -684,9 +661,13 @@ private IEnumerable LoadDesignableProperties() yield return this.CreateSuppressedProperty(nameof(this.View.Visible), true); yield return this.CreateSuppressedProperty(nameof(this.View.Arrangement), ViewArrangement.Fixed); + yield return new ColorSchemeProperty(this); + yield return this.CreateSuppressedProperty(nameof(View.CanFocus), true); + yield return this.CreateProperty(nameof(this.View.ShadowStyle)); + // its important that this comes before Text because // changing the validator clears the text if (this.View is TextValidateField) diff --git a/src/DesignState.cs b/src/DesignState.cs index 22c2c411..930c2cd3 100644 --- a/src/DesignState.cs +++ b/src/DesignState.cs @@ -22,8 +22,8 @@ public DesignState(Design design) { this.Design = design; this.OriginalScheme = this.Design.View.GetExplicitColorScheme(); - this.Design.View.DrawContentComplete += this.DrawContentComplete; - this.Design.View.Enter += this.Enter; + this.Design.View.DrawComplete += this.DrawContentComplete; + this.Design.View.HasFocusChanged += this.Enter; } /// @@ -39,8 +39,13 @@ public DesignState(Design design) /// public Design Design { get; } - private void Enter(object? sender, FocusEventArgs obj) + private void Enter(object? sender, HasFocusEventArgs obj) { + // it's not enter + if (!obj.NewValue) + { + return; + } // when tabbing or clicking into this View when nothing complicated is going on (e.g. Ctrl+Click multi select) if (SelectionManager.Instance.Selected.Count <= 1) { diff --git a/src/DimExtensions.cs b/src/DimExtensions.cs index 107b8907..c0a06e32 100644 --- a/src/DimExtensions.cs +++ b/src/DimExtensions.cs @@ -17,7 +17,7 @@ public static class DimExtensions private const bool TreatNullDimAs0 = true; /// - /// Returns true if the is a DimFactor (i.e. created by ). + /// Returns true if the is a DimFactor (i.e. created by ). /// /// Dimension to determine Type. /// true if is DimFactor. @@ -34,7 +34,7 @@ public static bool IsPercent(this Dim d) /// /// The to determine whether it represents a percent. /// The 'percentage' value of . This is the value that would/could be - /// passed to to produce the or 0 if is + /// passed to to produce the or 0 if is /// not DimFactor. public static bool IsPercent(this Dim d, out int percent) { @@ -50,10 +50,10 @@ public static bool IsPercent(this Dim d, out int percent) } /// - /// Determines whether an input is a . + /// Determines whether an input is a . /// /// Input to classify. - /// if is the result of a call. + /// if is the result of a call. public static bool IsFill(this Dim d) { if (d == null) @@ -66,13 +66,13 @@ public static bool IsFill(this Dim d) /// /// Input to classify. - /// The margin of the used to create or 0. + /// The margin of the used to create or 0. public static bool IsFill(this Dim d, out int margin) { if (d != null && d.IsFill()) { var df = (DimFill)d; - margin = df.Margin; + margin = ((DimAbsolute)df.Margin).Size; return true; } @@ -100,6 +100,9 @@ public static bool IsAbsolute(this Dim d) /// True if is a width/height. /// /// The to determine whether it is auto. + /// If is then this is . + /// If is then this is + /// If is then this is /// if is a auto sizing. public static bool IsAuto(this Dim d, out DimAutoStyle das, out Dim? min, out Dim? max) { @@ -193,8 +196,8 @@ public static bool IsCombine(this Dim d, out Dim left, out Dim right, out bool a /// /// The to determine type of. /// The determined type. - /// The numerical element of the type e.g. for - /// the is the percentage but for the + /// The numerical element of the type e.g. for + /// the is the percentage but for the /// is the margin. /// The numerical offset if any, for example -5 in the following: /// Dim.Fill(1)-5 diff --git a/src/DimType.cs b/src/DimType.cs index 2e2670a3..dbe9e759 100644 --- a/src/DimType.cs +++ b/src/DimType.cs @@ -13,12 +13,12 @@ public enum DimType Absolute, /// - /// Percent of the remaining width/height e.g. . + /// Percent of the remaining width/height e.g. . /// Percent, /// - /// Filling the remaining space with a margin e.g. . + /// Filling the remaining space with a margin e.g. . /// Fill, diff --git a/src/Operations/AddViewOperation.cs b/src/Operations/AddViewOperation.cs index ed890487..0dec5cd1 100644 --- a/src/Operations/AddViewOperation.cs +++ b/src/Operations/AddViewOperation.cs @@ -46,7 +46,7 @@ public AddViewOperation(Design design) } /// - public override void Redo() + protected override void RedoImpl() { if (this.add == null) { @@ -55,11 +55,11 @@ public override void Redo() var v = this.GetViewToAddTo(); v.Add(this.add); - v.SetNeedsDisplay(); + v.SetNeedsDraw(); } /// - public override void Undo() + protected override void UndoImpl() { if (this.add == null) { @@ -68,7 +68,7 @@ public override void Undo() var v = this.GetViewToAddTo(); v.Remove(this.add); - v.SetNeedsDisplay(); + v.SetNeedsDraw(); } /// @@ -118,7 +118,7 @@ protected override bool DoImpl() SelectionManager.Instance.ForceSetSelection(design); - v.SetNeedsDisplay(); + v.SetNeedsDraw(); return true; } diff --git a/src/Operations/CompositeOperation.cs b/src/Operations/CompositeOperation.cs index da09d9d8..0c1dcb08 100644 --- a/src/Operations/CompositeOperation.cs +++ b/src/Operations/CompositeOperation.cs @@ -33,12 +33,12 @@ public CompositeOperation(params Operation[] operations) } /// - /// Gets the collection of sub operations performed on / . + /// Gets the collection of sub operations performed on / . /// public IReadOnlyCollection Operations => new ReadOnlyCollection(this.operations); /// - public override void Redo() + protected override void RedoImpl() { foreach (var op in this.operations) { @@ -47,7 +47,7 @@ public override void Redo() } /// - public override void Undo() + protected override void UndoImpl() { foreach (var op in this.operations) { diff --git a/src/Operations/CopyOperation.cs b/src/Operations/CopyOperation.cs index 80a509ba..e7febe4a 100644 --- a/src/Operations/CopyOperation.cs +++ b/src/Operations/CopyOperation.cs @@ -57,7 +57,7 @@ public override string ToString() /// Throws as you cannot undo a copy. /// /// Thrown if method run. - public override void Undo() + protected override void UndoImpl() { throw new NotSupportedException(); } @@ -66,7 +66,7 @@ public override void Undo() /// Throws as you cannot redo a copy. /// /// Thrown if method run. - public override void Redo() + protected override void RedoImpl() { throw new NotSupportedException(); } diff --git a/src/Operations/DeleteColorSchemeOperation.cs b/src/Operations/DeleteColorSchemeOperation.cs index 15a82dcb..03f963b3 100644 --- a/src/Operations/DeleteColorSchemeOperation.cs +++ b/src/Operations/DeleteColorSchemeOperation.cs @@ -36,13 +36,13 @@ public DeleteColorSchemeOperation(Design design, NamedColorScheme toDelete) public NamedColorScheme ToDelete { get; } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { foreach (var u in this.users) { diff --git a/src/Operations/DeleteViewOperation.cs b/src/Operations/DeleteViewOperation.cs index 5a527696..ddacff47 100644 --- a/src/Operations/DeleteViewOperation.cs +++ b/src/Operations/DeleteViewOperation.cs @@ -42,13 +42,13 @@ public DeleteViewOperation(params Design[] delete) } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { for (int i = 0; i < this.delete.Length; i++) { diff --git a/src/Operations/DragOperation.cs b/src/Operations/DragOperation.cs index b4eb800e..0f208c36 100644 --- a/src/Operations/DragOperation.cs +++ b/src/Operations/DragOperation.cs @@ -140,7 +140,7 @@ public View? DropInto /// /// Moves all dragged views back to original positions. /// - public override void Undo() + protected override void UndoImpl() { foreach (var mem in this.mementos) { @@ -149,7 +149,7 @@ public override void Undo() } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } diff --git a/src/Operations/Generics/AddOperation.cs b/src/Operations/Generics/AddOperation.cs index e49edbf2..7e8e9fc0 100644 --- a/src/Operations/Generics/AddOperation.cs +++ b/src/Operations/Generics/AddOperation.cs @@ -41,13 +41,13 @@ public AddOperation( } /// - public override void Undo() + protected override void UndoImpl() { this.Remove(this.newItem); } /// - public override void Redo() + protected override void RedoImpl() { this.Add(this.newItem); } @@ -83,7 +83,7 @@ protected override bool DoImpl() this.newItem = this.elementFactory(this.View, uniqueName); this.Add(this.newItem); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } } \ No newline at end of file diff --git a/src/Operations/Generics/GenericArrayOperation.cs b/src/Operations/Generics/GenericArrayOperation.cs index 1b54c7d4..5f1cba9d 100644 --- a/src/Operations/Generics/GenericArrayOperation.cs +++ b/src/Operations/Generics/GenericArrayOperation.cs @@ -63,16 +63,16 @@ protected virtual void Add(T2? newItem) current.Add(newItem); this.ArraySetter(this.View, current.Cast().ToArray()); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); } /// /// Calls any update/refresh status code that is needed after making changes to collection. - /// Default implementation just calls on . + /// Default implementation just calls on . /// - protected virtual void SetNeedsDisplay() + protected virtual void SetNeedsDraw() { - this.View.SetNeedsDisplay(); + this.View.SetNeedsDraw(); } /// @@ -92,7 +92,7 @@ protected bool Remove(T2? toRemove) current.Remove(toRemove); this.ArraySetter(this.View, current.Cast().ToArray()); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } diff --git a/src/Operations/Generics/MoveOperation.cs b/src/Operations/Generics/MoveOperation.cs index 38db9bad..c70f700b 100644 --- a/src/Operations/Generics/MoveOperation.cs +++ b/src/Operations/Generics/MoveOperation.cs @@ -80,13 +80,13 @@ public override string ToString() } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { var list = this.ArrayGetter(this.View).ToList(); @@ -94,7 +94,7 @@ public override void Undo() list.Insert(this.originalIdx, this.OperateOn); this.ArraySetter(this.View, list.Cast().ToArray()); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); } /// @@ -106,7 +106,7 @@ protected override bool DoImpl() list.Insert(this.newIndex, this.OperateOn); this.ArraySetter(this.View, list.Cast().ToArray()); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } } diff --git a/src/Operations/Generics/RemoveOperation.cs b/src/Operations/Generics/RemoveOperation.cs index da98e0c3..58edf422 100644 --- a/src/Operations/Generics/RemoveOperation.cs +++ b/src/Operations/Generics/RemoveOperation.cs @@ -33,7 +33,7 @@ public RemoveOperation( } /// - public override void Undo() + protected override void UndoImpl() { // its not there anyways if (this.OperateOn == null) @@ -44,11 +44,11 @@ public override void Undo() var current = this.ArrayGetter(this.View).Cast().ToList(); current.Insert(this.idx, this.OperateOn); this.ArraySetter(this.View, current.ToArray()); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } diff --git a/src/Operations/Generics/RenameOperation.cs b/src/Operations/Generics/RenameOperation.cs index b2e086c0..6d1bb988 100644 --- a/src/Operations/Generics/RenameOperation.cs +++ b/src/Operations/Generics/RenameOperation.cs @@ -49,7 +49,7 @@ public override string ToString() } /// - public override void Redo() + protected override void RedoImpl() { if (this.newName == null) { @@ -57,14 +57,14 @@ public override void Redo() } this.stringSetter(this.OperateOn, this.newName); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); } /// - public override void Undo() + protected override void UndoImpl() { this.stringSetter(this.OperateOn, this.originalName); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); } /// @@ -84,7 +84,7 @@ protected override bool DoImpl() } this.stringSetter(this.OperateOn, this.newName); - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } diff --git a/src/Operations/IOperation.cs b/src/Operations/IOperation.cs index 1f9822da..18aad942 100644 --- a/src/Operations/IOperation.cs +++ b/src/Operations/IOperation.cs @@ -33,7 +33,7 @@ public interface IOperation /// /// Gets the number of times this has been executed successfully /// - ref int TimesDone { get; } + int TimesDone { get; } /// /// Performs the operation. diff --git a/src/Operations/MenuOperations/AddMenuItemOperation.cs b/src/Operations/MenuOperations/AddMenuItemOperation.cs index 35c5056b..381a4024 100644 --- a/src/Operations/MenuOperations/AddMenuItemOperation.cs +++ b/src/Operations/MenuOperations/AddMenuItemOperation.cs @@ -28,7 +28,7 @@ public AddMenuItemOperation(MenuItem adjacentTo) } /// - public override void Redo() + protected override void RedoImpl() { if (this.added != null) { @@ -37,7 +37,7 @@ public override void Redo() } /// - public override void Undo() + protected override void UndoImpl() { if (this.added == null) { @@ -79,7 +79,7 @@ private bool Add(MenuItem menuItem) children.Insert(insertAt, menuItem); this.Parent.Children = children.ToArray(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); return true; } diff --git a/src/Operations/MenuOperations/ConvertMenuItemToSeperatorOperation.cs b/src/Operations/MenuOperations/ConvertMenuItemToSeperatorOperation.cs index b1a6e468..828bb869 100644 --- a/src/Operations/MenuOperations/ConvertMenuItemToSeperatorOperation.cs +++ b/src/Operations/MenuOperations/ConvertMenuItemToSeperatorOperation.cs @@ -22,13 +22,13 @@ public ConvertMenuItemToSeperatorOperation(MenuItem toConvert) } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { if (this.Parent == null || this.OperateOn == null) { @@ -39,7 +39,7 @@ public override void Undo() children[this.removedAtIdx] = this.OperateOn; this.Parent.Children = children.ToArray(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); } /// @@ -56,7 +56,7 @@ protected override bool DoImpl() children[this.removedAtIdx] = null; this.Parent.Children = children.ToArray(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); return true; } diff --git a/src/Operations/MenuOperations/MoveMenuItemLeftOperation.cs b/src/Operations/MenuOperations/MoveMenuItemLeftOperation.cs index 3bcfe173..8e701f71 100644 --- a/src/Operations/MenuOperations/MoveMenuItemLeftOperation.cs +++ b/src/Operations/MenuOperations/MoveMenuItemLeftOperation.cs @@ -38,13 +38,13 @@ public MoveMenuItemLeftOperation(MenuItem toMove) } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { if (this.OperateOn == null || this.IsImpossible) { @@ -94,7 +94,7 @@ protected override bool DoImpl() MenuTracker.Instance.ConvertEmptyMenus(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); return true; } diff --git a/src/Operations/MenuOperations/MoveMenuItemOperation.cs b/src/Operations/MenuOperations/MoveMenuItemOperation.cs index 75c7f1b8..062a5716 100644 --- a/src/Operations/MenuOperations/MoveMenuItemOperation.cs +++ b/src/Operations/MenuOperations/MoveMenuItemOperation.cs @@ -45,13 +45,13 @@ public MoveMenuItemOperation(MenuItem toMove, bool up) } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { this.Move(this.up ? 1 : -1); } @@ -80,7 +80,7 @@ private bool Move(int amount) this.siblings.Insert(moveTo, this.OperateOn); this.Parent.Children = this.siblings.ToArray(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); return true; } diff --git a/src/Operations/MenuOperations/MoveMenuItemRightOperation.cs b/src/Operations/MenuOperations/MoveMenuItemRightOperation.cs index 39800333..1d925c92 100644 --- a/src/Operations/MenuOperations/MoveMenuItemRightOperation.cs +++ b/src/Operations/MenuOperations/MoveMenuItemRightOperation.cs @@ -31,7 +31,7 @@ public MoveMenuItemRightOperation(MenuItem toMove) public int? InsertionIndex { get; set; } /// - public override void Redo() + protected override void RedoImpl() { if (this.OperateOn == null) { @@ -42,7 +42,7 @@ public override void Redo() } /// - public override void Undo() + protected override void UndoImpl() { if (this.Parent == null || this.OperateOn == null) { @@ -96,7 +96,7 @@ protected override bool DoImpl() // update the sub-menu addTo.Children = submenuChildren.ToArray(); - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); return true; } diff --git a/src/Operations/MenuOperations/RemoveMenuItemOperation.cs b/src/Operations/MenuOperations/RemoveMenuItemOperation.cs index c6cc9d60..d951564e 100644 --- a/src/Operations/MenuOperations/RemoveMenuItemOperation.cs +++ b/src/Operations/MenuOperations/RemoveMenuItemOperation.cs @@ -51,13 +51,13 @@ public RemoveMenuItemOperation(MenuItem toRemove) public bool PrunedTopLevelMenu => this.prunedEmptyTopLevelMenus != null && this.prunedEmptyTopLevelMenus.Any(); /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { if (this.Parent == null || this.OperateOn == null) { @@ -70,7 +70,7 @@ public override void Undo() this.OperateOn, .. Parent.Children[ removedAtIdx .. ] ]; - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); // if any MenuBarItem were converted to vanilla MenuItem // because we were removed from a sub-menu then convert @@ -131,7 +131,7 @@ protected override bool DoImpl() .. Parent.Children[ ..removedAtIdx ], .. Parent.Children[ ( removedAtIdx + 1 ).. ] ]; - this.Bar?.SetNeedsDisplay(); + this.Bar?.SetNeedsDraw(); if (this.Bar != null) { diff --git a/src/Operations/MenuOperations/RenameMenuItemOperation.cs b/src/Operations/MenuOperations/RenameMenuItemOperation.cs index dc71a2f1..5b82da44 100644 --- a/src/Operations/MenuOperations/RenameMenuItemOperation.cs +++ b/src/Operations/MenuOperations/RenameMenuItemOperation.cs @@ -28,7 +28,7 @@ public RenameMenuItemOperation(MenuItem toRename) } /// - public override void Redo() + protected override void RedoImpl() { if (this.OperateOn != null) { @@ -37,7 +37,7 @@ public override void Redo() } /// - public override void Undo() + protected override void UndoImpl() { if (this.OperateOn != null) { diff --git a/src/Operations/MoveViewOperation.cs b/src/Operations/MoveViewOperation.cs index ebdf1aae..40b8af0b 100644 --- a/src/Operations/MoveViewOperation.cs +++ b/src/Operations/MoveViewOperation.cs @@ -90,13 +90,13 @@ public MoveViewOperation(Design toMove, int deltaX, int deltaY) public int DestinationX { get; } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } /// - public override void Undo() + protected override void UndoImpl() { if (this.BeingMoved.View.X.IsAbsolute()) { diff --git a/src/Operations/Operation.cs b/src/Operations/Operation.cs index be32983c..019861ab 100644 --- a/src/Operations/Operation.cs +++ b/src/Operations/Operation.cs @@ -1,11 +1,17 @@ -namespace TerminalGuiDesigner.Operations; +using NLog; +using Terminal.Gui; + +namespace TerminalGuiDesigner.Operations; /// /// Abstract base class for . /// public abstract class Operation : IOperation { - protected int _timesDone; + /// + /// The number of times the operation has been performed. + /// + private int _timesDone; /// /// The name to give to all objects which do not have a title/text etc. @@ -20,7 +26,7 @@ public abstract class Operation : IOperation public bool SupportsUndo { get; protected set; } = true; /// - public ref int TimesDone => ref _timesDone; + public int TimesDone => _timesDone; /// /// Defaults to . @@ -45,6 +51,8 @@ public bool Do() return false; } + Logging.Information($"Do Operation {UniqueIdentifier} ({GetType().Name})"); + if ( this.DoImpl( ) ) { Interlocked.Increment( ref _timesDone ); @@ -55,10 +63,24 @@ public bool Do() } /// - public abstract void Undo(); + public void Undo() + { + Logging.Information($"Undo Operation {UniqueIdentifier} ({GetType().Name})"); + UndoImpl(); + } + + /// + protected abstract void UndoImpl(); /// - public abstract void Redo(); + public void Redo() + { + Logging.Information($"Redo Operation {UniqueIdentifier} ({GetType().Name})"); + RedoImpl(); + } + + /// + protected abstract void RedoImpl(); /// protected abstract bool DoImpl(); diff --git a/src/Operations/OperationFactory.cs b/src/Operations/OperationFactory.cs index 84fcf032..9ec55f3b 100644 --- a/src/Operations/OperationFactory.cs +++ b/src/Operations/OperationFactory.cs @@ -26,12 +26,12 @@ public OperationFactory(PropertyValueGetterDelegate valueGetter) /// set of given the mouse state. /// /// All that are currently selected (see ). - /// (if any) that prompted this request e.g. if user right clicks a . + /// (if any) that prompted this request e.g. if user right clicks a . /// If is populated then this should be the wrapper for - /// the that the mouse was over at the time it was clicked (see . + /// the that the mouse was over at the time it was clicked (see . /// String that represents what the returned act upon e.g. "myLabel" or "8 objects". /// Collection of all that can be offered to user as runnable given the current selection. - public IEnumerable CreateOperations(Design[] selected, MouseEvent? m, Design? rightClicked, out string name) + public IEnumerable CreateOperations(Design[] selected, MouseEventArgs? m, Design? rightClicked, out string name) { List toReturn = new(); @@ -99,7 +99,7 @@ public IEnumerable CreateOperations(Design[] selected, MouseEvent? m return toReturn; } - private IEnumerable CreateOperations(MouseEvent? m, Design d) + private IEnumerable CreateOperations(MouseEventArgs? m, Design d) { var ops = m == null ? d.GetExtraOperations() : diff --git a/src/Operations/PasteOperation.cs b/src/Operations/PasteOperation.cs index 606006c4..4e1508b6 100644 --- a/src/Operations/PasteOperation.cs +++ b/src/Operations/PasteOperation.cs @@ -63,7 +63,7 @@ public PasteOperation(Design addTo) } /// - public override void Undo() + protected override void UndoImpl() { foreach (var a in this.addOperations) { @@ -74,7 +74,7 @@ public override void Undo() } /// - public override void Redo() + protected override void RedoImpl() { foreach (var a in this.addOperations) { diff --git a/src/Operations/ResizeOperation.cs b/src/Operations/ResizeOperation.cs index 4f6019e1..4242ef66 100644 --- a/src/Operations/ResizeOperation.cs +++ b/src/Operations/ResizeOperation.cs @@ -55,14 +55,15 @@ public ResizeOperation(Design beingResized, int destX, int destY) public int DestinationY { get; private set; } /// - public override void Undo() + protected override void UndoImpl() { this.BeingResized.GetDesignableProperty("Width")?.SetValue(this.OriginalWidth); this.BeingResized.GetDesignableProperty("Height")?.SetValue(this.OriginalHeight); + this.BeingResized.View.Layout(); } /// - public override void Redo() + protected override void RedoImpl() { this.Do(); } @@ -81,6 +82,8 @@ public void ContinueResize(Point dest) this.DestinationY = dest.Y; this.SetHeight(); + + this.BeingResized.View.Layout(); } /// diff --git a/src/Operations/SetPropertyOperation.cs b/src/Operations/SetPropertyOperation.cs index 13f77269..ec03965a 100644 --- a/src/Operations/SetPropertyOperation.cs +++ b/src/Operations/SetPropertyOperation.cs @@ -116,7 +116,7 @@ public IReadOnlyCollection Designs } /// - public override void Undo() + protected override void UndoImpl() { foreach (var m in this.mementos) { @@ -125,7 +125,7 @@ public override void Undo() } /// - public override void Redo() + protected override void RedoImpl() { foreach (var m in this.mementos) { diff --git a/src/Operations/StatusBarOperations/MoveStatusItemOperation.cs b/src/Operations/StatusBarOperations/MoveStatusItemOperation.cs index f8c4797f..4525179d 100644 --- a/src/Operations/StatusBarOperations/MoveStatusItemOperation.cs +++ b/src/Operations/StatusBarOperations/MoveStatusItemOperation.cs @@ -4,7 +4,7 @@ namespace TerminalGuiDesigner.Operations.StatusBarOperations { /// - /// Moves a on a left or right. + /// Moves a on a left or right. /// public class MoveStatusItemOperation : MoveOperation { diff --git a/src/Operations/StatusBarOperations/RemoveStatusItemOperation.cs b/src/Operations/StatusBarOperations/RemoveStatusItemOperation.cs index 5f0cc8ed..25f59f54 100644 --- a/src/Operations/StatusBarOperations/RemoveStatusItemOperation.cs +++ b/src/Operations/StatusBarOperations/RemoveStatusItemOperation.cs @@ -5,7 +5,7 @@ namespace TerminalGuiDesigner.Operations.StatusBarOperations { /// - /// Removes a from a . + /// Removes a from a . /// public class RemoveStatusItemOperation : RemoveOperation { @@ -13,7 +13,7 @@ public class RemoveStatusItemOperation : RemoveOperation /// Initializes a new instance of the class. /// /// Wrapper for a . - /// A to remove from bar. + /// A to remove from bar. public RemoveStatusItemOperation(Design design, Shortcut toRemove) : base( (v) => v.GetShortcuts(), diff --git a/src/Operations/StatusBarOperations/RenameStatusItemOperation.cs b/src/Operations/StatusBarOperations/RenameStatusItemOperation.cs index f32eee92..fd83e73b 100644 --- a/src/Operations/StatusBarOperations/RenameStatusItemOperation.cs +++ b/src/Operations/StatusBarOperations/RenameStatusItemOperation.cs @@ -5,7 +5,7 @@ namespace TerminalGuiDesigner.Operations.StatusBarOperations { /// - /// Renames a on a . + /// Renames a on a . /// public class RenameStatusItemOperation : RenameOperation { @@ -13,7 +13,7 @@ public class RenameStatusItemOperation : RenameOperation /// Initializes a new instance of the class. /// /// Design wrapper for a . - /// The to rename. + /// The to rename. /// The new name to use or null to prompt user. public RenameStatusItemOperation(Design design, Shortcut toRename, string? newName) : base( diff --git a/src/Operations/StatusBarOperations/SetShortcutOperation.cs b/src/Operations/StatusBarOperations/SetShortcutOperation.cs index f0c8195d..38cc6608 100644 --- a/src/Operations/StatusBarOperations/SetShortcutOperation.cs +++ b/src/Operations/StatusBarOperations/SetShortcutOperation.cs @@ -5,19 +5,19 @@ namespace TerminalGuiDesigner.Operations.StatusBarOperations { /// - /// Changes the of a on + /// Changes the of a on /// a . /// public class SetShortcutOperation : GenericArrayElementOperation { private Key originalShortcut; - private Key? shortcut; + private Key shortcut; /// /// Initializes a new instance of the class. /// /// Wrapper for a . - /// The whose shortcut you want to change. + /// The whose shortcut you want to change. /// The new shortcut or null to prompt user at runtime. public SetShortcutOperation(Design design, Shortcut statusItem, Key? shortcut) : base( @@ -27,14 +27,14 @@ public SetShortcutOperation(Design design, Shortcut statusItem, Key? shortcut) design, statusItem) { - this.shortcut = shortcut; + this.shortcut = shortcut ?? Key.Empty; this.originalShortcut = statusItem.Key; } /// - public override void Redo() + protected override void RedoImpl() { - if (this.shortcut == null) + if (this.shortcut == Key.Empty) { return; } @@ -43,7 +43,7 @@ public override void Redo() } /// - public override void Undo() + protected override void UndoImpl() { this.OperateOn.Key = this.originalShortcut; } @@ -51,7 +51,7 @@ public override void Undo() /// protected override bool DoImpl() { - if (this.shortcut == null) + if (this.shortcut == Key.Empty) { this.shortcut = Modals.GetShortcut(); } diff --git a/src/Operations/TabOperations/RemoveTabOperation.cs b/src/Operations/TabOperations/RemoveTabOperation.cs index 4a447bc1..afad922e 100644 --- a/src/Operations/TabOperations/RemoveTabOperation.cs +++ b/src/Operations/TabOperations/RemoveTabOperation.cs @@ -26,13 +26,13 @@ public RemoveTabOperation(Design design, Tab toRemove) } /// - protected override void SetNeedsDisplay() + protected override void SetNeedsDraw() { if (!this.View.Tabs.Contains(this.View.SelectedTab)) { this.View.SelectedTab = this.View.Tabs.FirstOrDefault(); } - base.SetNeedsDisplay(); + base.SetNeedsDraw(); } } diff --git a/src/Operations/TabOperations/RenameTabOperation.cs b/src/Operations/TabOperations/RenameTabOperation.cs index 461604d8..c40177cf 100644 --- a/src/Operations/TabOperations/RenameTabOperation.cs +++ b/src/Operations/TabOperations/RenameTabOperation.cs @@ -4,14 +4,14 @@ namespace TerminalGuiDesigner.Operations.TabOperations; /// -/// Renames the of the currently selected +/// Renames the of the currently selected /// of a . /// public class RenameTabOperation : RenameOperation { /// /// Initializes a new instance of the class. - /// This command changes the on a . + /// This command changes the on a . /// /// Wrapper for a . /// Tab to rename. diff --git a/src/Operations/TableViewOperations/AddColumnOperation.cs b/src/Operations/TableViewOperations/AddColumnOperation.cs index d524ff19..72682afe 100644 --- a/src/Operations/TableViewOperations/AddColumnOperation.cs +++ b/src/Operations/TableViewOperations/AddColumnOperation.cs @@ -28,9 +28,9 @@ public AddColumnOperation(Design design, string? newColumnName) } /// - protected override void SetNeedsDisplay() + protected override void SetNeedsDraw() { this.View.Update(); - base.SetNeedsDisplay(); + base.SetNeedsDraw(); } } diff --git a/src/Options.cs b/src/Options.cs index bf8657e5..4e51a9a0 100644 --- a/src/Options.cs +++ b/src/Options.cs @@ -56,5 +56,19 @@ public static IEnumerable Examples [Option('e', HelpText = "Enables experimental features")] public bool Experimental { get; set; } + + /// + /// Gets or sets a which driver to use. + /// + [Option('d', HelpText = "Driver to use. v2, v2net, v2win, WindowsDriver, CursesDriver or NetDriver", + Default = "v2")] + public string Driver { get; set; } = "v2"; + + + /// + /// Gets or sets a value indicating whether to enable logging. + /// + [Option('q', HelpText = "Pass to suppress log generation")] + public bool Quiet { get; set; } #nullable enable warnings } diff --git a/src/PosExtensions.cs b/src/PosExtensions.cs index 853d2835..87e6d0da 100644 --- a/src/PosExtensions.cs +++ b/src/PosExtensions.cs @@ -196,7 +196,9 @@ public static bool IsRelative(this Pos? p, IList knownDesigns, [NotNullW } - /// + /// + ///Returns true if the is a summation or subtraction of two other + /// /// to classify. /// The left hand operand of the summation/subtraction. /// The right hand operand of the summation/subtraction. diff --git a/src/Program.cs b/src/Program.cs index 62bf379f..18184629 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -19,8 +19,9 @@ public static void Main(string[] args) .WithParsed(o => { Editor.Experimental = o.Experimental; - - Application.Init(); + Editor.Quiet = o.Quiet; + + Application.Init(null,o.Driver); var editor = new Editor(); editor.Run(o); }); diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json index 0ba7ea9b..dc17da51 100644 --- a/src/Properties/launchSettings.json +++ b/src/Properties/launchSettings.json @@ -1,7 +1,16 @@ { "profiles": { - "TerminalGuiDesigner": { - "commandName": "Project" + "WSL": { + "commandName": "WSL2", + "distributionName": "" + }, + "v2net": { + "commandName": "Project", + "commandLineArgs": "-d v2net" + }, + "v2win": { + "commandName": "Project", + "commandLineArgs": "-d v2win" } } } \ No newline at end of file diff --git a/src/ReflectionHelpers.cs b/src/ReflectionHelpers.cs index a7e954bd..4df4dc7d 100644 --- a/src/ReflectionHelpers.cs +++ b/src/ReflectionHelpers.cs @@ -35,7 +35,10 @@ internal static TOut GetNonNullNonPublicFieldValue( this TIn? item, s ArgumentNullException.ThrowIfNull( item, nameof( item ) ); ArgumentException.ThrowIfNullOrEmpty( fieldName, nameof( fieldName ) ); + // Try get private field e.g. 'blah'. But because upstream often flips + // around the naming of privates lets also look for '_blah' FieldInfo selectedField = typeof( TIn ).GetField( fieldName, BindingFlags.NonPublic | BindingFlags.Instance ) + ??typeof(TIn).GetField("_"+fieldName, BindingFlags.NonPublic | BindingFlags.Instance) ?? throw new MissingFieldException( $"Expected non-public instance field {fieldName} was not present on {typeof( TIn ).Name}" ); if ( selectedField.FieldType != typeof( TOut ) ) diff --git a/src/StatusBarExtensions.cs b/src/StatusBarExtensions.cs index 3a34d90f..fd20b13d 100644 --- a/src/StatusBarExtensions.cs +++ b/src/StatusBarExtensions.cs @@ -9,11 +9,11 @@ namespace TerminalGuiDesigner; public static class StatusBarExtensions { /// - /// Returns the that appears at the of the click. + /// Returns the that appears at the of the click. /// /// you want to find the clicked (top level menu) for. /// Screen coordinate of the click in X. - /// The under the mouse at this position or null (only considers X). + /// The under the mouse at this position or null (only considers X). public static Shortcut? ScreenToMenuBarItem(this StatusBar statusBar, int screenX) { // These might be changed in Terminal.Gui library @@ -38,7 +38,7 @@ public static class StatusBarExtensions int distance = initialWhitespace; Dictionary xLocations = new(); - foreach (var si in statusBar.Subviews.OfType()) + foreach (var si in statusBar.SubViews.OfType()) { xLocations.Add(distance, si); distance += si.Title.GetColumns() + afterEachItemWhitespace; @@ -65,14 +65,26 @@ public static class StatusBarExtensions /// public static int CountShortcuts(this StatusBar bar) { - return bar.Subviews.OfType().Count(); + return bar.SubViews.OfType().Count(); } + /// + /// Returns the items on the (previously + /// called StatusBarItems now called just ) + /// + /// + /// public static Shortcut[] GetShortcuts(this StatusBar bar) { - return bar.Subviews.OfType().ToArray(); + return bar.SubViews.OfType().ToArray(); } + /// + /// Replaces all items on the with the new + /// . + /// + /// + /// public static void SetShortcuts(this StatusBar bar, Shortcut[] shortcuts) { foreach(var old in bar.GetShortcuts()) diff --git a/src/TerminalGuiDesigner.csproj b/src/TerminalGuiDesigner.csproj index 730d58b9..d0f2b0f0 100644 --- a/src/TerminalGuiDesigner.csproj +++ b/src/TerminalGuiDesigner.csproj @@ -20,7 +20,7 @@ ./nupkg enable TerminalGuiDesigner - 2.0.0-alpha.2203 + 2.0.0-develop.4400 Thomas Nind enable MIT @@ -33,6 +33,8 @@ logo.png README.md + 2.0.0-alpha.4400 + * V2 driver support 2.0.0-alpha.2203 * True color `ColorPicker` 2.0.0-alpha.2189 @@ -129,7 +131,7 @@ * Right click context menu support * Increased mouse resizing click hit box * Added progress indicator for creating new Views - * Fixed mouse dragging/resizing of views in subviews (e.g. TabViews) + * Fixed mouse dragging/resizing of views in SubViews (e.g. TabViews) @@ -143,14 +145,15 @@ - - - + + + + diff --git a/src/ToCode/EnumToCode.cs b/src/ToCode/EnumToCode.cs index 0e62dad2..594fb07b 100644 --- a/src/ToCode/EnumToCode.cs +++ b/src/ToCode/EnumToCode.cs @@ -2,18 +2,31 @@ namespace TerminalGuiDesigner.ToCode; +/// +/// Code generation methods for writing out enum values +/// using CodeDom. +/// public class EnumToCode : ToCodeBase { private readonly Enum value; private readonly Type enumType; - + /// + /// Creates a new instance of the class, primed to generate code + /// for the supplied + /// + /// public EnumToCode(Enum value) { this.value = value; this.enumType = value.GetType(); } + /// + /// Returns code expression similar to MyEnum.SomeValue. + /// Supports Flags enums e.g. generating things like MyEnum.ValA | MyEnum.ValB + /// + /// public CodeExpression ToCode() { var isFlags = enumType.IsDefined(typeof(FlagsAttribute), false); diff --git a/src/ToCode/InstanceOfProperty.cs b/src/ToCode/InstanceOfProperty.cs index f161f666..366105e3 100644 --- a/src/ToCode/InstanceOfProperty.cs +++ b/src/ToCode/InstanceOfProperty.cs @@ -11,15 +11,29 @@ namespace TerminalGuiDesigner.ToCode; /// public class InstanceOfProperty : Property { - public Type MustBeDerrivedFrom { get; } + /// + /// Places a restriction on the that + /// can be supplied. When setting the value must be a class derrived + /// from this . + /// + public Type MustBeDerivedFrom { get; } + /// + /// Creates a new instance of designable property . + /// In which values set the supplied + /// + /// + /// + /// + /// public InstanceOfProperty(Design design, PropertyInfo property) : base(design, property) { - this.MustBeDerrivedFrom = property.PropertyType + this.MustBeDerivedFrom = property.PropertyType ?? throw new Exception("Unable to determine property type"); } + /// public override CodeExpression GetRhs() { var instance = this.GetValue(); diff --git a/src/ToCode/Property.cs b/src/ToCode/Property.cs index 4df3c3a1..97c04e52 100644 --- a/src/ToCode/Property.cs +++ b/src/ToCode/Property.cs @@ -108,13 +108,13 @@ public virtual void SetValue(object? value) case Orientation.Horizontal: v.Width = v.Height; v.Height = 1; - v.LineRune = ConfigurationManager.Glyphs.HLine; + v.LineRune = Glyphs.HLine; break; case Orientation.Vertical: v.Height = v.Width; v.Width = 1; - v.LineRune = ConfigurationManager.Glyphs.VLine; + v.LineRune = Glyphs.VLine; break; default: throw new ArgumentException($"Unknown Orientation {newOrientation}"); @@ -310,9 +310,9 @@ private CodeExpression ValueFactory(object val) if (type.GetGenericTypeDefinition() == typeof(SliderOption<>)) { // TODO: this feels very brittle! - var a1 = type.GetProperty(nameof(SliderOption.Legend)).GetValue(val); - var a2 = (Rune)type.GetProperty(nameof(SliderOption.LegendAbbr)).GetValue(val); - var a3 = type.GetProperty(nameof(SliderOption.Data)).GetValue(val); + var a1 = type.GetPropertyOrThrow(nameof(SliderOption.Legend)).GetValue(val); + var a2 = (Rune)type.GetPropertyOrThrow(nameof(SliderOption.LegendAbbr)).GetValue(val)!; + var a3 = type.GetPropertyOrThrow(nameof(SliderOption.Data)).GetValue(val); return new CodeObjectCreateExpression( @@ -476,6 +476,6 @@ private void CallRefreshMethodsIfAny() cp.ApplyStyleChanges(); } - this.Design.View.SetNeedsDisplay(); + this.Design.View.SetNeedsDraw(); } } \ No newline at end of file diff --git a/src/ToCode/StatusBarItemsToCode.cs b/src/ToCode/StatusBarItemsToCode.cs index 750b3de5..2103d2ed 100644 --- a/src/ToCode/StatusBarItemsToCode.cs +++ b/src/ToCode/StatusBarItemsToCode.cs @@ -4,7 +4,7 @@ namespace TerminalGuiDesigner.ToCode; /// -/// Handles generating all that are stored a the . +/// Handles generating all that are stored a the . /// public class StatusBarItemsToCode : ToCodeBase { @@ -28,7 +28,7 @@ public StatusBarItemsToCode(Design design) } /// - /// Adds code to .Designer.cs to construct and initialize all + /// Adds code to .Designer.cs to construct and initialize all /// in the . /// /// State object for the .Designer.cs file being generated. diff --git a/src/ToCode/ViewToCode.cs b/src/ToCode/ViewToCode.cs index 961ac05e..c6f5c3cb 100644 --- a/src/ToCode/ViewToCode.cs +++ b/src/ToCode/ViewToCode.cs @@ -206,7 +206,7 @@ public void GenerateDesignerCs(Design rootDesign, Type viewType) public void AddSubViewsToDesignerCs(View forView, CodeDomArgs args, CodeExpression? parentViewExpression = null) { // order the controls top left to lower right so that tab order is good - foreach (var sub in ViewExtensions.OrderViewsByScreenPosition(forView.Subviews)) + foreach (var sub in ViewExtensions.OrderViewsByScreenPosition(forView.SubViews)) { // If the sub child has a Design (and is not an public part of another control, // For example ContentView sub-view of Window diff --git a/src/TypeExtensions.cs b/src/TypeExtensions.cs index 53f0bb40..e918741f 100644 --- a/src/TypeExtensions.cs +++ b/src/TypeExtensions.cs @@ -1,5 +1,7 @@ using System; using System.Collections; +using System.Reflection; +using Terminal.Gui; namespace TerminalGuiDesigner { @@ -47,5 +49,18 @@ public static bool IsGenericType(this Type type, Type genericParentHypothesis) { return type.IsGenericType && type.GetGenericTypeDefinition() == genericParentHypothesis; } + + /// + /// Returns the of the given + /// or throws an . + /// + /// + /// + /// + /// + public static PropertyInfo GetPropertyOrThrow(this Type type, string name) + { + return type.GetProperty(name) ?? throw new Exception($"Could not find expected property {name} on type {type}"); + } } } diff --git a/src/UI/ColorSchemeBlueprint.cs b/src/UI/ColorSchemeBlueprint.cs index 85e0760b..cd4fd89e 100644 --- a/src/UI/ColorSchemeBlueprint.cs +++ b/src/UI/ColorSchemeBlueprint.cs @@ -10,69 +10,57 @@ namespace TerminalGuiDesigner.UI; /// Serializable version of . /// [YamlSerializable] -public record ColorSchemeBlueprint( ColorName NormalForeground, ColorName NormalBackground, ColorName HotNormalForeground, ColorName HotNormalBackground, ColorName FocusForeground, ColorName FocusBackground, ColorName HotFocusForeground, ColorName HotFocusBackground, ColorName DisabledForeground, ColorName DisabledBackground ) +public record ColorSchemeBlueprint( Color NormalForeground, Color NormalBackground, Color HotNormalForeground, Color HotNormalBackground, Color FocusForeground, Color FocusBackground, Color HotFocusForeground, Color HotFocusBackground, Color DisabledForeground, Color DisabledBackground ) { /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName NormalForeground { get; init; } = NormalForeground; + public Color NormalForeground { get; init; } = NormalForeground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName NormalBackground { get; init; } = NormalBackground; + public Color NormalBackground { get; init; } = NormalBackground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName HotNormalForeground { get; init; } = HotNormalForeground; + public Color HotNormalForeground { get; init; } = HotNormalForeground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName HotNormalBackground { get; init; } = HotNormalBackground; + public Color HotNormalBackground { get; init; } = HotNormalBackground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName FocusForeground { get; init; } = FocusForeground; + public Color FocusForeground { get; init; } = FocusForeground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName FocusBackground { get; init; } = FocusBackground; + public Color FocusBackground { get; init; } = FocusBackground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName HotFocusForeground { get; init; } = HotFocusForeground; + public Color HotFocusForeground { get; init; } = HotFocusForeground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - public ColorName HotFocusBackground { get; init; } = HotFocusBackground; + public Color HotFocusBackground { get; init; } = HotFocusBackground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - [YamlMember( typeof(ColorName), ScalarStyle = ScalarStyle.Plain, DefaultValuesHandling = DefaultValuesHandling.Preserve)] - public ColorName DisabledForeground { get; init; } = DisabledForeground; + public Color DisabledForeground { get; init; } = DisabledForeground; /// /// Gets the to use for . /// - [JsonConverter(typeof(JsonStringEnumConverter ))] - [YamlMember( typeof(ColorName), ScalarStyle = ScalarStyle.Plain, DefaultValuesHandling = DefaultValuesHandling.Preserve)] - public ColorName DisabledBackground { get; init; } = DisabledBackground; + public Color DisabledBackground { get; init; } = DisabledBackground; /// /// Gets a new from the blueprint. diff --git a/src/UI/Editor.cs b/src/UI/Editor.cs index 4f0b63b1..de16a5a5 100644 --- a/src/UI/Editor.cs +++ b/src/UI/Editor.cs @@ -2,12 +2,15 @@ using System.Reflection; using System.Text; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using Serilog; using Terminal.Gui; using TerminalGuiDesigner.FromCode; using TerminalGuiDesigner.Operations; using TerminalGuiDesigner.ToCode; using TerminalGuiDesigner.UI.Windows; using Attribute = Terminal.Gui.Attribute; +using ILogger = Microsoft.Extensions.Logging.ILogger; namespace TerminalGuiDesigner.UI; @@ -43,6 +46,13 @@ public class Editor : Toplevel /// internal Guid? LastSavedOperation; + private static string _logDirectory = string.Empty; + + /// + /// True to disable logging (must be set before constructing ). + /// + public static bool Quiet = false; + /// /// Initializes a new instance of the class. /// @@ -51,6 +61,11 @@ public Editor() // Bug: This will have strange inheritance behavior if Editor is inherited from. this.CanFocus = true; + if (!Quiet) + { + Logging.Logger = CreateLogger(); + } + try { this.keyMap = new ConfigurationBuilder( ).AddYamlFile( "Keys.yaml", true ).Build( ).Get( ) ?? new( ); @@ -71,10 +86,34 @@ public Editor() this.BuildRootMenu(); } + static ILogger CreateLogger() + { + _logDirectory = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "TerminalGuiDesigner", "logs"); + + // Configure Serilog to write logs to a file + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Verbose() // Verbose includes Trace and Debug + .WriteTo.File(Path.Combine(_logDirectory,"logfile.txt"), rollingInterval: RollingInterval.Day) + .CreateLogger(); + + // Create a logger factory compatible with Microsoft.Extensions.Logging + using var loggerFactory = LoggerFactory.Create(builder => + { + builder + .AddSerilog(dispose: true) // Integrate Serilog with ILogger + .SetMinimumLevel(LogLevel.Trace); // Set minimum log level + }); + + // Get an ILogger instance + return loggerFactory.CreateLogger("Global Logger"); + } + /// /// Gets or Sets a value indicating whether that do not have borders - /// (e.g. ) should have a dotted line rendered around them so - /// users don't lose track of where they are on a same-colored background. + /// should have a dotted line rendered around them so users don't lose track of where + /// they are on a same-colored background. /// // BUG: Thread-safety public static bool ShowBorders { get; set; } = true; @@ -193,58 +232,79 @@ public void Run(Options options) /// /// Tailors redrawing to add overlays (e.g. showing what is selected etc.). + /// Only runs when a view is open and . /// - /// The view bounds. - public override void OnDrawContent(Rectangle bounds) + protected override void OnDrawComplete(DrawContext? context) { - base.OnDrawContent(bounds); + base.OnDrawComplete(context); - // if we are editing a view - if (this.viewBeingEdited != null) + // if we are not editing a view + if (this.viewBeingEdited == null) { - if (this.enableShowFocused) - { - Application.Driver.SetAttribute(this.viewBeingEdited.View.ColorScheme.Normal); + return; + } - string? toDisplay = this.GetLowerRightTextIfAny(); + var bounds = Viewport; - // and have a designable view focused - if (toDisplay != null) - { - // write its name in the lower right - int y = this.GetContentSize().Height - 1; - int right = bounds.Width - 1; - var len = toDisplay.Length; + if (this.enableShowFocused) + { + Application.Driver.SetAttribute(this.viewBeingEdited.View.ColorScheme.Normal); - for (int i = 0; i < len; i++) - { - this.AddRune(right - len + i, y, new Rune(toDisplay[i])); - } + string? toDisplay = this.GetLowerRightTextIfAny(); + + // and have a designable view focused + if (toDisplay != null) + { + // write its name in the lower right + int y = this.GetContentSize().Height - 1; + int right = bounds.Width - 1; + var runes = toDisplay.EnumerateRunes().ToList(); + var len = runes.Count(); + + for (int i = 0; i < len; i++) + { + this.AddRune(right - len + i, y, runes[i]); } } + } - if (this.mouseManager.SelectionBox != null) + if (this.mouseManager.SelectionBox != null) + { + var box = this.mouseManager.SelectionBox.Value; + for (int x = 0; x < box.Width; x++) { - var box = this.mouseManager.SelectionBox.Value; - for (int x = 0; x < box.Width; x++) + for (int y = 0; y < box.Height; y++) { - for (int y = 0; y < box.Height; y++) + if (y == 0 || y == box.Height - 1 || x == 0 || x == box.Width - 1) { - if (y == 0 || y == box.Height - 1 || x == 0 || x == box.Width - 1) - { - this.AddRune(box.X + x, box.Y + y, new Rune('.')); - } + this.AddRune(box.X + x, box.Y + y, new Rune('.')); } } } - - return; } - else + } + + /// + /// Draws title screen when no view is currently open + /// + protected override bool OnDrawingContent() + { + var r = base.OnDrawingContent(); + + if (viewBeingEdited != null) { - var top = new Rectangle(0, 0, bounds.Width, rootCommandsListView.Frame.Top - 1); - RenderTitle(top); + return true; } + + var bounds = Viewport; + + Application.Driver.SetAttribute(new Attribute(Color.Black)); + Application.Driver.FillRect(bounds,' '); + + var top = new Rectangle(0, 0, bounds.Width, rootCommandsListView.Frame.Top - 1); + RenderTitle(top); + + return r; } private void RenderTitle(Rectangle inArea) @@ -280,6 +340,7 @@ ________ .__ ________ .__ // The version information line string versionLine = $"(Alpha - {informationalVersion} )"; + string logLine = "Logs - " + _logDirectory; // Split the ASCII art into lines var artLines = artText.Split('\n'); @@ -321,7 +382,7 @@ ________ .__ ________ .__ int y = inArea.Y + inArea.Height / 2 - 1; // Center the title vertically var colorAtPoint = fill.GetColor(new Point(x, y)); - Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black))); + Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(Color.Black))); this.AddRune(x, y, (Rune)simpleTitle[i]); } @@ -332,7 +393,7 @@ ________ .__ ________ .__ int y = inArea.Y + inArea.Height / 2; // Line below the title var colorAtPoint = fill.GetColor(new Point(x, y)); - Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black))); + Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(Color.Black))); this.AddRune(x, y, (Rune)versionLine[i]); } } @@ -369,7 +430,7 @@ ________ .__ ________ .__ int y = artStartY + i; var colorAtPoint = fill.GetColor(new Point(x, y)); - Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black))); + Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(Color.Black))); this.AddRune(x, y, (Rune)line[j]); } } @@ -384,9 +445,28 @@ ________ .__ ________ .__ int y = versionLineY; var colorAtPoint = fill.GetColor(new Point(x, y)); - Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(ColorName.Black))); + Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(Color.Black))); this.AddRune(x, y, (Rune)versionLine[i]); } + + if (Quiet) + { + return; + } + + // Render the log directory line below the version line + int logLineX = inArea.X + (inArea.Width - logLine.Length) / 2; + int logLineY = versionLineY+2; + + for (int i = 0; i < logLine.Length; i++) + { + int x = logLineX + i; + int y = logLineY; + + var colorAtPoint = fill.GetColor(new Point(x, y)); + Driver.SetAttribute(new Attribute(new Color(colorAtPoint), new Color(Color.Black))); + this.AddRune(x, y, (Rune)logLine[i]); + } } } @@ -530,14 +610,14 @@ public bool HandleKey(Key key) if (keyString == this.keyMap.ToggleShowFocused) { this.enableShowFocused = !this.enableShowFocused; - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } if (keyString == this.keyMap.ToggleShowBorders) { ShowBorders = !ShowBorders; - this.SetNeedsDisplay(); + this.SetNeedsDraw(); return true; } @@ -644,6 +724,7 @@ public bool HasUnsavedChanges } } + private string GetHelpWithEmptyFormLoaded() { return $"{this.keyMap.AddView} to Add a View"; @@ -782,7 +863,7 @@ private void Editor_Closing(object? sender, ToplevelClosingEventArgs obj) } } - private void CreateAndShowContextMenu(MouseEvent? m, Design? rightClicked) + private void CreateAndShowContextMenu(MouseEventArgs? m, Design? rightClicked) { if (this.viewBeingEdited == null) { @@ -850,7 +931,7 @@ private void CreateAndShowContextMenu(MouseEvent? m, Design? rightClicked) } var menu = new ContextMenu(); - menu.MenuItems = new MenuBarItem(all.ToArray()); + menu.SetMenuItems(new MenuBarItem(all.ToArray())); if (m != null) { @@ -871,7 +952,8 @@ private void CreateAndShowContextMenu(MouseEvent? m, Design? rightClicked) m.Handled = true; } - menu.Show(); + // TODO: rly? you have to pass it its own menu items!? + menu.Show(menu.MenuItems); menu.MenuBar.MenuAllClosed += (_, _) => { this.menuOpen = false; @@ -984,6 +1066,18 @@ private void ShowViewSpecificOperations() private void ShowHelp() { + if (menuOpen) + { + return; + } + var menuItem = MenuTracker.Instance.CurrentlyOpenMenuItem; + + // if we are in a menu + if (menuItem != null) + { + return; + } + ChoicesDialog.Query("Help", this.GetHelp(), "Ok"); } @@ -1043,7 +1137,9 @@ private void Open() { Title = "Open", AllowedTypes = new List(new[] { new AllowedType("View", SourceCodeFile.ExpectedExtension) }) - }; + }; + ofd.SetupNiceColorSchemes(); + ofd.Layout(); Application.Run(ofd, this.ErrorHandler); @@ -1124,6 +1220,8 @@ private void New() AllowedTypes = new List() { new AllowedType("C# File", ".cs") }, Path = "MyView.cs", }; + ofd.Layout(); + ofd.SetupNiceColorSchemes(); Application.Run(ofd); @@ -1287,7 +1385,7 @@ private void Save() this.viewBeingEdited.View.GetType().BaseType ?? throw new Exception("View being edited had no base class")); this.flashMessage = $"Saved {this.viewBeingEdited.SourceCode.DesignerFile.Name}"; - this.SetNeedsDisplay(); + this.SetNeedsDraw(); this.LastSavedOperation = OperationManager.Instance.GetLastAppliedOperation()?.UniqueIdentifier; } diff --git a/src/UI/KeyMap.cs b/src/UI/KeyMap.cs index a4e30d54..65958ffa 100644 --- a/src/UI/KeyMap.cs +++ b/src/UI/KeyMap.cs @@ -9,7 +9,7 @@ namespace TerminalGuiDesigner.UI; /// Serializable settings class for user keybinding/accessibility tailoring. -[JsonSourceGenerationOptions( JsonSerializerDefaults.General, Converters = new[] { typeof( JsonStringEnumConverter ), typeof( JsonStringEnumConverter ) } )] +[JsonSourceGenerationOptions( JsonSerializerDefaults.General, Converters = new[] { typeof( JsonStringEnumConverter ) } )] public sealed record KeyMap( string EditProperties, string ShowContextMenu, @@ -176,8 +176,7 @@ public KeyMap( ) public string ToggleDragging { get; init; } = ToggleDragging; /// - /// Gets the string to toggle showing dotted borders around views that otherwise do not have visible borders (e.g. - /// ). + /// Gets the string to toggle showing dotted borders around views that otherwise do not have visible borders. /// public string ToggleShowBorders { get; init; } = ToggleShowBorders; diff --git a/src/UI/KeyboardManager.cs b/src/UI/KeyboardManager.cs index da969137..058dfa32 100644 --- a/src/UI/KeyboardManager.cs +++ b/src/UI/KeyboardManager.cs @@ -30,7 +30,7 @@ public KeyboardManager(KeyMap keyMap) /// to the rest of the regular Terminal.Gui API layer. /// /// The that currently holds focus in . - /// The key that has been reported by . + /// The key that has been reported by . /// if should be suppressed. public bool HandleKey(View focusedView, Key keystroke) { @@ -111,7 +111,7 @@ private bool HandleKeyPressInMenu(View focusedView, MenuItem menuItem, Key keyst { menuItem.ShortcutKey = Modals.GetShortcut().KeyCode; - focusedView.SetNeedsDisplay(); + focusedView.SetNeedsDraw(); return false; } @@ -182,6 +182,16 @@ private bool HandleKeyPressInMenu(View focusedView, MenuItem menuItem, Key keyst } } + // When menu is being edited let user paste in text e.g. command names + if (keystroke == keyMap.Paste) + { + if (Clipboard.TryGetClipboardData(out string text) && IsValidSimpleStringToPaste(text)) + { + menuItem.Title += text; + return true; + } + } + // Allow typing but also Enter to create a new sub-item if ( !this.IsActionableKey( keystroke ) ) { @@ -209,7 +219,7 @@ private bool HandleKeyPressInMenu(View focusedView, MenuItem menuItem, Key keyst menuItem.Title = newValue; } - focusedView.SetNeedsDisplay(); + focusedView.SetNeedsDraw(); return true; } @@ -217,6 +227,26 @@ private bool HandleKeyPressInMenu(View focusedView, MenuItem menuItem, Key keyst return false; } + private bool IsValidSimpleStringToPaste(string result) + { + if (string.IsNullOrWhiteSpace(result)) + { + return false; + } + + if (result.Contains('\n') || result.Contains('\r')) + { + return false; + } + + if (result.Length > 100) + { + return false; + } + + return true; + } + private void ChangeKeyTo(Key keystroke, Key newKey) { Type t = typeof(Key); @@ -270,7 +300,7 @@ private bool ApplyKeystrokeToTextProperty(Key keystroke) } design.View.SetActualText(newStr); - design.View.SetNeedsDisplay(); + design.View.SetNeedsDraw(); this.currentOperation.NewValue = newStr; return true; diff --git a/src/UI/MouseManager.cs b/src/UI/MouseManager.cs index 0144ad58..86740eca 100644 --- a/src/UI/MouseManager.cs +++ b/src/UI/MouseManager.cs @@ -4,7 +4,7 @@ namespace TerminalGuiDesigner.UI; /// -/// Manages responding to e.g. by +/// Manages responding to root mouse e.g. by /// dragging around and/or resizing. /// public class MouseManager @@ -31,12 +31,12 @@ public class MouseManager public Rectangle? SelectionBox => RectExtensions.FromBetweenPoints(this.selectionStart, this.selectionEnd); /// - /// Responds to (by changing a 'drag a box' selection area + /// Responds to (by changing a 'drag a box' selection area /// or starting a resize etc). /// - /// The reported by . + /// The reported by . /// The root that is open in the . - public void HandleMouse(MouseEvent m, Design viewBeingEdited) + public void HandleMouse(MouseEventArgs m, Design viewBeingEdited) { // start dragging if (m.Flags.HasFlag(MouseFlags.Button1Pressed) @@ -122,10 +122,7 @@ public void HandleMouse(MouseEvent m, Design viewBeingEdited) { // move selection box to new mouse position this.selectionEnd = m.Position; - viewBeingEdited.View.SetNeedsDisplay(); - - // BUG: Method is gone, will this functionality work still without it? - // Application.DoEvents(); + viewBeingEdited.View.SetNeedsDraw(); return; } @@ -137,7 +134,7 @@ public void HandleMouse(MouseEvent m, Design viewBeingEdited) if (dest != null && this.dragOperation != null) { this.dragOperation.ContinueDrag(dest.Value); - viewBeingEdited.View.SetNeedsDisplay(); + viewBeingEdited.View.SetNeedsDraw(); // BUG: Method is gone, will this functionality work still without it? // Application.DoEvents(); } @@ -152,7 +149,7 @@ public void HandleMouse(MouseEvent m, Design viewBeingEdited) this.resizeOperation.ContinueResize(dest); - viewBeingEdited.View.SetNeedsDisplay(); + viewBeingEdited.View.SetNeedsDraw(); // BUG: Method is gone, will this functionality work still without it? // Application.DoEvents(); } @@ -174,7 +171,7 @@ public void HandleMouse(MouseEvent m, Design viewBeingEdited) this.selectionStart = null; this.selectionEnd = null; this.selectionContainer = null; - viewBeingEdited.View.SetNeedsDisplay(); + viewBeingEdited.View.SetNeedsDraw(); // BUG: Method is gone, will this functionality work still without it? // Application.DoEvents(); } diff --git a/src/UI/ValueFactory.cs b/src/UI/ValueFactory.cs index 8f38fbdd..ce9daa9f 100644 --- a/src/UI/ValueFactory.cs +++ b/src/UI/ValueFactory.cs @@ -191,7 +191,9 @@ internal static bool GetNewValue(string propertyName, Design design, Type type, if (type == typeof(FileSystemInfo)) { var fd = new FileDialog(); + fd.SetupNiceColorSchemes(); fd.AllowsMultipleSelection = false; + fd.Layout(); int answer = ChoicesDialog.Query(propertyName, $"Directory or File?", "Directory", "File", "Cancel"); @@ -246,7 +248,8 @@ internal static bool GetNewValue(Design design, Property property, object? oldVa if (Modals.Get( property.PropertyInfo.Name, "New Value", - typeof(Label).Assembly.GetTypes().Where(inst.MustBeDerrivedFrom.IsAssignableFrom).ToArray(), + typeof(Label).Assembly.GetTypes() + .Where(t=>inst.MustBeDerivedFrom.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface).ToArray(), inst.GetValue()?.GetType(), out Type? typeChosen)) { @@ -305,7 +308,7 @@ private static bool GetNewColorSchemeValue(Design design, out object? newValue) // add the option to jump to custom colors offer.Add(custom); - if (Modals.Get("Color Scheme", "Ok", offer.ToArray(), design.View.ColorScheme, out var selected)) + if (Modals.Get("Color Scheme", "Ok", offer.ToArray(), design.View.ColorScheme, out var selected,false)) { // if user clicked "Custom..." if (selected is string s && string.Equals(s, custom)) diff --git a/src/UI/Windows/ArrayEditor.Designer.cs b/src/UI/Windows/ArrayEditor.Designer.cs index 7a388dbc..0d82ce29 100644 --- a/src/UI/Windows/ArrayEditor.Designer.cs +++ b/src/UI/Windows/ArrayEditor.Designer.cs @@ -3,23 +3,26 @@ // // This code was generated by: -// TerminalGuiDesigner v1.1.0.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- - -using System.Collections.ObjectModel; - namespace TerminalGuiDesigner.UI.Windows { using System; using Terminal.Gui; using System.Collections; using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; public partial class ArrayEditor : Terminal.Gui.Dialog { + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + private Terminal.Gui.FrameView frameView; private Terminal.Gui.ListView lvElements; @@ -51,19 +54,28 @@ private void InitializeComponent() { this.btnAddElement = new Terminal.Gui.Button(); this.lvElements = new Terminal.Gui.ListView(); this.frameView = new Terminal.Gui.FrameView(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); this.Width = Dim.Percent(85); this.Height = Dim.Percent(85); this.X = Pos.Center(); this.Y = Pos.Center(); this.Visible = true; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; this.Modal = true; this.TextAlignment = Terminal.Gui.Alignment.Start; this.Title = "Array Editor"; this.frameView.Width = Dim.Fill(0); - this.frameView.Height = Dim.Fill(3); + this.frameView.Height = Dim.Fill(5); this.frameView.X = 0; this.frameView.Y = 0; this.frameView.Visible = true; + this.frameView.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.frameView.CanFocus = true; + this.frameView.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.frameView.Data = "frameView"; this.frameView.TextAlignment = Terminal.Gui.Alignment.Start; this.frameView.Title = "Elements"; @@ -73,60 +85,83 @@ private void InitializeComponent() { this.lvElements.X = 1; this.lvElements.Y = 0; this.lvElements.Visible = true; + this.lvElements.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lvElements.CanFocus = true; + this.lvElements.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lvElements.Data = "lvElements"; this.lvElements.TextAlignment = Terminal.Gui.Alignment.Start; - this.lvElements.Source = new Terminal.Gui.ListWrapper(new ObservableCollection(new string[] { - "Item1", - "Item2", - "Item3"})); + this.lvElements.Source = new Terminal.Gui.ListWrapper(new System.Collections.ObjectModel.ObservableCollection(new string[] { + "Item1", + "Item2", + "Item3"})); this.lvElements.AllowsMarking = false; this.lvElements.AllowsMultipleSelection = true; this.frameView.Add(this.lvElements); - this.btnAddElement.Width = 8; - this.btnAddElement.Height = 1; + this.btnAddElement.Width = Dim.Auto(); + this.btnAddElement.Height = Dim.Auto(); this.btnAddElement.X = 1; - this.btnAddElement.Y = Pos.AnchorEnd(3); + this.btnAddElement.Y = Pos.AnchorEnd(5); this.btnAddElement.Visible = true; + this.btnAddElement.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnAddElement.ColorScheme = this.buttons; + this.btnAddElement.CanFocus = true; + this.btnAddElement.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnAddElement.Data = "btnAddElement"; this.btnAddElement.Text = "Add"; this.btnAddElement.TextAlignment = Terminal.Gui.Alignment.Center; this.btnAddElement.IsDefault = false; this.Add(this.btnAddElement); - this.btnDelete.Width = 8; - this.btnDelete.Height = 1; + this.btnDelete.Width = Dim.Auto(); + this.btnDelete.Height = Dim.Auto(); this.btnDelete.X = 9; - this.btnDelete.Y = Pos.AnchorEnd(3); + this.btnDelete.Y = Pos.AnchorEnd(5); this.btnDelete.Visible = true; + this.btnDelete.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnDelete.ColorScheme = this.buttons; + this.btnDelete.CanFocus = true; + this.btnDelete.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnDelete.Data = "btnDelete"; this.btnDelete.Text = "Delete"; this.btnDelete.TextAlignment = Terminal.Gui.Alignment.Center; this.btnDelete.IsDefault = false; this.Add(this.btnDelete); - this.btnMoveUp.Width = 8; - this.btnMoveUp.Height = 1; - this.btnMoveUp.X = 20; - this.btnMoveUp.Y = Pos.AnchorEnd(3); + this.btnMoveUp.Width = Dim.Auto(); + this.btnMoveUp.Height = Dim.Auto(); + this.btnMoveUp.X = 22; + this.btnMoveUp.Y = Pos.AnchorEnd(5); this.btnMoveUp.Visible = true; + this.btnMoveUp.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnMoveUp.ColorScheme = this.buttons; + this.btnMoveUp.CanFocus = true; + this.btnMoveUp.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnMoveUp.Data = "btnMoveUp"; this.btnMoveUp.Text = "Move Up"; this.btnMoveUp.TextAlignment = Terminal.Gui.Alignment.Center; this.btnMoveUp.IsDefault = false; this.Add(this.btnMoveUp); - this.btnMoveDown.Width = 8; - this.btnMoveDown.Height = 1; - this.btnMoveDown.X = 32; - this.btnMoveDown.Y = Pos.AnchorEnd(3); + this.btnMoveDown.Width = Dim.Auto(); + this.btnMoveDown.Height = Dim.Auto(); + this.btnMoveDown.X = 34; + this.btnMoveDown.Y = Pos.AnchorEnd(5); this.btnMoveDown.Visible = true; + this.btnMoveDown.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnMoveDown.ColorScheme = this.buttons; + this.btnMoveDown.CanFocus = true; + this.btnMoveDown.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnMoveDown.Data = "btnMoveDown"; this.btnMoveDown.Text = "Move Down"; this.btnMoveDown.TextAlignment = Terminal.Gui.Alignment.Center; this.btnMoveDown.IsDefault = false; this.Add(this.btnMoveDown); - this.btnEdit.Width = 8; - this.btnEdit.Height = 1; - this.btnEdit.X = 46; - this.btnEdit.Y = Pos.AnchorEnd(3); + this.btnEdit.Width = Dim.Auto(); + this.btnEdit.Height = Dim.Auto(); + this.btnEdit.X = 48; + this.btnEdit.Y = Pos.AnchorEnd(5); this.btnEdit.Visible = true; + this.btnEdit.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEdit.ColorScheme = this.buttons; + this.btnEdit.CanFocus = true; + this.btnEdit.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnEdit.Data = "btnEdit"; this.btnEdit.Text = "Edit"; this.btnEdit.TextAlignment = Terminal.Gui.Alignment.Center; @@ -135,28 +170,39 @@ private void InitializeComponent() { this.lineView.Width = Dim.Fill(1); this.lineView.Height = 1; this.lineView.X = -1; - this.lineView.Y = Pos.AnchorEnd(2); + this.lineView.Y = Pos.AnchorEnd(3); this.lineView.Visible = true; + this.lineView.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lineView.CanFocus = true; + this.lineView.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lineView.Data = "lineView"; this.lineView.TextAlignment = Terminal.Gui.Alignment.Start; this.lineView.LineRune = new System.Text.Rune('─'); this.lineView.Orientation = Terminal.Gui.Orientation.Horizontal; this.Add(this.lineView); - this.btnOk.Width = 8; - this.btnOk.Height = 1; + this.btnOk.Width = Dim.Auto(); + this.btnOk.Height = Dim.Auto(); this.btnOk.X = 0; - this.btnOk.Y = Pos.AnchorEnd(1); + this.btnOk.Y = Pos.AnchorEnd(2); this.btnOk.Visible = true; + this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnOk.Data = "btnOk"; this.btnOk.Text = "Ok"; this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; this.btnOk.IsDefault = false; this.Add(this.btnOk); - this.btnCancel.Width = 8; - this.btnCancel.Height = 1; - this.btnCancel.X = 9; - this.btnCancel.Y = Pos.AnchorEnd(1); + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 7; + this.btnCancel.Y = Pos.AnchorEnd(2); this.btnCancel.Visible = true; + this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnCancel.Data = "btnCancel"; this.btnCancel.Text = "Cancel"; this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; diff --git a/src/UI/Windows/ArrayEditor.cs b/src/UI/Windows/ArrayEditor.cs index 15f820ba..f0945e9e 100644 --- a/src/UI/Windows/ArrayEditor.cs +++ b/src/UI/Windows/ArrayEditor.cs @@ -16,6 +16,9 @@ namespace TerminalGuiDesigner.UI.Windows { using Terminal.Gui; using TerminalGuiDesigner.ToCode; + /// + /// UI for configuring array elements + /// public partial class ArrayEditor : IValueGetterDialog { /// @@ -29,8 +32,11 @@ public partial class ArrayEditor : IValueGetterDialog { /// /// The new array /// - [CanBeNull] public object Result => ResultAsList; + + /// + /// Returns the being designed as an + /// public IList ResultAsList { get; private set; } @@ -56,17 +62,17 @@ public ArrayEditor(Design design, Type elementType, IList oldValue) { lvElements.Source = ResultAsList.ToListDataSource(); lvElements.KeyDown += LvElements_KeyDown; - btnOk.Accept += BtnOk_Clicked; - btnCancel.Accept += BtnCancel_Clicked; - btnAddElement.Accept += BtnAddElement_Clicked; - btnDelete.Accept += (s, e) => DeleteSelectedItem(); - btnMoveDown.Accept += BtnMoveDown_Clicked; - btnMoveUp.Accept += BtnMoveUp_Clicked; - btnEdit.Accept += BtnEdit_Clicked; + btnOk.Accepting += BtnOk_Clicked; + btnCancel.Accepting += BtnCancel_Clicked; + btnAddElement.Accepting += BtnAddElement_Clicked; + btnDelete.Accepting += (s, e) => DeleteSelectedItem(); + btnMoveDown.Accepting += BtnMoveDown_Clicked; + btnMoveUp.Accepting += BtnMoveUp_Clicked; + btnEdit.Accepting += BtnEdit_Clicked; } - private void BtnMoveUp_Clicked(object sender, EventArgs e) + private void BtnMoveUp_Clicked(object sender, CommandEventArgs e) { // Moving up means reducing the index by 1 var idx = lvElements.SelectedItem; @@ -80,11 +86,13 @@ private void BtnMoveUp_Clicked(object sender, EventArgs e) lvElements.Source = ResultAsList.ToListDataSource(); lvElements.SelectedItem = newIndex; - lvElements.SetNeedsDisplay(); + lvElements.SetNeedsDraw(); } + + e.Cancel = true; } - private void BtnMoveDown_Clicked(object sender, EventArgs e) + private void BtnMoveDown_Clicked(object sender, CommandEventArgs e) { // Moving up means increasing the index by 1 var idx = lvElements.SelectedItem; @@ -98,8 +106,10 @@ private void BtnMoveDown_Clicked(object sender, EventArgs e) lvElements.Source = ResultAsList.ToListDataSource(); lvElements.SelectedItem = newIndex; - lvElements.SetNeedsDisplay(); + lvElements.SetNeedsDraw(); } + + e.Cancel = true; } private void LvElements_KeyDown(object sender, Key e) @@ -120,12 +130,12 @@ private void DeleteSelectedItem() ResultAsList.RemoveAt(idx); lvElements.Source = ResultAsList.ToListDataSource(); - lvElements.SetNeedsDisplay(); + lvElements.SetNeedsDraw(); lvElements.SelectedItem = 0; } } - private void BtnAddElement_Clicked(object sender, EventArgs e) + private void BtnAddElement_Clicked(object sender, CommandEventArgs e) { if(ValueFactory.GetNewValue("Element Value", design, this.elementType,null, out var newValue,true)) { @@ -134,9 +144,10 @@ private void BtnAddElement_Clicked(object sender, EventArgs e) lvElements.Source = ResultAsList.ToListDataSource(); lvElements.SelectedItem = ResultAsList.Count - 1; - lvElements.SetNeedsDisplay(); + lvElements.SetNeedsDraw(); + e.Cancel = true; } - private void BtnEdit_Clicked(object sender, EventArgs e) + private void BtnEdit_Clicked(object sender, CommandEventArgs e) { var idx = lvElements.SelectedItem; @@ -153,18 +164,22 @@ private void BtnEdit_Clicked(object sender, EventArgs e) lvElements.Source = ResultAsList.ToListDataSource(); lvElements.SelectedItem = idx; - lvElements.SetNeedsDisplay(); + lvElements.SetNeedsDraw(); } + + e.Cancel = true; } - private void BtnCancel_Clicked(object sender, EventArgs e) + private void BtnCancel_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = true; Application.RequestStop(); } - private void BtnOk_Clicked(object sender, EventArgs e) + private void BtnOk_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = false; Application.RequestStop(); } diff --git a/src/UI/Windows/BigListBox.cs b/src/UI/Windows/BigListBox.cs index aabb9429..422a101c 100644 --- a/src/UI/Windows/BigListBox.cs +++ b/src/UI/Windows/BigListBox.cs @@ -47,17 +47,23 @@ public class BigListBox /// What to display in the list box (defaults to . /// Creates a selection option "Null" that returns a null selection. /// The optional existing value, if present it should be selected in the list. - public BigListBox( - string prompt, + /// + public BigListBox(string prompt, string okText, in bool addSearch, IList collection, Func displayMember, bool addNull, - T? currentSelection) + T? currentSelection, bool sort = true) { this.AspectGetter = displayMember ?? (arg => arg?.ToString() ?? string.Empty); + // Sort alphabetically according to display member + if (sort) + { + collection = collection.OrderBy(e => AspectGetter(e)).ToList(); + } + this.publicCollection = collection ?? throw new ArgumentNullException( nameof( collection ) ); this.addNull = addNull; @@ -82,15 +88,13 @@ public BigListBox( SelectedItem = 0 }; listView.SetSource(new ObservableCollection(ErrorStringArray)); - - this.listView.KeyDown += this.ListView_KeyPress; - + this.listView.MouseClick += this.ListView_MouseClick; this.collection = this.BuildList(this.GetInitialSource()).ToList(); this.listView.SetSource( - new ObservableCollection(this.collection.Select(o=>o.Object).ToArray()) + new ObservableCollection>(this.collection.ToArray()) ); this.win.Add(this.listView); @@ -100,8 +104,9 @@ public BigListBox( IsDefault = true, Y = Pos.Bottom(this.listView), }; - btnOk.Accept += (s, e) => + btnOk.Accepting += (s, e) => { + e.Cancel = true; this.Accept(); }; @@ -110,7 +115,11 @@ public BigListBox( Text = "Cancel", Y = Pos.Bottom(this.listView), }; - btnCancel.Accept += (s, e) => Application.RequestStop(); + btnCancel.Accepting += (s, e) => + { + e.Cancel = true; + Application.RequestStop(); + }; if (addSearch) { @@ -164,7 +173,7 @@ public BigListBox( this.callback = Application.AddTimeout(TimeSpan.FromMilliseconds(100), this.Timer); - this.listView.FocusFirst(TabBehavior.TabStop); + this.listView.FocusDeepest(NavigationDirection.Forward,TabBehavior.TabStop); } @@ -204,29 +213,15 @@ private void Accept() this.Selected = this.collection[selected].Object; } - private void ListView_MouseClick(object? sender, MouseEventEventArgs obj) + private void ListView_MouseClick(object? sender, MouseEventArgs obj) { - if (obj.MouseEvent.Flags.HasFlag(MouseFlags.Button1DoubleClicked)) + if (obj.Flags.HasFlag(MouseFlags.Button1DoubleClicked)) { obj.Handled = true; this.Accept(); } } - - private void ListView_KeyPress(object? sender, Key key) - { - // if user types in some text change the focus to the text box to enable searching - var c = (char)key; - - // backspace or letter/numbers - if (key == Key.Backspace || char.IsLetterOrDigit(c)) - { - this.searchBox?.FocusFirst(TabBehavior.TabStop); - this.searchBox?.NewKeyDownEvent(key); - key.Handled = true; - } - } - + private bool Timer() { if (this.changes && DateTime.Now.Subtract(this.lastKeypress) > TimeSpan.FromMilliseconds(100)) diff --git a/src/UI/Windows/ChoicesDialog.Designer.cs b/src/UI/Windows/ChoicesDialog.Designer.cs index ca55da23..337875cb 100644 --- a/src/UI/Windows/ChoicesDialog.Designer.cs +++ b/src/UI/Windows/ChoicesDialog.Designer.cs @@ -3,121 +3,139 @@ // // This code was generated by: -// TerminalGuiDesigner v1.0.18.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- -namespace TerminalGuiDesigner.UI.Windows; -using System; -using Terminal.Gui; - - -public partial class ChoicesDialog : Terminal.Gui.Window { - - private Terminal.Gui.ColorScheme dialogBackground; - - private Terminal.Gui.ColorScheme buttons; - - private Terminal.Gui.Label label1; +namespace TerminalGuiDesigner.UI.Windows { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.View buttonPanel; - private Terminal.Gui.Button btn1; - - private Terminal.Gui.Button btn2; - - private Terminal.Gui.Button btn3; - - private Terminal.Gui.Button btn4; - - private void InitializeComponent() { - this.btn4 = new Terminal.Gui.Button(); - this.btn3 = new Terminal.Gui.Button(); - this.btn2 = new Terminal.Gui.Button(); - this.btn1 = new Terminal.Gui.Button(); - this.buttonPanel = new Terminal.Gui.View(); - this.label1 = new Terminal.Gui.Label(); - this.dialogBackground = new Terminal.Gui.ColorScheme( - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Black), - new Terminal.Gui.Attribute(Terminal.Gui.Color.White, Terminal.Gui.Color.DarkGray) - ); - this.buttons = new Terminal.Gui.ColorScheme( - new Terminal.Gui.Attribute(Terminal.Gui.Color.DarkGray, Terminal.Gui.Color.White), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Red, Terminal.Gui.Color.Yellow), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.White), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Black), - new Terminal.Gui.Attribute(Terminal.Gui.Color.Black, Terminal.Gui.Color.Yellow) - ); - - this.Width = Dim.Percent(85); - this.Height = Dim.Percent(85); - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.ColorScheme = this.dialogBackground; - this.Modal = true; - this.Text = ""; - this.Border.BorderStyle = Terminal.Gui.LineStyle.Double; - this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = ""; - this.label1.Width = Dim.Fill(0); - this.label1.Height = Dim.Fill(0); - this.label1.X = 0; - this.label1.Y = 1; - this.label1.Data = "label1"; - this.label1.Text = "lblMessage"; - this.label1.TextAlignment = Terminal.Gui.Alignment.Center; - this.Add(this.label1); - this.buttonPanel.Width = 50; - this.buttonPanel.Height = 2; - this.buttonPanel.X = Pos.Center(); - this.buttonPanel.Y = Pos.AnchorEnd(2); - this.buttonPanel.Data = "buttonPanel"; - this.buttonPanel.Text = ""; - this.buttonPanel.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.buttonPanel); - this.btn1.Width = 10; - this.btn1.Height = 2; - this.btn1.X = 0; - this.btn1.Y = Pos.AnchorEnd(2); - this.btn1.ColorScheme = this.buttons; - this.btn1.Data = "btn1"; - this.btn1.Text = "btn1"; - this.btn1.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn1.IsDefault = true; - this.buttonPanel.Add(this.btn1); - this.btn2.Width = 9; - this.btn2.Height = 2; - this.btn2.X = Pos.Right(btn1) + 1; - this.btn2.Y = Pos.AnchorEnd(2); - this.btn2.ColorScheme = this.buttons; - this.btn2.Data = "btn2"; - this.btn2.Text = "btn2"; - this.btn2.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn2.IsDefault = false; - this.buttonPanel.Add(this.btn2); - this.btn3.Width = 8; - this.btn3.Height = 2; - this.btn3.X = Pos.Right(btn2) + 1; - this.btn3.Y = Pos.AnchorEnd(2); - this.btn3.ColorScheme = this.buttons; - this.btn3.Data = "btn3"; - this.btn3.Text = "btn3"; - this.btn3.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn3.IsDefault = false; - this.buttonPanel.Add(this.btn3); - this.btn4.Width = 8; - this.btn4.Height = 2; - this.btn4.X = Pos.Right(btn3) + 1; - this.btn4.Y = Pos.AnchorEnd(2); - this.btn4.ColorScheme = this.buttons; - this.btn4.Data = "btn4"; - this.btn4.Text = "btn4"; - this.btn4.TextAlignment = Terminal.Gui.Alignment.Center; - this.btn4.IsDefault = false; - this.buttonPanel.Add(this.btn4); + public partial class ChoicesDialog : Terminal.Gui.Window { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.Label label1; + + private Terminal.Gui.View buttonPanel; + + private Terminal.Gui.Button btn1; + + private Terminal.Gui.Button btn2; + + private Terminal.Gui.Button btn3; + + private Terminal.Gui.Button btn4; + + private void InitializeComponent() { + this.btn4 = new Terminal.Gui.Button(); + this.btn3 = new Terminal.Gui.Button(); + this.btn2 = new Terminal.Gui.Button(); + this.btn1 = new Terminal.Gui.Button(); + this.buttonPanel = new Terminal.Gui.View(); + this.label1 = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = Dim.Percent(85); + this.Height = Dim.Percent(85); + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = ((Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Resizable) + | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = ""; + this.label1.Width = Dim.Fill(0); + this.label1.Height = Dim.Fill(0); + this.label1.X = 0; + this.label1.Y = 1; + this.label1.Visible = true; + this.label1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label1.CanFocus = true; + this.label1.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label1.Data = "label1"; + this.label1.Text = "lblMessage"; + this.label1.TextAlignment = Terminal.Gui.Alignment.Center; + this.Add(this.label1); + this.buttonPanel.Width = 50; + this.buttonPanel.Height = 2; + this.buttonPanel.X = Pos.Center(); + this.buttonPanel.Y = Pos.AnchorEnd(2); + this.buttonPanel.Visible = true; + this.buttonPanel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.buttonPanel.CanFocus = true; + this.buttonPanel.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.buttonPanel.Data = "buttonPanel"; + this.buttonPanel.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.buttonPanel); + this.btn1.Width = Dim.Auto(); + this.btn1.Height = 2; + this.btn1.X = 0; + this.btn1.Y = Pos.AnchorEnd(2); + this.btn1.Visible = true; + this.btn1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn1.ColorScheme = this.buttons; + this.btn1.CanFocus = true; + this.btn1.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn1.Data = "btn1"; + this.btn1.Text = "btn1"; + this.btn1.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn1.IsDefault = true; + this.buttonPanel.Add(this.btn1); + this.btn2.Width = Dim.Auto(); + this.btn2.Height = 2; + this.btn2.X = Pos.Right(btn1) + 1; + this.btn2.Y = Pos.AnchorEnd(2); + this.btn2.Visible = true; + this.btn2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn2.ColorScheme = this.buttons; + this.btn2.CanFocus = true; + this.btn2.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn2.Data = "btn2"; + this.btn2.Text = "btn2"; + this.btn2.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn2.IsDefault = false; + this.buttonPanel.Add(this.btn2); + this.btn3.Width = Dim.Auto(); + this.btn3.Height = 2; + this.btn3.X = Pos.Right(btn2) + 1; + this.btn3.Y = Pos.AnchorEnd(2); + this.btn3.Visible = true; + this.btn3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn3.ColorScheme = this.buttons; + this.btn3.CanFocus = true; + this.btn3.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn3.Data = "btn3"; + this.btn3.Text = "btn3"; + this.btn3.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn3.IsDefault = false; + this.buttonPanel.Add(this.btn3); + this.btn4.Width = Dim.Auto(); + this.btn4.Height = 2; + this.btn4.X = Pos.Right(btn3) + 1; + this.btn4.Y = Pos.AnchorEnd(2); + this.btn4.Visible = true; + this.btn4.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btn4.ColorScheme = this.buttons; + this.btn4.CanFocus = true; + this.btn4.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btn4.Data = "btn4"; + this.btn4.Text = "btn4"; + this.btn4.TextAlignment = Terminal.Gui.Alignment.Center; + this.btn4.IsDefault = false; + this.buttonPanel.Add(this.btn4); + } } } diff --git a/src/UI/Windows/ChoicesDialog.cs b/src/UI/Windows/ChoicesDialog.cs index d91eb39d..65a0cfaf 100644 --- a/src/UI/Windows/ChoicesDialog.cs +++ b/src/UI/Windows/ChoicesDialog.cs @@ -52,22 +52,19 @@ public ChoicesDialog(string title, string message, params string[] options) { { // add space for right hand side shadow buttons[i].Text = options[i] + " "; - - // TODO think it depends if it is default if we have to do this hack - buttons[i].Width = Dim.Auto(); - var i2 = i; - buttons[i].Accept += (s,e) => { + buttons[i].Accepting += (s,e) => { Result = i2; + e.Cancel = true; Application.RequestStop(); - }; - buttons[i].DrawContentComplete += (s,r) => - ChoicesDialog.PaintShadow(buttons[i2], ColorScheme); + }; } + buttonPanel.LayoutSubViews(); + // hide other buttons for(int i=options.Length;ibuttonPanel.Subviews.Contains(b) ? b.Frame.Width : 0) + 1; + buttonPanel.Width = buttonWidth = buttons.Sum(b=>buttonPanel.SubViews.Contains(b) ? b.Frame.Width : 0) + 1; int maxWidthLine = TextFormatter.GetSumMaxCharWidth(message); if (maxWidthLine > Application.Driver.Cols) @@ -97,34 +94,8 @@ public ChoicesDialog(string title, string message, params string[] options) { Width = Math.Min(Math.Max(maxWidthLine, Math.Max(Title.GetColumns(), Math.Max(textWidth + 2, buttonWidth))), Application.Driver.Cols); Height = msgboxHeight; - } - - /// - public override void OnDrawContentComplete(Rectangle bounds) - { - base.OnDrawContentComplete(bounds); - var screenTopLeft = FrameToScreen(); - Driver.Move(screenTopLeft.X+2, screenTopLeft.Y); - - var padding = ((bounds.Width - _title.EnumerateRunes().Sum(v=>v.GetColumns())) / 2) - 1; - - Driver.SetAttribute( - new Attribute(ColorScheme.Normal.Foreground, ColorScheme.Normal.Background)); - - Driver.AddStr(string.Join("",Enumerable.Repeat(ConfigurationManager.Glyphs.HLineHv, padding))); - - Driver.SetAttribute( - new Attribute(ColorScheme.Normal.Background, ColorScheme.Normal.Foreground)); - Driver.AddStr(_title); - - Driver.SetAttribute( - new Attribute(ColorScheme.Normal.Foreground, ColorScheme.Normal.Background)); - - StringBuilder sb = new StringBuilder(); - sb.Append(ConfigurationManager.Glyphs.HLineHv); - - Driver.AddStr(string.Join("", Enumerable.Repeat(ConfigurationManager.Glyphs.HLineHv.ToString(), padding))); + btn1.FocusDeepest(NavigationDirection.Forward, TabBehavior.TabGroup); } internal static int Query(string title, string message, params string[] options) @@ -133,50 +104,6 @@ internal static int Query(string title, string message, params string[] options) Application.Run(dlg); return dlg.Result; } - - internal static void PaintShadow(Button btn, ColorScheme backgroundScheme) - { - var bounds = btn.GetContentSize(); - - Attribute buttonColor = btn.HasFocus ? - new Terminal.Gui.Attribute(btn.ColorScheme.Focus.Foreground, btn.ColorScheme.Focus.Background): - new Terminal.Gui.Attribute(btn.ColorScheme.Normal.Foreground, btn.ColorScheme.Normal.Background); - - Driver.SetAttribute(buttonColor); - - if (btn.IsDefault) - { - var rightDefault = Driver != null ? ConfigurationManager.Glyphs.RightDefaultIndicator : new Rune('>'); - - // draw the 'end' button symbol one in - btn.AddRune(bounds.Width - 3, 0, rightDefault); - } - - btn.AddRune(bounds.Width - 2, 0, new System.Text.Rune(']')); - btn.AddRune(0, 0, new System.Text.Rune('[')); - - var backgroundColor = backgroundScheme.Normal.Background; - - // shadow color - Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor)); - - // end shadow (right) - btn.AddRune(bounds.Width - 1, 0, new System.Text.Rune('▄')); - - // leave whitespace in lower left in parent/default background color - Driver.SetAttribute(new Terminal.Gui.Attribute(Color.Black, backgroundColor)); - btn.AddRune(0, 1, new System.Text.Rune(' ')); - - // The color for rendering shadow is 'black' + parent/default background color - Driver.SetAttribute(new Terminal.Gui.Attribute(backgroundColor, Color.Black)); - - // underline shadow - for (int x = 1; x < bounds.Width; x++) - { - btn.AddRune(x, 1, new System.Text.Rune('▄')); - } - } - internal static bool Confirm(string title, string message, string okText = "Yes", string cancelText = "No") { var dlg = new ChoicesDialog(title, message, okText, cancelText); diff --git a/src/UI/Windows/ColorPicker.Designer.cs b/src/UI/Windows/ColorPicker.Designer.cs index ba15c3bc..9e930ffb 100644 --- a/src/UI/Windows/ColorPicker.Designer.cs +++ b/src/UI/Windows/ColorPicker.Designer.cs @@ -19,6 +19,10 @@ namespace TerminalGuiDesigner.UI.Windows { public partial class ColorPicker : Terminal.Gui.Dialog { + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + private Terminal.Gui.Label lblForeground; private Terminal.Gui.ColorPicker cpForeground; @@ -44,12 +48,17 @@ private void InitializeComponent() { this.lblBackground = new Terminal.Gui.Label(); this.cpForeground = new Terminal.Gui.ColorPicker(); this.lblForeground = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); this.Width = Dim.Fill(2); - this.Height = 17; + this.Height = 19; this.X = Pos.Center(); this.Y = Pos.Center(); this.Visible = true; this.Arrangement = Terminal.Gui.ViewArrangement.Movable; + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; this.Modal = true; this.TextAlignment = Terminal.Gui.Alignment.Start; this.Title = "Color Picker"; @@ -59,6 +68,8 @@ private void InitializeComponent() { this.lblForeground.Y = 0; this.lblForeground.Visible = true; this.lblForeground.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForeground.CanFocus = false; + this.lblForeground.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblForeground.Data = "lblForeground"; this.lblForeground.Text = "Foreground:"; this.lblForeground.TextAlignment = Terminal.Gui.Alignment.Start; @@ -69,6 +80,8 @@ private void InitializeComponent() { this.cpForeground.Y = 1; this.cpForeground.Visible = true; this.cpForeground.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.cpForeground.CanFocus = true; + this.cpForeground.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.cpForeground.Data = "cpForeground"; this.cpForeground.Text = ""; this.cpForeground.TextAlignment = Terminal.Gui.Alignment.Start; @@ -83,6 +96,8 @@ private void InitializeComponent() { this.lblBackground.Y = 6; this.lblBackground.Visible = true; this.lblBackground.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackground.CanFocus = false; + this.lblBackground.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblBackground.Data = "lblBackground"; this.lblBackground.Text = "Background:"; this.lblBackground.TextAlignment = Terminal.Gui.Alignment.Start; @@ -93,6 +108,8 @@ private void InitializeComponent() { this.cpBackground.Y = 7; this.cpBackground.Visible = true; this.cpBackground.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.cpBackground.CanFocus = true; + this.cpBackground.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.cpBackground.Data = "cpBackground"; this.cpBackground.Text = ""; this.cpBackground.TextAlignment = Terminal.Gui.Alignment.Start; @@ -107,6 +124,8 @@ private void InitializeComponent() { this.lblResult.Y = 12; this.lblResult.Visible = true; this.lblResult.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblResult.CanFocus = false; + this.lblResult.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblResult.Data = "lblResult"; this.lblResult.Text = "Preview:"; this.lblResult.TextAlignment = Terminal.Gui.Alignment.Start; @@ -117,6 +136,8 @@ private void InitializeComponent() { this.lblPreview.Y = 13; this.lblPreview.Visible = true; this.lblPreview.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblPreview.CanFocus = false; + this.lblPreview.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblPreview.Data = "lblPreview"; this.lblPreview.Text = "\"Sample Text\""; this.lblPreview.TextAlignment = Terminal.Gui.Alignment.Center; @@ -127,6 +148,9 @@ private void InitializeComponent() { this.btnOk.Y = 14; this.btnOk.Visible = true; this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnOk.Data = "btnOk"; this.btnOk.Text = "Ok"; this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; @@ -138,6 +162,9 @@ private void InitializeComponent() { this.btnCancel.Y = 14; this.btnCancel.Visible = true; this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnCancel.Data = "btnCancel"; this.btnCancel.Text = "Cancel"; this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; diff --git a/src/UI/Windows/ColorPicker.cs b/src/UI/Windows/ColorPicker.cs index 0959281d..c5cf050d 100644 --- a/src/UI/Windows/ColorPicker.cs +++ b/src/UI/Windows/ColorPicker.cs @@ -47,8 +47,12 @@ public ColorPicker(Attribute? currentValue) cpForeground.ColorChanged += (s,e) => UpdatePreview(); cpBackground.ColorChanged += (s,e) => UpdatePreview(); - btnOk.Accept += (s, e) => Ok(); - btnCancel.Accept += (s, e) => Cancel(); + btnOk.Accepting += (s, e) => + { + e.Cancel = true; + Ok(); + }; + btnCancel.Accepting += (s, e) => { e.Cancel = true; Cancel(); }; } private void Ok() @@ -67,7 +71,7 @@ private void Cancel() private void UpdatePreview() { lblPreview.ColorScheme = new ColorScheme(GetColor()); - lblPreview.SetNeedsDisplay(); + lblPreview.SetNeedsDraw(); } private Attribute GetColor() diff --git a/src/UI/Windows/ColorSchemeEditor.Designer.cs b/src/UI/Windows/ColorSchemeEditor.Designer.cs index 30cf4fc4..2745ddba 100644 --- a/src/UI/Windows/ColorSchemeEditor.Designer.cs +++ b/src/UI/Windows/ColorSchemeEditor.Designer.cs @@ -3,324 +3,460 @@ // // This code was generated by: -// TerminalGuiDesigner v1.0.18.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- -namespace TerminalGuiDesigner.UI.Windows; -using System; -using Terminal.Gui; - - -public partial class ColorSchemeEditor : Terminal.Gui.Dialog { - - private Terminal.Gui.Label label2; - - private Terminal.Gui.Label lblForegroundNormal; - - private Terminal.Gui.Label label1; - - private Terminal.Gui.Label lblBackgroundNormal; - - private Terminal.Gui.Button btnEditNormal; - - private Terminal.Gui.Label label22; - - private Terminal.Gui.Label lblForegroundHotNormal; - - private Terminal.Gui.Label lblHotNormalSlash; - - private Terminal.Gui.Label lblBackgroundHotNormal; - - private Terminal.Gui.Button btnEditHotNormal; - - private Terminal.Gui.Label lblFocus; - - private Terminal.Gui.Label lblForegroundFocus; - - private Terminal.Gui.Label lblHotNormalSlash2; - - private Terminal.Gui.Label lblBackgroundFocus; - - private Terminal.Gui.Button btnEditFocus; - - private Terminal.Gui.Label label223; - - private Terminal.Gui.Label lblForegroundHotFocus; - - private Terminal.Gui.Label lblHotNormalSlash3; - - private Terminal.Gui.Label lblBackgroundHotFocus; - - private Terminal.Gui.Button btnEditHotFocus; - - private Terminal.Gui.Label label2232; - - private Terminal.Gui.Label lblForegroundDisabled; - - private Terminal.Gui.Label lblHotNormalSlash32; - - private Terminal.Gui.Label lblBackgroundDisabled; - - private Terminal.Gui.Button btnEditDisabled; - - private Terminal.Gui.Button btnOk; +namespace TerminalGuiDesigner.UI.Windows { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.Button btnCancel; - private void InitializeComponent() { - this.btnCancel = new Terminal.Gui.Button(); - this.btnOk = new Terminal.Gui.Button(); - this.btnEditDisabled = new Terminal.Gui.Button(); - this.lblBackgroundDisabled = new Terminal.Gui.Label(); - this.lblHotNormalSlash32 = new Terminal.Gui.Label(); - this.lblForegroundDisabled = new Terminal.Gui.Label(); - this.label2232 = new Terminal.Gui.Label(); - this.btnEditHotFocus = new Terminal.Gui.Button(); - this.lblBackgroundHotFocus = new Terminal.Gui.Label(); - this.lblHotNormalSlash3 = new Terminal.Gui.Label(); - this.lblForegroundHotFocus = new Terminal.Gui.Label(); - this.label223 = new Terminal.Gui.Label(); - this.btnEditFocus = new Terminal.Gui.Button(); - this.lblBackgroundFocus = new Terminal.Gui.Label(); - this.lblHotNormalSlash2 = new Terminal.Gui.Label(); - this.lblForegroundFocus = new Terminal.Gui.Label(); - this.lblFocus = new Terminal.Gui.Label(); - this.btnEditHotNormal = new Terminal.Gui.Button(); - this.lblBackgroundHotNormal = new Terminal.Gui.Label(); - this.lblHotNormalSlash = new Terminal.Gui.Label(); - this.lblForegroundHotNormal = new Terminal.Gui.Label(); - this.label22 = new Terminal.Gui.Label(); - this.btnEditNormal = new Terminal.Gui.Button(); - this.lblBackgroundNormal = new Terminal.Gui.Label(); - this.label1 = new Terminal.Gui.Label(); - this.lblForegroundNormal = new Terminal.Gui.Label(); - this.label2 = new Terminal.Gui.Label(); - this.Width = 31; - this.Height = 9; - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.Modal = true; - this.Text = ""; - this.Border.BorderStyle = Terminal.Gui.LineStyle.Single; - this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = "Color Scheme Editor"; - this.label2.Width = 10; - this.label2.Height = 1; - this.label2.X = 1; - this.label2.Y = 0; - this.label2.Data = "label2"; - this.label2.Text = "Normal :"; - this.label2.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label2); - this.lblForegroundNormal.Width = 1; - this.lblForegroundNormal.Height = 1; - this.lblForegroundNormal.X = Pos.Right(label2) + 1; - this.lblForegroundNormal.Y = 0; - this.lblForegroundNormal.Data = "lblForegroundNormal"; - this.lblForegroundNormal.Text = " "; - this.lblForegroundNormal.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblForegroundNormal); - this.label1.Width = 1; - this.label1.Height = 1; - this.label1.X = 13; - this.label1.Y = 0; - this.label1.Data = "label1"; - this.label1.Text = "\\"; - this.label1.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label1); - this.lblBackgroundNormal.Width = 1; - this.lblBackgroundNormal.Height = 1; - this.lblBackgroundNormal.X = Pos.Right(label2) + 3; - this.lblBackgroundNormal.Y = 0; - this.lblBackgroundNormal.Data = "lblBackgroundNormal"; - this.lblBackgroundNormal.Text = " "; - this.lblBackgroundNormal.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblBackgroundNormal); - this.btnEditNormal.Width = 13; - this.btnEditNormal.X = 15; - this.btnEditNormal.Y = 0; - this.btnEditNormal.Data = "btnEditNormal"; - this.btnEditNormal.Text = "Choose..."; - this.btnEditNormal.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnEditNormal.IsDefault = false; - this.Add(this.btnEditNormal); - this.label22.Width = 10; - this.label22.Height = 1; - this.label22.X = 1; - this.label22.Y = 1; - this.label22.Data = "label22"; - this.label22.Text = "HotNormal:"; - this.label22.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label22); - this.lblForegroundHotNormal.Width = 1; - this.lblForegroundHotNormal.Height = 1; - this.lblForegroundHotNormal.X = Pos.Right(label22) + 1; - this.lblForegroundHotNormal.Y = 1; - this.lblForegroundHotNormal.Data = "lblForegroundHotNormal"; - this.lblForegroundHotNormal.Text = " "; - this.lblForegroundHotNormal.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblForegroundHotNormal); - this.lblHotNormalSlash.Width = 1; - this.lblHotNormalSlash.Height = 1; - this.lblHotNormalSlash.X = 13; - this.lblHotNormalSlash.Y = 1; - this.lblHotNormalSlash.Data = "lblHotNormalSlash"; - this.lblHotNormalSlash.Text = "\\"; - this.lblHotNormalSlash.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblHotNormalSlash); - this.lblBackgroundHotNormal.Width = 1; - this.lblBackgroundHotNormal.Height = 1; - this.lblBackgroundHotNormal.X = Pos.Right(label22) + 3; - this.lblBackgroundHotNormal.Y = 1; - this.lblBackgroundHotNormal.Data = "lblBackgroundHotNormal"; - this.lblBackgroundHotNormal.Text = " "; - this.lblBackgroundHotNormal.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblBackgroundHotNormal); - this.btnEditHotNormal.Width = 13; - this.btnEditHotNormal.X = 15; - this.btnEditHotNormal.Y = 1; - this.btnEditHotNormal.Data = "btnEditHotNormal"; - this.btnEditHotNormal.Text = "Choose..."; - this.btnEditHotNormal.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnEditHotNormal.IsDefault = false; - this.Add(this.btnEditHotNormal); - this.lblFocus.Width = 10; - this.lblFocus.Height = 1; - this.lblFocus.X = 1; - this.lblFocus.Y = 2; - this.lblFocus.Data = "lblFocus"; - this.lblFocus.Text = "Focus :"; - this.lblFocus.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblFocus); - this.lblForegroundFocus.Width = 1; - this.lblForegroundFocus.Height = 1; - this.lblForegroundFocus.X = Pos.Right(lblFocus) + 1; - this.lblForegroundFocus.Y = 2; - this.lblForegroundFocus.Data = "lblForegroundFocus"; - this.lblForegroundFocus.Text = " "; - this.lblForegroundFocus.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblForegroundFocus); - this.lblHotNormalSlash2.Width = 1; - this.lblHotNormalSlash2.Height = 1; - this.lblHotNormalSlash2.X = 13; - this.lblHotNormalSlash2.Y = 2; - this.lblHotNormalSlash2.Data = "lblHotNormalSlash2"; - this.lblHotNormalSlash2.Text = "\\"; - this.lblHotNormalSlash2.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblHotNormalSlash2); - this.lblBackgroundFocus.Width = 1; - this.lblBackgroundFocus.Height = 1; - this.lblBackgroundFocus.X = Pos.Right(lblFocus) + 3; - this.lblBackgroundFocus.Y = 2; - this.lblBackgroundFocus.Data = "lblBackgroundFocus"; - this.lblBackgroundFocus.Text = " "; - this.lblBackgroundFocus.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblBackgroundFocus); - this.btnEditFocus.Width = 13; - this.btnEditFocus.X = 15; - this.btnEditFocus.Y = 2; - this.btnEditFocus.Data = "btnEditFocus"; - this.btnEditFocus.Text = "Choose..."; - this.btnEditFocus.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnEditFocus.IsDefault = false; - this.Add(this.btnEditFocus); - this.label223.Width = 10; - this.label223.Height = 1; - this.label223.X = 1; - this.label223.Y = 3; - this.label223.Data = "label223"; - this.label223.Text = "HotFocus :"; - this.label223.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label223); - this.lblForegroundHotFocus.Width = 1; - this.lblForegroundHotFocus.Height = 1; - this.lblForegroundHotFocus.X = Pos.Right(label223) + 1; - this.lblForegroundHotFocus.Y = 3; - this.lblForegroundHotFocus.Data = "lblForegroundHotFocus"; - this.lblForegroundHotFocus.Text = " "; - this.lblForegroundHotFocus.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblForegroundHotFocus); - this.lblHotNormalSlash3.Width = 1; - this.lblHotNormalSlash3.Height = 1; - this.lblHotNormalSlash3.X = 13; - this.lblHotNormalSlash3.Y = 3; - this.lblHotNormalSlash3.Data = "lblHotNormalSlash3"; - this.lblHotNormalSlash3.Text = "\\"; - this.lblHotNormalSlash3.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblHotNormalSlash3); - this.lblBackgroundHotFocus.Width = 1; - this.lblBackgroundHotFocus.Height = 1; - this.lblBackgroundHotFocus.X = Pos.Right(label223) + 3; - this.lblBackgroundHotFocus.Y = 3; - this.lblBackgroundHotFocus.Data = "lblBackgroundHotFocus"; - this.lblBackgroundHotFocus.Text = " "; - this.lblBackgroundHotFocus.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblBackgroundHotFocus); - this.btnEditHotFocus.Width = 13; - this.btnEditHotFocus.X = 15; - this.btnEditHotFocus.Y = 3; - this.btnEditHotFocus.Data = "btnEditHotFocus"; - this.btnEditHotFocus.Text = "Choose..."; - this.btnEditHotFocus.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnEditHotFocus.IsDefault = false; - this.Add(this.btnEditHotFocus); - this.label2232.Width = 10; - this.label2232.Height = 1; - this.label2232.X = 1; - this.label2232.Y = 4; - this.label2232.Data = "label2232"; - this.label2232.Text = "Disabled :"; - this.label2232.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label2232); - this.lblForegroundDisabled.Width = 1; - this.lblForegroundDisabled.Height = 1; - this.lblForegroundDisabled.X = Pos.Right(label2232) + 1; - this.lblForegroundDisabled.Y = 4; - this.lblForegroundDisabled.Data = "lblForegroundDisabled"; - this.lblForegroundDisabled.Text = " "; - this.lblForegroundDisabled.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblForegroundDisabled); - this.lblHotNormalSlash32.Width = 1; - this.lblHotNormalSlash32.Height = 1; - this.lblHotNormalSlash32.X = 13; - this.lblHotNormalSlash32.Y = 4; - this.lblHotNormalSlash32.Data = "lblHotNormalSlash32"; - this.lblHotNormalSlash32.Text = "\\"; - this.lblHotNormalSlash32.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblHotNormalSlash32); - this.lblBackgroundDisabled.Width = 1; - this.lblBackgroundDisabled.Height = 1; - this.lblBackgroundDisabled.X = Pos.Right(label2232) + 3; - this.lblBackgroundDisabled.Y = 4; - this.lblBackgroundDisabled.Data = "lblBackgroundDisabled"; - this.lblBackgroundDisabled.Text = " "; - this.lblBackgroundDisabled.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblBackgroundDisabled); - this.btnEditDisabled.Width = 13; - this.btnEditDisabled.X = 15; - this.btnEditDisabled.Y = 4; - this.btnEditDisabled.Data = "btnEditDisabled"; - this.btnEditDisabled.Text = "Choose..."; - this.btnEditDisabled.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnEditDisabled.IsDefault = false; - this.Add(this.btnEditDisabled); - this.btnOk.Width = 6; - this.btnOk.X = 3; - this.btnOk.Y = 6; - this.btnOk.Data = "btnOk"; - this.btnOk.Text = "Ok"; - this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnOk.IsDefault = false; - this.Add(this.btnOk); - this.btnCancel.Width = 10; - this.btnCancel.X = 13; - this.btnCancel.Y = 6; - this.btnCancel.Data = "btnCancel"; - this.btnCancel.Text = "Cancel"; - this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnCancel.IsDefault = false; - this.Add(this.btnCancel); + public partial class ColorSchemeEditor : Terminal.Gui.Dialog { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.Label label2; + + private Terminal.Gui.Label lblForegroundNormal; + + private Terminal.Gui.Label label1; + + private Terminal.Gui.Label lblBackgroundNormal; + + private Terminal.Gui.Button btnEditNormal; + + private Terminal.Gui.Label label22; + + private Terminal.Gui.Label lblForegroundHotNormal; + + private Terminal.Gui.Label lblHotNormalSlash; + + private Terminal.Gui.Label lblBackgroundHotNormal; + + private Terminal.Gui.Button btnEditHotNormal; + + private Terminal.Gui.Label lblFocus; + + private Terminal.Gui.Label lblForegroundFocus; + + private Terminal.Gui.Label lblHotNormalSlash2; + + private Terminal.Gui.Label lblBackgroundFocus; + + private Terminal.Gui.Button btnEditFocus; + + private Terminal.Gui.Label label223; + + private Terminal.Gui.Label lblForegroundHotFocus; + + private Terminal.Gui.Label lblHotNormalSlash3; + + private Terminal.Gui.Label lblBackgroundHotFocus; + + private Terminal.Gui.Button btnEditHotFocus; + + private Terminal.Gui.Label label2232; + + private Terminal.Gui.Label lblForegroundDisabled; + + private Terminal.Gui.Label lblHotNormalSlash32; + + private Terminal.Gui.Label lblBackgroundDisabled; + + private Terminal.Gui.Button btnEditDisabled; + + private Terminal.Gui.Button btnOk; + + private Terminal.Gui.Button btnCancel; + + private void InitializeComponent() { + this.btnCancel = new Terminal.Gui.Button(); + this.btnOk = new Terminal.Gui.Button(); + this.btnEditDisabled = new Terminal.Gui.Button(); + this.lblBackgroundDisabled = new Terminal.Gui.Label(); + this.lblHotNormalSlash32 = new Terminal.Gui.Label(); + this.lblForegroundDisabled = new Terminal.Gui.Label(); + this.label2232 = new Terminal.Gui.Label(); + this.btnEditHotFocus = new Terminal.Gui.Button(); + this.lblBackgroundHotFocus = new Terminal.Gui.Label(); + this.lblHotNormalSlash3 = new Terminal.Gui.Label(); + this.lblForegroundHotFocus = new Terminal.Gui.Label(); + this.label223 = new Terminal.Gui.Label(); + this.btnEditFocus = new Terminal.Gui.Button(); + this.lblBackgroundFocus = new Terminal.Gui.Label(); + this.lblHotNormalSlash2 = new Terminal.Gui.Label(); + this.lblForegroundFocus = new Terminal.Gui.Label(); + this.lblFocus = new Terminal.Gui.Label(); + this.btnEditHotNormal = new Terminal.Gui.Button(); + this.lblBackgroundHotNormal = new Terminal.Gui.Label(); + this.lblHotNormalSlash = new Terminal.Gui.Label(); + this.lblForegroundHotNormal = new Terminal.Gui.Label(); + this.label22 = new Terminal.Gui.Label(); + this.btnEditNormal = new Terminal.Gui.Button(); + this.lblBackgroundNormal = new Terminal.Gui.Label(); + this.label1 = new Terminal.Gui.Label(); + this.lblForegroundNormal = new Terminal.Gui.Label(); + this.label2 = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = 31; + this.Height = 11; + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = "Color Scheme Editor"; + this.label2.Width = 10; + this.label2.Height = 1; + this.label2.X = 1; + this.label2.Y = 0; + this.label2.Visible = true; + this.label2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label2.CanFocus = false; + this.label2.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label2.Data = "label2"; + this.label2.Text = "Normal :"; + this.label2.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label2); + this.lblForegroundNormal.Width = 1; + this.lblForegroundNormal.Height = 1; + this.lblForegroundNormal.X = Pos.Right(label2) + 1; + this.lblForegroundNormal.Y = 0; + this.lblForegroundNormal.Visible = true; + this.lblForegroundNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForegroundNormal.CanFocus = false; + this.lblForegroundNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblForegroundNormal.Data = "lblForegroundNormal"; + this.lblForegroundNormal.Text = " "; + this.lblForegroundNormal.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblForegroundNormal); + this.label1.Width = 1; + this.label1.Height = 1; + this.label1.X = 13; + this.label1.Y = 0; + this.label1.Visible = true; + this.label1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label1.CanFocus = false; + this.label1.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label1.Data = "label1"; + this.label1.Text = "\\"; + this.label1.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label1); + this.lblBackgroundNormal.Width = 1; + this.lblBackgroundNormal.Height = 1; + this.lblBackgroundNormal.X = Pos.Right(label2) + 3; + this.lblBackgroundNormal.Y = 0; + this.lblBackgroundNormal.Visible = true; + this.lblBackgroundNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackgroundNormal.CanFocus = false; + this.lblBackgroundNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblBackgroundNormal.Data = "lblBackgroundNormal"; + this.lblBackgroundNormal.Text = " "; + this.lblBackgroundNormal.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblBackgroundNormal); + this.btnEditNormal.Width = 13; + this.btnEditNormal.Height = Dim.Auto(); + this.btnEditNormal.X = 15; + this.btnEditNormal.Y = 0; + this.btnEditNormal.Visible = true; + this.btnEditNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEditNormal.ColorScheme = this.buttons; + this.btnEditNormal.CanFocus = true; + this.btnEditNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.btnEditNormal.Data = "btnEditNormal"; + this.btnEditNormal.Text = "Choose..."; + this.btnEditNormal.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnEditNormal.IsDefault = false; + this.Add(this.btnEditNormal); + this.label22.Width = 10; + this.label22.Height = 1; + this.label22.X = 1; + this.label22.Y = 1; + this.label22.Visible = true; + this.label22.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label22.CanFocus = false; + this.label22.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label22.Data = "label22"; + this.label22.Text = "HotNormal:"; + this.label22.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label22); + this.lblForegroundHotNormal.Width = 1; + this.lblForegroundHotNormal.Height = 1; + this.lblForegroundHotNormal.X = Pos.Right(label22) + 1; + this.lblForegroundHotNormal.Y = 1; + this.lblForegroundHotNormal.Visible = true; + this.lblForegroundHotNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForegroundHotNormal.CanFocus = false; + this.lblForegroundHotNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblForegroundHotNormal.Data = "lblForegroundHotNormal"; + this.lblForegroundHotNormal.Text = " "; + this.lblForegroundHotNormal.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblForegroundHotNormal); + this.lblHotNormalSlash.Width = 1; + this.lblHotNormalSlash.Height = 1; + this.lblHotNormalSlash.X = 13; + this.lblHotNormalSlash.Y = 1; + this.lblHotNormalSlash.Visible = true; + this.lblHotNormalSlash.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblHotNormalSlash.CanFocus = false; + this.lblHotNormalSlash.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblHotNormalSlash.Data = "lblHotNormalSlash"; + this.lblHotNormalSlash.Text = "\\"; + this.lblHotNormalSlash.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblHotNormalSlash); + this.lblBackgroundHotNormal.Width = 1; + this.lblBackgroundHotNormal.Height = 1; + this.lblBackgroundHotNormal.X = Pos.Right(label22) + 3; + this.lblBackgroundHotNormal.Y = 1; + this.lblBackgroundHotNormal.Visible = true; + this.lblBackgroundHotNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackgroundHotNormal.CanFocus = false; + this.lblBackgroundHotNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblBackgroundHotNormal.Data = "lblBackgroundHotNormal"; + this.lblBackgroundHotNormal.Text = " "; + this.lblBackgroundHotNormal.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblBackgroundHotNormal); + this.btnEditHotNormal.Width = 13; + this.btnEditHotNormal.Height = Dim.Auto(); + this.btnEditHotNormal.X = 15; + this.btnEditHotNormal.Y = 1; + this.btnEditHotNormal.Visible = true; + this.btnEditHotNormal.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEditHotNormal.ColorScheme = this.buttons; + this.btnEditHotNormal.CanFocus = true; + this.btnEditHotNormal.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.btnEditHotNormal.Data = "btnEditHotNormal"; + this.btnEditHotNormal.Text = "Choose..."; + this.btnEditHotNormal.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnEditHotNormal.IsDefault = false; + this.Add(this.btnEditHotNormal); + this.lblFocus.Width = 10; + this.lblFocus.Height = 1; + this.lblFocus.X = 1; + this.lblFocus.Y = 2; + this.lblFocus.Visible = true; + this.lblFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblFocus.CanFocus = false; + this.lblFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblFocus.Data = "lblFocus"; + this.lblFocus.Text = "Focus :"; + this.lblFocus.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblFocus); + this.lblForegroundFocus.Width = 1; + this.lblForegroundFocus.Height = 1; + this.lblForegroundFocus.X = Pos.Right(lblFocus) + 1; + this.lblForegroundFocus.Y = 2; + this.lblForegroundFocus.Visible = true; + this.lblForegroundFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForegroundFocus.CanFocus = false; + this.lblForegroundFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblForegroundFocus.Data = "lblForegroundFocus"; + this.lblForegroundFocus.Text = " "; + this.lblForegroundFocus.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblForegroundFocus); + this.lblHotNormalSlash2.Width = 1; + this.lblHotNormalSlash2.Height = 1; + this.lblHotNormalSlash2.X = 13; + this.lblHotNormalSlash2.Y = 2; + this.lblHotNormalSlash2.Visible = true; + this.lblHotNormalSlash2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblHotNormalSlash2.CanFocus = false; + this.lblHotNormalSlash2.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblHotNormalSlash2.Data = "lblHotNormalSlash2"; + this.lblHotNormalSlash2.Text = "\\"; + this.lblHotNormalSlash2.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblHotNormalSlash2); + this.lblBackgroundFocus.Width = 1; + this.lblBackgroundFocus.Height = 1; + this.lblBackgroundFocus.X = Pos.Right(lblFocus) + 3; + this.lblBackgroundFocus.Y = 2; + this.lblBackgroundFocus.Visible = true; + this.lblBackgroundFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackgroundFocus.CanFocus = false; + this.lblBackgroundFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblBackgroundFocus.Data = "lblBackgroundFocus"; + this.lblBackgroundFocus.Text = " "; + this.lblBackgroundFocus.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblBackgroundFocus); + this.btnEditFocus.Width = 13; + this.btnEditFocus.Height = Dim.Auto(); + this.btnEditFocus.X = 15; + this.btnEditFocus.Y = 2; + this.btnEditFocus.Visible = true; + this.btnEditFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEditFocus.ColorScheme = this.buttons; + this.btnEditFocus.CanFocus = true; + this.btnEditFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.btnEditFocus.Data = "btnEditFocus"; + this.btnEditFocus.Text = "Choose..."; + this.btnEditFocus.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnEditFocus.IsDefault = false; + this.Add(this.btnEditFocus); + this.label223.Width = 10; + this.label223.Height = 1; + this.label223.X = 1; + this.label223.Y = 3; + this.label223.Visible = true; + this.label223.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label223.CanFocus = false; + this.label223.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label223.Data = "label223"; + this.label223.Text = "HotFocus :"; + this.label223.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label223); + this.lblForegroundHotFocus.Width = 1; + this.lblForegroundHotFocus.Height = 1; + this.lblForegroundHotFocus.X = Pos.Right(label223) + 1; + this.lblForegroundHotFocus.Y = 3; + this.lblForegroundHotFocus.Visible = true; + this.lblForegroundHotFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForegroundHotFocus.CanFocus = false; + this.lblForegroundHotFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblForegroundHotFocus.Data = "lblForegroundHotFocus"; + this.lblForegroundHotFocus.Text = " "; + this.lblForegroundHotFocus.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblForegroundHotFocus); + this.lblHotNormalSlash3.Width = 1; + this.lblHotNormalSlash3.Height = 1; + this.lblHotNormalSlash3.X = 13; + this.lblHotNormalSlash3.Y = 3; + this.lblHotNormalSlash3.Visible = true; + this.lblHotNormalSlash3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblHotNormalSlash3.CanFocus = false; + this.lblHotNormalSlash3.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblHotNormalSlash3.Data = "lblHotNormalSlash3"; + this.lblHotNormalSlash3.Text = "\\"; + this.lblHotNormalSlash3.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblHotNormalSlash3); + this.lblBackgroundHotFocus.Width = 1; + this.lblBackgroundHotFocus.Height = 1; + this.lblBackgroundHotFocus.X = Pos.Right(label223) + 3; + this.lblBackgroundHotFocus.Y = 3; + this.lblBackgroundHotFocus.Visible = true; + this.lblBackgroundHotFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackgroundHotFocus.CanFocus = false; + this.lblBackgroundHotFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblBackgroundHotFocus.Data = "lblBackgroundHotFocus"; + this.lblBackgroundHotFocus.Text = " "; + this.lblBackgroundHotFocus.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblBackgroundHotFocus); + this.btnEditHotFocus.Width = 13; + this.btnEditHotFocus.Height = Dim.Auto(); + this.btnEditHotFocus.X = 15; + this.btnEditHotFocus.Y = 3; + this.btnEditHotFocus.Visible = true; + this.btnEditHotFocus.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEditHotFocus.ColorScheme = this.buttons; + this.btnEditHotFocus.CanFocus = true; + this.btnEditHotFocus.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.btnEditHotFocus.Data = "btnEditHotFocus"; + this.btnEditHotFocus.Text = "Choose..."; + this.btnEditHotFocus.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnEditHotFocus.IsDefault = false; + this.Add(this.btnEditHotFocus); + this.label2232.Width = 10; + this.label2232.Height = 1; + this.label2232.X = 1; + this.label2232.Y = 4; + this.label2232.Visible = true; + this.label2232.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label2232.CanFocus = false; + this.label2232.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label2232.Data = "label2232"; + this.label2232.Text = "Disabled :"; + this.label2232.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label2232); + this.lblForegroundDisabled.Width = 1; + this.lblForegroundDisabled.Height = 1; + this.lblForegroundDisabled.X = Pos.Right(label2232) + 1; + this.lblForegroundDisabled.Y = 4; + this.lblForegroundDisabled.Visible = true; + this.lblForegroundDisabled.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblForegroundDisabled.CanFocus = false; + this.lblForegroundDisabled.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblForegroundDisabled.Data = "lblForegroundDisabled"; + this.lblForegroundDisabled.Text = " "; + this.lblForegroundDisabled.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblForegroundDisabled); + this.lblHotNormalSlash32.Width = 1; + this.lblHotNormalSlash32.Height = 1; + this.lblHotNormalSlash32.X = 13; + this.lblHotNormalSlash32.Y = 4; + this.lblHotNormalSlash32.Visible = true; + this.lblHotNormalSlash32.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblHotNormalSlash32.CanFocus = false; + this.lblHotNormalSlash32.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblHotNormalSlash32.Data = "lblHotNormalSlash32"; + this.lblHotNormalSlash32.Text = "\\"; + this.lblHotNormalSlash32.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblHotNormalSlash32); + this.lblBackgroundDisabled.Width = 1; + this.lblBackgroundDisabled.Height = 1; + this.lblBackgroundDisabled.X = Pos.Right(label2232) + 3; + this.lblBackgroundDisabled.Y = 4; + this.lblBackgroundDisabled.Visible = true; + this.lblBackgroundDisabled.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblBackgroundDisabled.CanFocus = false; + this.lblBackgroundDisabled.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblBackgroundDisabled.Data = "lblBackgroundDisabled"; + this.lblBackgroundDisabled.Text = " "; + this.lblBackgroundDisabled.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblBackgroundDisabled); + this.btnEditDisabled.Width = 13; + this.btnEditDisabled.Height = Dim.Auto(); + this.btnEditDisabled.X = 15; + this.btnEditDisabled.Y = 4; + this.btnEditDisabled.Visible = true; + this.btnEditDisabled.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnEditDisabled.ColorScheme = this.buttons; + this.btnEditDisabled.CanFocus = true; + this.btnEditDisabled.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.btnEditDisabled.Data = "btnEditDisabled"; + this.btnEditDisabled.Text = "Choose..."; + this.btnEditDisabled.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnEditDisabled.IsDefault = false; + this.Add(this.btnEditDisabled); + this.btnOk.Width = Dim.Auto(); + this.btnOk.Height = Dim.Auto(); + this.btnOk.X = 3; + this.btnOk.Y = 6; + this.btnOk.Visible = true; + this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnOk.Data = "btnOk"; + this.btnOk.Text = "Ok"; + this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnOk.IsDefault = false; + this.Add(this.btnOk); + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 13; + this.btnCancel.Y = 6; + this.btnCancel.Visible = true; + this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnCancel.Data = "btnCancel"; + this.btnCancel.Text = "Cancel"; + this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnCancel.IsDefault = false; + this.Add(this.btnCancel); + } } } diff --git a/src/UI/Windows/ColorSchemeEditor.cs b/src/UI/Windows/ColorSchemeEditor.cs index c91f1dc9..7cca8624 100644 --- a/src/UI/Windows/ColorSchemeEditor.cs +++ b/src/UI/Windows/ColorSchemeEditor.cs @@ -17,26 +17,7 @@ namespace TerminalGuiDesigner.UI.Windows; /// public partial class ColorSchemeEditor { - class MutableColorScheme - { - public Attribute Disabled { get; set; } - public Attribute Focus { get; set; } - public Attribute HotFocus { get; set; } - public Attribute HotNormal { get; set; } - public Attribute Normal { get; set; } - - internal ColorScheme ToColorScheme() - { - return new ColorScheme - { - Normal = Normal, - HotNormal = HotNormal, - Focus = Focus, - HotFocus = HotFocus, - Disabled = Disabled, - }; - } - } + /// /// All colors to use in all states (focused, normal etc). /// @@ -60,41 +41,53 @@ public ColorSchemeEditor(ColorScheme scheme) { SetColorPatches(); - btnEditNormal.Accept += (s, e)=>{ + btnEditNormal.Accepting += (s, e)=> + { + e.Cancel = true; _result.Normal = PickNewColorsFor(Result.Normal); SetColorPatches(); }; - btnEditHotNormal.Accept += (s, e)=>{ + btnEditHotNormal.Accepting += (s, e)=> + { + e.Cancel = true; _result.HotNormal = PickNewColorsFor(Result.HotNormal); SetColorPatches(); }; - btnEditFocus.Accept += (s, e)=>{ + btnEditFocus.Accepting += (s, e)=>{ + e.Cancel = true; _result.Focus = PickNewColorsFor(Result.Focus); SetColorPatches(); }; - btnEditHotFocus.Accept += (s, e)=>{ + btnEditHotFocus.Accepting += (s, e)=> + { + e.Cancel = true; _result.HotFocus = PickNewColorsFor(Result.HotFocus); SetColorPatches(); }; - btnEditDisabled.Accept += (s, e)=>{ + btnEditDisabled.Accepting += (s, e)=>{ + e.Cancel = true; _result.Disabled = PickNewColorsFor(Result.Disabled); SetColorPatches(); }; - btnCancel.Accept += (s, e)=>{ + btnCancel.Accepting += (s, e)=> + { + e.Cancel = true; Cancelled = true; Application.RequestStop(); }; - btnOk.Accept += (s, e)=>{ + btnOk.Accepting += (s, e)=> + { + e.Cancel = true; Cancelled = false; Application.RequestStop(); }; diff --git a/src/UI/Windows/DimEditor.Designer.cs b/src/UI/Windows/DimEditor.Designer.cs index 7b10ff6e..e9ef9369 100644 --- a/src/UI/Windows/DimEditor.Designer.cs +++ b/src/UI/Windows/DimEditor.Designer.cs @@ -3,7 +3,7 @@ // // This code was generated by: -// TerminalGuiDesigner v1.1.0.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // @@ -13,11 +13,16 @@ namespace TerminalGuiDesigner.UI.Windows { using Terminal.Gui; using System.Collections; using System.Collections.Generic; + using System.Collections.ObjectModel; using System.Drawing; public partial class DimEditor : Terminal.Gui.Dialog { + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + private Terminal.Gui.RadioGroup rgDimType; private Terminal.Gui.LineView lineview1; @@ -43,12 +48,17 @@ private void InitializeComponent() { this.lblValue = new Terminal.Gui.Label(); this.lineview1 = new Terminal.Gui.LineView(); this.rgDimType = new Terminal.Gui.RadioGroup(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); this.Width = 40; - this.Height = 10; + this.Height = 11; this.X = Pos.Center(); this.Y = Pos.Center(); this.Visible = true; this.Arrangement = Terminal.Gui.ViewArrangement.Movable; + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; this.Modal = true; this.TextAlignment = Terminal.Gui.Alignment.Start; this.Title = ""; @@ -58,8 +68,10 @@ private void InitializeComponent() { this.rgDimType.Y = 1; this.rgDimType.Visible = true; this.rgDimType.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.rgDimType.ColorScheme = this.buttons; + this.rgDimType.CanFocus = true; + this.rgDimType.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.rgDimType.Data = "rgDimType"; - this.rgDimType.Text = ""; this.rgDimType.TextAlignment = Terminal.Gui.Alignment.Start; this.rgDimType.RadioLabels = new string[] { "Absolute", @@ -73,6 +85,8 @@ private void InitializeComponent() { this.lineview1.Y = 1; this.lineview1.Visible = true; this.lineview1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lineview1.CanFocus = false; + this.lineview1.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lineview1.Data = "lineview1"; this.lineview1.TextAlignment = Terminal.Gui.Alignment.Start; this.lineview1.LineRune = new System.Text.Rune('│'); @@ -84,6 +98,8 @@ private void InitializeComponent() { this.lblValue.Y = 1; this.lblValue.Visible = true; this.lblValue.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblValue.CanFocus = false; + this.lblValue.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblValue.Data = "lblValue"; this.lblValue.Text = "Value:"; this.lblValue.TextAlignment = Terminal.Gui.Alignment.Start; @@ -94,6 +110,8 @@ private void InitializeComponent() { this.tbValue.Y = Pos.Top(lblValue); this.tbValue.Visible = true; this.tbValue.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbValue.CanFocus = true; + this.tbValue.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.tbValue.Secret = false; this.tbValue.Data = "tbValue"; this.tbValue.Text = ""; @@ -105,6 +123,8 @@ private void InitializeComponent() { this.lblOffset.Y = 3; this.lblOffset.Visible = true; this.lblOffset.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblOffset.CanFocus = false; + this.lblOffset.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblOffset.Data = "lblOffset"; this.lblOffset.Text = "Offset:"; this.lblOffset.TextAlignment = Terminal.Gui.Alignment.Start; @@ -115,28 +135,36 @@ private void InitializeComponent() { this.tbOffset.Y = Pos.Top(lblOffset); this.tbOffset.Visible = true; this.tbOffset.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbOffset.CanFocus = true; + this.tbOffset.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.tbOffset.Secret = false; this.tbOffset.Data = "tbOffset"; this.tbOffset.Text = ""; this.tbOffset.TextAlignment = Terminal.Gui.Alignment.Start; this.Add(this.tbOffset); - this.btnOk.Width = 8; + this.btnOk.Width = Dim.Auto(); this.btnOk.Height = Dim.Auto(); this.btnOk.X = 5; this.btnOk.Y = 6; this.btnOk.Visible = true; this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnOk.Data = "btnOk"; this.btnOk.Text = "Ok"; this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; this.btnOk.IsDefault = true; this.Add(this.btnOk); - this.btnCancel.Width = 10; + this.btnCancel.Width = Dim.Auto(); this.btnCancel.Height = Dim.Auto(); this.btnCancel.X = 16; this.btnCancel.Y = 6; this.btnCancel.Visible = true; this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnCancel.Data = "btnCancel"; this.btnCancel.Text = "Cancel"; this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; diff --git a/src/UI/Windows/DimEditor.cs b/src/UI/Windows/DimEditor.cs index 3ac81a44..c6b07349 100644 --- a/src/UI/Windows/DimEditor.cs +++ b/src/UI/Windows/DimEditor.cs @@ -48,8 +48,8 @@ public DimEditor(Design design, Dim oldValue) { Title = "Dim Designer"; Border.BorderStyle = LineStyle.Double; - btnOk.Accept += BtnOk_Clicked; - btnCancel.Accept += BtnCancel_Clicked; + btnOk.Accepting += BtnOk_Clicked; + btnCancel.Accepting += BtnCancel_Clicked; Cancelled = true; Modal = true; rgDimType.KeyDown += RgDimType_KeyPress; @@ -88,7 +88,7 @@ private void RgDimType_KeyPress(object sender, Key obj) // if user types in some text change the focus to the text box to enable entering digits if ((obj == Key.Backspace || char.IsDigit(c)) && tbValue.Visible) { - tbValue?.FocusFirst(TabBehavior.TabStop); + tbValue?.FocusDeepest(NavigationDirection.Forward,TabBehavior.TabStop); } } @@ -111,7 +111,7 @@ private void SetupForCurrentDimType() lblOffset.Visible = false; tbOffset.Visible = false; - SetNeedsDisplay(); + SetNeedsDraw(); break; case DimType.Fill: lblValue.Text = "Margin"; @@ -120,7 +120,7 @@ private void SetupForCurrentDimType() lblOffset.Visible = false; tbOffset.Visible = false; - SetNeedsDisplay(); + SetNeedsDraw(); break; case DimType.Percent: lblValue.Text = "Factor"; @@ -129,28 +129,30 @@ private void SetupForCurrentDimType() lblOffset.Visible = true; tbOffset.Visible = true; - SetNeedsDisplay(); + SetNeedsDraw(); break; case DimType.Auto: lblValue.Visible = false; tbValue.Visible = false; lblOffset.Visible = false; tbOffset.Visible = false; - SetNeedsDisplay(); + SetNeedsDraw(); break; default: throw new ArgumentOutOfRangeException(); } } - private void BtnCancel_Clicked(object sender, EventArgs e) + private void BtnCancel_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = true; Application.RequestStop(); } - private void BtnOk_Clicked(object sender, EventArgs e) + private void BtnOk_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = false; Result = BuildResult(); Application.RequestStop(); diff --git a/src/UI/Windows/EditDialog.cs b/src/UI/Windows/EditDialog.cs index 4b362450..4d97e831 100644 --- a/src/UI/Windows/EditDialog.cs +++ b/src/UI/Windows/EditDialog.cs @@ -56,8 +56,9 @@ public EditDialog(Design design) IsDefault = true, }; - btnSet.Accept += (s, e) => + btnSet.Accepting += (s, e) => { + e.Cancel = true; this.SetProperty(false); }; @@ -67,7 +68,11 @@ public EditDialog(Design design) X = Pos.Right(btnSet), Y = Pos.Bottom(this.list), }; - btnClose.Accept += (s, e) => Application.RequestStop(); + btnClose.Accepting += (s, e) => + { + e.Cancel = true; + Application.RequestStop(); + }; this.list.KeyDown += (s, e) => { diff --git a/src/UI/Windows/ExceptionViewer.cs b/src/UI/Windows/ExceptionViewer.cs index 075491e0..1d9f2a51 100644 --- a/src/UI/Windows/ExceptionViewer.cs +++ b/src/UI/Windows/ExceptionViewer.cs @@ -16,6 +16,7 @@ public class ExceptionViewer /// to show. public static void ShowException(string errorText, Exception exception) { + Logging.Critical(errorText + exception); var msg = GetExceptionText(errorText, exception, false); var textView = new TextView() @@ -37,16 +38,21 @@ public static void ShowException(string errorText, Exception exception) IsDefault = true }; - btnOk.Accept += (s, e) => Application.RequestStop(); + btnOk.Accepting += (s, e) => + { + e.Cancel = true; + Application.RequestStop(); + }; var btnStack = new Button() { Text = "Stack" }; - btnStack.Accept += (s, e) => + btnStack.Accepting += (s, e) => { + e.Cancel = true; // flip between stack / no stack textView.Text = GetExceptionText(errorText, exception, toggleStack); - textView.SetNeedsDisplay(); + textView.SetNeedsDraw(); toggleStack = !toggleStack; }; diff --git a/src/UI/Windows/GetTextDialog.cs b/src/UI/Windows/GetTextDialog.cs index d507cd21..19eb7d24 100644 --- a/src/UI/Windows/GetTextDialog.cs +++ b/src/UI/Windows/GetTextDialog.cs @@ -55,9 +55,6 @@ public GetTextDialog(DialogArgs args, string? initialValue) }; this.textView.KeyDown += this.TextViewKeyPress; - // make it easier for user to replace this text with something else - // by directly selecting it all so next keypress replaces text - this.textView.SelectAll(); this.win.Add(this.textView); @@ -71,6 +68,12 @@ public GetTextDialog(DialogArgs args, string? initialValue) SetupMultiLineOptional(); } + this.textView.CursorPosition = new(0, 0); + + // make it easier for user to replace this text with something else + // by directly selecting it all so next keypress replaces text + this.textView.SelectAll(); + var btnOk = new Button() { Text = "Ok", @@ -78,8 +81,9 @@ public GetTextDialog(DialogArgs args, string? initialValue) Y = Pos.Bottom(this.textView), IsDefault = !this.args.MultiLine, }; - btnOk.Accept += (s, e) => + btnOk.Accepting += (s, e) => { + e.Cancel = true; this.Accept(); }; @@ -90,8 +94,9 @@ public GetTextDialog(DialogArgs args, string? initialValue) Y = Pos.Bottom(this.textView), IsDefault = false, }; - btnCancel.Accept += (s, e) => + btnCancel.Accepting += (s, e) => { + e.Cancel = true; this.okClicked = false; Application.RequestStop(); }; @@ -102,8 +107,9 @@ public GetTextDialog(DialogArgs args, string? initialValue) X = Pos.Right(btnCancel), Y = Pos.Bottom(this.textView), }; - btnClear.Accept += (s, e) => + btnClear.Accepting += (s, e) => { + e.Cancel = true; this.textView.Text = string.Empty; }; diff --git a/src/UI/Windows/LoadingDialog.Designer.cs b/src/UI/Windows/LoadingDialog.Designer.cs index ca5719cf..ec05bb8c 100644 --- a/src/UI/Windows/LoadingDialog.Designer.cs +++ b/src/UI/Windows/LoadingDialog.Designer.cs @@ -1,38 +1,58 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace TerminalGuiDesigner; -using System; -using Terminal.Gui; +//------------------------------------------------------------------------------ -public partial class LoadingDialog : Terminal.Gui.Dialog { +// +// This code was generated by: +// TerminalGuiDesigner v2.0.0.0 +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ----------------------------------------------------------------------------- +namespace TerminalGuiDesigner { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.Label lblLoading; - private void InitializeComponent() { - this.Text = ""; - this.Width = 40; - this.Height = 5; - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.TextAlignment = Alignment.Start; - this.Title = "Loading..."; - this.Title = "Loading..."; - this.lblLoading = new Terminal.Gui.Label(); - this.lblLoading.Data = "lblLoading"; - this.lblLoading.Text = "Please wait ..."; - this.lblLoading.Width = 36; - this.lblLoading.Height = 1; - this.lblLoading.X = 1; - this.lblLoading.Y = 1; - this.lblLoading.TextAlignment = Alignment.Start; - this.Add(this.lblLoading); + public partial class LoadingDialog : Terminal.Gui.Dialog { + + private Terminal.Gui.Label lblLoading; + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private void InitializeComponent() { + this.lblLoading = new Terminal.Gui.Label(); + this.Width = 40; + this.Height = 6; + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.ColorScheme = this.dialogBackground; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = "Loading..."; + this.lblLoading.Width = 36; + this.lblLoading.Height = 1; + this.lblLoading.X = 1; + this.lblLoading.Y = 1; + this.lblLoading.Visible = true; + this.lblLoading.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblLoading.CanFocus = false; + this.lblLoading.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblLoading.Data = "lblLoading"; + this.lblLoading.Text = "Please wait ..."; + this.lblLoading.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblLoading); + } } } diff --git a/src/UI/Windows/Modals.cs b/src/UI/Windows/Modals.cs index 51f68295..4c999d4e 100644 --- a/src/UI/Windows/Modals.cs +++ b/src/UI/Windows/Modals.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Text; using Terminal.Gui; using YamlDotNet.Core.Tokens; using Key = Terminal.Gui.Key; @@ -136,14 +137,14 @@ internal static bool GetString(string windowTitle, string entryLabel, string? in return false; } - internal static bool Get(string prompt, string okText, T[] collection, T? currentSelection, out T? selected) + internal static bool Get(string prompt, string okText, T[] collection, T? currentSelection, out T? selected, bool sort = true) { - return Get(prompt, okText, true, collection, o => o?.ToString() ?? "Null", false, currentSelection, out selected); + return Get(prompt, okText, true, collection, o => o is Type t ? t.Name : o?.ToString() ?? "Null", false, currentSelection, out selected,sort); } - internal static bool Get( string prompt, string okText, in bool addSearch, T[] collection, Func displayMember, bool addNull, [NotNullWhen( true )]T? currentSelection, [NotNullWhen( true )] out T? selected ) + internal static bool Get( string prompt, string okText, in bool addSearch, T[] collection, Func displayMember, bool addNull, [NotNullWhen( true )]T? currentSelection, [NotNullWhen( true )] out T? selected, bool sort=true ) { - var pick = new BigListBox( prompt, okText, in addSearch, collection, displayMember, addNull, currentSelection ); + var pick = new BigListBox( prompt, okText, in addSearch, collection, displayMember, addNull, currentSelection,sort ); bool toReturn = pick.ShowDialog( ); selected = pick.Selected; return toReturn; @@ -193,9 +194,11 @@ internal static Terminal.Gui.Key GetShortcut() return key == Key.DeleteChar ? KeyCode.Null : key; } - private static bool IsValidShortcut(Key key) + public static bool IsValidShortcut(Key key) { - if (key.KeyCode == KeyCode.CtrlMask || key.KeyCode == KeyCode.ShiftMask || key.KeyCode == KeyCode.AltMask) + const KeyCode modifierMask = KeyCode.CtrlMask | KeyCode.ShiftMask | KeyCode.AltMask; + + if ((key.KeyCode & modifierMask) != 0 && (key.KeyCode & ~modifierMask) == 0) { return false; } diff --git a/src/UI/Windows/MutableColorScheme.cs b/src/UI/Windows/MutableColorScheme.cs new file mode 100644 index 00000000..03b13eed --- /dev/null +++ b/src/UI/Windows/MutableColorScheme.cs @@ -0,0 +1,29 @@ +#nullable disable +using Terminal.Gui; +using Attribute = Terminal.Gui.Attribute; + +namespace TerminalGuiDesigner.UI.Windows; + +/// +/// Version of with setters, for use with +/// +class MutableColorScheme +{ + public Attribute Disabled { get; set; } + public Attribute Focus { get; set; } + public Attribute HotFocus { get; set; } + public Attribute HotNormal { get; set; } + public Attribute Normal { get; set; } + + internal ColorScheme ToColorScheme() + { + return new ColorScheme + { + Normal = Normal, + HotNormal = HotNormal, + Focus = Focus, + HotFocus = HotFocus, + Disabled = Disabled, + }; + } +} \ No newline at end of file diff --git a/src/UI/Windows/PointEditor.Designer.cs b/src/UI/Windows/PointEditor.Designer.cs index 4a64ae13..d91cb286 100644 --- a/src/UI/Windows/PointEditor.Designer.cs +++ b/src/UI/Windows/PointEditor.Designer.cs @@ -1,94 +1,138 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace TerminalGuiDesigner; -using System; -using Terminal.Gui; +//------------------------------------------------------------------------------ -public partial class PointEditor : Terminal.Gui.Dialog { - - private Terminal.Gui.Label lblX; - - private Terminal.Gui.TextField tbX; - - private Terminal.Gui.Label lblY; - - private Terminal.Gui.TextField tbY; - - private Terminal.Gui.Button btnOk; +// +// This code was generated by: +// TerminalGuiDesigner v2.0.0.0 +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// ----------------------------------------------------------------------------- +namespace TerminalGuiDesigner { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.Button btnCancel; - private void InitializeComponent() { - this.Text = ""; - this.Width = 23; - this.Height = 8; - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.TextAlignment = Alignment.Start; - this.Title = "Point Designer"; - this.lblX = new Terminal.Gui.Label(); - this.lblX.Data = "lblX"; - this.lblX.Text = "X:"; - this.lblX.Width = 2; - this.lblX.Height = 1; - this.lblX.X = 2; - this.lblX.Y = 1; - this.lblX.TextAlignment = Alignment.Start; - this.Add(this.lblX); - this.tbX = new Terminal.Gui.TextField(); - this.tbX.Data = "tbX"; - this.tbX.Text = ""; - this.tbX.Width = 10; - this.tbX.Height = 1; - this.tbX.X = 5; - this.tbX.Y = 1; - this.tbX.TextAlignment = Alignment.Start; - this.Add(this.tbX); - this.lblY = new Terminal.Gui.Label(); - this.lblY.Data = "lblY"; - this.lblY.Text = "Y:"; - this.lblY.Width = 2; - this.lblY.Height = 1; - this.lblY.X = 2; - this.lblY.Y = 3; - this.lblY.TextAlignment = Alignment.Start; - this.Add(this.lblY); - this.tbY = new Terminal.Gui.TextField(); - this.tbY.Data = "tbY"; - this.tbY.Text = ""; - this.tbY.Width = 10; - this.tbY.Height = 1; - this.tbY.X = 5; - this.tbY.Y = 3; - this.tbY.TextAlignment = Alignment.Start; - this.Add(this.tbY); - this.btnOk = new Terminal.Gui.Button(); - this.btnOk.Data = "btnOk"; - this.btnOk.Text = "Ok"; - this.btnOk.Width = 8; - this.btnOk.Height = 1; - this.btnOk.X = 1; - this.btnOk.Y = 5; - this.btnOk.TextAlignment = Alignment.Center; - this.btnOk.IsDefault = true; - this.Add(this.btnOk); - this.btnCancel = new Terminal.Gui.Button(); - this.btnCancel.Data = "btnCancel"; - this.btnCancel.Text = "Cancel"; - this.btnCancel.Width = 10; - this.btnCancel.Height = 1; - this.btnCancel.X = 10; - this.btnCancel.Y = 5; - this.btnCancel.TextAlignment = Alignment.Center; - this.btnCancel.IsDefault = false; - this.Add(this.btnCancel); + public partial class PointEditor : Terminal.Gui.Dialog { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.Label lblX; + + private Terminal.Gui.TextField tbX; + + private Terminal.Gui.Label lblY; + + private Terminal.Gui.TextField tbY; + + private Terminal.Gui.Button btnOk; + + private Terminal.Gui.Button btnCancel; + + private void InitializeComponent() { + this.btnCancel = new Terminal.Gui.Button(); + this.btnOk = new Terminal.Gui.Button(); + this.tbY = new Terminal.Gui.TextField(); + this.lblY = new Terminal.Gui.Label(); + this.tbX = new Terminal.Gui.TextField(); + this.lblX = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = 25; + this.Height = 10; + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = "Point Designer"; + this.lblX.Width = 2; + this.lblX.Height = 1; + this.lblX.X = 2; + this.lblX.Y = 1; + this.lblX.Visible = true; + this.lblX.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblX.CanFocus = false; + this.lblX.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblX.Data = "lblX"; + this.lblX.Text = "X:"; + this.lblX.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblX); + this.tbX.Width = 10; + this.tbX.Height = 1; + this.tbX.X = 5; + this.tbX.Y = 1; + this.tbX.Visible = true; + this.tbX.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbX.CanFocus = true; + this.tbX.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tbX.Secret = false; + this.tbX.Data = "tbX"; + this.tbX.Text = ""; + this.tbX.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tbX); + this.lblY.Width = 2; + this.lblY.Height = 1; + this.lblY.X = 2; + this.lblY.Y = 3; + this.lblY.Visible = true; + this.lblY.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblY.CanFocus = false; + this.lblY.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblY.Data = "lblY"; + this.lblY.Text = "Y:"; + this.lblY.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblY); + this.tbY.Width = 10; + this.tbY.Height = 1; + this.tbY.X = 5; + this.tbY.Y = 3; + this.tbY.Visible = true; + this.tbY.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbY.CanFocus = true; + this.tbY.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tbY.Secret = false; + this.tbY.Data = "tbY"; + this.tbY.Text = ""; + this.tbY.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tbY); + this.btnOk.Width = 8; + this.btnOk.Height = Dim.Auto(); + this.btnOk.X = 1; + this.btnOk.Y = 5; + this.btnOk.Visible = true; + this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnOk.Data = "btnOk"; + this.btnOk.Text = "Ok"; + this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnOk.IsDefault = true; + this.Add(this.btnOk); + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 10; + this.btnCancel.Y = 5; + this.btnCancel.Visible = true; + this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.dialogBackground; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnCancel.Data = "btnCancel"; + this.btnCancel.Text = "Cancel"; + this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnCancel.IsDefault = false; + this.Add(this.btnCancel); + } } } diff --git a/src/UI/Windows/PointEditor.cs b/src/UI/Windows/PointEditor.cs index 4daaef18..9e097a00 100644 --- a/src/UI/Windows/PointEditor.cs +++ b/src/UI/Windows/PointEditor.cs @@ -48,18 +48,20 @@ public PointEditor(float x, float y) { tbX.Text = x.ToString(); tbY.Text = y.ToString(); - btnOk.Accept += Ok; - btnCancel.Accept += Cancel; + btnOk.Accepting += Ok; + btnCancel.Accepting += Cancel; } - private void Cancel(object sender, EventArgs e) + private void Cancel(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = true; Application.RequestStop(); } - private void Ok(object sender, EventArgs e) + private void Ok(object sender, CommandEventArgs e) { + e.Cancel = true; if(int.TryParse(tbX.Text.ToString(), out var x)) { if(int.TryParse(tbY.Text.ToString(), out var y)) diff --git a/src/UI/Windows/PosEditor.Designer.cs b/src/UI/Windows/PosEditor.Designer.cs index 416e5092..09042998 100644 --- a/src/UI/Windows/PosEditor.Designer.cs +++ b/src/UI/Windows/PosEditor.Designer.cs @@ -3,169 +3,239 @@ // // This code was generated by: -// TerminalGuiDesigner v1.0.18.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- -namespace TerminalGuiDesigner.UI.Windows; -using System; -using Terminal.Gui; - - -public partial class PosEditor : Terminal.Gui.Dialog { - - private Terminal.Gui.RadioGroup rgPosType; - - private Terminal.Gui.LineView lineview1; - - private Terminal.Gui.Label lblValue; - - private Terminal.Gui.TextField tbValue; - - private Terminal.Gui.Label lblRelativeTo; - - private Terminal.Gui.ComboBox ddRelativeTo; - - private Terminal.Gui.Label lblSide; - - private Terminal.Gui.ComboBox ddSide; - - private Terminal.Gui.Label lblOffset; - - private Terminal.Gui.TextField tbOffset; - - private Terminal.Gui.Button btnOk; +namespace TerminalGuiDesigner.UI.Windows { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.Button btnCancel; - private void InitializeComponent() { - this.btnCancel = new Terminal.Gui.Button(); - this.btnOk = new Terminal.Gui.Button(); - this.tbOffset = new Terminal.Gui.TextField(); - this.lblOffset = new Terminal.Gui.Label(); - this.ddSide = new Terminal.Gui.ComboBox(); - this.lblSide = new Terminal.Gui.Label(); - this.ddRelativeTo = new Terminal.Gui.ComboBox(); - this.lblRelativeTo = new Terminal.Gui.Label(); - this.tbValue = new Terminal.Gui.TextField(); - this.lblValue = new Terminal.Gui.Label(); - this.lineview1 = new Terminal.Gui.LineView(); - this.rgPosType = new Terminal.Gui.RadioGroup(); - this.Width = 47; - this.Height = 12; - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.Modal = true; - this.Text = ""; - this.Border.BorderStyle = Terminal.Gui.LineStyle.Single; - this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = ""; - this.rgPosType.Width = 12; - this.rgPosType.Height = 5; - this.rgPosType.X = 1; - this.rgPosType.Y = 1; - this.rgPosType.Data = "rgPosType"; - this.rgPosType.Text = ""; - this.rgPosType.TextAlignment = Terminal.Gui.Alignment.Start; - this.rgPosType.RadioLabels = new string[] { - "Absolute", - "Percent", - "Relative", - "Center", - "AnchorEnd"}; - this.Add(this.rgPosType); - this.lineview1.Width = 1; - this.lineview1.Height = 5; - this.lineview1.X = 14; - this.lineview1.Y = 1; - this.lineview1.Data = "lineview1"; - this.lineview1.Text = ""; - this.lineview1.TextAlignment = Terminal.Gui.Alignment.Start; - this.lineview1.LineRune = new System.Text.Rune('│'); - this.lineview1.Orientation = Orientation.Vertical; - this.Add(this.lineview1); - this.lblValue.Width = 6; - this.lblValue.Height = 1; - this.lblValue.X = 22; - this.lblValue.Y = 1; - this.lblValue.Data = "lblValue"; - this.lblValue.Text = "Value:"; - this.lblValue.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblValue); - this.tbValue.Width = 15; - this.tbValue.Height = 1; - this.tbValue.X = Pos.Right(lblValue) + 1; - this.tbValue.Y = Pos.Top(lblValue); - this.tbValue.Secret = false; - this.tbValue.Data = "tbValue"; - this.tbValue.Text = ""; - this.tbValue.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.tbValue); - this.lblRelativeTo.Width = 12; - this.lblRelativeTo.Height = 1; - this.lblRelativeTo.X = 16; - this.lblRelativeTo.Y = 3; - this.lblRelativeTo.Data = "lblRelativeTo"; - this.lblRelativeTo.Text = "Relative To:"; - this.lblRelativeTo.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblRelativeTo); - this.ddRelativeTo.Width = 15; - this.ddRelativeTo.Height = 5; - this.ddRelativeTo.X = Pos.Right(lblRelativeTo) + 1; - this.ddRelativeTo.Y = 3; - this.ddRelativeTo.Data = "ddRelativeTo"; - this.ddRelativeTo.Text = ""; - this.ddRelativeTo.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.ddRelativeTo); - this.lblSide.Width = 5; - this.lblSide.Height = 1; - this.lblSide.X = 23; - this.lblSide.Y = 5; - this.lblSide.Data = "lblSide"; - this.lblSide.Text = "Side:"; - this.lblSide.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblSide); - this.ddSide.Width = 15; - this.ddSide.Height = 5; - this.ddSide.X = Pos.Right(lblSide) + 1; - this.ddSide.Y = Pos.Top(lblSide); - this.ddSide.Data = "ddSide"; - this.ddSide.Text = ""; - this.ddSide.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.ddSide); - this.lblOffset.Width = 7; - this.lblOffset.Height = 1; - this.lblOffset.X = 21; - this.lblOffset.Y = 7; - this.lblOffset.Data = "lblOffset"; - this.lblOffset.Text = "Offset:"; - this.lblOffset.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.lblOffset); - this.tbOffset.Width = 15; - this.tbOffset.Height = 1; - this.tbOffset.X = Pos.Right(lblOffset) + 1; - this.tbOffset.Y = 7; - this.tbOffset.Secret = false; - this.tbOffset.Data = "tbOffset"; - this.tbOffset.Text = ""; - this.tbOffset.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.tbOffset); - this.btnOk.Width = 8; - this.btnOk.X = 11; - this.btnOk.Y = 9; - this.btnOk.Data = "btnOk"; - this.btnOk.Text = "Ok"; - this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnOk.IsDefault = true; - this.Add(this.btnOk); - this.btnCancel.Width = 10; - this.btnCancel.X = 21; - this.btnCancel.Y = 9; - this.btnCancel.Data = "btnCancel"; - this.btnCancel.Text = "Cancel"; - this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnCancel.IsDefault = false; - this.Add(this.btnCancel); + public partial class PosEditor : Terminal.Gui.Dialog { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.RadioGroup rgPosType; + + private Terminal.Gui.LineView lineview1; + + private Terminal.Gui.Label lblValue; + + private Terminal.Gui.TextField tbValue; + + private Terminal.Gui.Label lblRelativeTo; + + private Terminal.Gui.TextField tbRelativeTo; + + private Terminal.Gui.Label lblSide; + + private Terminal.Gui.RadioGroup rgSide; + + private Terminal.Gui.Label lblOffset; + + private Terminal.Gui.TextField tbOffset; + + private Terminal.Gui.Button btnOk; + + private Terminal.Gui.Button btnCancel; + + private void InitializeComponent() { + this.btnCancel = new Terminal.Gui.Button(); + this.btnOk = new Terminal.Gui.Button(); + this.tbOffset = new Terminal.Gui.TextField(); + this.lblOffset = new Terminal.Gui.Label(); + this.rgSide = new Terminal.Gui.RadioGroup(); + this.lblSide = new Terminal.Gui.Label(); + this.tbRelativeTo = new Terminal.Gui.TextField(); + this.lblRelativeTo = new Terminal.Gui.Label(); + this.tbValue = new Terminal.Gui.TextField(); + this.lblValue = new Terminal.Gui.Label(); + this.lineview1 = new Terminal.Gui.LineView(); + this.rgPosType = new Terminal.Gui.RadioGroup(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = 47; + this.Height = 16; + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = ""; + this.rgPosType.Width = 12; + this.rgPosType.Height = 5; + this.rgPosType.X = 1; + this.rgPosType.Y = 1; + this.rgPosType.Visible = true; + this.rgPosType.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.rgPosType.ColorScheme = this.buttons; + this.rgPosType.CanFocus = true; + this.rgPosType.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.rgPosType.Data = "rgPosType"; + this.rgPosType.TextAlignment = Terminal.Gui.Alignment.Start; + this.rgPosType.RadioLabels = new string[] { + "Absolute", + "Percent", + "Relative", + "Center", + "AnchorEnd"}; + this.Add(this.rgPosType); + this.lineview1.Width = 1; + this.lineview1.Height = 5; + this.lineview1.X = 14; + this.lineview1.Y = 1; + this.lineview1.Visible = true; + this.lineview1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lineview1.CanFocus = false; + this.lineview1.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lineview1.Data = "lineview1"; + this.lineview1.TextAlignment = Terminal.Gui.Alignment.Start; + this.lineview1.LineRune = new System.Text.Rune('│'); + this.lineview1.Orientation = Terminal.Gui.Orientation.Vertical; + this.Add(this.lineview1); + this.lblValue.Width = 6; + this.lblValue.Height = 1; + this.lblValue.X = 22; + this.lblValue.Y = 1; + this.lblValue.Visible = true; + this.lblValue.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblValue.CanFocus = false; + this.lblValue.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblValue.Data = "lblValue"; + this.lblValue.Text = "Value:"; + this.lblValue.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblValue); + this.tbValue.Width = 15; + this.tbValue.Height = 1; + this.tbValue.X = Pos.Right(lblValue) + 1; + this.tbValue.Y = Pos.Top(lblValue); + this.tbValue.Visible = true; + this.tbValue.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbValue.CanFocus = true; + this.tbValue.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tbValue.Secret = false; + this.tbValue.Data = "tbValue"; + this.tbValue.Text = ""; + this.tbValue.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tbValue); + this.lblRelativeTo.Width = 12; + this.lblRelativeTo.Height = 1; + this.lblRelativeTo.X = 16; + this.lblRelativeTo.Y = 3; + this.lblRelativeTo.Visible = true; + this.lblRelativeTo.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblRelativeTo.CanFocus = false; + this.lblRelativeTo.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblRelativeTo.Data = "lblRelativeTo"; + this.lblRelativeTo.Text = "Relative To:"; + this.lblRelativeTo.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblRelativeTo); + this.tbRelativeTo.Width = 15; + this.tbRelativeTo.Height = 1; + this.tbRelativeTo.X = Pos.Right(lblOffset) + 1; + this.tbRelativeTo.Y = 3; + this.tbRelativeTo.Visible = true; + this.tbRelativeTo.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbRelativeTo.CanFocus = true; + this.tbRelativeTo.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tbRelativeTo.Secret = false; + this.tbRelativeTo.Data = "tbRelativeTo"; + this.tbRelativeTo.Text = ""; + this.tbRelativeTo.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tbRelativeTo); + this.lblSide.Width = 5; + this.lblSide.Height = 1; + this.lblSide.X = 23; + this.lblSide.Y = 5; + this.lblSide.Visible = true; + this.lblSide.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblSide.CanFocus = false; + this.lblSide.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblSide.Data = "lblSide"; + this.lblSide.Text = "Side:"; + this.lblSide.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblSide); + this.rgSide.Width = 10; + this.rgSide.Height = 4; + this.rgSide.X = 30; + this.rgSide.Y = 5; + this.rgSide.Visible = true; + this.rgSide.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.rgSide.CanFocus = true; + this.rgSide.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.rgSide.Data = "rgSide"; + this.rgSide.TextAlignment = Terminal.Gui.Alignment.Start; + this.rgSide.RadioLabels = new string[] { + "Left", + "Top", + "Right", + "Bottom"}; + this.Add(this.rgSide); + this.lblOffset.Width = 7; + this.lblOffset.Height = 1; + this.lblOffset.X = 21; + this.lblOffset.Y = 9; + this.lblOffset.Visible = true; + this.lblOffset.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblOffset.CanFocus = false; + this.lblOffset.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.lblOffset.Data = "lblOffset"; + this.lblOffset.Text = "Offset:"; + this.lblOffset.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.lblOffset); + this.tbOffset.Width = 15; + this.tbOffset.Height = 1; + this.tbOffset.X = Pos.Right(lblOffset) + 1; + this.tbOffset.Y = 9; + this.tbOffset.Visible = true; + this.tbOffset.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tbOffset.CanFocus = true; + this.tbOffset.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tbOffset.Secret = false; + this.tbOffset.Data = "tbOffset"; + this.tbOffset.Text = ""; + this.tbOffset.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tbOffset); + this.btnOk.Width = Dim.Auto(); + this.btnOk.Height = Dim.Auto(); + this.btnOk.X = 14; + this.btnOk.Y = 11; + this.btnOk.Visible = true; + this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnOk.Data = "btnOk"; + this.btnOk.Text = "Ok"; + this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnOk.IsDefault = true; + this.Add(this.btnOk); + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 23; + this.btnCancel.Y = 11; + this.btnCancel.Visible = true; + this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnCancel.Data = "btnCancel"; + this.btnCancel.Text = "Cancel"; + this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnCancel.IsDefault = false; + this.Add(this.btnCancel); + } } } diff --git a/src/UI/Windows/PosEditor.cs b/src/UI/Windows/PosEditor.cs index 7b65d2b9..63521b9e 100644 --- a/src/UI/Windows/PosEditor.cs +++ b/src/UI/Windows/PosEditor.cs @@ -23,6 +23,7 @@ namespace TerminalGuiDesigner.UI.Windows; public partial class PosEditor : Dialog, IValueGetterDialog { private Design design; + private readonly Dictionary _siblings; /// /// Users configured (assembled from radio button @@ -52,18 +53,23 @@ public PosEditor(Design design, Pos oldValue) { rgPosType.KeyDown += RgPosType_KeyPress; - btnOk.Accept += BtnOk_Clicked; - btnCancel.Accept += BtnCancel_Clicked; + btnOk.Accepting += BtnOk_Clicked; + btnCancel.Accepting += BtnCancel_Clicked; Cancelled = true; Modal = true; - var siblings = design.GetSiblings().ToListObs(); + _siblings = design.GetSiblings().ToDictionary( + d=>d.FieldName, + d=>d); - ddRelativeTo.SetSource(siblings); - ddSide.SetSource(Enum.GetValues(typeof(Side)).Cast().ToListObs()); + tbRelativeTo.Autocomplete.SuggestionGenerator = new SingleWordSuggestionGenerator() + { + AllSuggestions = _siblings.Keys.OrderBy(a => a).ToList() + }; var val = oldValue; - if(val.GetPosType(siblings,out var type,out var value,out var relativeTo,out var side, out var offset)) + if(val.GetPosType(_siblings.Values.ToList(), + out var type,out var value,out var relativeTo,out var side, out var offset)) { switch(type) { @@ -76,8 +82,8 @@ public PosEditor(Design design, Pos oldValue) { case PosType.Relative: rgPosType.SelectedItem = 2; if(relativeTo != null) - ddRelativeTo.SelectedItem = siblings.IndexOf(relativeTo); - ddSide.SelectedItem = (int)side; + tbRelativeTo.Text = relativeTo.FieldName; + rgSide.SelectedItem = (int)side; break; case PosType.Center: rgPosType.SelectedItem = 3; @@ -104,7 +110,7 @@ private void RgPosType_KeyPress(object sender, Key key) // if user types in some text change the focus to the text box to enable entering digits if ((key == Key.Backspace || char.IsDigit(c)) && tbValue.Visible) { - tbValue?.FocusFirst(TabBehavior.TabStop); + tbValue?.FocusDeepest(NavigationDirection.Forward,TabBehavior.TabStop); } } @@ -120,9 +126,9 @@ private void SetupForCurrentPosType() { case PosType.Percent: lblRelativeTo.Visible = false; - ddRelativeTo.Visible = false; + tbRelativeTo.Visible = false; lblSide.Visible = false; - ddSide.Visible = false; + rgSide.Visible = false; lblValue.Y = 1; lblValue.Visible = true; @@ -134,13 +140,13 @@ private void SetupForCurrentPosType() tbOffset.Y = 3; tbOffset.Visible = true; - SetNeedsDisplay(); + SetNeedsDraw(); break; case PosType.Center: lblRelativeTo.Visible = false; - ddRelativeTo.Visible = false; + tbRelativeTo.Visible = false; lblSide.Visible = false; - ddSide.Visible = false; + rgSide.Visible = false; lblValue.Visible = false; tbValue.Visible = false; @@ -150,14 +156,14 @@ private void SetupForCurrentPosType() tbOffset.Y = 1; tbOffset.Visible = true; - SetNeedsDisplay(); + SetNeedsDraw(); break; case PosType.Absolute: case PosType.AnchorEnd: - ddRelativeTo.Visible = false; + tbRelativeTo.Visible = false; lblRelativeTo.Visible = false; lblSide.Visible = false; - ddSide.Visible = false; + rgSide.Visible = false; lblValue.Y = 1; lblValue.Visible = true; @@ -165,44 +171,46 @@ private void SetupForCurrentPosType() lblOffset.Visible = false; tbOffset.Visible = false; - SetNeedsDisplay(); + SetNeedsDraw(); break; case PosType.Relative: lblRelativeTo.Y = 1; lblRelativeTo.Visible = true; - ddRelativeTo.Y = 1; - ddRelativeTo.Visible = true; + tbRelativeTo.Y = 1; + tbRelativeTo.Visible = true; lblSide.Y = 3; lblSide.Visible = true; - ddSide.IsInitialized = false; - ddSide.Y = 3; - ddSide.Visible = true; - ddSide.IsInitialized = true; + rgSide.IsInitialized = false; + rgSide.Y = 3; + rgSide.Visible = true; + rgSide.IsInitialized = true; lblValue.Visible = false; tbValue.Visible = false; - lblOffset.Y = 5; + lblOffset.Y = 7; lblOffset.Visible = true; - tbOffset.Y = 5; + tbOffset.Y = 7; tbOffset.Visible = true; - SetNeedsDisplay(); + SetNeedsDraw(); break; default: throw new ArgumentOutOfRangeException(); } } - private void BtnCancel_Clicked(object sender, EventArgs e) + private void BtnCancel_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; Cancelled = true; Application.RequestStop(); } - private void BtnOk_Clicked(object sender, EventArgs e) + private void BtnOk_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; if(GetPosType() == PosType.AnchorEnd && GetValue(out var value) && value <=0) { if (!ChoicesDialog.Confirm("Anchor Without Margin", "Using AnchorEnd without a margin will result in a point outside of parent bounds.\nAre you sure?")) @@ -247,7 +255,7 @@ private PosType GetPosType() private Side? GetSide() { - return ddSide.SelectedItem == -1 ? null : (Side)ddSide.Source.ToList()[ddSide.SelectedItem]; + return rgSide.SelectedItem == -1 ? null : (Side)rgSide.SelectedItem; } private bool GetOffset(out int offset) @@ -272,7 +280,9 @@ private bool GetOffset(out int offset) private bool BuildPosRelative(out Pos result) { - var relativeTo = ddRelativeTo.SelectedItem == -1 ? null : ddRelativeTo.Source.ToList()[ddRelativeTo.SelectedItem] as Design; + var key = tbRelativeTo.Text; + + var relativeTo = (!string.IsNullOrWhiteSpace(key)) && _siblings.TryGetValue(key, out var d) ? d : null; if (relativeTo != null) { diff --git a/src/UI/Windows/SizeEditor.Designer.cs b/src/UI/Windows/SizeEditor.Designer.cs index ff9578d0..bcc9a6c5 100644 --- a/src/UI/Windows/SizeEditor.Designer.cs +++ b/src/UI/Windows/SizeEditor.Designer.cs @@ -3,95 +3,136 @@ // // This code was generated by: -// TerminalGuiDesigner v1.0.18.0 +// TerminalGuiDesigner v2.0.0.0 // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // // ----------------------------------------------------------------------------- -namespace TerminalGuiDesigner.UI.Windows; -using System; -using Terminal.Gui; - - -public partial class SizeEditor : Terminal.Gui.Dialog { - - private Terminal.Gui.Label label1; - - private Terminal.Gui.TextField tfWidth; - - private Terminal.Gui.Label label12; - - private Terminal.Gui.TextField tfHeight; - - private Terminal.Gui.Button btnOk; +namespace TerminalGuiDesigner.UI.Windows { + using System; + using Terminal.Gui; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Drawing; - private Terminal.Gui.Button btnCancel; - private void InitializeComponent() { - this.btnCancel = new Terminal.Gui.Button(); - this.btnOk = new Terminal.Gui.Button(); - this.tfHeight = new Terminal.Gui.TextField(); - this.label12 = new Terminal.Gui.Label(); - this.tfWidth = new Terminal.Gui.TextField(); - this.label1 = new Terminal.Gui.Label(); - this.Width = 20; - this.Height = 7; - this.X = Pos.Center(); - this.Y = Pos.Center(); - this.Modal = true; - this.Text = ""; - this.Border.BorderStyle = Terminal.Gui.LineStyle.Single; - this.TextAlignment = Terminal.Gui.Alignment.Start; - this.Title = "Size"; - this.label1.Width = 4; - this.label1.Height = 1; - this.label1.X = 1; - this.label1.Y = 0; - this.label1.Data = "label1"; - this.label1.Text = "Width:"; - this.label1.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label1); - this.tfWidth.Width = Dim.Fill(1); - this.tfWidth.Height = 1; - this.tfWidth.X = 8; - this.tfWidth.Y = 0; - this.tfWidth.Secret = false; - this.tfWidth.Data = "tfWidth"; - this.tfWidth.Text = ""; - this.tfWidth.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.tfWidth); - this.label12.Width = 4; - this.label12.Height = 1; - this.label12.X = 0; - this.label12.Y = 2; - this.label12.Data = "label12"; - this.label12.Text = "Height:"; - this.label12.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.label12); - this.tfHeight.Width = Dim.Fill(1); - this.tfHeight.Height = 1; - this.tfHeight.X = 8; - this.tfHeight.Y = 2; - this.tfHeight.Secret = false; - this.tfHeight.Data = "tfHeight"; - this.tfHeight.Text = ""; - this.tfHeight.TextAlignment = Terminal.Gui.Alignment.Start; - this.Add(this.tfHeight); - this.btnOk.Width = 6; - this.btnOk.X = 0; - this.btnOk.Y = 4; - this.btnOk.Data = "btnOk"; - this.btnOk.Text = "Ok"; - this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnOk.IsDefault = false; - this.Add(this.btnOk); - this.btnCancel.Width = 10; - this.btnCancel.X = 8; - this.btnCancel.Y = 4; - this.btnCancel.Data = "btnCancel"; - this.btnCancel.Text = "Cancel"; - this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; - this.btnCancel.IsDefault = false; - this.Add(this.btnCancel); + public partial class SizeEditor : Terminal.Gui.Dialog { + + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + + private Terminal.Gui.Label label1; + + private Terminal.Gui.TextField tfWidth; + + private Terminal.Gui.Label label12; + + private Terminal.Gui.TextField tfHeight; + + private Terminal.Gui.Button btnOk; + + private Terminal.Gui.Button btnCancel; + private void InitializeComponent() { + this.btnCancel = new Terminal.Gui.Button(); + this.btnOk = new Terminal.Gui.Button(); + this.tfHeight = new Terminal.Gui.TextField(); + this.label12 = new Terminal.Gui.Label(); + this.tfWidth = new Terminal.Gui.TextField(); + this.label1 = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + this.Width = 21; + this.Height = 9; + this.X = Pos.Center(); + this.Y = Pos.Center(); + this.Visible = true; + this.Arrangement = (Terminal.Gui.ViewArrangement.Movable | Terminal.Gui.ViewArrangement.Overlapped); + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; + this.Modal = true; + this.TextAlignment = Terminal.Gui.Alignment.Start; + this.Title = "Size"; + this.label1.Width = Dim.Auto(); + this.label1.Height = 1; + this.label1.X = 1; + this.label1.Y = 0; + this.label1.Visible = true; + this.label1.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label1.CanFocus = false; + this.label1.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label1.Data = "label1"; + this.label1.Text = "Width:"; + this.label1.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label1); + this.tfWidth.Width = Dim.Fill(1); + this.tfWidth.Height = 1; + this.tfWidth.X = 8; + this.tfWidth.Y = 0; + this.tfWidth.Visible = true; + this.tfWidth.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tfWidth.CanFocus = true; + this.tfWidth.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tfWidth.Secret = false; + this.tfWidth.Data = "tfWidth"; + this.tfWidth.Text = ""; + this.tfWidth.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tfWidth); + this.label12.Width = Dim.Auto(); + this.label12.Height = 1; + this.label12.X = 0; + this.label12.Y = 2; + this.label12.Visible = true; + this.label12.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label12.CanFocus = false; + this.label12.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.label12.Data = "label12"; + this.label12.Text = "Height:"; + this.label12.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.label12); + this.tfHeight.Width = Dim.Fill(1); + this.tfHeight.Height = 1; + this.tfHeight.X = 8; + this.tfHeight.Y = 2; + this.tfHeight.Visible = true; + this.tfHeight.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tfHeight.CanFocus = true; + this.tfHeight.ShadowStyle = Terminal.Gui.ShadowStyle.None; + this.tfHeight.Secret = false; + this.tfHeight.Data = "tfHeight"; + this.tfHeight.Text = ""; + this.tfHeight.TextAlignment = Terminal.Gui.Alignment.Start; + this.Add(this.tfHeight); + this.btnOk.Width = Dim.Auto(); + this.btnOk.Height = Dim.Auto(); + this.btnOk.X = 0; + this.btnOk.Y = 4; + this.btnOk.Visible = true; + this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnOk.Data = "btnOk"; + this.btnOk.Text = "Ok"; + this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnOk.IsDefault = false; + this.Add(this.btnOk); + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 8; + this.btnCancel.Y = 4; + this.btnCancel.Visible = true; + this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; + this.btnCancel.Data = "btnCancel"; + this.btnCancel.Text = "Cancel"; + this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; + this.btnCancel.IsDefault = false; + this.Add(this.btnCancel); + } } } diff --git a/src/UI/Windows/SizeEditor.cs b/src/UI/Windows/SizeEditor.cs index afe00549..7bc50092 100644 --- a/src/UI/Windows/SizeEditor.cs +++ b/src/UI/Windows/SizeEditor.cs @@ -17,6 +17,7 @@ namespace TerminalGuiDesigner.UI.Windows; public partial class SizeEditor : IValueGetterDialog { + /// /// The users edited /// @@ -39,8 +40,9 @@ public SizeEditor(Size s) tfWidth.Text = s.Width.ToString(); tfHeight.Text = s.Height.ToString(); - btnOk.Accept += (s, e) => + btnOk.Accepting += (s, e) => { + e.Cancel = true; try { Result = new Size(int.Parse(tfWidth.Text.ToString()), int.Parse(tfHeight.Text.ToString())); @@ -55,8 +57,9 @@ public SizeEditor(Size s) RequestStop(); }; - btnCancel.Accept += (s, e) => + btnCancel.Accepting += (s, e) => { + e.Cancel = true; Cancelled = true; RequestStop(); }; diff --git a/src/UI/Windows/SliderOptionEditor.Designer.cs b/src/UI/Windows/SliderOptionEditor.Designer.cs index b19f3a85..6cf3d934 100644 --- a/src/UI/Windows/SliderOptionEditor.Designer.cs +++ b/src/UI/Windows/SliderOptionEditor.Designer.cs @@ -19,6 +19,10 @@ namespace TerminalGuiDesigner.UI.Windows { public partial class SliderOptionEditor : Terminal.Gui.Dialog { + private Terminal.Gui.ColorScheme dialogBackground; + + private Terminal.Gui.ColorScheme buttons; + private Terminal.Gui.ColorScheme redOnBlack; private Terminal.Gui.ColorScheme tgDefault; @@ -54,14 +58,19 @@ private void InitializeComponent() { this.label2 = new Terminal.Gui.Label(); this.tfLegend = new Terminal.Gui.TextField(); this.label = new Terminal.Gui.Label(); + this.dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + this.buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); this.redOnBlack = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4291104543u, 4278979596u), new Terminal.Gui.Attribute(4291104543u, 4286595104u), new Terminal.Gui.Attribute(4293347414u, 4278979596u), new Terminal.Gui.Attribute(4291611852u, 4278979596u), new Terminal.Gui.Attribute(4293347414u, 4286595104u)); this.tgDefault = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294111986u, 4278204378u), new Terminal.Gui.Attribute(4278979596u, 4291611852u), new Terminal.Gui.Attribute(4284602070u, 4278204378u), new Terminal.Gui.Attribute(4286595104u, 4278204378u), new Terminal.Gui.Attribute(4282087679u, 4291611852u)); this.Width = 50; - this.Height = 8; + this.Height = 10; this.X = Pos.Center(); this.Y = Pos.Center(); this.Visible = true; this.Arrangement = Terminal.Gui.ViewArrangement.Movable; + this.ColorScheme = this.dialogBackground; + this.CanFocus = true; + this.ShadowStyle = Terminal.Gui.ShadowStyle.Transparent; this.Modal = true; this.TextAlignment = Terminal.Gui.Alignment.Start; this.Title = "OptionEditor"; @@ -71,6 +80,8 @@ private void InitializeComponent() { this.label.Y = 0; this.label.Visible = true; this.label.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label.CanFocus = false; + this.label.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label.Data = "label"; this.label.Text = "Legend:"; this.label.TextAlignment = Terminal.Gui.Alignment.Start; @@ -81,6 +92,8 @@ private void InitializeComponent() { this.tfLegend.Y = 0; this.tfLegend.Visible = true; this.tfLegend.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tfLegend.CanFocus = true; + this.tfLegend.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.tfLegend.Secret = false; this.tfLegend.Data = "tfLegend"; this.tfLegend.Text = ""; @@ -92,6 +105,8 @@ private void InitializeComponent() { this.label2.Y = 1; this.label2.Visible = true; this.label2.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label2.CanFocus = false; + this.label2.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label2.Data = "label2"; this.label2.Text = "Abbreviation:"; this.label2.TextAlignment = Terminal.Gui.Alignment.Start; @@ -102,6 +117,8 @@ private void InitializeComponent() { this.tfLegendAbbr.Y = 1; this.tfLegendAbbr.Visible = true; this.tfLegendAbbr.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tfLegendAbbr.CanFocus = true; + this.tfLegendAbbr.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.tfLegendAbbr.Secret = false; this.tfLegendAbbr.Data = "tfLegendAbbr"; this.tfLegendAbbr.Text = ""; @@ -113,6 +130,8 @@ private void InitializeComponent() { this.lblOneChar.Y = 2; this.lblOneChar.Visible = true; this.lblOneChar.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblOneChar.CanFocus = false; + this.lblOneChar.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblOneChar.Data = "lblOneChar"; this.lblOneChar.Text = "(Single Char) "; this.lblOneChar.TextAlignment = Terminal.Gui.Alignment.Center; @@ -123,6 +142,8 @@ private void InitializeComponent() { this.label3.Y = 3; this.label3.Visible = true; this.label3.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.label3.CanFocus = false; + this.label3.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.label3.Data = "label3"; this.label3.Text = "Data:"; this.label3.TextAlignment = Terminal.Gui.Alignment.Start; @@ -133,38 +154,48 @@ private void InitializeComponent() { this.tfData.Y = 3; this.tfData.Visible = true; this.tfData.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.tfData.CanFocus = true; + this.tfData.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.tfData.Secret = false; this.tfData.Data = "tfData"; this.tfData.Text = ""; this.tfData.TextAlignment = Terminal.Gui.Alignment.Start; this.Add(this.tfData); this.lblType.Width = Dim.Fill(0); - this.lblType.Height = 1; - this.lblType.X = 0; + this.lblType.Height = Dim.Auto(); + this.lblType.X = -1; this.lblType.Y = 4; this.lblType.Visible = true; this.lblType.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.lblType.CanFocus = true; + this.lblType.ShadowStyle = Terminal.Gui.ShadowStyle.None; this.lblType.Data = "lblType"; this.lblType.Text = "( Type ) "; this.lblType.TextAlignment = Terminal.Gui.Alignment.Center; this.Add(this.lblType); - this.btnOk.Width = 8; - this.btnOk.Height = 1; - this.btnOk.X = 11; + this.btnOk.Width = Dim.Auto(); + this.btnOk.Height = Dim.Auto(); + this.btnOk.X = 10; this.btnOk.Y = 5; this.btnOk.Visible = true; this.btnOk.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnOk.ColorScheme = this.buttons; + this.btnOk.CanFocus = true; + this.btnOk.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnOk.Data = "btnOk"; this.btnOk.Text = "Ok"; this.btnOk.TextAlignment = Terminal.Gui.Alignment.Center; this.btnOk.IsDefault = true; this.Add(this.btnOk); - this.btnCancel.Width = 8; - this.btnCancel.Height = 1; - this.btnCancel.X = 23; + this.btnCancel.Width = Dim.Auto(); + this.btnCancel.Height = Dim.Auto(); + this.btnCancel.X = 22; this.btnCancel.Y = 5; this.btnCancel.Visible = true; this.btnCancel.Arrangement = Terminal.Gui.ViewArrangement.Fixed; + this.btnCancel.ColorScheme = this.buttons; + this.btnCancel.CanFocus = true; + this.btnCancel.ShadowStyle = Terminal.Gui.ShadowStyle.Opaque; this.btnCancel.Data = "btnCancel"; this.btnCancel.Text = "Cancel"; this.btnCancel.TextAlignment = Terminal.Gui.Alignment.Center; diff --git a/src/UI/Windows/SliderOptionEditor.cs b/src/UI/Windows/SliderOptionEditor.cs index c30255db..cdc4df0b 100644 --- a/src/UI/Windows/SliderOptionEditor.cs +++ b/src/UI/Windows/SliderOptionEditor.cs @@ -42,8 +42,8 @@ public SliderOptionEditor(Type genericTypeArgument, object? oldValue) { this.genericTypeArgument = genericTypeArgument; this.sliderOptionType = typeof(SliderOption<>).MakeGenericType(this.genericTypeArgument); - btnOk.Accept += BtnOk_Clicked; - btnCancel.Accept += BtnCancel_Clicked; + btnOk.Accepting += BtnOk_Clicked; + btnCancel.Accepting += BtnCancel_Clicked; lblType.Text = $"({genericTypeArgument.Name})"; @@ -68,14 +68,16 @@ public SliderOptionEditor(Type genericTypeArgument, object? oldValue) { } } - private void BtnCancel_Clicked(object sender, EventArgs e) + private void BtnCancel_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; this.Cancelled = true; Application.RequestStop(); } - private void BtnOk_Clicked(object sender, EventArgs e) + private void BtnOk_Clicked(object sender, CommandEventArgs e) { + e.Cancel = true; try { this.BuildResult(); diff --git a/src/ViewExtensions.cs b/src/ViewExtensions.cs index fc9de70b..3690271c 100644 --- a/src/ViewExtensions.cs +++ b/src/ViewExtensions.cs @@ -8,6 +8,10 @@ namespace TerminalGuiDesigner; /// public static class ViewExtensions { + public static View? FindDeepestView(Point screenPoint) + { + return View.GetViewsUnderMouse(screenPoint).LastOrDefault(v=> v!= null); + } /// /// Returns the sub-views of skipping out any /// public views used by the Terminal.Gui API e.g. the 'ContentView' @@ -19,20 +23,14 @@ public static class ViewExtensions /// whose children you want to find. /// All that user perceives as within skipping over /// any Terminal.Gui artifacts (e.g. ContentView). - public static IList GetActualSubviews(this View v) + public static IReadOnlyCollection GetActualSubviews(this View v) { if (v is TabView t) { return t.Tabs.Select(tab => tab.View).Where(v => v != null).ToList(); } - // ScrollView has a content view so to reach its children you have to dive down an extra layer - if (v is ScrollView sc) - { - return sc.Subviews[0].Subviews; - } - - return v.Subviews; + return v.SubViews; } /// @@ -202,7 +200,6 @@ public static bool IsContainerView(this View v) // TODO: are there any others? return - v is ScrollView || v is TabView || v is FrameView || v is Window || @@ -250,7 +247,7 @@ public static bool IsBorderlessContainerView(this View v) /// True if the click lands in the lower right of the returned . /// One or more to ignore (click through) when performing the hit test. /// The at the given screen location or null if none found. - public static View? HitTest(this View w, MouseEvent m, out bool isBorder, out bool isLowerRight, params View[] ignoring) + public static View? HitTest(this View w, MouseEventArgs m, out bool isBorder, out bool isLowerRight, params View[] ignoring) { ignoring = ignoring.Union(w.GetAllNonDesignableSubviews()).ToArray(); @@ -259,10 +256,8 @@ public static bool IsBorderlessContainerView(this View v) { v.Visible = false; } - - var point = w.ScreenToContent(m.Position); - - var hit = View.FindDeepestView(w, m.Position); + + var hit = ViewExtensions.FindDeepestView(m.Position); hit = UnpackHitView(hit); @@ -272,10 +267,10 @@ public static bool IsBorderlessContainerView(this View v) { var screenFrame = hit.FrameToScreen(); - if (point != new Point(screenFrame.X, screenFrame.Y)) + if (m.Position != new Point(screenFrame.X, screenFrame.Y)) { - isLowerRight = Math.Abs(screenFrame.X + screenFrame.Width - point.X) <= resizeBoxArea - && Math.Abs(screenFrame.Y + screenFrame.Height - point.Y) <= resizeBoxArea; + isLowerRight = Math.Abs(screenFrame.X + screenFrame.Width - m.Position.X) <= resizeBoxArea + && Math.Abs(screenFrame.Y + screenFrame.Height - m.Position.Y) <= resizeBoxArea; } else { @@ -306,7 +301,7 @@ public static bool IsBorderlessContainerView(this View v) /// /// - /// Sometimes returns what the library considers + /// Sometimes returns what the library considers /// the clicked View rather than what the user would expect. For example clicking in /// the area of a . /// @@ -316,6 +311,7 @@ public static bool IsBorderlessContainerView(this View v) /// public static View? UnpackHitView(this View? hit) { + if (hit != null && hit.GetType().Name.Equals("TabRowView")) { hit = hit.SuperView; @@ -328,6 +324,11 @@ public static bool IsBorderlessContainerView(this View v) } + if (hit?.IsAdornment() ?? false) + { + hit = hit.GetAdornmentParent(); + } + // TabView nesting of 'fake' views goes: // TabView // - TabViewRow @@ -398,8 +399,8 @@ public static IEnumerable OrderViewsByScreenPosition(IEnumerable vie } /// - /// Returns all subviews that are not Designable. Beware that designs can be nested - /// e.g. calling this on a root view with return subviews that belong to other designed + /// Returns all SubViews that are not Designable. Beware that designs can be nested + /// e.g. calling this on a root view with return SubViews that belong to other designed /// components that were added to the root designed window. /// /// @@ -412,13 +413,17 @@ public static IEnumerable GetAllNonDesignableSubviews(this View view) } private static void RecursivelyIgnoreAllNonDesignableSubviews(View view, List alsoIgnore) { - foreach (var sub in view.Subviews) + foreach (var sub in view.SubViews) { - if (sub.Data is not Design) + // If Data is string then it is likely a View that is going to + // end up having a Design but we haven't gotten to it yet (i.e. method is being called mid-load) + if (sub.Data is not Design and not string) { alsoIgnore.Add(sub); } + + RecursivelyIgnoreAllNonDesignableSubviews(sub, alsoIgnore); } } @@ -433,5 +438,83 @@ private static bool HasNoBorderProperty(this View v) return false; } + /// + /// Returns if is part of + /// a (either directly or embedded sub view of + /// one - e.g. ). + /// + /// + /// + public static bool IsAdornment(this View v) + { + return v is Adornment || v.AnySuperViewIs(); + } + + /// + /// Returns if any of + /// is of type T. + /// + /// + /// + /// + public static bool AnySuperViewIs(this View v) where T : View + { + var parent = v.SuperView; + + while (parent != null) + { + if (parent is T) + { + return true; + } + parent = parent.SuperView; + } + + return false; + } + + /// + /// Returns the of + /// if it is an . Or if is not + /// directly an adornment but then the method + /// will traverse up hierarchy until parent is found. + /// + /// + /// + public static View? GetAdornmentParent(this View v) + { + while (v != null) + { + if (v is Adornment a) + { + return a.Parent; + } + + v = v.SuperView; + } + + return null; + } + + public static void SetupNiceColorSchemes(this Dialog v) + { + + ColorScheme dialogBackground; + ColorScheme buttons; + dialogBackground = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4294967295u, 4285953654u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4294967295u, 4285953654u)); + buttons = new Terminal.Gui.ColorScheme(new Terminal.Gui.Attribute(4285953654u, 4294967295u), new Terminal.Gui.Attribute(4294901760u, 4294967040u), new Terminal.Gui.Attribute(4278190080u, 4294967295u), new Terminal.Gui.Attribute(4278190080u, 4278190080u), new Terminal.Gui.Attribute(4278190080u, 4294967040u)); + v.ColorScheme = dialogBackground; + + void ApplyScheme(View view) + { + if (view is Button or TableView) + view.ColorScheme = buttons; + + foreach (var subView in view.SubViews) + ApplyScheme(subView); + } + + ApplyScheme(v); + } } diff --git a/src/ViewFactory.cs b/src/ViewFactory.cs index 8b8b3154..0a82f48e 100644 --- a/src/ViewFactory.cs +++ b/src/ViewFactory.cs @@ -35,7 +35,6 @@ public static class ViewFactory typeof( FileDialog ), typeof( SaveDialog ), typeof( OpenDialog ), - typeof( ScrollBarView ), // BUG These seem to cause stack overflows in CreateSubControlDesigns (see TestAddView_RoundTrip) typeof( Wizard ), @@ -47,6 +46,16 @@ public static class ViewFactory // This is unstable when added directly as a view see https://github.com/gui-cs/Terminal.Gui/issues/3664 typeof(Shortcut), + typeof(Tab), + typeof(CharMap), + typeof(LegendAnnotation), + typeof(Menuv2), + typeof(ScrollBar), + typeof(ScrollSlider), + typeof(TileView), + + // Terminal.Gui combo boxes do not really work properly + typeof(ComboBox) ]; /// @@ -92,7 +101,7 @@ internal static MenuBarItem[] DefaultMenuBarItems private static bool IsSupportedType( this Type t ) { - return t == typeof( Window ) || ( !KnownUnsupportedTypes.Any( t.IsSubclassOf ) & !KnownUnsupportedTypes.Contains( t ) ); + return t == typeof( Window ) ||!KnownUnsupportedTypes.Contains( t ); } /// @@ -134,13 +143,15 @@ public static T Create(int? width = null, int? height = null, string? text = switch ( newView ) { + case TimeField: + SetDefaultDimensions(newView, width ?? 9, height ?? 1); + break; case Button: case CheckBox: case ComboBox: case Label: - newView.SetActualText( text ?? "Heya" ); - SetDefaultDimensions( newView, width ?? 4, height ?? 1 ); - newView.Width = Dim.Auto(); + newView.SetActualText(text ?? "Heya"); + SetDefaultDimensionsDimAuto(newView); break; case ColorPicker: newView.Width = width ?? 20; @@ -245,9 +256,8 @@ public static T Create(int? width = null, int? height = null, string? text = SetDefaultDimensions(newView, width ?? 16, height ?? 5); break; - case ScrollView sv: - sv.SetContentSize(new Size( 20, 10 )); - SetDefaultDimensions(newView, width ?? 10, height ?? 5 ); + case DatePicker: + // Use defaults break; case SpinnerView sv: sv.AutoSpin = true; @@ -271,9 +281,9 @@ public static T Create(int? width = null, int? height = null, string? text = SetDefaultDimensions(newView, 10, 5); break; case null: - throw new InvalidOperationException( $"Unexpected null result from type {typeof( T ).Name} construtor." ); + throw new InvalidOperationException( $"Unexpected null result from type {typeof( T ).Name} constructor." ); } - + return newView; static void SetDefaultDimensions( T v, int width = 5, int height = 1 ) @@ -282,8 +292,14 @@ static void SetDefaultDimensions( T v, int width = 5, int height = 1 ) v.Height = v.Height is DimFill ? height : Math.Max( v.GetContentSize().Height, height ); } + static void SetDefaultDimensionsDimAuto(T v) + { + v.Width = Dim.Auto(); + v.Height = Dim.Auto(); + } } + /// /// Creates a new instance of of with /// size/placeholder values that make it easy to see and design in the editor. @@ -309,6 +325,7 @@ public static View Create( Type requestedType ) return requestedType switch { null => throw new ArgumentNullException( nameof( requestedType ) ), + { } t when t == typeof(TimeField) => Create(), { } t when t == typeof( DateField ) => Create( ), { } t when t == typeof( Button ) => Create