mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Redo r3571 - seems that was not the cause of slowness.
This commit is contained in:
@ -84,19 +84,17 @@ object frmTableEditor: TfrmTableEditor
|
|||||||
OnFocusChanged = listColumnsFocusChanged
|
OnFocusChanged = listColumnsFocusChanged
|
||||||
OnGetText = listColumnsGetText
|
OnGetText = listColumnsGetText
|
||||||
OnPaintText = listColumnsPaintText
|
OnPaintText = listColumnsPaintText
|
||||||
OnGetImageIndex = listColumnsGetImageIndex
|
|
||||||
OnGetNodeDataSize = listColumnsGetNodeDataSize
|
OnGetNodeDataSize = listColumnsGetNodeDataSize
|
||||||
OnInitNode = listColumnsInitNode
|
OnInitNode = listColumnsInitNode
|
||||||
OnKeyPress = listColumnsKeyPress
|
OnKeyPress = listColumnsKeyPress
|
||||||
OnNewText = listColumnsNewText
|
OnNewText = listColumnsNewText
|
||||||
OnNodeMoved = listColumnsNodeMoved
|
OnNodeMoved = listColumnsNodeMoved
|
||||||
OnStructureChange = listColumnsStructureChange
|
|
||||||
Columns = <
|
Columns = <
|
||||||
item
|
item
|
||||||
Alignment = taRightJustify
|
Alignment = taRightJustify
|
||||||
Color = clBtnFace
|
Color = clBtnFace
|
||||||
MinWidth = 20
|
MinWidth = 20
|
||||||
Options = [coDraggable, coEnabled, coParentBidiMode, coResizable, coShowDropMark, coVisible, coAllowFocus]
|
Options = [coDraggable, coEnabled, coParentBidiMode, coShowDropMark, coVisible, coAllowFocus]
|
||||||
Position = 0
|
Position = 0
|
||||||
Width = 20
|
Width = 20
|
||||||
WideText = '#'
|
WideText = '#'
|
||||||
|
@ -5,7 +5,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Windows, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
|
Windows, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
|
||||||
ComCtrls, ToolWin, VirtualTrees, SynRegExpr, ActiveX, ExtCtrls, SynEdit,
|
ComCtrls, ToolWin, VirtualTrees, SynRegExpr, ActiveX, ExtCtrls, SynEdit,
|
||||||
SynMemo, Menus, Contnrs, Clipbrd,
|
SynMemo, Menus, Contnrs, Clipbrd, Math,
|
||||||
grideditlinks, mysql_structures, mysql_connection, helpers, mysql_api;
|
grideditlinks, mysql_structures, mysql_connection, helpers, mysql_api;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -145,9 +145,6 @@ type
|
|||||||
procedure btnDiscardClick(Sender: TObject);
|
procedure btnDiscardClick(Sender: TObject);
|
||||||
procedure popupColumnsPopup(Sender: TObject);
|
procedure popupColumnsPopup(Sender: TObject);
|
||||||
procedure AddIndexByColumn(Sender: TObject);
|
procedure AddIndexByColumn(Sender: TObject);
|
||||||
procedure listColumnsGetImageIndex(Sender: TBaseVirtualTree;
|
|
||||||
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
|
|
||||||
var Ghosted: Boolean; var ImageIndex: Integer);
|
|
||||||
procedure listForeignKeysBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
|
procedure listForeignKeysBeforePaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas);
|
||||||
procedure listForeignKeysCreateEditor(Sender: TBaseVirtualTree;
|
procedure listForeignKeysCreateEditor(Sender: TBaseVirtualTree;
|
||||||
Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
|
Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
|
||||||
@ -174,8 +171,6 @@ type
|
|||||||
procedure listColumnsKeyPress(Sender: TObject; var Key: Char);
|
procedure listColumnsKeyPress(Sender: TObject; var Key: Char);
|
||||||
procedure vtHandleClickOrKeyPress(Sender: TVirtualStringTree;
|
procedure vtHandleClickOrKeyPress(Sender: TVirtualStringTree;
|
||||||
Node: PVirtualNode; Column: TColumnIndex; HitPositions: THitPositions);
|
Node: PVirtualNode; Column: TColumnIndex; HitPositions: THitPositions);
|
||||||
procedure listColumnsStructureChange(Sender: TBaseVirtualTree;
|
|
||||||
Node: PVirtualNode; Reason: TChangeReason);
|
|
||||||
procedure menuCopyColumnsClick(Sender: TObject);
|
procedure menuCopyColumnsClick(Sender: TObject);
|
||||||
procedure menuPasteColumnsClick(Sender: TObject);
|
procedure menuPasteColumnsClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
@ -194,6 +189,7 @@ type
|
|||||||
function ComposeAlterStatement: String;
|
function ComposeAlterStatement: String;
|
||||||
procedure UpdateSQLcode;
|
procedure UpdateSQLcode;
|
||||||
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
||||||
|
procedure CalcMinColWidth;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -339,6 +335,7 @@ begin
|
|||||||
AlterCodeValid := False;
|
AlterCodeValid := False;
|
||||||
PageControlMainChange(Self); // Foreign key editor needs a hit
|
PageControlMainChange(Self); // Foreign key editor needs a hit
|
||||||
UpdateSQLCode;
|
UpdateSQLCode;
|
||||||
|
CalcMinColWidth;
|
||||||
// Indicate change mechanisms can call their events now. See Modification().
|
// Indicate change mechanisms can call their events now. See Modification().
|
||||||
FLoaded := True;
|
FLoaded := True;
|
||||||
// Empty status panel
|
// Empty status panel
|
||||||
@ -671,6 +668,7 @@ begin
|
|||||||
CreateCodeValid := False;
|
CreateCodeValid := False;
|
||||||
AlterCodeValid := False;
|
AlterCodeValid := False;
|
||||||
UpdateSQLcode;
|
UpdateSQLcode;
|
||||||
|
CalcMinColWidth;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -825,24 +823,68 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TfrmTableEditor.CalcMinColWidth;
|
||||||
|
var
|
||||||
|
i, j, MinWidthThisCol, MinWidthAllCols: Integer;
|
||||||
|
begin
|
||||||
|
// Find maximum column widths so the index icons have enough room after auto-fitting
|
||||||
|
MinWidthAllCols := 0;
|
||||||
|
for i:=0 to FColumns.Count-1 do begin
|
||||||
|
MinWidthThisCol := 0;
|
||||||
|
for j:=0 to FKeys.Count-1 do begin
|
||||||
|
if FKeys[j].Columns.IndexOf(FColumns[i].Name) > -1 then
|
||||||
|
Inc(MinWidthThisCol, listColumns.Images.Width);
|
||||||
|
end;
|
||||||
|
for j:=0 to FForeignKeys.Count-1 do begin
|
||||||
|
if FForeignKeys[j].Columns.IndexOf(FColumns[i].Name) > -1 then
|
||||||
|
Inc(MinWidthThisCol, listColumns.Images.Width);
|
||||||
|
end;
|
||||||
|
MinWidthAllCols := Max(MinWidthAllCols, MinWidthThisCol);
|
||||||
|
end;
|
||||||
|
// Add space for number
|
||||||
|
Inc(MinWidthAllCols, listColumns.Canvas.TextWidth(IntToStr(FColumns.Count+1)) + listColumns.TextMargin*4);
|
||||||
|
listColumns.Header.Columns[0].Width := MinWidthAllCols;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.listColumnsAfterCellPaint(Sender: TBaseVirtualTree;
|
procedure TfrmTableEditor.listColumnsAfterCellPaint(Sender: TBaseVirtualTree;
|
||||||
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
|
||||||
CellRect: TRect);
|
CellRect: TRect);
|
||||||
var
|
var
|
||||||
Col: PTableColumn;
|
Col: PTableColumn;
|
||||||
ImageIndex, X, Y: Integer;
|
ImageIndex, X, Y, i: Integer;
|
||||||
VT: TVirtualStringTree;
|
VT: TVirtualStringTree;
|
||||||
begin
|
begin
|
||||||
|
VT := TVirtualStringTree(Sender);
|
||||||
|
Col := Sender.GetNodeData(Node);
|
||||||
|
Y := CellRect.Top + Integer(VT.NodeHeight[Node] div 2) - (VT.Images.Height div 2);
|
||||||
|
|
||||||
|
// Paint one icon per index of which this column is part of
|
||||||
|
if Column = 0 then begin
|
||||||
|
X := 0;
|
||||||
|
for i:=0 to FKeys.Count-1 do begin
|
||||||
|
if FKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
||||||
|
ImageIndex := GetIndexIcon(FKeys[i].IndexType);
|
||||||
|
VT.Images.Draw(TargetCanvas, X, Y, ImageIndex);
|
||||||
|
Inc(X, VT.Images.Width);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
for i:=0 to FForeignKeys.Count-1 do begin
|
||||||
|
if FForeignKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
||||||
|
ImageIndex := ICONINDEX_FOREIGNKEY;
|
||||||
|
VT.Images.Draw(TargetCanvas, X, Y, ImageIndex);
|
||||||
|
Inc(X, VT.Images.Width);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
// Paint checkbox image in certain columns
|
// Paint checkbox image in certain columns
|
||||||
// while restricting "Allow NULL" checkbox to numeric datatypes
|
// while restricting "Allow NULL" checkbox to numeric datatypes
|
||||||
if (Column in [4, 5, 6]) and CellEditingAllowed(Node, Column) then begin
|
if (Column in [4, 5, 6]) and CellEditingAllowed(Node, Column) then begin
|
||||||
Col := Sender.GetNodeData(Node);
|
|
||||||
if (Col.Unsigned and (Column=4)) or (Col.AllowNull and (Column=5)) or (Col.ZeroFill and (Column = 6)) then
|
if (Col.Unsigned and (Column=4)) or (Col.AllowNull and (Column=5)) or (Col.ZeroFill and (Column = 6)) then
|
||||||
ImageIndex := 128
|
ImageIndex := 128
|
||||||
else ImageIndex := 127;
|
else ImageIndex := 127;
|
||||||
VT := TVirtualStringTree(Sender);
|
|
||||||
X := CellRect.Left + (VT.Header.Columns[Column].Width div 2) - (VT.Images.Width div 2);
|
X := CellRect.Left + (VT.Header.Columns[Column].Width div 2) - (VT.Images.Width div 2);
|
||||||
Y := CellRect.Top + Integer(VT.NodeHeight[Node] div 2) - (VT.Images.Height div 2);
|
|
||||||
VT.Images.Draw(TargetCanvas, X, Y, ImageIndex);
|
VT.Images.Draw(TargetCanvas, X, Y, ImageIndex);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -946,35 +988,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.listColumnsGetImageIndex(Sender: TBaseVirtualTree;
|
|
||||||
Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
|
|
||||||
var Ghosted: Boolean; var ImageIndex: Integer);
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
Col: PTableColumn;
|
|
||||||
begin
|
|
||||||
// Primary key icon
|
|
||||||
if Column <> 0 then Exit;
|
|
||||||
if not (Kind in [ikNormal, ikSelected]) then Exit;
|
|
||||||
Col := Sender.GetNodeData(Node);
|
|
||||||
|
|
||||||
for i:=0 to FKeys.Count-1 do begin
|
|
||||||
if FKeys[i].Columns.IndexOf(Col.Name) > -1 then
|
|
||||||
ImageIndex := GetIndexIcon(FKeys[i].IndexType);
|
|
||||||
// Priority for PK columns. We cannot display more than one icon anyway.
|
|
||||||
if ImageIndex > -1 then
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
|
|
||||||
for i:=0 to FForeignKeys.Count-1 do begin
|
|
||||||
if FForeignKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
|
||||||
ImageIndex := ICONINDEX_FOREIGNKEY;
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.listColumnsGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
|
procedure TfrmTableEditor.listColumnsGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
|
||||||
begin
|
begin
|
||||||
NodeDataSize := SizeOf(TTableColumn);
|
NodeDataSize := SizeOf(TTableColumn);
|
||||||
@ -1021,14 +1034,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.listColumnsStructureChange(Sender: TBaseVirtualTree;
|
|
||||||
Node: PVirtualNode; Reason: TChangeReason);
|
|
||||||
begin
|
|
||||||
// Auto resize first column to optimal width
|
|
||||||
listColumns.Header.AutoFitColumns(False, smaUseColumnOption, 0, 0);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.listColumnsNewText(Sender: TBaseVirtualTree;
|
procedure TfrmTableEditor.listColumnsNewText(Sender: TBaseVirtualTree;
|
||||||
Node: PVirtualNode; Column: TColumnIndex; NewText: String);
|
Node: PVirtualNode; Column: TColumnIndex; NewText: String);
|
||||||
var
|
var
|
||||||
|
Reference in New Issue
Block a user