Skip to content

Commit bd0d2df

Browse files
committed
Minor updates and QOL fixes
Various minor updates and quality-of-life fixes: - Select Columns dialog control by keyboard updates - Detect Columns dialog right-click for fixed width columns widths - Data Convert dialog SQL batch size +100 -100 - MySQL escape '\' as '\\' - Update scripts comment add "Notepad++ CSV Lint",
1 parent e48e21d commit bd0d2df

File tree

8 files changed

+91
-33
lines changed

8 files changed

+91
-33
lines changed

CSVLintNppPlugin/CsvLint/CsvAnalyze.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,14 @@ public static void StatisticalReportData(CsvDefinition csvdef)
594594
INotepadPPGateway notepad = new NotepadPPGateway();
595595
IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
596596

597-
string FILE_NAME = Path.GetFileName(notepad.GetCurrentFilePath());
598-
string strhead = csvdef.ColNameHeader ? " (+1 header line)" : "";
597+
// title and default comment
598+
sb.Append("Analyze data report\r\n");
599+
List<String> comment = CsvEdit.ScriptInfo(notepad);
600+
foreach (var str in comment) sb.Append(string.Format("{0}\r\n", str));
599601

600-
sb.Append("Analyze dataset\r\n");
601-
sb.Append(string.Format("File: {0}\r\n", FILE_NAME));
602-
sb.Append(string.Format("Date: {0}\r\n", DateTime.Now.ToString("dd-MMM-yyyy HH:mm")));
603-
sb.Append(string.Format("CSV Lint: v{0}\r\n\r\n", Main.GetVersion()));
604-
sb.Append(string.Format("Data records: {0}{1}\r\n", lineCount, strhead));
602+
// display data file and analysis properties
603+
string strhead = csvdef.ColNameHeader ? " (+1 header line)" : "";
604+
sb.Append(string.Format("\r\nData records: {0}{1}\r\n", lineCount, strhead));
605605
if (commentCount > 0) sb.Append(string.Format("Comment lines total: {0}\r\n", commentCount));
606606
sb.Append(string.Format("Max.unique values: {0}\r\n", Main.Settings.UniqueValuesMax));
607607
sb.Append("\r\n");

CSVLintNppPlugin/CsvLint/CsvEdit.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public static List<String> ScriptInfo(INotepadPPGateway notepad)
301301
string VERSION_NO = Main.GetVersion();
302302
string FILE_NAME = Path.GetFileName(notepad.GetCurrentFilePath());
303303

304-
list.Add(string.Format("CSV Lint plug-in: v{0}", VERSION_NO));
304+
list.Add(string.Format("Notepad++ CSV Lint plug-in: v{0}", VERSION_NO));
305305
list.Add(string.Format("File: {0}", FILE_NAME));
306306
list.Add(string.Format("Date: {0}", DateTime.Now.ToString("dd-MMM-yyyy HH:mm")));
307307

@@ -582,6 +582,10 @@ public static void ConvertToSQL(CsvDefinition csvdef)
582582
//str = ??
583583
}
584584
}
585+
// Exception for MySQL/MariaDB escape backslashes
586+
if (Main.Settings.DataConvertSQL == 0) // 0=MySQL/MariaDB
587+
colvalue = colvalue.Replace("\\", "\\\\");
588+
585589
// sql single quotes
586590
colvalue = colvalue.Replace("'", "''");
587591
colvalue = string.Format("'{0}'", colvalue);

CSVLintNppPlugin/Forms/ColumnsSelectForm.cs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Linq;
55
using System.Net.NetworkInformation;
6+
using System.Reflection;
67
using System.Windows.Forms;
78

