Skip to content

Commit 2bc36b4

Browse files
committed
refactor: move grid null colors away from data types array to the new color scheme
1 parent 38faf57 commit 2bc36b4

File tree

7 files changed

+22
-44
lines changed

7 files changed

+22
-44
lines changed

source/dbstructures.pas

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ TDBDatatype = record
5151
TDBDatatypeCategory = record
5252
Index: TDBDatatypeCategoryIndex;
5353
Name: String;
54-
Color: TColor;
55-
NullColor: TColor;
5654
end;
5755

5856
// Server variables

source/generic_types.pas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ TAppColorScheme = class(TObject)
2828
Name: String;
2929
SynSqlSyn: TSynSqlsyn;
3030
GridTextColors: TGridTextColors;
31+
GridNullColors: TGridTextColors;
3132
ActiveLineBackground: TColor;
3233
MatchingBraceForeground: TColor;
3334
MatchingBraceBackground: TColor;
35+
const GridNullBrightness = 20;
3436
constructor Create;
3537
destructor Destroy; override;
3638
// Load colors from settings
@@ -138,6 +140,7 @@ procedure TAppColorScheme.LoadFromSettings;
138140
var
139141
i: Integer;
140142
Attri: TSynHighlighterAttributes;
143+
dtc: TDBDatatypeCategoryIndex;
141144
begin
142145
Name := _('Current custom settings');
143146
for i:=0 to SynSqlSyn.AttrCount - 1 do begin
@@ -158,6 +161,11 @@ procedure TAppColorScheme.LoadFromSettings;
158161
GridTextColors[dtcTemporal] := AppSettings.ReadInt(asFieldColorDatetime);
159162
GridTextColors[dtcSpatial] := AppSettings.ReadInt(asFieldColorSpatial);
160163
GridTextColors[dtcOther] := AppSettings.ReadInt(asFieldColorOther);
164+
165+
// Calculate brighter NULL colors - not part of color presets
166+
for dtc:=Low(DatatypeCategories) to High(DatatypeCategories) do begin
167+
GridNullColors[dtc] := ColorAdjustBrightness(GridTextColors[dtc], GridNullBrightness);
168+
end;
161169
end;
162170

163171
destructor TAppColorScheme.Destroy;

source/grideditlinks.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface
99
uses
1010
Forms, Graphics, Messages, laz.VirtualTrees, ComCtrls, SysUtils, Classes,
1111
StdCtrls, ExtCtrls, CheckLst, Controls, Types, Dialogs, Menus, MaskEdit, DateUtils, Math,
12-
dbconnection, dbstructures, apphelpers, texteditor, bineditor, lazaruscompat,
12+
dbconnection, dbstructures, apphelpers, generic_types, texteditor, bineditor, lazaruscompat,
1313
{$IFNDEF FREEBSD}System.UITypes,{$ENDIF} RegExpr, extra_controls, EditBtn, LCLType, LCLIntf;
1414

1515
type
@@ -340,7 +340,7 @@ function TBaseGridEditorLink.PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualN
340340

