mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Improve file dialog scenario UX
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Terminal.Gui;
|
using Terminal.Gui;
|
||||||
|
using Terminal.Gui.Graphs;
|
||||||
|
using static Terminal.Gui.OpenDialog;
|
||||||
|
|
||||||
namespace UICatalog.Scenarios {
|
namespace UICatalog.Scenarios {
|
||||||
[ScenarioMetadata (Name: "FileDialog2", Description: "Demonstrates how to the FileDialog2 class")]
|
[ScenarioMetadata (Name: "FileDialog2", Description: "Demonstrates how to the FileDialog2 class")]
|
||||||
@@ -12,15 +14,18 @@ namespace UICatalog.Scenarios {
|
|||||||
private CheckBox cbIcons;
|
private CheckBox cbIcons;
|
||||||
private CheckBox cbMonochrome;
|
private CheckBox cbMonochrome;
|
||||||
private CheckBox cbCaseSensitive;
|
private CheckBox cbCaseSensitive;
|
||||||
|
private CheckBox cbAllowMultipleSelection;
|
||||||
|
|
||||||
private RadioGroup rgCaption;
|
private RadioGroup rgCaption;
|
||||||
|
private RadioGroup rgOpenMode;
|
||||||
|
private RadioGroup rgAllowedTypes;
|
||||||
|
|
||||||
public override void Setup ()
|
public override void Setup ()
|
||||||
{
|
{
|
||||||
var y = 0;
|
var y = 0;
|
||||||
var x = 1;
|
var x = 1;
|
||||||
|
|
||||||
cbMustExist = new CheckBox ("Must Exist") { Checked = true, X=x};
|
cbMustExist = new CheckBox ("Must Exist") { Checked = true, Y = y++, X=x};
|
||||||
Win.Add (cbMustExist);
|
Win.Add (cbMustExist);
|
||||||
|
|
||||||
|
|
||||||
@@ -33,61 +38,71 @@ namespace UICatalog.Scenarios {
|
|||||||
cbCaseSensitive = new CheckBox ("Case Sensitive Search") { Checked = false, Y = y++, X=x };
|
cbCaseSensitive = new CheckBox ("Case Sensitive Search") { Checked = false, Y = y++, X=x };
|
||||||
Win.Add (cbCaseSensitive);
|
Win.Add (cbCaseSensitive);
|
||||||
|
|
||||||
|
cbAllowMultipleSelection = new CheckBox ("Multiple") { Checked = false, Y = y++, X=x };
|
||||||
|
Win.Add (cbAllowMultipleSelection);
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
x = 24;
|
x = 24;
|
||||||
|
|
||||||
Win.Add(new Label("Open Caption"){X=x++,Y=y++});
|
Win.Add(new LineView(Orientation.Vertical){
|
||||||
|
X = x++,
|
||||||
|
Y = 1,
|
||||||
|
Height = 4
|
||||||
|
});
|
||||||
|
Win.Add(new Label("Caption"){X=x++,Y=y++});
|
||||||
|
|
||||||
rgCaption = new RadioGroup{X = x, Y=y};
|
rgCaption = new RadioGroup{X = x, Y=y};
|
||||||
rgCaption.RadioLabels = new NStack.ustring[]{"Ok","Open","Save"};
|
rgCaption.RadioLabels = new NStack.ustring[]{"Ok","Open","Save"};
|
||||||
Win.Add(rgCaption);
|
Win.Add(rgCaption);
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
x = 37;
|
||||||
|
|
||||||
|
Win.Add(new LineView(Orientation.Vertical){
|
||||||
|
X = x++,
|
||||||
|
Y = 1,
|
||||||
|
Height = 4
|
||||||
|
});
|
||||||
|
Win.Add(new Label("OpenMode"){X=x++,Y=y++});
|
||||||
|
|
||||||
|
rgOpenMode = new RadioGroup{X = x, Y=y};
|
||||||
|
rgOpenMode.RadioLabels = new NStack.ustring[]{"File","Directory","Mixed"};
|
||||||
|
Win.Add(rgOpenMode);
|
||||||
|
|
||||||
x = 1;
|
|
||||||
y = 5;
|
|
||||||
|
|
||||||
foreach (var multi in new bool [] { false, true }) {
|
|
||||||
foreach (OpenDialog.OpenMode openMode in Enum.GetValues (typeof (OpenDialog.OpenMode))) {
|
|
||||||
var btn = new Button ($"Select {(multi ? "Many" : "One")} {openMode}") {
|
|
||||||
X = x,
|
|
||||||
Y = y
|
|
||||||
};
|
|
||||||
SetupHandler (btn, openMode, multi);
|
|
||||||
y += 2;
|
|
||||||
Win.Add (btn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
y = 5;
|
y = 5;
|
||||||
|
x = 24;
|
||||||
|
|
||||||
// SubViews[0] is ContentView
|
Win.Add(new LineView(Orientation.Vertical){
|
||||||
x = Win.Subviews [0].Subviews.OfType<Button> ().Max (b => b.Text.Length + 5);
|
X = x++,
|
||||||
|
Y = y+1,
|
||||||
|
Height = 4
|
||||||
|
});
|
||||||
|
Win.Add(new Label("Allowed"){X=x++,Y=y++});
|
||||||
|
|
||||||
foreach (var multi in new bool [] { false, true }) {
|
rgAllowedTypes = new RadioGroup{X = x, Y=y};
|
||||||
foreach (var strict in new bool [] { false, true }) {
|
rgAllowedTypes.RadioLabels = new NStack.ustring[]{"Any","Csv (Recommended)","Csv (Strict)"};
|
||||||
{
|
Win.Add(rgAllowedTypes);
|
||||||
var btn = new Button ($"Select {(multi ? "Many" : "One")} .csv ({(strict ? "Strict" : "Recommended")})") {
|
|
||||||
X = x,
|
|
||||||
Y = y
|
|
||||||
};
|
|
||||||
|
|
||||||
SetupHandler (btn, OpenDialog.OpenMode.File, multi, true, strict);
|
var btn = new Button ($"Run Dialog") {
|
||||||
y += 2;
|
X = 1,
|
||||||
Win.Add (btn);
|
Y = 7
|
||||||
}
|
};
|
||||||
};
|
|
||||||
}
|
SetupHandler (btn);
|
||||||
|
Win.Add (btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupHandler (Button btn, OpenDialog.OpenMode mode, bool isMulti, bool csv = false, bool strict = false)
|
private void SetupHandler (Button btn)
|
||||||
{
|
{
|
||||||
btn.Clicked += () => {
|
btn.Clicked += () => {
|
||||||
var fd = new FileDialog2(
|
var fd = new FileDialog2(
|
||||||
rgCaption.RadioLabels[rgCaption.SelectedItem].ToString()
|
rgCaption.RadioLabels[rgCaption.SelectedItem].ToString()
|
||||||
) {
|
) {
|
||||||
AllowsMultipleSelection = isMulti,
|
OpenMode = Enum.Parse<OpenMode>(
|
||||||
OpenMode = mode,
|
rgOpenMode.RadioLabels[rgOpenMode.SelectedItem].ToString()),
|
||||||
MustExist = cbMustExist.Checked ?? false
|
MustExist = cbMustExist.Checked ?? false,
|
||||||
|
AllowsMultipleSelection = cbAllowMultipleSelection.Checked ?? false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (cbIcons.Checked ?? false) {
|
if (cbIcons.Checked ?? false) {
|
||||||
@@ -101,9 +116,9 @@ namespace UICatalog.Scenarios {
|
|||||||
|
|
||||||
fd.Monochrome = cbMonochrome.Checked ?? false;
|
fd.Monochrome = cbMonochrome.Checked ?? false;
|
||||||
|
|
||||||
if (csv) {
|
if (rgAllowedTypes.SelectedItem > 0) {
|
||||||
fd.AllowedTypes.Add (new FileDialog2.AllowedType ("Data File", ".csv", ".tsv"));
|
fd.AllowedTypes.Add (new FileDialog2.AllowedType ("Data File", ".csv", ".tsv"));
|
||||||
fd.AllowedTypesIsStrict = strict;
|
fd.AllowedTypesIsStrict = rgAllowedTypes.SelectedItem > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Application.Run (fd);
|
Application.Run (fd);
|
||||||
@@ -113,7 +128,7 @@ namespace UICatalog.Scenarios {
|
|||||||
"Canceled",
|
"Canceled",
|
||||||
"You canceled navigation and did not pick anything",
|
"You canceled navigation and did not pick anything",
|
||||||
"Ok");
|
"Ok");
|
||||||
} else if (isMulti) {
|
} else if (cbAllowMultipleSelection.Checked ?? false) {
|
||||||
MessageBox.Query (
|
MessageBox.Query (
|
||||||
"Chosen!",
|
"Chosen!",
|
||||||
"You chose:" + Environment.NewLine +
|
"You chose:" + Environment.NewLine +
|
||||||
|
|||||||
Reference in New Issue
Block a user