mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 19:42:47 +02:00
IDEIntf: OI: implemented sorting sub properties
git-svn-id: trunk@15192 -
This commit is contained in:
parent
acc201bc8b
commit
f2fa3c549d
@ -93,7 +93,7 @@ type
|
|||||||
|
|
||||||
TOIFavouriteProperties = class
|
TOIFavouriteProperties = class
|
||||||
private
|
private
|
||||||
FItems: TList;
|
FItems: TFPList; // list of TOIFavouriteProperty
|
||||||
FModified: Boolean;
|
FModified: Boolean;
|
||||||
FSorted: Boolean;
|
FSorted: Boolean;
|
||||||
FDoublesDeleted: Boolean;
|
FDoublesDeleted: Boolean;
|
||||||
@ -236,18 +236,23 @@ type
|
|||||||
FWidgetSets: TLCLPlatforms;
|
FWidgetSets: TLCLPlatforms;
|
||||||
procedure GetLvl;
|
procedure GetLvl;
|
||||||
public
|
public
|
||||||
constructor Create(PropertyTree:TOICustomPropertyGrid;
|
constructor Create(PropertyTree: TOICustomPropertyGrid;
|
||||||
PropEditor:TPropertyEditor; ParentNode:TOIPropertyGridRow; WidgetSets: TLCLPlatforms);
|
PropEditor:TPropertyEditor; ParentNode:TOIPropertyGridRow; WidgetSets: TLCLPlatforms);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function ConsistencyCheck: integer;
|
function ConsistencyCheck: integer;
|
||||||
function HasChild(Row: TOIPropertyGridRow): boolean;
|
function HasChild(Row: TOIPropertyGridRow): boolean;
|
||||||
|
procedure WriteDebugReport(const Prefix: string);
|
||||||
public
|
public
|
||||||
Index:integer;
|
Index:integer;
|
||||||
LastPaintedValue:string;
|
LastPaintedValue: string;
|
||||||
function GetBottom:integer;
|
function GetBottom: integer;
|
||||||
function IsReadOnly: boolean;
|
function IsReadOnly: boolean;
|
||||||
function IsDisabled: boolean;
|
function IsDisabled: boolean;
|
||||||
procedure MeasureHeight(ACanvas: TCanvas);
|
procedure MeasureHeight(ACanvas: TCanvas);
|
||||||
|
function Sort(const Compare: TListSortCompare): boolean;// true if changed
|
||||||
|
function IsSorted(const Compare: TListSortCompare): boolean;
|
||||||
|
function Next: TOIPropertyGridRow;
|
||||||
|
function NextSkipChilds: TOIPropertyGridRow;
|
||||||
public
|
public
|
||||||
property Editor:TPropertyEditor read FEditor;
|
property Editor:TPropertyEditor read FEditor;
|
||||||
property Top:integer read FTop write FTop;
|
property Top:integer read FTop write FTop;
|
||||||
@ -301,7 +306,7 @@ type
|
|||||||
FCurrentEditorLookupRoot: TPersistent;
|
FCurrentEditorLookupRoot: TPersistent;
|
||||||
FDefaultItemHeight:integer;
|
FDefaultItemHeight:integer;
|
||||||
FDragging: boolean;
|
FDragging: boolean;
|
||||||
FExpandedProperties: TStringList;
|
FExpandedProperties: TStringList;// used to restore expanded state when switching selected component(s)
|
||||||
FExpandingRow: TOIPropertyGridRow;
|
FExpandingRow: TOIPropertyGridRow;
|
||||||
FFavourites: TOIFavouriteProperties;
|
FFavourites: TOIFavouriteProperties;
|
||||||
FFilter: TTypeKinds;
|
FFilter: TTypeKinds;
|
||||||
@ -312,7 +317,7 @@ type
|
|||||||
FOnModified: TNotifyEvent;
|
FOnModified: TNotifyEvent;
|
||||||
FPreferredSplitterX: integer; // best splitter position
|
FPreferredSplitterX: integer; // best splitter position
|
||||||
FPropertyEditorHook: TPropertyEditorHook;
|
FPropertyEditorHook: TPropertyEditorHook;
|
||||||
FRows: TList;
|
FRows: TFPList;// list of TOIPropertyGridRow
|
||||||
FSelection: TPersistentSelectionList;
|
FSelection: TPersistentSelectionList;
|
||||||
FNotificationComponents: TFPList;
|
FNotificationComponents: TFPList;
|
||||||
FSplitterX: integer; // current splitter position
|
FSplitterX: integer; // current splitter position
|
||||||
@ -362,6 +367,8 @@ type
|
|||||||
procedure ExpandRow(Index: integer);
|
procedure ExpandRow(Index: integer);
|
||||||
procedure ShrinkRow(Index: integer);
|
procedure ShrinkRow(Index: integer);
|
||||||
procedure AddSubEditor(PropEditor: TPropertyEditor);
|
procedure AddSubEditor(PropEditor: TPropertyEditor);
|
||||||
|
procedure SortSubEditors(ParentRow: TOIPropertyGridRow);
|
||||||
|
function CanExpandRow(Row: TOIPropertyGridRow): boolean;
|
||||||
|
|
||||||
procedure SetRowValue;
|
procedure SetRowValue;
|
||||||
procedure DoCallEdit;
|
procedure DoCallEdit;
|
||||||
@ -746,7 +753,8 @@ const
|
|||||||
|
|
||||||
function SortGridRows(Item1, Item2 : pointer) : integer;
|
function SortGridRows(Item1, Item2 : pointer) : integer;
|
||||||
begin
|
begin
|
||||||
Result:= AnsiCompareText(TOIPropertyGridRow(Item1).Name, TOIPropertyGridRow(Item2).Name);
|
Result:=SysUtils.CompareText(TOIPropertyGridRow(Item1).Name,
|
||||||
|
TOIPropertyGridRow(Item2).Name);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareOIFavouriteProperties(Data1, Data2: Pointer): integer;
|
function CompareOIFavouriteProperties(Data1, Data2: Pointer): integer;
|
||||||
@ -775,7 +783,7 @@ begin
|
|||||||
FFilter:=TypeFilter;
|
FFilter:=TypeFilter;
|
||||||
FItemIndex:=-1;
|
FItemIndex:=-1;
|
||||||
FStates:=[];
|
FStates:=[];
|
||||||
FRows:=TList.Create;
|
FRows:=TFPList.Create;
|
||||||
FExpandingRow:=nil;
|
FExpandingRow:=nil;
|
||||||
FDragging:=false;
|
FDragging:=false;
|
||||||
FExpandedProperties:=TStringList.Create;
|
FExpandedProperties:=TStringList.Create;
|
||||||
@ -1485,9 +1493,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TOICustomPropertyGrid.BuildPropertyList(OnlyIfNeeded: boolean);
|
procedure TOICustomPropertyGrid.BuildPropertyList(OnlyIfNeeded: boolean);
|
||||||
var a:integer;
|
var a: integer;
|
||||||
CurRow:TOIPropertyGridRow;
|
CurRow: TOIPropertyGridRow;
|
||||||
OldSelectedRowPath:string;
|
OldSelectedRowPath: string;
|
||||||
begin
|
begin
|
||||||
if OnlyIfNeeded and (not (pgsBuildPropertyListNeeded in FStates)) then exit;
|
if OnlyIfNeeded and (not (pgsBuildPropertyListNeeded in FStates)) then exit;
|
||||||
Exclude(FStates,pgsBuildPropertyListNeeded);
|
Exclude(FStates,pgsBuildPropertyListNeeded);
|
||||||
@ -1579,12 +1587,13 @@ var a:integer;
|
|||||||
begin
|
begin
|
||||||
FExpandingRow:=Rows[Index];
|
FExpandingRow:=Rows[Index];
|
||||||
if (FExpandingRow.Expanded)
|
if (FExpandingRow.Expanded)
|
||||||
or (not (paSubProperties in FExpandingRow.Editor.GetAttributes))
|
or (not CanExpandRow(FExpandingRow))
|
||||||
then begin
|
then begin
|
||||||
FExpandingRow:=nil;
|
FExpandingRow:=nil;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
FExpandingRow.Editor.GetProperties(@AddSubEditor);
|
FExpandingRow.Editor.GetProperties(@AddSubEditor);
|
||||||
|
SortSubEditors(FExpandingRow);
|
||||||
SetItemsTops;
|
SetItemsTops;
|
||||||
FExpandingRow.FExpanded:=true;
|
FExpandingRow.FExpanded:=true;
|
||||||
a:=0;
|
a:=0;
|
||||||
@ -1660,6 +1669,7 @@ var NewRow:TOIPropertyGridRow;
|
|||||||
begin
|
begin
|
||||||
NewRow:=TOIPropertyGridRow.Create(Self,PropEditor,FExpandingRow, []);
|
NewRow:=TOIPropertyGridRow.Create(Self,PropEditor,FExpandingRow, []);
|
||||||
NewIndex:=FExpandingRow.Index+1+FExpandingRow.ChildCount;
|
NewIndex:=FExpandingRow.Index+1+FExpandingRow.ChildCount;
|
||||||
|
NewRow.Index:=NewIndex;
|
||||||
FRows.Insert(NewIndex,NewRow);
|
FRows.Insert(NewIndex,NewRow);
|
||||||
if NewIndex<FItemIndex
|
if NewIndex<FItemIndex
|
||||||
then inc(FItemIndex);
|
then inc(FItemIndex);
|
||||||
@ -1672,6 +1682,33 @@ begin
|
|||||||
inc(FExpandingRow.FChildCount);
|
inc(FExpandingRow.FChildCount);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TOICustomPropertyGrid.SortSubEditors(ParentRow: TOIPropertyGridRow);
|
||||||
|
var
|
||||||
|
Item: TOIPropertyGridRow;
|
||||||
|
Index: Integer;
|
||||||
|
Next: TOIPropertyGridRow;
|
||||||
|
begin
|
||||||
|
if not ParentRow.Sort(@SortGridRows) then exit;
|
||||||
|
// update FRows
|
||||||
|
Item:=ParentRow.FirstChild;
|
||||||
|
Index:=ParentRow.Index+1;
|
||||||
|
Next:=ParentRow.NextSkipChilds;
|
||||||
|
while (Item<>nil) and (Item<>Next) do begin
|
||||||
|
FRows[Index]:=Item;
|
||||||
|
Item.Index:=Index;
|
||||||
|
Item:=Item.Next;
|
||||||
|
inc(Index);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TOICustomPropertyGrid.CanExpandRow(Row: TOIPropertyGridRow): boolean;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if (Row=nil) or (Row.Editor=nil) then exit;
|
||||||
|
if (not (paSubProperties in Row.Editor.GetAttributes)) then exit;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
function TOICustomPropertyGrid.MouseToIndex(y:integer;MustExist:boolean):integer;
|
function TOICustomPropertyGrid.MouseToIndex(y:integer;MustExist:boolean):integer;
|
||||||
var l,r,m:integer;
|
var l,r,m:integer;
|
||||||
begin
|
begin
|
||||||
@ -1798,7 +1835,7 @@ begin
|
|||||||
if (Index>=0) and (Index<FRows.Count) then
|
if (Index>=0) and (Index<FRows.Count) then
|
||||||
begin
|
begin
|
||||||
PointedRow:=Rows[Index];
|
PointedRow:=Rows[Index];
|
||||||
if paSubProperties in PointedRow.Editor.GetAttributes then
|
if CanExpandRow(PointedRow) then
|
||||||
begin
|
begin
|
||||||
IconX:=GetTreeIconX(Index);
|
IconX:=GetTreeIconX(Index);
|
||||||
if ((X>=IconX) and (X<=IconX+FIndent)) or (ssDouble in Shift) then
|
if ((X>=IconX) and (X<=IconX+FIndent)) or (ssDouble in Shift) then
|
||||||
@ -1940,7 +1977,7 @@ begin
|
|||||||
VK_RIGHT:
|
VK_RIGHT:
|
||||||
if ((FCurrentEdit = nil) or not FCurrentEdit.Focused)
|
if ((FCurrentEdit = nil) or not FCurrentEdit.Focused)
|
||||||
and (ItemIndex >= 0) and (not Rows[ItemIndex].Expanded)
|
and (ItemIndex >= 0) and (not Rows[ItemIndex].Expanded)
|
||||||
and (paSubProperties in Rows[ItemIndex].Editor.GetAttributes) then
|
and CanExpandRow(Rows[ItemIndex]) then
|
||||||
ExpandRow(ItemIndex)
|
ExpandRow(ItemIndex)
|
||||||
else
|
else
|
||||||
Handled:=false;
|
Handled:=false;
|
||||||
@ -2256,10 +2293,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// draw icon
|
// draw icon
|
||||||
if paSubProperties in CurRow.Editor.GetAttributes
|
if CanExpandRow(CurRow) then
|
||||||
then begin
|
|
||||||
DrawTreeIcon(IconX,IconY,not CurRow.Expanded);
|
DrawTreeIcon(IconX,IconY,not CurRow.Expanded);
|
||||||
end;
|
|
||||||
|
|
||||||
// draw name
|
// draw name
|
||||||
OldFont:=Font;
|
OldFont:=Font;
|
||||||
@ -2448,7 +2483,7 @@ end;
|
|||||||
procedure TOICustomPropertyGrid.SetItemsTops;
|
procedure TOICustomPropertyGrid.SetItemsTops;
|
||||||
// compute row tops from row heights
|
// compute row tops from row heights
|
||||||
// set indices of all rows
|
// set indices of all rows
|
||||||
var a,scrollmax:integer;
|
var a:integer;
|
||||||
begin
|
begin
|
||||||
for a:=0 to FRows.Count-1 do begin
|
for a:=0 to FRows.Count-1 do begin
|
||||||
Rows[a].Index:=a;
|
Rows[a].Index:=a;
|
||||||
@ -2458,12 +2493,6 @@ begin
|
|||||||
Rows[0].Top:=0;
|
Rows[0].Top:=0;
|
||||||
for a:=1 to FRows.Count-1 do
|
for a:=1 to FRows.Count-1 do
|
||||||
Rows[a].FTop:=Rows[a-1].Bottom + FRowSpacing;
|
Rows[a].FTop:=Rows[a-1].Bottom + FRowSpacing;
|
||||||
if FRows.Count>0 then
|
|
||||||
scrollmax:=Rows[FRows.Count-1].Bottom-Height
|
|
||||||
else
|
|
||||||
scrollmax:=0;
|
|
||||||
// always show something
|
|
||||||
if scrollmax<10 then scrollmax:=10;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TOICustomPropertyGrid.ClearRows;
|
procedure TOICustomPropertyGrid.ClearRows;
|
||||||
@ -2913,6 +2942,21 @@ begin
|
|||||||
Result:=false;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TOIPropertyGridRow.WriteDebugReport(const Prefix: string);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
Item: TOIPropertyGridRow;
|
||||||
|
begin
|
||||||
|
DebugLn([Prefix+'TOIPropertyGridRow.WriteDebugReport ',Name]);
|
||||||
|
i:=0;
|
||||||
|
Item:=FirstChild;
|
||||||
|
while Item<>nil do begin
|
||||||
|
DebugLn([Prefix+' ',i,' ',Item.Name]);
|
||||||
|
inc(i);
|
||||||
|
Item:=Item.NextBrother;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TOIPropertyGridRow.GetLvl;
|
procedure TOIPropertyGridRow.GetLvl;
|
||||||
var n:TOIPropertyGridRow;
|
var n:TOIPropertyGridRow;
|
||||||
begin
|
begin
|
||||||
@ -2957,6 +3001,80 @@ begin
|
|||||||
Editor.PropMeasureHeight(Name,ACanvas,FHeight);
|
Editor.PropMeasureHeight(Name,ACanvas,FHeight);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TOIPropertyGridRow.Sort(const Compare: TListSortCompare): boolean;
|
||||||
|
var
|
||||||
|
List: TFPList;
|
||||||
|
Item: TOIPropertyGridRow;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
if IsSorted(Compare) then exit(false);
|
||||||
|
List:=TFPList.Create;
|
||||||
|
try
|
||||||
|
// create a TFPList of the childs
|
||||||
|
List.Capacity:=ChildCount;
|
||||||
|
Item:=FirstChild;
|
||||||
|
while Item<>nil do begin
|
||||||
|
List.Add(Item);
|
||||||
|
Item:=Item.NextBrother;
|
||||||
|
end;
|
||||||
|
// sort the TFPList
|
||||||
|
List.Sort(Compare);
|
||||||
|
// sort in double linked list
|
||||||
|
for i:=0 to List.Count-1 do begin
|
||||||
|
Item:=TOIPropertyGridRow(List[i]);
|
||||||
|
if i=0 then begin
|
||||||
|
FFirstChild:=Item;
|
||||||
|
Item.FPriorBrother:=nil;
|
||||||
|
end else
|
||||||
|
Item.FPriorBrother:=TOIPropertyGridRow(List[i-1]);
|
||||||
|
if i=List.Count-1 then begin
|
||||||
|
FLastChild:=Item;
|
||||||
|
Item.FNextBrother:=nil;
|
||||||
|
end else
|
||||||
|
Item.FNextBrother:=TOIPropertyGridRow(List[i+1]);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
List.Free;
|
||||||
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TOIPropertyGridRow.IsSorted(const Compare: TListSortCompare): boolean;
|
||||||
|
var
|
||||||
|
Item1: TOIPropertyGridRow;
|
||||||
|
Item2: TOIPropertyGridRow;
|
||||||
|
begin
|
||||||
|
if ChildCount<2 then exit(true);
|
||||||
|
Item1:=FirstChild;
|
||||||
|
while true do begin
|
||||||
|
Item2:=Item1.NextBrother;
|
||||||
|
if Item2=nil then break;
|
||||||
|
if Compare(Item1,Item2)>0 then exit(false);
|
||||||
|
Item1:=Item2;
|
||||||
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TOIPropertyGridRow.Next: TOIPropertyGridRow;
|
||||||
|
begin
|
||||||
|
if fFirstChild<>nil then
|
||||||
|
Result:=fFirstChild
|
||||||
|
else
|
||||||
|
Result:=NextSkipChilds;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TOIPropertyGridRow.NextSkipChilds: TOIPropertyGridRow;
|
||||||
|
begin
|
||||||
|
Result:=Self;
|
||||||
|
while (Result<>nil) do begin
|
||||||
|
if Result.NextBrother<>nil then begin
|
||||||
|
Result:=Result.NextBrother;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result:=Result.Parent;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
|
|
||||||
@ -4350,7 +4468,7 @@ end;
|
|||||||
|
|
||||||
constructor TOIFavouriteProperties.Create;
|
constructor TOIFavouriteProperties.Create;
|
||||||
begin
|
begin
|
||||||
FItems:=TList.Create;
|
FItems:=TFPList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TOIFavouriteProperties.Destroy;
|
destructor TOIFavouriteProperties.Destroy;
|
||||||
@ -4662,7 +4780,7 @@ var
|
|||||||
CurItem: TOIFavouriteProperty;
|
CurItem: TOIFavouriteProperty;
|
||||||
cmp: LongInt;
|
cmp: LongInt;
|
||||||
begin
|
begin
|
||||||
Result:=TList. Create;
|
Result:=TList.Create;
|
||||||
DeleteDoubles; // this also sorts descending
|
DeleteDoubles; // this also sorts descending
|
||||||
FavouritesToSubtract.DeleteDoubles; // this also sorts descending
|
FavouritesToSubtract.DeleteDoubles; // this also sorts descending
|
||||||
SelfIndex:=0;
|
SelfIndex:=0;
|
||||||
|
@ -1397,8 +1397,8 @@ type
|
|||||||
|
|
||||||
// Global flags:
|
// Global flags:
|
||||||
var
|
var
|
||||||
GReferenceExpandable: Boolean;
|
GReferenceExpandable: Boolean = true;
|
||||||
GShowReadOnlyProps: Boolean;
|
GShowReadOnlyProps: Boolean = true;
|
||||||
|
|
||||||
// default Hook - set by IDE
|
// default Hook - set by IDE
|
||||||
var
|
var
|
||||||
@ -4062,7 +4062,7 @@ begin
|
|||||||
Result := Result + [paSubProperties, paVolatileSubProperties];
|
Result := Result + [paSubProperties, paVolatileSubProperties];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPersistentPropertyEditor.GetProperties(Proc:TGetPropEditProc);
|
procedure TPersistentPropertyEditor.GetProperties(Proc: TGetPropEditProc);
|
||||||
var
|
var
|
||||||
LPersistents: TPersistentSelectionList;
|
LPersistents: TPersistentSelectionList;
|
||||||
begin
|
begin
|
||||||
@ -6133,9 +6133,6 @@ end;
|
|||||||
|
|
||||||
procedure InitPropEdits;
|
procedure InitPropEdits;
|
||||||
begin
|
begin
|
||||||
GReferenceExpandable:=true;
|
|
||||||
GShowReadOnlyProps:=true;
|
|
||||||
|
|
||||||
PropertyClassList:=TList.Create;
|
PropertyClassList:=TList.Create;
|
||||||
PropertyEditorMapperList:=TList.Create;
|
PropertyEditorMapperList:=TList.Create;
|
||||||
// register the standard property editors
|
// register the standard property editors
|
||||||
|
Loading…
Reference in New Issue
Block a user