Can actions in TActionList be sorted in Delphi XE IDE?
When the number of actions in DXE IDE grows, in a single actionlist, it quickly becomes hard to locate the action you want to inspect or change.
There is no search / filter box like there is for components, and actions are not automatically sorted. Sorting action declarations in code does not alter the order in which they are displayed in the actionlist editor.
Not even incremental search works: if you focus the actionlist pane and start typing, the keypresses go to the o开发者_Go百科bject inspector (and you inadvertently change some property or other). Major annoyance!
Is there perhaps a hidden setting, a registry hack (there are quite a few for Delphi), or maybe a third-party extension that would keep actions sorted?
Write a small IDE plugin that extends the context menu of a TActionList with a Sort option. For sorting the actionlist you can use this code:
procedure SortActions(ActionList: TActionList);
var
act: TContainedAction;
arr: TArray<TContainedAction>;
I: Integer;
begin
SetLength(arr, ActionList.ActionCount);
for I := 0 to ActionList.ActionCount - 1 do begin
arr[I] := ActionList[I];
end;
TArray.Sort<TContainedAction>(arr,
TDelegatedComparer<TContainedAction>.Create(
function(const Left, Right: TContainedAction): Integer
begin
result := CompareText(Left.Name, Right.Name);
end));
for I := 0 to High(arr) do
arr[I].Index := I;
end;
You could sort them in the dfm file. You would want to write a little utility script to do it.
Or a workaround would be to use categories to make the list of actions more manageable.
精彩评论