mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
This commit is contained in:
@@ -999,7 +999,7 @@ public class GraphViewExample : Scenario
|
||||
|
||||
protected override void DrawBarLine (GraphView graph, Point start, Point end, BarSeriesBar beingDrawn)
|
||||
{
|
||||
IConsoleDriver driver = Application.Driver;
|
||||
IDriver driver = Application.Driver;
|
||||
|
||||
int x = start.X;
|
||||
|
||||
|
||||
@@ -158,10 +158,7 @@ public class Keys : Scenario
|
||||
appKeyListView.SchemeName = "TopLevel";
|
||||
win.Add (onSwallowedListView);
|
||||
|
||||
if (Application.Driver is IConsoleDriverFacade fac)
|
||||
{
|
||||
fac.InputProcessor.AnsiSequenceSwallowed += (s, e) => { swallowedList.Add (e.Replace ("\x1b","Esc")); };
|
||||
}
|
||||
Application.Driver!.InputProcessor.AnsiSequenceSwallowed += (s, e) => { swallowedList.Add (e.Replace ("\x1b", "Esc")); };
|
||||
|
||||
Application.KeyDown += (s, a) => KeyDownPressUp (a, "Down");
|
||||
Application.KeyUp += (s, a) => KeyDownPressUp (a, "Up");
|
||||
|
||||
@@ -129,7 +129,7 @@ public class Mazing : Scenario
|
||||
return;
|
||||
}
|
||||
|
||||
Point newPos = _m.Player;
|
||||
Point newPos = _m!.Player;
|
||||
|
||||
Command? command = e.Context?.Command;
|
||||
|
||||
|
||||
@@ -107,18 +107,7 @@ public class Navigation : Scenario
|
||||
// };
|
||||
//timer.Start ();
|
||||
|
||||
Application.Iteration += (sender, args) =>
|
||||
{
|
||||
if (progressBar.Fraction == 1.0)
|
||||
{
|
||||
progressBar.Fraction = 0;
|
||||
}
|
||||
|
||||
progressBar.Fraction += 0.01f;
|
||||
|
||||
Application.Invoke (() => { });
|
||||
|
||||
};
|
||||
Application.Iteration += OnApplicationIteration;
|
||||
|
||||
View overlappedView2 = CreateOverlappedView (3, 8, 10);
|
||||
|
||||
@@ -214,12 +203,25 @@ public class Navigation : Scenario
|
||||
|
||||
testFrame.SetFocus ();
|
||||
Application.Run (app);
|
||||
Application.Iteration -= OnApplicationIteration;
|
||||
// timer.Close ();
|
||||
app.Dispose ();
|
||||
Application.Shutdown ();
|
||||
|
||||
return;
|
||||
|
||||
void OnApplicationIteration (object sender, IterationEventArgs args)
|
||||
{
|
||||
if (progressBar.Fraction == 1.0)
|
||||
{
|
||||
progressBar.Fraction = 0;
|
||||
}
|
||||
|
||||
progressBar.Fraction += 0.01f;
|
||||
|
||||
Application.Invoke (() => { });
|
||||
}
|
||||
|
||||
void ColorPicker_ColorChanged (object sender, ResultEventArgs<Color> e)
|
||||
{
|
||||
testFrame.SetScheme (testFrame.GetScheme () with { Normal = new (testFrame.GetAttributeForRole (VisualRole.Normal).Foreground, e.Result) });
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
namespace UICatalog.Scenarios;
|
||||
|
||||
[ScenarioMetadata ("Notepad", "Multi-tab text editor using the TabView control.")]
|
||||
@@ -9,10 +7,10 @@ namespace UICatalog.Scenarios;
|
||||
[ScenarioCategory ("TextView")]
|
||||
public class Notepad : Scenario
|
||||
{
|
||||
private TabView _focusedTabView;
|
||||
public Shortcut LenShortcut { get; private set; }
|
||||
private TabView? _focusedTabView;
|
||||
private int _numNewTabs = 1;
|
||||
private TabView _tabView;
|
||||
private TabView? _tabView;
|
||||
public Shortcut? LenShortcut { get; private set; }
|
||||
|
||||
public override void Main ()
|
||||
{
|
||||
@@ -67,14 +65,15 @@ public class Notepad : Scenario
|
||||
top.Add (_tabView);
|
||||
LenShortcut = new (Key.Empty, "Len: ", null);
|
||||
|
||||
var statusBar = new StatusBar (new [] {
|
||||
new (Application.QuitKey, $"Quit", Quit),
|
||||
new Shortcut(Key.F2, "Open", Open),
|
||||
new Shortcut(Key.F1, "New", New),
|
||||
var statusBar = new StatusBar (
|
||||
[
|
||||
new (Application.QuitKey, "Quit", Quit),
|
||||
new (Key.F2, "Open", Open),
|
||||
new (Key.F1, "New", New),
|
||||
new (Key.F3, "Save", Save),
|
||||
new (Key.F6, "Close", Close),
|
||||
LenShortcut
|
||||
}
|
||||
]
|
||||
)
|
||||
{
|
||||
AlignmentModes = AlignmentModes.IgnoreFirstOrLast
|
||||
@@ -97,7 +96,7 @@ public class Notepad : Scenario
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
public void Save () { Save (_focusedTabView, _focusedTabView.SelectedTab); }
|
||||
public void Save () { Save (_focusedTabView!, _focusedTabView!.SelectedTab!); }
|
||||
|
||||
public void Save (TabView tabViewToSave, Tab tabToSave)
|
||||
{
|
||||
@@ -119,7 +118,7 @@ public class Notepad : Scenario
|
||||
|
||||
public bool SaveAs ()
|
||||
{
|
||||
var tab = _focusedTabView.SelectedTab as OpenedFile;
|
||||
var tab = _focusedTabView!.SelectedTab as OpenedFile;
|
||||
|
||||
if (tab == null)
|
||||
{
|
||||
@@ -152,7 +151,7 @@ public class Notepad : Scenario
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Close () { Close (_focusedTabView, _focusedTabView.SelectedTab); }
|
||||
private void Close () { Close (_focusedTabView!, _focusedTabView!.SelectedTab!); }
|
||||
|
||||
private void Close (TabView tv, Tab tabToClose)
|
||||
{
|
||||
@@ -196,7 +195,7 @@ public class Notepad : Scenario
|
||||
|
||||
// close and dispose the tab
|
||||
tv.RemoveTab (tab);
|
||||
tab.View.Dispose ();
|
||||
tab.View?.Dispose ();
|
||||
_focusedTabView = tv;
|
||||
|
||||
// If last tab is closed, open a new one
|
||||
@@ -217,7 +216,7 @@ public class Notepad : Scenario
|
||||
return tv;
|
||||
}
|
||||
|
||||
private void New () { Open (null, $"new {_numNewTabs++}"); }
|
||||
private void New () { Open (null!, $"new {_numNewTabs++}"); }
|
||||
|
||||
private void Open ()
|
||||
{
|
||||
@@ -246,26 +245,27 @@ public class Notepad : Scenario
|
||||
|
||||
/// <summary>Creates a new tab with initial text</summary>
|
||||
/// <param name="fileInfo">File that was read or null if a new blank document</param>
|
||||
/// <param name="tabName"></param>
|
||||
private void Open (FileInfo fileInfo, string tabName)
|
||||
{
|
||||
var tab = new OpenedFile (this) { DisplayText = tabName, File = fileInfo };
|
||||
tab.View = tab.CreateTextView (fileInfo);
|
||||
tab.SavedText = tab.View.Text;
|
||||
tab.RegisterTextViewEvents (_focusedTabView);
|
||||
tab.RegisterTextViewEvents (_focusedTabView!);
|
||||
|
||||
_focusedTabView.AddTab (tab, true);
|
||||
_focusedTabView!.AddTab (tab, true);
|
||||
}
|
||||
|
||||
private void Quit () { Application.RequestStop (); }
|
||||
|
||||
private void TabView_SelectedTabChanged (object sender, TabChangedEventArgs e)
|
||||
private void TabView_SelectedTabChanged (object? sender, TabChangedEventArgs e)
|
||||
{
|
||||
LenShortcut.Title = $"Len:{e.NewTab?.View?.Text?.Length ?? 0}";
|
||||
LenShortcut!.Title = $"Len:{e.NewTab?.View?.Text?.Length ?? 0}";
|
||||
|
||||
e.NewTab?.View?.SetFocus ();
|
||||
}
|
||||
|
||||
private void TabView_TabClicked (object sender, TabMouseEventArgs e)
|
||||
private void TabView_TabClicked (object? sender, TabMouseEventArgs e)
|
||||
{
|
||||
// we are only interested in right clicks
|
||||
if (!e.MouseEvent.Flags.HasFlag (MouseFlags.Button3Clicked))
|
||||
@@ -281,12 +281,12 @@ public class Notepad : Scenario
|
||||
}
|
||||
else
|
||||
{
|
||||
var tv = (TabView)sender;
|
||||
var tv = (TabView)sender!;
|
||||
var t = (OpenedFile)e.Tab;
|
||||
|
||||
items =
|
||||
[
|
||||
new MenuItemv2 ("Save", "", () => Save (_focusedTabView, e.Tab)),
|
||||
new MenuItemv2 ("Save", "", () => Save (_focusedTabView!, e.Tab)),
|
||||
new MenuItemv2 ("Close", "", () => Close (tv, e.Tab))
|
||||
];
|
||||
|
||||
@@ -303,12 +303,12 @@ public class Notepad : Scenario
|
||||
|
||||
private class OpenedFile (Notepad notepad) : Tab
|
||||
{
|
||||
private Notepad _notepad = notepad;
|
||||
private readonly Notepad _notepad = notepad;
|
||||
|
||||
public OpenedFile CloneTo (TabView other)
|
||||
{
|
||||
var newTab = new OpenedFile (_notepad) { DisplayText = base.Text, File = File };
|
||||
newTab.View = newTab.CreateTextView (newTab.File);
|
||||
newTab.View = newTab.CreateTextView (newTab.File!);
|
||||
newTab.SavedText = newTab.View.Text;
|
||||
newTab.RegisterTextViewEvents (other);
|
||||
other.AddTab (newTab, true);
|
||||
@@ -316,11 +316,11 @@ public class Notepad : Scenario
|
||||
return newTab;
|
||||
}
|
||||
|
||||
public View CreateTextView (FileInfo file)
|
||||
public View CreateTextView (FileInfo? file)
|
||||
{
|
||||
var initialText = string.Empty;
|
||||
|
||||
if (file != null && file.Exists)
|
||||
if (file is { Exists: true })
|
||||
{
|
||||
initialText = System.IO.File.ReadAllText (file.FullName);
|
||||
}
|
||||
@@ -336,11 +336,11 @@ public class Notepad : Scenario
|
||||
};
|
||||
}
|
||||
|
||||
public FileInfo File { get; set; }
|
||||
public FileInfo? File { get; set; }
|
||||
|
||||
public void RegisterTextViewEvents (TabView parent)
|
||||
{
|
||||
var textView = (TextView)View;
|
||||
var textView = (TextView)View!;
|
||||
|
||||
// when user makes changes rename tab to indicate unsaved
|
||||
textView.ContentsChanged += (s, k) =>
|
||||
@@ -362,19 +362,20 @@ public class Notepad : Scenario
|
||||
DisplayText = Text.TrimEnd ('*');
|
||||
}
|
||||
}
|
||||
_notepad.LenShortcut.Title = $"Len:{textView.Text.Length}";
|
||||
|
||||
_notepad.LenShortcut!.Title = $"Len:{textView.Text.Length}";
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The text of the tab the last time it was saved</summary>
|
||||
/// <value></value>
|
||||
public string SavedText { get; set; }
|
||||
public string? SavedText { get; set; }
|
||||
|
||||
public bool UnsavedChanges => !string.Equals (SavedText, View.Text);
|
||||
public bool UnsavedChanges => !string.Equals (SavedText, View!.Text);
|
||||
|
||||
internal void Save ()
|
||||
{
|
||||
string newText = View.Text;
|
||||
string newText = View!.Text;
|
||||
|
||||
if (File is null || string.IsNullOrWhiteSpace (File.FullName))
|
||||
{
|
||||
|
||||
@@ -266,14 +266,14 @@ internal class NumericUpDownEditor<T> : View where T : notnull
|
||||
|
||||
void NumericUpDownOnIncrementChanged (object? o, EventArgs<T> eventArgs)
|
||||
{
|
||||
_increment.Text = _numericUpDown.Increment.ToString ();
|
||||
_increment.Text = _numericUpDown!.Increment?.ToString ();
|
||||
}
|
||||
|
||||
Add (_numericUpDown);
|
||||
|
||||
_value.Text = _numericUpDown.Text;
|
||||
_format.Text = _numericUpDown.Format;
|
||||
_increment.Text = _numericUpDown.Increment.ToString ();
|
||||
_increment.Text = _numericUpDown!.Increment?.ToString ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -498,5 +498,5 @@ public class TextInputControls : Scenario
|
||||
|
||||
|
||||
|
||||
private void TimeChanged (object sender, DateTimeEventArgs<TimeSpan> e) { _labelMirroringTimeField.Text = _timeField.Text; }
|
||||
private void TimeChanged (object sender, EventArgs<TimeSpan> e) { _labelMirroringTimeField.Text = _timeField.Text; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
|
||||
@@ -7,12 +8,12 @@ namespace UICatalog.Scenarios;
|
||||
[ScenarioCategory ("DateTime")]
|
||||
public class TimeAndDate : Scenario
|
||||
{
|
||||
private Label _lblDateFmt;
|
||||
private Label _lblNewDate;
|
||||
private Label _lblNewTime;
|
||||
private Label _lblOldDate;
|
||||
private Label _lblOldTime;
|
||||
private Label _lblTimeFmt;
|
||||
private Label? _lblDateFmt;
|
||||
private Label? _lblNewDate;
|
||||
private Label? _lblNewTime;
|
||||
private Label? _lblOldDate;
|
||||
private Label? _lblOldTime;
|
||||
private Label? _lblTimeFmt;
|
||||
|
||||
public override void Main ()
|
||||
{
|
||||
@@ -143,17 +144,13 @@ public class TimeAndDate : Scenario
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private void DateChanged (object sender, DateTimeEventArgs<DateTime> e)
|
||||
private void DateChanged (object? sender, EventArgs<DateTime> e)
|
||||
{
|
||||
_lblOldDate.Text = $"Old Date: {e.OldValue}";
|
||||
_lblNewDate.Text = $"New Date: {e.NewValue}";
|
||||
_lblDateFmt.Text = $"Date Format: {e.Format}";
|
||||
_lblNewDate!.Text = $"New Date: {e.Value}";
|
||||
}
|
||||
|
||||
private void TimeChanged (object sender, DateTimeEventArgs<TimeSpan> e)
|
||||
private void TimeChanged (object? sender, EventArgs<TimeSpan> e)
|
||||
{
|
||||
_lblOldTime.Text = $"Old Time: {e.OldValue}";
|
||||
_lblNewTime.Text = $"New Time: {e.NewValue}";
|
||||
_lblTimeFmt.Text = $"Time Format: {e.Format}";
|
||||
_lblNewTime!.Text = $"New Time: {e.Value}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ public class TreeViewFileSystem : Scenario
|
||||
|
||||
private void ShowContextMenu (Point screenPoint, IFileSystemInfo forObject)
|
||||
{
|
||||
PopoverMenu? contextMenu = new ([new ("Properties", $"Show {forObject.Name} properties", () => ShowPropertiesOf (forObject))]);
|
||||
PopoverMenu contextMenu = new ([new ("Properties", $"Show {forObject.Name} properties", () => ShowPropertiesOf (forObject))]);
|
||||
|
||||
// Registering with the PopoverManager will ensure that the context menu is closed when the view is no longer focused
|
||||
// and the context menu is disposed when it is closed.
|
||||
|
||||
@@ -71,8 +71,7 @@ public class UnicodeInMenu : Scenario
|
||||
appWindow.Add (menu);
|
||||
|
||||
var statusBar = new StatusBar (
|
||||
new Shortcut []
|
||||
{
|
||||
[
|
||||
new (
|
||||
Application.QuitKey,
|
||||
"Выход",
|
||||
@@ -80,7 +79,7 @@ public class UnicodeInMenu : Scenario
|
||||
),
|
||||
new (Key.F2, "Создать", null),
|
||||
new (Key.F3, "Со_хранить", null)
|
||||
}
|
||||
]
|
||||
);
|
||||
appWindow.Add (statusBar);
|
||||
|
||||
@@ -145,13 +144,13 @@ public class UnicodeInMenu : Scenario
|
||||
};
|
||||
appWindow.Add (checkBox, checkBoxRight);
|
||||
|
||||
label = new () { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1, Text = "ComboBox:" };
|
||||
appWindow.Add (label);
|
||||
var comboBox = new ComboBox { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
|
||||
comboBox.SetSource (new ObservableCollection<string> { gitString, "Со_хранить" });
|
||||
//label = new () { X = Pos.X (label), Y = Pos.Bottom (checkBoxRight) + 1, Text = "ComboBox:" };
|
||||
//appWindow.Add (label);
|
||||
//var comboBox = new ComboBox { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50) };
|
||||
//comboBox.SetSource (new ObservableCollection<string> { gitString, "Со_хранить" });
|
||||
|
||||
appWindow.Add (comboBox);
|
||||
comboBox.Text = gitString;
|
||||
//appWindow.Add (comboBox);
|
||||
//comboBox.Text = gitString;
|
||||
|
||||
label = new () { X = Pos.X (label), Y = Pos.Bottom (label) + 2, Text = "HexView:" };
|
||||
appWindow.Add (label);
|
||||
@@ -185,7 +184,7 @@ public class UnicodeInMenu : Scenario
|
||||
X = 20,
|
||||
Y = Pos.Y (label),
|
||||
Width = Dim.Percent (60),
|
||||
RadioLabels = new [] { "item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ" }
|
||||
RadioLabels = ["item #1", gitString, "Со_хранить", "𝔽𝕆𝕆𝔹𝔸ℝ"]
|
||||
};
|
||||
appWindow.Add (radioGroup);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user