Skip to content
Snippets Groups Projects
Commit abe67b3f authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Move the confirmation dialog to a separate method, provide fallback.

Sometimes the TaskDialog doesn't work but raises an exception. Until we
can reproduce and fix this issue we simply provide a fallback using the
(less user-friendly) MessageBox.

Refers to #2
parent 49a86173
No related branches found
No related tags found
No related merge requests found
...@@ -254,19 +254,27 @@ namespace ATxTray ...@@ -254,19 +254,27 @@ namespace ATxTray
return; return;
} }
ReviewNewTxDialog();
}
private static void ReviewNewTxDialog() {
var folderName = _selectedDir.Name; var folderName = _selectedDir.Name;
var locationPath = _selectedDir.Parent?.FullName; var locationPath = _selectedDir.Parent?.FullName;
var size = Conv.BytesToString(FsUtils.GetDirectorySize(_selectedDir.FullName)); var size = Conv.BytesToString(FsUtils.GetDirectorySize(_selectedDir.FullName));
const string caption = "AutoTx - Folder Selection Confirmation";
const string instructionText = "Review your folder selection:";
var footerText = "Selection summary:\n\n" +
$"Selected Folder: [{folderName}]\n" +
$"Size: {size}\n" +
$"Folder Location: [{locationPath}]";
_confirmDialog = new TaskDialog { _confirmDialog = new TaskDialog {
Caption = "AutoTx - Folder Selection Confirmation", Caption = caption,
// Icon is buggy in the API and has to be set via an event handler, see below // Icon is buggy in the API and has to be set via an event handler, see below
// Icon = TaskDialogStandardIcon.Shield, // Icon = TaskDialogStandardIcon.Shield,
InstructionText = "Review your folder selection:", InstructionText = instructionText,
FooterText = "Selection summary:\n\n" + FooterText = footerText,
$"Selected Folder: [{folderName}]\n" +
$"Size: {size}\n" +
$"Folder Location: [{locationPath}]",
DetailsExpanded = true, DetailsExpanded = true,
StandardButtons = TaskDialogStandardButtons.Cancel, StandardButtons = TaskDialogStandardButtons.Cancel,
}; };
...@@ -283,7 +291,17 @@ namespace ATxTray ...@@ -283,7 +291,17 @@ namespace ATxTray
_confirmDialog.Controls.Add(acceptBtn); _confirmDialog.Controls.Add(acceptBtn);
_confirmDialog.Controls.Add(changeBtn); _confirmDialog.Controls.Add(changeBtn);
_confirmDialog.Show(); try {
_confirmDialog.Show();
}
catch (Exception ex) {
Log.Error("Showing the TaskDialog failed: {0}", ex.Message);
var res = MessageBox.Show($"{instructionText}\n{footerText}\n\n" +
"Press [OK] to confirm selection.", caption,
MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (res == DialogResult.OK)
SubmitDirForTransfer();
}
} }
private static void TaskDialogOpened(object sender, EventArgs e) { private static void TaskDialogOpened(object sender, EventArgs e) {
...@@ -293,6 +311,16 @@ namespace ATxTray ...@@ -293,6 +311,16 @@ namespace ATxTray
private static void ConfirmAcceptClick(object sender, EventArgs e) { private static void ConfirmAcceptClick(object sender, EventArgs e) {
_confirmDialog.Close(); _confirmDialog.Close();
SubmitDirForTransfer();
}
private static void ConfirmChangeClick(object sender, EventArgs e) {
_confirmDialog.Close();
Log.Debug("User wants to change directory choice.");
StartNewTransfer(sender, e);
}
private static void SubmitDirForTransfer() {
Log.Debug($"User accepted directory choice [{_selectedDir.FullName}]."); Log.Debug($"User accepted directory choice [{_selectedDir.FullName}].");
var tgtPath = Path.Combine(_submitPath, _selectedDir.Name); var tgtPath = Path.Combine(_submitPath, _selectedDir.Name);
try { try {
...@@ -304,13 +332,8 @@ namespace ATxTray ...@@ -304,13 +332,8 @@ namespace ATxTray
@"AutoTx New Transfer Error", MessageBoxButtons.OK, MessageBoxIcon.Error); @"AutoTx New Transfer Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
Log.Info($"Submitted new transfer: [{_selectedDir.FullName}].");
}
private static void ConfirmChangeClick(object sender, EventArgs e) { Log.Info($"Submitted new transfer: [{_selectedDir.FullName}].");
_confirmDialog.Close();
Log.Debug("User wants to change directory choice.");
StartNewTransfer(sender, e);
} }
/// <summary> /// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment