Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Toplevel.Ready event #446

Merged
merged 8 commits into from
May 20, 2020
Merged

Add Toplevel.Ready event #446

merged 8 commits into from
May 20, 2020

Conversation

tig
Copy link
Collaborator

@tig tig commented May 19, 2020

This PR addresses a common problem found in building Terminal.Gui apps...namely, I frequently need to do some setup/initialization code AFTER Application.Run is called. This is often things having to do with setting focus or changing layout, which is all first computed as Application.Run executes.

#445 explains the rationale more fully.

The challenge is addressed by introducing a Ready event to Toplevel:

		/// <summary>
		/// Fired once the Toplevel's <see cref="T:Terminal.Gui.MainLoop"/> has started it's first iteration. 
		/// Subscribe to this event to perform tasks when the <see cref="T:Terminal.Gui.Toplevel"/> has been laid out and focus has been set.
		/// changes. A Ready event handler is a good place to finalize initialization after calling `<see cref="T:Terminal.Gui.Application.Run"/>(topLevel)`. 
		/// </summary>
		public event EventHandler Ready;

Applications then can then implement an event handling method for Ready where they can do things like set which control gets focus. E.g.:

_top.Ready += (o, e) => _top.SetFocus (_rightPane);
Application.Run(_top);

The latest UI Config PR branch (#387) utilizes Toplevel.Ready to ensure the right-hand pane retains focus after a Scenario is run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants