Browse Source

removed unneeded AlternateBack/FormardKey code from Toplevel

Tig 1 year ago
parent
commit
4a56b84324

+ 0 - 32
Terminal.Gui/Application/Application.Keyboard.cs

@@ -29,20 +29,10 @@ public static partial class Application // Keyboard handling
                 {
                 {
                     KeyBindings.ReplaceKey (oldKey, _alternateForwardKey);
                     KeyBindings.ReplaceKey (oldKey, _alternateForwardKey);
                 }
                 }
-                OnAlternateForwardKeyChanged (new (oldKey, value));
             }
             }
         }
         }
     }
     }
 
 
-    private static void OnAlternateForwardKeyChanged (KeyChangedEventArgs e)
-    {
-        // TODO: The fact Top has it's own AlternateForwardKey and events is needlessly complex. Remove it.
-        foreach (Toplevel top in _topLevels.ToArray ())
-        {
-            top.OnAlternateForwardKeyChanged (e);
-        }
-    }
-
     private static Key _alternateBackwardKey = Key.Empty; // Defined in config.json
     private static Key _alternateBackwardKey = Key.Empty; // Defined in config.json
 
 
     /// <summary>Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.</summary>
     /// <summary>Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.</summary>
@@ -66,21 +56,10 @@ public static partial class Application // Keyboard handling
                 {
                 {
                     KeyBindings.ReplaceKey (oldKey, _alternateBackwardKey);
                     KeyBindings.ReplaceKey (oldKey, _alternateBackwardKey);
                 }
                 }
-
-                OnAlternateBackwardKeyChanged (new (oldKey, value));
             }
             }
         }
         }
     }
     }
 
 
-    private static void OnAlternateBackwardKeyChanged (KeyChangedEventArgs oldKey)
-    {
-        // TODO: The fact Top has it's own AlternateBackwardKey and events is needlessly complex. Remove it.
-        foreach (Toplevel top in _topLevels.ToArray ())
-        {
-            top.OnAlternateBackwardKeyChanged (oldKey);
-        }
-    }
-
     private static Key _quitKey = Key.Empty; // Defined in config.json
     private static Key _quitKey = Key.Empty; // Defined in config.json
 
 
     /// <summary>Gets or sets the key to quit the application.</summary>
     /// <summary>Gets or sets the key to quit the application.</summary>
@@ -103,21 +82,10 @@ public static partial class Application // Keyboard handling
                 {
                 {
                     KeyBindings.ReplaceKey (oldKey, _quitKey);
                     KeyBindings.ReplaceKey (oldKey, _quitKey);
                 }
                 }
-                OnQuitKeyChanged (new (oldKey, value));
             }
             }
         }
         }
     }
     }
 
 
-    private static void OnQuitKeyChanged (KeyChangedEventArgs e)
-    {
-        // TODO: The fact Top has it's own QuitKey and events is needlessly complex. Remove it.
-        // Duplicate the list so if it changes during enumeration we're safe
-        foreach (Toplevel top in _topLevels.ToArray ())
-        {
-            top.OnQuitKeyChanged (e);
-        }
-    }
-
     /// <summary>
     /// <summary>
     ///     Event fired when the user presses a key. Fired by <see cref="OnKeyDown"/>.
     ///     Event fired when the user presses a key. Fired by <see cref="OnKeyDown"/>.
     ///     <para>
     ///     <para>

+ 0 - 37
Terminal.Gui/Views/Toplevel.cs

@@ -62,43 +62,6 @@ public partial class Toplevel : View
 
 
     private void Toplevel_MouseClick (object sender, MouseEventEventArgs e) { e.Handled = InvokeCommand (Command.HotKey) == true; }
     private void Toplevel_MouseClick (object sender, MouseEventEventArgs e) { e.Handled = InvokeCommand (Command.HotKey) == true; }
 
 
-    // TODO: Deprecate - No need for this at View level; having at Application is sufficient.
-    /// <summary>Invoked when the <see cref="Application.AlternateBackwardKey"/> is changed.</summary>
-    public event EventHandler<KeyChangedEventArgs> AlternateBackwardKeyChanged;
-
-    // TODO: Deprecate - No need for this at View level; having at Application is sufficient.
-    /// <summary>Invoked when the <see cref="Application.AlternateForwardKey"/> is changed.</summary>
-    public event EventHandler<KeyChangedEventArgs> AlternateForwardKeyChanged;
-
-    // TODO: Deprecate - No need for this at View level; having at Application is sufficient.
-    /// <summary>Virtual method to invoke the <see cref="AlternateBackwardKeyChanged"/> event.</summary>
-    /// <param name="e"></param>
-    public virtual void OnAlternateBackwardKeyChanged (KeyChangedEventArgs e)
-    {
-        KeyBindings.ReplaceKey (e.OldKey, e.NewKey);
-        AlternateBackwardKeyChanged?.Invoke (this, e);
-    }
-
-    // TODO: Deprecate - No need for this at View level; having at Application is sufficient.
-    /// <summary>Virtual method to invoke the <see cref="AlternateForwardKeyChanged"/> event.</summary>
-    /// <param name="e"></param>
-    public virtual void OnAlternateForwardKeyChanged (KeyChangedEventArgs e)
-    {
-        KeyBindings.ReplaceKey (e.OldKey, e.NewKey);
-        AlternateForwardKeyChanged?.Invoke (this, e);
-    }
-
-    /// <summary>Virtual method to invoke the <see cref="QuitKeyChanged"/> event.</summary>
-    /// <param name="e"></param>
-    public virtual void OnQuitKeyChanged (KeyChangedEventArgs e)
-    {
-        KeyBindings.ReplaceKey (e.OldKey, e.NewKey);
-        QuitKeyChanged?.Invoke (this, e);
-    }
-
-    /// <summary>Invoked when the <see cref="Application.QuitKey"/> is changed.</summary>
-    public event EventHandler<KeyChangedEventArgs> QuitKeyChanged;
-
     #endregion
     #endregion
 
 
     #region Subviews
     #region Subviews

