@@ -236,6 +236,13 @@ TfrmTableEditor = class(TFrame)
236236 const ColNumInvisible = 13 ;
237237 const ColNumCompressed = 14 ;
238238 const ColNumsCheckboxes = [ColNumUnsigned, ColNumAllownull, ColNumZerofill, ColNumInvisible, ColNumCompressed];
239+ // Columns in index tree
240+ const IndexColNumName = 0 ;
241+ const IndexColNumType = 1 ;
242+ const IndexColNumAlgorithm = 2 ;
243+ const IndexColNumComment = 3 ;
244+ const IndexColNumDirection = 4 ;
245+ const IndexColNumVisibility = 5 ;
239246 procedure ValidateColumnControls ;
240247 procedure ValidateIndexControls ;
241248 procedure MoveFocusedIndexPart (NewIdx: Cardinal);
@@ -2079,8 +2086,10 @@ procedure TfrmTableEditor.treeIndexesGetImageIndex(Sender: TBaseVirtualTree;
20792086begin
20802087 // Icon image showing type of index
20812088 VT := Sender as TVirtualStringTree;
2082- if Column <> 0 then Exit;
2083- if not (Kind in [ikNormal, ikSelected]) then Exit;
2089+ if Column <> IndexColNumName then
2090+ Exit;
2091+ if not (Kind in [ikNormal, ikSelected]) then
2092+ Exit;
20842093 case VT.GetNodeLevel(Node) of
20852094 0 : ImageIndex := FKeys[Node.Index].ImageIndex;
20862095 1 : begin
@@ -2105,27 +2114,29 @@ procedure TfrmTableEditor.treeIndexesGetText(Sender: TBaseVirtualTree;
21052114 0 : begin
21062115 TblKey := FKeys[Node.Index];
21072116 case Column of
2108- 0 : if TblKey.IsPrimary then
2117+ IndexColNumName : if TblKey.IsPrimary then
21092118 CellText := TblKey.IndexType + ' KEY' // Fixed name "PRIMARY KEY", cannot be changed
21102119 else
21112120 CellText := TblKey.Name ;
2112- 1 : CellText := TblKey.IndexType;
2113- 2 : CellText := TblKey.Algorithm;
2114- 3 : CellText := TblKey.Comment;
2115- 4 : CellText := ' ' ; // Column collation
2121+ IndexColNumType: CellText := TblKey.IndexType;
2122+ IndexColNumAlgorithm: CellText := TblKey.Algorithm;
2123+ IndexColNumComment: CellText := TblKey.Comment;
2124+ IndexColNumDirection: CellText := ' ' ; // Column collation
2125+ IndexColNumVisibility: CellText := IfThen(TblKey.Visible, ' Visible' , ' Invisible' );
21162126 end ;
21172127 end ;
21182128 1 : begin
21192129 TblKey := FKeys[Node.Parent.Index];
21202130 case Column of
2121- 0 : CellText := TblKey.Columns[Node.Index];
2122- 1 : CellText := TblKey.SubParts[Node.Index];
2123- 2 : CellText := ' ' ; // Index algorithm
2124- 3 : CellText := ' ' ; // Index comment
2125- 4 : begin
2131+ IndexColNumName : CellText := TblKey.Columns[Node.Index];
2132+ IndexColNumType : CellText := TblKey.SubParts[Node.Index];
2133+ IndexColNumAlgorithm : CellText := ' ' ; // Index algorithm
2134+ IndexColNumComment : CellText := ' ' ; // Index comment
2135+ IndexColNumDirection : begin
21262136 CellText := TblKey.Collations[Node.Index];
21272137 CellText := IfThen(CellText.ToLower = ' a' , ' ASC' , ' DESC' );
21282138 end ;
2139+ IndexColNumVisibility: CellText := ' ' ;
21292140 end ;
21302141 end ;
21312142 end ;
@@ -2344,13 +2355,17 @@ procedure TfrmTableEditor.treeIndexesEditing(Sender: TBaseVirtualTree;
23442355 Allowed := False;
23452356 if VT.GetNodeLevel(Node) = 0 then begin
23462357 // Disallow renaming primary key, and direction/collation of key node level
2347- if (Column = 0 ) and (VT.Text[Node, 1 ] <> TTableKey.PRIMARY) then
2348- Allowed := True
2349- else
2350- Allowed := Column in [1 ,2 ,3 ];
2351- end else case Column of
2352- 0 : Allowed := True;
2353- 1 : begin
2358+ case Column of
2359+ IndexColNumName: Allowed := (VT.Text[Node, 1 ] <> TTableKey.PRIMARY);
2360+ IndexColNumType: Allowed := True;
2361+ IndexColNumAlgorithm: Allowed := True;
2362+ IndexColNumComment: Allowed := True;
2363+ IndexColNumVisibility: Allowed := DBObject.Connection.Has(frInvisibleIndexes);
2364+ end ;
2365+ end
2366+ else case Column of
2367+ IndexColNumName: Allowed := True;
2368+ IndexColNumType: begin
23542369 // Column length is allowed for (var)char/text types only, even mandantory for text and blobs
23552370 IndexedColName := VT.Text[Node, 0 ];
23562371 for i:=0 to FColumns.Count-1 do begin
@@ -2360,7 +2375,7 @@ procedure TfrmTableEditor.treeIndexesEditing(Sender: TBaseVirtualTree;
23602375 end ;
23612376 end ;
23622377 end ;
2363- 4 : Allowed := True; // Collation
2378+ IndexColNumDirection : Allowed := True; // Collation
23642379 end ;
23652380end ;
23662381
@@ -2377,18 +2392,23 @@ procedure TfrmTableEditor.treeIndexesCreateEditor(Sender: TBaseVirtualTree;
23772392 // Start cell editor
23782393 VT := Sender as TVirtualStringTree;
23792394 Level := (Sender as TVirtualStringtree).GetNodeLevel(Node);
2380- if (Level = 0 ) and (Column = 1 ) then begin
2395+ if (Level = 0 ) and (Column = IndexColNumType ) then begin
23812396 // Index type pulldown
23822397 EnumEditor := TEnumEditorLink.Create(VT, True, nil );
23832398 EnumEditor.ValueList := TStringList.Create;
23842399 EnumEditor.ValueList.CommaText := TTableKey.PRIMARY +' ,' + TTableKey.KEY +' ,' + TTableKey.UNIQUE +' ,' + TTableKey.FULLTEXT +' ,' + TTableKey.SPATIAL;
23852400 EditLink := EnumEditor;
2386- end else if (Level = 0 ) and (Column = 2 ) then begin
2401+ end else if (Level = 0 ) and (Column = IndexColNumAlgorithm ) then begin
23872402 // Algorithm pulldown
23882403 EnumEditor := TEnumEditorLink.Create(VT, True, nil );
23892404 EnumEditor.ValueList := Explode(' ,' , ' ,BTREE,HASH,RTREE' );
23902405 EditLink := EnumEditor;
2391- end else if (Level = 1 ) and (Column = 0 ) then begin
2406+ end else if (Level = 0 ) and (Column = IndexColNumVisibility) then begin
2407+ // Visibility pulldown
2408+ EnumEditor := TEnumEditorLink.Create(VT, True, nil );
2409+ EnumEditor.ValueList := Explode(' ,' , ' Visible,Invisible' );
2410+ EditLink := EnumEditor;
2411+ end else if (Level = 1 ) and (Column = IndexColNumName) then begin
23922412 // Column names pulldown
23932413 EnumEditor := TEnumEditorLink.Create(VT, True, nil );
23942414 ColNode := listColumns.GetFirst;
@@ -2399,7 +2419,7 @@ procedure TfrmTableEditor.treeIndexesCreateEditor(Sender: TBaseVirtualTree;
23992419 end ;
24002420 EnumEditor.AllowCustomText := True; // Allows adding a subpart in index parts: "TextCol(20)"
24012421 EditLink := EnumEditor;
2402- end else if (Level = 1 ) and (Column = 4 ) then begin
2422+ end else if (Level = 1 ) and (Column = IndexColNumDirection ) then begin
24032423 EnumEditor := TEnumEditorLink.Create(VT, True, nil );
24042424 EnumEditor.ValueList := Explode(' ,' , ' ,ASC,DESC' );
24052425 EditLink := EnumEditor;
@@ -2421,22 +2441,23 @@ procedure TfrmTableEditor.treeIndexesNewText(Sender: TBaseVirtualTree;
24212441 0 : begin
24222442 TblKey := FKeys[Node.Index];
24232443 case Column of
2424- 0 : TblKey.Name := NewText;
2425- 1 : begin
2444+ IndexColNumName : TblKey.Name := NewText;
2445+ IndexColNumType : begin
24262446 TblKey.IndexType := NewText;
24272447 if NewText = TTableKey.PRIMARY then
24282448 TblKey.Name := TTableKey.PRIMARY;
24292449 end ;
2430- 2 : TblKey.Algorithm := NewText;
2431- 3 : TblKey.Comment := NewText;
2450+ IndexColNumAlgorithm: TblKey.Algorithm := NewText;
2451+ IndexColNumComment: TblKey.Comment := NewText;
2452+ IndexColNumVisibility: TblKey.Visible := SameText(NewText, ' Visible' );
24322453 end ;
24332454 // Needs to be called manually for Name and IndexType properties:
24342455 TblKey.Modification(Sender);
24352456 end ;
24362457 1 : begin
24372458 TblKey := FKeys[Node.Parent.Index];
24382459 case Column of
2439- 0 : begin
2460+ IndexColNumName : begin
24402461 // Detect input of "col(123)" and move "123" into subpart
24412462 rx := TRegExpr.Create;
24422463 rx.Expression := ' .+\((\d+)\)' ;
@@ -2446,8 +2467,8 @@ procedure TfrmTableEditor.treeIndexesNewText(Sender: TBaseVirtualTree;
24462467 end else
24472468 TblKey.Columns[Node.Index] := NewText;
24482469 end ;
2449- 1 : TblKey.SubParts[Node.Index] := NewText;
2450- 4 : begin
2470+ IndexColNumType : TblKey.SubParts[Node.Index] := NewText;
2471+ IndexColNumDirection : begin
24512472 if NewText.ToLower = ' asc' then
24522473 TblKey.Collations[Node.Index] := ' A'
24532474 else
0 commit comments