Skip to content

Commit a5ae04b

Browse files
committed
feat: bypass automatic foreign key lookup in data grid editing through new menu item
Refs #2454
1 parent 1633c33 commit a5ae04b

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

extra/locale/heidisql.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6842,3 +6842,6 @@ msgstr "Copy formatted text"
68426842

68436843
msgid "Copies selected text with formatting from current editor to clipboard"
68446844
msgstr "Copies selected text with formatting from current editor to clipboard"
6845+
6846+
msgid "Edit value without foreign key lookup"
6847+
msgstr "Edit value without foreign key lookup"

source/main.lfm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,6 +5113,12 @@ object MainForm: TMainForm
51135113
ImageIndex = 3
51145114
OnExecute = actCopyFormattedExecute
51155115
end
5116+
object actDataEditWithoutLookup: TAction
5117+
Category = 'Data'
5118+
Caption = 'Edit value without foreign key lookup'
5119+
ImageIndex = 58
5120+
OnExecute = actDataEditWithoutLookupExecute
5121+
end
51165122
end
51175123
object ImageListMain: TImageList
51185124
Scaled = True
@@ -20633,6 +20639,9 @@ object MainForm: TMainForm
2063320639
ImageIndex = 28
2063420640
OnClick = InsertValue
2063520641
end
20642+
object menuDataEditWithoutLookup: TMenuItem
20643+
Action = actDataEditWithoutLookup
20644+
end
2063620645
object N11: TMenuItem
2063720646
Caption = '-'
2063820647
end

source/main.pas

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ TQueryHistoryItemComparer = class(TComparer<TQueryHistoryItem>)
216216

217217
TMainForm = class(TExtForm)
218218
actCopyColumnNames: TAction;
219+
actDataEditWithoutLookup: TAction;
219220
actPreferencesSQL: TAction;
220221
MainMenu1: TMainMenu;
221222
MainMenuFile: TMenuItem;
@@ -224,6 +225,7 @@ TMainForm = class(TExtForm)
224225
FollowForeignKey: TMenuItem;
225226
menuColorScheme: TMenuItem;
226227
MenuItem3: TMenuItem;
228+
menuDataEditWithoutLookup: TMenuItem;
227229
menuRenameSnippet: TMenuItem;
228230
menuSQLpreferences: TMenuItem;
229231
menuQFdummy: TMenuItem;
@@ -831,6 +833,7 @@ TMainForm = class(TExtForm)
831833
actCopyFormatted: TAction;
832834
Copyformattedtext1: TMenuItem;
833835
procedure actCreateDBObjectExecute(Sender: TObject);
836+
procedure actDataEditWithoutLookupExecute(Sender: TObject);
834837
procedure actNextTabExecute(Sender: TObject);
835838
procedure actPreviousTabExecute(Sender: TObject);
836839
procedure DataGridContextPopup(Sender: TObject; MousePos: TPoint;
@@ -1281,6 +1284,7 @@ TMainForm = class(TExtForm)
12811284
FCreateDatabaseDialog: TCreateDatabaseForm;
12821285
FTableToolsDialog: TfrmTableTools;
12831286
FGridEditFunctionMode: Boolean;
1287+
FDataEditWithoutLookup: Boolean;
12841288
FClipboardHasNull: Boolean;
12851289
FTimeZoneOffset: Integer;
12861290
FGridCopying: Boolean;
@@ -1705,6 +1709,11 @@ procedure TMainForm.actGridEditFunctionExecute(Sender: TObject);
17051709
ActiveGrid.EditNode(ActiveGrid.FocusedNode, ActiveGrid.FocusedColumn);
17061710
end;
17071711

1712+
procedure TMainForm.actDataEditWithoutLookupExecute(Sender: TObject);
1713+
begin
1714+
FDataEditWithoutLookup := True;
1715+
DataGrid.EditNode(DataGrid.FocusedNode, DataGrid.FocusedColumn);
1716+
end;
17081717

17091718
procedure TMainForm.StoreLastSessions;
17101719
var
@@ -5918,7 +5927,7 @@ procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
59185927
col := vt.Header.Columns.Add;
59195928
col.Text := TblCol.Name;
59205929
col.Hint := TblCol.Comment;
5921-
col.Options := col.Options + [coSmartResize];
5930+
col.Options := col.Options + [coSmartResize, coEditable];
59225931
if DatagridHiddenColumns.IndexOf(TblCol.Name) > -1 then
59235932
col.Options := col.Options - [coVisible];
59245933
// Column header icon
@@ -6602,6 +6611,7 @@ procedure TMainForm.ValidateControls(Sender: TObject);
66026611
actDataCancelChanges.Enabled := HasConnection and GridHasChanges;
66036612
actDataSaveBlobToFile.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
66046613
actGridEditFunction.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
6614+
actDataEditWithoutLookup.Enabled := HasConnection and inDataTab;
66056615
actDataPreview.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
66066616
actDataOpenUrl.Enabled := (Length(CellText)<SIZE_MB) and ExecRegExpr('^(https?://[^\s]+|www\.\w\S+)$', CellText);
66076617
actUnixTimestampColumn.Enabled := HasConnection and inDataTab and EnableTimestamp;
@@ -7982,6 +7992,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject);
79827992
begin
79837993
// Manipulate quick filter menuitems
79847994
Grid := ActiveGrid;
7995+
FLastMouseButtonUpOnGrid := mbLeft;
79857996
// Make sure ValidateControls detects the grid as focused, which is not the case when
79867997
// it has 0 nodes, even with TreeOptions.SelectionOptions.RightclickSelect enabled
79877998
Grid.SetFocus;
@@ -10710,7 +10721,6 @@ procedure TMainForm.AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
1071010721
on E:Exception do
1071110722
ErrorDialog(E.Message);
1071210723
end;
10713-
FGridEditFunctionMode := False;
1071410724
ValidateControls(Sender);
1071510725
end;
1071610726

