Editor/Tool/ArchNameDialog.cs
using Editor;

namespace Sunless.Architecture;

// One name, asked for and handed back. A menu option that needs a word before it can act has nowhere in the
// sidebar to put a field, and naming the thing after the fact is a rename nobody remembers to do.
public sealed class ArchNameDialog : Dialog {
	public static void Ask( Widget parent, string title, string advice, string seed, Action<string> named ) {
		new ArchNameDialog( parent, title, advice, seed, named ).Show();
	}

	readonly LineEdit edit;

	ArchNameDialog( Widget parent, string title, string advice, string seed, Action<string> named ) : base( parent ) {
		Window.Title = title;
		Window.SetWindowIcon( "drive_file_rename_outline" );
		Window.Size = new Vector2( 360, 150 );
		Window.SetModal( true, true );

		Layout = Layout.Column();
		Layout.Margin = 12;
		Layout.Spacing = 8;

		Layout.Add( ArchPartUi.Wrapped( advice ) );

		edit = new LineEdit( seed ?? "" ) { PlaceholderText = seed };
		edit.ReturnPressed += () => Accept( named );

		Layout.Add( edit );
		Layout.AddStretchCell();

		var footer = Layout.AddRow();
		footer.Spacing = 4;
		footer.AddStretchCell();
		footer.Add( new Button( "Cancel", "close" ) { Clicked = Close } );
		footer.Add( new Button.Primary( "Save", "save" ) { Clicked = () => Accept( named ) } );

		edit.Focus();
	}

	void Accept( Action<string> named ) {
		var wanted = edit.Text?.Trim();

		if ( string.IsNullOrWhiteSpace( wanted ) ) {
			return;
		}

		Close();
		named( wanted );
	}
}