mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-14 01:56:36 +08:00
Limit icons on column in table editor to show only one per key type. Closes #945
This commit is contained in:
@ -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, Clipbrd, Math, System.UITypes,
|
SynMemo, Menus, Clipbrd, Math, System.UITypes, System.Generics.Collections,
|
||||||
grideditlinks, dbstructures, dbconnection, apphelpers, gnugettext, StrUtils, extra_controls;
|
grideditlinks, dbstructures, dbconnection, apphelpers, gnugettext, StrUtils, extra_controls;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -220,6 +220,7 @@ type
|
|||||||
function ComposeAlterStatement: TSQLBatch;
|
function ComposeAlterStatement: TSQLBatch;
|
||||||
procedure UpdateSQLcode;
|
procedure UpdateSQLcode;
|
||||||
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
||||||
|
function GetKeyImageIndexes(Col: TTableColumn): TList<Integer>;
|
||||||
procedure CalcMinColWidth;
|
procedure CalcMinColWidth;
|
||||||
procedure UpdateTabCaptions;
|
procedure UpdateTabCaptions;
|
||||||
public
|
public
|
||||||
@ -1079,22 +1080,38 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TfrmTableEditor.GetKeyImageIndexes(Col: TTableColumn): TList<Integer>;
|
||||||
|
var
|
||||||
|
idx, i: Integer;
|
||||||
|
begin
|
||||||
|
Result := TList<Integer>.Create;
|
||||||
|
for i:=0 to FKeys.Count-1 do begin
|
||||||
|
if FKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
||||||
|
idx := FKeys[i].ImageIndex;
|
||||||
|
if not Result.Contains(idx) then
|
||||||
|
Result.Add(idx);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
for i:=0 to FForeignKeys.Count-1 do begin
|
||||||
|
if FForeignKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
||||||
|
idx := ICONINDEX_FOREIGNKEY;
|
||||||
|
if not Result.Contains(idx) then
|
||||||
|
Result.Add(idx);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.CalcMinColWidth;
|
procedure TfrmTableEditor.CalcMinColWidth;
|
||||||
var
|
var
|
||||||
i, j, MinWidthThisCol, MinWidthAllCols: Integer;
|
i, j, MinWidthThisCol, MinWidthAllCols: Integer;
|
||||||
|
ImageIndexes: TList<Integer>;
|
||||||
begin
|
begin
|
||||||
// Find maximum column widths so the index icons have enough room after auto-fitting
|
// Find maximum width for first column so the index icons have enough room after auto-fitting
|
||||||
MinWidthAllCols := 0;
|
MinWidthAllCols := 0;
|
||||||
for i:=0 to FColumns.Count-1 do begin
|
for i:=0 to FColumns.Count-1 do begin
|
||||||
MinWidthThisCol := 0;
|
ImageIndexes := GetKeyImageIndexes(FColumns[i]);
|
||||||
for j:=0 to FKeys.Count-1 do begin
|
MinWidthThisCol := ImageIndexes.Count * listColumns.Images.Width;
|
||||||
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);
|
MinWidthAllCols := Max(MinWidthAllCols, MinWidthThisCol);
|
||||||
end;
|
end;
|
||||||
// Add space for number
|
// Add space for number
|
||||||
@ -1111,28 +1128,22 @@ var
|
|||||||
ImageIndex, X, Y, i: Integer;
|
ImageIndex, X, Y, i: Integer;
|
||||||
VT: TVirtualStringTree;
|
VT: TVirtualStringTree;
|
||||||
Checked: Boolean;
|
Checked: Boolean;
|
||||||
|
ImageIndexes: TList<Integer>;
|
||||||
begin
|
begin
|
||||||
VT := TVirtualStringTree(Sender);
|
VT := TVirtualStringTree(Sender);
|
||||||
Col := Sender.GetNodeData(Node);
|
Col := Sender.GetNodeData(Node);
|
||||||
Y := CellRect.Top + Integer(VT.NodeHeight[Node] div 2) - (VT.Images.Height div 2);
|
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
|
// Paint one icon per index type of which this column is part of
|
||||||
if Column = 0 then begin
|
if Column = 0 then begin
|
||||||
|
ImageIndexes := TList<Integer>.Create;
|
||||||
X := 0;
|
X := 0;
|
||||||
for i:=0 to FKeys.Count-1 do begin
|
ImageIndexes := GetKeyImageIndexes(Col^);
|
||||||
if FKeys[i].Columns.IndexOf(Col.Name) > -1 then begin
|
for i in ImageIndexes do begin
|
||||||
ImageIndex := FKeys[i].ImageIndex;
|
VT.Images.Draw(TargetCanvas, X, Y, i);
|
||||||
VT.Images.Draw(TargetCanvas, X, Y, ImageIndex);
|
|
||||||
Inc(X, VT.Images.Width);
|
Inc(X, VT.Images.Width);
|
||||||
end;
|
end;
|
||||||
end;
|
ImageIndexes.Free;
|
||||||
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;
|
end;
|
||||||
|
|
||||||
// Paint checkbox image in certain columns
|
// Paint checkbox image in certain columns
|
||||||
|
Reference in New Issue
Block a user