diff --git a/.gitattributes b/.gitattributes index 720d595a7a..2fa130261b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3707,6 +3707,7 @@ ideintf/checklistboxeditordlg.lrs svneol=native#text/pascal ideintf/checklistboxeditordlg.pas svneol=native#text/plain ideintf/collectionpropeditform.lfm svneol=native#text/plain ideintf/collectionpropeditform.lrs svneol=native#text/pascal +ideintf/collectionpropeditform.pas svneol=native#text/plain ideintf/columndlg.pp svneol=native#text/pascal ideintf/componenteditors.pas svneol=native#text/pascal ideintf/componentreg.pas svneol=native#text/pascal diff --git a/ideintf/allideintf.pas b/ideintf/allideintf.pas index ca9a642656..f31ae894ca 100644 --- a/ideintf/allideintf.pas +++ b/ideintf/allideintf.pas @@ -23,6 +23,7 @@ uses ActionsEditor, ActionsEditorStd, BaseIDEIntf, + CollectionPropEditForm, ComponentEditors, ComponentReg, ComponentTreeView, diff --git a/ideintf/collectionpropeditform.lfm b/ideintf/collectionpropeditform.lfm index b2e793b54d..e12cd18b20 100644 --- a/ideintf/collectionpropeditform.lfm +++ b/ideintf/collectionpropeditform.lfm @@ -1,4 +1,10 @@ object CollectionPropertyEditorForm: TCollectionPropertyEditorForm + Left = 220 + Height = 300 + Top = 220 + Width = 190 + HorzScrollBar.Page = 189 + VertScrollBar.Page = 299 ActiveControl = CollectionListBox BorderStyle = bsSizeToolWin Caption = 'CollectionPropertyEditorForm' @@ -8,72 +14,59 @@ object CollectionPropertyEditorForm: TCollectionPropertyEditorForm Constraints.MinWidth = 190 OnCreate = FormCreate OnDestroy = FormDestroy - PixelsPerInch = 96 Position = poDefaultPosOnly - HorzScrollBar.Page = 189 - VertScrollBar.Page = 299 - Left = 290 - Height = 300 - Top = 153 - Width = 190 + LCLVersion = '0.9.29' object ToolBar1: TToolBar + Left = 0 + Height = 42 + Top = 0 + Width = 190 AutoSize = True ButtonHeight = 40 ButtonWidth = 44 Caption = 'ToolBar1' - Flat = True - Height = 42 ShowCaptions = True TabOrder = 0 - Height = 42 - Width = 190 object AddButton: TToolButton + Left = 1 + Top = 2 Caption = 'Add' OnClick = AddButtonClick - Height = 40 - Top = 2 - Width = 44 end object DeleteButton: TToolButton + Left = 45 + Top = 2 Caption = 'Delete' OnClick = DeleteButtonClick - Left = 45 - Height = 40 - Top = 2 - Width = 44 end object ToolButton3: TToolButton + Left = 89 + Top = 2 + Width = 10 Caption = 'ToolButton3' Style = tbsSeparator - Width = 10 - Left = 89 - Height = 40 - Top = 2 - Width = 10 end object MoveUpButton: TToolButton + Left = 99 + Top = 2 Caption = 'Up' OnClick = MoveUpButtonClick - Left = 99 - Height = 40 - Top = 2 - Width = 44 end object MoveDownButton: TToolButton + Left = 143 + Top = 2 Caption = 'Down' OnClick = MoveDownButtonClick - Left = 143 - Height = 40 - Top = 2 - Width = 44 end end object CollectionListBox: TListBox - Align = alClient - OnClick = CollectionListBoxClick - TabOrder = 1 + Left = 0 Height = 258 Top = 42 Width = 190 + Align = alClient + ItemHeight = 0 + OnClick = CollectionListBoxClick + TabOrder = 1 end end diff --git a/ideintf/collectionpropeditform.lrs b/ideintf/collectionpropeditform.lrs index 935f797216..c829c28d20 100644 --- a/ideintf/collectionpropeditform.lrs +++ b/ideintf/collectionpropeditform.lrs @@ -1,24 +1,25 @@ +{ This is an automatically generated lazarus resource file } + LazarusResources.Add('TCollectionPropertyEditorForm','FORMDATA',[ - 'TPF0'#29'TCollectionPropertyEditorForm'#28'CollectionPropertyEditorForm'#13 - +'ActiveControl'#7#17'CollectionListBox'#11'BorderStyle'#7#13'bsSizeToolWin'#7 - +'Caption'#6#28'CollectionPropertyEditorForm'#12'ClientHeight'#3','#1#11'Clie' - +'ntWidth'#3#190#0#21'Constraints.MinHeight'#2'd'#20'Constraints.MinWidth'#3 - +#190#0#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#13'Pixels' - +'PerInch'#2'`'#8'Position'#7#16'poDefaultPosOnly'#18'HorzScrollBar.Page'#3 - +#189#0#18'VertScrollBar.Page'#3'+'#1#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3 - +#153#0#5'Width'#3#190#0#0#8'TToolBar'#8'ToolBar1'#8'AutoSize'#9#12'ButtonHei' - +'ght'#2'('#11'ButtonWidth'#2','#7'Caption'#6#8'ToolBar1'#4'Flat'#9#6'Height' - +#2'*'#12'ShowCaptions'#9#8'TabOrder'#2#0#6'Height'#2'*'#5'Width'#3#190#0#0#11 - +'TToolButton'#9'AddButton'#7'Caption'#6#3'Add'#7'OnClick'#7#14'AddButtonClic' - +'k'#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#12'DeleteBut' - +'ton'#7'Caption'#6#6'Delete'#7'OnClick'#7#17'DeleteButtonClick'#4'Left'#2'-' - +#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#11'ToolButton3' - +#7'Caption'#6#11'ToolButton3'#5'Style'#7#12'tbsSeparator'#5'Width'#2#10#4'Le' - +'ft'#2'Y'#6'Height'#2'('#3'Top'#2#2#5'Width'#2#10#0#0#11'TToolButton'#12'Mov' - +'eUpButton'#7'Caption'#6#2'Up'#7'OnClick'#7#17'MoveUpButtonClick'#4'Left'#2 - +'c'#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#14'MoveDownB' - +'utton'#7'Caption'#6#4'Down'#7'OnClick'#7#19'MoveDownButtonClick'#4'Left'#3 - +#143#0#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#0#8'TListBox'#17'Collecti' - +'onListBox'#5'Align'#7#8'alClient'#7'OnClick'#7#22'CollectionListBoxClick'#8 - +'TabOrder'#2#1#6'Height'#3#2#1#3'Top'#2'*'#5'Width'#3#190#0#0#0#0 + 'TPF0'#29'TCollectionPropertyEditorForm'#28'CollectionPropertyEditorForm'#4'L' + +'eft'#3#220#0#6'Height'#3','#1#3'Top'#3#220#0#5'Width'#3#190#0#18'HorzScroll' + +'Bar.Page'#3#189#0#18'VertScrollBar.Page'#3'+'#1#13'ActiveControl'#7#17'Coll' + +'ectionListBox'#11'BorderStyle'#7#13'bsSizeToolWin'#7'Caption'#6#28'Collecti' + +'onPropertyEditorForm'#12'ClientHeight'#3','#1#11'ClientWidth'#3#190#0#21'Co' + +'nstraints.MinHeight'#2'd'#20'Constraints.MinWidth'#3#190#0#8'OnCreate'#7#10 + +'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#8'Position'#7#16'poDefaultPosOnl' + +'y'#10'LCLVersion'#6#6'0.9.29'#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Heigh' + +'t'#2'*'#3'Top'#2#0#5'Width'#3#190#0#8'AutoSize'#9#12'ButtonHeight'#2'('#11 + +'ButtonWidth'#2','#7'Caption'#6#8'ToolBar1'#12'ShowCaptions'#9#8'TabOrder'#2 + +#0#0#11'TToolButton'#9'AddButton'#4'Left'#2#1#3'Top'#2#2#7'Caption'#6#3'Add' + +#7'OnClick'#7#14'AddButtonClick'#0#0#11'TToolButton'#12'DeleteButton'#4'Left' + +#2'-'#3'Top'#2#2#7'Caption'#6#6'Delete'#7'OnClick'#7#17'DeleteButtonClick'#0 + +#0#11'TToolButton'#11'ToolButton3'#4'Left'#2'Y'#3'Top'#2#2#5'Width'#2#10#7'C' + +'aption'#6#11'ToolButton3'#5'Style'#7#12'tbsSeparator'#0#0#11'TToolButton'#12 + +'MoveUpButton'#4'Left'#2'c'#3'Top'#2#2#7'Caption'#6#2'Up'#7'OnClick'#7#17'Mo' + +'veUpButtonClick'#0#0#11'TToolButton'#14'MoveDownButton'#4'Left'#3#143#0#3'T' + +'op'#2#2#7'Caption'#6#4'Down'#7'OnClick'#7#19'MoveDownButtonClick'#0#0#0#8'T' + +'ListBox'#17'CollectionListBox'#4'Left'#2#0#6'Height'#3#2#1#3'Top'#2'*'#5'Wi' + +'dth'#3#190#0#5'Align'#7#8'alClient'#10'ItemHeight'#2#0#7'OnClick'#7#22'Coll' + +'ectionListBoxClick'#8'TabOrder'#2#1#0#0#0 ]); diff --git a/ideintf/collectionpropeditform.pas b/ideintf/collectionpropeditform.pas new file mode 100644 index 0000000000..10efb2b833 --- /dev/null +++ b/ideintf/collectionpropeditform.pas @@ -0,0 +1,340 @@ +unit CollectionPropEditForm; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, ComCtrls, StdCtrls; + +type + { TCollectionPropertyEditor } + + TCollectionPropertyEditorForm = class(TForm) + CollectionListBox: TListBox; + ToolBar1: TToolBar; + AddButton: TToolButton; + DeleteButton: TToolButton; + ToolButton3: TToolButton; + MoveUpButton: TToolButton; + MoveDownButton: TToolButton; + procedure AddButtonClick(Sender: TObject); + procedure CollectionListBoxClick(Sender: TObject); + procedure DeleteButtonClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormDestroy(Sender: TObject); + procedure MoveDownButtonClick(Sender: TObject); + procedure MoveUpButtonClick(Sender: TObject); + private + FCollection: TCollection; + FOwnerPersistent: TPersistent; + FPropertyName: String; + protected + procedure UpdateCaption; + procedure UpdateButtons; + procedure ComponentRenamed(AComponent: TComponent); + procedure PersistentDeleting(APersistent: TPersistent); + procedure RefreshPropertyValues; + public + procedure FillCollectionListBox; + procedure SelectInObjectInspector(UnselectAll: Boolean); + procedure SetCollection(NewCollection: TCollection; + NewOwnerPersistent: TPersistent; const NewPropName: String); + procedure Modified; + public + property Collection: TCollection read FCollection; + property OwnerPersistent: TPersistent read FOwnerPersistent; + property PropertyName: String read FPropertyName; + end; + +implementation + +uses + Controls, Dialogs, IDEImagesIntf, LResources, ObjInspStrConsts, PropEdits; + +procedure TCollectionPropertyEditorForm.FormCreate(Sender: TObject); +begin + ToolBar1.Images := IDEImages.Images_16; + AddButton.Caption := oiColEditAdd; + DeleteButton.Caption := oiColEditDelete; + MoveUpButton.Caption := oiColEditUp; + MoveDownButton.Caption := oiColEditDown; + AddButton.ImageIndex := IDEImages.LoadImage(16, 'laz_add'); + DeleteButton.ImageIndex := IDEImages.LoadImage(16, 'laz_delete'); + MoveUpButton.ImageIndex := IDEImages.LoadImage(16, 'arrow_up'); + MoveDownButton.ImageIndex := IDEImages.LoadImage(16, 'arrow_down'); +end; + +procedure TCollectionPropertyEditorForm.FormDestroy(Sender: TObject); +begin + if GlobalDesignHook <> nil then + GlobalDesignHook.RemoveAllHandlersForObject(Self); +end; + +procedure TCollectionPropertyEditorForm.MoveDownButtonClick(Sender: TObject); +var + I: Integer; +begin + if Collection = nil then Exit; + + I := CollectionListBox.ItemIndex; + if I >= Collection.Count - 1 then Exit; + + Collection.Items[I].Index := I + 1; + CollectionListBox.ItemIndex := I + 1; + + FillCollectionListBox; + SelectInObjectInspector(False); + Modified; +end; + +procedure TCollectionPropertyEditorForm.MoveUpButtonClick(Sender: TObject); +var + I: Integer; +begin + if Collection = nil then Exit; + + I := CollectionListBox.ItemIndex; + if I < 0 then Exit; + + Collection.Items[I].Index := I - 1; + CollectionListBox.ItemIndex := I - 1; + + FillCollectionListBox; + SelectInObjectInspector(False); + Modified; +end; + +procedure TCollectionPropertyEditorForm.AddButtonClick(Sender: TObject); +begin + if Collection = nil then Exit; + Collection.Add; + + FillCollectionListBox; + if CollectionListBox.Items.Count > 0 then + CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1; + SelectInObjectInspector(False); + UpdateButtons; + UpdateCaption; + Modified; +end; + +procedure TCollectionPropertyEditorForm.CollectionListBoxClick(Sender: TObject); +begin + UpdateButtons; + UpdateCaption; + SelectInObjectInspector(False); +end; + +procedure TCollectionPropertyEditorForm.DeleteButtonClick(Sender: TObject); +var + I : Integer; + NewItemIndex: Integer; +begin + if Collection = nil then Exit; + + I := CollectionListBox.ItemIndex; + if (I >= 0) and (I < Collection.Count) then + begin + if MessageDlg(oisConfirmDelete, + Format(oisDeleteItem, ['"', Collection.Items[I].DisplayName, '"']), + mtConfirmation, [mbYes, mbNo], 0) = mrYes then + begin + // select other item, or unselect + NewItemIndex := I + 1; + while (NewItemIndex < CollectionListBox.Items.Count) + and (CollectionListBox.Selected[NewItemIndex]) do Inc(NewItemIndex); + + if NewItemIndex = CollectionListBox.Items.Count then + begin + NewItemIndex := 0; + while (NewItemIndex < Pred(I)) + and not (CollectionListBox.Selected[NewItemIndex]) do Inc(NewItemIndex); + + if NewItemIndex = I then NewItemIndex := -1; + end; + + CollectionListBox.ItemIndex := -1; + + if NewItemIndex > I then Dec(NewItemIndex); + //debugln('TCollectionPropertyEditorForm.DeleteClick A NewItemIndex=',dbgs(NewItemIndex),' ItemIndex=',dbgs(CollectionListBox.ItemIndex),' CollectionListBox.Items.Count=',dbgs(CollectionListBox.Items.Count),' Collection.Count=',dbgs(Collection.Count)); + // unselect all items in OI (collections can act strange on delete) + SelectInObjectInspector(True); + // now delete + Collection.Items[I].Free; + // update listbox after whatever happened + FillCollectionListBox; + // set NewItemIndex + if NewItemIndex < CollectionListBox.Items.Count then + begin + CollectionListBox.ItemIndex := NewItemIndex; + SelectInObjectInspector(False); + end; + //debugln('TCollectionPropertyEditorForm.DeleteClick B'); + Modified; + end; + end; + UpdateButtons; + UpdateCaption; +end; + +procedure TCollectionPropertyEditorForm.UpdateCaption; +var + NewCaption: String; +begin + //I think to match Delphi this should be formatted like + //"Editing ComponentName.PropertyName[Index]" + if OwnerPersistent is TComponent then + NewCaption := TComponent(OwnerPersistent).Name + else + if OwnerPersistent <> nil then + NewCaption := OwnerPersistent.GetNamePath + else + NewCaption := ''; + + if NewCaption <> '' then NewCaption := NewCaption + '.'; + NewCaption := oiColEditEditing + ' ' + NewCaption + PropertyName; + + if CollectionListBox.ItemIndex > -1 then + NewCaption := NewCaption + '[' + IntToStr(CollectionListBox.ItemIndex) + ']'; + Caption := NewCaption; +end; + +procedure TCollectionPropertyEditorForm.UpdateButtons; +var + I: Integer; +begin + I := CollectionListBox.ItemIndex; + AddButton.Enabled := Collection <> nil; + DeleteButton.Enabled := I > -1; + MoveUpButton.Enabled := I > 0; + MoveDownButton.Enabled := (I >= 0) and (I < Collection.Count - 1); +end; + +procedure TCollectionPropertyEditorForm.ComponentRenamed(AComponent: TComponent); +begin + if AComponent = OwnerPersistent then UpdateCaption; +end; + +procedure TCollectionPropertyEditorForm.PersistentDeleting(APersistent: TPersistent); +var + OldCollection: TCollection; +begin + //debugln('TCollectionPropertyEditorForm.PersistentDeleting A APersistent=',dbgsName(APersistent),' OwnerPersistent=',dbgsName(OwnerPersistent)); + if APersistent = OwnerPersistent then + begin + OldCollection := Collection; + SetCollection(nil, nil, ''); + GlobalDesignHook.Unselect(OldCollection); + if GlobalDesignHook.LookupRoot = OldCollection then + GlobalDesignHook.LookupRoot := nil; + + Hide; + end; +end; + +procedure TCollectionPropertyEditorForm.RefreshPropertyValues; +begin + FillCollectionListBox; +end; + +procedure TCollectionPropertyEditorForm.FillCollectionListBox; +var + I: Integer; + CurItem: String; + Cnt: Integer; +begin + CollectionListBox.Items.BeginUpdate; + try + if Collection <> nil then Cnt := Collection.Count + else Cnt := 0; + + // add or replace list items + for I := 0 to Cnt - 1 do + begin + CurItem := IntToStr(I) + ' - ' + Collection.Items[I].DisplayName; + if I >= CollectionListBox.Items.Count then + CollectionListBox.Items.Add(CurItem) + else + CollectionListBox.Items[I] := CurItem; + end; + + // delete unneeded list items + if Cnt > 0 then + begin + while CollectionListBox.Items.Count > Cnt do + begin + CollectionListBox.Items.Delete(CollectionListBox.Items.Count - 1); + end; + end + else + begin + CollectionListBox.Items.Clear; + end; + finally + CollectionListBox.Items.EndUpdate; + UpdateButtons; + UpdateCaption; + end; +end; + +procedure TCollectionPropertyEditorForm.SelectInObjectInspector(UnselectAll: Boolean); +var + I: Integer; + NewSelection: TPersistentSelectionList; +begin + if Collection = nil then Exit; + // select in OI + NewSelection := TPersistentSelectionList.Create; + try + if not UnselectAll then + begin + for I := 0 to CollectionListBox.Items.Count - 1 do + if CollectionListBox.Selected[I] then + NewSelection.Add(Collection.Items[I]); + end; + GlobalDesignHook.SetSelection(NewSelection); + GlobalDesignHook.LookupRoot := GetLookupRootForComponent(OwnerPersistent); + finally + NewSelection.Free; + end; +end; + +procedure TCollectionPropertyEditorForm.SetCollection(NewCollection: TCollection; + NewOwnerPersistent: TPersistent; const NewPropName: String); +begin + if (FCollection = NewCollection) and (FOwnerPersistent = NewOwnerPersistent) + and (FPropertyName = NewPropName) then Exit; + + FCollection := NewCollection; + FOwnerPersistent := NewOwnerPersistent; + FPropertyName := NewPropName; + //debugln('TCollectionPropertyEditorForm.SetCollection A Collection=',dbgsName(FCollection),' OwnerPersistent=',dbgsName(OwnerPersistent),' PropName=',PropertyName); + if GlobalDesignHook <> nil then + begin + if FOwnerPersistent <> nil then + begin + GlobalDesignHook.AddHandlerComponentRenamed(@ComponentRenamed); + GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting); + GlobalDesignHook.AddHandlerRefreshPropertyValues(@RefreshPropertyValues); + end + else + begin + GlobalDesignHook.RemoveAllHandlersForObject(Self); + end; + end; + + FillCollectionListBox; + UpdateCaption; +end; + +procedure TCollectionPropertyEditorForm.Modified; +begin + GlobalDesignHook.Modified(Self); +end; + +initialization +{$I collectionpropeditform.lrs} + +end. + diff --git a/ideintf/propedits.pp b/ideintf/propedits.pp index 070595a6e2..6f4f44c324 100644 --- a/ideintf/propedits.pp +++ b/ideintf/propedits.pp @@ -33,12 +33,13 @@ unit PropEdits; interface uses - Classes, TypInfo, SysUtils, LResources, + Classes, TypInfo, SysUtils, FPCAdds, // for StrToQWord in older fpc versions LCLProc, Forms, Controls, GraphType, StringHashList, ButtonPanel, - Graphics, StdCtrls, Buttons, ComCtrls, Menus, LCLType, ExtCtrls, LCLIntf, + Graphics, StdCtrls, Buttons, Menus, LCLType, ExtCtrls, LCLIntf, Dialogs, Grids, EditBtn, PropertyStorage, TextTools, FrmSelectProps, - StringsPropEditDlg, ColumnDlg, FileUtil, ObjInspStrConsts, IDEImagesIntf; + StringsPropEditDlg, ColumnDlg, FileUtil, ObjInspStrConsts, + CollectionPropEditForm; const MaxIdentLength: Byte = 63; @@ -3695,330 +3696,9 @@ begin end; -type - { TCollectionPropertyEditor } - - TCollectionPropertyEditorForm = class(TForm) - CollectionListBox: TListBox; - ToolBar1: TToolBar; - AddButton: TToolButton; - DeleteButton: TToolButton; - ToolButton3: TToolButton; - MoveUpButton: TToolButton; - MoveDownButton: TToolButton; - procedure AddButtonClick(Sender: TObject); - procedure CollectionListBoxClick(Sender: TObject); - procedure DeleteButtonClick(Sender: TObject); - procedure FormCreate(Sender: TObject); - procedure FormDestroy(Sender: TObject); - procedure MoveDownButtonClick(Sender: TObject); - procedure MoveUpButtonClick(Sender: TObject); - private - FCollection: TCollection; - FOwnerPersistent: TPersistent; - FPropertyName: String; - protected - procedure UpdateCaption; - procedure UpdateButtons; - procedure ComponentRenamed(AComponent: TComponent); - procedure PersistentDeleting(APersistent: TPersistent); - procedure RefreshPropertyValues; - public - procedure FillCollectionListBox; - procedure SelectInObjectInspector(UnselectAll: Boolean); - procedure SetCollection(NewCollection: TCollection; - NewOwnerPersistent: TPersistent; const NewPropName: String); - procedure Modified; - public - property Collection: TCollection read FCollection; - property OwnerPersistent: TPersistent read FOwnerPersistent; - property PropertyName: String read FPropertyName; - end; - const CollectionForm: TCollectionPropertyEditorForm = nil; -procedure TCollectionPropertyEditorForm.FormCreate(Sender: TObject); -begin - ToolBar1.Images := IDEImages.Images_16; - AddButton.Caption := oiColEditAdd; - DeleteButton.Caption := oiColEditDelete; - MoveUpButton.Caption := oiColEditUp; - MoveDownButton.Caption := oiColEditDown; - AddButton.ImageIndex := IDEImages.LoadImage(16, 'laz_add'); - DeleteButton.ImageIndex := IDEImages.LoadImage(16, 'laz_delete'); - MoveUpButton.ImageIndex := IDEImages.LoadImage(16, 'arrow_up'); - MoveDownButton.ImageIndex := IDEImages.LoadImage(16, 'arrow_down'); -end; - -procedure TCollectionPropertyEditorForm.FormDestroy(Sender: TObject); -begin - if GlobalDesignHook <> nil then - GlobalDesignHook.RemoveAllHandlersForObject(Self); -end; - -procedure TCollectionPropertyEditorForm.MoveDownButtonClick(Sender: TObject); -var - I: Integer; -begin - if Collection = nil then Exit; - - I := CollectionListBox.ItemIndex; - if I >= Collection.Count - 1 then Exit; - - Collection.Items[I].Index := I + 1; - CollectionListBox.ItemIndex := I + 1; - - FillCollectionListBox; - SelectInObjectInspector(False); - Modified; -end; - -procedure TCollectionPropertyEditorForm.MoveUpButtonClick(Sender: TObject); -var - I: Integer; -begin - if Collection = nil then Exit; - - I := CollectionListBox.ItemIndex; - if I < 0 then Exit; - - Collection.Items[I].Index := I - 1; - CollectionListBox.ItemIndex := I - 1; - - FillCollectionListBox; - SelectInObjectInspector(False); - Modified; -end; - -procedure TCollectionPropertyEditorForm.AddButtonClick(Sender: TObject); -begin - if Collection = nil then Exit; - Collection.Add; - - FillCollectionListBox; - if CollectionListBox.Items.Count > 0 then - CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1; - SelectInObjectInspector(False); - UpdateButtons; - UpdateCaption; - Modified; -end; - -procedure TCollectionPropertyEditorForm.CollectionListBoxClick(Sender: TObject); -begin - UpdateButtons; - UpdateCaption; - SelectInObjectInspector(False); -end; - -procedure TCollectionPropertyEditorForm.DeleteButtonClick(Sender: TObject); -var - I : Integer; - NewItemIndex: Integer; -begin - if Collection = nil then Exit; - - I := CollectionListBox.ItemIndex; - if (I >= 0) and (I < Collection.Count) then - begin - if MessageDlg(oisConfirmDelete, - Format(oisDeleteItem, ['"', Collection.Items[I].DisplayName, '"']), - mtConfirmation, [mbYes, mbNo], 0) = mrYes then - begin - // select other item, or unselect - NewItemIndex := I + 1; - while (NewItemIndex < CollectionListBox.Items.Count) - and (CollectionListBox.Selected[NewItemIndex]) do Inc(NewItemIndex); - - if NewItemIndex = CollectionListBox.Items.Count then - begin - NewItemIndex := 0; - while (NewItemIndex < Pred(I)) - and not (CollectionListBox.Selected[NewItemIndex]) do Inc(NewItemIndex); - - if NewItemIndex = I then NewItemIndex := -1; - end; - - CollectionListBox.ItemIndex := -1; - - if NewItemIndex > I then Dec(NewItemIndex); - //debugln('TCollectionPropertyEditorForm.DeleteClick A NewItemIndex=',dbgs(NewItemIndex),' ItemIndex=',dbgs(CollectionListBox.ItemIndex),' CollectionListBox.Items.Count=',dbgs(CollectionListBox.Items.Count),' Collection.Count=',dbgs(Collection.Count)); - // unselect all items in OI (collections can act strange on delete) - SelectInObjectInspector(True); - // now delete - Collection.Items[I].Free; - // update listbox after whatever happened - FillCollectionListBox; - // set NewItemIndex - if NewItemIndex < CollectionListBox.Items.Count then - begin - CollectionListBox.ItemIndex := NewItemIndex; - SelectInObjectInspector(False); - end; - //debugln('TCollectionPropertyEditorForm.DeleteClick B'); - Modified; - end; - end; - UpdateButtons; - UpdateCaption; -end; - -procedure TCollectionPropertyEditorForm.UpdateCaption; -var - NewCaption: String; -begin - //I think to match Delphi this should be formatted like - //"Editing ComponentName.PropertyName[Index]" - if OwnerPersistent is TComponent then - NewCaption := TComponent(OwnerPersistent).Name - else - if OwnerPersistent <> nil then - NewCaption := OwnerPersistent.GetNamePath - else - NewCaption := ''; - - if NewCaption <> '' then NewCaption := NewCaption + '.'; - NewCaption := oiColEditEditing + ' ' + NewCaption + PropertyName; - - if CollectionListBox.ItemIndex > -1 then - NewCaption := NewCaption + '[' + IntToStr(CollectionListBox.ItemIndex) + ']'; - Caption := NewCaption; -end; - -procedure TCollectionPropertyEditorForm.UpdateButtons; -var - I: Integer; -begin - I := CollectionListBox.ItemIndex; - AddButton.Enabled := Collection <> nil; - DeleteButton.Enabled := I > -1; - MoveUpButton.Enabled := I > 0; - MoveDownButton.Enabled := (I >= 0) and (I < Collection.Count - 1); -end; - -procedure TCollectionPropertyEditorForm.ComponentRenamed(AComponent: TComponent); -begin - if AComponent = OwnerPersistent then UpdateCaption; -end; - -procedure TCollectionPropertyEditorForm.PersistentDeleting(APersistent: TPersistent); -var - OldCollection: TCollection; -begin - //debugln('TCollectionPropertyEditorForm.PersistentDeleting A APersistent=',dbgsName(APersistent),' OwnerPersistent=',dbgsName(OwnerPersistent)); - if APersistent = OwnerPersistent then - begin - OldCollection := Collection; - SetCollection(nil, nil, ''); - GlobalDesignHook.Unselect(OldCollection); - if GlobalDesignHook.LookupRoot = OldCollection then - GlobalDesignHook.LookupRoot := nil; - - Hide; - end; -end; - -procedure TCollectionPropertyEditorForm.RefreshPropertyValues; -begin - FillCollectionListBox; -end; - -procedure TCollectionPropertyEditorForm.FillCollectionListBox; -var - I: Integer; - CurItem: String; - Cnt: Integer; -begin - CollectionListBox.Items.BeginUpdate; - try - if Collection <> nil then Cnt := Collection.Count - else Cnt := 0; - - // add or replace list items - for I := 0 to Cnt - 1 do - begin - CurItem := IntToStr(I) + ' - ' + Collection.Items[I].DisplayName; - if I >= CollectionListBox.Items.Count then - CollectionListBox.Items.Add(CurItem) - else - CollectionListBox.Items[I] := CurItem; - end; - - // delete unneeded list items - if Cnt > 0 then - begin - while CollectionListBox.Items.Count > Cnt do - begin - CollectionListBox.Items.Delete(CollectionListBox.Items.Count - 1); - end; - end - else - begin - CollectionListBox.Items.Clear; - end; - finally - CollectionListBox.Items.EndUpdate; - UpdateButtons; - UpdateCaption; - end; -end; - -procedure TCollectionPropertyEditorForm.SelectInObjectInspector(UnselectAll: Boolean); -var - I: Integer; - NewSelection: TPersistentSelectionList; -begin - if Collection = nil then Exit; - // select in OI - NewSelection := TPersistentSelectionList.Create; - try - if not UnselectAll then - begin - for I := 0 to CollectionListBox.Items.Count - 1 do - if CollectionListBox.Selected[I] then - NewSelection.Add(Collection.Items[I]); - end; - GlobalDesignHook.SetSelection(NewSelection); - GlobalDesignHook.LookupRoot := GetLookupRootForComponent(OwnerPersistent); - finally - NewSelection.Free; - end; -end; - -procedure TCollectionPropertyEditorForm.SetCollection(NewCollection: TCollection; - NewOwnerPersistent: TPersistent; const NewPropName: String); -begin - if (FCollection = NewCollection) and (FOwnerPersistent = NewOwnerPersistent) - and (FPropertyName = NewPropName) then Exit; - - FCollection := NewCollection; - FOwnerPersistent := NewOwnerPersistent; - FPropertyName := NewPropName; - //debugln('TCollectionPropertyEditorForm.SetCollection A Collection=',dbgsName(FCollection),' OwnerPersistent=',dbgsName(OwnerPersistent),' PropName=',PropertyName); - if GlobalDesignHook <> nil then - begin - if FOwnerPersistent <> nil then - begin - GlobalDesignHook.AddHandlerComponentRenamed(@ComponentRenamed); - GlobalDesignHook.AddHandlerPersistentDeleting(@PersistentDeleting); - GlobalDesignHook.AddHandlerRefreshPropertyValues(@RefreshPropertyValues); - end - else - begin - GlobalDesignHook.RemoveAllHandlersForObject(Self); - end; - end; - - FillCollectionListBox; - UpdateCaption; -end; - -procedure TCollectionPropertyEditorForm.Modified; -begin - GlobalDesignHook.Modified(Self); -end; - // - - - - - - - - - - - - - - - - - - - - - - - - - - function TCollectionPropertyEditor.ReadElement(Index: integer): TPersistent; @@ -7217,8 +6897,7 @@ begin end; initialization - {$I collectionpropeditform.lrs} - + InitPropEdits; finalization