Skip to content

Commit 118e9d9

Browse files
committed
feat: bypass automatic foreign key lookup in data grid editing through new menu item
Refs #2454
1 parent 50325ea commit 118e9d9

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

source/main.dfm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,12 @@ object MainForm: TMainForm
34583458
ImageIndex = 3
34593459
OnExecute = actCopyFormattedExecute
34603460
end
3461+
object actDataEditWithoutLookup: TAction
3462+
Category = 'Data'
3463+
Caption = 'Edit value without foreign key lookup'
3464+
ImageIndex = 58
3465+
OnExecute = actDataEditWithoutLookupExecute
3466+
end
34613467
end
34623468
object menuConnections: TPopupMenu
34633469
AutoHotkeys = maManual
@@ -3703,6 +3709,9 @@ object MainForm: TMainForm
37033709
ImageIndex = 28
37043710
OnClick = InsertValue
37053711
end
3712+
object menuDataEditWithoutLookup: TMenuItem
3713+
Action = actDataEditWithoutLookup
3714+
end
37063715
object N11: TMenuItem
37073716
Caption = '-'
37083717
end

source/main.pas

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,13 @@ TQueryHistoryItemComparer = class(TComparer<TQueryHistoryItem>)
197197
end;
198198

199199
TMainForm = class(TExtForm)
200+
actDataEditWithoutLookup: TAction;
200201
MainMenu1: TMainMenu;
201202
MainMenuFile: TMenuItem;
202203
FileNewItem: TMenuItem;
203204
MainMenuHelp: TMenuItem;
204205
FollowForeignKey: TMenuItem;
206+
menuDataEditWithoutLookup: TMenuItem;
205207
menuRenameSnippet: TMenuItem;
206208
N1: TMenuItem;
207209
FileExitItem: TMenuItem;
@@ -813,6 +815,7 @@ TMainForm = class(TExtForm)
813815
actCopyFormatted: TAction;
814816
Copyformattedtext1: TMenuItem;
815817
procedure actCreateDBObjectExecute(Sender: TObject);
818+
procedure actDataEditWithoutLookupExecute(Sender: TObject);
816819
procedure menuConnectionsPopup(Sender: TObject);
817820
procedure actExitApplicationExecute(Sender: TObject);
818821
procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
@@ -1264,6 +1267,7 @@ TMainForm = class(TExtForm)
12641267
FCreateDatabaseDialog: TCreateDatabaseForm;
12651268
FTableToolsDialog: TfrmTableTools;
12661269
FGridEditFunctionMode: Boolean;
1270+
FDataEditWithoutLookup: Boolean;
12671271
FClipboardHasNull: Boolean;
12681272
FTimeZoneOffset: Integer;
12691273
FGridCopying: Boolean;
@@ -1743,6 +1747,11 @@ procedure TMainForm.actGridEditFunctionExecute(Sender: TObject);
17431747
ActiveGrid.EditNode(ActiveGrid.FocusedNode, ActiveGrid.FocusedColumn);
17441748
end;
17451749

1750+
procedure TMainForm.actDataEditWithoutLookupExecute(Sender: TObject);
1751+
begin
1752+
FDataEditWithoutLookup := True;
1753+
DataGrid.EditNode(DataGrid.FocusedNode, DataGrid.FocusedColumn);
1754+
end;
17461755

17471756
procedure TMainForm.StoreLastSessions;
17481757
var
@@ -5971,7 +5980,7 @@ procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
59715980
col := vt.Header.Columns.Add;
59725981
col.Text := TblCol.Name;
59735982
col.Hint := TblCol.Comment;
5974-
col.Options := col.Options + [coSmartResize];
5983+
col.Options := col.Options + [coSmartResize, coEditable];
59755984
if DatagridHiddenColumns.IndexOf(TblCol.Name) > -1 then
59765985
col.Options := col.Options - [coVisible];
59775986
// Column header icon
@@ -6656,6 +6665,7 @@ procedure TMainForm.ValidateControls(Sender: TObject);
66566665
actDataCancelChanges.Enabled := HasConnection and GridHasChanges;
66576666
actDataSaveBlobToFile.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
66586667
actGridEditFunction.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
6668+
actDataEditWithoutLookup.Enabled := HasConnection and inDataTab;
66596669
actDataPreview.Enabled := HasConnection and inDataOrQueryTabNotEmpty and Assigned(Grid.FocusedNode);
66606670
actDataOpenUrl.Enabled := (Length(CellText)<SIZE_MB) and ExecRegExpr('^(https?://[^\s]+|www\.\w\S+)$', CellText);
66616671
actUnixTimestampColumn.Enabled := HasConnection and inDataTab and EnableTimestamp;
@@ -10953,7 +10963,6 @@ procedure TMainForm.AnyGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode;
1095310963
on E:Exception do
1095410964
ErrorDialog(E.Message);
1095510965
end;
10956-
FGridEditFunctionMode := False;
1095710966
ValidateControls(Sender);
1095810967
end;
1095910968

@@ -11000,6 +11009,9 @@ procedure TMainForm.AnyGridFocusChanged(Sender: TBaseVirtualTree; Node: PVirtual
1100011009
Sender.ScrollIntoView(Sender.FocusedNode, False, True);
1100111010
// Required for highlighting fields with same text
1100211011
Sender.Invalidate;
11012+
// Reset flags when moving focus
11013+
FGridEditFunctionMode := False;
11014+
FDataEditWithoutLookup := False;
1100311015
end;
1100411016

1100511017

@@ -11077,7 +11089,6 @@ procedure TMainForm.AnyGridEdited(Sender: TBaseVirtualTree; Node:
1107711089
if ([tsEditing, tsEditPending] * Sender.TreeStates) = [] then begin
1107811090
actDataCancelChanges.ShortCut := TextToShortcut('Esc');
1107911091
actDataPostChanges.ShortCut := TextToShortcut('Ctrl+Enter');
11080-
FGridEditFunctionMode := False;
1108111092
end;
1108211093
end;
1108311094

@@ -11115,6 +11126,7 @@ procedure TMainForm.AnyGridCreateEditor(Sender: TBaseVirtualTree; Node:
1111511126
ResultCol: Integer;
1111611127
begin
1111711128
VT := Sender as TVirtualStringTree;
11129+
EditLink := nil;
1111811130
Results := GridResult(VT);
1111911131
RowNum := VT.GetNodeData(Node);
1112011132
Results.RecNo := RowNum^;
@@ -11125,7 +11137,7 @@ procedure TMainForm.AnyGridCreateEditor(Sender: TBaseVirtualTree; Node:
1112511137
TblColumn := Results.ColAttributes(ResultCol);
1112611138

1112711139
// Find foreign key values
11128-
if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) then begin
11140+
if AppSettings.ReadBool(asForeignDropDown) and (Sender = DataGrid) and (not FDataEditWithoutLookup) then begin
1112911141
for ForeignKey in SelectedTableForeignKeys do begin
1113011142
idx := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Column].Text);
1113111143
if idx > -1 then try

0 commit comments

Comments
 (0)