// // FileDialog.cs: File system dialogs for open and save // using System; using System.Collections.Generic; using NStack; namespace Terminal.Gui { public class FileDialog : Dialog { Button prompt; Label nameFieldLabel, message; public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustring message) : base (title, Driver.Cols - 20, Driver.Rows - 6, null) { this.prompt = new Button (prompt); AddButton (this.prompt); this.nameFieldLabel = new Label (Rect.Empty, nameFieldLabel); this.message = new Label (Rect.Empty, message); } /// /// Gets or sets the prompt label for the button displayed to the user /// /// The prompt. public ustring Prompt { get => prompt.Text; set { prompt.Text = value; } } /// /// Gets or sets the name field label. /// /// The name field label. public ustring NameFieldLabel { get => nameFieldLabel.Text; set { nameFieldLabel.Text = value; } } /// /// Gets or sets the message displayed to the user, defaults to nothing /// /// The message. public ustring Message { get; set; } /// /// Gets or sets a value indicating whether this can create directories. /// /// true if can create directories; otherwise, false. public bool CanCreateDirectories { get; set; } /// /// Gets or sets a value indicating whether this is extension hidden. /// /// true if is extension hidden; otherwise, false. public bool IsExtensionHidden { get; set; } /// /// Gets or sets the directory path for this panel /// /// The directory path. public ustring DirectoryPath { get; set; } /// /// The array of filename extensions allowed, or null if all file extensions are allowed. /// /// The allowed file types. public ustring [] AllowedFileTypes { get; set; } /// /// Gets or sets a value indicating whether this allows the file to be saved with a different extension /// /// true if allows other file types; otherwise, false. public bool AllowsOtherFileTypes { get; set; } /// /// The File path that is currently shown on the panel /// /// The absolute file path for the file path entered. public ustring FilePath { get; set; } } public class SaveDialog : FileDialog { public SaveDialog (ustring title, ustring message) : base (title, "Save", "Save as:", message) { } } public class OpenDialog : FileDialog { public OpenDialog (ustring title, ustring message) : base (title, "Open", "Open", message) { } /// /// Gets or sets a value indicating whether this can choose files. /// /// true if can choose files; otherwise, false. public bool CanChooseFiles { get; set; } /// /// Gets or sets a value indicating whether this can choose directories. /// /// true if can choose directories; otherwise, false. public bool CanChooseDirectories { get; set; } /// /// Gets or sets a value indicating whether this allows multiple selection. /// /// true if allows multiple selection; otherwise, false. public bool AllowsMultipleSelection { get; set; } /// /// Gets the file paths selected /// /// The file paths. public IReadOnlyList FilePaths { get; } } }