89
namespace CSVLintNppPlugin.Forms
@@ -218,15 +219,15 @@ private void InitializeComponent()
218219
this.pnlDistinctOptions.Location = new System.Drawing.Point(4, 420);
219220
this.pnlDistinctOptions.Name = "pnlDistinctOptions";
220221
this.pnlDistinctOptions.Size = new System.Drawing.Size(365, 45);
221-
this.pnlDistinctOptions.TabIndex = 11;
222+
this.pnlDistinctOptions.TabIndex = 13;
222223
//
223224
// rdbSortDesc
224225
//
225226
this.rdbSortDesc.AutoSize = true;
226227
this.rdbSortDesc.Location = new System.Drawing.Point(267, 24);
227228
this.rdbSortDesc.Name = "rdbSortDesc";
228229
this.rdbSortDesc.Size = new System.Drawing.Size(82, 17);
229-
this.rdbSortDesc.TabIndex = 14;
230+
this.rdbSortDesc.TabIndex = 17;
230231
this.rdbSortDesc.TabStop = true;
231232
this.rdbSortDesc.Tag = "1";
232233
this.rdbSortDesc.Text = "Descending";
@@ -239,7 +240,7 @@ private void InitializeComponent()
239240
this.rdbSortAsc.Location = new System.Drawing.Point(189, 24);
240241
this.rdbSortAsc.Name = "rdbSortAsc";
241242
this.rdbSortAsc.Size = new System.Drawing.Size(75, 17);
242-
this.rdbSortAsc.TabIndex = 13;
243+
this.rdbSortAsc.TabIndex = 16;
243244
this.rdbSortAsc.TabStop = true;
244245
this.rdbSortAsc.Tag = "1";
245246
this.rdbSortAsc.Text = "Ascending";
@@ -252,7 +253,7 @@ private void InitializeComponent()
252253
this.chkDistinctCount.Location = new System.Drawing.Point(12, 25);
253254
this.chkDistinctCount.Name = "chkDistinctCount";
254255
this.chkDistinctCount.Size = new System.Drawing.Size(167, 17);
255-
this.chkDistinctCount.TabIndex = 12;
256+
this.chkDistinctCount.TabIndex = 15;
256257
this.chkDistinctCount.Tag = "1";
257258
this.chkDistinctCount.Text = "Select distinct values and sort";
258259
this.chkDistinctCount.UseVisualStyleBackColor = true;
@@ -264,7 +265,7 @@ private void InitializeComponent()
264265
this.chkNewFile.Location = new System.Drawing.Point(12, 3);
265266
this.chkNewFile.Name = "chkNewFile";
266267
this.chkNewFile.Size = new System.Drawing.Size(108, 17);
267-
this.chkNewFile.TabIndex = 11;
268+
this.chkNewFile.TabIndex = 14;
268269
this.chkNewFile.Text = "Result in new tab";
269270
this.chkNewFile.UseVisualStyleBackColor = true;
270271
//
@@ -298,7 +299,7 @@ private void InitializeComponent()
298299
this.gbxAvailableColumns.Location = new System.Drawing.Point(3, 3);
299300
this.gbxAvailableColumns.Name = "gbxAvailableColumns";
300301
this.gbxAvailableColumns.Size = new System.Drawing.Size(221, 326);
301-
this.gbxAvailableColumns.TabIndex = 17;
302+
this.gbxAvailableColumns.TabIndex = 3;
302303
this.gbxAvailableColumns.TabStop = false;
303304
this.gbxAvailableColumns.Text = "Available columns";
304305
//
@@ -314,6 +315,7 @@ private void InitializeComponent()
314315
this.listAvailableColumns.TabIndex = 3;
315316
this.listAvailableColumns.SelectedIndexChanged += new System.EventHandler(this.list_SelectedIndexChanged);
316317
this.listAvailableColumns.DoubleClick += new System.EventHandler(this.listAvailableColumns_DoubleClick);
318+
this.listAvailableColumns.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listAvailableColumns_KeyDown);
317319
//
318320
// pnlColSelect
319321
//
@@ -327,15 +329,15 @@ private void InitializeComponent()
327329
this.pnlColSelect.Location = new System.Drawing.Point(230, 3);
328330
this.pnlColSelect.Name = "pnlColSelect";
329331
this.pnlColSelect.Size = new System.Drawing.Size(104, 326);
330-
this.pnlColSelect.TabIndex = 2;
332+
this.pnlColSelect.TabIndex = 4;
331333
//
332334
// btnAllRemove
333335
//
334336
this.btnAllRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
335337
this.btnAllRemove.Location = new System.Drawing.Point(0, 242);
336338
this.btnAllRemove.Name = "btnAllRemove";
337339
this.btnAllRemove.Size = new System.Drawing.Size(100, 30);
338-
this.btnAllRemove.TabIndex = 7;
340+
this.btnAllRemove.TabIndex = 8;
339341
this.btnAllRemove.Text = "<< All";
340342
this.btnAllRemove.UseVisualStyleBackColor = true;
341343
this.btnAllRemove.Click += new System.EventHandler(this.btnAllRemove_Click);
@@ -346,7 +348,7 @@ private void InitializeComponent()
346348
this.btnAllSelect.Location = new System.Drawing.Point(0, 206);
347349
this.btnAllSelect.Name = "btnAllSelect";
348350
this.btnAllSelect.Size = new System.Drawing.Size(100, 30);
349-
this.btnAllSelect.TabIndex = 6;
351+
this.btnAllSelect.TabIndex = 7;
350352
this.btnAllSelect.Text = "All >>";
351353
this.btnAllSelect.UseVisualStyleBackColor = true;
352354
this.btnAllSelect.Click += new System.EventHandler(this.btnAllSelect_Click);
@@ -356,7 +358,7 @@ private void InitializeComponent()
356358
this.btnColRemove.Location = new System.Drawing.Point(0, 84);
357359
this.btnColRemove.Name = "btnColRemove";
358360
this.btnColRemove.Size = new System.Drawing.Size(100, 30);
359-
this.btnColRemove.TabIndex = 5;
361+
this.btnColRemove.TabIndex = 6;
360362
this.btnColRemove.Text = "<<";
361363
this.btnColRemove.UseVisualStyleBackColor = true;
362364
this.btnColRemove.Click += new System.EventHandler(this.btnColRemove_Click);
@@ -366,7 +368,7 @@ private void InitializeComponent()
366368
this.btnColSelect.Location = new System.Drawing.Point(0, 48);
367369
this.btnColSelect.Name = "btnColSelect";
368370
this.btnColSelect.Size = new System.Drawing.Size(100, 30);
369-
this.btnColSelect.TabIndex = 4;
371+
this.btnColSelect.TabIndex = 5;
370372
this.btnColSelect.Text = ">>";
371373
this.btnColSelect.UseVisualStyleBackColor = true;
372374
this.btnColSelect.Click += new System.EventHandler(this.btnColSelect_Click);
@@ -378,14 +380,14 @@ private void InitializeComponent()
378380
this.pnlColMove.Location = new System.Drawing.Point(567, 3);
379381
this.pnlColMove.Name = "pnlColMove";
380382
this.pnlColMove.Size = new System.Drawing.Size(103, 310);
381-
this.pnlColMove.TabIndex = 3;
383+
this.pnlColMove.TabIndex = 10;
382384
//
383385
// btnColMoveDown
384386
//
385387
this.btnColMoveDown.Location = new System.Drawing.Point(0, 84);
386388
this.btnColMoveDown.Name = "btnColMoveDown";
387389
this.btnColMoveDown.Size = new System.Drawing.Size(100, 30);
388-
this.btnColMoveDown.TabIndex = 10;
390+
this.btnColMoveDown.TabIndex = 12;
389391
this.btnColMoveDown.Text = "Move down";
390392
this.btnColMoveDown.UseVisualStyleBackColor = true;
391393
this.btnColMoveDown.Click += new System.EventHandler(this.btnColMoveDown_Click);
@@ -395,7 +397,7 @@ private void InitializeComponent()
395397
this.btnColMoveUp.Location = new System.Drawing.Point(0, 48);
396398
this.btnColMoveUp.Name = "btnColMoveUp";
397399
this.btnColMoveUp.Size = new System.Drawing.Size(100, 30);
398-
this.btnColMoveUp.TabIndex = 9;
400+
this.btnColMoveUp.TabIndex = 11;
399401
this.btnColMoveUp.Text = "Move up";
400402
this.btnColMoveUp.UseVisualStyleBackColor = true;
401403
this.btnColMoveUp.Click += new System.EventHandler(this.btnColMoveUp_Click);
@@ -409,7 +411,7 @@ private void InitializeComponent()
409411
this.gbxSelectedColumns.Location = new System.Drawing.Point(340, 3);
410412
this.gbxSelectedColumns.Name = "gbxSelectedColumns";
411413
this.gbxSelectedColumns.Size = new System.Drawing.Size(221, 326);
412-
this.gbxSelectedColumns.TabIndex = 18;
414+
this.gbxSelectedColumns.TabIndex = 9;
413415
this.gbxSelectedColumns.TabStop = false;
414416
this.gbxSelectedColumns.Text = "Selected columns";
415417
//
@@ -422,9 +424,10 @@ private void InitializeComponent()
422424
this.listSelectedColumns.Location = new System.Drawing.Point(4, 18);
423425
this.listSelectedColumns.Name = "listSelectedColumns";
424426
this.listSelectedColumns.Size = new System.Drawing.Size(213, 303);
425-
this.listSelectedColumns.TabIndex = 8;
427+
this.listSelectedColumns.TabIndex = 9;
426428
this.listSelectedColumns.SelectedIndexChanged += new System.EventHandler(this.list_SelectedIndexChanged);
427429
this.listSelectedColumns.DoubleClick += new System.EventHandler(this.listSelectedColumns_DoubleClick);
430+
this.listSelectedColumns.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listSelectedColumns_KeyDown);
428431
//
429432
// ColumnsSelectForm
430433
//
@@ -517,13 +520,35 @@ private void listAvailableColumns_DoubleClick(object sender, EventArgs e)
517520
// double click to add column
518521
btnColSelect_Click(sender, e);
519522
}
523+
private void listAvailableColumns_KeyDown(object sender, KeyEventArgs e)
524+
{
525+
if (e.KeyCode == Keys.Enter) btnColSelect_Click(sender, e);
526+
}
520527

