Skip to content

Commit

Permalink
When only one file is present in container, autoselect this one
Browse files Browse the repository at this point in the history
  • Loading branch information
RNoeldner committed Jun 26, 2023
1 parent 953babc commit 7fa35bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Application/FormEditSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ private async void BtnOpenFile_Click(object? sender, EventArgs e)
m_ViewSettings.FillGuessSettings,
list =>
{
if (list.Count==1)
return list.First();
using var frm = new FormSelectInDropdown(list, list.First(x => x.AssumeDelimited()));
if (frm.ShowWithFont(this, true) == DialogResult.Cancel)
throw new OperationCanceledException();
Expand Down
10 changes: 6 additions & 4 deletions Application/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ public async Task LoadCsvOrZipFileAsync(string fileName, CancellationToken cance
m_ViewSettings.GuessHasHeader, m_ViewSettings.GuessNewLine, m_ViewSettings.GuessComment,
m_ViewSettings.FillGuessSettings, list =>
{
using var frm = new FormSelectInDropdown(list, list.First(x => x.AssumeDelimited()));
if (frm.ShowWithFont(this, true) == DialogResult.Cancel)
throw new OperationCanceledException();
return frm.SelectedText;
if (list.Count==1)
return list.First();
using var frm = new FormSelectInDropdown(list, list.First(x => x.AssumeDelimited()));
if (frm.ShowWithFont(this, true) == DialogResult.Cancel)
throw new OperationCanceledException();
return frm.SelectedText;
}, m_ViewSettings.DefaultInspectionResult,
PgpHelper.GetKeyAndValidate(fileName, m_ViewSettings.KeyFileRead), cancellationToken);

Expand Down
4 changes: 2 additions & 2 deletions Library/ClassLibraryCSV/CsvHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static IEnumerable<ZipEntry> GetFilesInZip(this ZipFile archive)
bool guessCodePage, bool guessEscapePrefix,
bool guessDelimiter, bool guessQualifier, bool guessStartRow,
bool guessHasHeader, bool guessNewLine, bool guessCommentLine,
FillGuessSettings fillGuessSettings, Func<IEnumerable<string>, string>? selectFile,
FillGuessSettings fillGuessSettings, Func<IReadOnlyCollection<string>, string>? selectFile,
InspectionResult defaultInspectionResult
#if SupportPGP
, string privateKey
Expand Down Expand Up @@ -357,7 +357,7 @@ InspectionResult defaultInspectionResult
return setting;
}
using var zipFile = new ZipFile(fileName2);
var list = zipFile.GetFilesInZip().OrderByDescending(x => x.Name.AssumeDelimited()).ThenByDescending(x => x.Size).Select(x => $"{x.Name}");
var list = zipFile.GetFilesInZip().OrderByDescending(x => x.Name.AssumeDelimited()).ThenByDescending(x => x.Size).Select(x => $"{x.Name}").ToList();
selectedFile = selectFile?.Invoke(list) ?? list.First();
}

Expand Down

0 comments on commit 7fa35bf

Please sign in to comment.