From f013627a24c1de705db8c44443c5c37f93f075e8 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 18 Dec 2021 13:54:54 +0000 Subject: [PATCH] Fixes #1535. Added IsMouseDisabled prop to Application (#1546) --- Terminal.Gui/Core/Application.cs | 9 +++++++++ UICatalog/UICatalog.cs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index e09d6f8c5..9526c64bb 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -159,6 +159,11 @@ namespace Terminal.Gui { /// The main loop. public static MainLoop MainLoop { get; private set; } + /// + /// Disable or enable the mouse in this + /// + public static bool IsMouseDisabled { get; set; } + /// /// This event is raised on each iteration of the /// @@ -523,6 +528,10 @@ namespace Terminal.Gui { static void ProcessMouseEvent (MouseEvent me) { + if (IsMouseDisabled) { + return; + } + var view = FindDeepestView (Current, me.X, me.Y, out int rx, out int ry); if (view != null && view.WantContinuousButtonPressed) diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 3dc1d9f59..ee011a0bf 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -312,9 +312,26 @@ namespace UICatalog { menuItems.Add (new MenuItem [] { null }); menuItems.Add (CreateSizeStyle ()); menuItems.Add (CreateAlwaysSetPosition ()); + menuItems.Add (CreateDisabledEnabledMouse ()); return menuItems; } + private static MenuItem [] CreateDisabledEnabledMouse () + { + List menuItems = new List (); + var item = new MenuItem (); + item.Title = "_Disable/Enable Mouse"; + item.Shortcut = Key.CtrlMask | Key.AltMask | (Key)item.Title.ToString ().Substring (1, 1) [0]; + item.CheckType |= MenuItemCheckStyle.Checked; + item.Checked = Application.IsMouseDisabled; + item.Action += () => { + item.Checked = Application.IsMouseDisabled = !item.Checked; + }; + menuItems.Add (item); + + return menuItems.ToArray (); + } + static MenuItem [] CreateAlwaysSetPosition () { List menuItems = new List ();