Added: filter options in Units dialog
Added: support for Project Source Added: dialog overrides View Form Added: dialog now actually activates the unit Changed: refactored filters to use Visitor pattern Note: requires at least Delphi 7
This commit is contained in:
parent
4e7456ac74
commit
27a1a5023f
@ -34,6 +34,7 @@ requires
|
|||||||
contains
|
contains
|
||||||
UnSwClient in '..\..\Source\UnSwClient.pas',
|
UnSwClient in '..\..\Source\UnSwClient.pas',
|
||||||
UnSwObjects in '..\..\Source\UnSwObjects.pas',
|
UnSwObjects in '..\..\Source\UnSwObjects.pas',
|
||||||
UnSwDialog in '..\..\Source\UnSwDialog.pas' {frmUnSwDialog};
|
UnSwDialog in '..\..\Source\UnSwDialog.pas' {frmUnSwDialog},
|
||||||
|
UnSwFilters in '..\..\Source\UnSwFilters.pas';
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -16,9 +16,12 @@ uses
|
|||||||
type
|
type
|
||||||
TUnitSwitcherHook = class(TObject)
|
TUnitSwitcherHook = class(TObject)
|
||||||
private
|
private
|
||||||
FOldExecute: TNotifyEvent;
|
FOldUnitExecute: TNotifyEvent;
|
||||||
|
FOldFormExecute: TNotifyEvent;
|
||||||
FViewUnitAction: TContainedAction;
|
FViewUnitAction: TContainedAction;
|
||||||
|
FViewFormAction: TContainedAction;
|
||||||
protected
|
protected
|
||||||
|
function ActiveFileName(): String;
|
||||||
procedure NewExecute(Sender: TObject); virtual;
|
procedure NewExecute(Sender: TObject); virtual;
|
||||||
public
|
public
|
||||||
constructor Create();
|
constructor Create();
|
||||||
@ -48,15 +51,21 @@ begin
|
|||||||
pAction := ifNTA.ActionList.Actions[iAction];
|
pAction := ifNTA.ActionList.Actions[iAction];
|
||||||
if pAction.Name = 'ViewUnitCommand' then
|
if pAction.Name = 'ViewUnitCommand' then
|
||||||
begin
|
begin
|
||||||
FOldExecute := pAction.OnExecute;
|
FOldUnitExecute := pAction.OnExecute;
|
||||||
pAction.OnExecute := NewExecute;
|
pAction.OnExecute := NewExecute;
|
||||||
FViewUnitAction := pAction;
|
FViewUnitAction := pAction;
|
||||||
break;
|
end else if pAction.Name = 'ViewFormCommand' then
|
||||||
|
begin
|
||||||
|
FOldFormExecute := pAction.OnExecute;
|
||||||
|
pAction.OnExecute := NewExecute;
|
||||||
|
FViewFormAction := pAction;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Assert(Assigned(FViewUnitAction), 'ViewUnitCommand action is not' +
|
Assert(Assigned(FViewUnitAction), 'ViewUnitCommand action is not' +
|
||||||
'available in the IDE.');
|
'available in the IDE.');
|
||||||
|
Assert(Assigned(FViewFormAction), 'ViewFormCommand action is not' +
|
||||||
|
'available in the IDE.');
|
||||||
except
|
except
|
||||||
on E:EAssertionFailed do
|
on E:EAssertionFailed do
|
||||||
ShowMessage('Error while loading UnitSwitcher: ' + E.Message);
|
ShowMessage('Error while loading UnitSwitcher: ' + E.Message);
|
||||||
@ -65,30 +74,59 @@ end;
|
|||||||
|
|
||||||
destructor TUnitSwitcherHook.Destroy();
|
destructor TUnitSwitcherHook.Destroy();
|
||||||
begin
|
begin
|
||||||
|
if Assigned(FViewFormAction) then
|
||||||
|
FViewFormAction.OnExecute := FOldFormExecute;
|
||||||
|
|
||||||
if Assigned(FViewUnitAction) then
|
if Assigned(FViewUnitAction) then
|
||||||
FViewUnitAction.OnExecute := FOldExecute;
|
FViewUnitAction.OnExecute := FOldUnitExecute;
|
||||||
|
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TUnitSwitcherHook.ActiveFileName(): String;
|
||||||
|
var
|
||||||
|
ifModule: IOTAModule;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
ifModule := (BorlandIDEServices as IOTAModuleServices).CurrentModule;
|
||||||
|
if Assigned(ifModule) then
|
||||||
|
begin
|
||||||
|
if Assigned(ifModule.CurrentEditor) then
|
||||||
|
Result := ifModule.FileName;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TUnitSwitcherHook.NewExecute(Sender: TObject);
|
procedure TUnitSwitcherHook.NewExecute(Sender: TObject);
|
||||||
var
|
var
|
||||||
|
iActive: Integer;
|
||||||
|
ifProject: IOTAProject;
|
||||||
iModule: Integer;
|
iModule: Integer;
|
||||||
pProject: IOTAProject;
|
pActive: TUnSwUnit;
|
||||||
pUnits: TUnSwUnitList;
|
pUnits: TUnSwUnitList;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
pProject := (BorlandIDEServices as IOTAModuleServices).GetActiveProject;
|
ifProject := (BorlandIDEServices as IOTAModuleServices).GetActiveProject;
|
||||||
if not Assigned(pProject) then
|
if not Assigned(ifProject) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
pUnits := TUnSwUnitList.Create();
|
pUnits := TUnSwUnitList.Create();
|
||||||
try
|
try
|
||||||
for iModule := 0 to Pred(pProject.GetModuleCount) do
|
pUnits.Add(TUnSwProjectUnit.Create(ifProject));
|
||||||
pUnits.Add(TUnSwUnit.Create(pProject.GetModule(iModule)));
|
|
||||||
|
|
||||||
TfrmUnSwDialog.Execute(pUnits);
|
for iModule := 0 to Pred(ifProject.GetModuleCount) do
|
||||||
|
pUnits.Add(TUnSwModuleUnit.Create(ifProject.GetModule(iModule)));
|
||||||
|
|
||||||
|
pActive := nil;
|
||||||
|
iActive := pUnits.IndexOfFileName(ActiveFileName());
|
||||||
|
if iActive > -1 then
|
||||||
|
pActive := pUnits[iActive];
|
||||||
|
|
||||||
|
pActive := TfrmUnSwDialog.Execute(pUnits, (Sender = FViewFormAction),
|
||||||
|
pActive);
|
||||||
|
if Assigned(pActive) then
|
||||||
|
pActive.Activate((Sender = FViewUnitAction));
|
||||||
finally
|
finally
|
||||||
FreeAndNil(pUnits);
|
FreeAndNil(pUnits);
|
||||||
end;
|
end;
|
||||||
|
@ -3,7 +3,7 @@ object frmUnSwDialog: TfrmUnSwDialog
|
|||||||
Top = 83
|
Top = 83
|
||||||
BorderIcons = [biSystemMenu]
|
BorderIcons = [biSystemMenu]
|
||||||
Caption = 'UnitSwitcher - it almosts makes coffee.'
|
Caption = 'UnitSwitcher - it almosts makes coffee.'
|
||||||
ClientHeight = 387
|
ClientHeight = 427
|
||||||
ClientWidth = 299
|
ClientWidth = 299
|
||||||
Color = clBtnFace
|
Color = clBtnFace
|
||||||
Font.Charset = DEFAULT_CHARSET
|
Font.Charset = DEFAULT_CHARSET
|
||||||
@ -17,7 +17,7 @@ object frmUnSwDialog: TfrmUnSwDialog
|
|||||||
TextHeight = 13
|
TextHeight = 13
|
||||||
object sbStatus: TStatusBar
|
object sbStatus: TStatusBar
|
||||||
Left = 0
|
Left = 0
|
||||||
Top = 368
|
Top = 408
|
||||||
Width = 299
|
Width = 299
|
||||||
Height = 19
|
Height = 19
|
||||||
Panels = <
|
Panels = <
|
||||||
@ -29,11 +29,11 @@ object frmUnSwDialog: TfrmUnSwDialog
|
|||||||
Left = 0
|
Left = 0
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 299
|
Width = 299
|
||||||
Height = 334
|
Height = 317
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
BorderWidth = 4
|
BorderWidth = 4
|
||||||
TabOrder = 1
|
TabOrder = 0
|
||||||
ExplicitWidth = 297
|
ExplicitWidth = 297
|
||||||
ExplicitHeight = 368
|
ExplicitHeight = 368
|
||||||
object pnlSearch: TPanel
|
object pnlSearch: TPanel
|
||||||
@ -59,7 +59,7 @@ object frmUnSwDialog: TfrmUnSwDialog
|
|||||||
Left = 4
|
Left = 4
|
||||||
Top = 29
|
Top = 29
|
||||||
Width = 291
|
Width = 291
|
||||||
Height = 301
|
Height = 284
|
||||||
Style = lbVirtualOwnerDraw
|
Style = lbVirtualOwnerDraw
|
||||||
Align = alClient
|
Align = alClient
|
||||||
ItemHeight = 20
|
ItemHeight = 20
|
||||||
@ -68,38 +68,74 @@ object frmUnSwDialog: TfrmUnSwDialog
|
|||||||
OnDrawItem = lstUnitsDrawItem
|
OnDrawItem = lstUnitsDrawItem
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object Panel1: TPanel
|
object pnlButtons: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Top = 334
|
Top = 372
|
||||||
Width = 299
|
Width = 299
|
||||||
Height = 34
|
Height = 36
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
TabOrder = 2
|
TabOrder = 2
|
||||||
DesignSize = (
|
DesignSize = (
|
||||||
299
|
299
|
||||||
34)
|
36)
|
||||||
object btnCancel: TButton
|
object btnCancel: TButton
|
||||||
Left = 220
|
Left = 220
|
||||||
Top = 2
|
Top = 5
|
||||||
Width = 75
|
Width = 75
|
||||||
Height = 25
|
Height = 25
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akRight, akBottom]
|
||||||
Cancel = True
|
Cancel = True
|
||||||
Caption = 'Cancel'
|
Caption = 'Cancel'
|
||||||
ModalResult = 2
|
ModalResult = 2
|
||||||
TabOrder = 0
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
object btnOK: TButton
|
object btnOK: TButton
|
||||||
Left = 139
|
Left = 139
|
||||||
Top = 2
|
Top = 5
|
||||||
Width = 75
|
Width = 75
|
||||||
Height = 25
|
Height = 25
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akRight, akBottom]
|
||||||
Caption = 'OK'
|
Caption = 'OK'
|
||||||
Default = True
|
Default = True
|
||||||
ModalResult = 1
|
ModalResult = 1
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object pnlIncludeTypes: TPanel
|
||||||
|
Left = 0
|
||||||
|
Top = 317
|
||||||
|
Width = 299
|
||||||
|
Height = 55
|
||||||
|
Align = alBottom
|
||||||
|
BevelOuter = bvNone
|
||||||
|
TabOrder = 1
|
||||||
|
object chkDataModules: TCheckBox
|
||||||
|
Left = 4
|
||||||
|
Top = 19
|
||||||
|
Width = 291
|
||||||
|
Height = 17
|
||||||
|
Caption = 'Show &DataModule units'
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
|
OnClick = TypeFilterChange
|
||||||
|
end
|
||||||
|
object chkForms: TCheckBox
|
||||||
|
Left = 4
|
||||||
|
Top = 2
|
||||||
|
Width = 291
|
||||||
|
Height = 17
|
||||||
|
Caption = 'Show &Form units'
|
||||||
|
TabOrder = 0
|
||||||
|
OnClick = TypeFilterChange
|
||||||
|
end
|
||||||
|
object chkProjectSource: TCheckBox
|
||||||
|
Left = 4
|
||||||
|
Top = 36
|
||||||
|
Width = 291
|
||||||
|
Height = 17
|
||||||
|
Caption = 'Show &Project source'
|
||||||
|
TabOrder = 2
|
||||||
|
OnClick = TypeFilterChange
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object ilsTypes: TImageList
|
object ilsTypes: TImageList
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
unit UnSwDialog;
|
unit UnSwDialog;
|
||||||
|
|
||||||
|
// #ToDo1 Store dialog settings
|
||||||
|
|
||||||
interface
|
interface
|
||||||
uses
|
uses
|
||||||
Classes,
|
Classes,
|
||||||
@ -11,19 +13,35 @@ uses
|
|||||||
StdCtrls,
|
StdCtrls,
|
||||||
Windows,
|
Windows,
|
||||||
|
|
||||||
UnSwObjects;
|
UnSwObjects,
|
||||||
|
UnSwFilters;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
TUnSwIconVisitor = class(TUnSwNoRefIntfObject, IUnSwVisitor)
|
||||||
|
private
|
||||||
|
FImageIndex: Integer;
|
||||||
|
protected
|
||||||
|
procedure VisitModule(const AUnit: TUnSwModuleUnit);
|
||||||
|
procedure VisitProject(const AUnit: TUnSwProjectUnit);
|
||||||
|
public
|
||||||
|
property ImageIndex: Integer read FImageIndex;
|
||||||
|
end;
|
||||||
|
|
||||||
TfrmUnSwDialog = class(TForm)
|
TfrmUnSwDialog = class(TForm)
|
||||||
|
btnCancel: TButton;
|
||||||
|
btnOK: TButton;
|
||||||
edtSearch: TEdit;
|
edtSearch: TEdit;
|
||||||
ilsTypes: TImageList;
|
ilsTypes: TImageList;
|
||||||
lstUnits: TListBox;
|
lstUnits: TListBox;
|
||||||
|
pnlButtons: TPanel;
|
||||||
pnlMain: TPanel;
|
pnlMain: TPanel;
|
||||||
pnlSearch: TPanel;
|
pnlSearch: TPanel;
|
||||||
sbStatus: TStatusBar;
|
sbStatus: TStatusBar;
|
||||||
Panel1: TPanel;
|
chkForms: TCheckBox;
|
||||||
btnCancel: TButton;
|
chkDataModules: TCheckBox;
|
||||||
btnOK: TButton;
|
chkProjectSource: TCheckBox;
|
||||||
|
pnlIncludeTypes: TPanel;
|
||||||
|
procedure TypeFilterChange(Sender: TObject);
|
||||||
|
|
||||||
procedure edtSearchChange(Sender: TObject);
|
procedure edtSearchChange(Sender: TObject);
|
||||||
procedure edtSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
procedure edtSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||||
@ -31,18 +49,26 @@ type
|
|||||||
procedure lstUnitsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
procedure lstUnitsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
||||||
private
|
private
|
||||||
FUnitList: TUnSwUnitList;
|
FUnitList: TUnSwUnitList;
|
||||||
|
FActiveUnit: TUnSwUnit;
|
||||||
|
FFormsOnly: Boolean;
|
||||||
|
|
||||||
FTypeFilteredList: TUnSwUnitList;
|
FTypeFilteredList: TUnSwUnitList;
|
||||||
FInputFilteredList: TUnSwUnitList;
|
FInputFilteredList: TUnSwUnitList;
|
||||||
|
|
||||||
FTypeFilter: TUnSwUnitTypeFilter;
|
FTypeFilter: TUnSwUnitTypeFilter;
|
||||||
FInputFilter: TUnSwUnitSimpleFilter;
|
FInputFilter: TUnSwUnitSimpleFilter;
|
||||||
|
|
||||||
function InternalExecute(const AUnits: TUnSwUnitList): Integer;
|
FIconVisitor: TUnSwIconVisitor;
|
||||||
|
|
||||||
|
function InternalExecute(): TUnSwUnit;
|
||||||
|
procedure UpdateTypeFilter();
|
||||||
procedure UpdateList();
|
procedure UpdateList();
|
||||||
|
|
||||||
function GetActiveUnit(): TUnSwUnit;
|
function GetActiveUnit(): TUnSwUnit;
|
||||||
public
|
public
|
||||||
class function Execute(const AUnits: TUnSwUnitList): Integer;
|
class function Execute(const AUnits: TUnSwUnitList;
|
||||||
|
const AFormsOnly: Boolean;
|
||||||
|
const AActive: TUnSwUnit = nil): TUnSwUnit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -50,41 +76,74 @@ uses
|
|||||||
SysUtils,
|
SysUtils,
|
||||||
Graphics;
|
Graphics;
|
||||||
|
|
||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwIconVisitor }
|
||||||
|
procedure TUnSwIconVisitor.VisitModule(const AUnit: TUnSwModuleUnit);
|
||||||
|
begin
|
||||||
|
case AUnit.UnitType of
|
||||||
|
swutForm: FImageIndex := 1;
|
||||||
|
swutDataModule: FImageIndex := 2;
|
||||||
|
else
|
||||||
|
FImageIndex := 0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwIconVisitor.VisitProject(const AUnit: TUnSwProjectUnit);
|
||||||
|
begin
|
||||||
|
FImageIndex := 3;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TfrmUnSwDialog }
|
{ TfrmUnSwDialog }
|
||||||
class function TfrmUnSwDialog.Execute(const AUnits: TUnSwUnitList): Integer;
|
class function TfrmUnSwDialog.Execute(const AUnits: TUnSwUnitList;
|
||||||
|
const AFormsOnly: Boolean;
|
||||||
|
const AActive: TUnSwUnit): TUnSwUnit;
|
||||||
begin
|
begin
|
||||||
with Self.Create(nil) do
|
with Self.Create(nil) do
|
||||||
try
|
try
|
||||||
Result := InternalExecute(AUnits);
|
FUnitList := AUnits;
|
||||||
|
FActiveUnit := AActive;
|
||||||
|
FFormsOnly := AFormsOnly;
|
||||||
|
Result := InternalExecute();
|
||||||
finally
|
finally
|
||||||
Free();
|
Free();
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function SortByName(Item1, Item2: Pointer): Integer;
|
function SortByName(Item1, Item2: Pointer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := CompareText(TUnSwUnit(Item1).Name, TUnSwUnit(Item2).Name)
|
Result := CompareText(TUnSwUnit(Item1).Name, TUnSwUnit(Item2).Name)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TfrmUnSwDialog.InternalExecute(const AUnits: TUnSwUnitList): Integer;
|
function TfrmUnSwDialog.InternalExecute(): TUnSwUnit;
|
||||||
begin
|
begin
|
||||||
Result := -1;
|
Result := nil;
|
||||||
FUnitList := AUnits;
|
|
||||||
|
if not FFormsOnly then
|
||||||
|
begin
|
||||||
|
chkForms.Checked := FTypeFilter.IncludeForms;
|
||||||
|
chkDataModules.Checked := FTypeFilter.IncludeDataModules;
|
||||||
|
chkProjectSource.Checked := FTypeFilter.IncludeProjectSource;
|
||||||
|
end else
|
||||||
|
pnlIncludeTypes.Visible := False;
|
||||||
|
|
||||||
FTypeFilteredList := TUnSwUnitList.Create();
|
FTypeFilteredList := TUnSwUnitList.Create();
|
||||||
FInputFilteredList := TUnSwUnitList.Create();
|
FInputFilteredList := TUnSwUnitList.Create();
|
||||||
FTypeFilter := TUnSwUnitTypeFilter.Create();
|
FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList);
|
||||||
FInputFilter := TUnSwUnitSimpleFilter.Create();
|
FInputFilter := TUnSwUnitSimpleFilter.Create(FInputFilteredList);
|
||||||
try
|
try
|
||||||
FTypeFilteredList.Clone(FUnitList);
|
UpdateTypeFilter();
|
||||||
FTypeFilteredList.ApplyFilter(FTypeFilter);
|
|
||||||
FTypeFilteredList.Sort(SortByName);
|
|
||||||
UpdateList();
|
|
||||||
|
|
||||||
Self.ShowModal();
|
FIconVisitor := TUnSwIconVisitor.Create();
|
||||||
|
try
|
||||||
|
if Self.ShowModal() = mrOk then
|
||||||
|
Result := GetActiveUnit();
|
||||||
|
finally
|
||||||
|
FreeAndNil(FIconVisitor);
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
FreeAndNil(FInputFilter);
|
FreeAndNil(FInputFilter);
|
||||||
FreeAndNil(FTypeFilter);
|
FreeAndNil(FTypeFilter);
|
||||||
@ -99,10 +158,9 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
pActive := GetActiveUnit();
|
pActive := GetActiveUnit();
|
||||||
// #ToDo1 Try to select the previous unit, otherwise select the first
|
|
||||||
|
|
||||||
FInputFilteredList.Clone(FTypeFilteredList);
|
FInputFilteredList.Clone(FTypeFilteredList);
|
||||||
FInputFilteredList.ApplyFilter(FInputFilter);
|
FInputFilteredList.AcceptVisitor(FInputFilter);
|
||||||
|
|
||||||
lstUnits.Count := FInputFilteredList.Count;
|
lstUnits.Count := FInputFilteredList.Count;
|
||||||
if FInputFilteredList.Count > 0 then
|
if FInputFilteredList.Count > 0 then
|
||||||
@ -115,11 +173,28 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TfrmUnSwDialog.UpdateTypeFilter();
|
||||||
|
begin
|
||||||
|
FTypeFilter.IncludeUnits := not FFormsOnly;
|
||||||
|
FTypeFilter.IncludeForms := (FFormsOnly or chkForms.Checked);
|
||||||
|
FTypeFilter.IncludeDataModules := ((not FFormsOnly) and chkDataModules.Checked);
|
||||||
|
FTypeFilter.IncludeProjectSource := ((not FFormsOnly) and chkProjectSource.Checked);
|
||||||
|
|
||||||
|
FTypeFilteredList.Clone(FUnitList);
|
||||||
|
FTypeFilteredList.AcceptVisitor(FTypeFilter);
|
||||||
|
FTypeFilteredList.Sort(SortByName);
|
||||||
|
UpdateList();
|
||||||
|
end;
|
||||||
|
|
||||||
function TfrmUnSwDialog.GetActiveUnit(): TUnSwUnit;
|
function TfrmUnSwDialog.GetActiveUnit(): TUnSwUnit;
|
||||||
begin
|
begin
|
||||||
Result := nil;
|
Result := FActiveUnit;
|
||||||
if lstUnits.ItemIndex > -1 then
|
if not Assigned(Result) then
|
||||||
Result := FInputFilteredList[lstUnits.ItemIndex];
|
begin
|
||||||
|
if lstUnits.ItemIndex > -1 then
|
||||||
|
Result := FInputFilteredList[lstUnits.ItemIndex];
|
||||||
|
end else
|
||||||
|
FActiveUnit := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject);
|
procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject);
|
||||||
@ -134,14 +209,26 @@ begin
|
|||||||
if Shift = [] then
|
if Shift = [] then
|
||||||
case Key of
|
case Key of
|
||||||
VK_UP:
|
VK_UP:
|
||||||
if lstUnits.ItemIndex > 0 then
|
begin
|
||||||
lstUnits.ItemIndex := Pred(lstUnits.ItemIndex);
|
if lstUnits.ItemIndex > 0 then
|
||||||
|
lstUnits.ItemIndex := Pred(lstUnits.ItemIndex);
|
||||||
|
|
||||||
|
Key := 0;
|
||||||
|
end;
|
||||||
VK_DOWN:
|
VK_DOWN:
|
||||||
if lstUnits.ItemIndex < Pred(lstUnits.Items.Count) then
|
begin
|
||||||
lstUnits.ItemIndex := Succ(lstUnits.ItemIndex);
|
if lstUnits.ItemIndex < Pred(lstUnits.Items.Count) then
|
||||||
|
lstUnits.ItemIndex := Succ(lstUnits.ItemIndex);
|
||||||
|
|
||||||
|
Key := 0;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
UpdateTypeFilter();
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TfrmUnSwDialog.lstUnitsData(Control: TWinControl; Index: Integer;
|
procedure TfrmUnSwDialog.lstUnitsData(Control: TWinControl; Index: Integer;
|
||||||
var Data: string);
|
var Data: string);
|
||||||
@ -152,13 +239,15 @@ end;
|
|||||||
procedure TfrmUnSwDialog.lstUnitsDrawItem(Control: TWinControl; Index: Integer;
|
procedure TfrmUnSwDialog.lstUnitsDrawItem(Control: TWinControl; Index: Integer;
|
||||||
Rect: TRect; State: TOwnerDrawState);
|
Rect: TRect; State: TOwnerDrawState);
|
||||||
var
|
var
|
||||||
iIcon: Integer;
|
pUnit: TUnSwUnit;
|
||||||
rText: TRect;
|
rText: TRect;
|
||||||
sText: String;
|
sText: String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
with TListBox(Control) do
|
with TListBox(Control) do
|
||||||
begin
|
begin
|
||||||
|
pUnit := FInputFilteredList[Index];
|
||||||
|
|
||||||
if odSelected in State then
|
if odSelected in State then
|
||||||
begin
|
begin
|
||||||
Canvas.Brush.Color := clHighlight;
|
Canvas.Brush.Color := clHighlight;
|
||||||
@ -173,16 +262,11 @@ begin
|
|||||||
rText := Rect;
|
rText := Rect;
|
||||||
InflateRect(rText, -2, -2);
|
InflateRect(rText, -2, -2);
|
||||||
|
|
||||||
iIcon := 0;
|
pUnit.AcceptVisitor(FIconVisitor);
|
||||||
case FInputFilteredList[Index].UnitType of
|
ilsTypes.Draw(Canvas, rText.Left, rText.Top, FIconVisitor.ImageIndex);
|
||||||
swutForm: iIcon := 1;
|
|
||||||
swutDataModule: iIcon := 2;
|
|
||||||
swutProjUnit: iIcon := 3;
|
|
||||||
end;
|
|
||||||
ilsTypes.Draw(Canvas, rText.Left, rText.Top, iIcon);
|
|
||||||
|
|
||||||
Inc(rText.Left, ilsTypes.Width + 4);
|
Inc(rText.Left, ilsTypes.Width + 4);
|
||||||
sText := FInputFilteredList[Index].Name;
|
sText := pUnit.Name;
|
||||||
DrawText(Canvas.Handle, PChar(sText), Length(sText), rText, DT_SINGLELINE or
|
DrawText(Canvas.Handle, PChar(sText), Length(sText), rText, DT_SINGLELINE or
|
||||||
DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS);
|
DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS);
|
||||||
end;
|
end;
|
||||||
|
137
Source/UnSwFilters.pas
Normal file
137
Source/UnSwFilters.pas
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
unit UnSwFilters;
|
||||||
|
|
||||||
|
interface
|
||||||
|
uses
|
||||||
|
UnSwObjects;
|
||||||
|
|
||||||
|
type
|
||||||
|
TUnSwUnitFilter = class(TUnSwNoRefIntfObject, IUnSwVisitor)
|
||||||
|
private
|
||||||
|
FList: TUnSwUnitList;
|
||||||
|
protected
|
||||||
|
// Called by default by all other Visit methods
|
||||||
|
procedure VisitUnit(const AUnit: TUnSwUnit); virtual;
|
||||||
|
|
||||||
|
procedure VisitModule(const AUnit: TUnSwModuleUnit); virtual;
|
||||||
|
procedure VisitProject(const AUnit: TUnSwProjectUnit); virtual;
|
||||||
|
|
||||||
|
procedure FilterUnit(const AUnit: TUnSwUnit); virtual;
|
||||||
|
public
|
||||||
|
constructor Create(const AList: TUnSwUnitList); virtual;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TUnSwUnitSimpleFilter = class(TUnSwUnitFilter)
|
||||||
|
private
|
||||||
|
FFilter: String;
|
||||||
|
|
||||||
|
procedure SetFilter(const Value: String);
|
||||||
|
protected
|
||||||
|
procedure VisitUnit(const AUnit: TUnSwUnit); override;
|
||||||
|
public
|
||||||
|
property Filter: String read FFilter write SetFilter;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TUnSwUnitTypeFilter = class(TUnSwUnitFilter)
|
||||||
|
private
|
||||||
|
FIncludeDataModules: Boolean;
|
||||||
|
FIncludeForms: Boolean;
|
||||||
|
FIncludeProjectSource: Boolean;
|
||||||
|
FIncludeUnits: Boolean;
|
||||||
|
protected
|
||||||
|
procedure VisitModule(const AUnit: TUnSwModuleUnit); override;
|
||||||
|
procedure VisitProject(const AUnit: TUnSwProjectUnit); override;
|
||||||
|
public
|
||||||
|
constructor Create(const AList: TUnSwUnitList); override;
|
||||||
|
|
||||||
|
property IncludeDataModules: Boolean read FIncludeDataModules write FIncludeDataModules;
|
||||||
|
property IncludeForms: Boolean read FIncludeForms write FIncludeForms;
|
||||||
|
property IncludeProjectSource: Boolean read FIncludeProjectSource write FIncludeProjectSource;
|
||||||
|
property IncludeUnits: Boolean read FIncludeUnits write FIncludeUnits;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
uses
|
||||||
|
SysUtils;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwUnitFilter }
|
||||||
|
constructor TUnSwUnitFilter.Create(const AList: TUnSwUnitList);
|
||||||
|
begin
|
||||||
|
inherited Create();
|
||||||
|
|
||||||
|
Assert(Assigned(AList), 'List must be assigned.');
|
||||||
|
FList := AList;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitFilter.VisitUnit(const AUnit: TUnSwUnit);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitFilter.VisitModule(const AUnit: TUnSwModuleUnit);
|
||||||
|
begin
|
||||||
|
VisitUnit(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitFilter.VisitProject(const AUnit: TUnSwProjectUnit);
|
||||||
|
begin
|
||||||
|
VisitUnit(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitFilter.FilterUnit(const AUnit: TUnSwUnit);
|
||||||
|
begin
|
||||||
|
FList.Remove(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwUnitSimpleFilter }
|
||||||
|
procedure TUnSwUnitSimpleFilter.VisitUnit(const AUnit: TUnSwUnit);
|
||||||
|
begin
|
||||||
|
if (Length(FFilter) > 0) and
|
||||||
|
(AnsiPos(FFilter, LowerCase(AUnit.Name)) = 0) then
|
||||||
|
FilterUnit(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitSimpleFilter.SetFilter(const Value: String);
|
||||||
|
begin
|
||||||
|
FFilter := LowerCase(Value);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwUnitTypeFilter }
|
||||||
|
constructor TUnSwUnitTypeFilter.Create(const AList: TUnSwUnitList);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
|
||||||
|
FIncludeDataModules := True;
|
||||||
|
FIncludeForms := True;
|
||||||
|
FIncludeProjectSource := True;
|
||||||
|
FIncludeUnits := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitTypeFilter.VisitModule(const AUnit: TUnSwModuleUnit);
|
||||||
|
var
|
||||||
|
eValidTypes: TUnSwUnitTypes;
|
||||||
|
|
||||||
|
begin
|
||||||
|
eValidTypes := [];
|
||||||
|
|
||||||
|
if FIncludeDataModules then
|
||||||
|
Include(eValidTypes, swutDataModule);
|
||||||
|
|
||||||
|
if FIncludeForms then
|
||||||
|
Include(eValidTypes, swutForm);
|
||||||
|
|
||||||
|
if FIncludeUnits then
|
||||||
|
Include(eValidTypes, swutUnit);
|
||||||
|
|
||||||
|
if not (AUnit.UnitType in eValidTypes) then
|
||||||
|
FilterUnit(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitTypeFilter.VisitProject(const AUnit: TUnSwProjectUnit);
|
||||||
|
begin
|
||||||
|
if not FIncludeProjectSource then
|
||||||
|
FilterUnit(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
@ -8,7 +8,46 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
TUnSwUnitFilter = class;
|
TUnSwUnit = class;
|
||||||
|
TUnSwModuleUnit = class;
|
||||||
|
TUnSwProjectUnit = class;
|
||||||
|
|
||||||
|
|
||||||
|
IUnSwVisitor = interface
|
||||||
|
['{A822C25B-5D0F-462F-94DD-47CD6235D79F}']
|
||||||
|
procedure VisitModule(const AUnit: TUnSwModuleUnit);
|
||||||
|
procedure VisitProject(const AUnit: TUnSwProjectUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
IUnSwVisited = interface
|
||||||
|
['{9540671E-184B-4DB6-A015-27B457C74C6C}']
|
||||||
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TUnSwNoRefIntfObject = class(TPersistent, IInterface)
|
||||||
|
protected
|
||||||
|
// IInterface
|
||||||
|
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
|
||||||
|
function _AddRef(): Integer; stdcall;
|
||||||
|
function _Release(): Integer; stdcall;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TUnSwUnit = class(TUnSwNoRefIntfObject, IUnSwVisited)
|
||||||
|
protected
|
||||||
|
function GetName(): String; virtual;
|
||||||
|
function GetFileName(): String; virtual;
|
||||||
|
public
|
||||||
|
// IUnSwVisited
|
||||||
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); virtual; abstract;
|
||||||
|
|
||||||
|
procedure Activate(const ASource: Boolean); virtual; abstract;
|
||||||
|
|
||||||
|
property Name: String read GetName;
|
||||||
|
property FileName: String read GetFileName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
TUnSwUnitType = (
|
TUnSwUnitType = (
|
||||||
swutForm = 0,
|
swutForm = 0,
|
||||||
@ -29,22 +68,38 @@ type
|
|||||||
);
|
);
|
||||||
TUnSwUnitTypes = set of TUnSwUnitType;
|
TUnSwUnitTypes = set of TUnSwUnitType;
|
||||||
|
|
||||||
TUnSwUnit = class(TPersistent)
|
|
||||||
|
TUnSwModuleUnit = class(TUnSwUnit)
|
||||||
private
|
private
|
||||||
FModule: IOTAModuleInfo;
|
FModule: IOTAModuleInfo;
|
||||||
|
protected
|
||||||
function GetName(): String;
|
function GetName(): String; override;
|
||||||
function GetFileName(): String;
|
function GetFileName(): String; override;
|
||||||
function GetUnitType(): TUnSwUnitType;
|
function GetUnitType(): TUnSwUnitType;
|
||||||
public
|
public
|
||||||
constructor Create(const AModule: IOTAModuleInfo); virtual;
|
constructor Create(const AModule: IOTAModuleInfo);
|
||||||
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); override;
|
||||||
|
|
||||||
|
procedure Activate(const ASource: Boolean); override;
|
||||||
|
|
||||||
property Name: String read GetName;
|
|
||||||
property FileName: String read GetFileName;
|
|
||||||
property UnitType: TUnSwUnitType read GetUnitType;
|
property UnitType: TUnSwUnitType read GetUnitType;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TUnSwUnitList = class(TPersistent)
|
TUnSwProjectUnit = class(TUnSwUnit)
|
||||||
|
private
|
||||||
|
FProject: IOTAProject;
|
||||||
|
protected
|
||||||
|
function GetName(): String; override;
|
||||||
|
function GetFileName(): String; override;
|
||||||
|
public
|
||||||
|
constructor Create(const AProject: IOTAProject);
|
||||||
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor); override;
|
||||||
|
|
||||||
|
procedure Activate(const ASource: Boolean); override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TUnSwUnitList = class(TUnSwNoRefIntfObject, IUnSwVisited)
|
||||||
private
|
private
|
||||||
FItems: TObjectList;
|
FItems: TObjectList;
|
||||||
|
|
||||||
@ -57,74 +112,94 @@ type
|
|||||||
|
|
||||||
function Add(const AUnit: TUnSwUnit): Integer; virtual;
|
function Add(const AUnit: TUnSwUnit): Integer; virtual;
|
||||||
function IndexOf(const AUnit: TUnSwUnit): Integer;
|
function IndexOf(const AUnit: TUnSwUnit): Integer;
|
||||||
procedure Sort(Compare: TListSortCompare);
|
function IndexOfFileName(const AFileName: String): Integer;
|
||||||
|
procedure Delete(const AIndex: Integer);
|
||||||
|
function Remove(const AUnit: TUnSwUnit): Integer;
|
||||||
|
|
||||||
|
procedure Sort(Compare: TListSortCompare);
|
||||||
procedure Clone(const ASource: TUnSwUnitList); virtual;
|
procedure Clone(const ASource: TUnSwUnitList); virtual;
|
||||||
procedure ApplyFilter(const AFilter: TUnSwUnitFilter); virtual;
|
|
||||||
|
procedure AcceptVisitor(const AVisitor: IUnSwVisitor);
|
||||||
|
|
||||||
property Count: Integer read GetCount;
|
property Count: Integer read GetCount;
|
||||||
property Items[Index: Integer]: TUnSwUnit read GetItem
|
property Items[Index: Integer]: TUnSwUnit read GetItem
|
||||||
write SetItem; default;
|
write SetItem; default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TUnSwUnitFilter = class(TObject)
|
|
||||||
protected
|
|
||||||
function IsFiltered(const AUnit: TUnSwUnit): Boolean; virtual; abstract;
|
|
||||||
public
|
|
||||||
constructor Create(); virtual;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TUnSwUnitSimpleFilter = class(TUnSwUnitFilter)
|
|
||||||
private
|
|
||||||
FFilter: String;
|
|
||||||
|
|
||||||
procedure SetFilter(const Value: String);
|
|
||||||
protected
|
|
||||||
function IsFiltered(const AUnit: TUnSwUnit): Boolean; override;
|
|
||||||
public
|
|
||||||
property Filter: String read FFilter write SetFilter;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TUnSwUnitTypeFilter = class(TUnSwUnitFilter)
|
|
||||||
private
|
|
||||||
FIncludeDataModules: Boolean;
|
|
||||||
FIncludeForms: Boolean;
|
|
||||||
FIncludeProjectSource: Boolean;
|
|
||||||
protected
|
|
||||||
function IsFiltered(const AUnit: TUnSwUnit): Boolean; override;
|
|
||||||
public
|
|
||||||
constructor Create(); override;
|
|
||||||
|
|
||||||
property IncludeDataModules: Boolean read FIncludeDataModules write FIncludeDataModules;
|
|
||||||
property IncludeForms: Boolean read FIncludeForms write FIncludeForms;
|
|
||||||
property IncludeProjectSource: Boolean read FIncludeProjectSource write FIncludeProjectSource;
|
|
||||||
end;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwNoRefIntfObject }
|
||||||
|
function TUnSwNoRefIntfObject.QueryInterface(const IID: TGUID; out Obj): HResult;
|
||||||
|
begin
|
||||||
|
if GetInterface(IID, Obj) then
|
||||||
|
Result := S_OK
|
||||||
|
else
|
||||||
|
Result := E_NOINTERFACE;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwNoRefIntfObject._AddRef(): Integer;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwNoRefIntfObject._Release(): Integer;
|
||||||
|
begin
|
||||||
|
Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TUnSwUnit }
|
{ TUnSwUnit }
|
||||||
constructor TUnSwUnit.Create(const AModule: IOTAModuleInfo);
|
function TUnSwUnit.GetName(): String;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwUnit.GetFileName(): String;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwModuleUnit }
|
||||||
|
constructor TUnSwModuleUnit.Create(const AModule: IOTAModuleInfo);
|
||||||
begin
|
begin
|
||||||
inherited Create();
|
inherited Create();
|
||||||
|
|
||||||
FModule := AModule;
|
FModule := AModule;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwModuleUnit.Activate(const ASource: Boolean);
|
||||||
|
var
|
||||||
|
ifModule: IOTAModule;
|
||||||
|
|
||||||
function TUnSwUnit.GetName(): String;
|
begin
|
||||||
|
ifModule := FModule.OpenModule();
|
||||||
|
if Assigned(ifModule) then
|
||||||
|
if ASource then
|
||||||
|
ifModule.ShowFilename(ifModule.FileName)
|
||||||
|
else
|
||||||
|
ifModule.Show();
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwModuleUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
||||||
|
begin
|
||||||
|
AVisitor.VisitModule(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwModuleUnit.GetName(): String;
|
||||||
begin
|
begin
|
||||||
Result := FModule.Name;
|
Result := FModule.Name;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUnSwUnit.GetFileName(): String;
|
function TUnSwModuleUnit.GetFileName(): String;
|
||||||
begin
|
begin
|
||||||
Result := FModule.FileName;
|
Result := FModule.FileName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TUnSwUnit.GetUnitType(): TUnSwUnitType;
|
function TUnSwModuleUnit.GetUnitType(): TUnSwUnitType;
|
||||||
begin
|
begin
|
||||||
Result := TUnSwUnitType(FModule.ModuleType);
|
Result := TUnSwUnitType(FModule.ModuleType);
|
||||||
if (Result = swutForm) and (Length(FModule.FormName) = 0) then
|
if (Result = swutForm) and (Length(FModule.FormName) = 0) then
|
||||||
@ -132,6 +207,35 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ TUnSwProjectUnit }
|
||||||
|
constructor TUnSwProjectUnit.Create(const AProject: IOTAProject);
|
||||||
|
begin
|
||||||
|
inherited Create();
|
||||||
|
|
||||||
|
FProject := AProject;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwProjectUnit.Activate(const ASource: Boolean);
|
||||||
|
begin
|
||||||
|
FProject.ShowFilename(FProject.FileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwProjectUnit.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
||||||
|
begin
|
||||||
|
AVisitor.VisitProject(Self);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwProjectUnit.GetName(): String;
|
||||||
|
begin
|
||||||
|
Result := ChangeFileExt(ExtractFileName(FProject.FileName), '');
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwProjectUnit.GetFileName(): String;
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TUnSwUnitList}
|
{ TUnSwUnitList}
|
||||||
constructor TUnSwUnitList.Create();
|
constructor TUnSwUnitList.Create();
|
||||||
begin
|
begin
|
||||||
@ -149,6 +253,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TUnSwUnitList.AcceptVisitor(const AVisitor: IUnSwVisitor);
|
||||||
|
var
|
||||||
|
iItem: Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
for iItem := Pred(Count) downto 0 do
|
||||||
|
Items[iItem].AcceptVisitor(AVisitor);
|
||||||
|
end;
|
||||||
|
|
||||||
function TUnSwUnitList.Add(const AUnit: TUnSwUnit): Integer;
|
function TUnSwUnitList.Add(const AUnit: TUnSwUnit): Integer;
|
||||||
begin
|
begin
|
||||||
Result := FItems.Add(AUnit);
|
Result := FItems.Add(AUnit);
|
||||||
@ -159,20 +272,36 @@ begin
|
|||||||
Result := FItems.IndexOf(AUnit);
|
Result := FItems.IndexOf(AUnit);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUnSwUnitList.Sort(Compare: TListSortCompare);
|
function TUnSwUnitList.IndexOfFileName(const AFileName: String): Integer;
|
||||||
begin
|
|
||||||
FItems.Sort(Compare);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TUnSwUnitList.ApplyFilter(const AFilter: TUnSwUnitFilter);
|
|
||||||
var
|
var
|
||||||
iItem: Integer;
|
iItem: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Result := -1;
|
||||||
|
if Length(AFileName) = 0 then
|
||||||
|
exit;
|
||||||
|
|
||||||
for iItem := Pred(Count) downto 0 do
|
for iItem := Pred(Count) downto 0 do
|
||||||
if AFilter.IsFiltered(Items[iItem]) then
|
if SameText(Items[iItem].FileName, AFileName) then
|
||||||
FItems.Delete(iItem);
|
begin
|
||||||
|
Result := iItem;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitList.Delete(const AIndex: Integer);
|
||||||
|
begin
|
||||||
|
FItems.Delete(AIndex);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TUnSwUnitList.Remove(const AUnit: TUnSwUnit): Integer;
|
||||||
|
begin
|
||||||
|
Result := FItems.Remove(AUnit);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TUnSwUnitList.Sort(Compare: TListSortCompare);
|
||||||
|
begin
|
||||||
|
FItems.Sort(Compare);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TUnSwUnitList.Clone(const ASource: TUnSwUnitList);
|
procedure TUnSwUnitList.Clone(const ASource: TUnSwUnitList);
|
||||||
@ -203,54 +332,4 @@ begin
|
|||||||
FItems[Index] := Value;
|
FItems[Index] := Value;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TUnSwUnitFilter }
|
|
||||||
constructor TUnSwUnitFilter.Create();
|
|
||||||
begin
|
|
||||||
inherited Create();
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TUnSwUnitSimpleFilter }
|
|
||||||
function TUnSwUnitSimpleFilter.IsFiltered(const AUnit: TUnSwUnit): Boolean;
|
|
||||||
begin
|
|
||||||
Result := (Length(FFilter) > 0) and
|
|
||||||
(AnsiPos(FFilter, LowerCase(AUnit.Name)) = 0);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TUnSwUnitSimpleFilter.SetFilter(const Value: String);
|
|
||||||
begin
|
|
||||||
FFilter := LowerCase(Value);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TUnSwUnitTypeFilter }
|
|
||||||
constructor TUnSwUnitTypeFilter.Create();
|
|
||||||
begin
|
|
||||||
inherited;
|
|
||||||
|
|
||||||
FIncludeDataModules := True;
|
|
||||||
FIncludeForms := True;
|
|
||||||
FIncludeProjectSource := True;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TUnSwUnitTypeFilter.IsFiltered(const AUnit: TUnSwUnit): Boolean;
|
|
||||||
var
|
|
||||||
eValidTypes: TUnSwUnitTypes;
|
|
||||||
|
|
||||||
begin
|
|
||||||
eValidTypes := [swutUnit];
|
|
||||||
|
|
||||||
if FIncludeDataModules then
|
|
||||||
Include(eValidTypes, swutDataModule);
|
|
||||||
|
|
||||||
if FIncludeForms then
|
|
||||||
Include(eValidTypes, swutForm);
|
|
||||||
|
|
||||||
if FIncludeProjectSource then
|
|
||||||
Include(eValidTypes, swutProjUnit);
|
|
||||||
|
|
||||||
Result := not (AUnit.UnitType in eValidTypes);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user