@@ -6929,9 +6929,7 @@ procedure TMainForm.SynCompletionProposalExecute(Kind: SynCompletionType;
69296929 Columns: TTableColumnList;
69306930 Col: TTableColumn;
69316931 Keys: TTableKeyList;
6932- Key: TTableKey;
69336932 Obj: TDBObject;
6934- ColumnIcon: Integer;
69356933 begin
69366934 dbname := '';
69376935 tblname := LeftToken;
@@ -6950,16 +6948,8 @@ procedure TMainForm.SynCompletionProposalExecute(Kind: SynCompletionType;
69506948 Columns := Obj.TableColumns;
69516949 Keys := Obj.TableKeys;
69526950 for Col in Columns do begin
6953- // Detect index icon, if any
6954- ColumnIcon := ICONINDEX_FIELD;
6955- for Key in Keys do begin
6956- if Key.Columns.Contains(Col.Name) then begin
6957- ColumnIcon := Key.ImageIndex;
6958- Break;
6959- end;
6960- end;
69616951 // Put formatted text and icon into proposal
6962- DisplayText := SynCompletionProposalPrettyText(ColumnIcon , LowerCase(Col.DataType.Name), Col.Name, Col.Comment, DatatypeCategories[Col.DataType.Category].NullColor);
6952+ DisplayText := SynCompletionProposalPrettyText(Keys.ImageIndex(Col.Name) , LowerCase(Col.DataType.Name), Col.Name, Col.Comment, DatatypeCategories[Col.DataType.Category].NullColor);
69636953 if CurrentInput.StartsWith(Conn.QuoteChar) then
69646954 Proposal.AddItem(DisplayText, Conn.QuoteChar + Col.Name)
69656955 else
@@ -7700,10 +7690,14 @@ procedure TMainForm.SynMemoQueryDragDrop(Sender, Source: TObject; X,
77007690 // Insert table or database name. If a table is dropped and Shift is pressed, prepend the db name.
77017691 case ActiveDbObj.NodeType of
77027692 lntDb: Text := ActiveDbObj.QuotedDatabase(False);
7703- lntTable..lntEvent: begin
7704- if ShiftPressed then
7705- Text := ActiveDbObj.QuotedDatabase(False) + '.';
7706- Text := Text + ActiveDbObj.Connection.QuoteIdent(ActiveDbObj.Name, False);
7693+ lntTable..lntEvent, lntColumn: begin
7694+ Text := '';
7695+ if ShiftPressed then begin
7696+ Text := Text + ActiveDbObj.QuotedDatabase(False) + '.';
7697+ if ActiveDbObj.NodeType = lntColumn then
7698+ Text := Text + ActiveDbObj.QuotedName(False) + '.';
7699+ end;
7700+ Text := Text + ActiveDbObj.Connection.QuoteIdent(DBtree.Text[DBtree.FocusedNode, DBtree.FocusedColumn], False);
77077701 end;
77087702 end;
77097703 end else if src = Tree then begin
@@ -9806,7 +9800,8 @@ procedure TMainForm.DBtreeGetImageIndex(Sender: TBaseVirtualTree; Node:
98069800 PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted:
98079801 Boolean; var ImageIndex: TImageIndex);
98089802var
9809- DBObj: PDBObject;
9803+ DBObj, ParentObj: PDBObject;
9804+ TableKeys: TTableKeyList;
98109805begin
98119806 if Column > 0 then
98129807 Exit;
@@ -9816,6 +9811,11 @@ procedure TMainForm.DBtreeGetImageIndex(Sender: TBaseVirtualTree; Node:
98169811 case Kind of
98179812 ikNormal, ikSelected: begin
98189813 ImageIndex := DBObj.ImageIndex;
9814+ if DBObj.NodeType = lntColumn then begin // Key/index icon
9815+ ParentObj := Sender.GetNodeData(Node.Parent);
9816+ ImageIndex := ParentObj.TableKeys.ImageIndex(DBObj.Column);
9817+ end;
9818+
98199819 Ghosted := (DBObj.NodeType = lntNone) and (not DBObj.Connection.Active);
98209820 Ghosted := Ghosted or ((DBObj.NodeType = lntDB)
98219821 and (not DBObj.Connection.DbObjectsCached(DBObj.Database))
@@ -9878,8 +9878,7 @@ procedure TMainForm.DBtreeInitChildren(Sender: TBaseVirtualTree; Node: PVirtualN
98789878 DBObjects := DBObj.Connection.GetDBObjects(DBObj.Database, False, DBObj.GroupType);
98799879 ChildCount := DBObjects.Count;
98809880 end;
9881- lntTable:
9882- if GetParentFormOrFrame(Sender) is TfrmSelectDBObject then begin
9881+ lntTable: begin
98839882 Columns := DBObj.TableColumns;
98849883 ChildCount := Columns.Count;
98859884 end;
@@ -9929,14 +9928,14 @@ procedure TMainForm.DBtreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node:
99299928 end else begin
99309929 DBObjects := ParentObj.Connection.GetDBObjects(ParentObj.Database);
99319930 Item^ := DBObjects[Node.Index];
9932- if (GetParentFormOrFrame(Sender) is TfrmSelectDBObject) and ( Item.NodeType = lntTable) then
9931+ if Item.NodeType = lntTable then
99339932 Include(InitialStates, ivsHasChildren);
99349933 end;
99359934 end;
99369935 lntGroup: begin
99379936 DBObjects := ParentObj.Connection.GetDBObjects(ParentObj.Database, False, ParentObj.GroupType);
99389937 Item^ := DBObjects[Node.Index];
9939- if (GetParentFormOrFrame(Sender) is TfrmSelectDBObject) and ( Item.NodeType = lntTable) then
9938+ if Item.NodeType = lntTable then
99409939 Include(InitialStates, ivsHasChildren);
99419940 end;
99429941 lntTable: begin
@@ -9958,13 +9957,15 @@ procedure TMainForm.DBtreeInitNode(Sender: TBaseVirtualTree; ParentNode, Node:
99589957procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
99599958var
99609959 DBObj, PrevDBObj, ParentDBObj: PDBObject;
9960+ TableLevelObj: TDBObject;
99619961 MainTabToActivate: TTabSheet;
99629962 EnteringSession: Boolean;
99639963begin
99649964 // Set wanted main tab and call SetMainTab later, when all lists have been invalidated
99659965 MainTabToActivate := nil;
99669966 PrevDBObj := nil;
99679967 ParentDBObj := nil;
9968+ TableLevelObj := nil;
99689969
99699970 if Assigned(Node) then begin
99709971 LogSQL('DBtreeFocusChanged, Node level: '+IntToStr(Sender.GetNodeLevel(Node))+', FTreeRefreshInProgress: '+IntToStr(Integer(FTreeRefreshInProgress)), lcDebug);
@@ -9979,6 +9980,10 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
99799980 FActiveDbObj.Assign(DBObj^);
99809981 if Assigned(Node.Parent) and (DBtree.GetNodeLevel(Node) > 0) then
99819982 ParentDBObj := Sender.GetNodeData(Node.Parent);
9983+ if FActiveDbObj.NodeType = lntColumn then
9984+ TableLevelObj := ParentDBObj^
9985+ else
9986+ TableLevelObj := FActiveDbObj;
99829987
99839988 case FActiveDbObj.NodeType of
99849989 lntNone: begin
@@ -10000,7 +10005,7 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
1000010005 MainTabToActivate := tabDatabase;
1000110006 FActiveObjectGroup := FActiveDbObj.GroupType;
1000210007 end;
10003- lntTable..lntEvent: begin
10008+ lntTable..lntEvent, lntColumn : begin
1000410009 try
1000510010 FActiveDbObj.Connection.Database := FActiveDbObj.Database;
1000610011 except on E:EDbError do begin
@@ -10019,21 +10024,22 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
1001910024 menuQueryExactRowCount.Checked := False;
1002010025 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
1002110026 try
10022- if FActiveDbObj .NodeType in [lntTable, lntView] then begin
10023- SelectedTableColumns := FActiveDbObj .TableColumns;
10027+ if TableLevelObj .NodeType in [lntTable, lntView] then begin
10028+ SelectedTableColumns := TableLevelObj .TableColumns;
1002410029 try
10025- SelectedTableKeys := FActiveDbObj .TableKeys;
10030+ SelectedTableKeys := TableLevelObj .TableKeys;
1002610031 except // No show stopper, happening when a view references a renamed table column, see #1130
1002710032 on E:EDbError do
1002810033 ErrorDialog(_('This view probably contains an error in its code.')+sLineBreak+sLineBreak+E.Message);
1002910034 end;
10030- SelectedTableForeignKeys := FActiveDbObj .TableForeignKeys;
10035+ SelectedTableForeignKeys := TableLevelObj .TableForeignKeys;
1003110036 end;
10032- PlaceObjectEditor(FActiveDbObj );
10037+ PlaceObjectEditor(TableLevelObj );
1003310038 // When a table is clicked in the tree, and the current
1003410039 // tab is a Host or Database tab, switch to showing table columns.
1003510040 if (PagecontrolMain.ActivePage = tabHost) or (PagecontrolMain.ActivePage = tabDatabase) then
1003610041 MainTabToActivate := tabEditor;
10042+ // Todo: prevent reload when focus has changed within a table's children only
1003710043 if DataGrid.Tag = VTREE_LOADED then
1003810044 InvalidateVT(DataGrid, VTREE_NOTLOADED_PURGECACHE, False);
1003910045 // Update the list of columns
@@ -10127,8 +10133,8 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
1012710133 if not FTreeRefreshInProgress then begin
1012810134 SetMainTab(MainTabToActivate);
1012910135 tabDatabase.TabVisible := (FActiveDbObj <> nil) and (FActiveDbObj.NodeType <> lntNone);
10130- tabEditor.TabVisible := (FActiveDbObj <> nil) and (FActiveDbObj.NodeType in [lntTable..lntEvent]);
10131- tabData.TabVisible := (FActiveDbObj <> nil) and (FActiveDbObj.NodeType in [lntTable, lntView]);
10136+ tabEditor.TabVisible := (FActiveDbObj <> nil) and (FActiveDbObj.NodeType in [lntTable..lntEvent, lntColumn ]);
10137+ tabData.TabVisible := (FActiveDbObj <> nil) and (FActiveDbObj.NodeType in [lntTable, lntView, lntColumn ]);
1013210138 end;
1013310139
1013410140 // Store click history item
@@ -10257,7 +10263,7 @@ procedure TMainForm.DBtreeDblClick(Sender: TObject);
1025710263 // Paste DB or table name into query window on treeview double click.
1025810264 if AppSettings.ReadBool(asDoubleClickInsertsNodeText) and QueryTabs.HasActiveTab and Assigned(DBtree.FocusedNode) then begin
1025910265 DBObj := DBtree.GetNodeData(DBtree.FocusedNode);
10260- if DBObj.NodeType in [lntDb, lntTable..lntEvent] then begin
10266+ if DBObj.NodeType in [lntDb, lntTable..lntEvent, lntColumn ] then begin
1026110267 m := QueryTabs.ActiveMemo;
1026210268 m.DragDrop(Sender, m.CaretX, m.CaretY);
1026310269 end;
@@ -10298,18 +10304,36 @@ procedure TMainForm.DBtreePaintText(Sender: TBaseVirtualTree; const
1029810304 TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType:
1029910305 TVSTTextType);
1030010306var
10301- DBObj: PDBObject;
10307+ DBObj, ParentObj : PDBObject;
1030210308 WalkNode: PVirtualNode;
10309+ Columns: TTableColumnList;
10310+ Datatype: TDBDatatype;
1030310311begin
10304- // Grey out non-current connection nodes, and rather unimportant "Size" column
10312+ // Grey out non-current connection nodes
1030510313 DBObj := Sender.GetNodeData(Node);
10306- if DBObj.Connection <> ActiveConnection then
10307- TargetCanvas.Font.Color := clGrayText
10308- else if (Column = 1) and (DBObj.NodeType in [lntTable..lntEvent]) then
10314+ if DBObj.Connection <> ActiveConnection then begin
1030910315 TargetCanvas.Font.Color := clGrayText;
10316+ Exit;
10317+ end;
10318+
10319+ // Set text color
10320+ case Column of
10321+ 0: begin
10322+ if DBObj.NodeType = lntColumn then begin
10323+ ParentObj := Sender.GetNodeData(Node.Parent);
10324+ Columns := ParentObj.TableColumns;
10325+ Datatype := Columns[Node.Index].DataType;
10326+ TargetCanvas.Font.Color := DatatypeCategories[Datatype.Category].Color;
10327+ end;
10328+ end;
10329+ 1: begin // Grey out rather unimportant "Size" column
10330+ if DBObj.NodeType in [lntTable..lntEvent] then
10331+ TargetCanvas.Font.Color := clGrayText;
10332+ end;
10333+ end;
1031010334
1031110335 // Set bold text if painted node is in focused path
10312- if (Column = Sender .Header.MainColumn) then begin
10336+ if (Column = DBtree .Header.MainColumn) then begin
1031310337 WalkNode := Sender.FocusedNode;
1031410338 while Assigned(WalkNode) do begin
1031510339 if WalkNode = Node then begin
@@ -11613,10 +11637,13 @@ procedure TMainForm.HandleDataGridAttributes(RefreshingData: Boolean);
1161311637
1161411638
1161511639function TMainForm.GetRegKeyTable: String;
11640+ var
11641+ o: TDBObject;
1161611642begin
1161711643 // Return the slightly complex registry path to \Servers\CustomFolder\ActiveServer\curdb|curtable
11618- Result := ActiveDbObj.Connection.Parameters.SessionPath + '\' +
11619- ActiveDatabase + DELIM + ActiveDbObj.Name;
11644+ o := ActiveDbObj;
11645+ Result := o.Connection.Parameters.SessionPath + '\' +
11646+ ActiveDatabase + DELIM + o.Name;
1162011647end;
1162111648
1162211649
@@ -13963,7 +13990,7 @@ procedure TMainForm.DBtreeBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas
1396313990 TargetCanvas.Brush.Color := DbObj.Connection.Parameters.SessionColor;
1396413991 TargetCanvas.FillRect(CellRect);
1396513992 end;
13966- if (Column=1) and DBObj.Connection.DbObjectsCached(DBObj.Database) then begin
13993+ if (Column=1) and (DBObj.NodeType in [lntTable..lntEvent]) and DBObj.Connection.DbObjectsCached(DBObj.Database) then begin
1396713994 AllObjects := DBObj.Connection.GetDBObjects(DBObj.Database);
1396813995 PaintColorBar(DBObj.Size, AllObjects.LargestObjectSize, TargetCanvas, CellRect);
1396913996 end;
@@ -14476,13 +14503,13 @@ procedure TMainForm.treeQueryHelpersGetImageIndex(Sender: TBaseVirtualTree; Node
1447614503 TQueryTab.HelperNodeBinding: ImageIndex := 119;
1447714504 end;
1447814505 1: case Node.Parent.Index of
14479- TQueryTab.HelperNodeColumns: ImageIndex := 42 ;
14506+ TQueryTab.HelperNodeColumns: ImageIndex := ICONINDEX_FIELD ;
1448014507 TQueryTab.HelperNodeFunctions: ImageIndex := 13;
1448114508 TQueryTab.HelperNodeKeywords: ImageIndex := 25;
1448214509 TQueryTab.HelperNodeSnippets: ImageIndex := 68;
1448314510 TQueryTab.HelperNodeHistory: ImageIndex := 80;
1448414511 TQueryTab.HelperNodeProfile: ImageIndex := 145;
14485- TQueryTab.HelperNodeBinding: ImageIndex := 42 ;
14512+ TQueryTab.HelperNodeBinding: ImageIndex := ICONINDEX_FIELD ;
1448614513 end;
1448714514 end;
1448814515end;
0 commit comments