Toplevel.cs 22 KB

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