mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Convert ComboboxKeys on the index-editor from a standard TCombobox to a TComboboxEx. Avoids/removes hackish code for drawing icons on items.
Also create some imageindexes constants to const.inc where they will be useful for other units.
This commit is contained in:
@ -41,3 +41,9 @@ const
|
|||||||
// this value should probably be user configurable
|
// this value should probably be user configurable
|
||||||
LOAD_SIZE = 5*1024*1024;
|
LOAD_SIZE = 5*1024*1024;
|
||||||
|
|
||||||
|
// Various iconindexes
|
||||||
|
ICONINDEX_PRIMARYKEY = 26;
|
||||||
|
ICONINDEX_INDEXKEY = 63;
|
||||||
|
ICONINDEX_UNIQUEKEY = 64;
|
||||||
|
ICONINDEX_FULLTEXTKEY = 65;
|
||||||
|
|
||||||
|
@ -191,16 +191,17 @@ object FieldEditForm: TFieldEditForm
|
|||||||
Height = 13
|
Height = 13
|
||||||
Caption = 'Available Columns:'
|
Caption = 'Available Columns:'
|
||||||
end
|
end
|
||||||
object ComboBoxKeys: TComboBox
|
object ComboBoxKeys: TComboBoxEx
|
||||||
Left = 72
|
Left = 72
|
||||||
Top = 8
|
Top = 8
|
||||||
Width = 209
|
Width = 209
|
||||||
Height = 22
|
Height = 22
|
||||||
Style = csOwnerDrawFixed
|
ItemsEx = <>
|
||||||
|
Style = csExDropDownList
|
||||||
ItemHeight = 16
|
ItemHeight = 16
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
OnChange = ComboBoxKeysChange
|
OnChange = ComboBoxKeysChange
|
||||||
OnDrawItem = ComboBoxKeysDrawItem
|
Images = MainForm.ImageList1
|
||||||
end
|
end
|
||||||
object CheckBoxUnique: TCheckBox
|
object CheckBoxUnique: TCheckBox
|
||||||
Left = 8
|
Left = 8
|
||||||
|
@ -35,7 +35,7 @@ type
|
|||||||
CheckBoxNotNull: TCheckBox;
|
CheckBoxNotNull: TCheckBox;
|
||||||
CheckBoxAutoIncrement: TCheckBox;
|
CheckBoxAutoIncrement: TCheckBox;
|
||||||
tabIndexes: TTabSheet;
|
tabIndexes: TTabSheet;
|
||||||
ComboBoxKeys: TComboBox;
|
ComboBoxKeys: TComboBoxEx;
|
||||||
lblIndexName: TLabel;
|
lblIndexName: TLabel;
|
||||||
CheckBoxUnique: TCheckBox;
|
CheckBoxUnique: TCheckBox;
|
||||||
ButtonAdd: TButton;
|
ButtonAdd: TButton;
|
||||||
@ -75,8 +75,6 @@ type
|
|||||||
procedure btnAddAllColumnsToIndexClick(Sender: TObject);
|
procedure btnAddAllColumnsToIndexClick(Sender: TObject);
|
||||||
procedure btnDeleteAllColumnsFromIndexClick(Sender: TObject);
|
procedure btnDeleteAllColumnsFromIndexClick(Sender: TObject);
|
||||||
procedure togglebuttons(Sender: TObject);
|
procedure togglebuttons(Sender: TObject);
|
||||||
procedure ComboBoxKeysDrawItem(Control: TWinControl; Index: Integer;
|
|
||||||
Rect: TRect; State: TOwnerDrawState);
|
|
||||||
private
|
private
|
||||||
{ Private declarations }
|
{ Private declarations }
|
||||||
TempKeys : TStringList;
|
TempKeys : TStringList;
|
||||||
@ -549,8 +547,8 @@ begin
|
|||||||
CheckBoxFulltext.OnClick := nil;
|
CheckBoxFulltext.OnClick := nil;
|
||||||
CheckBoxFulltext.Checked := Fulltext;
|
CheckBoxFulltext.Checked := Fulltext;
|
||||||
CheckBoxFulltext.OnClick := CheckBoxFulltextClick;
|
CheckBoxFulltext.OnClick := CheckBoxFulltextClick;
|
||||||
CheckBoxUnique.Enabled := not (ComboBoxKeys.Text = 'PRIMARY');
|
CheckBoxUnique.Enabled := not (ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].Caption = 'PRIMARY');
|
||||||
CheckBoxFulltext.Enabled := not (ComboBoxKeys.Text = 'PRIMARY');
|
CheckBoxFulltext.Enabled := not (ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].Caption = 'PRIMARY');
|
||||||
ButtonDelete.Enabled := true;
|
ButtonDelete.Enabled := true;
|
||||||
listColumnsUsed.Enabled := true;
|
listColumnsUsed.Enabled := true;
|
||||||
listColumnsAvailable.Enabled := true;
|
listColumnsAvailable.Enabled := true;
|
||||||
@ -593,7 +591,7 @@ var i,j : Integer;
|
|||||||
begin
|
begin
|
||||||
i := ComboBoxKeys.ItemIndex;
|
i := ComboBoxKeys.ItemIndex;
|
||||||
if i > -1 then
|
if i > -1 then
|
||||||
if MessageDlg('Delete Index ''' + ComboBoxKeys.Text + ''' ?',
|
if MessageDlg('Delete Index ''' + ComboBoxKeys.Items[ComboBoxKeys.ItemIndex] + ''' ?',
|
||||||
mtConfirmation, [mbYes,mbCancel], 0) = mrYes then begin
|
mtConfirmation, [mbYes,mbCancel], 0) = mrYes then begin
|
||||||
inc(i); // jump to next entry after the one to delete!
|
inc(i); // jump to next entry after the one to delete!
|
||||||
for j:=i to length(klist)-1 do
|
for j:=i to length(klist)-1 do
|
||||||
@ -628,9 +626,9 @@ end;
|
|||||||
}
|
}
|
||||||
procedure TFieldEditForm.ShowKeys(index: Integer=0);
|
procedure TFieldEditForm.ShowKeys(index: Integer=0);
|
||||||
var
|
var
|
||||||
i : Integer;
|
i, icon : Integer;
|
||||||
begin
|
begin
|
||||||
ComboBoxKeys.Items.Clear;
|
ComboBoxKeys.ItemsEx.Clear;
|
||||||
ButtonAddPrimary.Enabled := true;
|
ButtonAddPrimary.Enabled := true;
|
||||||
ButtonDelete.Enabled := false;
|
ButtonDelete.Enabled := false;
|
||||||
listColumnsUsed.Enabled := false;
|
listColumnsUsed.Enabled := false;
|
||||||
@ -638,7 +636,17 @@ begin
|
|||||||
btnAddColumnToIndex.Enabled := false;
|
btnAddColumnToIndex.Enabled := false;
|
||||||
btnDeleteColumnFromIndex.Enabled := false;
|
btnDeleteColumnFromIndex.Enabled := false;
|
||||||
for i:=0 to length(klist)-1 do
|
for i:=0 to length(klist)-1 do
|
||||||
ComboBoxKeys.Items.Add(klist[i].Name);
|
begin
|
||||||
|
if (klist[i].Unique) and (klist[i].Name <> 'PRIMARY') then
|
||||||
|
icon := ICONINDEX_UNIQUEKEY
|
||||||
|
else if klist[i].Fulltext then
|
||||||
|
icon := ICONINDEX_FULLTEXTKEY
|
||||||
|
else if klist[i].Name = 'PRIMARY' then
|
||||||
|
icon := ICONINDEX_PRIMARYKEY
|
||||||
|
else
|
||||||
|
icon := ICONINDEX_INDEXKEY;
|
||||||
|
ComboBoxKeys.ItemsEx.AddItem( klist[i].Name, icon, icon, -1, 0, nil);
|
||||||
|
end;
|
||||||
|
|
||||||
if ComboBoxKeys.Items.IndexOf('PRIMARY') > -1 then
|
if ComboBoxKeys.Items.IndexOf('PRIMARY') > -1 then
|
||||||
ButtonAddPrimary.Enabled := false;
|
ButtonAddPrimary.Enabled := false;
|
||||||
@ -671,6 +679,12 @@ begin
|
|||||||
if CheckBoxUnique.Checked then begin
|
if CheckBoxUnique.Checked then begin
|
||||||
klist[ComboBoxKeys.ItemIndex].Fulltext := false;
|
klist[ComboBoxKeys.ItemIndex].Fulltext := false;
|
||||||
CheckBoxFulltext.Checked := false;
|
CheckBoxFulltext.Checked := false;
|
||||||
|
ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].ImageIndex := ICONINDEX_UNIQUEKEY;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Not unique, not fulltext
|
||||||
|
ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].ImageIndex := ICONINDEX_INDEXKEY;
|
||||||
end;
|
end;
|
||||||
klist[ComboBoxKeys.ItemIndex].Modified := true;
|
klist[ComboBoxKeys.ItemIndex].Modified := true;
|
||||||
end;
|
end;
|
||||||
@ -686,6 +700,12 @@ begin
|
|||||||
if CheckBoxFulltext.Checked then begin
|
if CheckBoxFulltext.Checked then begin
|
||||||
klist[ComboBoxKeys.ItemIndex].Unique := false;
|
klist[ComboBoxKeys.ItemIndex].Unique := false;
|
||||||
CheckBoxUnique.Checked := false;
|
CheckBoxUnique.Checked := false;
|
||||||
|
ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].ImageIndex := ICONINDEX_FULLTEXTKEY;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Not unique, not fulltext
|
||||||
|
ComboBoxKeys.ItemsEx[ComboBoxKeys.ItemIndex].ImageIndex := ICONINDEX_INDEXKEY;
|
||||||
end;
|
end;
|
||||||
klist[ComboBoxKeys.ItemIndex].Modified := true;
|
klist[ComboBoxKeys.ItemIndex].Modified := true;
|
||||||
end;
|
end;
|
||||||
@ -907,37 +927,6 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
{***
|
|
||||||
Add square-icon to index-names in combobox
|
|
||||||
@todo: use Delphi's built-in TComboBox with icon-support
|
|
||||||
}
|
|
||||||
procedure TFieldEditForm.ComboBoxKeysDrawItem(Control: TWinControl;
|
|
||||||
Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
|
||||||
var
|
|
||||||
icon : Integer;
|
|
||||||
c : tComboBox;
|
|
||||||
begin
|
|
||||||
c := (Control as TComboBox);
|
|
||||||
with c.Canvas do
|
|
||||||
begin
|
|
||||||
Brush.Color := clWindow;
|
|
||||||
FillRect(rect);
|
|
||||||
if (klist[index].Unique) and (klist[index].Name <> 'PRIMARY') then
|
|
||||||
icon := 64
|
|
||||||
else if klist[index].Fulltext then
|
|
||||||
icon := 65
|
|
||||||
else if klist[index].Name = 'PRIMARY' then
|
|
||||||
icon := 26
|
|
||||||
else
|
|
||||||
icon := 63;
|
|
||||||
Mainform.ImageList1.Draw(c.canvas, Rect.Left, Rect.Top, Icon);
|
|
||||||
Font.Color := clWindowText;
|
|
||||||
TextOut(Rect.Left + 18, Rect.Top, c.Items[Index]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{***
|
{***
|
||||||
Call SQL help for selected datatype
|
Call SQL help for selected datatype
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user