diff --git a/Examples/Example/Example.cs b/Examples/Example/Example.cs index d3e02a342c..735cfe3ff8 100644 --- a/Examples/Example/Example.cs +++ b/Examples/Example/Example.cs @@ -67,7 +67,7 @@ public ExampleWindow () // center the login button horizontally X = Pos.Center (), - IsDefault = true + IsDefaultAcceptView = true }; // When login button is clicked display a message popup diff --git a/Examples/NativeAot/Program.cs b/Examples/NativeAot/Program.cs index bfc566c6d3..1a2a33ec31 100644 --- a/Examples/NativeAot/Program.cs +++ b/Examples/NativeAot/Program.cs @@ -93,7 +93,7 @@ public ExampleWindow () // center the login button horizontally X = Pos.Center (), - IsDefault = true + IsDefaultAcceptView = true }; // When login button is clicked display a message popup diff --git a/Examples/SelfContained/Program.cs b/Examples/SelfContained/Program.cs index 2cfdb8cc94..170030651e 100644 --- a/Examples/SelfContained/Program.cs +++ b/Examples/SelfContained/Program.cs @@ -92,7 +92,7 @@ public ExampleWindow () // center the login button horizontally X = Pos.Center (), - IsDefault = true + IsDefaultAcceptView = true }; // When login button is clicked display a message popup diff --git a/Examples/UICatalog/Scenarios/AllViewsTester.cs b/Examples/UICatalog/Scenarios/AllViewsTester.cs index 71d9edbe56..e9f0efb8f5 100644 --- a/Examples/UICatalog/Scenarios/AllViewsTester.cs +++ b/Examples/UICatalog/Scenarios/AllViewsTester.cs @@ -158,16 +158,13 @@ public override void Main () _eventLog = new () { - // X = Pos.Right(_layoutEditor), + X = Pos.AnchorEnd () - 1, + Y = 0, + Width = 30, + Height = Dim.Fill (), SuperViewRendersLineCanvas = true }; _eventLog.Border!.Thickness = new (1); - _eventLog.X = Pos.AnchorEnd () - 1; - _eventLog.Y = 0; - - _eventLog.Height = Dim.Height (_classListView); - - //_eventLog.Width = 30; _layoutEditor.Width = Dim.Fill ( Dim.Func ( @@ -194,7 +191,6 @@ public override void Main () Height = Dim.Fill (), CanFocus = true, TabStop = TabBehavior.TabStop, - //SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Base), Arrangement = ViewArrangement.LeftResizable | ViewArrangement.BottomResizable | ViewArrangement.RightResizable, BorderStyle = LineStyle.Double, SuperViewRendersLineCanvas = true @@ -228,7 +224,7 @@ private void CreateCurrentView (Type type) if (type.IsGenericType) { // For each of the arguments - List typeArguments = new (); + List typeArguments = []; // use or the original type if applicable foreach (Type arg in type.GetGenericArguments ()) diff --git a/Examples/UICatalog/Scenarios/AnsiRequestsScenario.cs b/Examples/UICatalog/Scenarios/AnsiRequestsScenario.cs index 9a68b25670..d12dd5bd48 100644 --- a/Examples/UICatalog/Scenarios/AnsiRequestsScenario.cs +++ b/Examples/UICatalog/Scenarios/AnsiRequestsScenario.cs @@ -149,7 +149,7 @@ private View BuildSingleTab () var tvTerminator = new TextView { X = Pos.Left (label), Y = Pos.Bottom (label), Width = 4, Height = 4, ReadOnly = true }; w.Add (label, tvTerminator); - var btnResponse = new Button { X = Pos.Center (), Y = Pos.Bottom (tvResponse) + 2, Text = "Send Request", IsDefault = true }; + var btnResponse = new Button { X = Pos.Center (), Y = Pos.Bottom (tvResponse) + 2, Text = "Send Request", IsDefaultAcceptView = true }; var lblSuccess = new Label { X = Pos.Center (), Y = Pos.Bottom (btnResponse) + 1 }; w.Add (lblSuccess); diff --git a/Examples/UICatalog/Scenarios/Bars.cs b/Examples/UICatalog/Scenarios/Bars.cs index 226e18e26a..336e92ee5f 100644 --- a/Examples/UICatalog/Scenarios/Bars.cs +++ b/Examples/UICatalog/Scenarios/Bars.cs @@ -185,9 +185,9 @@ void PopOverMenuOnAccept (object o, CommandEventArgs args) menuLikeExamples.Add (popOverMenu); - menuLikeExamples.MouseClick += MenuLikeExamplesMouseClick; + menuLikeExamples.MouseEvent += MenuLikeExamplesMouseEvent; - void MenuLikeExamplesMouseClick (object sender, MouseEventArgs e) + void MenuLikeExamplesMouseEvent (object _, MouseEventArgs e) { if (e.Flags.HasFlag (MouseFlags.Button3Clicked)) { diff --git a/Examples/UICatalog/Scenarios/Buttons.cs b/Examples/UICatalog/Scenarios/Buttons.cs index b4c921437d..b928718786 100644 --- a/Examples/UICatalog/Scenarios/Buttons.cs +++ b/Examples/UICatalog/Scenarios/Buttons.cs @@ -20,17 +20,17 @@ public override void Main () Title = GetQuitKeyAndName () }; - // Add a label & text field so we can demo IsDefault - var editLabel = new Label { X = 0, Y = 0, Text = "TextField (to demo IsDefault):" }; + // Add a label & text field so we can demo IsDefaultAcceptView + var editLabel = new Label { X = 0, Y = 0, Text = "TextField (to demo IsDefaultAcceptView):" }; main.Add (editLabel); // Add a TextField using Absolute layout. var edit = new TextField { X = 31, Width = 15, HotKey = Key.Y.WithAlt }; main.Add (edit); - // This is the default button (IsDefault = true); if user presses ENTER in the TextField + // This is the default button (IsDefaultAcceptView = true); if user presses ENTER in the TextField // the scenario will quit - var defaultButton = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), IsDefault = true, Text = "_Quit" }; + var defaultButton = new Button { X = Pos.Center (), Y = Pos.AnchorEnd (), IsDefaultAcceptView = true, Text = "_Quit" }; main.Add (defaultButton); @@ -48,14 +48,14 @@ public override void Main () swapButton.Accepting += (s, e) => { - e.Handled = !swapButton.IsDefault; - defaultButton.IsDefault = !defaultButton.IsDefault; - swapButton.IsDefault = !swapButton.IsDefault; + e.Handled = !swapButton.IsDefaultAcceptView; + defaultButton.IsDefaultAcceptView = !defaultButton.IsDefaultAcceptView; + swapButton.IsDefaultAcceptView = !swapButton.IsDefaultAcceptView; }; defaultButton.Accepting += (s, e) => { - e.Handled = !defaultButton.IsDefault; + e.Handled = !defaultButton.IsDefaultAcceptView; if (e.Handled) { diff --git a/Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs b/Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs index 4e7679b6bc..c551206b6b 100644 --- a/Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs +++ b/Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs @@ -106,9 +106,15 @@ public override void Main () _categoryList.Table = CreateCategoryTable (0, isDescending); - // if user clicks the mouse in TableView - _categoryList.MouseClick += (s, e) => + // if user clicks the mouse in TableView, change sorting by that column + _categoryList.Activating += (s, commandEventArgs) => { + if (commandEventArgs.Context is not CommandContext mouseContext) + { + return; + } + + MouseEventArgs e = mouseContext.Binding.MouseEventArgs!; _categoryList.ScreenToCell (e.Position, out int? clickedCol); if (clickedCol != null && e.Flags.HasFlag (MouseFlags.Button1Clicked)) diff --git a/Examples/UICatalog/Scenarios/ContextMenus.cs b/Examples/UICatalog/Scenarios/ContextMenus.cs index 141392f292..2ff0de2292 100644 --- a/Examples/UICatalog/Scenarios/ContextMenus.cs +++ b/Examples/UICatalog/Scenarios/ContextMenus.cs @@ -3,7 +3,7 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("ContextMenus", "Context Menu Sample.")] +[ScenarioMetadata ("ContextMenus", "Demonstrates using PopoverMenu as a Context Menu.")] [ScenarioCategory ("Menus")] public class ContextMenus : Scenario { @@ -26,6 +26,21 @@ public override void Main () SchemeName = "Toplevel" }; + // Create keyboard and mouse bindings for the context menu. + appWindow.KeyBindings.Add (_winContextMenuKey, Command.Context); + appWindow.MouseBindings.Add (MouseFlags.Button3Clicked, Command.Context); + + // View.AddCommand is protected; but we can use the CommandNotBound event to handle Command.Context + appWindow.CommandNotBound += (s, e) => + { + if (e.Context!.Command == Command.Context) + { + // ReSharper disable once AccessToDisposedClosure + _winContextMenu?.MakeVisible (); + e.Handled = true; + } + }; + var text = "Context Menu"; var width = 20; @@ -60,43 +75,16 @@ public override void Main () _tfBottomRight = new () { Id = "_tfBottomRight", X = Pos.AnchorEnd (width), Y = Pos.AnchorEnd (1), Width = width, Text = text }; appWindow.Add (_tfBottomRight); - appWindow.KeyDown += OnAppWindowOnKeyDown; - appWindow.MouseClick += OnAppWindowOnMouseClick; - CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture; appWindow.Closed += (s, e) => { Thread.CurrentThread.CurrentUICulture = originalCulture; }; // Run - Start the application. Application.Run (appWindow); appWindow.Dispose (); - appWindow.KeyDown -= OnAppWindowOnKeyDown; - appWindow.MouseClick -= OnAppWindowOnMouseClick; _winContextMenu?.Dispose (); // Shutdown - Calling Application.Shutdown is required. Application.Shutdown (); - - return; - - void OnAppWindowOnMouseClick (object s, MouseEventArgs e) - { - if (e.Flags == MouseFlags.Button3Clicked) - { - // ReSharper disable once AccessToDisposedClosure - _winContextMenu?.MakeVisible (e.ScreenPosition); - e.Handled = true; - } - } - - void OnAppWindowOnKeyDown (object s, Key e) - { - if (e == _winContextMenuKey) - { - // ReSharper disable once AccessToDisposedClosure - _winContextMenu?.MakeVisible (); - e.Handled = true; - } - } } private void CreateWinContextMenu () @@ -182,7 +170,12 @@ private Menuv2 GetSupportedCultureMenu () { MenuItemv2 culture = new (); - culture.CommandView = new CheckBox { CanFocus = false }; + culture.CommandView = new CheckBox + { + // Best practice for CheckBoxes in menus is to disable focus and highlight states + CanFocus = false, + HighlightStates = MouseState.None + }; if (index == -1) { @@ -198,7 +191,12 @@ private Menuv2 GetSupportedCultureMenu () index++; culture = new (); - culture.CommandView = new CheckBox { CanFocus = false }; + culture.CommandView = new CheckBox + { + // Best practice for CheckBoxes in menus is to disable focus and highlight states + CanFocus = false, + HighlightStates = MouseState.None + }; } culture.Id = $"_{c.Parent.EnglishName}"; diff --git a/Examples/UICatalog/Scenarios/CsvEditor.cs b/Examples/UICatalog/Scenarios/CsvEditor.cs index 609cb4e06b..575d692a23 100644 --- a/Examples/UICatalog/Scenarios/CsvEditor.cs +++ b/Examples/UICatalog/Scenarios/CsvEditor.cs @@ -301,7 +301,7 @@ private bool GetText (string title, string label, string initialText, out string { var okPressed = false; - var ok = new Button { Text = "Ok", IsDefault = true }; + var ok = new Button { Text = "Ok", IsDefaultAcceptView = true }; ok.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/Dialogs.cs b/Examples/UICatalog/Scenarios/Dialogs.cs index 949b45d4ad..6ae5d66152 100644 --- a/Examples/UICatalog/Scenarios/Dialogs.cs +++ b/Examples/UICatalog/Scenarios/Dialogs.cs @@ -151,18 +151,16 @@ public override void Main () }; frame.Add (label); - // Add hotkeys - var labels = Enum.GetNames ().Select (n => n = "_" + n); - var alignmentGroup = new RadioGroup + List labels = Enum.GetNames ().Select (n => n = "_" + n).ToList (); + OptionSelector alignmentGroup = new () { X = Pos.Right (label) + 1, Y = Pos.Top (label), - RadioLabels = labels.ToArray (), Title = "Ali_gn", - BorderStyle = LineStyle.Dashed + Labels = labels, }; frame.Add (alignmentGroup); - alignmentGroup.SelectedItem = labels.ToList ().IndexOf ("_" + Dialog.DefaultButtonAlignment.ToString ()); + alignmentGroup.Value = labels.IndexOf ("_" + Dialog.DefaultButtonAlignment.ToString ()); frame.ValidatePosDim = true; @@ -181,7 +179,7 @@ public override void Main () var showDialogButton = new Button { - X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "_Show Dialog" + X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefaultAcceptView = true, Text = "_Show Dialog" }; app.Accepting += (s, e) => @@ -216,7 +214,7 @@ private Dialog CreateDemoDialog ( TextField titleEdit, TextField numButtonsEdit, CheckBox glyphsNotWords, - RadioGroup alignmentRadioGroup, + OptionSelector alignmentGroup, Label buttonPressedLabel ) { @@ -246,12 +244,12 @@ Label buttonPressedLabel button = new () { Text = "_" + NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), - IsDefault = buttonId == 0 + IsDefaultAcceptView = buttonId == 0 }; } else { - button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; + button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefaultAcceptView = buttonId == 0 }; } button.Accepting += (s, e) => @@ -269,7 +267,7 @@ Label buttonPressedLabel { Title = titleEdit.Text, Text = "Dialog Text", - ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentRadioGroup.RadioLabels [alignmentRadioGroup.SelectedItem].Substring (1)), + ButtonAlignment = (Alignment)Enum.Parse (typeof (Alignment), alignmentGroup.Labels! [(int)alignmentGroup.Value!.Value] [1..]), Buttons = buttons.ToArray () }; @@ -300,12 +298,12 @@ Label buttonPressedLabel button = new () { Text = "_" + NumberToWords.Convert (buttonId) + " " + char.ConvertFromUtf32 (buttonId + CODE_POINT), - IsDefault = buttonId == 0 + IsDefaultAcceptView = buttonId == 0 }; } else { - button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefault = buttonId == 0 }; + button = new () { Text = "_" + NumberToWords.Convert (buttonId), IsDefaultAcceptView = buttonId == 0 }; } button.Accepting += (s, e) => diff --git a/Examples/UICatalog/Scenarios/DynamicMenuBar.cs b/Examples/UICatalog/Scenarios/DynamicMenuBar.cs index fc61a7a3b6..9cdef76a0b 100644 --- a/Examples/UICatalog/Scenarios/DynamicMenuBar.cs +++ b/Examples/UICatalog/Scenarios/DynamicMenuBar.cs @@ -391,7 +391,7 @@ public DynamicMenuItem EnterMenuItem () EditMenuBarItem (_menuItem); } - var btnOk = new Button { IsDefault = true, Text = "Ok" }; + var btnOk = new Button { IsDefaultAcceptView = true, Text = "Ok" }; btnOk.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/DynamicStatusBar.cs b/Examples/UICatalog/Scenarios/DynamicStatusBar.cs index de110d0c6f..8fe4059a91 100644 --- a/Examples/UICatalog/Scenarios/DynamicStatusBar.cs +++ b/Examples/UICatalog/Scenarios/DynamicStatusBar.cs @@ -178,7 +178,7 @@ public DynamicStatusItem EnterStatusItem () EditStatusItem (_statusItem); } - var btnOk = new Button { IsDefault = true, Text = "OK" }; + var btnOk = new Button { IsDefaultAcceptView = true, Text = "OK" }; btnOk.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/Editor.cs b/Examples/UICatalog/Scenarios/Editor.cs index b005fec552..4bbd03af37 100644 --- a/Examples/UICatalog/Scenarios/Editor.cs +++ b/Examples/UICatalog/Scenarios/Editor.cs @@ -894,7 +894,7 @@ private View CreateFindTab () X = Pos.Align (Alignment.Center), Y = Pos.AnchorEnd (), Enabled = !string.IsNullOrEmpty (txtToFind.Text), - IsDefault = true, + IsDefaultAcceptView = true, Text = "Find _Next" }; @@ -1122,7 +1122,7 @@ private View CreateReplaceTab () X = Pos.Align (Alignment.Center), Y = Pos.AnchorEnd (), Enabled = !string.IsNullOrEmpty (txtToFind.Text), - IsDefault = true, + IsDefaultAcceptView = true, Text = "Replace _Next" }; btnFindNext.Accepting += (s, e) => ReplaceNext (); diff --git a/Examples/UICatalog/Scenarios/EditorsAndHelpers/AllViewsView.cs b/Examples/UICatalog/Scenarios/EditorsAndHelpers/AllViewsView.cs index 862cc20837..3e0f216b16 100644 --- a/Examples/UICatalog/Scenarios/EditorsAndHelpers/AllViewsView.cs +++ b/Examples/UICatalog/Scenarios/EditorsAndHelpers/AllViewsView.cs @@ -56,7 +56,6 @@ public AllViewsView () KeyBindings.Add (Key.End, Command.End); KeyBindings.Add (PopoverMenu.DefaultKey, Command.Context); - MouseBindings.Add (MouseFlags.Button1DoubleClicked, Command.Accept); MouseBindings.ReplaceCommands (MouseFlags.Button3Clicked, Command.Context); MouseBindings.ReplaceCommands (MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl, Command.Context); MouseBindings.Add (MouseFlags.WheeledDown, Command.ScrollDown); diff --git a/Examples/UICatalog/Scenarios/EditorsAndHelpers/ArrangementEditor.cs b/Examples/UICatalog/Scenarios/EditorsAndHelpers/ArrangementEditor.cs index 6d262ef2e3..ec92620baa 100644 --- a/Examples/UICatalog/Scenarios/EditorsAndHelpers/ArrangementEditor.cs +++ b/Examples/UICatalog/Scenarios/EditorsAndHelpers/ArrangementEditor.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.Collections.Generic; +using Terminal.Gui.ViewBase; namespace UICatalog.Scenarios; @@ -16,92 +17,67 @@ public ArrangementEditor () Initialized += ArrangementEditor_Initialized; - _arrangementSlider.Options = - [ - new SliderOption - { - Legend = ViewArrangement.Movable.ToString (), - Data = ViewArrangement.Movable - }, - - new SliderOption - { - Legend = ViewArrangement.LeftResizable.ToString (), - Data = ViewArrangement.LeftResizable - }, - - new SliderOption - { - Legend = ViewArrangement.RightResizable.ToString (), - Data = ViewArrangement.RightResizable - }, - - new SliderOption - { - Legend = ViewArrangement.TopResizable.ToString (), - Data = ViewArrangement.TopResizable - }, - - new SliderOption - { - Legend = ViewArrangement.BottomResizable.ToString (), - Data = ViewArrangement.BottomResizable - }, - - new SliderOption - { - Legend = ViewArrangement.Overlapped.ToString (), - Data = ViewArrangement.Overlapped - } - ]; - - Add (_arrangementSlider); + Add (_arrangementSelector); } - private readonly Slider _arrangementSlider = new() + private readonly FlagSelector _arrangementSelector = new() { Orientation = Orientation.Vertical, - UseMinimumSize = true, - Type = SliderType.Multiple, - AllowEmpty = true, }; protected override void OnViewToEditChanged () { - _arrangementSlider.Enabled = ViewToEdit is not Adornment; + _arrangementSelector.Enabled = ViewToEdit is not Adornment; - _arrangementSlider.OptionsChanged -= ArrangementSliderOnOptionsChanged; + _arrangementSelector.ValueChanged -= ArrangementFlagsOnValueChanged; // Set the appropriate options in the slider based on _viewToEdit.Arrangement if (ViewToEdit is { }) { - _arrangementSlider.Options.ForEach ( - option => - { - _arrangementSlider.ChangeOption ( - _arrangementSlider.Options.IndexOf (option), - (ViewToEdit.Arrangement & option.Data) == option.Data); - }); + _arrangementSelector.Value = ViewToEdit.Arrangement; } - _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; + _arrangementSelector.ValueChanged += ArrangementFlagsOnValueChanged; } - private void ArrangementEditor_Initialized (object? sender, EventArgs e) { _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; } - - private void ArrangementSliderOnOptionsChanged (object? sender, SliderEventArgs e) + private void ArrangementFlagsOnValueChanged (object? sender, EventArgs e) { - if (ViewToEdit is { }) + if (ViewToEdit is { } && e.Value is { }) { - // Set the arrangement based on the selected options - var arrangement = ViewArrangement.Fixed; + ViewToEdit.Arrangement = (ViewArrangement)e.Value; - foreach (KeyValuePair> option in e.Options) + if (ViewToEdit.Arrangement.HasFlag (ViewArrangement.Overlapped)) { - arrangement |= option.Value.Data; + ViewToEdit.ShadowStyle = ShadowStyle.Transparent; + ViewToEdit.SchemeName = "Toplevel"; + } + else + { + ViewToEdit.ShadowStyle = ShadowStyle.None; + ViewToEdit.SchemeName = ViewToEdit!.SuperView!.SchemeName; } - ViewToEdit.Arrangement = arrangement; + if (ViewToEdit.Arrangement.HasFlag (ViewArrangement.Movable)) + { + ViewToEdit.BorderStyle = LineStyle.Double; + } + else + { + ViewToEdit.BorderStyle = LineStyle.Single; + } + } + } + + private void ArrangementEditor_Initialized (object? sender, EventArgs e) + { + _arrangementSelector.ValueChanged += ArrangementFlagsOnValueChanged; + } + + private void ArrangementFlagsOnValueChanged (object? sender, EventArgs e) + { + if (ViewToEdit is { } && e.Value is {}) + { + ViewToEdit.Arrangement = (ViewArrangement)e.Value; if (ViewToEdit.Arrangement.HasFlag (ViewArrangement.Overlapped)) { diff --git a/Examples/UICatalog/Scenarios/EditorsAndHelpers/EventLog.cs b/Examples/UICatalog/Scenarios/EditorsAndHelpers/EventLog.cs index b64acc865e..9f1d60f5a1 100644 --- a/Examples/UICatalog/Scenarios/EditorsAndHelpers/EventLog.cs +++ b/Examples/UICatalog/Scenarios/EditorsAndHelpers/EventLog.cs @@ -79,10 +79,9 @@ public View? ViewToLog Log ($"Initialized: {GetIdentifyingString (sender)}"); }; - _viewToLog.MouseClick += (s, args) => { Log ($"MouseClick: {args}"); }; _viewToLog.MouseWheel += (s, args) => { Log ($"MouseWheel: {args}"); }; _viewToLog.HandlingHotKey += (s, args) => { Log ($"HandlingHotKey: {args.Context}"); }; - _viewToLog.Selecting += (s, args) => { Log ($"Selecting: {args.Context}"); }; + _viewToLog.Activating += (s, args) => { Log ($"Activating: {args.Context}"); }; _viewToLog.Accepting += (s, args) => { Log ($"Accepting: {args.Context}"); }; } } diff --git a/Examples/UICatalog/Scenarios/EditorsAndHelpers/MarginEditor.cs b/Examples/UICatalog/Scenarios/EditorsAndHelpers/MarginEditor.cs index 9bcf2d2137..b4576e36c6 100644 --- a/Examples/UICatalog/Scenarios/EditorsAndHelpers/MarginEditor.cs +++ b/Examples/UICatalog/Scenarios/EditorsAndHelpers/MarginEditor.cs @@ -12,7 +12,7 @@ public MarginEditor () AdornmentChanged += MarginEditor_AdornmentChanged; } - private RadioGroup? _rgShadow; + private OptionSelector? _optionsShadow; private FlagSelector? _flagSelectorTransparent; @@ -20,18 +20,18 @@ private void MarginEditor_AdornmentChanged (object? sender, EventArgs e) { if (AdornmentToEdit is { }) { - _rgShadow!.SelectedItem = (int)((Margin)AdornmentToEdit).ShadowStyle; + _optionsShadow!.Value = ((Margin)AdornmentToEdit).ShadowStyle; } if (AdornmentToEdit is { }) { - _flagSelectorTransparent!.Value = (uint)((Margin)AdornmentToEdit).ViewportSettings; + _flagSelectorTransparent!.Value = (int)((Margin)AdornmentToEdit).ViewportSettings; } } private void MarginEditor_Initialized (object? sender, EventArgs e) { - _rgShadow = new RadioGroup + _optionsShadow = new () { X = 0, Y = Pos.Bottom (SubViews.ElementAt(SubViews.Count-1)), @@ -39,44 +39,39 @@ private void MarginEditor_Initialized (object? sender, EventArgs e) SuperViewRendersLineCanvas = true, Title = "_Shadow", BorderStyle = LineStyle.Single, - RadioLabels = Enum.GetNames (typeof (ShadowStyle)), + AssignHotKeys = true }; if (AdornmentToEdit is { }) { - _rgShadow.SelectedItem = (int)((Margin)AdornmentToEdit).ShadowStyle; + _optionsShadow.SelectedItem = (int)((Margin)AdornmentToEdit).ShadowStyle; } - _rgShadow.SelectedItemChanged += (_, args) => + _optionsShadow.SelectedItemChanged += (_, args) => { ((Margin)AdornmentToEdit!).ShadowStyle = (ShadowStyle)args.SelectedItem!; }; - Add (_rgShadow); + Add (_optionsShadow); - var flags = new Dictionary () - { - { (uint)Terminal.Gui.ViewBase.ViewportSettingsFlags.Transparent, "Transparent" }, - { (uint)Terminal.Gui.ViewBase.ViewportSettingsFlags.TransparentMouse, "TransparentMouse" } - }; - - _flagSelectorTransparent = new FlagSelector () + _flagSelectorTransparent = new FlagSelector () { X = 0, - Y = Pos.Bottom (_rgShadow), + Y = Pos.Bottom (_optionsShadow), SuperViewRendersLineCanvas = true, Title = "_ViewportSettings", BorderStyle = LineStyle.Single, }; - _flagSelectorTransparent.SetFlags(flags.AsReadOnly ()); - + _flagSelectorTransparent.Values = [(int)ViewportSettingsFlags.Transparent, (int)ViewportSettingsFlags.TransparentMouse]; + _flagSelectorTransparent.Labels = ["Transparent", "TransparentMouse"]; + _flagSelectorTransparent.AssignHotKeys = true; Add (_flagSelectorTransparent); if (AdornmentToEdit is { }) { - _flagSelectorTransparent.Value = (uint)((Margin)AdornmentToEdit).ViewportSettings; + _flagSelectorTransparent.Value = (int)((Margin)AdornmentToEdit).ViewportSettings; } _flagSelectorTransparent.ValueChanged += (_, args) => diff --git a/Examples/UICatalog/Scenarios/EditorsAndHelpers/ThemeViewer.cs b/Examples/UICatalog/Scenarios/EditorsAndHelpers/ThemeViewer.cs index 0141cbfc9d..637c78aebb 100644 --- a/Examples/UICatalog/Scenarios/EditorsAndHelpers/ThemeViewer.cs +++ b/Examples/UICatalog/Scenarios/EditorsAndHelpers/ThemeViewer.cs @@ -65,7 +65,6 @@ public ThemeViewer () KeyBindings.Add (Key.End, Command.End); KeyBindings.Add (PopoverMenu.DefaultKey, Command.Context); - MouseBindings.Add (MouseFlags.Button1DoubleClicked, Command.Accept); MouseBindings.ReplaceCommands (MouseFlags.Button3Clicked, Command.Context); MouseBindings.ReplaceCommands (MouseFlags.Button1Clicked | MouseFlags.ButtonCtrl, Command.Context); MouseBindings.Add (MouseFlags.WheeledDown, Command.ScrollDown); diff --git a/Examples/UICatalog/Scenarios/FileDialogExamples.cs b/Examples/UICatalog/Scenarios/FileDialogExamples.cs index 10dcf8c35e..158a9eda97 100644 --- a/Examples/UICatalog/Scenarios/FileDialogExamples.cs +++ b/Examples/UICatalog/Scenarios/FileDialogExamples.cs @@ -126,7 +126,7 @@ public override void Main () _cbFlipButtonOrder = new CheckBox { X = x, Y = y++, Text = "Flip Ord_er" }; win.Add (_cbFlipButtonOrder); - var btn = new Button { X = 1, Y = 9, IsDefault = true, Text = "Run Dialog" }; + var btn = new Button { X = 1, Y = 9, IsDefaultAcceptView = true, Text = "Run Dialog" }; win.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/Generic.cs b/Examples/UICatalog/Scenarios/Generic.cs index f0da0dd537..4b6a72da90 100644 --- a/Examples/UICatalog/Scenarios/Generic.cs +++ b/Examples/UICatalog/Scenarios/Generic.cs @@ -15,20 +15,28 @@ public override void Main () Window appWindow = new () { Title = GetQuitKeyAndName (), - BorderStyle = LineStyle.None + BorderStyle = LineStyle.None, + InvertFocusAttribute = true }; - var button = new Button () + + + var button = new CheckBox () { X = Pos.Center (), Y = 1, Title = "_Button", + + // Comment this out to see how Issue #4170 is about IsDefaultAcceptView not working with Accepting event. + // IsDefaultAcceptView = true, + //SchemeName = "Error" }; button.Accepting += (s, e) => { // When Accepting is handled, set e.Handled to true to prevent further processing. - e.Handled = true; + //e.Handled = true; + Logging.Debug ($"button.Acccepting"); MessageBox.ErrorQuery ("Error", "You pressed the button!", "_Ok"); }; diff --git a/Examples/UICatalog/Scenarios/InteractiveTree.cs b/Examples/UICatalog/Scenarios/InteractiveTree.cs index c3b414901c..4e92b9c96e 100644 --- a/Examples/UICatalog/Scenarios/InteractiveTree.cs +++ b/Examples/UICatalog/Scenarios/InteractiveTree.cs @@ -79,7 +79,7 @@ private bool GetText (string title, string label, string initialText, out string { var okPressed = false; - var ok = new Button { Text = "Ok", IsDefault = true }; + var ok = new Button { Text = "Ok", IsDefaultAcceptView = true }; ok.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/LineDrawing.cs b/Examples/UICatalog/Scenarios/LineDrawing.cs index 46f51dda7f..87c6216724 100644 --- a/Examples/UICatalog/Scenarios/LineDrawing.cs +++ b/Examples/UICatalog/Scenarios/LineDrawing.cs @@ -146,7 +146,7 @@ public static bool PromptForColor (string title, Color current, out Color newCol Y = Application.Force16Colors ? 6 : 4, Text = "Ok", Width = Dim.Auto (), - IsDefault = true + IsDefaultAcceptView = true }; btnOk.Accepting += (s, e) => diff --git a/Examples/UICatalog/Scenarios/ListColumns.cs b/Examples/UICatalog/Scenarios/ListColumns.cs index 402e2944db..70462e764f 100644 --- a/Examples/UICatalog/Scenarios/ListColumns.cs +++ b/Examples/UICatalog/Scenarios/ListColumns.cs @@ -245,9 +245,6 @@ public override void Main () Normal = new (Color.White, Color.BrightBlue) }; - // if user clicks the mouse in TableView - _listColView.MouseClick += (s, e) => { _listColView.ScreenToCell (e.Position, out int? clickedCol); }; - _listColView.KeyBindings.ReplaceCommands (Key.Space, Command.Accept); top.Add (menu, appWindow, statusBar); @@ -269,7 +266,7 @@ public override void Main () private void RunListWidthDialog (string prompt, Action setter, Func getter) { var accepted = false; - var ok = new Button { Text = "Ok", IsDefault = true }; + var ok = new Button { Text = "Ok", IsDefaultAcceptView = true }; ok.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/ListViewWithSelection.cs b/Examples/UICatalog/Scenarios/ListViewWithSelection.cs index 123e4d54a5..f25ed9e0b6 100644 --- a/Examples/UICatalog/Scenarios/ListViewWithSelection.cs +++ b/Examples/UICatalog/Scenarios/ListViewWithSelection.cs @@ -105,7 +105,7 @@ public override void Main () _listView.OpenSelectedItem += (s, a) => LogEvent (s as View, a, "OpenSelectedItem"); _listView.CollectionChanged += (s, a) => LogEvent (s as View, a, "CollectionChanged"); _listView.Accepting += (s, a) => LogEvent (s as View, a, "Accept"); - _listView.Selecting += (s, a) => LogEvent (s as View, a, "Select"); + _listView.Activating += (s, a) => LogEvent (s as View, a, "Activating"); _listView.VerticalScrollBar.AutoShow = true; _listView.HorizontalScrollBar.AutoShow = true; diff --git a/Examples/UICatalog/Scenarios/MenuBarScenario.cs b/Examples/UICatalog/Scenarios/MenuBarScenario.cs index e61438767f..91a86076d9 100644 --- a/Examples/UICatalog/Scenarios/MenuBarScenario.cs +++ b/Examples/UICatalog/Scenarios/MenuBarScenario.cs @@ -108,7 +108,7 @@ bool FnAction (string s) // There's no focus change event, so this is a bit of a hack. menuBar.SubViewsLaidOut += (s, e) => { _focusedView.Text = appWindow.MostFocused?.ToString () ?? "None"; }; - var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefault = true }; + var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefaultAcceptView = true }; openBtn.Accepting += (s, e) => { menuBar.OpenMenu (); }; appWindow.Add (openBtn); diff --git a/Examples/UICatalog/Scenarios/Menus.cs b/Examples/UICatalog/Scenarios/Menus.cs index 70f67f6e29..8f822d4adc 100644 --- a/Examples/UICatalog/Scenarios/Menus.cs +++ b/Examples/UICatalog/Scenarios/Menus.cs @@ -358,7 +358,7 @@ public MenuHost () }; // Add a button to open the contextmenu - var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefault = true }; + var openBtn = new Button { X = Pos.Center (), Y = 4, Text = "_Open Menu", IsDefaultAcceptView = true }; openBtn.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/MessageBoxes.cs b/Examples/UICatalog/Scenarios/MessageBoxes.cs index 71dde85e2d..d490a00fe4 100644 --- a/Examples/UICatalog/Scenarios/MessageBoxes.cs +++ b/Examples/UICatalog/Scenarios/MessageBoxes.cs @@ -182,11 +182,12 @@ public override void Main () }; frame.Add (label); - var styleRadioGroup = new RadioGroup + var styleRadioGroup = new OptionSelector () { - X = Pos.Right (label) + 1, - Y = Pos.Top (label), - RadioLabels = ["_Query", "_Error"], + X = Pos.Right (label) + 1, + Y = Pos.Top (label), + Labels = ["_Query", "_Error"], + Title = "Sty_le" }; frame.Add (styleRadioGroup); @@ -227,7 +228,7 @@ public override void Main () var showMessageBoxButton = new Button { - X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefault = true, Text = "_Show MessageBox" + X = Pos.Center (), Y = Pos.Bottom (frame) + 2, IsDefaultAcceptView = true, Text = "_Show MessageBox" }; app.Accepting += (s, e) => diff --git a/Examples/UICatalog/Scenarios/Mouse.cs b/Examples/UICatalog/Scenarios/Mouse.cs index 658789cf6e..0e35abd6d0 100644 --- a/Examples/UICatalog/Scenarios/Mouse.cs +++ b/Examples/UICatalog/Scenarios/Mouse.cs @@ -302,10 +302,17 @@ void DemoPaddingOnInitialized (object o, EventArgs eventArgs) } }; - win.MouseClick += (sender, a) => + win.Activating += (sender, commandEventArgs) => { - winLogList.Add ($"MouseClick: ({a.Position}) - {a.Flags} {count++}"); + if (commandEventArgs.Context is not CommandContext mouseContext) + { + return; + } + + MouseEventArgs e = mouseContext.Binding.MouseEventArgs!; + winLogList.Add ($"Activating: ({e.Position}) - {e.Flags} {count++}"); winLog.MoveDown (); + commandEventArgs.Handled = true; }; Application.Run (win); diff --git a/Examples/UICatalog/Scenarios/MultiColouredTable.cs b/Examples/UICatalog/Scenarios/MultiColouredTable.cs index cf013f86c0..729f078c33 100644 --- a/Examples/UICatalog/Scenarios/MultiColouredTable.cs +++ b/Examples/UICatalog/Scenarios/MultiColouredTable.cs @@ -101,7 +101,7 @@ private bool GetText (string title, string label, string initialText, out string { var okPressed = false; - var ok = new Button { Text = "Ok", IsDefault = true }; + var ok = new Button { Text = "Ok", IsDefaultAcceptView = true }; ok.Accepting += (s, e) => { diff --git a/Examples/UICatalog/Scenarios/Navigation.cs b/Examples/UICatalog/Scenarios/Navigation.cs index 7a3390c6fc..f6da2f11f5 100644 --- a/Examples/UICatalog/Scenarios/Navigation.cs +++ b/Examples/UICatalog/Scenarios/Navigation.cs @@ -1,5 +1,6 @@ using System.Text; using System.Timers; +using Timer = System.Timers.Timer; namespace UICatalog.Scenarios; @@ -75,6 +76,8 @@ public override void Main () testFrame.Add (tiledView3); View overlappedView1 = CreateOverlappedView (2, 10, Pos.Center ()); + // Set the button to CanFocus = false to illustrate https://github.com/gui-cs/Terminal.Gui/issues/4179 + overlappedView1.SubViews.OfType