diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 953b91c1..77999937 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -179,7 +179,7 @@ type TAppSettingIndex = (asHiddenColumns, asFilter, asSort, asDisplayedColumnsSorted, asLastSessions, asLastActiveSession, asAutoReconnect, asRestoreLastUsedDB, asLastUsedDB, asTreeBackground, asIgnoreDatabasePattern, asLogFileDdl, asLogFileDml, asLogFilePath, asFontName, asFontSize, asTabWidth, asDataFontName, asDataFontSize, asDataLocalNumberFormat, asLowercaseHex, asHintsOnResultTabs, asHightlightSameTextBackground, - asShowRowId, + asShowRowId, asRememberColWidths, asDataGridColWidth, asLogsqlnum, asLogsqlwidth, asSessionLogsDirectory, asLogHorizontalScrollbar, asSQLColActiveLine, asSQLColMatchingBraceForeground, asSQLColMatchingBraceBackground, asMaxColWidth, asDatagridMaximumRows, asDatagridRowsPerStep, asGridRowLineCount, asColumnHeaderClick, asReuseEditorConfiguration, @@ -3875,6 +3875,8 @@ begin InitSetting(asLowercaseHex, 'LowercaseHex', 0, True); InitSetting(asHintsOnResultTabs, 'HintsOnResultTabs', 0, True); InitSetting(asShowRowId, 'ShowRowId', 0, True); + InitSetting(asRememberColWidths, 'RememberColWidths', 0, False); + InitSetting(asDataGridColWidth, 'ColWidth_%s', 0, False, '', True); InitSetting(asHightlightSameTextBackground, 'HightlightSameTextBackground', GetThemeColor(clInfoBk)); InitSetting(asLogsqlnum, 'logsqlnum', 300); InitSetting(asLogsqlwidth, 'logsqlwidth', 2000); diff --git a/source/main.pas b/source/main.pas index 22d92276..ebd43b11 100644 --- a/source/main.pas +++ b/source/main.pas @@ -6292,8 +6292,15 @@ end; procedure TMainForm.DataGridColumnResize(Sender: TVTHeader; Column: TColumnIndex); begin // Remember current table after last column resizing so we can auto size them as long as this did not happen - if not TBaseVirtualTree(Sender.Treeview).IsUpdating then + if not TBaseVirtualTree(Sender.Treeview).IsUpdating then begin FDataGridColumnWidthsCustomized := True; + // Save the width per database + table + column + if (Column > 0) and Assigned(DataGridTable) and AppSettings.ReadBool(asRememberColWidths) then begin + AppSettings.SessionPath := DataGridTable.Connection.Parameters.SessionPath + '\' + + DataGridTable.Database + DELIM + DataGridTable.Name; + AppSettings.WriteInt(asDataGridColWidth, Sender.Columns[Column].Width, Sender.Columns[Column].Text); + end; + end; end; @@ -11534,9 +11541,10 @@ end; procedure TMainForm.AutoCalcColWidth(Tree: TVirtualStringTree; Column: TColumnIndex); var Node: PVirtualNode; - i, ColTextWidth, ContentTextWidth: Integer; + i, ColTextWidth, ContentTextWidth, SavedWidth: Integer; Rect: TRect; Col: TVirtualTreeColumn; + RegKey: String; begin // Find optimal default width for columns. Needs to be done late, after the SQL // composing to enable text width calculation based on actual table content @@ -11545,6 +11553,20 @@ begin Col := Tree.Header.Columns[Column]; if not (coVisible in Col.Options) then Exit; + // Use the width saved for this database + table + column, if any + if (Tree = DataGrid) and (Column > 0) and Assigned(DataGridTable) + and AppSettings.ReadBool(asRememberColWidths) then begin + SavedWidth := 0; + RegKey := DataGridTable.Connection.Parameters.SessionPath + '\' + DataGridTable.Database + DELIM + DataGridTable.Name; + if AppSettings.SessionPathExists(RegKey) then begin + AppSettings.SessionPath := RegKey; + SavedWidth := AppSettings.ReadInt(asDataGridColWidth, Col.Text); + end; + if SavedWidth > 0 then begin + Col.Width := SavedWidth; + Exit; + end; + end; ColTextWidth := Tree.Canvas.TextWidth(Col.Text); // Add space for column id ... if (Column > 0) and AppSettings.ReadBool(asShowRowId) then diff --git a/source/preferences.dfm b/source/preferences.dfm index 2678b336..f8568059 100644 --- a/source/preferences.dfm +++ b/source/preferences.dfm @@ -1184,6 +1184,16 @@ object frmPreferences: TfrmPreferences TabOrder = 23 OnClick = Modified end + object chkRememberColWidths: TCheckBox + Left = 220 + Top = 402 + Width = 453 + Height = 17 + Anchors = [akLeft, akTop, akRight] + Caption = 'Remember column widths per table' + TabOrder = 24 + OnClick = Modified + end end object tabDataEditors: TTabSheet Caption = 'Data editors' diff --git a/source/preferences.pas b/source/preferences.pas index 37c75301..4b4f1192 100644 --- a/source/preferences.pas +++ b/source/preferences.pas @@ -186,6 +186,7 @@ type chkColumnHeaderClick: TCheckBox; chkIncrementalSearch: TCheckBox; chkShowRowId: TCheckBox; + chkRememberColWidths: TCheckBox; chkTabCloseOnMiddleClick: TCheckBox; btnRemoveHotKey1: TButton; btnRemoveHotKey2: TButton; @@ -393,6 +394,7 @@ begin AppSettings.WriteBool(asLowercaseHex, chkLowercaseHex.Checked); AppSettings.WriteBool(asHintsOnResultTabs, chkHintsOnResultTabs.Checked); AppSettings.WriteBool(asShowRowId, chkShowRowId.Checked); + AppSettings.WriteBool(asRememberColWidths, chkRememberColWidths.Checked); // Editor Configuration AppSettings.WriteBool(asFieldEditorBinary, chkEditorBinary.Checked); @@ -800,6 +802,7 @@ begin chkLowercaseHex.Checked := AppSettings.ReadBool(asLowercaseHex); chkHintsOnResultTabs.Checked := AppSettings.ReadBool(asHintsOnResultTabs); chkShowRowId.Checked := AppSettings.ReadBool(asShowRowId); + chkRememberColWidths.Checked := AppSettings.ReadBool(asRememberColWidths); // Editor Configuration chkEditorBinary.Checked := AppSettings.ReadBool(asFieldEditorBinary);