mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-21 18:52:36 +01:00
Work on #8257
This commit is contained in:
parent
d6add13334
commit
f6399cf63e
@ -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;
|
||||
|
@ -94,7 +94,12 @@ 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)
|
||||
|
||||
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)))
|
||||
{
|
||||
@ -103,6 +108,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user