Permalink
Browse files

Use the grid export dialog for setting values for copy-to-clipboard c…

…licks on grids. Adds a new button in the lower left on that dialog. See https://www.heidisql.com/forum.php?t=23190
  • Loading branch information...
ansgarbecker committed Mar 6, 2017
1 parent 31dc8f3 commit ba300916de3e9c91a5d2b23afcb915ce4020c55f
Showing with 91 additions and 37 deletions.
  1. +10 −2 out/locale/en/LC_MESSAGES/default.po
  2. +16 −5 source/exportgrid.dfm
  3. +44 −11 source/exportgrid.pas
  4. +15 −2 source/helpers.pas
  5. +6 −17 source/main.pas
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2017-02-28 20:21+0100\n"
"PO-Revision-Date: 2017-03-06 20:22+0100\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/"
"language/en/)\n"
@@ -16,7 +16,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.6\n"
"X-Generator: Poedit 1.8.12\n"
#. AboutBox..Caption
#: about.dfm:5
@@ -877,6 +877,14 @@ msgstr "Mac OS linebreak"
msgid "NUL character"
msgstr "NUL character"
#. grid export
msgid "Clipboard settings changed."
msgstr "Clipboard settings changed."
#. grid export
msgid "Save clipboard settings"
msgstr "Save clipboard settings"
#. frmInsertFiles..Caption
#: insertfiles.dfm:5
msgid "Insert files..."
View
@@ -249,7 +249,6 @@ object frmExportGrid: TfrmExportGrid
Anchors = [akLeft, akTop, akRight]
Caption = 'Include auto increment column'
TabOrder = 1
OnClick = CalcSize
end
object chkIncludeQuery: TCheckBox
Left = 6
@@ -274,10 +273,22 @@ object frmExportGrid: TfrmExportGrid
OnRightButtonClick = editCSVRightButtonClick
end
end
object btnSetClipboardDefaults: TButton
Left = 8
Top = 399
Width = 153
Height = 25
Anchors = [akLeft, akBottom]
Caption = 'Save clipboard settings'
ImageIndex = 4
Images = MainForm.ImageListMain
TabOrder = 6
OnClick = btnSetClipboardDefaultsClick
end
object popupCSVchar: TPopupMenu
AutoHotkeys = maManual
Left = 24
Top = 390
Left = 224
Top = 6
object menuCSVtab: TMenuItem
Caption = 'Tab'
Hint = '\t'
@@ -346,7 +357,7 @@ object frmExportGrid: TfrmExportGrid
object popupRecentFiles: TPopupMenu
AutoHotkeys = maManual
OnPopup = popupRecentFilesPopup
Left = 112
Top = 390
Left = 312
Top = 6
end
end
View
@@ -4,7 +4,7 @@ interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, VirtualTrees, SynExportHTML, gnugettext;
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, VirtualTrees, SynExportHTML, gnugettext, ActnList;
type
TGridExportFormat = (efExcel, efCSV, efHTML, efXML, efSQLInsert, efSQLReplace, efSQLDeleteInsert, efLaTeX, efWiki, efPHPArray, efMarkDown, efJSON);
@@ -48,6 +48,7 @@ TfrmExportGrid = class(TForm)
chkIncludeQuery: TCheckBox;
lblNull: TLabel;
editNull: TButtonedEdit;
btnSetClipboardDefaults: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CalcSize(Sender: TObject);
@@ -62,12 +63,14 @@ TfrmExportGrid = class(TForm)
procedure btnOKClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure grpFormatClick(Sender: TObject);
procedure btnSetClipboardDefaultsClick(Sender: TObject);
private
{ Private declarations }
FCSVEditor: TButtonedEdit;
FCSVSeparator, FCSVEncloser, FCSVTerminator, FCSVNull: String;
FGrid: TVirtualStringTree;
FRecentFiles: TStringList;
FHiddenCopyMode: Boolean;
const FFormatToFileExtension: Array[TGridExportFormat] of String =
(('csv'), ('csv'), ('html'), ('xml'), ('sql'), ('sql'), ('sql'), ('LaTeX'), ('wiki'), ('php'), ('md'), ('json'));
const FFormatToDescription: Array[TGridExportFormat] of String =
@@ -110,22 +113,37 @@ procedure TfrmExportGrid.FormCreate(Sender: TObject);
grpFormat.Items.Clear;
for FormatDesc in FFormatToDescription do
grpFormat.Items.Add(FormatDesc);
grpFormat.ItemIndex := AppSettings.ReadInt(asGridExportFormat);
grpSelection.ItemIndex := AppSettings.ReadInt(asGridExportSelection);
chkIncludeColumnNames.Checked := AppSettings.ReadBool(asGridExportColumnNames);
chkIncludeQuery.Checked := AppSettings.ReadBool(asGridExportIncludeQuery);
FCSVSeparator := AppSettings.ReadString(asGridExportSeparator);
FCSVEncloser := AppSettings.ReadString(asGridExportEncloser);
FCSVTerminator := AppSettings.ReadString(asGridExportTerminator);
FCSVNull := AppSettings.ReadString(asGridExportNull);
FHiddenCopyMode := (Owner = MainForm.actCopy) or (Owner = MainForm.actCut);
if FHiddenCopyMode then begin
grpFormat.ItemIndex := AppSettings.ReadInt(asGridExportClpFormat);
grpSelection.ItemIndex := 0; // Always use selected cells in copy mode
chkIncludeColumnNames.Checked := AppSettings.ReadBool(asGridExportClpColumnNames);
chkIncludeAutoIncrement.Checked := AppSettings.ReadBool(asGridExportClpIncludeAutoInc);
chkIncludeQuery.Checked := False; // Always off in copy mode
FCSVSeparator := AppSettings.ReadString(asGridExportClpSeparator);
FCSVEncloser := AppSettings.ReadString(asGridExportClpEncloser);
FCSVTerminator := AppSettings.ReadString(asGridExportClpTerminator);
FCSVNull := AppSettings.ReadString(asGridExportClpNull);
end else begin
grpFormat.ItemIndex := AppSettings.ReadInt(asGridExportFormat);
grpSelection.ItemIndex := AppSettings.ReadInt(asGridExportSelection);
chkIncludeColumnNames.Checked := AppSettings.ReadBool(asGridExportColumnNames);
chkIncludeAutoIncrement.Checked := AppSettings.ReadBool(asGridExportIncludeAutoInc);
chkIncludeQuery.Checked := AppSettings.ReadBool(asGridExportIncludeQuery);
FCSVSeparator := AppSettings.ReadString(asGridExportSeparator);
FCSVEncloser := AppSettings.ReadString(asGridExportEncloser);
FCSVTerminator := AppSettings.ReadString(asGridExportTerminator);
FCSVNull := AppSettings.ReadString(asGridExportNull);
end;
ValidateControls(Sender);
end;
procedure TfrmExportGrid.FormDestroy(Sender: TObject);
begin
// Store settings
if ModalResult = mrOK then begin
if (ModalResult = mrOK) and (not FHiddenCopyMode) then begin
AppSettings.WriteBool(asGridExportOutputCopy, radioOutputCopyToClipboard.Checked);
AppSettings.WriteBool(asGridExportOutputFile, radioOutputFile.Checked);
AppSettings.WriteString(asGridExportFilename, editFilename.Text);
@@ -147,7 +165,7 @@ procedure TfrmExportGrid.FormDestroy(Sender: TObject);
procedure TfrmExportGrid.FormShow(Sender: TObject);
begin
// Show dialog. Expect "Grid" property to be set now by the caller.
chkIncludeAutoIncrement.Checked := AppSettings.ReadBool(asGridExportIncludeAutoInc);
chkIncludeAutoIncrement.OnClick := CalcSize;
CalcSize(Sender);
end;
@@ -352,6 +370,21 @@ procedure TfrmExportGrid.PutFilenamePlaceholder(Sender: TObject);
end;
procedure TfrmExportGrid.btnSetClipboardDefaultsClick(Sender: TObject);
begin
// Store copy-to-clipboard settings
AppSettings.ResetPath;
AppSettings.WriteInt(asGridExportClpFormat, grpFormat.ItemIndex);
AppSettings.WriteBool(asGridExportClpColumnNames, chkIncludeColumnNames.Checked);
AppSettings.WriteBool(asGridExportClpIncludeAutoInc, chkIncludeAutoIncrement.Checked);
AppSettings.WriteString(asGridExportClpSeparator, FCSVSeparator);
AppSettings.WriteString(asGridExportClpEncloser, FCSVEncloser);
AppSettings.WriteString(asGridExportClpTerminator, FCSVTerminator);
AppSettings.WriteString(asGridExportClpNull, FCSVNull);
MessageDialog(_('Clipboard settings changed.'), mtInformation, [mbOK]);
end;
procedure TfrmExportGrid.CalcSize(Sender: TObject);
var
GridData: TDBQuery;
View
@@ -148,8 +148,12 @@ TQueryThread = class(TThread)
asGridExportOutputCopy, asGridExportOutputFile,
asGridExportFilename, asGridExportRecentFiles, asGridExportEncoding, asGridExportFormat, asGridExportSelection,
asGridExportColumnNames, asGridExportIncludeAutoInc, asGridExportIncludeQuery,
asGridExportSeparator, asGridExportEncloser, asGridExportTerminator, asGridExportNull, asCSVImportSeparator,
asCSVImportEncloser, asCSVImportTerminator, asCSVImportFieldEscaper, asCSVImportWindowWidth, asCSVImportWindowHeight,
asGridExportSeparator, asGridExportEncloser, asGridExportTerminator, asGridExportNull,
asGridExportClpFormat, asGridExportClpColumnNames, asGridExportClpIncludeAutoInc,
asGridExportClpSeparator, asGridExportClpEncloser, asGridExportClpTerminator, asGridExportClpNull,
asCSVImportSeparator, asCSVImportEncloser, asCSVImportTerminator, asCSVImportFieldEscaper, asCSVImportWindowWidth, asCSVImportWindowHeight,
asCSVImportFilename, asCSVImportFieldsEnclosedOptionally, asCSVImportIgnoreLines, asCSVImportLowPriority, asCSVImportLocalNumbers,
asCSVImportDuplicateHandling, asCSVImportParseMethod, asUpdatecheck, asUpdatecheckBuilds,
asUpdatecheckInterval, asUpdatecheckLastrun, asTableToolsWindowWidth, asTableToolsWindowHeight, asTableToolsTreeWidth,
@@ -3299,6 +3303,15 @@ constructor TAppSettings.Create;
InitSetting(asGridExportEncloser, 'GridExportEncloser', 0, False, '');
InitSetting(asGridExportTerminator, 'GridExportTerminator', 0, False, '\r\n');
InitSetting(asGridExportNull, 'GridExportNull', 0, False, '\N');
// Copy to clipboard defaults:
InitSetting(asGridExportClpFormat, 'GridExportClpFormat', 0);
InitSetting(asGridExportClpColumnNames, 'GridExportClpColumnNames', 0, False);
InitSetting(asGridExportClpIncludeAutoInc, 'GridExportClpAutoInc', 0, True);
InitSetting(asGridExportClpSeparator, 'GridExportClpSeparator', 0, False, ';');
InitSetting(asGridExportClpEncloser, 'GridExportClpEncloser', 0, False, '');
InitSetting(asGridExportClpTerminator, 'GridExportClpTerminator', 0, False, '\r\n');
InitSetting(asGridExportClpNull, 'GridExportClpNull', 0, False, '\N');
InitSetting(asCSVImportSeparator, 'CSVSeparatorV2', 0, False, ';');
InitSetting(asCSVImportEncloser, 'CSVEncloserV2', 0, False, '"');
InitSetting(asCSVImportTerminator, 'CSVTerminator', 0, False, '\r\n');
View
@@ -1046,7 +1046,6 @@ TMainForm = class(TForm)
FPreferencesDialog: Toptionsform;
FCreateDatabaseDialog: TCreateDatabaseForm;
FGridEditFunctionMode: Boolean;
FClipboardHasNull: Boolean;
FTimeZoneOffset: Integer;
FGridCopying: Boolean;
FGridPasting: Boolean;
@@ -8714,7 +8713,6 @@ procedure TMainForm.AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Results: TDBQuery;
RowNum: PInt64;
Timestamp: Int64;
IsNull: Boolean;
begin
Results := GridResult(Sender);
RowNum := Sender.GetNodeData(Node);
@@ -8728,8 +8726,7 @@ procedure TMainForm.AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
end else
NewText := NewText;
end;
IsNull := FGridPasting and FClipboardHasNull;
Results.SetCol(Column, NewText, IsNull, FGridEditFunctionMode);
Results.SetCol(Column, NewText, False, FGridEditFunctionMode);
except
on E:EDatabaseError do
ErrorDialog(E.Message);
@@ -9622,14 +9619,12 @@ procedure TMainForm.actCopyOrCutExecute(Sender: TObject);
ClpData: THandle;
APalette: HPalette;
Exporter: TSynExporterRTF;
Results: TDBQuery;
RowNum: PInt64;
ExportDialog: TfrmExportGrid;
begin
// Copy text from a focused control to clipboard
Success := False;
Control := Screen.ActiveControl;
DoCut := Sender = actCut;
FClipboardHasNull := False;
SendingControl := (Sender as TAction).ActionComponent;
Screen.Cursor := crHourglass;
try
@@ -9657,16 +9652,10 @@ procedure TMainForm.actCopyOrCutExecute(Sender: TObject);
IsResultGrid := Grid = ActiveGrid;
FGridCopying := True;
if IsResultGrid then begin
// Handle NULL values in grids, see issue #3171
AnyGridEnsureFullRow(Grid, Grid.FocusedNode);
Results := GridResult(Grid);
RowNum := Grid.GetNodeData(Grid.FocusedNode);
Results.RecNo := RowNum^;
if Results.IsNull(Grid.FocusedColumn) then begin
Clipboard.AsText := '';
FClipboardHasNull := True;
end else
Clipboard.AsText := Grid.Text[Grid.FocusedNode, Grid.FocusedColumn];
ExportDialog := TfrmExportGrid.Create(Sender as TAction);
ExportDialog.Grid := Grid;
ExportDialog.btnOK.Click;
ExportDialog.Free;
if DoCut then
Grid.Text[Grid.FocusedNode, Grid.FocusedColumn] := '';
end else

0 comments on commit ba30091

Please sign in to comment.