521528
private void listSelectedColumns_DoubleClick(object sender, EventArgs e)
522529
{
523530
// double click to remove column
524531
btnColRemove_Click(sender, e);
525532
}
526533

534+
private void listSelectedColumns_KeyDown(object sender, KeyEventArgs e)
535+
{
536+
if (e.KeyCode == Keys.Enter)
537+
{
538+
btnColRemove_Click(sender, e);
539+
}
540+
else if (e.Control && e.KeyCode == Keys.Up)
541+
{
542+
btnColMoveUp_Click(sender, e);
543+
listSelectedColumns.SelectedIndex++;
544+
}
545+
else if (e.Control && e.KeyCode == Keys.Down)
546+
{
547+
btnColMoveDown_Click(sender, e);
548+
listSelectedColumns.SelectedIndex--;
549+
}
550+
}
551+
527552
private void btnColMoveUp_Click(object sender, EventArgs e)
528553
{
529554
// move item up in the list

CSVLintNppPlugin/Forms/ColumnsSelectForm.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<data name="lblDescription.Text" xml:space="preserve">
121-
<value>Select columns to rearrange or count unique values by selecting one or more columns and press OK. Check "Select distinct" to only select unique values or combinations of values, including a new "Count distinct" column.</value>
121+
<value>Select and rearrange columns or count unique values by selecting one or more columns and press OK. Check the option "Select distinct" to select only unique values or combinations of values, this option also adds a Count_distinct column.</value>
122122
</data>
123123
</root>

CSVLintNppPlugin/Forms/DataConvertForm.Designer.cs

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

CSVLintNppPlugin/Forms/DetectColumnsForm.Designer.cs

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CSVLintNppPlugin/Forms/DetectColumnsForm.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CSVLint;
22
using Kbg.NppPluginNET;
3+
using Kbg.NppPluginNET.PluginInfrastructure;
34
using System;
45
using System.Collections.Generic;
56
using System.ComponentModel;
@@ -19,7 +20,7 @@ public DetectColumnsForm()
1920
InitializeComponent();
2021

2122
// tooltip initialization
22-
helperTip.SetToolTip(btnFixedWidthPos, "Column end positions based on current column widths");
23+
helperTip.SetToolTip(btnFixedWidthPos, "Column end positions based on current column widths\n(right-click for columns widths instead)");
2324
}
2425

