mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Make Ctrl+F10 toggle split line focusability
This commit is contained in:
@@ -13,6 +13,12 @@ namespace Terminal.Gui {
|
||||
public class TileView : View {
|
||||
TileView parentTileView;
|
||||
|
||||
/// <summary>
|
||||
/// The keyboard key that the user can press to toggle resizing
|
||||
/// of splitter lines. Mouse drag splitting is always enabled.
|
||||
/// </summary>
|
||||
public Key ToggleResizable { get; set; } = Key.CtrlMask | Key.F10;
|
||||
|
||||
/// <summary>
|
||||
/// A single <see cref="ContentView"/> presented in a <see cref="TileView"/>. To create
|
||||
/// new instances use <see cref="TileView.RebuildForTileCount(int)"/>
|
||||
@@ -548,6 +554,27 @@ namespace Terminal.Gui {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool ProcessHotKey (KeyEvent keyEvent)
|
||||
{
|
||||
bool focusMoved = false;
|
||||
|
||||
if(keyEvent.Key == ToggleResizable) {
|
||||
foreach(var l in splitterLines) {
|
||||
|
||||
l.CanFocus = !l.CanFocus;
|
||||
|
||||
if (l.CanFocus && !focusMoved) {
|
||||
l.SetFocus ();
|
||||
focusMoved = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.ProcessHotKey (keyEvent);
|
||||
}
|
||||
|
||||
private bool IsValidNewSplitterPos (int idx, Pos value, int fullSpace)
|
||||
{
|
||||
int newSize = value.Anchor (fullSpace);
|
||||
@@ -862,7 +889,7 @@ namespace Terminal.Gui {
|
||||
|
||||
public TileViewLineView (TileView parent, int idx)
|
||||
{
|
||||
CanFocus = true;
|
||||
CanFocus = false;
|
||||
TabStop = true;
|
||||
|
||||
this.Parent = parent;
|
||||
@@ -927,7 +954,7 @@ namespace Terminal.Gui {
|
||||
|
||||
public void DrawSplitterSymbol ()
|
||||
{
|
||||
if (CanFocus && HasFocus) {
|
||||
if (dragPosition != null || CanFocus) {
|
||||
var location = moveRuneRenderLocation ??
|
||||
new Point (Bounds.Width / 2, Bounds.Height / 2);
|
||||
|
||||
@@ -937,10 +964,6 @@ namespace Terminal.Gui {
|
||||
|
||||
public override bool MouseEvent (MouseEvent mouseEvent)
|
||||
{
|
||||
if (!CanFocus) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!dragPosition.HasValue && (mouseEvent.Flags == MouseFlags.Button1Pressed)) {
|
||||
|
||||
// Start a Drag
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Terminal.Gui;
|
||||
using Terminal.Gui.Graphs;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
@@ -60,7 +59,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_Focused ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
|
||||
@@ -100,7 +99,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_Focused_WithBorder ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
|
||||
@@ -141,9 +140,10 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_Focused_50PercentSplit ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.SetSplitterPos (0, Pos.Percent (50));
|
||||
Assert.IsType<Pos.PosFactor> (tileView.SplitterDistances.ElementAt (0));
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
|
||||
string looksLike =
|
||||
@@ -209,7 +209,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_View1MinSize_Absolute ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
tileView.Tiles.ElementAt (0).MinSize = 6;
|
||||
|
||||
// distance is too small (below 6)
|
||||
@@ -254,7 +254,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
tileView.Tiles.ElementAt (0).MinSize = 5;
|
||||
|
||||
// distance is too small (below 5)
|
||||
@@ -298,7 +298,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_View2MinSize_Absolute ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
tileView.Tiles.ElementAt (1).MinSize = 6;
|
||||
|
||||
// distance leaves too little space for view2 (less than 6 would remain)
|
||||
@@ -342,7 +342,7 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
tileView.Tiles.ElementAt (1).MinSize = 5;
|
||||
|
||||
// distance leaves too little space for view2 (less than 5 would remain)
|
||||
@@ -386,8 +386,6 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_InsertPanelAtStart ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
|
||||
tileView.InsertTile (0);
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
@@ -405,8 +403,6 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_InsertPanelMiddle ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
|
||||
tileView.InsertTile (1);
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
@@ -424,8 +420,6 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_InsertPanelAtEnd ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line, true);
|
||||
SetInputFocusLine (tileView);
|
||||
|
||||
tileView.InsertTile (2);
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
@@ -445,7 +439,9 @@ namespace Terminal.Gui.ViewTests {
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
|
||||
tileView.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
|
||||
Assert.True (line.HasFocus);
|
||||
|
||||
tileView.Redraw (tileView.Bounds);
|
||||
|
||||
@@ -485,9 +481,9 @@ namespace Terminal.Gui.ViewTests {
|
||||
public void TestTileView_Horizontal_View1MinSize_Absolute ()
|
||||
{
|
||||
var tileView = Get11By3TileView (out var line);
|
||||
tileView.ProcessHotKey (new KeyEvent (tileView.ToggleResizable, new KeyModifiers ()));
|
||||
|
||||
tileView.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
|
||||
SetInputFocusLine (tileView);
|
||||
tileView.Tiles.ElementAt (0).MinSize = 1;
|
||||
|
||||
// 0 should not be allowed because it brings us below minimum size of View1
|
||||
@@ -2247,13 +2243,6 @@ namespace Terminal.Gui.ViewTests {
|
||||
return tileView.Subviews.OfType<LineView> ().Single ();
|
||||
}
|
||||
|
||||
private void SetInputFocusLine (TileView tileView)
|
||||
{
|
||||
var line = GetLine (tileView);
|
||||
line.SetFocus ();
|
||||
Assert.True (line.HasFocus);
|
||||
}
|
||||
|
||||
|
||||
private TileView Get5x1TilesView (bool border = true)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user