From c3e86a75c117ce29c22086558fe0583dabd8d03c Mon Sep 17 00:00:00 2001
From: MojitoJoe1813 <71935206+MojitoJoe1813@users.noreply.github.com>
Date: Sun, 1 Dec 2024 22:39:18 +0100
Subject: [PATCH 1/2] Adding sorting by columns
---
TeddyBench/TeddyBench.csproj | 2 +-
TeddyBench/TrackSortDialog.Designer.cs | 10 ++-
TeddyBench/TrackSortDialog.cs | 100 ++++++++++++++++++++++++-
3 files changed, 108 insertions(+), 4 deletions(-)
diff --git a/TeddyBench/TeddyBench.csproj b/TeddyBench/TeddyBench.csproj
index 49d2fa4..8f5eff6 100644
--- a/TeddyBench/TeddyBench.csproj
+++ b/TeddyBench/TeddyBench.csproj
@@ -4,7 +4,7 @@
true
- net48
+ net481
WinExe
false
true
diff --git a/TeddyBench/TrackSortDialog.Designer.cs b/TeddyBench/TrackSortDialog.Designer.cs
index 2985057..4278434 100644
--- a/TeddyBench/TrackSortDialog.Designer.cs
+++ b/TeddyBench/TrackSortDialog.Designer.cs
@@ -51,6 +51,7 @@ private void InitializeComponent()
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -149,7 +150,8 @@ private void InitializeComponent()
this.lstTracks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
- this.columnHeader3});
+ this.columnHeader3,
+ this.columnHeader4});
this.lstTracks.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstTracks.FullRowSelect = true;
this.lstTracks.HideSelection = false;
@@ -164,6 +166,7 @@ private void InitializeComponent()
this.lstTracks.TabIndex = 0;
this.lstTracks.UseCompatibleStateImageBehavior = false;
this.lstTracks.View = System.Windows.Forms.View.Details;
+ this.lstTracks.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lstTracks_ColumnClick);
//
// columnHeader1
//
@@ -179,6 +182,10 @@ private void InitializeComponent()
this.columnHeader3.Text = "ID3";
this.columnHeader3.Width = 219;
//
+ // columnHeader4
+ //
+ this.columnHeader4.Text = "Track No.";
+ //
// TrackSortDialog
//
this.AcceptButton = this.btnEncode;
@@ -216,5 +223,6 @@ private void InitializeComponent()
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
+ private System.Windows.Forms.ColumnHeader columnHeader4;
}
}
\ No newline at end of file
diff --git a/TeddyBench/TrackSortDialog.cs b/TeddyBench/TrackSortDialog.cs
index 7c35377..a051a83 100644
--- a/TeddyBench/TrackSortDialog.cs
+++ b/TeddyBench/TrackSortDialog.cs
@@ -1,19 +1,25 @@
using Id3;
using System;
+using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TeddyBench
{
+
+
public partial class TrackSortDialog : Form
{
private string[] FileNames;
+ private bool isAscending = false;
+ private string[] originalColumnHeaders;
private List> FileList = new List>();
public TrackSortDialog()
@@ -38,6 +44,13 @@ protected override void OnLoad(EventArgs e)
}
UpdateView();
+
+ // Store original column headers
+ originalColumnHeaders = new string[lstTracks.Columns.Count];
+ for (int i = 0; i < lstTracks.Columns.Count; i++)
+ {
+ originalColumnHeaders[i] = lstTracks.Columns[i].Text;
+ }
}
private Id3Tag GetTag(string f)
@@ -46,7 +59,8 @@ private Id3Tag GetTag(string f)
{
Mp3 mp3 = new Mp3(f, Mp3Permissions.Read);
- Id3Tag ret = mp3.GetAllTags().Where(t => t.Track.IsAssigned).FirstOrDefault();
+ //Id3Tag ret = mp3.GetAllTags().Where(t => t.Track.IsAssigned).FirstOrDefault();
+ Id3Tag ret = mp3.GetAllTags().FirstOrDefault();
return ret;
}
@@ -68,13 +82,33 @@ private void UpdateView()
lvi.Text = track.ToString();
string id3 = "";
+ string storedTrack = "";
if (item.Item2 != null)
{
- id3 = item.Item2.Artists + " - " + item.Item2.Title;
+ string artist;
+ if (item.Item2.Artists == null)
+ {
+ artist = Regex.Replace(item.Item2.Band, @"\0+$", "");
+ } else
+ {
+ artist = Regex.Replace(item.Item2.Artists, @"\0+$", "");
+ }
+
+ id3 = artist + " - " + Regex.Replace(item.Item2.Title, @"\0+$", "");
+
+ if (item.Item2.Track.IsAssigned)
+ {
+ storedTrack = item.Item2.Track.ToString();
+ }
+
}
+
lvi.SubItems.Add(item.Item1);
lvi.SubItems.Add(id3);
+ lvi.SubItems.Add(item.Item2.Track);
+ // Set the ToolTip text to the full ID3 information
+ lvi.ToolTipText = id3;
lstTracks.Items.Add(lvi);
@@ -111,6 +145,8 @@ private void btnUp_Click(object sender, EventArgs e)
int numberOfItems = lstTracks.Items.Count;
List