Skip to content

Commit

Permalink
Improve vhf and vhr folder selection messages
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Oct 14, 2024
1 parent 2bfcfbc commit 97c10f5
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 53 deletions.
70 changes: 37 additions & 33 deletions src/Vocup.WinForms/Forms/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ private void SettingsDialog_Load(object sender, EventArgs e)
TbVhfPath.Text = settings.VhfPath;
TbVhrPath.Text = settings.VhrPath;

switch (settings.OverrideCulture)
CbLanguage.SelectedIndex = settings.OverrideCulture switch
{
case "en-US": CbLanguage.SelectedIndex = 1; break;
case "de-DE": CbLanguage.SelectedIndex = 2; break;
case "nl-NL": CbLanguage.SelectedIndex = 3; break;
default: CbLanguage.SelectedIndex = 0; break; // System language
}
"en-US" => 1,
"de-DE" => 2,
"nl-NL" => 3,
_ => 0,
};

// Evaluation
CbManualCheck.Checked = settings.UserEvaluates;
Expand Down Expand Up @@ -163,46 +163,50 @@ private void TrbWrongRight_ValueChanged(object sender, EventArgs e)

private void BtnVhfPath_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog fbd = new FolderBrowserDialog
using FolderBrowserDialog fbd = new()
{
UseDescriptionForTitle = true,
Description = Messages.BrowseVhfPath,
SelectedPath = settings.VhfPath
})
};

if (fbd.ShowDialog() == DialogResult.OK)
{
if (fbd.ShowDialog() == DialogResult.OK)
try
{
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(fbd.SelectedPath);

TbVhfPath.Text = fbd.SelectedPath;
}
catch (IOException)
{
try
{
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(fbd.SelectedPath);

TbVhfPath.Text = fbd.SelectedPath;
}
catch (IOException)
{
MessageBox.Show(Messages.VhfPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show(Messages.VhfPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

private void BtnVhrPath_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog fbd = new FolderBrowserDialog { SelectedPath = settings.VhrPath })
using FolderBrowserDialog fbd = new()
{
if (fbd.ShowDialog() == DialogResult.OK)
UseDescriptionForTitle = true,
Description = Messages.BrowseVhrPath,
SelectedPath = settings.VhrPath,
};

if (fbd.ShowDialog() == DialogResult.OK)
{
try
{
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(fbd.SelectedPath);

TbVhrPath.Text = fbd.SelectedPath;
}
catch (IOException)
{
try
{
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(fbd.SelectedPath);

TbVhrPath.Text = fbd.SelectedPath;
}
catch (IOException)
{
MessageBox.Show(Messages.VhrPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show(Messages.VhrPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/Vocup.WinForms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,31 +253,31 @@ private void FileTreeView_FileSelected(object sender, FileSelectedEventArgs e)

private void FileTreeView_BrowseClick(object sender, EventArgs e)
{
using (FolderBrowserDialog dialog = new FolderBrowserDialog
using FolderBrowserDialog dialog = new()
{
UseDescriptionForTitle = true,
Description = Messages.BrowseVhfPath,
SelectedPath = Program.Settings.VhfPath
})
};

if (dialog.ShowDialog() == DialogResult.OK)
{
if (dialog.ShowDialog() == DialogResult.OK)
try
{
try
{
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(dialog.SelectedPath);

// Eventually refresh tree view root path
if (dialog.SelectedPath != Program.Settings.VhfPath)
{
Program.Settings.VhfPath = dialog.SelectedPath;
FileTreeView.RootPath = dialog.SelectedPath;
}
}
catch (IOException)
// This call fails for inaccessible paths like optical disk drives
_ = Directory.GetFiles(dialog.SelectedPath);

// Eventually refresh tree view root path
if (dialog.SelectedPath != Program.Settings.VhfPath)
{
MessageBox.Show(Messages.VhfPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
Program.Settings.VhfPath = dialog.SelectedPath;
FileTreeView.RootPath = dialog.SelectedPath;
}
}
catch (IOException)
{
MessageBox.Show(Messages.VhfPathInvalid, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/Vocup.WinForms/Properties/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/Vocup.WinForms/Properties/Messages.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Tipp: Unter Optionen können Sie festlegen, wie oft eine Vokabel richtig hintere
<value>Herzlichen Glückwunsch!</value>
</data>
<data name="BrowseVhfPath" xml:space="preserve">
<value>Bitte wählen Sie einen Ordner als Standardspeicherort für Ihre Vokabelhefte aus.</value>
<value>Wählen Sie den Standardordner für Vokabelhefte aus.</value>
</data>
<data name="CsvExportError" xml:space="preserve">
<value>Beim Exportieren einer CSV Datei ist ein unerwarteter Fehler aufgetreten.
Expand Down Expand Up @@ -328,4 +328,7 @@ Stellen Sie sicher, dass die Datei nicht leer ist.</value>
<data name="VocupFileWriteErrorT" xml:space="preserve">
<value>Fehler beim Speichern</value>
</data>
<data name="BrowseVhrPath" xml:space="preserve">
<value>Wählen Sie den Ordner für Übungserbnisse aus.</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Vocup.WinForms/Properties/Messages.nl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,7 @@ Controleer of het bestand niet leeg is.</value>
<data name="VocupFileWriteErrorT" xml:space="preserve">
<value>Fout bij opslaan</value>
</data>
<data name="BrowseVhrPath" xml:space="preserve">
<value>Selecteer de map voor oefenresultaten</value>
</data>
</root>
5 changes: 4 additions & 1 deletion src/Vocup.WinForms/Properties/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Hint: In the settings you can configure how often a word has to be correctly tra
<value>Congratulations!</value>
</data>
<data name="BrowseVhfPath" xml:space="preserve">
<value>Please select the default folder for your vocabulary books.</value>
<value>Select the default folder for vocabulary books.</value>
</data>
<data name="CsvExportError" xml:space="preserve">
<value>An unexpected error occured when exporting a CSV file.
Expand Down Expand Up @@ -328,4 +328,7 @@ Please ensure that the file is not empty.</value>
<data name="VocupFileWriteErrorT" xml:space="preserve">
<value>Error when saving</value>
</data>
<data name="BrowseVhrPath" xml:space="preserve">
<value>Select the folder for practice results</value>
</data>
</root>

0 comments on commit 97c10f5

Please sign in to comment.