//
// FileDialog.cs: File system dialogs for open and save
//
// TODO:
// * Add directory selector
// * Implement subclasses
// * Figure out why message text does not show
// * Remove the extra space when message does not show
// * Use a line separator to show the file listing, so we can use same colors as the rest
// * DirListView: Add mouse support
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using Terminal.Gui.Resources;
using System.Collections.ObjectModel;
namespace Terminal.Gui {
///
/// Determine which type to open.
///
public enum OpenMode {
///
/// Opens only file or files.
///
File,
///
/// Opens only directory or directories.
///
Directory,
///
/// Opens files and directories.
///
Mixed
}
///
/// The provides an interactive dialog box for users to select files or directories.
///
///
///
/// The open dialog can be used to select files for opening, it can be configured to allow
/// multiple items to be selected (based on the AllowsMultipleSelection) variable and
/// you can control whether this should allow files or directories to be selected.
///
///
/// To use, create an instance of , and pass it to
/// . This will run the dialog modally,
/// and when this returns, the list of files will be available on the property.
///
///
/// To select more than one file, users can use the spacebar, or control-t.
///
///
public class OpenDialog : FileDialog {
///
/// Initializes a new .
///
public OpenDialog () : this (title: string.Empty) { }
///
/// Initializes a new .
///
/// The title.
/// The allowed types.
/// The open mode.
public OpenDialog (string title, List allowedTypes = null, OpenMode openMode = OpenMode.File)
{
this.OpenMode = openMode;
Title = title;
Style.OkButtonText = openMode == OpenMode.File ? Strings.fdOpen : openMode == OpenMode.Directory ? Strings.fdSelectFolder : Strings.fdSelectMixed;
if (allowedTypes != null) {
AllowedTypes = allowedTypes;
}
}
///
/// Returns the selected files, or an empty list if nothing has been selected
///
/// The file paths.
public IReadOnlyList FilePaths {
get => Canceled ? Enumerable.Empty ().ToList().AsReadOnly()
: AllowsMultipleSelection ? base.MultiSelected : new ReadOnlyCollection(new [] { Path });
}
}
}