2007-12-07 15:33:00 +00:00
|
|
|
{: Implements the base filtering visitors.
|
|
|
|
|
|
|
|
Last changed: $Date$
|
|
|
|
Revision: $Rev$
|
|
|
|
Author: $Author$
|
|
|
|
}
|
|
|
|
unit BaseSwFilters;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
2009-05-01 08:44:18 +00:00
|
|
|
Masks,
|
2007-12-07 15:33:00 +00:00
|
|
|
|
|
|
|
BaseSwObjects;
|
|
|
|
|
|
|
|
type
|
|
|
|
TBaseSwItemFilter = class(TInterfacedPersistent, IBaseSwVisitor)
|
|
|
|
private
|
|
|
|
FList: TBaseSwItemList;
|
|
|
|
protected
|
|
|
|
// IBaseSwVisitor
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure VisitItem(const AItem: TBaseSwItem); virtual;
|
2007-12-07 15:33:00 +00:00
|
|
|
|
|
|
|
procedure FilterItem(const AItem: TBaseSwItem); virtual;
|
|
|
|
public
|
|
|
|
procedure FilterList(AList: TBaseSwItemList);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TBaseSwItemSimpleFilter = class(TBaseSwItemFilter)
|
|
|
|
private
|
|
|
|
FFilter: String;
|
2009-05-01 08:44:18 +00:00
|
|
|
FFilterMask: TMask;
|
|
|
|
FWildchars: Boolean;
|
2007-12-07 15:33:00 +00:00
|
|
|
|
2009-05-01 08:44:18 +00:00
|
|
|
function GetFilterMask(): TMask;
|
2007-12-07 15:33:00 +00:00
|
|
|
procedure SetFilter(const Value: String);
|
2009-05-01 08:44:18 +00:00
|
|
|
protected
|
|
|
|
property FilterMask: TMask read GetFilterMask;
|
2007-12-07 15:33:00 +00:00
|
|
|
public
|
2009-05-01 08:44:18 +00:00
|
|
|
property Filter: String read FFilter write SetFilter;
|
|
|
|
property Wildchars: Boolean read FWildchars write FWildchars;
|
2007-12-07 15:33:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TBaseSwItemSimpleNameFilter = class(TBaseSwItemSimpleFilter)
|
|
|
|
protected
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure VisitItem(const AItem: TBaseSwItem); override;
|
2007-12-07 15:33:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
SysUtils;
|
|
|
|
|
|
|
|
|
|
|
|
{ TBaseSwItemFilter }
|
|
|
|
procedure TBaseSwItemFilter.FilterList(AList: TBaseSwItemList);
|
|
|
|
begin
|
|
|
|
FList := AList;
|
|
|
|
try
|
|
|
|
FList.AcceptVisitor(Self);
|
|
|
|
finally
|
|
|
|
FList := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TBaseSwItemFilter.FilterItem(const AItem: TBaseSwItem);
|
|
|
|
begin
|
|
|
|
FList.Remove(AItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure TBaseSwItemFilter.VisitItem(const AItem: TBaseSwItem);
|
2007-12-07 15:33:00 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TBaseSwItemSimpleFilter }
|
2009-05-01 08:44:18 +00:00
|
|
|
function TBaseSwItemSimpleFilter.GetFilterMask(): TMask;
|
|
|
|
begin
|
|
|
|
if not Assigned(FFilterMask) then
|
|
|
|
FFilterMask := TMask.Create('*' + FFilter + '*');
|
|
|
|
|
|
|
|
Result := FFilterMask;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
procedure TBaseSwItemSimpleFilter.SetFilter(const Value: String);
|
2009-05-01 08:44:18 +00:00
|
|
|
var
|
|
|
|
newValue: string;
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
begin
|
2009-05-01 08:44:18 +00:00
|
|
|
newValue := LowerCase(Value);
|
|
|
|
if newValue <> FFilter then
|
|
|
|
begin
|
|
|
|
FFilter := newValue;
|
|
|
|
FreeAndNil(FFilterMask);
|
|
|
|
end;
|
2007-12-07 15:33:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TBaseSwItemSimpleNameFilter }
|
2007-12-09 12:02:11 +00:00
|
|
|
procedure TBaseSwItemSimpleNameFilter.VisitItem(const AItem: TBaseSwItem);
|
2009-05-01 08:44:18 +00:00
|
|
|
var
|
|
|
|
matches: Boolean;
|
|
|
|
itemName: string;
|
|
|
|
|
2007-12-07 15:33:00 +00:00
|
|
|
begin
|
2009-05-01 08:44:18 +00:00
|
|
|
if Length(Filter) > 0 then
|
|
|
|
begin
|
|
|
|
itemName := LowerCase(AItem.Name);
|
|
|
|
|
|
|
|
if Wildchars then
|
|
|
|
matches := FilterMask.Matches(itemName)
|
|
|
|
else
|
|
|
|
matches := (AnsiPos(Filter, itemName) > 0);
|
|
|
|
|
|
|
|
if not matches then
|
|
|
|
FilterItem(AItem);
|
|
|
|
end;
|
2007-12-07 15:33:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|