+ 1 - 75
UnitTests/Views/ToplevelTests.cs

@@ -573,23 +573,6 @@ public partial class ToplevelTests (ITestOutputHelper output)
 
 
         void View_Added (object sender, SuperViewChangedEventArgs e)
         void View_Added (object sender, SuperViewChangedEventArgs e)
         {
         {
-            Assert.Throws<NullReferenceException> (
-                                                   () =>
-                                                       Application.Top.AlternateForwardKeyChanged +=
-                                                           (s, e) => alternateForwardKey = (KeyCode)e.OldKey
-                                                  );
-
-            Assert.Throws<NullReferenceException> (
-                                                   () =>
-                                                       Application.Top.AlternateBackwardKeyChanged +=
-                                                           (s, e) => alternateBackwardKey = (KeyCode)e.OldKey
-                                                  );
-
-            Assert.Throws<NullReferenceException> (
-                                                   () =>
-                                                       Application.Top.QuitKeyChanged += (s, e) =>
-                                                                                             quitKey = (KeyCode)e.OldKey
-                                                  );
             Assert.False (wasAdded);
             Assert.False (wasAdded);
             wasAdded = true;
             wasAdded = true;
             view.Added -= View_Added;
             view.Added -= View_Added;
@@ -605,64 +588,7 @@ public partial class ToplevelTests (ITestOutputHelper output)
 
 
         Application.Shutdown ();
         Application.Shutdown ();
     }
     }
-
-    [Fact]
-    [AutoInitShutdown]
-    public void AlternateForwardKeyChanged_AlternateBackwardKeyChanged_QuitKeyChanged_Events ()
-    {
-        Key alternateForwardKey = KeyCode.Null;
-        Key alternateBackwardKey = KeyCode.Null;
-        Key quitKey = KeyCode.Null;
-
-        Key previousQuitKey = Application.QuitKey;
-
-        Toplevel top = new ();
-        var view = new View ();
-        view.Initialized += View_Initialized;
-
-        void View_Initialized (object sender, EventArgs e)
-        {
-            top.AlternateForwardKeyChanged += (s, e) => alternateForwardKey = e.OldKey;
-            top.AlternateBackwardKeyChanged += (s, e) => alternateBackwardKey = e.OldKey;
-            top.QuitKeyChanged += (s, e) => quitKey = e.OldKey;
-        }
-
-        var win = new Window ();
-        win.Add (view);
-        top.Add (win);
-        Application.Begin (top);
-
-        Assert.Equal (KeyCode.Null, alternateForwardKey);
-        Assert.Equal (KeyCode.Null, alternateBackwardKey);
-        Assert.Equal (KeyCode.Null, quitKey);
-
-        Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey);
-        Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey);
-        Assert.Equal (Key.Esc, Application.QuitKey);
-
-        Application.AlternateForwardKey = KeyCode.A;
-        Application.AlternateBackwardKey = KeyCode.B;
-        Application.QuitKey = KeyCode.C;
-
-        Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, alternateForwardKey);
-        Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, alternateBackwardKey);
-        Assert.Equal (previousQuitKey, quitKey);
-
-        Assert.Equal (KeyCode.A, Application.AlternateForwardKey);
-        Assert.Equal (KeyCode.B, Application.AlternateBackwardKey);
-        Assert.Equal (KeyCode.C, Application.QuitKey);
-
-        // Replacing the defaults keys to avoid errors on others unit tests that are using it.
-        Application.AlternateForwardKey = Key.PageDown.WithCtrl;
-        Application.AlternateBackwardKey = Key.PageUp.WithCtrl;
-        Application.QuitKey = previousQuitKey;
-
-        Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey);
-        Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey);
-        Assert.Equal (previousQuitKey, Application.QuitKey);
-        top.Dispose ();
-    }
-
+    
     [Fact]
     [Fact]
     [AutoInitShutdown]
     [AutoInitShutdown]
     public void Mouse_Drag_On_Top_With_Superview_Null ()
     public void Mouse_Drag_On_Top_With_Superview_Null ()