From 805c0c35b29b2e21a5f4a3b3cc19bfbff14252dc Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 8 Dec 2019 11:59:15 +0100 Subject: [PATCH] Add checkbox option to remove line breaks from field contents in grid export dialog. Closes #474 --- out/locale/en/LC_MESSAGES/default.po | 7 +++-- source/apphelpers.pas | 8 +++-- source/exportgrid.dfm | 46 +++++++++++++++++----------- source/exportgrid.pas | 27 +++++++++++++--- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/out/locale/en/LC_MESSAGES/default.po b/out/locale/en/LC_MESSAGES/default.po index ac85a2a0..5f806f08 100644 --- a/out/locale/en/LC_MESSAGES/default.po +++ b/out/locale/en/LC_MESSAGES/default.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: HeidiSQL\n" "POT-Creation-Date: 2012-11-05 21:40\n" -"PO-Revision-Date: 2019-10-05 14:07+0200\n" +"PO-Revision-Date: 2019-12-08 11:56+0100\n" "Last-Translator: Ansgar Becker \n" "Language-Team: English (http://www.transifex.com/projects/p/heidisql/language/en/)\n" "MIME-Version: 1.0\n" @@ -15,7 +15,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Language: en\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Poedit 2.2.3\n" +"X-Generator: Poedit 2.2.4\n" #. AboutBox..Caption #: about.dfm:5 @@ -855,6 +855,9 @@ msgstr "Include auto increment column" msgid "Include SQL query" msgstr "Include SQL query" +msgid "Remove linebreaks from contents" +msgstr "Remove linebreaks from contents" + #. frmExportGrid..popupCSVchar..menuCSVcomma..Caption #: exportgrid.dfm:266 msgid "Comma" diff --git a/source/apphelpers.pas b/source/apphelpers.pas index c105bbf7..89aacfe6 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -157,10 +157,10 @@ type asExportSQLDatabase, asExportSQLServerDatabase, asExportSQLOutput, asExportSQLAddComments, asExportSQLRemoveAutoIncrement, asExportSQLRemoveDefiner, asGridExportWindowWidth, asGridExportWindowHeight, asGridExportOutputCopy, asGridExportOutputFile, asGridExportFilename, asGridExportRecentFiles, asGridExportEncoding, asGridExportFormat, asGridExportSelection, - asGridExportColumnNames, asGridExportIncludeAutoInc, asGridExportIncludeQuery, + asGridExportColumnNames, asGridExportIncludeAutoInc, asGridExportIncludeQuery, asGridExportRemoveLinebreaks, asGridExportSeparator, asGridExportEncloser, asGridExportTerminator, asGridExportNull, - asGridExportClpFormat, asGridExportClpColumnNames, asGridExportClpIncludeAutoInc, + asGridExportClpFormat, asGridExportClpColumnNames, asGridExportClpIncludeAutoInc, asGridExportClpRemoveLinebreaks, asGridExportClpSeparator, asGridExportClpEncloser, asGridExportClpTerminator, asGridExportClpNull, asCSVImportSeparator, asCSVImportEncloser, asCSVImportTerminator, asCSVImportFieldEscaper, asCSVImportWindowWidth, asCSVImportWindowHeight, @@ -3560,7 +3560,7 @@ begin InitSetting(asExportSQLRemoveAutoIncrement, 'ExportSQLRemoveAutoIncrement', 0, False); InitSetting(asExportSQLRemoveDefiner, 'ExportSQLRemoveDefiner', 0, True); InitSetting(asGridExportWindowWidth, 'GridExportWindowWidth', 400); - InitSetting(asGridExportWindowHeight, 'GridExportWindowHeight', 460); + InitSetting(asGridExportWindowHeight, 'GridExportWindowHeight', 480); InitSetting(asGridExportOutputCopy, 'GridExportOutputCopy', 0, True); InitSetting(asGridExportOutputFile, 'GridExportOutputFile', 0, False); InitSetting(asGridExportFilename, 'GridExportFilename', 0, False, ''); @@ -3571,6 +3571,7 @@ begin InitSetting(asGridExportColumnNames, 'GridExportColumnNames', 0, True); InitSetting(asGridExportIncludeAutoInc, 'GridExportAutoInc', 0, True); InitSetting(asGridExportIncludeQuery, 'GridExportIncludeQuery', 0, False); + InitSetting(asGridExportRemoveLinebreaks, 'GridExportRemoveLinebreaks', 0, False); InitSetting(asGridExportSeparator, 'GridExportSeparator', 0, False, ';'); InitSetting(asGridExportEncloser, 'GridExportEncloser', 0, False, ''); InitSetting(asGridExportTerminator, 'GridExportTerminator', 0, False, '\r\n'); @@ -3579,6 +3580,7 @@ begin InitSetting(asGridExportClpFormat, 'GridExportClpFormat', 0); InitSetting(asGridExportClpColumnNames, 'GridExportClpColumnNames', 0, False); InitSetting(asGridExportClpIncludeAutoInc, 'GridExportClpAutoInc', 0, True); + InitSetting(asGridExportClpRemoveLinebreaks, 'GridExportClpRemoveLinebreaks', 0, False); InitSetting(asGridExportClpSeparator, 'GridExportClpSeparator', 0, False, ';'); InitSetting(asGridExportClpEncloser, 'GridExportClpEncloser', 0, False, ''); InitSetting(asGridExportClpTerminator, 'GridExportClpTerminator', 0, False, '\r\n'); diff --git a/source/exportgrid.dfm b/source/exportgrid.dfm index f47f0e54..6b4e08fd 100644 --- a/source/exportgrid.dfm +++ b/source/exportgrid.dfm @@ -3,10 +3,10 @@ object frmExportGrid: TfrmExportGrid Top = 0 BorderIcons = [biSystemMenu] Caption = 'Export grid rows' - ClientHeight = 422 + ClientHeight = 445 ClientWidth = 373 Color = clBtnFace - Constraints.MinHeight = 450 + Constraints.MinHeight = 480 Constraints.MinWidth = 350 Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText @@ -22,12 +22,12 @@ object frmExportGrid: TfrmExportGrid OnShow = FormShow DesignSize = ( 373 - 422) + 445) PixelsPerInch = 96 TextHeight = 13 object btnOK: TButton Left = 209 - Top = 389 + Top = 412 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -39,7 +39,7 @@ object frmExportGrid: TfrmExportGrid end object btnCancel: TButton Left = 290 - Top = 389 + Top = 412 Width = 75 Height = 25 Anchors = [akRight, akBottom] @@ -52,7 +52,7 @@ object frmExportGrid: TfrmExportGrid Left = 8 Top = 112 Width = 137 - Height = 271 + Height = 294 Anchors = [akLeft, akTop, akBottom] Caption = 'Output format' ItemIndex = 0 @@ -153,37 +153,37 @@ object frmExportGrid: TfrmExportGrid Left = 151 Top = 184 Width = 214 - Height = 199 + Height = 222 Anchors = [akTop, akRight, akBottom] Caption = 'Options' TabOrder = 5 DesignSize = ( 214 - 199) + 222) object lblSeparator: TLabel Left = 6 - Top = 97 + Top = 116 Width = 76 Height = 13 Caption = 'Field separator:' end object lblEncloser: TLabel Left = 6 - Top = 122 + Top = 141 Width = 44 Height = 13 Caption = 'Encloser:' end object lblTerminator: TLabel Left = 6 - Top = 148 + Top = 167 Width = 76 Height = 13 Caption = 'Line terminator:' end object lblNull: TLabel Left = 6 - Top = 175 + Top = 194 Width = 57 Height = 13 Caption = 'NULL value:' @@ -201,7 +201,7 @@ object frmExportGrid: TfrmExportGrid end object editSeparator: TButtonedEdit Left = 106 - Top = 93 + Top = 112 Width = 93 Height = 21 Anchors = [akLeft, akTop, akRight] @@ -216,7 +216,7 @@ object frmExportGrid: TfrmExportGrid end object editEncloser: TButtonedEdit Left = 106 - Top = 119 + Top = 138 Width = 93 Height = 21 Anchors = [akLeft, akTop, akRight] @@ -230,7 +230,7 @@ object frmExportGrid: TfrmExportGrid end object editTerminator: TButtonedEdit Left = 106 - Top = 145 + Top = 164 Width = 93 Height = 21 Anchors = [akLeft, akTop, akRight] @@ -255,14 +255,15 @@ object frmExportGrid: TfrmExportGrid object chkIncludeQuery: TCheckBox Left = 6 Top = 64 - Width = 177 + Width = 191 Height = 17 + Anchors = [akLeft, akTop, akRight] Caption = 'Include SQL query' TabOrder = 2 end object editNull: TButtonedEdit Left = 106 - Top = 172 + Top = 191 Width = 93 Height = 21 Anchors = [akLeft, akTop, akRight] @@ -274,10 +275,19 @@ object frmExportGrid: TfrmExportGrid OnChange = editCSVChange OnRightButtonClick = editCSVRightButtonClick end + object chkRemoveLinebreaks: TCheckBox + Left = 6 + Top = 87 + Width = 191 + Height = 17 + Anchors = [akLeft, akTop, akRight] + Caption = 'Remove linebreaks from contents' + TabOrder = 7 + end end object btnSetClipboardDefaults: TButton Left = 8 - Top = 389 + Top = 412 Width = 153 Height = 25 Anchors = [akLeft, akBottom] diff --git a/source/exportgrid.pas b/source/exportgrid.pas index 0e607494..c42a8281 100644 --- a/source/exportgrid.pas +++ b/source/exportgrid.pas @@ -50,6 +50,7 @@ type lblNull: TLabel; editNull: TButtonedEdit; btnSetClipboardDefaults: TButton; + chkRemoveLinebreaks: TCheckBox; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure CalcSize(Sender: TObject); @@ -123,6 +124,7 @@ begin chkIncludeColumnNames.Checked := AppSettings.ReadBool(asGridExportClpColumnNames); chkIncludeAutoIncrement.Checked := AppSettings.ReadBool(asGridExportClpIncludeAutoInc); chkIncludeQuery.Checked := False; // Always off in copy mode + chkRemoveLinebreaks.Checked := AppSettings.ReadBool(asGridExportClpRemoveLinebreaks); FCSVSeparator := AppSettings.ReadString(asGridExportClpSeparator); FCSVEncloser := AppSettings.ReadString(asGridExportClpEncloser); FCSVTerminator := AppSettings.ReadString(asGridExportClpTerminator); @@ -135,6 +137,7 @@ begin chkIncludeColumnNames.Checked := AppSettings.ReadBool(asGridExportColumnNames); chkIncludeAutoIncrement.Checked := AppSettings.ReadBool(asGridExportIncludeAutoInc); chkIncludeQuery.Checked := AppSettings.ReadBool(asGridExportIncludeQuery); + chkRemoveLinebreaks.Checked := AppSettings.ReadBool(asGridExportRemoveLinebreaks); FCSVSeparator := AppSettings.ReadString(asGridExportSeparator); FCSVEncloser := AppSettings.ReadString(asGridExportEncloser); FCSVTerminator := AppSettings.ReadString(asGridExportTerminator); @@ -161,6 +164,7 @@ begin AppSettings.WriteBool(asGridExportColumnNames, chkIncludeColumnNames.Checked); AppSettings.WriteBool(asGridExportIncludeAutoInc, chkIncludeAutoIncrement.Checked); AppSettings.WriteBool(asGridExportIncludeQuery, chkIncludeQuery.Checked); + AppSettings.WriteBool(asGridExportRemoveLinebreaks, chkRemoveLinebreaks.Checked); AppSettings.WriteString(asGridExportSeparator, FCSVSeparator); AppSettings.WriteString(asGridExportEncloser, FCSVEncloser); AppSettings.WriteString(asGridExportTerminator, FCSVTerminator); @@ -394,6 +398,7 @@ begin AppSettings.WriteInt(asGridExportClpFormat, grpFormat.ItemIndex); AppSettings.WriteBool(asGridExportClpColumnNames, chkIncludeColumnNames.Checked); AppSettings.WriteBool(asGridExportClpIncludeAutoInc, chkIncludeAutoIncrement.Checked); + AppSettings.WriteBool(asGridExportRemoveLinebreaks, chkRemoveLinebreaks.Checked); AppSettings.WriteString(asGridExportClpSeparator, FCSVSeparator); AppSettings.WriteString(asGridExportClpEncloser, FCSVEncloser); AppSettings.WriteString(asGridExportClpTerminator, FCSVTerminator); @@ -806,17 +811,29 @@ begin else tmp := ''; end; + // Row contents Col := Grid.Header.Columns.GetFirstVisibleColumn; while Col > NoColumn do begin if Col <> ExcludeCol then begin - if (GridData.DataType(Col).Category in [dtcBinary, dtcSpatial]) and (not Mainform.actBlobAsText.Checked) then - Data := GridData.HexValue(Col) - else + if (GridData.DataType(Col).Category in [dtcBinary, dtcSpatial]) + and (not Mainform.actBlobAsText.Checked) then begin + Data := GridData.HexValue(Col); + end else begin Data := GridData.Col(Col); + end; + // Keep formatted numeric values if (GridData.DataType(Col).Category in [dtcInteger, dtcReal]) - and (ExportFormat in [efExcel, efHTML, efMarkDown]) then - Data := FormatNumber(Data, False); + and (ExportFormat in [efExcel, efHTML, efMarkDown]) then begin + Data := FormatNumber(Data, False); + end; + + // Remove linebreaks, see #474 + if chkRemoveLinebreaks.Checked then begin + Data := StringReplace(Data, #13#10, ' ', [rfReplaceAll]); + Data := StringReplace(Data, #13, ' ', [rfReplaceAll]); + Data := StringReplace(Data, #10, ' ', [rfReplaceAll]); + end; case ExportFormat of efHTML: begin