This commit is contained in:
Nikolaj Olsson 2024-04-29 06:02:52 +02:00
parent d6add13334
commit f6399cf63e
3 changed files with 38 additions and 17 deletions

View File

@ -68,7 +68,7 @@ namespace Nikse.SubtitleEdit.Core.Common
if (info.VideoWidth == 0 &&
parts.Length == 2 &&
int.TryParse(parts[0], out var w) &&
int.TryParse(parts[0], out var h))
int.TryParse(parts[1], out var h))
{
info.VideoWidth = w;
info.VideoHeight = h;

View File

@ -94,15 +94,21 @@ namespace Nikse.SubtitleEdit.Forms
private void listViewParts_DragDrop(object sender, DragEventArgs e)
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var fileName in files)
{
if (!_fileNamesToJoin.Any(file => file.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
{
_fileNamesToJoin.Add(fileName);
}
}
SortAndLoad();
TaskDelayHelper.RunDelayed(TimeSpan.FromMilliseconds(1), () =>
{
var fileNames = files.ToList();
fileNames.Sort(ListViewSorter.NaturalComparer);
foreach (var fileName in fileNames)
{
if (!_fileNamesToJoin.Any(file => file.Equals(fileName, StringComparison.OrdinalIgnoreCase)))
{
_fileNamesToJoin.Add(fileName);
}
}
SortAndLoad();
});
}
private void SortAndLoad()
@ -289,6 +295,7 @@ namespace Nikse.SubtitleEdit.Forms
{
var sub = subtitles[i];
var lvi = new ListViewItem($"{sub.Paragraphs.Count:#,###,###}");
lvi.Tag = fileName;
if (sub.Paragraphs.Count > 0)
{
lvi.SubItems.Add(sub.Paragraphs[0].StartTime.ToString());
@ -371,7 +378,9 @@ namespace Nikse.SubtitleEdit.Forms
if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
var sb = new StringBuilder();
foreach (string fileName in openFileDialog1.FileNames)
var fileNames = openFileDialog1.FileNames.ToList();
fileNames.Sort(ListViewSorter.NaturalComparer);
foreach (var fileName in fileNames)
{
Application.DoEvents();
if (File.Exists(fileName))
@ -390,6 +399,7 @@ namespace Nikse.SubtitleEdit.Forms
}
}
}
SortAndLoad();
if (sb.Length > 0)
{
@ -650,6 +660,13 @@ namespace Nikse.SubtitleEdit.Forms
lv.Sort();
ListViewSorter.SetSortArrow(listViewParts.Columns[e.Column], sorter.Descending ? SortOrder.Descending : SortOrder.Ascending);
_fileNamesToJoin.Clear();
foreach (ListViewItem item in listViewParts.Items)
{
_fileNamesToJoin.Add((string)item.Tag);
}
SortAndLoad();
}
}
}

View File

@ -13,8 +13,8 @@ namespace Nikse.SubtitleEdit.Logic
public bool IsDisplayFileSize { get; set; }
public bool Descending { get; set; }
private readonly Regex _numbers = new Regex(@"\d+", RegexOptions.Compiled);
private readonly Regex _invariantNumber = new Regex(@"\d+\.{1,2}", RegexOptions.Compiled);
private static readonly Regex Numbers = new Regex(@"\d+", RegexOptions.Compiled);
private static readonly Regex InvariantNumber = new Regex(@"\d+\.{1,2}", RegexOptions.Compiled);
public int Compare(object o1, object o2)
{
@ -33,7 +33,7 @@ namespace Nikse.SubtitleEdit.Logic
var s1 = lvi1.SubItems[ColumnNumber].Text;
var s2 = lvi2.SubItems[ColumnNumber].Text;
if (_invariantNumber.IsMatch(s1) && _invariantNumber.IsMatch(s2) &&
if (InvariantNumber.IsMatch(s1) && InvariantNumber.IsMatch(s2) &&
int.TryParse(s1, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var i1) &&
int.TryParse(s2, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var i2))
{
@ -54,10 +54,7 @@ namespace Nikse.SubtitleEdit.Logic
return i1 > i2 ? 1 : i1 == i2 ? 0 : -1;
}
// use natural sort order
var str2 = _numbers.Replace(lvi2.SubItems[ColumnNumber].Text, m => m.Value.PadLeft(10, '0')).RemoveChar(' ');
var str1 = _numbers.Replace(lvi1.SubItems[ColumnNumber].Text, m => m.Value.PadLeft(10, '0')).RemoveChar(' ');
return string.Compare(str2, str1, StringComparison.Ordinal);
return NaturalComparer(lvi2.SubItems[ColumnNumber].Text, lvi1.SubItems[ColumnNumber].Text);
}
public static void SetSortArrow(ColumnHeader columnHeader, SortOrder sortOrder)
@ -80,5 +77,12 @@ namespace Nikse.SubtitleEdit.Logic
break;
}
}
public static int NaturalComparer(string x, string y)
{
var str2 = Numbers.Replace(x, m => m.Value.PadLeft(10, '0')).RemoveChar(' ');
var str1 = Numbers.Replace(y, m => m.Value.PadLeft(10, '0')).RemoveChar(' ');
return string.Compare(str2, str1, StringComparison.OrdinalIgnoreCase);
}
}
}