From 965dc3554e7fc0a73b0372b02a212abf97f3bbe2 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 28 Apr 2024 20:40:49 +0200 Subject: [PATCH] Minor refact --- src/ui/Forms/JoinSubtitles.cs | 29 ++++++----------------------- src/ui/Logic/ListViewSorter.cs | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/ui/Forms/JoinSubtitles.cs b/src/ui/Forms/JoinSubtitles.cs index f78641c14..ccaec13ce 100644 --- a/src/ui/Forms/JoinSubtitles.cs +++ b/src/ui/Forms/JoinSubtitles.cs @@ -445,7 +445,7 @@ namespace Nikse.SubtitleEdit.Forms numericUpDownAddMs.Enabled = radioButtonJoinAddTime.Checked; labelAddTime.Enabled = radioButtonJoinAddTime.Checked; SortAndLoad(); - SetSortArrow(listViewParts.Columns[3], SortOrder.None); + ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None); } private void contextMenuStripParts_Opening(object sender, System.ComponentModel.CancelEventArgs e) @@ -584,7 +584,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - SetSortArrow(listViewParts.Columns[3], SortOrder.None); + ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveUp(listViewParts); } @@ -595,7 +595,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - SetSortArrow(listViewParts.Columns[3], SortOrder.None); + ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveDown(listViewParts); } @@ -606,7 +606,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - SetSortArrow(listViewParts.Columns[3], SortOrder.None); + ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveToTop(listViewParts); } @@ -617,7 +617,7 @@ namespace Nikse.SubtitleEdit.Forms return; } - SetSortArrow(listViewParts.Columns[3], SortOrder.None); + ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None); MoveToBottom(listViewParts); } @@ -649,24 +649,7 @@ 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; - } + ListViewSorter.SetSortArrow(listViewParts.Columns[e.Column], sorter.Descending ? SortOrder.Descending : SortOrder.Ascending); } } } diff --git a/src/ui/Logic/ListViewSorter.cs b/src/ui/Logic/ListViewSorter.cs index 88c6de482..11de406db 100644 --- a/src/ui/Logic/ListViewSorter.cs +++ b/src/ui/Logic/ListViewSorter.cs @@ -1,8 +1,6 @@ using Nikse.SubtitleEdit.Core.Common; using System; -using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -61,5 +59,26 @@ namespace Nikse.SubtitleEdit.Logic var str1 = _numbers.Replace(lvi1.SubItems[ColumnNumber].Text, m => m.Value.PadLeft(10, '0')).RemoveChar(' '); return string.Compare(str2, str1, StringComparison.Ordinal); } + + public static void SetSortArrow(ColumnHeader columnHeader, SortOrder sortOrder) + { + const string ascArrow = " ▲"; + const string descArrow = " ▼"; + + if (columnHeader.Text.EndsWith(ascArrow) || columnHeader.Text.EndsWith(descArrow)) + { + columnHeader.Text = columnHeader.Text.Substring(0, columnHeader.Text.Length - 2); + } + + switch (sortOrder) + { + case SortOrder.Ascending: + columnHeader.Text += ascArrow; + break; + case SortOrder.Descending: + columnHeader.Text += descArrow; + break; + } + } } }