mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Fix broken drop target index for a dragged column in the index tree. Now taking into account whether the dropped column comes from above or from below. Closes #385
This commit is contained in:
@ -1809,9 +1809,9 @@ procedure TfrmTableEditor.treeIndexesDragDrop(Sender: TBaseVirtualTree;
|
|||||||
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
|
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
|
||||||
Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
|
Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
|
||||||
var
|
var
|
||||||
Node: PVirtualNode;
|
FocusedNode, TargetNode, IndexNode: PVirtualNode;
|
||||||
ColName, PartLength: String;
|
ColName, PartLength: String;
|
||||||
ColPos: Integer;
|
ColPos: Cardinal;
|
||||||
VT, SourceVT: TVirtualStringtree;
|
VT, SourceVT: TVirtualStringtree;
|
||||||
Col: PTableColumn;
|
Col: PTableColumn;
|
||||||
TblKey: TTableKey;
|
TblKey: TTableKey;
|
||||||
@ -1819,28 +1819,38 @@ begin
|
|||||||
// Column node dropped here
|
// Column node dropped here
|
||||||
VT := Sender as TVirtualStringtree;
|
VT := Sender as TVirtualStringtree;
|
||||||
SourceVT := Source as TVirtualStringtree;
|
SourceVT := Source as TVirtualStringtree;
|
||||||
Node := VT.GetNodeAt(Pt.X, Pt.Y);
|
TargetNode := VT.GetNodeAt(Pt.X, Pt.Y);
|
||||||
if not Assigned(Node) then begin
|
FocusedNode := VT.FocusedNode;
|
||||||
|
if not Assigned(TargetNode) then begin
|
||||||
MessageBeep(MB_ICONEXCLAMATION);
|
MessageBeep(MB_ICONEXCLAMATION);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
if VT.GetNodeLevel(Node) = 1 then begin
|
if VT.GetNodeLevel(TargetNode) = 1 then begin
|
||||||
ColPos := Node.Index;
|
IndexNode := TargetNode.Parent;
|
||||||
if (Mode = dmAbove) and (ColPos > 0) then
|
// Find the right new position for the dropped column
|
||||||
Dec(ColPos);
|
ColPos := TargetNode.Index;
|
||||||
Node := Node.Parent;
|
Mainform.LogSQL('TargetNode.Index: '+TargetNode.Index.ToString, lcDebug);
|
||||||
end else
|
if (Source = Sender) and (FocusedNode <> nil) then begin
|
||||||
ColPos := Node.ChildCount;
|
// Take care if user dragged from above or from below the target node
|
||||||
|
if (FocusedNode.Index < TargetNode.Index) and (Mode = dmAbove) and (ColPos > 0) then
|
||||||
|
Dec(ColPos);
|
||||||
|
if (FocusedNode.Index > TargetNode.Index) and (Mode = dmBelow) and (ColPos < IndexNode.ChildCount-1) then
|
||||||
|
Inc(ColPos);
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
IndexNode := TargetNode;
|
||||||
|
ColPos := IndexNode.ChildCount;
|
||||||
|
end;
|
||||||
|
|
||||||
if Source = Sender then
|
if Source = Sender then
|
||||||
MoveFocusedIndexPart(ColPos)
|
MoveFocusedIndexPart(ColPos)
|
||||||
else begin
|
else begin
|
||||||
TblKey := FKeys[Node.Index];
|
TblKey := FKeys[IndexNode.Index];
|
||||||
Col := SourceVT.GetNodeData(SourceVT.FocusedNode);
|
Col := SourceVT.GetNodeData(SourceVT.FocusedNode);
|
||||||
ColName := Col.Name;
|
ColName := Col.Name;
|
||||||
if TblKey.Columns.IndexOf(ColName) > -1 then begin
|
if TblKey.Columns.IndexOf(ColName) > -1 then begin
|
||||||
if MessageDialog(_('Add duplicated column to index?'),
|
if MessageDialog(_('Add duplicated column to index?'),
|
||||||
f_('Index "%s" already contains the column "%s". It is possible to add a column twice into a index, but total nonsense in practice.', [VT.Text[Node, 0], ColName]),
|
f_('Index "%s" already contains the column "%s". It is possible to add a column twice into a index, but total nonsense in practice.', [VT.Text[IndexNode, 0], ColName]),
|
||||||
mtConfirmation, [mbYes, mbNo]) = mrNo then
|
mtConfirmation, [mbYes, mbNo]) = mrNo then
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
@ -1850,11 +1860,12 @@ begin
|
|||||||
if (TblKey.IndexType <> FKEY) and (Col.DataType.Index in [dtTinyText, dtText, dtMediumText, dtLongText, dtTinyBlob, dtBlob, dtMediumBlob, dtLongBlob]) then
|
if (TblKey.IndexType <> FKEY) and (Col.DataType.Index in [dtTinyText, dtText, dtMediumText, dtLongText, dtTinyBlob, dtBlob, dtMediumBlob, dtLongBlob]) then
|
||||||
PartLength := '100';
|
PartLength := '100';
|
||||||
TblKey.Subparts.Insert(ColPos, PartLength);
|
TblKey.Subparts.Insert(ColPos, PartLength);
|
||||||
Node.States := Node.States + [vsHasChildren, vsExpanded];
|
IndexNode.States := IndexNode.States + [vsHasChildren, vsExpanded];
|
||||||
end;
|
end;
|
||||||
Modification(Sender);
|
Modification(Sender);
|
||||||
// Finally tell parent node to update its children
|
// Finally tell parent node to update its children
|
||||||
VT.ReinitChildren(Node, False);
|
VT.ReinitChildren(IndexNode, False);
|
||||||
|
VT.Repaint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1880,7 +1891,7 @@ begin
|
|||||||
if treeIndexes.IsEditing then
|
if treeIndexes.IsEditing then
|
||||||
treeIndexes.EndEditNode;
|
treeIndexes.EndEditNode;
|
||||||
TblKey := FKeys[treeIndexes.FocusedNode.Parent.Index];
|
TblKey := FKeys[treeIndexes.FocusedNode.Parent.Index];
|
||||||
if (NewIdx >= TblKey.Columns.Count) or (NewIdx < 0) then begin
|
if NewIdx >= Cardinal(TblKey.Columns.Count) then begin
|
||||||
MessageBeep(MB_ICONEXCLAMATION);
|
MessageBeep(MB_ICONEXCLAMATION);
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user