diff --git a/components/sqlite/sqlite3laz.lpk b/components/sqlite/sqlite3laz.lpk index ff75d9da75..ff68cafc6f 100644 --- a/components/sqlite/sqlite3laz.lpk +++ b/components/sqlite/sqlite3laz.lpk @@ -1,25 +1,22 @@ - + - + - - - - - + @@ -43,7 +40,7 @@ - + diff --git a/components/sqlite/sqlitecomponenteditor.lfm b/components/sqlite/sqlitecomponenteditor.lfm index 437a02c3e7..5f8afe549c 100644 --- a/components/sqlite/sqlitecomponenteditor.lfm +++ b/components/sqlite/sqlitecomponenteditor.lfm @@ -1,120 +1,112 @@ object SqliteTableEditorForm: TSqliteTableEditorForm + Left = 373 + Height = 269 + Top = 244 + Width = 290 ActiveControl = butAdd Caption = 'Sqlite Table Editor' ClientHeight = 269 ClientWidth = 290 OnShow = SqliteTableEditorFormShow - PixelsPerInch = 83 - HorzScrollBar.Page = 289 - VertScrollBar.Page = 268 - Left = 373 - Height = 269 - Top = 244 - Width = 290 + LCLVersion = '0.9.27' object Label1: TLabel - Caption = 'Field Name' - Color = clNone - ParentColor = False Left = 147 - Height = 13 + Height = 14 Top = 64 - Width = 67 + Width = 53 + Caption = 'Field Name' + ParentColor = False end object Label2: TLabel - Caption = 'Field Type' - Color = clNone - ParentColor = False Left = 147 - Height = 13 + Height = 14 Top = 120 - Width = 59 + Width = 50 + Caption = 'Field Type' + ParentColor = False end object lblFilePath: TLabel - Caption = 'lblFilePath' - Color = clNone - ParentColor = False Left = 8 - Height = 13 + Height = 14 Top = 4 - Width = 61 + Width = 49 + Caption = 'lblFilePath' + ParentColor = False end object Label3: TLabel - Caption = 'Label3' - Color = clNone - ParentColor = False Left = 8 - Height = 13 + Height = 14 Top = 20 - Width = 40 + Width = 32 + Caption = 'Label3' + ParentColor = False end object listFields: TListBox - OnSelectionChange = listFieldsSelectionChange - TabOrder = 6 - TopIndex = -1 Left = 8 Height = 192 Top = 64 Width = 124 + ItemHeight = 0 + OnSelectionChange = listFieldsSelectionChange + TabOrder = 6 end object butCreate: TButton - - Caption = 'Create Table' - OnClick = butOkClick - TabOrder = 1 - TabStop = False Left = 147 Height = 25 Top = 192 Width = 136 + Caption = 'Create Table' + OnClick = butOkClick + TabOrder = 1 + TabStop = False end object butClose: TButton - - Caption = 'Close' - OnClick = butCancelClick - TabOrder = 2 - TabStop = False Left = 147 Height = 25 Top = 232 Width = 136 + Caption = 'Close' + OnClick = butCancelClick + TabOrder = 2 + TabStop = False end object editFieldName: TEdit - OnEditingDone = editFieldNameEditingDone - TabOrder = 4 Left = 147 Height = 23 Top = 80 Width = 136 + OnEditingDone = editFieldNameEditingDone + TabOrder = 4 end object comboFieldType: TComboBox - DropDownCount = 12 - MaxLength = 0 - OnChange = comboFieldTypeChange - Style = csDropDownList - TabOrder = 5 Left = 147 Height = 21 Top = 136 Width = 136 + AutoComplete = False + DropDownCount = 12 + ItemHeight = 13 + ItemWidth = 0 + OnChange = comboFieldTypeChange + Style = csDropDownList + TabOrder = 5 end object butAdd: TButton - - Caption = 'Add' - OnClick = butAddClick - TabOrder = 0 Left = 8 Height = 25 Top = 40 Width = 64 + Caption = 'Add' + OnClick = butAddClick + TabOrder = 0 end object butDelete: TButton - - Caption = 'Delete' - OnClick = butDeleteClick - TabOrder = 3 Left = 72 Height = 25 Top = 40 Width = 60 + Caption = 'Delete' + OnClick = butDeleteClick + TabOrder = 3 end end diff --git a/components/sqlite/sqlitecomponenteditor.lrs b/components/sqlite/sqlitecomponenteditor.lrs index 1a54c761c1..77ef3d68e4 100644 --- a/components/sqlite/sqlitecomponenteditor.lrs +++ b/components/sqlite/sqlitecomponenteditor.lrs @@ -1,31 +1,32 @@ +{ This is an automatically generated lazarus resource file } + LazarusResources.Add('TSqliteTableEditorForm','FORMDATA',[ - 'TPF0'#22'TSqliteTableEditorForm'#21'SqliteTableEditorForm'#13'ActiveControl' - +#7#6'butAdd'#7'Caption'#6#19'Sqlite Table Editor'#12'ClientHeight'#3#13#1#11 - +'ClientWidth'#3'"'#1#6'OnShow'#7#25'SqliteTableEditorFormShow'#13'PixelsPerI' - +'nch'#2'S'#18'HorzScrollBar.Page'#3'!'#1#18'VertScrollBar.Page'#3#12#1#4'Lef' - +'t'#3'u'#1#6'Height'#3#13#1#3'Top'#3#244#0#5'Width'#3'"'#1#0#6'TLabel'#6'Lab' - +'el1'#7'Caption'#6#10'Field Name'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'L' - +'eft'#3#147#0#6'Height'#2#13#3'Top'#2'@'#5'Width'#2'C'#0#0#6'TLabel'#6'Label' - +'2'#7'Caption'#6#10'Field Type'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'Lef' - +'t'#3#147#0#6'Height'#2#13#3'Top'#2'x'#5'Width'#2';'#0#0#6'TLabel'#11'lblFil' - +'ePath'#7'Caption'#6#11'lblFilePath'#5'Color'#7#6'clNone'#11'ParentColor'#8#4 - +'Left'#2#8#6'Height'#2#13#3'Top'#2#4#5'Width'#2'='#0#0#6'TLabel'#6'Label3'#7 - +'Caption'#6#6'Label3'#5'Color'#7#6'clNone'#11'ParentColor'#8#4'Left'#2#8#6'H' - +'eight'#2#13#3'Top'#2#20#5'Width'#2'('#0#0#8'TListBox'#10'listFields'#17'OnS' - +'electionChange'#7#25'listFieldsSelectionChange'#8'TabOrder'#2#6#8'TopIndex' - +#2#255#4'Left'#2#8#6'Height'#3#192#0#3'Top'#2'@'#5'Width'#2'|'#0#0#7'TButton' - +#9'butCreate'#7'Caption'#6#12'Create Table'#7'OnClick'#7#10'butOkClick'#8'Ta' - +'bOrder'#2#1#7'TabStop'#8#4'Left'#3#147#0#6'Height'#2#25#3'Top'#3#192#0#5'Wi' - +'dth'#3#136#0#0#0#7'TButton'#8'butClose'#7'Caption'#6#5'Close'#7'OnClick'#7 - +#14'butCancelClick'#8'TabOrder'#2#2#7'TabStop'#8#4'Left'#3#147#0#6'Height'#2 - +#25#3'Top'#3#232#0#5'Width'#3#136#0#0#0#5'TEdit'#13'editFieldName'#13'OnEdit' - +'ingDone'#7#24'editFieldNameEditingDone'#8'TabOrder'#2#4#4'Left'#3#147#0#6'H' - +'eight'#2#23#3'Top'#2'P'#5'Width'#3#136#0#0#0#9'TComboBox'#14'comboFieldType' - +#13'DropDownCount'#2#12#9'MaxLength'#2#0#8'OnChange'#7#20'comboFieldTypeChan' - +'ge'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#5#4'Left'#3#147#0#6'Height' - +#2#21#3'Top'#3#136#0#5'Width'#3#136#0#0#0#7'TButton'#6'butAdd'#7'Caption'#6#3 - +'Add'#7'OnClick'#7#11'butAddClick'#8'TabOrder'#2#0#4'Left'#2#8#6'Height'#2#25 - +#3'Top'#2'('#5'Width'#2'@'#0#0#7'TButton'#9'butDelete'#7'Caption'#6#6'Delete' - +#7'OnClick'#7#14'butDeleteClick'#8'TabOrder'#2#3#4'Left'#2'H'#6'Height'#2#25 - +#3'Top'#2'('#5'Width'#2'<'#0#0#0 + 'TPF0'#22'TSqliteTableEditorForm'#21'SqliteTableEditorForm'#4'Left'#3'u'#1#6 + +'Height'#3#13#1#3'Top'#3#244#0#5'Width'#3'"'#1#13'ActiveControl'#7#6'butAdd' + +#7'Caption'#6#19'Sqlite Table Editor'#12'ClientHeight'#3#13#1#11'ClientWidth' + +#3'"'#1#6'OnShow'#7#25'SqliteTableEditorFormShow'#10'LCLVersion'#6#6'0.9.27' + +#0#6'TLabel'#6'Label1'#4'Left'#3#147#0#6'Height'#2#14#3'Top'#2'@'#5'Width'#2 + +'5'#7'Caption'#6#10'Field Name'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4 + +'Left'#3#147#0#6'Height'#2#14#3'Top'#2'x'#5'Width'#2'2'#7'Caption'#6#10'Fiel' + +'d Type'#11'ParentColor'#8#0#0#6'TLabel'#11'lblFilePath'#4'Left'#2#8#6'Heigh' + +'t'#2#14#3'Top'#2#4#5'Width'#2'1'#7'Caption'#6#11'lblFilePath'#11'ParentColo' + +'r'#8#0#0#6'TLabel'#6'Label3'#4'Left'#2#8#6'Height'#2#14#3'Top'#2#20#5'Width' + +#2' '#7'Caption'#6#6'Label3'#11'ParentColor'#8#0#0#8'TListBox'#10'listFields' + +#4'Left'#2#8#6'Height'#3#192#0#3'Top'#2'@'#5'Width'#2'|'#10'ItemHeight'#2#0 + +#17'OnSelectionChange'#7#25'listFieldsSelectionChange'#8'TabOrder'#2#6#0#0#7 + +'TButton'#9'butCreate'#4'Left'#3#147#0#6'Height'#2#25#3'Top'#3#192#0#5'Width' + +#3#136#0#7'Caption'#6#12'Create Table'#7'OnClick'#7#10'butOkClick'#8'TabOrde' + +'r'#2#1#7'TabStop'#8#0#0#7'TButton'#8'butClose'#4'Left'#3#147#0#6'Height'#2 + +#25#3'Top'#3#232#0#5'Width'#3#136#0#7'Caption'#6#5'Close'#7'OnClick'#7#14'bu' + +'tCancelClick'#8'TabOrder'#2#2#7'TabStop'#8#0#0#5'TEdit'#13'editFieldName'#4 + +'Left'#3#147#0#6'Height'#2#23#3'Top'#2'P'#5'Width'#3#136#0#13'OnEditingDone' + +#7#24'editFieldNameEditingDone'#8'TabOrder'#2#4#0#0#9'TComboBox'#14'comboFie' + +'ldType'#4'Left'#3#147#0#6'Height'#2#21#3'Top'#3#136#0#5'Width'#3#136#0#12'A' + +'utoComplete'#8#13'DropDownCount'#2#12#10'ItemHeight'#2#13#9'ItemWidth'#2#0#8 + +'OnChange'#7#20'comboFieldTypeChange'#5'Style'#7#14'csDropDownList'#8'TabOrd' + +'er'#2#5#0#0#7'TButton'#6'butAdd'#4'Left'#2#8#6'Height'#2#25#3'Top'#2'('#5'W' + +'idth'#2'@'#7'Caption'#6#3'Add'#7'OnClick'#7#11'butAddClick'#8'TabOrder'#2#0 + +#0#0#7'TButton'#9'butDelete'#4'Left'#2'H'#6'Height'#2#25#3'Top'#2'('#5'Width' + +#2'<'#7'Caption'#6#6'Delete'#7'OnClick'#7#14'butDeleteClick'#8'TabOrder'#2#3 + +#0#0#0 ]); diff --git a/components/sqlite/sqlitecomponenteditor.pas b/components/sqlite/sqlitecomponenteditor.pas index c7ece474ff..c891b1e1ac 100644 --- a/components/sqlite/sqlitecomponenteditor.pas +++ b/components/sqlite/sqlitecomponenteditor.pas @@ -18,13 +18,16 @@ interface uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Dialogs, StdCtrls, - Buttons, customsqliteds, ComponentEditors, LazarusPackageIntf, LazIdeIntf; + Buttons, customsqliteds, ComponentEditors, LazarusPackageIntf, LazIdeIntf, + fieldseditor; type {TSqliteEditor} - TSqliteEditor = class(TComponentEditor) + TSqliteEditor = class(TFieldsComponentEditor) + private + FVerbOffset: Integer; public procedure ExecuteVerb(Index: Integer); override; function GetVerb(Index: Integer): string; override; @@ -69,9 +72,6 @@ implementation uses db; -var - IsAddingField:Boolean;//hack to avoid LCL bug 1428 - function StringListHasDuplicates(const List:TStrings):boolean; var i,j:Integer; @@ -90,33 +90,35 @@ end; procedure TSqliteEditor.ExecuteVerb(Index: Integer); begin - case Index of - 0:Edit; + case Index - FVerbOffset of + 0: Edit; + else + inherited ExecuteVerb(Index); end; end; function TSqliteEditor.GetVerb(Index: Integer): string; begin - case Index of + case Index - FVerbOffset of 0: begin - if not TCustomSqliteDataset(GetComponent).TableExists then - Result:='Create Table' - else - Result:='Edit Table'; + Result := 'Create/Edit Table' end; + else + Result := inherited GetVerb(Index); end; end; function TSqliteEditor.GetVerbCount: Integer; begin - Result:=1; + FVerbOffset := inherited GetVerbCount; + Result := FVerbOffset + 1; end; procedure TSqliteEditor.Edit; var ADataSet:TCustomSqliteDataSet; - OldDir:String; + OldDir, ProjectDir:String; begin ADataSet:=TCustomSqliteDataSet(GetComponent); if ADataSet.Filename = '' then @@ -135,10 +137,11 @@ begin try // In case Filename is a relative one, change dir to project dir // so the datafile will be created in the right place - OldDir:=GetCurrentDirUTF8; - if ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName) <> '' then - SetCurrentDirUTF8(ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName)); - Dataset:=ADataset; + OldDir := GetCurrentDirUTF8; + ProjectDir := ExtractFilePath (LazarusIDE.ActiveProject.MainFile.FileName); + if ProjectDir <> '' then + SetCurrentDirUTF8(ProjectDir); + Dataset := ADataset; ShowModal; finally SetCurrentDirUTF8(OldDir); @@ -154,9 +157,7 @@ begin //In the case there's no items editFieldName.Enabled:=True; comboFieldType.Enabled:=True; - IsAddingField:=True; //to be removed listFields.Items.AddObject('AFieldName',TObject(ftString)); - IsAddingField:=False; listFields.ItemIndex:=listFields.Items.Count-1; editFieldName.Text:='AFieldName'; editFieldName.SetFocus; @@ -208,7 +209,6 @@ procedure TSqliteTableEditorForm.SetComboValue(AObject: TObject); var AIndex:Integer; begin - //warning: using inline in this function causes a crash with fpc 2.0.0 AIndex:=comboFieldType.Items.IndexOfObject(AObject); if AIndex <> -1 then @@ -317,7 +317,7 @@ end; procedure TSqliteTableEditorForm.listFieldsSelectionChange(Sender: TObject; User: boolean); begin - if (listFields.ItemIndex <> -1) and not IsAddingField then //remove when LCL is fixed + if (listFields.ItemIndex <> -1) then begin editFieldName.Text:=listFields.Items[listFields.ItemIndex]; SetComboValue(listFields.Items.Objects[listFields.ItemIndex]); diff --git a/components/sqlite/sqlitelaz.lpk b/components/sqlite/sqlitelaz.lpk index 083f438132..a1ac93663f 100644 --- a/components/sqlite/sqlitelaz.lpk +++ b/components/sqlite/sqlitelaz.lpk @@ -12,9 +12,11 @@ - - - + + + @@ -43,7 +45,7 @@ - +