ideintf: Extract CollectionPropEditForm from the Propedits unit by Alexander S. Klenin (issue #0015490)

git-svn-id: trunk@23432 -
This commit is contained in:
paul 2010-01-13 07:47:05 +00:00
parent 2cd1e874be
commit c376225ef0
6 changed files with 397 additions and 382 deletions

1
.gitattributes vendored
View File

@ -3707,6 +3707,7 @@ ideintf/checklistboxeditordlg.lrs svneol=native#text/pascal
ideintf/checklistboxeditordlg.pas svneol=native#text/plain ideintf/checklistboxeditordlg.pas svneol=native#text/plain
ideintf/collectionpropeditform.lfm svneol=native#text/plain ideintf/collectionpropeditform.lfm svneol=native#text/plain
ideintf/collectionpropeditform.lrs svneol=native#text/pascal ideintf/collectionpropeditform.lrs svneol=native#text/pascal
ideintf/collectionpropeditform.pas svneol=native#text/plain
ideintf/columndlg.pp svneol=native#text/pascal ideintf/columndlg.pp svneol=native#text/pascal
ideintf/componenteditors.pas svneol=native#text/pascal ideintf/componenteditors.pas svneol=native#text/pascal
ideintf/componentreg.pas svneol=native#text/pascal ideintf/componentreg.pas svneol=native#text/pascal

View File

@ -23,6 +23,7 @@ uses
ActionsEditor, ActionsEditor,
ActionsEditorStd, ActionsEditorStd,
BaseIDEIntf, BaseIDEIntf,
CollectionPropEditForm,
ComponentEditors, ComponentEditors,
ComponentReg, ComponentReg,
ComponentTreeView, ComponentTreeView,

View File

@ -1,4 +1,10 @@
object CollectionPropertyEditorForm: TCollectionPropertyEditorForm object CollectionPropertyEditorForm: TCollectionPropertyEditorForm
Left = 220
Height = 300
Top = 220
Width = 190
HorzScrollBar.Page = 189
VertScrollBar.Page = 299
ActiveControl = CollectionListBox ActiveControl = CollectionListBox
BorderStyle = bsSizeToolWin BorderStyle = bsSizeToolWin
Caption = 'CollectionPropertyEditorForm' Caption = 'CollectionPropertyEditorForm'
@ -8,72 +14,59 @@ object CollectionPropertyEditorForm: TCollectionPropertyEditorForm
Constraints.MinWidth = 190 Constraints.MinWidth = 190
OnCreate = FormCreate OnCreate = FormCreate
OnDestroy = FormDestroy OnDestroy = FormDestroy
PixelsPerInch = 96
Position = poDefaultPosOnly Position = poDefaultPosOnly
HorzScrollBar.Page = 189 LCLVersion = '0.9.29'
VertScrollBar.Page = 299
Left = 290
Height = 300
Top = 153
Width = 190
object ToolBar1: TToolBar object ToolBar1: TToolBar
Left = 0
Height = 42
Top = 0
Width = 190
AutoSize = True AutoSize = True
ButtonHeight = 40 ButtonHeight = 40
ButtonWidth = 44 ButtonWidth = 44
Caption = 'ToolBar1' Caption = 'ToolBar1'
Flat = True
Height = 42
ShowCaptions = True ShowCaptions = True
TabOrder = 0 TabOrder = 0
Height = 42
Width = 190
object AddButton: TToolButton object AddButton: TToolButton
Left = 1
Top = 2
Caption = 'Add' Caption = 'Add'
OnClick = AddButtonClick OnClick = AddButtonClick
Height = 40
Top = 2
Width = 44
end end
object DeleteButton: TToolButton object DeleteButton: TToolButton
Left = 45
Top = 2
Caption = 'Delete' Caption = 'Delete'
OnClick = DeleteButtonClick OnClick = DeleteButtonClick
Left = 45
Height = 40
Top = 2
Width = 44
end end
object ToolButton3: TToolButton object ToolButton3: TToolButton
Left = 89
Top = 2
Width = 10
Caption = 'ToolButton3' Caption = 'ToolButton3'
Style = tbsSeparator Style = tbsSeparator
Width = 10
Left = 89
Height = 40
Top = 2
Width = 10
end end
object MoveUpButton: TToolButton object MoveUpButton: TToolButton
Left = 99
Top = 2
Caption = 'Up' Caption = 'Up'
OnClick = MoveUpButtonClick OnClick = MoveUpButtonClick
Left = 99
Height = 40
Top = 2
Width = 44
end end
object MoveDownButton: TToolButton object MoveDownButton: TToolButton
Left = 143
Top = 2
Caption = 'Down' Caption = 'Down'
OnClick = MoveDownButtonClick OnClick = MoveDownButtonClick
Left = 143
Height = 40
Top = 2
Width = 44
end end
end end
object CollectionListBox: TListBox object CollectionListBox: TListBox
Align = alClient Left = 0
OnClick = CollectionListBoxClick
TabOrder = 1
Height = 258 Height = 258
Top = 42 Top = 42
Width = 190 Width = 190
Align = alClient
ItemHeight = 0
OnClick = CollectionListBoxClick
TabOrder = 1
end end
end end

View File

@ -1,24 +1,25 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TCollectionPropertyEditorForm','FORMDATA',[ LazarusResources.Add('TCollectionPropertyEditorForm','FORMDATA',[
'TPF0'#29'TCollectionPropertyEditorForm'#28'CollectionPropertyEditorForm'#13 'TPF0'#29'TCollectionPropertyEditorForm'#28'CollectionPropertyEditorForm'#4'L'
+'ActiveControl'#7#17'CollectionListBox'#11'BorderStyle'#7#13'bsSizeToolWin'#7 +'eft'#3#220#0#6'Height'#3','#1#3'Top'#3#220#0#5'Width'#3#190#0#18'HorzScroll'
+'Caption'#6#28'CollectionPropertyEditorForm'#12'ClientHeight'#3','#1#11'Clie' +'Bar.Page'#3#189#0#18'VertScrollBar.Page'#3'+'#1#13'ActiveControl'#7#17'Coll'
+'ntWidth'#3#190#0#21'Constraints.MinHeight'#2'd'#20'Constraints.MinWidth'#3 +'ectionListBox'#11'BorderStyle'#7#13'bsSizeToolWin'#7'Caption'#6#28'Collecti'
+#190#0#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#13'Pixels' +'onPropertyEditorForm'#12'ClientHeight'#3','#1#11'ClientWidth'#3#190#0#21'Co'
+'PerInch'#2'`'#8'Position'#7#16'poDefaultPosOnly'#18'HorzScrollBar.Page'#3 +'nstraints.MinHeight'#2'd'#20'Constraints.MinWidth'#3#190#0#8'OnCreate'#7#10
+#189#0#18'VertScrollBar.Page'#3'+'#1#4'Left'#3'"'#1#6'Height'#3','#1#3'Top'#3 +'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#8'Position'#7#16'poDefaultPosOnl'
+#153#0#5'Width'#3#190#0#0#8'TToolBar'#8'ToolBar1'#8'AutoSize'#9#12'ButtonHei' +'y'#10'LCLVersion'#6#6'0.9.29'#0#8'TToolBar'#8'ToolBar1'#4'Left'#2#0#6'Heigh'
+'ght'#2'('#11'ButtonWidth'#2','#7'Caption'#6#8'ToolBar1'#4'Flat'#9#6'Height' +'t'#2'*'#3'Top'#2#0#5'Width'#3#190#0#8'AutoSize'#9#12'ButtonHeight'#2'('#11
+#2'*'#12'ShowCaptions'#9#8'TabOrder'#2#0#6'Height'#2'*'#5'Width'#3#190#0#0#11 +'ButtonWidth'#2','#7'Caption'#6#8'ToolBar1'#12'ShowCaptions'#9#8'TabOrder'#2
+'TToolButton'#9'AddButton'#7'Caption'#6#3'Add'#7'OnClick'#7#14'AddButtonClic' +#0#0#11'TToolButton'#9'AddButton'#4'Left'#2#1#3'Top'#2#2#7'Caption'#6#3'Add'
+'k'#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#12'DeleteBut' +#7'OnClick'#7#14'AddButtonClick'#0#0#11'TToolButton'#12'DeleteButton'#4'Left'
+'ton'#7'Caption'#6#6'Delete'#7'OnClick'#7#17'DeleteButtonClick'#4'Left'#2'-' +#2'-'#3'Top'#2#2#7'Caption'#6#6'Delete'#7'OnClick'#7#17'DeleteButtonClick'#0
+#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#11'ToolButton3' +#0#11'TToolButton'#11'ToolButton3'#4'Left'#2'Y'#3'Top'#2#2#5'Width'#2#10#7'C'
+#7'Caption'#6#11'ToolButton3'#5'Style'#7#12'tbsSeparator'#5'Width'#2#10#4'Le' +'aption'#6#11'ToolButton3'#5'Style'#7#12'tbsSeparator'#0#0#11'TToolButton'#12
+'ft'#2'Y'#6'Height'#2'('#3'Top'#2#2#5'Width'#2#10#0#0#11'TToolButton'#12'Mov' +'MoveUpButton'#4'Left'#2'c'#3'Top'#2#2#7'Caption'#6#2'Up'#7'OnClick'#7#17'Mo'
+'eUpButton'#7'Caption'#6#2'Up'#7'OnClick'#7#17'MoveUpButtonClick'#4'Left'#2 +'veUpButtonClick'#0#0#11'TToolButton'#14'MoveDownButton'#4'Left'#3#143#0#3'T'
+'c'#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#11'TToolButton'#14'MoveDownB' +'op'#2#2#7'Caption'#6#4'Down'#7'OnClick'#7#19'MoveDownButtonClick'#0#0#0#8'T'
+'utton'#7'Caption'#6#4'Down'#7'OnClick'#7#19'MoveDownButtonClick'#4'Left'#3 +'ListBox'#17'CollectionListBox'#4'Left'#2#0#6'Height'#3#2#1#3'Top'#2'*'#5'Wi'
+#143#0#6'Height'#2'('#3'Top'#2#2#5'Width'#2','#0#0#0#8'TListBox'#17'Collecti' +'dth'#3#190#0#5'Align'#7#8'alClient'#10'ItemHeight'#2#0#7'OnClick'#7#22'Coll'
+'onListBox'#5'Align'#7#8'alClient'#7'OnClick'#7#22'CollectionListBoxClick'#8 +'ectionListBoxClick'#8'TabOrder'#2#1#0#0#0
+'TabOrder'#2#1#6'Height'#3#2#1#3'Top'#2'*'#5'Width'#3#190#0#0#0#0
]); ]);

View File

@ -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.

View File

@ -33,12 +33,13 @@ unit PropEdits;
interface interface
uses uses
Classes, TypInfo, SysUtils, LResources, Classes, TypInfo, SysUtils,
FPCAdds, // for StrToQWord in older fpc versions FPCAdds, // for StrToQWord in older fpc versions
LCLProc, Forms, Controls, GraphType, StringHashList, ButtonPanel, 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, Dialogs, Grids, EditBtn, PropertyStorage, TextTools, FrmSelectProps,
StringsPropEditDlg, ColumnDlg, FileUtil, ObjInspStrConsts, IDEImagesIntf; StringsPropEditDlg, ColumnDlg, FileUtil, ObjInspStrConsts,
CollectionPropEditForm;
const const
MaxIdentLength: Byte = 63; MaxIdentLength: Byte = 63;
@ -3695,330 +3696,9 @@ begin
end; 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 const
CollectionForm: TCollectionPropertyEditorForm = nil; 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; function TCollectionPropertyEditor.ReadElement(Index: integer): TPersistent;
@ -7217,7 +6897,6 @@ begin
end; end;
initialization initialization
{$I collectionpropeditform.lrs}
InitPropEdits; InitPropEdits;