2526
public char Separator { get; set; }
@@ -146,15 +147,27 @@ private void OnChkbx_CheckedChanged(object sender, EventArgs e)
146147

147148
private void btnFixedWidthPos_Click(object sender, EventArgs e)
148149
{
150+
// left-lick for absolute positions or right-click for individual widths, treat keyboard as left-click
151+
var abspos = true;
152+
if (e is MouseEventArgs me) abspos = (me.Button == MouseButtons.Left);
153+
var poswid = (abspos ? "end positions" : "widths");
154+
149155
// show dialog
150-
DialogResult dialogResult = MessageBox.Show("Paste column end positions based on the current column widths?", "Paste end positions", MessageBoxButtons.OKCancel);
156+
DialogResult dialogResult = MessageBox.Show("Paste column " + poswid + " based on the current column widths?", "Paste " + poswid, MessageBoxButtons.OKCancel);
151157
if (dialogResult == DialogResult.OK)
152158
{
153159
// paste column positions
154160
if (!Main.TryGetCurrentCsvDef(out CsvDefinition csvdef))
155161
return;
156-
txtFixedWidthPos.Text = csvdef.GetColumnWidths(true);
162+
txtFixedWidthPos.Text = csvdef.GetColumnWidths(abspos);
157163
}
158164
}
165+
166+
private void btnFixedWidthPos_MouseUp(object sender, MouseEventArgs e)
167+
{
168+
// Use MouseUp instead of MouseDown, because MouseDown is not triggered when using keyboard
169+
if (e.Button == MouseButtons.Right)
170+
btnFixedWidthPos_Click(sender, e);
171+
}
159172
}
160173
}

0 commit comments

Comments
 (0)