Introduce new preference option "Prefill empty date/time fields". Fixes issue #2708.

This commit is contained in:
Ansgar Becker
2012-02-27 22:36:48 +00:00
parent af3f590723
commit cedf5d888e
4 changed files with 39 additions and 12 deletions

View File

@ -270,10 +270,12 @@ const
REGNAME_FIELDEDITOR_BINARY = 'FieldEditor_Binary';
REGNAME_FIELDEDITOR_DATETIME = 'FieldEditor_Datetime';
REGNAME_PREFILL_DATETIME = 'FieldEditor_Datetime_Prefill';
REGNAME_FIELDEDITOR_ENUM = 'FieldEditor_Enum';
REGNAME_FIELDEDITOR_SET = 'FieldEditor_Set';
DEFAULT_FIELDEDITOR_BINARY = True;
DEFAULT_FIELDEDITOR_DATETIME = True;
DEFAULT_PREFILL_DATETIME = True;
DEFAULT_FIELDEDITOR_ENUM = True;
DEFAULT_FIELDEDITOR_SET = True;

View File

@ -942,6 +942,7 @@ type
prefLogDebug: Boolean;
prefEnableBinaryEditor: Boolean;
prefEnableDatetimeEditor: Boolean;
prefPrefillDateTime: Boolean;
prefEnableEnumEditor: Boolean;
prefEnableSetEditor: Boolean;
prefNullColorDefault: TColor;
@ -1546,6 +1547,7 @@ begin
// Editor enablings
prefEnableBinaryEditor := GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY);
prefEnableDatetimeEditor := GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME);
prefPrefillDateTime := GetRegValue(REGNAME_PREFILL_DATETIME, DEFAULT_PREFILL_DATETIME);
prefEnableEnumEditor := GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM);
prefEnableSetEditor := GetRegValue(REGNAME_FIELDEDITOR_SET, DEFAULT_FIELDEDITOR_SET);
@ -7642,7 +7644,7 @@ var
ForeignKey: TForeignKey;
TblColumn: TTableColumn;
idx: Integer;
KeyCol, TextCol, SQL, CreateTable: String;
KeyCol, TextCol, SQL, CreateTable, NowText: String;
Columns: TTableColumnList;
Keys: TTableKeyList;
ForeignKeys: TForeignKeyList;
@ -7720,6 +7722,15 @@ begin
HexEditor.MaxLength := Results.MaxLength(Column);
EditLink := HexEditor;
end else if (TypeCat = dtcTemporal) and prefEnableDatetimeEditor then begin
// Ensure date/time editor starts with a non-empty text value
if (Results.Col(Column) = '') and prefPrefillDateTime then begin
NowText := Conn.GetVar('SELECT NOW()');
case Results.DataType(Column).Index of
dtDate: NowText := Copy(NowText, 1, 10);
dtTime: NowText := Copy(NowText, 12, 8);
end;
VT.Text[Node, Column] := NowText;
end;
DateTimeEditor := TDateTimeEditorLink.Create(VT);
DateTimeEditor.DataType := Results.DataType(Column).Index;
EditLink := DateTimeEditor;

View File

@ -744,25 +744,35 @@ object optionsform: Toptionsform
OnClick = Modified
end
object chkEditorEnum: TCheckBox
Left = 8
Top = 210
Width = 433
Height = 17
Anchors = [akLeft, akTop, akRight]
Caption = 'Enable ENUM pulldown editor'
TabOrder = 14
OnClick = Modified
end
object chkEditorSet: TCheckBox
Left = 8
Top = 233
Width = 433
Height = 17
Anchors = [akLeft, akTop, akRight]
Caption = 'Enable SET checkbox editor'
Caption = 'Enable ENUM pulldown editor'
TabOrder = 15
OnClick = Modified
end
object chkEditorSet: TCheckBox
Left = 8
Top = 256
Width = 433
Height = 17
Anchors = [akLeft, akTop, akRight]
Caption = 'Enable SET checkbox editor'
TabOrder = 16
OnClick = Modified
end
object chkPrefillDateTime: TCheckBox
Left = 24
Top = 210
Width = 417
Height = 17
Anchors = [akLeft, akTop, akRight]
Caption = 'Prefill empty date/time fields with current date/time'
TabOrder = 14
OnClick = Modified
end
end
object tabShortcuts: TTabSheet
Caption = 'Shortcuts'

View File

@ -113,6 +113,7 @@ type
chkEditorDatetime: TCheckBox;
chkEditorEnum: TCheckBox;
chkEditorSet: TCheckBox;
chkPrefillDateTime: TCheckBox;
procedure FormShow(Sender: TObject);
procedure Modified(Sender: TObject);
procedure Apply(Sender: TObject);
@ -255,6 +256,7 @@ begin
// Editor enablings
MainReg.WriteBool(REGNAME_FIELDEDITOR_BINARY, chkEditorBinary.Checked);
MainReg.WriteBool(REGNAME_FIELDEDITOR_DATETIME, chkEditorDatetime.Checked);
MainReg.WriteBool(REGNAME_PREFILL_DATETIME, chkPrefillDatetime.Checked);
MainReg.WriteBool(REGNAME_FIELDEDITOR_ENUM, chkEditorEnum.Checked);
MainReg.WriteBool(REGNAME_FIELDEDITOR_SET, chkEditorSet.Checked);
@ -327,6 +329,7 @@ begin
Mainform.QueryGrid.Repaint;
Mainform.prefEnableBinaryEditor := chkEditorBinary.Checked;
Mainform.prefEnableDatetimeEditor := chkEditorDatetime.Checked;
Mainform.prefPrefillDateTime := chkPrefillDateTime.Checked;
Mainform.prefEnableEnumEditor := chkEditorEnum.Checked;
Mainform.prefEnableSetEditor := chkEditorSet.Checked;
Mainform.prefDisplayBars := chkColorBars.Checked;
@ -464,6 +467,7 @@ begin
// Editor enablings
chkEditorBinary.Checked := GetRegValue(REGNAME_FIELDEDITOR_BINARY, DEFAULT_FIELDEDITOR_BINARY);
chkEditorDatetime.Checked := GetRegValue(REGNAME_FIELDEDITOR_DATETIME, DEFAULT_FIELDEDITOR_DATETIME);
chkPrefillDateTime.Checked := GetRegValue(REGNAME_PREFILL_DATETIME, DEFAULT_PREFILL_DATETIME);
chkEditorEnum.Checked := GetRegValue(REGNAME_FIELDEDITOR_ENUM, DEFAULT_FIELDEDITOR_ENUM);
chkEditorSet.Checked := GetRegValue(REGNAME_FIELDEDITOR_SET, DEFAULT_FIELDEDITOR_SET);