mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Merge branch 'master' of tig:migueldeicaza/gui.cs
This commit is contained in:
@@ -242,17 +242,7 @@ static class Demo {
|
||||
|
||||
var ntop = Application.Top;
|
||||
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("_File", new MenuItem [] {
|
||||
new MenuItem ("_Close", "", () => { if (Quit ()) { running = MainApp; Application.RequestStop (); } }, null, null, Key.AltMask | Key.Q),
|
||||
}),
|
||||
new MenuBarItem ("_Edit", new MenuItem [] {
|
||||
new MenuItem ("_Copy", "", null, null, null, Key.C | Key.CtrlMask),
|
||||
new MenuItem ("C_ut", "", null, null, null, Key.X | Key.CtrlMask),
|
||||
new MenuItem ("_Paste", "", null, null, null, Key.V | Key.CtrlMask)
|
||||
}),
|
||||
});
|
||||
ntop.Add (menu);
|
||||
var text = new TextView () { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
string fname = GetFileName ();
|
||||
|
||||
@@ -264,12 +254,43 @@ static class Demo {
|
||||
};
|
||||
ntop.Add (win);
|
||||
|
||||
var text = new TextView () { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
|
||||
if (fname != null)
|
||||
text.Text = System.IO.File.ReadAllText (fname);
|
||||
win.Add (text);
|
||||
|
||||
void Paste ()
|
||||
{
|
||||
if (text != null) {
|
||||
text.Paste ();
|
||||
}
|
||||
}
|
||||
|
||||
void Cut ()
|
||||
{
|
||||
if (text != null) {
|
||||
text.Cut ();
|
||||
}
|
||||
}
|
||||
|
||||
void Copy ()
|
||||
{
|
||||
if (text != null) {
|
||||
text.Copy ();
|
||||
}
|
||||
}
|
||||
|
||||
var menu = new MenuBar (new MenuBarItem [] {
|
||||
new MenuBarItem ("_File", new MenuItem [] {
|
||||
new MenuItem ("_Close", "", () => { if (Quit ()) { running = MainApp; Application.RequestStop (); } }, null, null, Key.AltMask | Key.Q),
|
||||
}),
|
||||
new MenuBarItem ("_Edit", new MenuItem [] {
|
||||
new MenuItem ("_Copy", "", Copy, null, null, Key.C | Key.CtrlMask),
|
||||
new MenuItem ("C_ut", "", Cut, null, null, Key.X | Key.CtrlMask),
|
||||
new MenuItem ("_Paste", "", Paste, null, null, Key.Y | Key.CtrlMask)
|
||||
}),
|
||||
});
|
||||
ntop.Add (menu);
|
||||
|
||||
Application.Run (ntop);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Terminal.Gui {
|
||||
Curses.move (crow, ccol);
|
||||
needMove = false;
|
||||
}
|
||||
Curses.addch ((int)(uint)MakePrintable(rune));
|
||||
Curses.addch ((int)(uint)MakePrintable (rune));
|
||||
} else
|
||||
needMove = true;
|
||||
if (sync)
|
||||
@@ -71,7 +71,8 @@ namespace Terminal.Gui {
|
||||
AddRune (rune);
|
||||
}
|
||||
|
||||
public override void Refresh () {
|
||||
public override void Refresh ()
|
||||
{
|
||||
Curses.refresh ();
|
||||
if (Curses.CheckWinChange ()) {
|
||||
Clip = new Rect (0, 0, Cols, Rows);
|
||||
@@ -87,7 +88,7 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
SetCursorVisibility (CursorVisibility.Default);
|
||||
|
||||
|
||||
Curses.endwin ();
|
||||
// Clear and reset entire screen.
|
||||
Console.Out.Write ("\x1b[2J");
|
||||
@@ -100,7 +101,8 @@ namespace Terminal.Gui {
|
||||
|
||||
int currentAttribute;
|
||||
|
||||
public override void SetAttribute (Attribute c) {
|
||||
public override void SetAttribute (Attribute c)
|
||||
{
|
||||
currentAttribute = c.Value;
|
||||
Curses.attrset (currentAttribute);
|
||||
}
|
||||
@@ -266,7 +268,7 @@ namespace Terminal.Gui {
|
||||
if (cev.ButtonState == Curses.Event.ReportMousePosition) {
|
||||
mouseFlag = MapCursesButton ((Curses.Event)LastMouseButtonPressed) | MouseFlags.ReportMousePosition;
|
||||
point = new Point ();
|
||||
//cancelButtonClicked = true;
|
||||
cancelButtonClicked = true;
|
||||
} else {
|
||||
point = new Point () {
|
||||
X = cev.X,
|
||||
@@ -700,23 +702,23 @@ namespace Terminal.Gui {
|
||||
// We are setting Invisible as default so we could ignore XTerm DECSUSR setting
|
||||
//
|
||||
switch (Curses.curs_set (0)) {
|
||||
case 0:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Invisible;
|
||||
break;
|
||||
case 0:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Invisible;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Underline;
|
||||
Curses.curs_set (1);
|
||||
break;
|
||||
case 1:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Underline;
|
||||
Curses.curs_set (1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Box;
|
||||
Curses.curs_set (2);
|
||||
break;
|
||||
case 2:
|
||||
currentCursorVisibility = initialCursorVisibility = CursorVisibility.Box;
|
||||
Curses.curs_set (2);
|
||||
break;
|
||||
|
||||
default:
|
||||
currentCursorVisibility = initialCursorVisibility = null;
|
||||
break;
|
||||
default:
|
||||
currentCursorVisibility = initialCursorVisibility = null;
|
||||
break;
|
||||
}
|
||||
|
||||
Curses.raw ();
|
||||
@@ -915,13 +917,13 @@ namespace Terminal.Gui {
|
||||
/// <inheritdoc/>
|
||||
public override bool SetCursorVisibility (CursorVisibility visibility)
|
||||
{
|
||||
if (initialCursorVisibility.HasValue == false)
|
||||
if (initialCursorVisibility.HasValue == false)
|
||||
return false;
|
||||
|
||||
Curses.curs_set (((int) visibility >> 16) & 0x000000FF);
|
||||
Curses.curs_set (((int)visibility >> 16) & 0x000000FF);
|
||||
|
||||
if (visibility != CursorVisibility.Invisible) {
|
||||
Console.Out.Write ("\x1b[{0} q", ((int) visibility >> 24) & 0xFF);
|
||||
Console.Out.Write ("\x1b[{0} q", ((int)visibility >> 24) & 0xFF);
|
||||
Console.Out.Flush ();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Terminal.Gui {
|
||||
if (text == null)
|
||||
text = "";
|
||||
|
||||
this.text = TextModel.ToRunes (text);
|
||||
this.text = TextModel.ToRunes (text.Split ("\n") [0]);
|
||||
point = text.RuneCount;
|
||||
first = point > w ? point - w : 0;
|
||||
CanFocus = true;
|
||||
@@ -139,7 +139,7 @@ namespace Terminal.Gui {
|
||||
if (oldText == value)
|
||||
return;
|
||||
|
||||
var newText = OnTextChanging (value);
|
||||
var newText = OnTextChanging (value.Split ("\n") [0]);
|
||||
if (newText.Cancel) {
|
||||
return;
|
||||
}
|
||||
@@ -826,8 +826,8 @@ namespace Terminal.Gui {
|
||||
(var _, var len) = TextModel.DisplaySize (text, 0, selStart, false);
|
||||
(var _, var len2) = TextModel.DisplaySize (text, selStart, selStart + selLength, false);
|
||||
(var _, var len3) = TextModel.DisplaySize (text, selStart + selLength, actualText.RuneCount, false);
|
||||
Text = actualText[0, len] +
|
||||
actualText[len + len2, len + len2 + len3];
|
||||
Text = actualText [0, len] +
|
||||
actualText [len + len2, len + len2 + len3];
|
||||
ClearAllSelection ();
|
||||
point = selStart >= Text.RuneCount ? Text.RuneCount : selStart;
|
||||
Adjust ();
|
||||
@@ -848,7 +848,7 @@ namespace Terminal.Gui {
|
||||
(int _, int len) = TextModel.DisplaySize (text, 0, selStart, false);
|
||||
(var _, var len2) = TextModel.DisplaySize (text, selStart, selStart + length, false);
|
||||
(var _, var len3) = TextModel.DisplaySize (text, selStart + length, actualText.RuneCount, false);
|
||||
ustring cbTxt = Clipboard.Contents ?? "";
|
||||
ustring cbTxt = Clipboard.Contents.Split ("\n") [0] ?? "";
|
||||
Text = actualText [0, len] +
|
||||
cbTxt +
|
||||
actualText [len + len2, len + len2 + len3];
|
||||
@@ -874,12 +874,11 @@ namespace Terminal.Gui {
|
||||
/// <summary>
|
||||
/// Get / Set the wished cursor when the field is focused
|
||||
/// </summary>
|
||||
public CursorVisibility DesiredCursorVisibility
|
||||
{
|
||||
get => desiredCursorVisibility;
|
||||
public CursorVisibility DesiredCursorVisibility {
|
||||
get => desiredCursorVisibility;
|
||||
set {
|
||||
if (desiredCursorVisibility != value && HasFocus) {
|
||||
Application.Driver.SetCursorVisibility (value);
|
||||
Application.Driver.SetCursorVisibility (value);
|
||||
}
|
||||
|
||||
desiredCursorVisibility = value;
|
||||
|
||||
@@ -1340,12 +1340,6 @@ namespace Terminal.Gui {
|
||||
List<Rune> rest;
|
||||
bool lineRemoved = false;
|
||||
|
||||
if (shiftSelecting && selecting && !kb.Key.HasFlag (Key.ShiftMask)
|
||||
&& !kb.Key.HasFlag (Key.CtrlMask | Key.C)) {
|
||||
shiftSelecting = false;
|
||||
selecting = false;
|
||||
}
|
||||
|
||||
// Handle some state here - whether the last command was a kill
|
||||
// operation and the column tracking (up/down)
|
||||
switch (kb.Key) {
|
||||
@@ -1370,6 +1364,8 @@ namespace Terminal.Gui {
|
||||
case Key.PageDown | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
int nPageDnShift = Frame.Height - 1;
|
||||
if (currentRow < model.Count) {
|
||||
@@ -1390,6 +1386,8 @@ namespace Terminal.Gui {
|
||||
case Key.PageUp | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
int nPageUpShift = Frame.Height - 1;
|
||||
if (currentRow > 0) {
|
||||
@@ -1410,6 +1408,8 @@ namespace Terminal.Gui {
|
||||
case Key.CursorDown | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
MoveDown ();
|
||||
break;
|
||||
@@ -1419,6 +1419,8 @@ namespace Terminal.Gui {
|
||||
case Key.CursorUp | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
MoveUp ();
|
||||
break;
|
||||
@@ -1428,6 +1430,8 @@ namespace Terminal.Gui {
|
||||
case Key.CursorRight | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
var currentLine = GetCurrentLine ();
|
||||
if (currentColumn < currentLine.Count) {
|
||||
@@ -1450,6 +1454,8 @@ namespace Terminal.Gui {
|
||||
case Key.CursorLeft | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
if (currentColumn > 0) {
|
||||
currentColumn--;
|
||||
@@ -1516,6 +1522,8 @@ namespace Terminal.Gui {
|
||||
case Key.A | Key.CtrlMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
currentColumn = 0;
|
||||
Adjust ();
|
||||
@@ -1555,6 +1563,8 @@ namespace Terminal.Gui {
|
||||
case Key.E | Key.CtrlMask: // End
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
currentLine = GetCurrentLine ();
|
||||
currentColumn = currentLine.Count;
|
||||
@@ -1645,6 +1655,8 @@ namespace Terminal.Gui {
|
||||
case (Key)((int)'B' + Key.AltMask):
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
var newPos = WordBackward (currentColumn, currentRow);
|
||||
if (newPos.HasValue) {
|
||||
@@ -1660,6 +1672,8 @@ namespace Terminal.Gui {
|
||||
case (Key)((int)'F' + Key.AltMask):
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
newPos = WordForward (currentColumn, currentRow);
|
||||
if (newPos.HasValue) {
|
||||
@@ -1703,6 +1717,8 @@ namespace Terminal.Gui {
|
||||
case Key.CtrlMask | Key.End | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
MoveEnd ();
|
||||
break;
|
||||
@@ -1711,6 +1727,8 @@ namespace Terminal.Gui {
|
||||
case Key.CtrlMask | Key.Home | Key.ShiftMask:
|
||||
if (kb.Key.HasFlag (Key.ShiftMask)) {
|
||||
StartSelecting ();
|
||||
} else if (shiftSelecting && selecting) {
|
||||
StopSelecting ();
|
||||
}
|
||||
MoveHome ();
|
||||
break;
|
||||
@@ -1814,6 +1832,12 @@ namespace Terminal.Gui {
|
||||
selectionStartRow = currentRow;
|
||||
}
|
||||
|
||||
void StopSelecting ()
|
||||
{
|
||||
shiftSelecting = false;
|
||||
selecting = false;
|
||||
}
|
||||
|
||||
void MoveUp ()
|
||||
{
|
||||
if (currentRow > 0) {
|
||||
|
||||
Reference in New Issue
Block a user