@@ -10757,6 +10767,9 @@ procedure TMainForm.AnyGridFocusChanged(Sender: TBaseVirtualTree; Node: PVirtual
1075710767
Sender.ScrollIntoView(Sender.FocusedNode, False, True);
1075810768
// Required for highlighting fields with same text
1075910769
Sender.Invalidate;
10770+
// Reset flags when moving focus
10771+
FGridEditFunctionMode := False;
10772+
FDataEditWithoutLookup := False;
1076010773
end;
1076110774

1076210775

@@ -10837,7 +10850,6 @@ procedure TMainForm.AnyGridEdited(Sender: TBaseVirtualTree; Node:
1083710850
if ([tsEditing, tsEditPending] * Sender.TreeStates) = [] then begin
1083810851
actDataCancelChanges.ShortCut := KeyToShortCut(VK_ESCAPE, []);
1083910852
actDataPostChanges.ShortCut := KeyToShortCut(VK_RETURN, [ssCtrl]);
10840-
FGridEditFunctionMode := False;
1084110853
end;
1084210854
end;
1084310855

@@ -10875,6 +10887,7 @@ procedure TMainForm.AnyGridCreateEditor(Sender: TBaseVirtualTree; Node:
1087510887
ResultCol: Integer;
1087610888
begin
1087710889
VT := Sender as TVirtualStringTree;
10890+
EditLink := nil;
1087810891
Results := GridResult(VT);
1087910892
RowNum := VT.GetNodeData(Node);
1088010893
Results.RecNo := RowNum^;
@@ -10885,7 +10898,7 @@ procedure TMainForm.AnyGridCreateEditor(Sender: TBaseVirtualTree; Node:
1088510898
TblColumn := Results.ColAttributes(ResultCol);
1088610899

1088710900
// Find foreign key values
10888-
if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) then begin
10901+
if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) and (not FDataEditWithoutLookup) then begin
1088910902
for ForeignKey in SelectedTableForeignKeys do begin
1089010903
idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text);
1089110904
if idx > -1 then try

0 commit comments

Comments
 (0)