|
@@ -19,6 +19,7 @@ namespace Terminal.Gui {
|
|
internal class DirListView : View {
|
|
internal class DirListView : View {
|
|
int top, selected;
|
|
int top, selected;
|
|
DirectoryInfo dirInfo;
|
|
DirectoryInfo dirInfo;
|
|
|
|
+ FileSystemWatcher watcher;
|
|
List<(string, bool, bool)> infos;
|
|
List<(string, bool, bool)> infos;
|
|
internal bool canChooseFiles = true;
|
|
internal bool canChooseFiles = true;
|
|
internal bool canChooseDirectories = false;
|
|
internal bool canChooseDirectories = false;
|
|
@@ -39,7 +40,7 @@ namespace Terminal.Gui {
|
|
if (allowedFileTypes == null)
|
|
if (allowedFileTypes == null)
|
|
return true;
|
|
return true;
|
|
foreach (var ft in allowedFileTypes)
|
|
foreach (var ft in allowedFileTypes)
|
|
- if (fsi.Name.EndsWith (ft))
|
|
|
|
|
|
+ if (fsi.Name.EndsWith (ft) || ft == ".*")
|
|
return true;
|
|
return true;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -49,6 +50,21 @@ namespace Terminal.Gui {
|
|
bool valid = false;
|
|
bool valid = false;
|
|
try {
|
|
try {
|
|
dirInfo = new DirectoryInfo (value == null ? directory.ToString () : value.ToString ());
|
|
dirInfo = new DirectoryInfo (value == null ? directory.ToString () : value.ToString ());
|
|
|
|
+ watcher = new FileSystemWatcher (dirInfo.FullName);
|
|
|
|
+ watcher.NotifyFilter = NotifyFilters.Attributes
|
|
|
|
+ | NotifyFilters.CreationTime
|
|
|
|
+ | NotifyFilters.DirectoryName
|
|
|
|
+ | NotifyFilters.FileName
|
|
|
|
+ | NotifyFilters.LastAccess
|
|
|
|
+ | NotifyFilters.LastWrite
|
|
|
|
+ | NotifyFilters.Security
|
|
|
|
+ | NotifyFilters.Size;
|
|
|
|
+ watcher.Changed += Watcher_Changed;
|
|
|
|
+ watcher.Created += Watcher_Changed;
|
|
|
|
+ watcher.Deleted += Watcher_Changed;
|
|
|
|
+ watcher.Renamed += Watcher_Changed;
|
|
|
|
+ watcher.Error += Watcher_Error;
|
|
|
|
+ watcher.EnableRaisingEvents = true;
|
|
infos = (from x in dirInfo.GetFileSystemInfos ()
|
|
infos = (from x in dirInfo.GetFileSystemInfos ()
|
|
where IsAllowed (x) && (!canChooseFiles ? x.Attributes.HasFlag (FileAttributes.Directory) : true)
|
|
where IsAllowed (x) && (!canChooseFiles ? x.Attributes.HasFlag (FileAttributes.Directory) : true)
|
|
orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name
|
|
orderby (!x.Attributes.HasFlag (FileAttributes.Directory)) + x.Name
|
|
@@ -62,6 +78,7 @@ namespace Terminal.Gui {
|
|
case DirectoryNotFoundException _:
|
|
case DirectoryNotFoundException _:
|
|
case ArgumentException _:
|
|
case ArgumentException _:
|
|
dirInfo = null;
|
|
dirInfo = null;
|
|
|
|
+ watcher = null;
|
|
infos.Clear ();
|
|
infos.Clear ();
|
|
valid = true;
|
|
valid = true;
|
|
break;
|
|
break;
|
|
@@ -77,6 +94,16 @@ namespace Terminal.Gui {
|
|
return valid;
|
|
return valid;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ void Watcher_Error (object sender, ErrorEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Application.MainLoop.Invoke (() => Reload ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void Watcher_Changed (object sender, FileSystemEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ Application.MainLoop.Invoke (() => Reload ());
|
|
|
|
+ }
|
|
|
|
+
|
|
ustring directory;
|
|
ustring directory;
|
|
public ustring Directory {
|
|
public ustring Directory {
|
|
get => directory;
|
|
get => directory;
|
|
@@ -168,13 +195,11 @@ namespace Terminal.Gui {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void UnMarkAll ()
|
|
|
|
|
|
+ void UnMarkAll ()
|
|
{
|
|
{
|
|
- if (allowsMultipleSelection && infos.Count > 0) {
|
|
|
|
- for (int i = 0; i < infos.Count; i++) {
|
|
|
|
- if (infos [i].Item3) {
|
|
|
|
- infos [i] = (infos [i].Item1, infos [i].Item2, false);
|
|
|
|
- }
|
|
|
|
|
|
+ for (int i = 0; i < infos.Count; i++) {
|
|
|
|
+ if (infos [i].Item3) {
|
|
|
|
+ infos [i] = (infos [i].Item1, infos [i].Item2, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -221,7 +246,8 @@ namespace Terminal.Gui {
|
|
for (int row = 0; row < f.Height; row++, item++) {
|
|
for (int row = 0; row < f.Height; row++, item++) {
|
|
bool isSelected = item == selected;
|
|
bool isSelected = item == selected;
|
|
Move (0, row);
|
|
Move (0, row);
|
|
- var newcolor = focused ? (isSelected ? ColorScheme.HotNormal : ColorScheme.Focus) : ColorScheme.Focus;
|
|
|
|
|
|
+ var newcolor = focused ? (isSelected ? ColorScheme.HotNormal : ColorScheme.Focus)
|
|
|
|
+ : Enabled ? ColorScheme.Focus : ColorScheme.Disabled;
|
|
if (newcolor != current) {
|
|
if (newcolor != current) {
|
|
Driver.SetAttribute (newcolor);
|
|
Driver.SetAttribute (newcolor);
|
|
current = newcolor;
|
|
current = newcolor;
|
|
@@ -250,11 +276,13 @@ namespace Terminal.Gui {
|
|
public Action<ustring> DirectoryChanged { get; set; }
|
|
public Action<ustring> DirectoryChanged { get; set; }
|
|
public Action<ustring> FileChanged { get; set; }
|
|
public Action<ustring> FileChanged { get; set; }
|
|
|
|
|
|
|
|
+ string splitString = ",";
|
|
|
|
+
|
|
void OnSelectionChanged ()
|
|
void OnSelectionChanged ()
|
|
{
|
|
{
|
|
if (allowsMultipleSelection) {
|
|
if (allowsMultipleSelection) {
|
|
if (FilePaths.Count > 0) {
|
|
if (FilePaths.Count > 0) {
|
|
- FileChanged?.Invoke (string.Join (", ", GetFilesName (FilePaths)));
|
|
|
|
|
|
+ FileChanged?.Invoke (string.Join (splitString, GetFilesName (FilePaths)));
|
|
} else {
|
|
} else {
|
|
FileChanged?.Invoke (infos [selected].Item2 && !canChooseDirectories ? "" : Path.GetFileName (infos [selected].Item1));
|
|
FileChanged?.Invoke (infos [selected].Item2 && !canChooseDirectories ? "" : Path.GetFileName (infos [selected].Item1));
|
|
}
|
|
}
|
|
@@ -275,6 +303,46 @@ namespace Terminal.Gui {
|
|
return filesName;
|
|
return filesName;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public bool GetValidFilesName (string files, out string result)
|
|
|
|
+ {
|
|
|
|
+ result = string.Empty;
|
|
|
|
+ if (infos?.Count == 0) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var valid = true;
|
|
|
|
+ IReadOnlyList<string> filesList = new List<string> (files.Split (splitString.ToArray (), StringSplitOptions.None));
|
|
|
|
+ var filesName = new List<string> ();
|
|
|
|
+ UnMarkAll ();
|
|
|
|
+
|
|
|
|
+ foreach (var file in filesList) {
|
|
|
|
+ if (!allowsMultipleSelection && filesName.Count > 0) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ var idx = infos.IndexOf (x => x.Item1.IndexOf (file, StringComparison.OrdinalIgnoreCase) >= 0);
|
|
|
|
+ if (idx > -1 && string.Equals (infos [idx].Item1, file, StringComparison.OrdinalIgnoreCase)) {
|
|
|
|
+ if (canChooseDirectories && !canChooseFiles && !infos [idx].Item2) {
|
|
|
|
+ valid = false;
|
|
|
|
+ }
|
|
|
|
+ if (allowsMultipleSelection && !infos [idx].Item3) {
|
|
|
|
+ infos [idx] = (infos [idx].Item1, infos [idx].Item2, true);
|
|
|
|
+ }
|
|
|
|
+ if (!allowsMultipleSelection) {
|
|
|
|
+ selected = idx;
|
|
|
|
+ }
|
|
|
|
+ filesName.Add (Path.GetFileName (infos [idx].Item1));
|
|
|
|
+ } else if (idx > -1) {
|
|
|
|
+ valid = false;
|
|
|
|
+ filesName.Add (Path.GetFileName (file));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ result = string.Join (splitString, filesName);
|
|
|
|
+ if (string.IsNullOrEmpty (result)) {
|
|
|
|
+ valid = false;
|
|
|
|
+ }
|
|
|
|
+ return valid;
|
|
|
|
+ }
|
|
|
|
+
|
|
public override bool ProcessKey (KeyEvent keyEvent)
|
|
public override bool ProcessKey (KeyEvent keyEvent)
|
|
{
|
|
{
|
|
switch (keyEvent.Key) {
|
|
switch (keyEvent.Key) {
|
|
@@ -378,7 +446,7 @@ namespace Terminal.Gui {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- internal bool ExecuteSelection ()
|
|
|
|
|
|
+ internal bool ExecuteSelection (bool navigateFolder = true)
|
|
{
|
|
{
|
|
if (infos.Count == 0) {
|
|
if (infos.Count == 0) {
|
|
return false;
|
|
return false;
|
|
@@ -388,8 +456,11 @@ namespace Terminal.Gui {
|
|
if (isDir) {
|
|
if (isDir) {
|
|
Directory = Path.GetFullPath (Path.Combine (Path.GetFullPath (Directory.ToString ()), infos [selected].Item1));
|
|
Directory = Path.GetFullPath (Path.Combine (Path.GetFullPath (Directory.ToString ()), infos [selected].Item1));
|
|
DirectoryChanged?.Invoke (Directory);
|
|
DirectoryChanged?.Invoke (Directory);
|
|
|
|
+ if (canChooseDirectories && !navigateFolder) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- FileChanged?.Invoke (infos [selected].Item1);
|
|
|
|
|
|
+ OnSelectionChanged ();
|
|
if (canChooseFiles) {
|
|
if (canChooseFiles) {
|
|
// Ensures that at least one file is selected.
|
|
// Ensures that at least one file is selected.
|
|
if (FilePaths.Count == 0)
|
|
if (FilePaths.Count == 0)
|
|
@@ -483,11 +554,14 @@ namespace Terminal.Gui {
|
|
Label nameFieldLabel, message, nameDirLabel;
|
|
Label nameFieldLabel, message, nameDirLabel;
|
|
TextField dirEntry, nameEntry;
|
|
TextField dirEntry, nameEntry;
|
|
internal DirListView dirListView;
|
|
internal DirListView dirListView;
|
|
|
|
+ ComboBox cmbAllowedTypes;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new <see cref="FileDialog"/>.
|
|
/// Initializes a new <see cref="FileDialog"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
- public FileDialog () : this (title: string.Empty, prompt: string.Empty, nameFieldLabel: string.Empty, message: string.Empty) { }
|
|
|
|
|
|
+ public FileDialog () : this (title: string.Empty, prompt: string.Empty,
|
|
|
|
+ nameFieldLabel: string.Empty, message: string.Empty)
|
|
|
|
+ { }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
@@ -496,8 +570,9 @@ namespace Terminal.Gui {
|
|
/// <param name="prompt">The prompt.</param>
|
|
/// <param name="prompt">The prompt.</param>
|
|
/// <param name="nameFieldLabel">The name of the file field label..</param>
|
|
/// <param name="nameFieldLabel">The name of the file field label..</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="message">The message.</param>
|
|
- public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustring message)
|
|
|
|
- : this (title, prompt, ustring.Empty, nameFieldLabel, message) { }
|
|
|
|
|
|
+ /// <param name="allowedTypes">The allowed types.</param>
|
|
|
|
+ public FileDialog (ustring title, ustring prompt, ustring nameFieldLabel, ustring message, List<string> allowedTypes = null)
|
|
|
|
+ : this (title, prompt, ustring.Empty, nameFieldLabel, message, allowedTypes) { }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
@@ -505,8 +580,9 @@ namespace Terminal.Gui {
|
|
/// <param name="title">The title.</param>
|
|
/// <param name="title">The title.</param>
|
|
/// <param name="prompt">The prompt.</param>
|
|
/// <param name="prompt">The prompt.</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="message">The message.</param>
|
|
-
|
|
|
|
- public FileDialog (ustring title, ustring prompt, ustring message) : this (title, prompt, ustring.Empty, message) { }
|
|
|
|
|
|
+ /// <param name="allowedTypes">The allowed types.</param>
|
|
|
|
+ public FileDialog (ustring title, ustring prompt, ustring message, List<string> allowedTypes)
|
|
|
|
+ : this (title, prompt, ustring.Empty, message, allowedTypes) { }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
/// Initializes a new instance of <see cref="FileDialog"/>
|
|
@@ -516,7 +592,9 @@ namespace Terminal.Gui {
|
|
/// <param name="nameDirLabel">The name of the directory field label.</param>
|
|
/// <param name="nameDirLabel">The name of the directory field label.</param>
|
|
/// <param name="nameFieldLabel">The name of the file field label..</param>
|
|
/// <param name="nameFieldLabel">The name of the file field label..</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="message">The message.</param>
|
|
- public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring nameFieldLabel, ustring message) : base (title)//, Driver.Cols - 20, Driver.Rows - 5, null)
|
|
|
|
|
|
+ /// <param name="allowedTypes">The allowed types.</param>
|
|
|
|
+ public FileDialog (ustring title, ustring prompt, ustring nameDirLabel, ustring nameFieldLabel, ustring message,
|
|
|
|
+ List<string> allowedTypes = null) : base (title)//, Driver.Cols - 20, Driver.Rows - 5, null)
|
|
{
|
|
{
|
|
this.message = new Label (message) {
|
|
this.message = new Label (message) {
|
|
X = 1,
|
|
X = 1,
|
|
@@ -550,10 +628,22 @@ namespace Terminal.Gui {
|
|
nameEntry = new TextField ("") {
|
|
nameEntry = new TextField ("") {
|
|
X = Pos.Left (dirEntry),
|
|
X = Pos.Left (dirEntry),
|
|
Y = 3 + msgLines,
|
|
Y = 3 + msgLines,
|
|
- Width = Dim.Fill () - 1
|
|
|
|
|
|
+ Width = Dim.Percent (70, true)
|
|
};
|
|
};
|
|
Add (this.nameFieldLabel, nameEntry);
|
|
Add (this.nameFieldLabel, nameEntry);
|
|
|
|
|
|
|
|
+ cmbAllowedTypes = new ComboBox () {
|
|
|
|
+ X = Pos.Right (nameEntry) + 2,
|
|
|
|
+ Y = Pos.Top (nameEntry),
|
|
|
|
+ Width = Dim.Fill (1),
|
|
|
|
+ Height = allowedTypes != null ? allowedTypes.Count + 1 : 1,
|
|
|
|
+ Text = allowedTypes?.Count > 0 ? allowedTypes [0] : string.Empty,
|
|
|
|
+ ReadOnly = true
|
|
|
|
+ };
|
|
|
|
+ cmbAllowedTypes.SetSource (allowedTypes ?? new List<string> ());
|
|
|
|
+ cmbAllowedTypes.OpenSelectedItem += (e) => AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';');
|
|
|
|
+ Add (cmbAllowedTypes);
|
|
|
|
+
|
|
dirListView = new DirListView (this) {
|
|
dirListView = new DirListView (this) {
|
|
X = 1,
|
|
X = 1,
|
|
Y = 3 + msgLines + 2,
|
|
Y = 3 + msgLines + 2,
|
|
@@ -562,21 +652,40 @@ namespace Terminal.Gui {
|
|
};
|
|
};
|
|
DirectoryPath = Path.GetFullPath (Environment.CurrentDirectory);
|
|
DirectoryPath = Path.GetFullPath (Environment.CurrentDirectory);
|
|
Add (dirListView);
|
|
Add (dirListView);
|
|
|
|
+
|
|
|
|
+ AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';');
|
|
dirListView.DirectoryChanged = (dir) => { nameEntry.Text = ustring.Empty; dirEntry.Text = dir; };
|
|
dirListView.DirectoryChanged = (dir) => { nameEntry.Text = ustring.Empty; dirEntry.Text = dir; };
|
|
dirListView.FileChanged = (file) => nameEntry.Text = file == ".." ? "" : file;
|
|
dirListView.FileChanged = (file) => nameEntry.Text = file == ".." ? "" : file;
|
|
dirListView.SelectedChanged = (file) => nameEntry.Text = file.Item1 == ".." ? "" : file.Item1;
|
|
dirListView.SelectedChanged = (file) => nameEntry.Text = file.Item1 == ".." ? "" : file.Item1;
|
|
this.cancel = new Button ("Cancel");
|
|
this.cancel = new Button ("Cancel");
|
|
this.cancel.Clicked += () => {
|
|
this.cancel.Clicked += () => {
|
|
- canceled = true;
|
|
|
|
- Application.RequestStop ();
|
|
|
|
|
|
+ Cancel ();
|
|
};
|
|
};
|
|
AddButton (cancel);
|
|
AddButton (cancel);
|
|
|
|
|
|
this.prompt = new Button (prompt.IsEmpty ? "Ok" : prompt) {
|
|
this.prompt = new Button (prompt.IsEmpty ? "Ok" : prompt) {
|
|
IsDefault = true,
|
|
IsDefault = true,
|
|
- CanFocus = nameEntry.Text.IsEmpty ? false : true
|
|
|
|
|
|
+ Enabled = nameEntry.Text.IsEmpty ? false : true
|
|
};
|
|
};
|
|
this.prompt.Clicked += () => {
|
|
this.prompt.Clicked += () => {
|
|
|
|
+ if (this is OpenDialog) {
|
|
|
|
+ if (!dirListView.GetValidFilesName (nameEntry.Text.ToString (), out string res)) {
|
|
|
|
+ nameEntry.Text = res;
|
|
|
|
+ dirListView.SetNeedsDisplay ();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (!dirListView.canChooseDirectories && !dirListView.ExecuteSelection (false)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ } else if (this is SaveDialog) {
|
|
|
|
+ var name = nameEntry.Text.ToString ();
|
|
|
|
+ if (FilePath.IsEmpty || name.Split (',').Length > 1) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ var ext = name.EndsWith (cmbAllowedTypes.Text.ToString ())
|
|
|
|
+ ? "" : cmbAllowedTypes.Text.ToString ();
|
|
|
|
+ FilePath = Path.Combine (FilePath.ToString (), $"{name}{ext}");
|
|
|
|
+ }
|
|
canceled = false;
|
|
canceled = false;
|
|
Application.RequestStop ();
|
|
Application.RequestStop ();
|
|
};
|
|
};
|
|
@@ -584,9 +693,9 @@ namespace Terminal.Gui {
|
|
|
|
|
|
nameEntry.TextChanged += (e) => {
|
|
nameEntry.TextChanged += (e) => {
|
|
if (nameEntry.Text.IsEmpty) {
|
|
if (nameEntry.Text.IsEmpty) {
|
|
- this.prompt.CanFocus = false;
|
|
|
|
|
|
+ this.prompt.Enabled = false;
|
|
} else {
|
|
} else {
|
|
- this.prompt.CanFocus = true;
|
|
|
|
|
|
+ this.prompt.Enabled = true;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -595,6 +704,18 @@ namespace Terminal.Gui {
|
|
|
|
|
|
// On success, we will set this to false.
|
|
// On success, we will set this to false.
|
|
canceled = true;
|
|
canceled = true;
|
|
|
|
+
|
|
|
|
+ KeyPress += (e) => {
|
|
|
|
+ if (e.KeyEvent.Key == Key.Esc) {
|
|
|
|
+ Cancel ();
|
|
|
|
+ e.Handled = true;
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ void Cancel ()
|
|
|
|
+ {
|
|
|
|
+ canceled = true;
|
|
|
|
+ Application.RequestStop ();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
internal bool canceled;
|
|
internal bool canceled;
|
|
@@ -603,7 +724,7 @@ namespace Terminal.Gui {
|
|
public override void WillPresent ()
|
|
public override void WillPresent ()
|
|
{
|
|
{
|
|
base.WillPresent ();
|
|
base.WillPresent ();
|
|
- //SetFocus (nameEntry);
|
|
|
|
|
|
+ dirListView.SetFocus ();
|
|
}
|
|
}
|
|
|
|
|
|
//protected override void Dispose (bool disposing)
|
|
//protected override void Dispose (bool disposing)
|
|
@@ -689,7 +810,6 @@ namespace Terminal.Gui {
|
|
set => dirListView.AllowedFileTypes = value;
|
|
set => dirListView.AllowedFileTypes = value;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether this <see cref="FileDialog"/> allows the file to be saved with a different extension
|
|
/// Gets or sets a value indicating whether this <see cref="FileDialog"/> allows the file to be saved with a different extension
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -736,7 +856,9 @@ namespace Terminal.Gui {
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="title">The title.</param>
|
|
/// <param name="title">The title.</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="message">The message.</param>
|
|
- public SaveDialog (ustring title, ustring message) : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message) { }
|
|
|
|
|
|
+ /// <param name="allowedTypes">The allowed types.</param>
|
|
|
|
+ public SaveDialog (ustring title, ustring message, List<string> allowedTypes = null)
|
|
|
|
+ : base (title, prompt: "Save", nameFieldLabel: "Save as:", message: message, allowedTypes) { }
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the name of the file the user selected for saving, or null
|
|
/// Gets the name of the file the user selected for saving, or null
|
|
@@ -764,13 +886,33 @@ namespace Terminal.Gui {
|
|
/// <para>
|
|
/// <para>
|
|
/// To use, create an instance of <see cref="OpenDialog"/>, and pass it to
|
|
/// To use, create an instance of <see cref="OpenDialog"/>, and pass it to
|
|
/// <see cref="Application.Run(Func{Exception, bool})"/>. This will run the dialog modally,
|
|
/// <see cref="Application.Run(Func{Exception, bool})"/>. This will run the dialog modally,
|
|
- /// and when this returns, the list of filds will be available on the <see cref="FilePaths"/> property.
|
|
|
|
|
|
+ /// and when this returns, the list of files will be available on the <see cref="FilePaths"/> property.
|
|
/// </para>
|
|
/// </para>
|
|
/// <para>
|
|
/// <para>
|
|
/// To select more than one file, users can use the spacebar, or control-t.
|
|
/// To select more than one file, users can use the spacebar, or control-t.
|
|
/// </para>
|
|
/// </para>
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public class OpenDialog : FileDialog {
|
|
public class OpenDialog : FileDialog {
|
|
|
|
+ OpenMode openMode;
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Determine which <see cref="System.IO"/> type to open.
|
|
|
|
+ /// </summary>
|
|
|
|
+ public enum OpenMode {
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens only file or files.
|
|
|
|
+ /// </summary>
|
|
|
|
+ File,
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens only directory or directories.
|
|
|
|
+ /// </summary>
|
|
|
|
+ Directory,
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Opens files and directories.
|
|
|
|
+ /// </summary>
|
|
|
|
+ Mixed
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new <see cref="OpenDialog"/>.
|
|
/// Initializes a new <see cref="OpenDialog"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -779,10 +921,30 @@ namespace Terminal.Gui {
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Initializes a new <see cref="OpenDialog"/>.
|
|
/// Initializes a new <see cref="OpenDialog"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="title"></param>
|
|
|
|
- /// <param name="message"></param>
|
|
|
|
- public OpenDialog (ustring title, ustring message) : base (title, prompt: "Open", nameFieldLabel: "Open", message: message)
|
|
|
|
|
|
+ /// <param name="title">The title.</param>
|
|
|
|
+ /// <param name="message">The message.</param>
|
|
|
|
+ /// <param name="allowedTypes">The allowed types.</param>
|
|
|
|
+ /// <param name="openMode">The open mode.</param>
|
|
|
|
+ public OpenDialog (ustring title, ustring message, List<string> allowedTypes = null, OpenMode openMode = OpenMode.File) : base (title,
|
|
|
|
+ prompt: openMode == OpenMode.File ? "Open" : openMode == OpenMode.Directory ? "Select folder" : "Select Mixed",
|
|
|
|
+ nameFieldLabel: "Open", message: message, allowedTypes)
|
|
{
|
|
{
|
|
|
|
+ this.openMode = openMode;
|
|
|
|
+ switch (openMode) {
|
|
|
|
+ case OpenMode.File:
|
|
|
|
+ CanChooseFiles = true;
|
|
|
|
+ CanChooseDirectories = false;
|
|
|
|
+ break;
|
|
|
|
+ case OpenMode.Directory:
|
|
|
|
+ CanChooseFiles = false;
|
|
|
|
+ CanChooseDirectories = true;
|
|
|
|
+ break;
|
|
|
|
+ case OpenMode.Mixed:
|
|
|
|
+ CanChooseFiles = true;
|
|
|
|
+ CanChooseDirectories = true;
|
|
|
|
+ AllowsMultipleSelection = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -816,6 +978,9 @@ namespace Terminal.Gui {
|
|
public bool AllowsMultipleSelection {
|
|
public bool AllowsMultipleSelection {
|
|
get => dirListView.allowsMultipleSelection;
|
|
get => dirListView.allowsMultipleSelection;
|
|
set {
|
|
set {
|
|
|
|
+ if (!value && openMode == OpenMode.Mixed) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
dirListView.allowsMultipleSelection = value;
|
|
dirListView.allowsMultipleSelection = value;
|
|
dirListView.Reload ();
|
|
dirListView.Reload ();
|
|
}
|
|
}
|