MG: started TCollectionPropertyEditor

git-svn-id: trunk@1415 -
This commit is contained in:
lazarus 2002-02-09 02:30:39 +00:00
parent 9fee6d8ff2
commit 18dadda900

View File

@ -675,7 +675,8 @@ type
end; end;
{ TListElementPropertyEditor { TListElementPropertyEditor
UNDER CONSTRUCTION by Mattias} A property editor for a single element of a TListPropertyEditor
This editor simply redirects all methods to the TListPropertyEditor }
TListPropertyEditor = class; TListPropertyEditor = class;
TListElementPropertyEditor = class(TNestedPropertyEditor) TListElementPropertyEditor = class(TNestedPropertyEditor)
@ -686,6 +687,10 @@ type
constructor Create(Parent: TListPropertyEditor; AnIndex: integer); constructor Create(Parent: TListPropertyEditor; AnIndex: integer);
destructor Destroy; override; destructor Destroy; override;
function GetAttributes: TPropertyAttributes; override; function GetAttributes: TPropertyAttributes; override;
function GetName:shortstring; override;
function GetValue: ansistring; override;
procedure GetValues(Proc: TGetStringProc); override;
procedure SetValue(const NewValue: ansistring); override;
property List: TListPropertyEditor read FList; property List: TListPropertyEditor read FList;
property TheIndex: integer read FIndex; property TheIndex: integer read FIndex;
end; end;
@ -710,24 +715,57 @@ type
SavedPropertyEditors: TList; SavedPropertyEditors: TList;
function ReadElementCount: integer; virtual; function ReadElementCount: integer; virtual;
function ReadElement(Index: integer): TObject; virtual; function ReadElement(Index: integer): TObject; virtual;
function CreateElementPropEditor(Index: integer): TListElementPropertyEditor; virtual; function CreateElementPropEditor(
Index: integer): TListElementPropertyEditor; virtual;
procedure DoSaveElements; virtual; procedure DoSaveElements; virtual;
procedure FreeElementPropertyEditors; virtual; procedure FreeElementPropertyEditors; virtual;
function GetElementAttributes(AnIndex: integer): TPropertyAttributes; virtual; function GetElementAttributes(
Element: TListElementPropertyEditor): TPropertyAttributes; virtual;
function GetElementName(
Element: TListElementPropertyEditor):shortstring; virtual;
function GetElementValue(
Element: TListElementPropertyEditor): ansistring; virtual;
procedure GetElementValues(Element: TListElementPropertyEditor;
Proc: TGetStringProc); virtual;
procedure SetElementValue(Element: TListElementPropertyEditor;
NewValue: ansistring); virtual;
public public
constructor Create(Hook:TPropertyEditorHook; constructor Create(Hook:TPropertyEditorHook;
ComponentList: TComponentSelectionList; APropCount:Integer); override; ComponentList: TComponentSelectionList; APropCount:Integer); override;
destructor Destroy; override; destructor Destroy; override;
function GetAttributes: TPropertyAttributes; override; function GetAttributes: TPropertyAttributes; override;
procedure GetProperties(Proc: TGetPropEditProc); override;
function GetValue: AnsiString; override;
procedure SaveElements;
function SubPropertiesNeedsUpdate: boolean; override;
function GetElementCount: integer; function GetElementCount: integer;
function GetElement(Index: integer): TObject; function GetElement(Index: integer): TObject;
function GetElement(Element: TListElementPropertyEditor): TObject;
function GetElementPropEditor(Index: integer): TListElementPropertyEditor; function GetElementPropEditor(Index: integer): TListElementPropertyEditor;
procedure GetProperties(Proc: TGetPropEditProc); override;
function GetValue: AnsiString; override;
procedure Initialize; override;
procedure SaveElements;
function SubPropertiesNeedsUpdate: boolean; override;
end; end;
{ TCollectionPropertyEditor
A property editor for TCollection lists.
UNDER CONSTRUCTION by Mattias}
TCollectionPropertyEditor = class(TListPropertyEditor)
private
protected
function ReadElementCount: integer; override;
function ReadElement(Index: integer): TObject; override;
function GetElementAttributes(
Element: TListElementPropertyEditor): TPropertyAttributes; override;
function GetElementName(
Element: TListElementPropertyEditor):shortstring; override;
function GetElementValue(
Element: TListElementPropertyEditor): ansistring; override;
procedure GetElementValues(Element: TListElementPropertyEditor;
Proc: TGetStringProc); override;
procedure SetElementValue(Element: TListElementPropertyEditor;
NewValue: ansistring); override;
public
end;
//============================================================================== //==============================================================================
@ -1061,6 +1099,7 @@ begin
end; end;
end; end;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const const
@ -1258,7 +1297,7 @@ begin
P^.PropertyType:=PropertyType; P^.PropertyType:=PropertyType;
P^.ComponentClass:=ComponentClass; P^.ComponentClass:=ComponentClass;
P^.PropertyName:=PropertyName; P^.PropertyName:=PropertyName;
if Assigned(ComponentClass) then P^.PropertyName:=PropertyName; //if Assigned(ComponentClass) then P^.PropertyName:=PropertyName;
P^.EditorClass:=EditorClass; P^.EditorClass:=EditorClass;
PropertyClassList.Insert(0,P); PropertyClassList.Insert(0,P);
end; end;
@ -1374,12 +1413,14 @@ begin
and (PropInfo^.SetProc = nil))) and (PropInfo^.SetProc = nil)))
then begin then begin
Candidates.Delete(I); Candidates.Delete(I);
writeln('AAA1 ',PropInfo^.Name);
continue; continue;
end; end;
EdClass := GetEditorClass(PropInfo, Obj); EdClass := GetEditorClass(PropInfo, Obj);
if EdClass = nil then if EdClass = nil then begin
writeln('AAA2 ',PropInfo^.Name);
Candidates.Delete(I) Candidates.Delete(I)
else end else
begin begin
// create a test property editor for the property // create a test property editor for the property
PropEditor := EdClass.Create(Hook,Components,1); PropEditor := EdClass.Create(Hook,Components,1);
@ -1391,8 +1432,10 @@ begin
and not (paMultiSelect in PropEditor.GetAttributes)) and not (paMultiSelect in PropEditor.GetAttributes))
or not PropEditor.ValueAvailable or not PropEditor.ValueAvailable
or (Assigned(EditorFilterFunc) and not EditorFilterFunc(PropEditor)) or (Assigned(EditorFilterFunc) and not EditorFilterFunc(PropEditor))
then then begin
Candidates.Delete(I); Candidates.Delete(I);
writeln('AAA3 ',PropInfo^.Name);
end;
end; end;
end; end;
PropLists := TList.Create; PropLists := TList.Create;
@ -1431,8 +1474,11 @@ begin
if AddEditor then if AddEditor then
begin begin
PropEditor.Initialize; PropEditor.Initialize;
if PropEditor.ValueAvailable then Proc(PropEditor); if not PropEditor.ValueAvailable then AddEditor:=false;
end else end;
if AddEditor then
Proc(PropEditor)
else
PropEditor.Free; PropEditor.Free;
end; end;
finally finally
@ -1698,9 +1744,9 @@ begin
Result:=True; Result:=True;
for I:=0 to FPropCount-1 do for I:=0 to FPropCount-1 do
begin begin
if (FPropList^[I].Instance is TComponent) and if (FPropList^[I].Instance is TComponent)
(csCheckPropAvail in TComponent(FPropList^[I].Instance).ComponentStyle) then and (csCheckPropAvail in TComponent(FPropList^[I].Instance).ComponentStyle)
begin then begin
try try
GetValue; GetValue;
AllEqual; AllEqual;
@ -2221,7 +2267,27 @@ end;
function TListElementPropertyEditor.GetAttributes: TPropertyAttributes; function TListElementPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=List.GetElementAttributes(TheIndex); Result:=List.GetElementAttributes(Self);
end;
function TListElementPropertyEditor.GetName: shortstring;
begin
Result:=List.GetElementName(Self);
end;
function TListElementPropertyEditor.GetValue: ansistring;
begin
Result:=List.GetElementValue(Self);
end;
procedure TListElementPropertyEditor.GetValues(Proc: TGetStringProc);
begin
List.GetElementValues(Self,Proc);
end;
procedure TListElementPropertyEditor.SetValue(const NewValue: ansistring);
begin
List.SetElementValue(Self,NewValue);
end; end;
{ TListPropertyEditor } { TListPropertyEditor }
@ -2252,6 +2318,12 @@ begin
Result:=ReadElement(Index); Result:=ReadElement(Index);
end; end;
function TListPropertyEditor.GetElement(Element: TListElementPropertyEditor
): TObject;
begin
Result:=GetElement(Element.TheIndex);
end;
function TListPropertyEditor.GetElementPropEditor(Index: integer function TListPropertyEditor.GetElementPropEditor(Index: integer
): TListElementPropertyEditor; ): TListElementPropertyEditor;
begin begin
@ -2265,6 +2337,7 @@ procedure TListPropertyEditor.SaveElements;
begin begin
if IsSaving then exit; if IsSaving then exit;
BeginSaveElement; BeginSaveElement;
FreeElementPropertyEditors;
DoSaveElements; DoSaveElements;
FSubPropertiesChanged:=false; FSubPropertiesChanged:=false;
EndSaveElement; EndSaveElement;
@ -2288,7 +2361,7 @@ function TListPropertyEditor.ReadElementCount: integer;
var var
TheList: TList; TheList: TList;
begin begin
TheList:=TList(GetComponent(0)); TheList:=TList(GetOrdValue);
if (TheList<>nil) and (TheList is TList) then if (TheList<>nil) and (TheList is TList) then
Result:=TheList.Count Result:=TheList.Count
else else
@ -2297,7 +2370,7 @@ end;
function TListPropertyEditor.ReadElement(Index: integer): TObject; function TListPropertyEditor.ReadElement(Index: integer): TObject;
begin begin
Result:=TObject(TList(GetComponent(0)).Items[Index]); Result:=TObject(TList(GetOrdValue).Items[Index]);
end; end;
function TListPropertyEditor.CreateElementPropEditor(Index: integer function TListPropertyEditor.CreateElementPropEditor(Index: integer
@ -2336,17 +2409,42 @@ procedure TListPropertyEditor.FreeElementPropertyEditors;
var var
i: integer; i: integer;
begin begin
for i:=0 to SavedPropertyEditors.Count do for i:=0 to SavedPropertyEditors.Count-1 do
TObject(SavedPropertyEditors[i]).Free; TObject(SavedPropertyEditors[i]).Free;
SavedPropertyEditors.Clear; SavedPropertyEditors.Clear;
end; end;
function TListPropertyEditor.GetElementAttributes(AnIndex: integer function TListPropertyEditor.GetElementAttributes(
Element: TListElementPropertyEditor
): TPropertyAttributes; ): TPropertyAttributes;
begin begin
Result:= [paReadOnly]; Result:= [paReadOnly];
end; end;
function TListPropertyEditor.GetElementName(Element: TListElementPropertyEditor
): shortstring;
begin
Result:='Item '+IntToStr(Element.TheIndex);
end;
function TListPropertyEditor.GetElementValue(Element: TListElementPropertyEditor
): ansistring;
begin
Result:='';
end;
procedure TListPropertyEditor.GetElementValues(
Element: TListElementPropertyEditor; Proc: TGetStringProc);
begin
end;
procedure TListPropertyEditor.SetElementValue(
Element: TListElementPropertyEditor; NewValue: ansistring);
begin
end;
function TListPropertyEditor.IsSaving: boolean; function TListPropertyEditor.IsSaving: boolean;
begin begin
Result:=SaveElementLock>0; Result:=SaveElementLock>0;
@ -2358,14 +2456,12 @@ begin
inherited Create(Hook, ComponentList, APropCount); inherited Create(Hook, ComponentList, APropCount);
SavedElements:=TList.Create; SavedElements:=TList.Create;
SavedPropertyEditors:=TList.Create; SavedPropertyEditors:=TList.Create;
if (ComponentList<>nil) and (ComponentList.Count=1) then
RegisterListPropertyEditor(Self);
SaveElements;
end; end;
destructor TListPropertyEditor.Destroy; destructor TListPropertyEditor.Destroy;
begin begin
UnregisterListPropertyEditor(Self); UnregisterListPropertyEditor(Self);
FreeElementPropertyEditors;
FreeAndNil(SavedPropertyEditors); FreeAndNil(SavedPropertyEditors);
FreeAndNil(SavedElements); FreeAndNil(SavedElements);
inherited Destroy; inherited Destroy;
@ -2397,14 +2493,69 @@ begin
Result:='1 item'; Result:='1 item';
end; end;
procedure TListPropertyEditor.Initialize;
begin
inherited Initialize;
RegisterListPropertyEditor(Self);
SaveElements;
end;
{ TCollectionPropertyEditor }
function TCollectionPropertyEditor.ReadElementCount: integer;
var
Collection: TCollection;
begin
Collection:=TCollection(GetOrdValue);
if (Collection<>nil) and (Collection is TCollection) then
Result:=Collection.Count
else
Result:=0;
end;
function TCollectionPropertyEditor.ReadElement(Index: integer): TObject;
var
Collection: TCollection;
begin
Collection:=TCollection(GetOrdValue);
Result:=Collection.Items[Index];
end;
function TCollectionPropertyEditor.GetElementAttributes(
Element: TListElementPropertyEditor): TPropertyAttributes;
begin
Result:=inherited GetElementAttributes(Element);
end;
function TCollectionPropertyEditor.GetElementName(
Element: TListElementPropertyEditor): shortstring;
begin
Result:=inherited GetElementName(Element);
end;
function TCollectionPropertyEditor.GetElementValue(
Element: TListElementPropertyEditor): ansistring;
begin
Result:=IntToStr(TCollectionItem(GetElement(Element)).ID);
end;
procedure TCollectionPropertyEditor.GetElementValues(
Element: TListElementPropertyEditor; Proc: TGetStringProc);
begin
inherited GetElementValues(Element, Proc);
end;
procedure TCollectionPropertyEditor.SetElementValue(
Element: TListElementPropertyEditor; NewValue: ansistring);
begin
inherited SetElementValue(Element, NewValue);
end;
{ TClassPropertyEditor } { TClassPropertyEditor }
function TClassPropertyEditor.GetAttributes: TPropertyAttributes; function TClassPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paSubProperties, paReadOnly]; Result := [paMultiSelect, paSubProperties, paReadOnly];
if (PropCount>0) then begin
end;
end; end;
procedure TClassPropertyEditor.GetProperties(Proc: TGetPropEditProc); procedure TClassPropertyEditor.GetProperties(Proc: TGetPropEditProc);
@ -3745,18 +3896,16 @@ begin
// Normaly it should use be something like this; // Normaly it should use be something like this;
// RegisterPropertyEditor(TypeInfo(TColor),nil,'',TColorPropertyEditor); // RegisterPropertyEditor(TypeInfo(TColor),nil,'',TColorPropertyEditor);
DummyClassForPropTypes:=TDummyClassForPropTypes.Create; DummyClassForPropTypes:=TDummyClassForPropTypes.Create;
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TComponent'),nil
,'',TComponentPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('AnsiString'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('AnsiString'),
nil,'Name',TComponentNamePropertyEditor); nil,'Name',TComponentNamePropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('AnsiString'),
TCustomLabel, 'Caption', TCaptionMultilinePropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('longint'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('longint'),
nil,'Tag',TTabOrderPropertyEditor); nil,'Tag',TTabOrderPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('shortstring'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('shortstring'),
nil,'',TCaptionPropertyEditor); nil,'',TCaptionPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TStrings'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TStrings'),
nil,'',TStringsPropertyEditor); nil,'',TStringsPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TListColumns'),
nil,'',TListColumnsPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TModalResult'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TModalResult'),
nil,'ModalResult',TModalResultPropertyEditor); nil,'ModalResult',TModalResultPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TShortCut'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TShortCut'),
@ -3768,10 +3917,11 @@ begin
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TDateTime'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TDateTime'),
nil,'',TShortCutPropertyEditor); nil,'',TShortCutPropertyEditor);
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TCursor'), RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TCursor'),
nil,'Cursor',TCursorPropertyEditor); nil,'',TCursorPropertyEditor);
RegisterPropertyEditor(ClassTypeInfo(TComponent),nil
RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('AnsiString'), ,'',TComponentPropertyEditor);
TCustomLabel, 'Caption', TCaptionMultilinePropertyEditor); RegisterPropertyEditor(DummyClassForPropTypes.PTypeInfos('TListColumns'),
nil,'',TListColumnsPropertyEditor);
end; end;
procedure FinalPropEdits; procedure FinalPropEdits;