Minor refact

This commit is contained in:
Nikolaj Olsson 2024-04-28 20:40:49 +02:00
parent 59ab0fca5b
commit 965dc3554e
2 changed files with 27 additions and 25 deletions

View File

@ -445,7 +445,7 @@ namespace Nikse.SubtitleEdit.Forms
numericUpDownAddMs.Enabled = radioButtonJoinAddTime.Checked; numericUpDownAddMs.Enabled = radioButtonJoinAddTime.Checked;
labelAddTime.Enabled = radioButtonJoinAddTime.Checked; labelAddTime.Enabled = radioButtonJoinAddTime.Checked;
SortAndLoad(); SortAndLoad();
SetSortArrow(listViewParts.Columns[3], SortOrder.None); ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None);
} }
private void contextMenuStripParts_Opening(object sender, System.ComponentModel.CancelEventArgs e) private void contextMenuStripParts_Opening(object sender, System.ComponentModel.CancelEventArgs e)
@ -584,7 +584,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
SetSortArrow(listViewParts.Columns[3], SortOrder.None); ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None);
MoveUp(listViewParts); MoveUp(listViewParts);
} }
@ -595,7 +595,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
SetSortArrow(listViewParts.Columns[3], SortOrder.None); ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None);
MoveDown(listViewParts); MoveDown(listViewParts);
} }
@ -606,7 +606,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
SetSortArrow(listViewParts.Columns[3], SortOrder.None); ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None);
MoveToTop(listViewParts); MoveToTop(listViewParts);
} }
@ -617,7 +617,7 @@ namespace Nikse.SubtitleEdit.Forms
return; return;
} }
SetSortArrow(listViewParts.Columns[3], SortOrder.None); ListViewSorter.SetSortArrow(listViewParts.Columns[3], SortOrder.None);
MoveToBottom(listViewParts); MoveToBottom(listViewParts);
} }
@ -649,24 +649,7 @@ namespace Nikse.SubtitleEdit.Forms
lv.Sort(); lv.Sort();
SetSortArrow(listViewParts.Columns[e.Column], sorter.Descending ? SortOrder.Descending : SortOrder.Ascending); ListViewSorter.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;
}
} }
} }
} }

View File

@ -1,8 +1,6 @@
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Common;
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; 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(' '); var str1 = _numbers.Replace(lvi1.SubItems[ColumnNumber].Text, m => m.Value.PadLeft(10, '0')).RemoveChar(' ');
return string.Compare(str2, str1, StringComparison.Ordinal); 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;
}
}
} }
} }