Skip to content

Commit c51226b

Browse files
committed
Sort dialog, new option Sort on length of value
Sort dialog, new option Sort on length of value
1 parent 29c250e commit c51226b

File tree

5 files changed

+121
-50
lines changed

5 files changed

+121
-50
lines changed

CSVLintNppPlugin/CsvLint/CsvEdit.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ private static string SortableString(string val, CsvColumn csvcol)
10021002
/// </summary>
10031003
/// <param name="data">csv data</param>
10041004
/// <param name="AscDesc">true = ascending, true = decending</param>
1005-
public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc)
1005+
public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc, bool ValLen)
10061006
{
10071007
// this should never happen
10081008
if (SortIdx > csvdef.Fields.Count - 1)
@@ -1056,7 +1056,12 @@ public static void SortData(CsvDefinition csvdef, int SortIdx, bool AscDesc)
10561056
{
10571057
// construct sortable value
10581058
var val = (SortIdx < values.Count ? values[SortIdx] : "");
1059-
sortval = SortableString(val, csvcol);
1059+
1060+
// sort on values or on length of values
1061+
if (ValLen)
1062+
sortval = SortableString(val, csvcol); // sort on values
1063+
else
1064+
sortval = val.Length.ToString().PadLeft(8, '0'); // sort on length of values. Implicit assumption: max. string length = 99999999 characters
10601065
}
10611066

10621067
// reconstruct original line of data

CSVLintNppPlugin/Forms/CsvLintWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ private void btnSort_Click(object sender, EventArgs e)
351351
// user clicked OK or Cancel
352352
int idx = frmsort.SortColumn;
353353
bool asc = frmsort.SortAscending;
354+
bool val = frmsort.SortValue;
354355

355356
// clear up
356357
frmsort.Dispose();
@@ -365,7 +366,7 @@ private void btnSort_Click(object sender, EventArgs e)
365366
var dtStart = DateTime.Now;
366367

367368
// split column
368-
CsvEdit.SortData(csvdef, idx, asc);
369+
CsvEdit.SortData(csvdef, idx, asc, val);
369370

370371
var dtElapsed = (DateTime.Now - dtStart).ToString(@"hh\:mm\:ss\.fff");
371372

CSVLintNppPlugin/Forms/SortForm.Designer.cs

Lines changed: 99 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CSVLintNppPlugin/Forms/SortForm.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public SortForm()
2020
public int SortColumn { get; set; }
2121

2222
public bool SortAscending { get; set; }
23+
public bool SortValue { get; set; }
2324

2425
public void InitialiseSetting(CsvDefinition csvdef)
2526
{
@@ -36,14 +37,19 @@ public void InitialiseSetting(CsvDefinition csvdef)
3637
cmbSelectColumn.SelectedIndex = idx;
3738

3839
// which option selected
39-
rdbtnAscending.Checked = (Main.Settings.SortAscending);
40+
rdbtnAscending.Checked = (Main.Settings.SortAscending);
4041
rdbtnDescending.Checked = (!Main.Settings.SortAscending);
42+
43+
rdbtnValue.Checked = (Main.Settings.SortValue);
44+
rdbtnLength.Checked = (!Main.Settings.SortValue);
4145
}
46+
4247
private void EvaluateOkButton()
4348
{
4449
// can not press OK when nothing selected
4550
btnOk.Enabled = (cmbSelectColumn.SelectedIndex > 0);
4651
}
52+
4753
private void cmbSelectColumn_SelectedIndexChanged(object sender, EventArgs e)
4854
{
4955
EvaluateOkButton();
@@ -55,6 +61,7 @@ private void SortForm_FormClosing(object sender, FormClosingEventArgs e)
5561
SortColumn = cmbSelectColumn.SelectedIndex - 1; // zero based, first item is a dummy
5662

5763
SortAscending = rdbtnAscending.Checked;
64+
SortValue = rdbtnValue.Checked;
5865
}
5966

6067
private void btnOk_Click(object sender, EventArgs e)
@@ -63,6 +70,7 @@ private void btnOk_Click(object sender, EventArgs e)
6370
Main.Settings.SortColName = cmbSelectColumn.Items[cmbSelectColumn.SelectedIndex].ToString(); ;
6471

6572
Main.Settings.SortAscending = rdbtnAscending.Checked;
73+
Main.Settings.SortValue = rdbtnValue.Checked;
6674

6775
// save to file
6876
Main.Settings.SaveToIniFile();

CSVLintNppPlugin/Tools/Settings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ public int DataConvertBatch
274274
[Category("UserDialogs"), Browsable(false), DefaultValue("")]
275275
public string SortColName { get; set; }
276276

277-
// ADD NEW COLUMNS (2) user preferences
277+
[Category("UserDialogs"), Browsable(false), DefaultValue(true)]
278+
public bool SortValue { get; set; }
279+
280+
// ADD NEW COLUMNS (2) user preferences
278281
[Description("Add new columns (2)"), Category("UserDialogs"), Browsable(false), DefaultValue("/")]
279282
public string SplitChar { get; set; }
280283

0 commit comments

Comments
 (0)