//
// 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 Terminal.Gui.Resources;
namespace Terminal.Gui {
///
/// The provides an interactive dialog box for users to pick a file to
/// save.
///
///
///
/// To use, create an instance of , and pass it to
/// . This will run the dialog modally,
/// and when this returns, the property will contain the selected file name or
/// null if the user canceled.
///
///
public class SaveDialog : FileDialog {
///
/// Initializes a new .
///
public SaveDialog () : this (title: string.Empty) { }
///
/// Initializes a new .
///
/// The title.
/// The allowed types.
public SaveDialog (string title, List allowedTypes = null)
{
//: base (title, prompt: Strings.fdSave, nameFieldLabel: $"{Strings.fdSaveAs}:", message: message, allowedTypes) { }
Title = title;
Style.OkButtonText = Strings.btnSave;
if(allowedTypes != null) {
AllowedTypes = allowedTypes;
}
}
///
/// Gets the name of the file the user selected for saving, or null
/// if the user canceled the .
///
/// The name of the file.
public string FileName {
get {
if (Canceled)
return null;
return Path;
}
}
///
/// Gets the default title for the .
///
///
protected override string GetDefaultTitle ()
{
List titleParts = new () {
Strings.fdSave
};
if (MustExist) {
titleParts.Add (Strings.fdExisting);
}
switch (OpenMode) {
case OpenMode.File:
titleParts.Add (Strings.fdFile);
break;
case OpenMode.Directory:
titleParts.Add (Strings.fdDirectory);
break;
}
return string.Join (' ', titleParts);
}
}
}