IdeIntf: propedits: fix highlighting default (=not stored) properties.

git-svn-id: trunk@54955 -
This commit is contained in:
ondrej 2017-05-17 18:27:55 +00:00
parent 697a3ee6fa
commit 3a7e2ee5dd
6 changed files with 114 additions and 53 deletions

View File

@ -303,8 +303,6 @@ end;
function TColorPropertyEditor.GetAttributes: TPropertyAttributes; function TColorPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect,paDialog,paValueList,paCustomDrawn,paRevertable]; Result := [paMultiSelect,paDialog,paValueList,paCustomDrawn,paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TColorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TColorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
@ -453,7 +451,7 @@ end;
function TFontCharsetPropertyEditor.GetAttributes: TPropertyAttributes; function TFontCharsetPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=[paMultiSelect,paSortList,paValueList,paRevertable,paHasDefaultValue]; Result:=[paMultiSelect,paSortList,paValueList,paRevertable];
end; end;
function TFontCharsetPropertyEditor.OrdValueToVisualValue(OrdValue: longint function TFontCharsetPropertyEditor.OrdValueToVisualValue(OrdValue: longint
@ -562,7 +560,7 @@ end;
function TBrushStylePropertyEditor.GetAttributes: TPropertyAttributes; function TBrushStylePropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=(inherited GetAttributes)-[paHasDefaultValue]+[paCustomDrawn]; Result:=(inherited GetAttributes)+[paCustomDrawn];
end; end;
procedure TBrushStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring; procedure TBrushStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring;
@ -632,7 +630,7 @@ end;
function TPenStylePropertyEditor.GetAttributes: TPropertyAttributes; function TPenStylePropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=(inherited GetAttributes)-[paHasDefaultValue]+[paCustomDrawn]; Result:=(inherited GetAttributes)+[paCustomDrawn];
end; end;
procedure TPenStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring; procedure TPenStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring;
@ -708,8 +706,6 @@ end;
function TImageIndexPropertyEditor.GetAttributes: TPropertyAttributes; function TImageIndexPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paValueList, paCustomDrawn, paRevertable]; Result := [paValueList, paCustomDrawn, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
procedure TImageIndexPropertyEditor.GetValues(Proc: TGetStrProc); procedure TImageIndexPropertyEditor.GetValues(Proc: TGetStrProc);

View File

@ -4633,7 +4633,7 @@ begin
Result:=False; Result:=False;
DefaultStr:=''; DefaultStr:='';
CurRow:=GetActivePropertyRow; CurRow:=GetActivePropertyRow;
if Assigned(CurRow) and (paHasDefaultValue in CurRow.Editor.GetAttributes) then if Assigned(CurRow) and (CurRow.Editor.HasDefaultValue) then
begin begin
try try
DefaultStr:=CurRow.Editor.GetDefaultValue; DefaultStr:=CurRow.Editor.GetDefaultValue;

View File

@ -23,7 +23,7 @@ interface
uses uses
// RTL / FCL // RTL / FCL
Classes, TypInfo, SysUtils, types, RtlConsts, variants, Classes, TypInfo, SysUtils, types, RtlConsts, variants, Contnrs,
// LCL // LCL
LCLType, LCLIntf, LCLProc, Forms, Controls, GraphType, ButtonPanel, Graphics, LCLType, LCLIntf, LCLProc, Forms, Controls, GraphType, ButtonPanel, Graphics,
StdCtrls, Buttons, Menus, ExtCtrls, ComCtrls, Dialogs, EditBtn, Grids, ValEdit, StdCtrls, Buttons, Menus, ExtCtrls, ComCtrls, Dialogs, EditBtn, Grids, ValEdit,
@ -258,7 +258,6 @@ type
paDisableSubProperties, paDisableSubProperties,
paReference, paReference,
paNotNestable, paNotNestable,
paHasDefaultValue,
paCustomDrawn paCustomDrawn
); );
TPropertyAttributes = set of TPropertyAttribute; TPropertyAttributes = set of TPropertyAttribute;
@ -360,7 +359,10 @@ type
function GetUnicodeStrValueAt(Index: Integer): UnicodeString; function GetUnicodeStrValueAt(Index: Integer): UnicodeString;
function GetValue: ansistring; virtual; function GetValue: ansistring; virtual;
function GetHint({%H-}HintType: TPropEditHint; {%H-}x, {%H-}y: integer): string; virtual; function GetHint({%H-}HintType: TPropEditHint; {%H-}x, {%H-}y: integer): string; virtual;
function HasDefaultValue: Boolean;
function HasStoredFunction: Boolean;
function GetDefaultValue: ansistring; virtual; function GetDefaultValue: ansistring; virtual;
function CallStoredFunction: Boolean; virtual;
function GetVisualValue: ansistring; virtual; function GetVisualValue: ansistring; virtual;
procedure GetValues({%H-}Proc: TGetStrProc); virtual; procedure GetValues({%H-}Proc: TGetStrProc); virtual;
procedure Initialize; virtual; procedure Initialize; virtual;
@ -397,7 +399,7 @@ type
procedure UpdateSubProperties; virtual; procedure UpdateSubProperties; virtual;
function SubPropertiesNeedsUpdate: boolean; virtual; function SubPropertiesNeedsUpdate: boolean; virtual;
function IsDefaultValue: boolean; virtual; function IsDefaultValue: boolean; virtual;
function IsNotDefaultValue: boolean; virtual; function IsNotDefaultValue: boolean;
function IsRevertableToInherited: boolean; virtual; function IsRevertableToInherited: boolean; virtual;
// These are used for the popup menu in OI // These are used for the popup menu in OI
function GetVerbCount: Integer; virtual; function GetVerbCount: Integer; virtual;
@ -431,7 +433,6 @@ type
public public
function AllEqual: Boolean; override; function AllEqual: Boolean; override;
function GetEditLimit: Integer; override; function GetEditLimit: Integer; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: ansistring; override; function GetValue: ansistring; override;
function GetDefaultValue: ansistring; override; function GetDefaultValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; virtual; function OrdValueToVisualValue(OrdValue: longint): string; virtual;
@ -600,7 +601,7 @@ type
function GetVisualValue: ansistring; override; function GetVisualValue: ansistring; override;
procedure GetValues(Proc: TGetStrProc); override; procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const NewValue: ansistring); override; procedure SetValue(const NewValue: ansistring); override;
function IsNotDefaultValue: boolean; override; function IsDefaultValue: boolean; override;
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
AState: TPropEditDrawState); override; AState: TPropEditDrawState); override;
end; end;
@ -629,13 +630,17 @@ type
FSubPropsTypeFilter: TTypeKinds; FSubPropsTypeFilter: TTypeKinds;
FSubPropsNameFilter: String; FSubPropsNameFilter: String;
FHideClassName: Boolean; FHideClassName: Boolean;
FSubProps: TObjectList;
procedure ListSubProps(Prop: TPropertyEditor);
procedure SetSubPropsTypeFilter(const AValue: TTypeKinds); procedure SetSubPropsTypeFilter(const AValue: TTypeKinds);
function EditorFilter(const AEditor: TPropertyEditor): Boolean; function EditorFilter(const AEditor: TPropertyEditor): Boolean;
protected protected
function GetSelections: TPersistentSelectionList; virtual; function GetSelections: TPersistentSelectionList; virtual;
public public
constructor Create(Hook: TPropertyEditorHook; APropCount: Integer); override; constructor Create(Hook: TPropertyEditorHook; APropCount: Integer); override;
destructor Destroy; override;
function IsDefaultValue: boolean; override;
function AllEqual: Boolean; override; function AllEqual: Boolean; override;
function GetAttributes: TPropertyAttributes; override; function GetAttributes: TPropertyAttributes; override;
procedure GetProperties(Proc: TGetPropEditProc); override; procedure GetProperties(Proc: TGetPropEditProc); override;
@ -2543,6 +2548,35 @@ begin
Result:=True; Result:=True;
end; end;
type
TBoolFunc = function: Boolean of object;
function TPropertyEditor.CallStoredFunction: Boolean;
var
Func: TMethod;
FFunc: TBoolFunc;
APropInfo: PPropInfo;
StoredProcType: Byte;
begin
APropInfo:=FPropList^[0].PropInfo;
StoredProcType := ((APropInfo^.PropProcs shr 4) and 3);
if StoredProcType in [ptStatic, ptVirtual] then
begin
case StoredProcType of
ptStatic: Func.Code := APropInfo^.StoredProc;
ptVirtual: Func.Code := PPointer(Pointer(FPropList^[0].Instance.ClassType))[{%H-}PtrInt(APropInfo^.StoredProc) div SizeOf(Pointer)];
end;
if Func.Code = nil then
raise EPropertyError.Create('No property stored method available');
Func.Data := FPropList^[0].Instance;
FFunc := TBoolFunc(Func);
Result := FFunc();
end else
if StoredProcType = ptConst then
Result := APropInfo^.StoredProc<>nil
else
raise EPropertyError.Create('No property stored method/const available');
end;
function TPropertyEditor.DrawCheckbox(ACanvas: TCanvas; const ARect: TRect; function TPropertyEditor.DrawCheckbox(ACanvas: TCanvas; const ARect: TRect;
IsTrue: Boolean): TRect; IsTrue: Boolean): TRect;
// Draws a Checkbox using theme services for editing booleans. // Draws a Checkbox using theme services for editing booleans.
@ -2886,6 +2920,24 @@ begin
with FPropList^[Index] do Result:=GetWideStrProp(Instance,PropInfo); with FPropList^[Index] do Result:=GetWideStrProp(Instance,PropInfo);
end; end;
function TPropertyEditor.HasDefaultValue: Boolean;
var
APropInfo: PPropInfo;
begin
APropInfo:=FPropList^[0].PropInfo;
Result := APropInfo^.Default<>NoDefaultValue;
end;
function TPropertyEditor.HasStoredFunction: Boolean;
var
APropInfo: PPropInfo;
StoredProcType: Byte;
begin
APropInfo:=FPropList^[0].PropInfo;
StoredProcType := ((APropInfo^.PropProcs shr 4) and 3);
Result := StoredProcType in [ptConst, ptStatic, ptVirtual];
end;
function TPropertyEditor.GetUnicodeStrValue: UnicodeString; function TPropertyEditor.GetUnicodeStrValue: UnicodeString;
begin begin
Result:=GetUnicodeStrValueAt(0); Result:=GetUnicodeStrValueAt(0);
@ -2933,7 +2985,7 @@ end;
function TPropertyEditor.GetDefaultValue: ansistring; function TPropertyEditor.GetDefaultValue: ansistring;
begin begin
if not (paHasDefaultValue in GetAttributes) then if not HasDefaultValue then
raise EPropertyError.Create('No property default available'); raise EPropertyError.Create('No property default available');
Result:=''; Result:='';
end; end;
@ -3348,14 +3400,18 @@ end;
function TPropertyEditor.IsDefaultValue: boolean; function TPropertyEditor.IsDefaultValue: boolean;
begin begin
Result:=(paHasDefaultValue in GetAttributes) if HasDefaultValue then
and (GetDefaultValue=GetVisualValue); Result := (GetDefaultValue=GetVisualValue)
else
if HasStoredFunction then
Result := not CallStoredFunction
else
Result := False;
end; end;
function TPropertyEditor.IsNotDefaultValue: boolean; function TPropertyEditor.IsNotDefaultValue: boolean;
begin begin
Result:=(paHasDefaultValue in GetAttributes) Result := not IsDefaultValue;
and (GetDefaultValue<>GetVisualValue);
end; end;
function TPropertyEditor.IsRevertableToInherited: boolean; function TPropertyEditor.IsRevertableToInherited: boolean;
@ -3378,7 +3434,7 @@ end;
function TPropertyEditor.GetVerbCount: Integer; function TPropertyEditor.GetVerbCount: Integer;
begin begin
Result:=0; Result:=0;
if paHasDefaultValue in GetAttributes then if HasDefaultValue then
inc(Result); // show a menu item for default value only if there is default value inc(Result); // show a menu item for default value only if there is default value
if IsRevertableToInherited then if IsRevertableToInherited then
inc(Result); // show a menu item for 'Revert to inherited' inc(Result); // show a menu item for 'Revert to inherited'
@ -3389,7 +3445,7 @@ var
i: Integer; i: Integer;
begin begin
i:=-1; i:=-1;
if paHasDefaultValue in GetAttributes then begin if HasDefaultValue then begin
inc(i); inc(i);
if i=Index then begin if i=Index then begin
Result := Format(oisSetToDefault, [GetDefaultValue]); Result := Format(oisSetToDefault, [GetDefaultValue]);
@ -3415,7 +3471,7 @@ var
i: Integer; i: Integer;
begin begin
i:=-1; i:=-1;
if paHasDefaultValue in GetAttributes then begin if HasDefaultValue then begin
inc(i); inc(i);
if i=Index then begin if i=Index then begin
SetValue(GetDefaultValue); SetValue(GetDefaultValue);
@ -3453,13 +3509,6 @@ begin
Result := 63; Result := 63;
end; end;
function TOrdinalPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result:=(inherited GetAttributes);
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end;
function TOrdinalPropertyEditor.GetValue: ansistring; function TOrdinalPropertyEditor.GetValue: ansistring;
begin begin
Result:=OrdValueToVisualValue(GetOrdValue); Result:=OrdValueToVisualValue(GetOrdValue);
@ -3568,8 +3617,6 @@ end;
function TEnumPropertyEditor.GetAttributes: TPropertyAttributes; function TEnumPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paSortList, paRevertable]; Result := [paMultiSelect, paValueList, paSortList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TEnumPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TEnumPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
@ -3919,8 +3966,6 @@ end;
function TSetElementPropertyEditor.GetAttributes: TPropertyAttributes; function TSetElementPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paSortList]; Result := [paMultiSelect, paValueList, paSortList];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TSetElementPropertyEditor.GetName: shortstring; function TSetElementPropertyEditor.GetName: shortstring;
@ -3968,17 +4013,20 @@ begin
SetOrdValue(Integer(S)); SetOrdValue(Integer(S));
end; end;
function TSetElementPropertyEditor.IsNotDefaultValue: boolean; function TSetElementPropertyEditor.IsDefaultValue: boolean;
var var
S1, S2: TIntegerSet; S1, S2: TIntegerSet;
begin begin
Result := (paHasDefaultValue in GetAttributes); if HasDefaultValue then
if Result then
begin begin
Integer(S1) := GetOrdValue; Integer(S1) := GetOrdValue;
Integer(S2) := GetDefaultOrdValue; Integer(S2) := GetDefaultOrdValue;
Result := (FElement in S1) <> (FElement in S2); Result := (FElement in S1) = (FElement in S2);
end; end else
if HasStoredFunction then
Result := not CallStoredFunction
else
Result := False;
end; end;
procedure TSetElementPropertyEditor.PropDrawValue(ACanvas: TCanvas; const ARect: TRect; procedure TSetElementPropertyEditor.PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
@ -3998,8 +4046,6 @@ end;
function TSetPropertyEditor.GetAttributes: TPropertyAttributes; function TSetPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paSubProperties, paReadOnly, paRevertable]; Result := [paMultiSelect, paSubProperties, paReadOnly, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TSetPropertyEditor.GetEditLimit: Integer; function TSetPropertyEditor.GetEditLimit: Integer;
@ -4419,6 +4465,12 @@ begin
Result:=True; // ToDo: Maybe all sub-properties should be compared for equality. Result:=True; // ToDo: Maybe all sub-properties should be compared for equality.
end; end;
destructor TClassPropertyEditor.Destroy;
begin
FSubProps.Free;
inherited Destroy;
end;
function TClassPropertyEditor.EditorFilter(const AEditor: TPropertyEditor): Boolean; function TClassPropertyEditor.EditorFilter(const AEditor: TPropertyEditor): Boolean;
begin begin
Result := IsInteresting(AEditor, SubPropsTypeFilter, SubPropsNameFilter); Result := IsInteresting(AEditor, SubPropsTypeFilter, SubPropsNameFilter);
@ -4463,6 +4515,31 @@ begin
if not FHideClassName then Result:='(' + GetPropType^.Name + ')'; if not FHideClassName then Result:='(' + GetPropType^.Name + ')';
end; end;
function TClassPropertyEditor.IsDefaultValue: boolean;
var
I: Integer;
begin
Result := inherited IsDefaultValue;
if Result then
Exit;
if FSubProps=nil then
begin
FSubProps := TObjectList.Create(True);
GetProperties(@ListSubProps);
end;
for I := 0 to FSubProps.Count-1 do
if not TPropertyEditor(FSubProps[I]).IsDefaultValue then
Exit(False);
Result := True;
end;
procedure TClassPropertyEditor.ListSubProps(Prop: TPropertyEditor);
begin
FSubProps.Add(Prop);
end;
procedure TClassPropertyEditor.SetSubPropsTypeFilter(const AValue: TTypeKinds); procedure TClassPropertyEditor.SetSubPropsTypeFilter(const AValue: TTypeKinds);
begin begin
if FSubPropsTypeFilter = AValue then exit; if FSubPropsTypeFilter = AValue then exit;
@ -5309,8 +5386,6 @@ end;
function TModalResultPropertyEditor.GetAttributes: TPropertyAttributes; function TModalResultPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paRevertable]; Result := [paMultiSelect, paValueList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TModalResultPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TModalResultPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
@ -5538,8 +5613,6 @@ end;
function TShortCutPropertyEditor.GetAttributes: TPropertyAttributes; function TShortCutPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paRevertable, paDialog]; Result := [paMultiSelect, paValueList, paRevertable, paDialog];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TShortCutPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TShortCutPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
@ -5686,8 +5759,6 @@ end;
function TCursorPropertyEditor.GetAttributes: TPropertyAttributes; function TCursorPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paSortList, paValueList, paRevertable]; Result := [paMultiSelect, paSortList, paValueList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TCursorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TCursorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;

View File

@ -2158,7 +2158,7 @@ end;
function TPropertyNamePropertyEditor.GetAttributes: TPropertyAttributes; function TPropertyNamePropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=[paMultiSelect,paValueList,paSortList,paRevertable,paHasDefaultValue]; Result:=[paMultiSelect,paValueList,paSortList,paRevertable];
end; end;
function TPropertyNamePropertyEditor.GetEditLimit: Integer; function TPropertyNamePropertyEditor.GetEditLimit: Integer;
@ -3861,7 +3861,7 @@ end;
function TTIElementNamePropertyEditor.GetAttributes: TPropertyAttributes; function TTIElementNamePropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result:=[paMultiSelect,paValueList,paSortList,paRevertable,paHasDefaultValue]; Result:=[paMultiSelect,paValueList,paSortList,paRevertable];
end; end;
function TTIElementNamePropertyEditor.GetEditLimit: Integer; function TTIElementNamePropertyEditor.GetEditLimit: Integer;

View File

@ -199,8 +199,6 @@ end;
function TSynKeyCommandPropertyEditor.GetAttributes: TPropertyAttributes; function TSynKeyCommandPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paRevertable]; Result := [paMultiSelect, paValueList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TSynKeyCommandPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TSynKeyCommandPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
@ -233,8 +231,6 @@ end;
function TSynMouseCommandPropertyEditor.GetAttributes: TPropertyAttributes; function TSynMouseCommandPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paRevertable]; Result := [paMultiSelect, paValueList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
function TSynMouseCommandPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string; function TSynMouseCommandPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;

View File

@ -31,8 +31,6 @@ end;
function TAxisIndexPropertyEditor.GetAttributes: TPropertyAttributes; function TAxisIndexPropertyEditor.GetAttributes: TPropertyAttributes;
begin begin
Result := [paMultiSelect, paValueList, paRevertable]; Result := [paMultiSelect, paValueList, paRevertable];
if GetDefaultOrdValue <> NoDefaultValue then
Result := Result + [paHasDefaultValue];
end; end;
procedure TAxisIndexPropertyEditor.GetValues(AProc: TGetStrProc); procedure TAxisIndexPropertyEditor.GetValues(AProc: TGetStrProc);