IDE: filter the all compiler options list properly using recursion.

git-svn-id: trunk@42114 -
This commit is contained in:
juha 2013-07-17 10:12:32 +00:00
parent a402774cac
commit b3e2c62f6b
2 changed files with 39 additions and 5 deletions

View File

@ -117,6 +117,7 @@ type
fDescription: string;
fIndentation: integer; // Indentation level in "fpc -h" output.
fOwnerGroup: TCompilerOptGroup;
fVisible: Boolean; // Used for filtering.
procedure ParseOption(aDescr: string; aIndent: integer);
protected
function GuessEditKind: TCompilerOptEditKind; virtual;
@ -128,6 +129,7 @@ type
property EditKind: TCompilerOptEditKind read fEditKind;
property Description: string read fDescription;
property Indentation: integer read fIndentation;
property Visible: Boolean read fVisible write fVisible;
end;
TCompilerOptList = TObjectList;
@ -180,6 +182,7 @@ type
constructor Create;
destructor Destroy; override;
function ReadAndParseOptions: TModalResult;
function FilterOptions(aFilter: string): Boolean;
public
property SupportedCategories: TStringList read fSupportedCategories;
property RootOptGroup: TCompilerOptGroup read fRootOptGroup;
@ -727,5 +730,36 @@ begin
end;
end;
function FilterOneOpt(aOpt: TCompilerOpt; aFilt: string): Boolean;
begin
Result := (aFilt='') or (Pos(aFilt,UTF8LowerCase(aOpt.Option))>0)
or (Pos(aFilt,UTF8LowerCase(aOpt.Description))>0);
end;
function TCompilerOptReader.FilterOptions(aFilter: string): Boolean;
// Filter all options recursively, setting their Visible flag as needed.
// Returns True if Option(group) or child options have visible items.
function FilterOptionsSub(aRoot: TCompilerOpt): Boolean;
var
Children: TCompilerOptList;
i: Integer;
begin
// Filter the root item
aRoot.Visible := FilterOneOpt(aRoot, aFilter);
// Filter children in a group
if aRoot is TCompilerOptGroup then
begin
Children := TCompilerOptGroup(aRoot).CompilerOpts;
for i := 0 to Children.Count-1 do // Recursive call for children.
aRoot.Visible := FilterOptionsSub(TCompilerOpt(Children[i])) or aRoot.Visible;
end;
Result := aRoot.Visible;
end;
begin
Result := FilterOptionsSub(fRootOptGroup);
end;
end.

View File

@ -198,10 +198,7 @@ var
begin
for i := 0 to aParentGroup.CompilerOpts.Count-1 do begin
Opt := TCompilerOpt(aParentGroup.CompilerOpts[i]);
if (edOptionsFilter.Text <> '')
and (Pos(edOptionsFilter.Text, Opt.Option) = 0)
and (Pos(edOptionsFilter.Text, Opt.Description) = 0) then Continue;
if not Opt.Visible then Continue; // Maybe filtered out
case Opt.EditKind of
oeNone: begin // Label
Cntrl := MakeHeaderLabel;
@ -254,13 +251,16 @@ begin
Container := sbAllOptions;
Container.DisableAutoSizing;
try
// First filter and set Visible flag.
FOptionsReader.FilterOptions(edOptionsFilter.Text);
// Then create and place new controls in GUI
FGeneratedControls.Clear;
// Create and place new controls
yLoc := 0;
RenderOneLevel(FOptionsReader.RootOptGroup);
FEffectiveFilter:=edOptionsFilter.Text;
finally
Container.EnableAutoSizing;
Container.Invalidate;
end;
end;