Skip to content

Commit f013627

Browse files
authored
Fixes #1535. Added IsMouseDisabled prop to Application (#1546)
1 parent 239191c commit f013627

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Terminal.Gui/Core/Application.cs

+9
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public static bool AlwaysSetPosition {
159159
/// <value>The main loop.</value>
160160
public static MainLoop MainLoop { get; private set; }
161161

162+
/// <summary>
163+
/// Disable or enable the mouse in this <see cref="Application"/>
164+
/// </summary>
165+
public static bool IsMouseDisabled { get; set; }
166+
162167
/// <summary>
163168
/// This event is raised on each iteration of the <see cref="MainLoop"/>
164169
/// </summary>
@@ -523,6 +528,10 @@ public static void UngrabMouse ()
523528

524529
static void ProcessMouseEvent (MouseEvent me)
525530
{
531+
if (IsMouseDisabled) {
532+
return;
533+
}
534+
526535
var view = FindDeepestView (Current, me.X, me.Y, out int rx, out int ry);
527536

528537
if (view != null && view.WantContinuousButtonPressed)

UICatalog/UICatalog.cs

+17
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,26 @@ static List<MenuItem []> CreateDiagnosticMenuItems ()
312312
menuItems.Add (new MenuItem [] { null });
313313
menuItems.Add (CreateSizeStyle ());
314314
menuItems.Add (CreateAlwaysSetPosition ());
315+
menuItems.Add (CreateDisabledEnabledMouse ());
315316
return menuItems;
316317
}
317318

319+
private static MenuItem [] CreateDisabledEnabledMouse ()
320+
{
321+
List<MenuItem> menuItems = new List<MenuItem> ();
322+
var item = new MenuItem ();
323+
item.Title = "_Disable/Enable Mouse";
324+
item.Shortcut = Key.CtrlMask | Key.AltMask | (Key)item.Title.ToString ().Substring (1, 1) [0];
325+
item.CheckType |= MenuItemCheckStyle.Checked;
326+
item.Checked = Application.IsMouseDisabled;
327+
item.Action += () => {
328+
item.Checked = Application.IsMouseDisabled = !item.Checked;
329+
};
330+
menuItems.Add (item);
331+
332+
return menuItems.ToArray ();
333+
}
334+
318335
static MenuItem [] CreateAlwaysSetPosition ()
319336
{
320337
List<MenuItem> menuItems = new List<MenuItem> ();

0 commit comments

Comments
 (0)