From 0c28e8a0ec0014d8c2b57cccccd2c9a893b53aa5 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 28 Apr 2024 19:09:03 +0200 Subject: [PATCH] Add sort mark to join subs - thx Leon :) Work on #8257 --- src/ui/Forms/GenerateVideoWithHardSubs.cs | 38 ++++++++++++++++------- src/ui/Forms/JoinSubtitles.cs | 25 +++++++++++++++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/ui/Forms/GenerateVideoWithHardSubs.cs b/src/ui/Forms/GenerateVideoWithHardSubs.cs index 9bfe80d3a..4458db121 100644 --- a/src/ui/Forms/GenerateVideoWithHardSubs.cs +++ b/src/ui/Forms/GenerateVideoWithHardSubs.cs @@ -29,7 +29,7 @@ namespace Nikse.SubtitleEdit.Forms private long _totalFrames; private StringBuilder _log; private readonly bool _isAssa; - private readonly FfmpegMediaInfo _mediaInfo; + private FfmpegMediaInfo _mediaInfo; private bool _promptFFmpegParameters; private readonly bool _mpvOn; private readonly string _mpvSubtitleFileName; @@ -248,7 +248,6 @@ namespace Nikse.SubtitleEdit.Forms UiUtil.FixLargeFonts(this, buttonGenerate); UiUtil.FixFonts(this, 2000); - _mediaInfo = FfmpegMediaInfo.Parse(inputVideoFileName); if (_videoInfo != null && _videoInfo.TotalSeconds > 0) @@ -459,6 +458,8 @@ namespace Nikse.SubtitleEdit.Forms labelPleaseWait.Text = $"{index + 1}/{_batchVideoAndSubList.Count} - {LanguageSettings.Current.General.PleaseWait}"; var videoAndSub = _batchVideoAndSubList[index]; + + _mediaInfo = FfmpegMediaInfo.Parse(videoAndSub.VideoFileName); _videoInfo = UiUtil.GetVideoInfo(videoAndSub.VideoFileName); if (useSourceResolution) { @@ -2162,25 +2163,38 @@ namespace Nikse.SubtitleEdit.Forms item.SubtitleFileFileSizeInBytes = new FileInfo(subFileName).Length; } - - var vInfo = new VideoInfo { Success = false }; - if (fileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) + var width = 0; + var height = 0; + var mediaInfo = FfmpegMediaInfo.Parse(fileName); + if (mediaInfo.VideoWidth > 0 && mediaInfo.VideoHeight > 0) { - vInfo = QuartsPlayer.GetVideoInfo(fileName); + width = mediaInfo.VideoWidth; + height = mediaInfo.VideoHeight; + } + else + { + var vInfo = new VideoInfo { Success = false }; + if (fileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) + { + vInfo = QuartsPlayer.GetVideoInfo(fileName); + if (!vInfo.Success) + { + vInfo = LibMpvDynamic.GetVideoInfo(fileName); + } + } + if (!vInfo.Success) { - vInfo = LibMpvDynamic.GetVideoInfo(fileName); + vInfo = UiUtil.GetVideoInfo(fileName); } - } - if (!vInfo.Success) - { - vInfo = UiUtil.GetVideoInfo(fileName); + width = vInfo.Width; + height = vInfo.Height; } var listViewItem = new ListViewItem(fileName); listViewItem.Tag = item; - listViewItem.SubItems.Add($"{vInfo.Width}x{vInfo.Height}"); + listViewItem.SubItems.Add($"{width}x{height}"); var s = Utilities.FormatBytesToDisplayFileSize(item.VideoFileSizeInBytes); listViewItem.SubItems.Add(s); listViewItem.SubItems.Add(Path.GetFileName(item.SubtitleFileName)); diff --git a/src/ui/Forms/JoinSubtitles.cs b/src/ui/Forms/JoinSubtitles.cs index 79e3b69ae..9035c0988 100644 --- a/src/ui/Forms/JoinSubtitles.cs +++ b/src/ui/Forms/JoinSubtitles.cs @@ -3,6 +3,7 @@ using Nikse.SubtitleEdit.Core.SubtitleFormats; using Nikse.SubtitleEdit.Logic; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -443,6 +444,7 @@ namespace Nikse.SubtitleEdit.Forms numericUpDownAddMs.Enabled = radioButtonJoinAddTime.Checked; labelAddTime.Enabled = radioButtonJoinAddTime.Checked; SortAndLoad(); + SetSortArrow(listViewParts.Columns[3], SortOrder.None); } private void contextMenuStripParts_Opening(object sender, System.ComponentModel.CancelEventArgs e) @@ -581,6 +583,7 @@ namespace Nikse.SubtitleEdit.Forms return; } + SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveUp(listViewParts); } @@ -591,6 +594,7 @@ namespace Nikse.SubtitleEdit.Forms return; } + SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveDown(listViewParts); } @@ -601,6 +605,7 @@ namespace Nikse.SubtitleEdit.Forms return; } + SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveToTop(listViewParts); } @@ -611,6 +616,7 @@ namespace Nikse.SubtitleEdit.Forms return; } + SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveToBottom(listViewParts); } @@ -641,6 +647,25 @@ namespace Nikse.SubtitleEdit.Forms } lv.Sort(); + + SetSortArrow(listViewParts.Columns[e.Column], sorter.Descending ? SortOrder.Descending : SortOrder.Ascending); + } + + private static void SetSortArrow(ColumnHeader head, SortOrder order) + { + const string ascArrow = " ▲"; + const string descArrow = " ▼"; + + // remove arrow + if (head.Text.EndsWith(ascArrow) || head.Text.EndsWith(descArrow)) + head.Text = head.Text.Substring(0, head.Text.Length - 2); + + // add arrow + switch (order) + { + case SortOrder.Ascending: head.Text += ascArrow; break; + case SortOrder.Descending: head.Text += descArrow; break; + } } } }