refactor: move grid null colors away from data types array to the new color scheme

This commit is contained in:
Ansgar Becker
2026-01-26 11:08:21 +01:00
parent 38faf5787d
commit 2bc36b47e6
7 changed files with 22 additions and 44 deletions

View File

@@ -51,8 +51,6 @@ type
TDBDatatypeCategory = record
Index: TDBDatatypeCategoryIndex;
Name: String;
Color: TColor;
NullColor: TColor;
end;
// Server variables

View File

@@ -28,9 +28,11 @@ type
Name: String;
SynSqlSyn: TSynSqlsyn;
GridTextColors: TGridTextColors;
GridNullColors: TGridTextColors;
ActiveLineBackground: TColor;
MatchingBraceForeground: TColor;
MatchingBraceBackground: TColor;
const GridNullBrightness = 20;
constructor Create;
destructor Destroy; override;
// Load colors from settings
@@ -138,6 +140,7 @@ procedure TAppColorScheme.LoadFromSettings;
var
i: Integer;
Attri: TSynHighlighterAttributes;
dtc: TDBDatatypeCategoryIndex;
begin
Name := _('Current custom settings');
for i:=0 to SynSqlSyn.AttrCount - 1 do begin
@@ -158,6 +161,11 @@ begin
GridTextColors[dtcTemporal] := AppSettings.ReadInt(asFieldColorDatetime);
GridTextColors[dtcSpatial] := AppSettings.ReadInt(asFieldColorSpatial);
GridTextColors[dtcOther] := AppSettings.ReadInt(asFieldColorOther);
// Calculate brighter NULL colors - not part of color presets
for dtc:=Low(DatatypeCategories) to High(DatatypeCategories) do begin
GridNullColors[dtc] := ColorAdjustBrightness(GridTextColors[dtc], GridNullBrightness);
end;
end;
destructor TAppColorScheme.Destroy;

View File

@@ -9,7 +9,7 @@ interface
uses
Forms, Graphics, Messages, laz.VirtualTrees, ComCtrls, SysUtils, Classes,
StdCtrls, ExtCtrls, CheckLst, Controls, Types, Dialogs, Menus, MaskEdit, DateUtils, Math,
dbconnection, dbstructures, apphelpers, texteditor, bineditor, lazaruscompat,
dbconnection, dbstructures, apphelpers, generic_types, texteditor, bineditor, lazaruscompat,
{$IFNDEF FREEBSD}System.UITypes,{$ENDIF} RegExpr, extra_controls, EditBtn, LCLType, LCLIntf;
type
@@ -340,7 +340,7 @@ begin
// Not all editors have a connection assigned, e.g. session manager tree
if Assigned(FTableColumn) then begin
FCellFont.Color := DatatypeCategories[FTableColumn.DataType.Category].Color;
FCellFont.Color := AppColorSchemes.First.GridTextColors[FTableColumn.DataType.Category];
end;
FCellBackground := FTree.Header.Columns[FColumn].Color;
if Assigned(FMainControl) then begin
@@ -1880,7 +1880,7 @@ begin
case Sender.GetNodeLevel(Node) of
0: TargetCanvas.Font.Style := TargetCanvas.Font.Style + [fsBold];
1: if not (vsSelected in Node.States) then
TargetCanvas.Font.Color := DatatypeCategories[TDBDatatypeCategoryIndex(Node.Parent.Index)].Color;
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[TDBDatatypeCategoryIndex(Node.Parent.Index)];
end;
end;

View File

@@ -7,7 +7,7 @@ interface
uses
SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls,
Math, Graphics, ComCtrls, LCLType, extra_controls, lazaruscompat,
dbconnection, dbstructures, laz.VirtualTrees, RegExpr, apphelpers, extfiledialog;
dbconnection, dbstructures, laz.VirtualTrees, RegExpr, apphelpers, generic_types, extfiledialog;
type
TColInfo = class
@@ -196,7 +196,7 @@ begin
// Datatype specific font color
if Column = ColDatatype then begin
ColInfo := Sender.GetNodeData(Node);
TargetCanvas.Font.Color := DatatypeCategories[ColInfo.DataType.Category].Color;
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[ColInfo.DataType.Category];
end;
end;

View File

