Toplevel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Toplevel views are used for both an application's main view (filling the entire screen and for modal (pop-up)
  5. /// views such as <see cref="Dialog"/>, <see cref="MessageBox"/>, and <see cref="Wizard"/>).
  6. /// </summary>
  7. /// <remarks>
  8. /// <para>
  9. /// Toplevel views can run as modal (popup) views, started by calling
  10. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/>. They return control to the caller when
  11. /// <see cref="Application.RequestStop(Toplevel)"/> has been called (which sets the <see cref="Toplevel.Running"/>
  12. /// property to <c>false</c>).
  13. /// </para>
  14. /// <para>
  15. /// A Toplevel is created when an application initializes Terminal.Gui by calling <see cref="Application.Init"/>.
  16. /// The application Toplevel can be accessed via <see cref="Application.Top"/>. Additional Toplevels can be created
  17. /// and run (e.g. <see cref="Dialog"/>s). To run a Toplevel, create the <see cref="Toplevel"/> and call
  18. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/>.
  19. /// </para>
  20. /// </remarks>
  21. public partial class Toplevel : View
  22. {
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="Toplevel"/> class,
  25. /// defaulting to full screen. The <see cref="View.Width"/> and <see cref="View.Height"/> properties will be set to the
  26. /// dimensions of the terminal using <see cref="Dim.Fill"/>.
  27. /// </summary>
  28. public Toplevel ()
  29. {
  30. CanFocus = true;
  31. TabStop = TabBehavior.TabGroup;
  32. Arrangement = ViewArrangement.Fixed;
  33. Width = Dim.Fill ();
  34. Height = Dim.Fill ();
  35. ColorScheme = Colors.ColorSchemes ["TopLevel"];
  36. MouseClick += Toplevel_MouseClick;
  37. }
  38. #region Keyboard & Mouse
  39. // TODO: IRunnable: Re-implement - Modal means IRunnable, ViewArrangement.Overlapped where modalView.Z > allOtherViews.Max (v = v.Z), and exclusive key/mouse input.
  40. /// <summary>
  41. /// Determines whether the <see cref="Toplevel"/> is modal or not. If set to <c>false</c> (the default):
  42. /// <list type="bullet">
  43. /// <item>
  44. /// <description><see cref="View.OnKeyDown"/> events will propagate keys upwards.</description>
  45. /// </item>
  46. /// <item>
  47. /// <description>The Toplevel will act as an embedded view (not a modal/pop-up).</description>
  48. /// </item>
  49. /// </list>
  50. /// If set to <c>true</c>:
  51. /// <list type="bullet">
  52. /// <item>
  53. /// <description><see cref="View.OnKeyDown"/> events will NOT propagate keys upwards.</description>
  54. /// </item>
  55. /// <item>
  56. /// <description>The Toplevel will and look like a modal (pop-up) (e.g. see <see cref="Dialog"/>.</description>
  57. /// </item>
  58. /// </list>
  59. /// </summary>
  60. public bool Modal { get; set; }
  61. private void Toplevel_MouseClick (object? sender, MouseEventEventArgs e) { e.Handled = InvokeCommand (Command.HotKey) == true; }
  62. #endregion
  63. #region Subviews
  64. // TODO: Deprecate - Any view can host a menubar in v2
  65. /// <summary>Gets or sets the menu for this Toplevel.</summary>
  66. public MenuBar? MenuBar { get; set; }
  67. // TODO: Deprecate - Any view can host a statusbar in v2
  68. /// <summary>Gets or sets the status bar for this Toplevel.</summary>
  69. public StatusBar? StatusBar { get; set; }
  70. /// <inheritdoc/>
  71. public override View Add (View view)
  72. {
  73. CanFocus = true;
  74. AddMenuStatusBar (view);
  75. return base.Add (view);
  76. }
  77. /// <inheritdoc/>
  78. public override View Remove (View view)
  79. {
  80. if (this is Toplevel { MenuBar: { } })
  81. {
  82. RemoveMenuStatusBar (view);
  83. }
  84. return base.Remove (view);
  85. }
  86. /// <inheritdoc/>
  87. public override void RemoveAll ()
  88. {
  89. if (this == Application.Top)
  90. {
  91. MenuBar?.Dispose ();
  92. MenuBar = null;
  93. StatusBar?.Dispose ();
  94. StatusBar = null;
  95. }
  96. base.RemoveAll ();
  97. }
  98. internal void AddMenuStatusBar (View view)
  99. {
  100. if (view is MenuBar)
  101. {
  102. MenuBar = view as MenuBar;
  103. }
  104. if (view is StatusBar)
  105. {
  106. StatusBar = view as StatusBar;
  107. }
  108. }
  109. internal void RemoveMenuStatusBar (View view)
  110. {
  111. if (view is MenuBar)
  112. {
  113. MenuBar?.Dispose ();
  114. MenuBar = null;
  115. }
  116. if (view is StatusBar)
  117. {
  118. StatusBar?.Dispose ();
  119. StatusBar = null;
  120. }
  121. }
  122. // TODO: Overlapped - Rename to AllSubviewsClosed - Move to View?
  123. /// <summary>
  124. /// Invoked when the last child of the Toplevel <see cref="RunState"/> is closed from by
  125. /// <see cref="Application.End(RunState)"/>.
  126. /// </summary>
  127. public event EventHandler? AllChildClosed;
  128. // TODO: Overlapped - Rename to *Subviews* - Move to View?
  129. /// <summary>
  130. /// Invoked when a child of the Toplevel <see cref="RunState"/> is closed by
  131. /// <see cref="Application.End(RunState)"/>.
  132. /// </summary>
  133. public event EventHandler<ToplevelEventArgs>? ChildClosed;
  134. // TODO: Overlapped - Rename to *Subviews* - Move to View?
  135. /// <summary>Invoked when a child Toplevel's <see cref="RunState"/> has been loaded.</summary>
  136. public event EventHandler<ToplevelEventArgs>? ChildLoaded;
  137. // TODO: Overlapped - Rename to *Subviews* - Move to View?
  138. /// <summary>Invoked when a cjhild Toplevel's <see cref="RunState"/> has been unloaded.</summary>
  139. public event EventHandler<ToplevelEventArgs>? ChildUnloaded;
  140. #endregion
  141. #region Life Cycle
  142. // TODO: IRunnable: Re-implement as a property on IRunnable
  143. /// <summary>Gets or sets whether the main loop for this <see cref="Toplevel"/> is running or not.</summary>
  144. /// <remarks>Setting this property directly is discouraged. Use <see cref="Application.RequestStop"/> instead.</remarks>
  145. public bool Running { get; set; }
  146. // TODO: IRunnable: Re-implement in IRunnable
  147. /// <summary>
  148. /// <see langword="true"/> if was already loaded by the <see cref="Application.Begin(Toplevel)"/>
  149. /// <see langword="false"/>, otherwise.
  150. /// </summary>
  151. public bool IsLoaded { get; private set; }
  152. // TODO: IRunnable: Re-implement as an event on IRunnable; IRunnable.Activating/Activate
  153. /// <summary>Invoked when the Toplevel <see cref="RunState"/> becomes the <see cref="Application.Current"/> Toplevel.</summary>
  154. public event EventHandler<ToplevelEventArgs>? Activate;
  155. // TODO: IRunnable: Re-implement as an event on IRunnable; IRunnable.Deactivating/Deactivate?
  156. /// <summary>Invoked when the Toplevel<see cref="RunState"/> ceases to be the <see cref="Application.Current"/> Toplevel.</summary>
  157. public event EventHandler<ToplevelEventArgs>? Deactivate;
  158. /// <summary>Invoked when the Toplevel's <see cref="RunState"/> is closed by <see cref="Application.End(RunState)"/>.</summary>
  159. public event EventHandler<ToplevelEventArgs>? Closed;
  160. /// <summary>
  161. /// Invoked when the Toplevel's <see cref="RunState"/> is being closed by
  162. /// <see cref="Application.RequestStop(Toplevel)"/>.
  163. /// </summary>
  164. public event EventHandler<ToplevelClosingEventArgs>? Closing;
  165. /// <summary>
  166. /// Invoked when the <see cref="Toplevel"/> <see cref="RunState"/> has begun to be loaded. A Loaded event handler
  167. /// is a good place to finalize initialization before calling <see cref="Application.RunLoop(RunState)"/>.
  168. /// </summary>
  169. public event EventHandler? Loaded;
  170. /// <summary>
  171. /// Called from <see cref="Application.Begin(Toplevel)"/> before the <see cref="Toplevel"/> redraws for the first
  172. /// time.
  173. /// </summary>
  174. /// <remarks>
  175. /// Overrides must call base.OnLoaded() to ensure any Toplevel subviews are initialized properly and the
  176. /// <see cref="Loaded"/> event is raised.
  177. /// </remarks>
  178. public virtual void OnLoaded ()
  179. {
  180. IsLoaded = true;
  181. foreach (var view in Subviews.Where (v => v is Toplevel))
  182. {
  183. var tl = (Toplevel)view;
  184. tl.OnLoaded ();
  185. }
  186. Loaded?.Invoke (this, EventArgs.Empty);
  187. }
  188. /// <summary>
  189. /// Invoked when the <see cref="Toplevel"/> main loop has started it's first iteration. Subscribe to this event to
  190. /// perform tasks when the <see cref="Toplevel"/> has been laid out and focus has been set. changes.
  191. /// <para>
  192. /// A Ready event handler is a good place to finalize initialization after calling
  193. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> on this <see cref="Toplevel"/>.
  194. /// </para>
  195. /// </summary>
  196. public event EventHandler? Ready;
  197. /// <summary>
  198. /// Stops and closes this <see cref="Toplevel"/>. If this Toplevel is the top-most Toplevel,
  199. /// <see cref="Application.RequestStop(Toplevel)"/> will be called, causing the application to exit.
  200. /// </summary>
  201. public virtual void RequestStop ()
  202. {
  203. if (IsOverlappedContainer
  204. && Running
  205. && (Application.Current == this
  206. || Application.Current?.Modal == false
  207. || (Application.Current?.Modal == true && Application.Current?.Running == false)))
  208. {
  209. foreach (Toplevel child in ApplicationOverlapped.OverlappedChildren!)
  210. {
  211. var ev = new ToplevelClosingEventArgs (this);
  212. if (child.OnClosing (ev))
  213. {
  214. return;
  215. }
  216. child.Running = false;
  217. Application.RequestStop (child);
  218. }
  219. Running = false;
  220. Application.RequestStop (this);
  221. }
  222. else if (IsOverlappedContainer && Running && Application.Current?.Modal == true && Application.Current?.Running == true)
  223. {
  224. var ev = new ToplevelClosingEventArgs (Application.Current);
  225. if (OnClosing (ev))
  226. {
  227. return;
  228. }
  229. Application.RequestStop (Application.Current);
  230. }
  231. else if (!IsOverlappedContainer && Running && (!Modal || (Modal && Application.Current != this)))
  232. {
  233. var ev = new ToplevelClosingEventArgs (this);
  234. if (OnClosing (ev))
  235. {
  236. return;
  237. }
  238. Running = false;
  239. Application.RequestStop (this);
  240. }
  241. else
  242. {
  243. Application.RequestStop (Application.Current);
  244. }
  245. }
  246. /// <summary>
  247. /// Invoked when the Toplevel <see cref="RunState"/> has been unloaded. A Unloaded event handler is a good place
  248. /// to dispose objects after calling <see cref="Application.End(RunState)"/>.
  249. /// </summary>
  250. public event EventHandler? Unloaded;
  251. internal virtual void OnActivate (Toplevel deactivated) { Activate?.Invoke (this, new (deactivated)); }
  252. /// <summary>
  253. /// Stops and closes the <see cref="Toplevel"/> specified by <paramref name="top"/>. If <paramref name="top"/> is
  254. /// the top-most Toplevel, <see cref="Application.RequestStop(Toplevel)"/> will be called, causing the application to
  255. /// exit.
  256. /// </summary>
  257. /// <param name="top">The Toplevel to request stop.</param>
  258. public virtual void RequestStop (Toplevel top) { top.RequestStop (); }
  259. internal virtual void OnAllChildClosed () { AllChildClosed?.Invoke (this, EventArgs.Empty); }
  260. internal virtual void OnChildClosed (Toplevel top)
  261. {
  262. if (IsOverlappedContainer)
  263. {
  264. SetSubViewNeedsDisplay ();
  265. }
  266. ChildClosed?.Invoke (this, new (top));
  267. }
  268. internal virtual void OnChildLoaded (Toplevel top) { ChildLoaded?.Invoke (this, new (top)); }
  269. internal virtual void OnChildUnloaded (Toplevel top) { ChildUnloaded?.Invoke (this, new (top)); }
  270. internal virtual void OnClosed (Toplevel top) { Closed?.Invoke (this, new (top)); }
  271. internal virtual bool OnClosing (ToplevelClosingEventArgs ev)
  272. {
  273. Closing?.Invoke (this, ev);
  274. return ev.Cancel;
  275. }
  276. internal virtual void OnDeactivate (Toplevel activated) { Deactivate?.Invoke (this, new (activated)); }
  277. /// <summary>
  278. /// Called from <see cref="Application.RunLoop"/> after the <see cref="Toplevel"/> has entered the first iteration
  279. /// of the loop.
  280. /// </summary>
  281. internal virtual void OnReady ()
  282. {
  283. foreach (var view in Subviews.Where (v => v is Toplevel))
  284. {
  285. var tl = (Toplevel)view;
  286. tl.OnReady ();
  287. }
  288. Ready?.Invoke (this, EventArgs.Empty);
  289. }
  290. /// <summary>Called from <see cref="Application.End(RunState)"/> before the <see cref="Toplevel"/> is disposed.</summary>
  291. internal virtual void OnUnloaded ()
  292. {
  293. foreach (var view in Subviews.Where (v => v is Toplevel))
  294. {
  295. var tl = (Toplevel)view;
  296. tl.OnUnloaded ();
  297. }
  298. Unloaded?.Invoke (this, EventArgs.Empty);
  299. }
  300. #endregion
  301. #region Draw
  302. /// <inheritdoc/>
  303. public override void OnDrawContent (Rectangle viewport)
  304. {
  305. if (!Visible)
  306. {
  307. return;
  308. }
  309. if (NeedsDisplay || SubViewNeedsDisplay /*|| LayoutNeeded*/)
  310. {
  311. Clear ();
  312. //LayoutSubviews ();
  313. PositionToplevels ();
  314. if (this == ApplicationOverlapped.OverlappedTop)
  315. {
  316. // This enables correct draw behavior when switching between overlapped subviews
  317. foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!.AsEnumerable ().Reverse ())
  318. {
  319. if (top.Frame.IntersectsWith (Viewport))
  320. {
  321. if (top != this && !top.IsCurrentTop && !OutsideTopFrame (top) && top.Visible)
  322. {
  323. top.SetNeedsLayout ();
  324. top.SetNeedsDisplay (top.Viewport);
  325. top.Draw ();
  326. top.OnRenderLineCanvas ();
  327. }
  328. }
  329. }
  330. }
  331. // BUGBUG: This appears to be a hack to get ScrollBarViews to render correctly.
  332. foreach (View view in Subviews)
  333. {
  334. if (view.Frame.IntersectsWith (Viewport) && !OutsideTopFrame (this))
  335. {
  336. //view.SetNeedsLayout ();
  337. view.SetNeedsDisplay ();
  338. view.SetSubViewNeedsDisplay ();
  339. }
  340. }
  341. base.OnDrawContent (viewport);
  342. }
  343. }
  344. #endregion
  345. #region Navigation
  346. /// <inheritdoc/>
  347. public override bool OnEnter (View view) { return MostFocused?.OnEnter (view) ?? base.OnEnter (view); }
  348. /// <inheritdoc/>
  349. public override bool OnLeave (View view) { return MostFocused?.OnLeave (view) ?? base.OnLeave (view); }
  350. #endregion
  351. #region Size / Position Management
  352. // TODO: Make cancelable?
  353. internal virtual void OnSizeChanging (SizeChangedEventArgs size) { SizeChanging?.Invoke (this, size); }
  354. /// <inheritdoc/>
  355. public override Point? PositionCursor ()
  356. {
  357. if (!IsOverlappedContainer)
  358. {
  359. if (Focused is null)
  360. {
  361. RestoreFocus ();
  362. }
  363. return null;
  364. }
  365. // This code path only happens when the Toplevel is an Overlapped container
  366. if (Focused is null)
  367. {
  368. // TODO: this is an Overlapped hack
  369. foreach (Toplevel top in ApplicationOverlapped.OverlappedChildren!)
  370. {
  371. if (top != this && top.Visible)
  372. {
  373. top.SetFocus ();
  374. return null;
  375. }
  376. }
  377. }
  378. Point? cursor2 = base.PositionCursor ();
  379. return null;
  380. }
  381. /// <summary>
  382. /// Adjusts the location and size of <paramref name="top"/> within this Toplevel. Virtual method enabling
  383. /// implementation of specific positions for inherited <see cref="Toplevel"/> views.
  384. /// </summary>
  385. /// <param name="top">The Toplevel to adjust.</param>
  386. public virtual void PositionToplevel (Toplevel? top)
  387. {
  388. if (top is null)
  389. {
  390. return;
  391. }
  392. View? superView = GetLocationEnsuringFullVisibility (
  393. top,
  394. top.Frame.X,
  395. top.Frame.Y,
  396. out int nx,
  397. out int ny,
  398. out StatusBar? sb
  399. );
  400. if (superView is null)
  401. {
  402. return;
  403. }
  404. var layoutSubviews = false;
  405. var maxWidth = 0;
  406. if (superView.Margin is { } && superView == top.SuperView)
  407. {
  408. maxWidth -= superView.GetAdornmentsThickness ().Left + superView.GetAdornmentsThickness ().Right;
  409. }
  410. if ((superView != top || top?.SuperView is { } || (top != Application.Top && top!.Modal) || (top?.SuperView is null && ApplicationOverlapped.IsOverlapped (top)))
  411. && (top!.Frame.X + top.Frame.Width > maxWidth || ny > top.Frame.Y))
  412. {
  413. if (top?.X is null or PosAbsolute && top?.Frame.X != nx)
  414. {
  415. top!.X = nx;
  416. layoutSubviews = true;
  417. }
  418. if (top?.Y is null or PosAbsolute && top?.Frame.Y != ny)
  419. {
  420. top!.Y = ny;
  421. layoutSubviews = true;
  422. }
  423. }
  424. // TODO: v2 - This is a hack to get the StatusBar to be positioned correctly.
  425. if (sb != null
  426. && !top!.Subviews.Contains (sb)
  427. && ny + top.Frame.Height != superView.Frame.Height - (sb.Visible ? 1 : 0)
  428. && top.Height is DimFill
  429. && -top.Height.GetAnchor (0) < 1)
  430. {
  431. top.Height = Dim.Fill (sb.Visible ? 1 : 0);
  432. layoutSubviews = true;
  433. }
  434. if (superView.LayoutNeeded || layoutSubviews)
  435. {
  436. superView.LayoutSubviews ();
  437. }
  438. if (LayoutNeeded)
  439. {
  440. LayoutSubviews ();
  441. }
  442. }
  443. /// <summary>Invoked when the terminal has been resized. The new <see cref="Size"/> of the terminal is provided.</summary>
  444. public event EventHandler<SizeChangedEventArgs>? SizeChanging;
  445. private bool OutsideTopFrame (Toplevel top)
  446. {
  447. if (top.Frame.X > Driver.Cols || top.Frame.Y > Driver.Rows)
  448. {
  449. return true;
  450. }
  451. return false;
  452. }
  453. // TODO: v2 - Not sure this is needed anymore.
  454. internal void PositionToplevels ()
  455. {
  456. PositionToplevel (this);
  457. foreach (View top in Subviews)
  458. {
  459. if (top is Toplevel)
  460. {
  461. PositionToplevel ((Toplevel)top);
  462. }
  463. }
  464. }
  465. #endregion
  466. }
  467. /// <summary>
  468. /// Implements the <see cref="IEqualityComparer{T}"/> for comparing two <see cref="Toplevel"/>s used by
  469. /// <see cref="StackExtensions"/>.
  470. /// </summary>
  471. public class ToplevelEqualityComparer : IEqualityComparer<Toplevel>
  472. {
  473. /// <summary>Determines whether the specified objects are equal.</summary>
  474. /// <param name="x">The first object of type <see cref="Toplevel"/> to compare.</param>
  475. /// <param name="y">The second object of type <see cref="Toplevel"/> to compare.</param>
  476. /// <returns><see langword="true"/> if the specified objects are equal; otherwise, <see langword="false"/>.</returns>
  477. public bool Equals (Toplevel? x, Toplevel? y)
  478. {
  479. if (y is null && x is null)
  480. {
  481. return true;
  482. }
  483. if (x is null || y is null)
  484. {
  485. return false;
  486. }
  487. if (x.Id == y.Id)
  488. {
  489. return true;
  490. }
  491. return false;
  492. }
  493. /// <summary>Returns a hash code for the specified object.</summary>
  494. /// <param name="obj">The <see cref="Toplevel"/> for which a hash code is to be returned.</param>
  495. /// <returns>A hash code for the specified object.</returns>
  496. /// <exception cref="ArgumentNullException">
  497. /// The type of <paramref name="obj"/> is a reference type and
  498. /// <paramref name="obj"/> is <see langword="null"/>.
  499. /// </exception>
  500. public int GetHashCode (Toplevel obj)
  501. {
  502. if (obj is null)
  503. {
  504. throw new ArgumentNullException ();
  505. }
  506. var hCode = 0;
  507. if (int.TryParse (obj.Id, out int result))
  508. {
  509. hCode = result;
  510. }
  511. return hCode.GetHashCode ();
  512. }
  513. }
  514. /// <summary>
  515. /// Implements the <see cref="IComparer{T}"/> to sort the <see cref="Toplevel"/> from the
  516. /// <see cref="ApplicationOverlapped.OverlappedChildren"/> if needed.
  517. /// </summary>
  518. public sealed class ToplevelComparer : IComparer<Toplevel>
  519. {
  520. /// <summary>
  521. /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the
  522. /// other.
  523. /// </summary>
  524. /// <param name="x">The first object to compare.</param>
  525. /// <param name="y">The second object to compare.</param>
  526. /// <returns>
  527. /// A signed integer that indicates the relative values of <paramref name="x"/> and <paramref name="y"/>, as shown
  528. /// in the following table.Value Meaning Less than zero <paramref name="x"/> is less than <paramref name="y"/>.Zero
  529. /// <paramref name="x"/> equals <paramref name="y"/> .Greater than zero <paramref name="x"/> is greater than
  530. /// <paramref name="y"/>.
  531. /// </returns>
  532. public int Compare (Toplevel? x, Toplevel? y)
  533. {
  534. if (ReferenceEquals (x, y))
  535. {
  536. return 0;
  537. }
  538. if (x is null)
  539. {
  540. return -1;
  541. }
  542. if (y is null)
  543. {
  544. return 1;
  545. }
  546. return string.CompareOrdinal (x.Id, y.Id);
  547. }
  548. }