mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 20:50:20 +08:00
Fulfill rfe #692 "Add color-coding settings to data-appearance tab in preferences". Including new default color for ENUM fields and settings to enable/disable the grid editors.
This commit is contained in:
@ -183,6 +183,29 @@ const
|
||||
REGNAME_COPYTABLE_INDEXES = 'CopyTable_Option_WithIndexes';
|
||||
REGNAME_COPYTABLE_ALLFIELDS = 'CopyTable_Option_WithAllFields';
|
||||
|
||||
REGNAME_FIELDCOLOR_NUMERIC = 'FieldColor_Numeric';
|
||||
REGNAME_FIELDCOLOR_TEXT = 'FieldColor_Text';
|
||||
REGNAME_FIELDCOLOR_BINARY = 'FieldColor_Binary';
|
||||
REGNAME_FIELDCOLOR_DATETIME = 'FieldColor_Datetime';
|
||||
REGNAME_FIELDCOLOR_ENUM = 'FieldColor_Enum';
|
||||
DEFAULT_FIELDCOLOR_NUMERIC = $00FF0000; // clBlue
|
||||
DEFAULT_FIELDCOLOR_TEXT = $00008000; // clGreen
|
||||
DEFAULT_FIELDCOLOR_BINARY = $00800080; // clPurple
|
||||
DEFAULT_FIELDCOLOR_DATETIME = $00000080; // clMaroon
|
||||
DEFAULT_FIELDCOLOR_ENUM = $00008080; // clOlive
|
||||
COLORSHIFT_NULLFIELDS = 30; // Percentage of brightness to add to normal field colors for NULL values
|
||||
|
||||
REGNAME_FIELDEDITOR_NUMERIC = 'FieldEditor_Numeric';
|
||||
REGNAME_FIELDEDITOR_TEXT = 'FieldEditor_Text';
|
||||
REGNAME_FIELDEDITOR_BINARY = 'FieldEditor_Binary';
|
||||
REGNAME_FIELDEDITOR_DATETIME = 'FieldEditor_Datetime';
|
||||
REGNAME_FIELDEDITOR_ENUM = 'FieldEditor_Enum';
|
||||
DEFAULT_FIELDEDITOR_NUMERIC = True;
|
||||
DEFAULT_FIELDEDITOR_TEXT = True;
|
||||
DEFAULT_FIELDEDITOR_BINARY = True;
|
||||
DEFAULT_FIELDEDITOR_DATETIME = True;
|
||||
DEFAULT_FIELDEDITOR_ENUM = True;
|
||||
|
||||
REGPREFIX_COLWIDTHS = 'ColWidths_';
|
||||
REGPREFIX_COLSVISIBLE = 'ColsVisible_';
|
||||
REGPREFIX_COLPOS = 'ColPositions_';
|
||||
@ -229,7 +252,6 @@ const
|
||||
// Used by ListViews and Grids
|
||||
COLOR_SORTCOLUMN_ASC = $00F7F7F7; // light grey
|
||||
COLOR_SORTCOLUMN_DESC = $00EEEEEE; // medium grey
|
||||
COLOR_NULLVALUE = $00707070; // darker gray
|
||||
ORDER_ASC = 0; // Used for tag-value of "Direction"-button
|
||||
ORDER_DESC = 1; // dito
|
||||
TXT_ASC = 'ASC'; // Used for caption of "Direction"-button
|
||||
|
@ -514,7 +514,22 @@ type
|
||||
prefCSVEncloser,
|
||||
prefCSVTerminator : String[10];
|
||||
prefLogToFile,
|
||||
prefPreferShowTables : Boolean;
|
||||
prefPreferShowTables,
|
||||
prefEnableTextEditor,
|
||||
prefEnableBinaryEditor,
|
||||
prefEnableDatetimeEditor,
|
||||
prefEnableEnumEditor : Boolean;
|
||||
prefFieldColorNumeric,
|
||||
prefFieldColorText,
|
||||
prefFieldColorBinary,
|
||||
prefFieldColorDatetime,
|
||||
prefFieldColorEnum,
|
||||
prefNullColorNumeric,
|
||||
prefNullColorText,
|
||||
prefNullColorBinary,
|
||||
prefNullColorDatetime,
|
||||
prefNullColorEnum,
|
||||
prefNullColorDefault : TColor;
|
||||
CreateDatabaseForm : TCreateDatabaseForm;
|
||||
CreateTableForm : TCreateTableForm;
|
||||
TablePropertiesForm : Ttbl_properties_form;
|
||||
@ -572,6 +587,7 @@ type
|
||||
procedure DataGridCancelEdit(Sender: TObject);
|
||||
property FSelectedTableColumns: TDataset read GetSelTableColumns write FLastSelectedTableColumns;
|
||||
property FSelectedTableKeys: TDataset read GetSelTableKeys write FLastSelectedTableKeys;
|
||||
procedure CalcNullColors;
|
||||
end;
|
||||
|
||||
type
|
||||
@ -904,6 +920,18 @@ begin
|
||||
QueryGrid.Font.Size := datafontsize;
|
||||
FixVT(DataGrid);
|
||||
FixVT(QueryGrid);
|
||||
// Load color settings
|
||||
prefFieldColorNumeric := Mainform.GetRegValue(REGNAME_FIELDCOLOR_NUMERIC, DEFAULT_FIELDCOLOR_NUMERIC);
|
||||
prefFieldColorText := Mainform.GetRegValue(REGNAME_FIELDCOLOR_TEXT, DEFAULT_FIELDCOLOR_TEXT);
|
||||
prefFieldColorBinary := Mainform.GetRegValue(REGNAME_FIELDCOLOR_BINARY, DEFAULT_FIELDCOLOR_BINARY);
|
||||
prefFieldColorDatetime := Mainform.GetRegValue(REGNAME_FIELDCOLOR_DATETIME, DEFAULT_FIELDCOLOR_DATETIME);
|
||||
prefFieldColorEnum := Mainform.GetRegValue(REGNAME_FIELDCOLOR_ENUM, DEFAULT_FIELDCOLOR_ENUM);
|
||||
CalcNullColors;
|
||||
// Editor enablings
|
||||
prefEnableTextEditor := Mainform.GetRegValue(REGNAME_FIELDEDITOR_TEXT, DEFAULT_FIELDEDITOR_TEXT);
|
||||
prefEnableBinaryEditor := Mainform.GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY);
|
||||
prefEnableDatetimeEditor := Mainform.GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME);
|
||||
prefEnableEnumEditor := Mainform.GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM);
|
||||
|
||||
// Color coding:
|
||||
SynSQLSyn1.KeyAttri.Foreground := StringToColor(Mainform.GetRegValue(REGNAME_SQLCOLKEYATTRI, ColorToString(DEFAULT_SQLCOLKEYATTRI)));
|
||||
@ -5560,6 +5588,17 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TMDIChild.CalcNullColors;
|
||||
begin
|
||||
prefNullColorNumeric := ColorAdjustBrightness(prefFieldColorNumeric, COLORSHIFT_NULLFIELDS);
|
||||
prefNullColorText := ColorAdjustBrightness(prefFieldColorText, COLORSHIFT_NULLFIELDS);
|
||||
prefNullColorBinary := ColorAdjustBrightness(prefFieldColorBinary, COLORSHIFT_NULLFIELDS);
|
||||
prefNullColorDatetime := ColorAdjustBrightness(prefFieldColorDatetime, COLORSHIFT_NULLFIELDS);
|
||||
prefNullColorEnum := ColorAdjustBrightness(prefFieldColorEnum, COLORSHIFT_NULLFIELDS);
|
||||
prefNullColorDefault := ColorAdjustBrightness(clWindow, COLORSHIFT_NULLFIELDS);
|
||||
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.
|
||||
@ -5593,18 +5632,21 @@ begin
|
||||
isNull := r.Rows[Node.Index].Cells[Column].IsNull;
|
||||
// Numeric field
|
||||
if r.Columns[Column].isInt or r.Columns[Column].isFloat then
|
||||
if isNull then cl := $FF9090 else cl := clBlue
|
||||
if isNull then cl := prefNullColorNumeric else cl := prefFieldColorNumeric
|
||||
// Date field
|
||||
else if r.Columns[Column].isDate then
|
||||
if isNull then cl := $6060CC else cl := clMaroon
|
||||
if isNull then cl := prefNullColorDatetime else cl := prefFieldColorDatetime
|
||||
// Text field
|
||||
else if r.Columns[Column].isText then
|
||||
if isNull then cl := $60CC60 else cl := clGreen
|
||||
if isNull then cl := prefNullColorText else cl := prefFieldColorText
|
||||
// Text field
|
||||
else if r.Columns[Column].isBinary then
|
||||
if isNull then cl := $CC60CC else cl := clPurple
|
||||
if isNull then cl := prefNullColorBinary else cl := prefFieldColorBinary
|
||||
// Enum field
|
||||
else if r.Columns[Column].isEnum then
|
||||
if isNull then cl := prefNullColorEnum else cl := prefFieldColorEnum
|
||||
else
|
||||
if isNull then cl := COLOR_NULLVALUE else cl := clWindowText;
|
||||
if isNull then cl := prefNullColorDefault else cl := clWindowText;
|
||||
TargetCanvas.Font.Color := cl;
|
||||
end;
|
||||
|
||||
@ -6151,17 +6193,17 @@ var
|
||||
EnumEditor: TEnumEditorLink;
|
||||
begin
|
||||
if
|
||||
FDataGridResult.Columns[Column].IsText or
|
||||
FDataGridResult.Columns[Column].IsBinary
|
||||
(FDataGridResult.Columns[Column].IsText and prefEnableTextEditor) or
|
||||
(FDataGridResult.Columns[Column].IsBinary and prefEnableBinaryEditor)
|
||||
then begin
|
||||
MemoEditor := TMemoEditorLink.Create;
|
||||
MemoEditor.MaxLength := FDataGridResult.Columns[Column].MaxLength;
|
||||
EditLink := MemoEditor;
|
||||
end else if FDataGridResult.Columns[Column].IsDate then begin
|
||||
end else if FDataGridResult.Columns[Column].IsDate and prefEnableDatetimeEditor then begin
|
||||
DateTimeEditor := TDateTimeEditorLink.Create;
|
||||
DateTimeEditor.DataType := FDataGridResult.Columns[Column].DataType;
|
||||
EditLink := DateTimeEditor;
|
||||
end else if FDataGridResult.Columns[Column].IsEnum then begin
|
||||
end else if FDataGridResult.Columns[Column].IsEnum and prefEnableEnumEditor then begin
|
||||
EnumEditor := TEnumEditorLink.Create;
|
||||
EnumEditor.ValueList := FDataGridResult.Columns[Column].EnumVals;
|
||||
EditLink := EnumEditor;
|
||||
|
@ -169,6 +169,7 @@ type
|
||||
function BinToWideHex(bin: string): WideString;
|
||||
procedure CheckHex(text: WideString; errorMessage: string);
|
||||
procedure FixVT(VT: TVirtualStringTree);
|
||||
function ColorAdjustBrightness(Col: TColor; ShiftPercent: ShortInt): TColor;
|
||||
|
||||
var
|
||||
MYSQL_KEYWORDS : TStringList;
|
||||
@ -2652,6 +2653,28 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function ColorAdjustBrightness(Col: TColor; ShiftPercent: ShortInt): TColor;
|
||||
var
|
||||
r, g, b, ShiftBytes: SmallInt;
|
||||
begin
|
||||
// Split colors
|
||||
r := GetRValue(Col);
|
||||
g := GetGValue(Col);
|
||||
b := GetBValue(Col);
|
||||
// Convert percent value to bytes
|
||||
ShiftBytes := Round(ShiftPercent * 255 / 100);
|
||||
// Adjust single colors
|
||||
r := r + ShiftBytes;
|
||||
g := g + ShiftBytes;
|
||||
b := b + ShiftBytes;
|
||||
// Fix exceeded bounds
|
||||
if r > 255 then r := 255 else if r < 0 then r := 0;
|
||||
if g > 255 then g := 255 else if g < 0 then g := 0;
|
||||
if b > 255 then b := 255 else if b < 0 then b := 0;
|
||||
// Merge result
|
||||
Result := RGB(r, g, b);
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
|
||||
|
@ -511,6 +511,140 @@ object optionsform: Toptionsform
|
||||
Position = 8
|
||||
TabOrder = 5
|
||||
end
|
||||
object grpFieldLayout: TGroupBox
|
||||
Left = 8
|
||||
Top = 84
|
||||
Width = 391
|
||||
Height = 148
|
||||
Caption = 'Field colors and editors'
|
||||
TabOrder = 6
|
||||
object lblFieldDatetime: TLabel
|
||||
Left = 12
|
||||
Top = 96
|
||||
Width = 51
|
||||
Height = 13
|
||||
Caption = '&Date/time:'
|
||||
FocusControl = cboxDatetime
|
||||
end
|
||||
object lblFieldText: TLabel
|
||||
Left = 12
|
||||
Top = 48
|
||||
Width = 26
|
||||
Height = 13
|
||||
Caption = '&Text:'
|
||||
FocusControl = cboxText
|
||||
end
|
||||
object lblFieldBinary: TLabel
|
||||
Left = 12
|
||||
Top = 72
|
||||
Width = 34
|
||||
Height = 13
|
||||
Caption = '&Binary:'
|
||||
FocusControl = cboxBinary
|
||||
end
|
||||
object lblFieldNumeric: TLabel
|
||||
Left = 12
|
||||
Top = 24
|
||||
Width = 46
|
||||
Height = 13
|
||||
Caption = '&Numbers:'
|
||||
FocusControl = cboxNumeric
|
||||
end
|
||||
object lblFieldEnum: TLabel
|
||||
Left = 12
|
||||
Top = 120
|
||||
Width = 30
|
||||
Height = 13
|
||||
Caption = '&Enum:'
|
||||
FocusControl = cboxEnum
|
||||
end
|
||||
object cboxText: TColorBox
|
||||
Left = 100
|
||||
Top = 45
|
||||
Width = 120
|
||||
Height = 22
|
||||
Style = [cbStandardColors, cbExtendedColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
ItemHeight = 16
|
||||
TabOrder = 0
|
||||
OnChange = Modified
|
||||
end
|
||||
object chkEditorText: TCheckBox
|
||||
Left = 234
|
||||
Top = 47
|
||||
Width = 154
|
||||
Height = 17
|
||||
Caption = 'Enable popup text editor'
|
||||
TabOrder = 1
|
||||
OnClick = Modified
|
||||
end
|
||||
object cboxBinary: TColorBox
|
||||
Left = 100
|
||||
Top = 69
|
||||
Width = 120
|
||||
Height = 22
|
||||
Style = [cbStandardColors, cbExtendedColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
ItemHeight = 16
|
||||
TabOrder = 2
|
||||
OnChange = Modified
|
||||
end
|
||||
object cboxDatetime: TColorBox
|
||||
Left = 100
|
||||
Top = 93
|
||||
Width = 120
|
||||
Height = 22
|
||||
Style = [cbStandardColors, cbExtendedColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
ItemHeight = 16
|
||||
TabOrder = 3
|
||||
OnChange = Modified
|
||||
end
|
||||
object cboxNumeric: TColorBox
|
||||
Left = 100
|
||||
Top = 21
|
||||
Width = 120
|
||||
Height = 22
|
||||
Style = [cbStandardColors, cbExtendedColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
ItemHeight = 16
|
||||
TabOrder = 4
|
||||
OnChange = Modified
|
||||
end
|
||||
object cboxEnum: TColorBox
|
||||
Left = 100
|
||||
Top = 117
|
||||
Width = 120
|
||||
Height = 22
|
||||
Style = [cbStandardColors, cbExtendedColors, cbCustomColor, cbPrettyNames, cbCustomColors]
|
||||
ItemHeight = 16
|
||||
TabOrder = 5
|
||||
OnChange = Modified
|
||||
end
|
||||
object chkEditorBinary: TCheckBox
|
||||
Left = 234
|
||||
Top = 71
|
||||
Width = 154
|
||||
Height = 17
|
||||
Caption = 'Enable popup HEX editor'
|
||||
TabOrder = 6
|
||||
OnClick = Modified
|
||||
end
|
||||
object chkEditorDatetime: TCheckBox
|
||||
Left = 234
|
||||
Top = 96
|
||||
Width = 154
|
||||
Height = 17
|
||||
Caption = 'Enable calendar editor'
|
||||
TabOrder = 7
|
||||
OnClick = Modified
|
||||
end
|
||||
object chkEditorEnum: TCheckBox
|
||||
Left = 234
|
||||
Top = 120
|
||||
Width = 154
|
||||
Height = 17
|
||||
Caption = 'Enable pulldown editor'
|
||||
TabOrder = 8
|
||||
OnClick = Modified
|
||||
end
|
||||
end
|
||||
end
|
||||
object TabSheet5: TTabSheet
|
||||
BorderWidth = 5
|
||||
|
@ -87,6 +87,21 @@ type
|
||||
updownUpdatecheckInterval: TUpDown;
|
||||
chkPreferShowTables: TCheckBox;
|
||||
chkUpdateCheckBuilds: TCheckBox;
|
||||
grpFieldLayout: TGroupBox;
|
||||
lblFieldDatetime: TLabel;
|
||||
cboxText: TColorBox;
|
||||
chkEditorText: TCheckBox;
|
||||
lblFieldText: TLabel;
|
||||
lblFieldBinary: TLabel;
|
||||
lblFieldNumeric: TLabel;
|
||||
lblFieldEnum: TLabel;
|
||||
cboxBinary: TColorBox;
|
||||
cboxDatetime: TColorBox;
|
||||
cboxNumeric: TColorBox;
|
||||
cboxEnum: TColorBox;
|
||||
chkEditorBinary: TCheckBox;
|
||||
chkEditorDatetime: TCheckBox;
|
||||
chkEditorEnum: TCheckBox;
|
||||
procedure ButtonCancelClick(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
procedure Modified(Sender: TObject);
|
||||
@ -168,6 +183,17 @@ begin
|
||||
reg.WriteBool(REGNAME_DO_UPDATECHECK_BUILDS, chkUpdatecheckBuilds.Checked);
|
||||
reg.WriteInteger(REGNAME_UPDATECHECK_INTERVAL, updownUpdatecheckInterval.Position);
|
||||
reg.WriteBool(REGNAME_PREFER_SHOWTABLES, chkPreferShowTables.Checked);
|
||||
// Save color settings
|
||||
reg.WriteInteger(REGNAME_FIELDCOLOR_NUMERIC, cboxNumeric.Selected);
|
||||
reg.WriteInteger(REGNAME_FIELDCOLOR_TEXT, cboxText.Selected);
|
||||
reg.WriteInteger(REGNAME_FIELDCOLOR_BINARY, cboxBinary.Selected);
|
||||
reg.WriteInteger(REGNAME_FIELDCOLOR_DATETIME, cboxDatetime.Selected);
|
||||
reg.WriteInteger(REGNAME_FIELDCOLOR_ENUM, cboxEnum.Selected);
|
||||
// Editor enablings
|
||||
reg.WriteBool(REGNAME_FIELDEDITOR_TEXT, chkEditorText.Checked);
|
||||
reg.WriteBool(REGNAME_FIELDEDITOR_BINARY, chkEditorBinary.Checked);
|
||||
reg.WriteBool(REGNAME_FIELDEDITOR_DATETIME, chkEditorDatetime.Checked);
|
||||
reg.WriteBool(REGNAME_FIELDEDITOR_ENUM, chkEditorEnum.Checked);
|
||||
|
||||
// Clean registry from unwanted WHERE clauses if "Remember WHERE filters" was unchecked
|
||||
if not chkRememberFilters.Checked then begin
|
||||
@ -211,8 +237,6 @@ begin
|
||||
cwin.QueryGrid.Font.Name := self.comboDataFont.Text;
|
||||
cwin.DataGrid.Font.Size := self.udDataFontSize.Position;
|
||||
cwin.QueryGrid.Font.Size := self.udDataFontSize.Position;
|
||||
cwin.DataGrid.Repaint;
|
||||
cwin.QueryGrid.Repaint;
|
||||
FixVT(cwin.QueryGrid);
|
||||
FixVT(cwin.DataGrid);
|
||||
cwin.prefRememberFilters := chkRememberFilters.Checked;
|
||||
@ -229,6 +253,18 @@ begin
|
||||
cwin.prefCSVEncloser := self.Edit2.text;
|
||||
cwin.prefCSVTerminator := self.Edit3.text;
|
||||
cwin.prefPreferShowTables := chkPreferShowTables.Checked;
|
||||
cwin.prefFieldColorNumeric := cboxNumeric.Selected;
|
||||
cwin.prefFieldColorText := cboxText.Selected;
|
||||
cwin.prefFieldColorBinary := cboxBinary.Selected;
|
||||
cwin.prefFieldColorDatetime := cboxDatetime.Selected;
|
||||
cwin.prefFieldColorEnum := cboxEnum.Selected;
|
||||
cwin.CalcNullColors;
|
||||
cwin.DataGrid.Repaint;
|
||||
cwin.QueryGrid.Repaint;
|
||||
cwin.prefEnableTextEditor := chkEditorText.Checked;
|
||||
cwin.prefEnableBinaryEditor := chkEditorBinary.Checked;
|
||||
cwin.prefEnableDatetimeEditor := chkEditorDatetime.Checked;
|
||||
cwin.prefEnableEnumEditor := chkEditorEnum.Checked;
|
||||
end;
|
||||
|
||||
// Settings have been applied, send a signal to the user
|
||||
@ -322,6 +358,17 @@ begin
|
||||
ItemIndex := Items.IndexOf(datafontname);
|
||||
end;
|
||||
udDataFontSize.Position := datafontsize;
|
||||
// Load color settings
|
||||
cboxNumeric.Selected := Mainform.GetRegValue(REGNAME_FIELDCOLOR_NUMERIC, DEFAULT_FIELDCOLOR_NUMERIC);
|
||||
cboxText.Selected := Mainform.GetRegValue(REGNAME_FIELDCOLOR_TEXT, DEFAULT_FIELDCOLOR_TEXT);
|
||||
cboxBinary.Selected := Mainform.GetRegValue(REGNAME_FIELDCOLOR_BINARY, DEFAULT_FIELDCOLOR_BINARY);
|
||||
cboxDatetime.Selected := Mainform.GetRegValue(REGNAME_FIELDCOLOR_DATETIME, DEFAULT_FIELDCOLOR_DATETIME);
|
||||
cboxEnum.Selected := Mainform.GetRegValue(REGNAME_FIELDCOLOR_ENUM, DEFAULT_FIELDCOLOR_ENUM);
|
||||
// Editor enablings
|
||||
chkEditorText.Checked := Mainform.GetRegValue(REGNAME_FIELDEDITOR_TEXT, DEFAULT_FIELDEDITOR_TEXT);
|
||||
chkEditorBinary.Checked := Mainform.GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY);
|
||||
chkEditorDatetime.Checked := Mainform.GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME);
|
||||
chkEditorEnum.Checked := Mainform.GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM);
|
||||
|
||||
ButtonApply.Enabled := false;
|
||||
screen.Cursor := crdefault;
|
||||
|
Reference in New Issue
Block a user