@@ -1373,7 +1373,6 @@ type
function GetRootNode(Tree: TVirtualStringTree; Connection: TDBConnection): PVirtualNode;
function FindDBObjectNode(Tree: TVirtualStringTree; Obj: TDBObject): PVirtualNode;
function FindDBNode(Tree: TVirtualStringTree; Connection: TDBConnection; db: String): PVirtualNode;
procedure CalcNullColors;
procedure HandleDataGridAttributes(RefreshingData: Boolean);
function GetRegKeyTable: String;
procedure UpdateEditorTab;
@@ -1974,15 +1973,6 @@ begin
// Data-Font:
ApplyFontToGrids;
// Load color settings
DatatypeCategories[dtcInteger].Color := AppSettings.ReadInt(asFieldColorNumeric);
DatatypeCategories[dtcReal].Color := AppSettings.ReadInt(asFieldColorReal);
DatatypeCategories[dtcText].Color := AppSettings.ReadInt(asFieldColorText);
DatatypeCategories[dtcBinary].Color := AppSettings.ReadInt(asFieldColorBinary);
DatatypeCategories[dtcTemporal].Color := AppSettings.ReadInt(asFieldColorDatetime);
DatatypeCategories[dtcSpatial].Color := AppSettings.ReadInt(asFieldColorSpatial);
DatatypeCategories[dtcOther].Color := AppSettings.ReadInt(asFieldColorOther);
CalcNullColors;
FDataGridSortItems := TSortItems.Create(True);
@@ -6831,7 +6821,7 @@ var
end;
end;
// Put formatted text and icon into proposal
DisplayText := SynCompletionProposalPrettyText(ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, DatatypeCategories[Col.DataType.Category].NullColor);
DisplayText := SynCompletionProposalPrettyText(ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, AppColorSchemes.First.GridNullColors[Col.DataType.Category]);
//if CurrentInput.StartsWith(Conn.QuoteChar) then
// Proposal.ItemList.Add(Conn.QuoteChar + Col.Name)
//else
@@ -9157,7 +9147,7 @@ begin
dcat := dtcOther
else
dcat := dtcText;
TargetCanvas.Font.Color := DatatypeCategories[dcat].Color;
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[dcat];
end;
end;
@@ -10326,16 +10316,6 @@ begin
end;
procedure TMainForm.CalcNullColors;
var
dtc: TDBDatatypeCategoryIndex;
begin
for dtc:=Low(DatatypeCategories) to High(DatatypeCategories) do begin
DatatypeCategories[dtc].NullColor := ColorAdjustBrightness(DatatypeCategories[dtc].Color, 20);
end;
end;
{**
Cell in data- or query grid gets painted. Colorize font. This procedure is
called extremely often for repainting the grid cells. Keep it highly optimized.
@@ -10371,9 +10351,9 @@ begin
if (vsSelected in Node.States) and (Node = Sender.FocusedNode) and (Column = Sender.FocusedColumn) then
cl := GetThemeColor(clHighlightText)
else if r.IsNull(ResultCol) then
cl := DatatypeCategories[r.DataType(ResultCol).Category].NullColor
cl := AppColorSchemes.First.GridNullColors[r.DataType(ResultCol).Category]
else
cl := DatatypeCategories[r.DataType(ResultCol).Category].Color;
cl := AppColorSchemes.First.GridTextColors[r.DataType(ResultCol).Category];
TargetCanvas.Font.Color := cl;
end;
@@ -13875,7 +13855,7 @@ begin
and (Sender.GetNodeLevel(Node)=1)
and (ActiveDbObj.NodeType in [lntView, lntTable])
then begin
TargetCanvas.Font.Color := DatatypeCategories[SelectedTableColumns[Node.Index].DataType.Category].Color;
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[SelectedTableColumns[Node.Index].DataType.Category];
end;
if (Sender.GetNodeLevel(Node)=2)
and (Node.Parent.Parent.Index=TQueryTab.HelperNodeHistory)

View File

@@ -420,15 +420,7 @@ begin
Mainform.LogToFile := chkLogToFile.Checked;
MainForm.actLogHorizontalScrollbar.Checked := chkHorizontalScrollbar.Checked;
MainForm.actLogHorizontalScrollbar.OnExecute(MainForm.actLogHorizontalScrollbar);
DatatypeCategories[dtcInteger].Color := FAppColorScheme.GridTextColors[dtcInteger];
DatatypeCategories[dtcReal].Color := FAppColorScheme.GridTextColors[dtcReal];
DatatypeCategories[dtcText].Color := FAppColorScheme.GridTextColors[dtcText];
DatatypeCategories[dtcBinary].Color := FAppColorScheme.GridTextColors[dtcBinary];
DatatypeCategories[dtcTemporal].Color := FAppColorScheme.GridTextColors[dtcTemporal];
DatatypeCategories[dtcSpatial].Color := FAppColorScheme.GridTextColors[dtcSpatial];
DatatypeCategories[dtcOther].Color := FAppColorScheme.GridTextColors[dtcOther];
Mainform.DataLocalNumberFormat := chkLocalNumberFormat.Checked;
Mainform.CalcNullColors;
Mainform.DataGrid.Repaint;
Mainform.QueryGrid.Repaint;
Mainform.ListTables.Invalidate;

View File

@@ -9,7 +9,7 @@ uses
ComCtrls, laz.VirtualTrees, RegExpr, ExtCtrls, SynEdit,
{$IFDEF Windows} ActiveX {$ELSE} laz.FakeActiveX {$ENDIF},
Menus, Clipbrd, Math, {$IFNDEF FREEBSD}System.UITypes,{$ENDIF} Generics.Collections, LCLProc, LCLType,
{grideditlinks,} dbstructures, dbstructures.mysql, dbconnection, apphelpers, StrUtils, extra_controls;
{grideditlinks,} dbstructures, dbstructures.mysql, dbconnection, apphelpers, generic_types, StrUtils, extra_controls;
type
TFrame = TDBObjectEditor;
@@ -1562,13 +1562,13 @@ begin
case Column of
ColNumCounter: TargetCanvas.Font.Color := clGrayText;
ColNumDatatype: TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].Color;
ColNumDatatype: TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[Col.DataType.Category];
ColNumDefault: case Col.DefaultType of
cdtNothing, cdtNull:
TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].NullColor;
TargetCanvas.Font.Color := AppColorSchemes.First.GridNullColors[Col.DataType.Category];
else
TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].Color;
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[Col.DataType.Category];
end;
end;