mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-02 01:03:29 +01:00
HexEditor - it was already broken!
This commit is contained in:
@@ -6,9 +6,6 @@
|
||||
//
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Channels;
|
||||
|
||||
namespace Terminal.Gui;
|
||||
|
||||
@@ -388,7 +385,7 @@ public class ComboBox : View, IDesignable
|
||||
{
|
||||
Selected ();
|
||||
|
||||
return true;
|
||||
return RaiseAccepted () == true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Terminal.Gui;
|
||||
/// </para>
|
||||
/// <para>Control the first byte shown by setting the <see cref="DisplayStart"/> property to an offset in the stream.</para>
|
||||
/// </remarks>
|
||||
public class HexView : View
|
||||
public class HexView : View, IDesignable
|
||||
{
|
||||
private const int bsize = 4;
|
||||
private const int displayWidth = 9;
|
||||
@@ -33,7 +33,8 @@ public class HexView : View
|
||||
private int bpl;
|
||||
private long displayStart, pos;
|
||||
private SortedDictionary<long, byte> edits = [];
|
||||
private bool firstNibble, leftSide;
|
||||
private bool firstNibble;
|
||||
private bool leftSide;
|
||||
private Stream source;
|
||||
private static readonly Rune SpaceCharRune = new (' ');
|
||||
private static readonly Rune PeriodCharRune = new ('.');
|
||||
@@ -46,8 +47,7 @@ public class HexView : View
|
||||
public HexView (Stream source)
|
||||
{
|
||||
Source = source;
|
||||
// BUG: This will always call the most-derived definition of CanFocus.
|
||||
// Either seal it or don't set it here.
|
||||
|
||||
CanFocus = true;
|
||||
CursorVisibility = CursorVisibility.Default;
|
||||
leftSide = true;
|
||||
@@ -61,7 +61,8 @@ public class HexView : View
|
||||
AddCommand (Command.Right, () => MoveRight ());
|
||||
AddCommand (Command.Down, () => MoveDown (bytesPerLine));
|
||||
AddCommand (Command.Up, () => MoveUp (bytesPerLine));
|
||||
AddCommand (Command.Accept, () => ToggleSide ());
|
||||
AddCommand (Command.Tab, () => Navigate (NavigationDirection.Forward));
|
||||
AddCommand (Command.BackTab, () => Navigate (NavigationDirection.Backward));
|
||||
AddCommand (Command.PageUp, () => MoveUp (bytesPerLine * Frame.Height));
|
||||
AddCommand (Command.PageDown, () => MoveDown (bytesPerLine * Frame.Height));
|
||||
AddCommand (Command.Start, () => MoveHome ());
|
||||
@@ -94,6 +95,9 @@ public class HexView : View
|
||||
KeyBindings.Add (Key.CursorUp.WithCtrl, Command.StartOfPage);
|
||||
KeyBindings.Add (Key.CursorDown.WithCtrl, Command.EndOfPage);
|
||||
|
||||
KeyBindings.Add (Key.Tab, Command.Tab);
|
||||
KeyBindings.Add (Key.Tab.WithShift, Command.BackTab);
|
||||
|
||||
LayoutComplete += HexView_LayoutComplete;
|
||||
}
|
||||
|
||||
@@ -246,7 +250,7 @@ public class HexView : View
|
||||
public event EventHandler<HexViewEditEventArgs> Edited;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override bool OnMouseEvent (MouseEvent me)
|
||||
protected internal override bool OnMouseEvent (MouseEvent me)
|
||||
{
|
||||
if (!me.Flags.HasFlag (MouseFlags.Button1Clicked)
|
||||
&& !me.Flags.HasFlag (MouseFlags.Button1DoubleClicked)
|
||||
@@ -528,12 +532,14 @@ public class HexView : View
|
||||
|
||||
int x = displayWidth + block * 14 + column + (firstNibble ? 0 : 1);
|
||||
int y = line;
|
||||
|
||||
if (!leftSide)
|
||||
{
|
||||
x = displayWidth + bytesPerLine / bsize * 14 + item - 1;
|
||||
}
|
||||
|
||||
Move (x, y);
|
||||
|
||||
return new (x, y);
|
||||
}
|
||||
|
||||
@@ -763,17 +769,49 @@ public class HexView : View
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var delta = (int)(pos - DisplayStart);
|
||||
int line = delta / bytesPerLine;
|
||||
|
||||
SetNeedsDisplay (new (0, line, Viewport.Width, 1));
|
||||
}
|
||||
|
||||
private bool ToggleSide ()
|
||||
private bool Navigate (NavigationDirection direction)
|
||||
{
|
||||
leftSide = !leftSide;
|
||||
RedisplayLine (position);
|
||||
firstNibble = true;
|
||||
switch (direction)
|
||||
{
|
||||
case NavigationDirection.Forward:
|
||||
if (leftSide)
|
||||
{
|
||||
leftSide = false;
|
||||
RedisplayLine (position);
|
||||
firstNibble = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case NavigationDirection.Backward:
|
||||
if (!leftSide)
|
||||
{
|
||||
leftSide = true;
|
||||
RedisplayLine (position);
|
||||
firstNibble = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
bool IDesignable.EnableForDesign ()
|
||||
{
|
||||
Source = new MemoryStream (Encoding.UTF8.GetBytes ("HexEditor Unicode that shouldn't 𝔹Aℝ𝔽!"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user