341341
// Not all editors have a connection assigned, e.g. session manager tree
342342
if Assigned(FTableColumn) then begin
343-
FCellFont.Color := DatatypeCategories[FTableColumn.DataType.Category].Color;
343+
FCellFont.Color := AppColorSchemes.First.GridTextColors[FTableColumn.DataType.Category];
344344
end;
345345
FCellBackground := FTree.Header.Columns[FColumn].Color;
346346
if Assigned(FMainControl) then begin
@@ -1880,7 +1880,7 @@ procedure TDataTypeEditorLink.DoTreeSelectPaintText(Sender: TBaseVirtualTree;
18801880
case Sender.GetNodeLevel(Node) of
18811881
0: TargetCanvas.Font.Style := TargetCanvas.Font.Style + [fsBold];
18821882
1: if not (vsSelected in Node.States) then
1883-
TargetCanvas.Font.Color := DatatypeCategories[TDBDatatypeCategoryIndex(Node.Parent.Index)].Color;
1883+
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[TDBDatatypeCategoryIndex(Node.Parent.Index)];
18841884
end;
18851885
end;
18861886

source/insertfiles.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface
77
uses
88
SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls,
99
Math, Graphics, ComCtrls, LCLType, extra_controls, lazaruscompat,
10-
dbconnection, dbstructures, laz.VirtualTrees, RegExpr, apphelpers, extfiledialog;
10+
dbconnection, dbstructures, laz.VirtualTrees, RegExpr, apphelpers, generic_types, extfiledialog;
1111

1212
type
1313
TColInfo = class
@@ -196,7 +196,7 @@ procedure TfrmInsertFiles.ListColumnsPaintText(Sender: TBaseVirtualTree;
196196
// Datatype specific font color
197197
if Column = ColDatatype then begin
198198
ColInfo := Sender.GetNodeData(Node);
199-
TargetCanvas.Font.Color := DatatypeCategories[ColInfo.DataType.Category].Color;
199+
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[ColInfo.DataType.Category];
200200
end;
201201
end;
202202

source/main.pas

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,6 @@ TMainForm = class(TExtForm)
13731373
function GetRootNode(Tree: TVirtualStringTree; Connection: TDBConnection): PVirtualNode;
13741374
function FindDBObjectNode(Tree: TVirtualStringTree; Obj: TDBObject): PVirtualNode;
13751375
function FindDBNode(Tree: TVirtualStringTree; Connection: TDBConnection; db: String): PVirtualNode;
1376-
procedure CalcNullColors;
13771376
procedure HandleDataGridAttributes(RefreshingData: Boolean);
13781377
function GetRegKeyTable: String;
13791378
procedure UpdateEditorTab;
@@ -1974,15 +1973,6 @@ procedure TMainForm.FormCreate(Sender: TObject);
19741973

19751974
// Data-Font:
19761975
ApplyFontToGrids;
1977-
// Load color settings
1978-
DatatypeCategories[dtcInteger].Color := AppSettings.ReadInt(asFieldColorNumeric);
1979-
DatatypeCategories[dtcReal].Color := AppSettings.ReadInt(asFieldColorReal);
1980-
DatatypeCategories[dtcText].Color := AppSettings.ReadInt(asFieldColorText);
1981-
DatatypeCategories[dtcBinary].Color := AppSettings.ReadInt(asFieldColorBinary);
1982-
DatatypeCategories[dtcTemporal].Color := AppSettings.ReadInt(asFieldColorDatetime);
1983-
DatatypeCategories[dtcSpatial].Color := AppSettings.ReadInt(asFieldColorSpatial);
1984-
DatatypeCategories[dtcOther].Color := AppSettings.ReadInt(asFieldColorOther);
1985-
CalcNullColors;
19861976

19871977
FDataGridSortItems := TSortItems.Create(True);
19881978

@@ -6831,7 +6821,7 @@ procedure TMainForm.SynCompletionProposalExecute(Sender: TObject);
68316821
end;
68326822
end;
68336823
// Put formatted text and icon into proposal
6834-
DisplayText := SynCompletionProposalPrettyText(ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, DatatypeCategories[Col.DataType.Category].NullColor);
6824+
DisplayText := SynCompletionProposalPrettyText(ColumnIcon, LowerCase(Col.DataType.Name), Col.Name, Col.Comment, AppColorSchemes.First.GridNullColors[Col.DataType.Category]);
68356825
//if CurrentInput.StartsWith(Conn.QuoteChar) then
68366826
// Proposal.ItemList.Add(Conn.QuoteChar + Col.Name)
68376827
//else
@@ -9157,7 +9147,7 @@ procedure TMainForm.ListVariablesPaintText(Sender: TBaseVirtualTree;
91579147
dcat := dtcOther
91589148
else
91599149
dcat := dtcText;
9160-
TargetCanvas.Font.Color := DatatypeCategories[dcat].Color;
9150+
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[dcat];
91619151
end;
91629152
end;
91639153

@@ -10326,16 +10316,6 @@ procedure TMainForm.AnyGridGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
1032610316
end;
1032710317

1032810318

10329-
procedure TMainForm.CalcNullColors;
10330-
var
10331-
dtc: TDBDatatypeCategoryIndex;
10332-
begin
10333-
for dtc:=Low(DatatypeCategories) to High(DatatypeCategories) do begin
10334-
DatatypeCategories[dtc].NullColor := ColorAdjustBrightness(DatatypeCategories[dtc].Color, 20);
10335-
end;
10336-
end;
10337-
10338-
1033910319
{**
1034010320
Cell in data- or query grid gets painted. Colorize font. This procedure is
1034110321
called extremely often for repainting the grid cells. Keep it highly optimized.
@@ -10371,9 +10351,9 @@ procedure TMainForm.AnyGridPaintText(Sender: TBaseVirtualTree; const TargetCanva
1037110351
if (vsSelected in Node.States) and (Node = Sender.FocusedNode) and (Column = Sender.FocusedColumn) then
1037210352
cl := GetThemeColor(clHighlightText)
1037310353
else if r.IsNull(ResultCol) then
10374-
cl := DatatypeCategories[r.DataType(ResultCol).Category].NullColor
10354+
cl := AppColorSchemes.First.GridNullColors[r.DataType(ResultCol).Category]
1037510355
else
10376-
cl := DatatypeCategories[r.DataType(ResultCol).Category].Color;
10356+
cl := AppColorSchemes.First.GridTextColors[r.DataType(ResultCol).Category];
1037710357
TargetCanvas.Font.Color := cl;
1037810358
end;
1037910359

@@ -13875,7 +13855,7 @@ procedure TMainForm.treeQueryHelpersPaintText(Sender: TBaseVirtualTree; const Ta
1387513855
and (Sender.GetNodeLevel(Node)=1)
1387613856
and (ActiveDbObj.NodeType in [lntView, lntTable])
1387713857
then begin
13878-
TargetCanvas.Font.Color := DatatypeCategories[SelectedTableColumns[Node.Index].DataType.Category].Color;
13858+
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[SelectedTableColumns[Node.Index].DataType.Category];
1387913859
end;
1388013860
if (Sender.GetNodeLevel(Node)=2)
1388113861
and (Node.Parent.Parent.Index=TQueryTab.HelperNodeHistory)

source/preferences.pas

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,7 @@ procedure TfrmPreferences.Apply(Sender: TObject);
420420
Mainform.LogToFile := chkLogToFile.Checked;
421421
MainForm.actLogHorizontalScrollbar.Checked := chkHorizontalScrollbar.Checked;
422422
MainForm.actLogHorizontalScrollbar.OnExecute(MainForm.actLogHorizontalScrollbar);
423-
DatatypeCategories[dtcInteger].Color := FAppColorScheme.GridTextColors[dtcInteger];
424-
DatatypeCategories[dtcReal].Color := FAppColorScheme.GridTextColors[dtcReal];
425-
DatatypeCategories[dtcText].Color := FAppColorScheme.GridTextColors[dtcText];
426-
DatatypeCategories[dtcBinary].Color := FAppColorScheme.GridTextColors[dtcBinary];
427-
DatatypeCategories[dtcTemporal].Color := FAppColorScheme.GridTextColors[dtcTemporal];
428-
DatatypeCategories[dtcSpatial].Color := FAppColorScheme.GridTextColors[dtcSpatial];
429-
DatatypeCategories[dtcOther].Color := FAppColorScheme.GridTextColors[dtcOther];
430423
Mainform.DataLocalNumberFormat := chkLocalNumberFormat.Checked;
431-
Mainform.CalcNullColors;
432424
Mainform.DataGrid.Repaint;
433425
Mainform.QueryGrid.Repaint;
434426
Mainform.ListTables.Invalidate;

source/table_editor.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface
99
ComCtrls, laz.VirtualTrees, RegExpr, ExtCtrls, SynEdit,
1010
{$IFDEF Windows} ActiveX {$ELSE} laz.FakeActiveX {$ENDIF},
1111
Menus, Clipbrd, Math, {$IFNDEF FREEBSD}System.UITypes,{$ENDIF} Generics.Collections, LCLProc, LCLType,
12-
{grideditlinks,} dbstructures, dbstructures.mysql, dbconnection, apphelpers, StrUtils, extra_controls;
12+
{grideditlinks,} dbstructures, dbstructures.mysql, dbconnection, apphelpers, generic_types, StrUtils, extra_controls;
1313

1414
type
1515
TFrame = TDBObjectEditor;
@@ -1562,13 +1562,13 @@ procedure TfrmTableEditor.listColumnsPaintText(Sender: TBaseVirtualTree;
15621562
case Column of
15631563
ColNumCounter: TargetCanvas.Font.Color := clGrayText;
15641564

1565-
ColNumDatatype: TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].Color;
1565+
ColNumDatatype: TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[Col.DataType.Category];
15661566

15671567
ColNumDefault: case Col.DefaultType of
15681568
cdtNothing, cdtNull:
1569-
TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].NullColor;
1569+
TargetCanvas.Font.Color := AppColorSchemes.First.GridNullColors[Col.DataType.Category];
15701570
else
1571-
TargetCanvas.Font.Color := DatatypeCategories[Col.DataType.Category].Color;
1571+
TargetCanvas.Font.Color := AppColorSchemes.First.GridTextColors[Col.DataType.Category];
15721572
end;
15731573
end;
15741574

0 commit comments

Comments
 (0)