2006-01-05 06:03:24 +00:00
|
|
|
unit UnSwDialog;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
ComCtrls,
|
|
|
|
Controls,
|
|
|
|
ExtCtrls,
|
|
|
|
Forms,
|
|
|
|
ImgList,
|
|
|
|
StdCtrls,
|
|
|
|
Windows,
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
UnSwObjects,
|
|
|
|
UnSwFilters;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
type
|
2006-01-05 21:04:59 +00:00
|
|
|
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;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
TfrmUnSwDialog = class(TForm)
|
2006-01-05 21:04:59 +00:00
|
|
|
btnCancel: TButton;
|
|
|
|
btnOK: TButton;
|
2006-01-05 21:14:36 +00:00
|
|
|
chkDataModules: TCheckBox;
|
|
|
|
chkForms: TCheckBox;
|
|
|
|
chkProjectSource: TCheckBox;
|
2006-01-05 06:03:24 +00:00
|
|
|
edtSearch: TEdit;
|
|
|
|
ilsTypes: TImageList;
|
|
|
|
lstUnits: TListBox;
|
2006-01-05 21:04:59 +00:00
|
|
|
pnlButtons: TPanel;
|
2006-01-05 21:14:36 +00:00
|
|
|
pnlIncludeTypes: TPanel;
|
2006-01-05 06:03:24 +00:00
|
|
|
pnlMain: TPanel;
|
|
|
|
pnlSearch: TPanel;
|
|
|
|
sbStatus: TStatusBar;
|
|
|
|
|
|
|
|
procedure edtSearchChange(Sender: TObject);
|
|
|
|
procedure edtSearchKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
2006-01-05 21:14:36 +00:00
|
|
|
procedure TypeFilterChange(Sender: TObject);
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure lstUnitsData(Control: TWinControl; Index: Integer; var Data: string);
|
|
|
|
procedure lstUnitsDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
|
|
|
|
private
|
2006-01-05 21:14:36 +00:00
|
|
|
FLoading: Boolean;
|
2006-01-05 06:03:24 +00:00
|
|
|
FUnitList: TUnSwUnitList;
|
2006-01-05 21:04:59 +00:00
|
|
|
FActiveUnit: TUnSwUnit;
|
|
|
|
FFormsOnly: Boolean;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
FTypeFilteredList: TUnSwUnitList;
|
|
|
|
FInputFilteredList: TUnSwUnitList;
|
|
|
|
|
|
|
|
FTypeFilter: TUnSwUnitTypeFilter;
|
|
|
|
FInputFilter: TUnSwUnitSimpleFilter;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
FIconVisitor: TUnSwIconVisitor;
|
|
|
|
|
|
|
|
function InternalExecute(): TUnSwUnit;
|
|
|
|
procedure UpdateTypeFilter();
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure UpdateList();
|
|
|
|
|
|
|
|
function GetActiveUnit(): TUnSwUnit;
|
2006-01-06 20:39:08 +00:00
|
|
|
|
|
|
|
procedure LoadSettings();
|
|
|
|
procedure SaveSettings();
|
2006-01-05 06:03:24 +00:00
|
|
|
public
|
2006-01-05 21:04:59 +00:00
|
|
|
class function Execute(const AUnits: TUnSwUnitList;
|
|
|
|
const AFormsOnly: Boolean;
|
|
|
|
const AActive: TUnSwUnit = nil): TUnSwUnit;
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
2006-01-06 20:39:08 +00:00
|
|
|
Graphics,
|
|
|
|
Messages,
|
|
|
|
SysUtils;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
{$R *.dfm}
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
|
|
|
|
{ TUnSwIconVisitor }
|
|
|
|
procedure TUnSwIconVisitor.VisitModule(const AUnit: TUnSwModuleUnit);
|
|
|
|
begin
|
|
|
|
case AUnit.UnitType of
|
2006-01-05 21:22:02 +00:00
|
|
|
swutUnit: FImageIndex := 1;
|
|
|
|
swutForm: FImageIndex := 2;
|
|
|
|
swutDataModule: FImageIndex := 3;
|
2006-01-05 21:04:59 +00:00
|
|
|
else
|
|
|
|
FImageIndex := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TUnSwIconVisitor.VisitProject(const AUnit: TUnSwProjectUnit);
|
|
|
|
begin
|
2006-01-05 21:22:02 +00:00
|
|
|
FImageIndex := 4;
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
{ TfrmUnSwDialog }
|
2006-01-05 21:04:59 +00:00
|
|
|
class function TfrmUnSwDialog.Execute(const AUnits: TUnSwUnitList;
|
|
|
|
const AFormsOnly: Boolean;
|
|
|
|
const AActive: TUnSwUnit): TUnSwUnit;
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
|
|
|
with Self.Create(nil) do
|
|
|
|
try
|
2006-01-05 21:04:59 +00:00
|
|
|
FUnitList := AUnits;
|
|
|
|
FActiveUnit := AActive;
|
|
|
|
FFormsOnly := AFormsOnly;
|
|
|
|
Result := InternalExecute();
|
2006-01-05 06:03:24 +00:00
|
|
|
finally
|
|
|
|
Free();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function SortByName(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
Result := CompareText(TUnSwUnit(Item1).Name, TUnSwUnit(Item2).Name)
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
function TfrmUnSwDialog.InternalExecute(): TUnSwUnit;
|
2006-01-05 06:03:24 +00:00
|
|
|
begin
|
2006-01-05 21:04:59 +00:00
|
|
|
Result := nil;
|
2006-01-05 06:03:24 +00:00
|
|
|
FTypeFilteredList := TUnSwUnitList.Create();
|
|
|
|
FInputFilteredList := TUnSwUnitList.Create();
|
2006-01-05 21:04:59 +00:00
|
|
|
FTypeFilter := TUnSwUnitTypeFilter.Create(FTypeFilteredList);
|
2006-01-06 05:57:45 +00:00
|
|
|
|
|
|
|
if FFormsOnly then
|
|
|
|
FInputFilter := TUnSwUnitSimpleFormNameFilter.Create(FInputFilteredList)
|
|
|
|
else
|
|
|
|
FInputFilter := TUnSwUnitSimpleNameFilter.Create(FInputFilteredList);
|
2006-01-05 06:03:24 +00:00
|
|
|
try
|
2006-01-06 20:39:08 +00:00
|
|
|
LoadSettings();
|
|
|
|
|
|
|
|
if FFormsOnly then
|
2006-01-05 21:14:36 +00:00
|
|
|
pnlIncludeTypes.Visible := False;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
UpdateTypeFilter();
|
2006-01-05 06:03:24 +00:00
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
FIconVisitor := TUnSwIconVisitor.Create();
|
|
|
|
try
|
|
|
|
if Self.ShowModal() = mrOk then
|
|
|
|
Result := GetActiveUnit();
|
2006-01-06 20:39:08 +00:00
|
|
|
|
|
|
|
SaveSettings();
|
2006-01-05 21:04:59 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(FIconVisitor);
|
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
finally
|
|
|
|
FreeAndNil(FInputFilter);
|
|
|
|
FreeAndNil(FTypeFilter);
|
|
|
|
FreeAndNil(FInputFilteredList);
|
|
|
|
FreeAndNil(FTypeFilteredList);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.UpdateList();
|
|
|
|
var
|
|
|
|
pActive: TUnSwUnit;
|
|
|
|
|
|
|
|
begin
|
|
|
|
pActive := GetActiveUnit();
|
|
|
|
|
|
|
|
FInputFilteredList.Clone(FTypeFilteredList);
|
2006-01-05 21:04:59 +00:00
|
|
|
FInputFilteredList.AcceptVisitor(FInputFilter);
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
lstUnits.Count := FInputFilteredList.Count;
|
|
|
|
if FInputFilteredList.Count > 0 then
|
|
|
|
begin
|
|
|
|
if Assigned(pActive) then
|
|
|
|
lstUnits.ItemIndex := FInputFilteredList.IndexOf(pActive);
|
|
|
|
|
|
|
|
if lstUnits.ItemIndex = -1 then
|
|
|
|
lstUnits.ItemIndex := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TfrmUnSwDialog.UpdateTypeFilter();
|
|
|
|
begin
|
|
|
|
FTypeFilter.IncludeUnits := not FFormsOnly;
|
|
|
|
FTypeFilter.IncludeForms := (FFormsOnly or chkForms.Checked);
|
2006-01-06 05:57:45 +00:00
|
|
|
FTypeFilter.IncludeDataModules := (FFormsOnly or chkDataModules.Checked);
|
2006-01-05 21:04:59 +00:00
|
|
|
FTypeFilter.IncludeProjectSource := ((not FFormsOnly) and chkProjectSource.Checked);
|
|
|
|
|
|
|
|
FTypeFilteredList.Clone(FUnitList);
|
|
|
|
FTypeFilteredList.AcceptVisitor(FTypeFilter);
|
|
|
|
FTypeFilteredList.Sort(SortByName);
|
|
|
|
UpdateList();
|
|
|
|
end;
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
function TfrmUnSwDialog.GetActiveUnit(): TUnSwUnit;
|
|
|
|
begin
|
2006-01-05 21:04:59 +00:00
|
|
|
Result := FActiveUnit;
|
|
|
|
if not Assigned(Result) then
|
|
|
|
begin
|
|
|
|
if lstUnits.ItemIndex > -1 then
|
|
|
|
Result := FInputFilteredList[lstUnits.ItemIndex];
|
|
|
|
end else
|
|
|
|
FActiveUnit := nil;
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
2006-01-06 20:39:08 +00:00
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.LoadSettings();
|
|
|
|
var
|
|
|
|
pSettings: TUnSwRegistry;
|
|
|
|
|
|
|
|
function ReadBoolDef(const AName: String; const ADefault: Boolean): Boolean;
|
|
|
|
begin
|
|
|
|
if pSettings.ValueExists(AName) then
|
|
|
|
Result := pSettings.ReadBool(AName)
|
|
|
|
else
|
|
|
|
Result := ADefault;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ReadIntegerDef(const AName: String; const ADefault: Integer): Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if pSettings.ValueExists(AName) then
|
|
|
|
Result := pSettings.ReadInteger(AName)
|
|
|
|
else
|
|
|
|
Result := ADefault;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
sKey: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
pSettings := TUnSwRegistry.Create();
|
|
|
|
with pSettings do
|
|
|
|
try
|
|
|
|
FLoading := True;
|
|
|
|
RootKey := HKEY_CURRENT_USER;
|
|
|
|
|
|
|
|
if OpenIDEKey() then
|
|
|
|
begin
|
|
|
|
chkForms.Checked := ReadBoolDef('IncludeForms', FTypeFilter.IncludeForms);
|
|
|
|
chkDataModules.Checked := ReadBoolDef('IncludeDataModules', FTypeFilter.IncludeDataModules);
|
|
|
|
chkProjectSource.Checked := ReadBoolDef('IncludeProjectSource', FTypeFilter.IncludeProjectSource);
|
|
|
|
|
|
|
|
if FFormsOnly then
|
|
|
|
sKey := 'Forms'
|
|
|
|
else
|
|
|
|
sKey := 'Units';
|
|
|
|
|
|
|
|
Self.ClientWidth := ReadIntegerDef(sKey + 'DialogWidth', Self.ClientWidth);
|
|
|
|
Self.ClientHeight := ReadIntegerDef(sKey + 'DialogHeight', Self.ClientHeight);
|
|
|
|
Self.Caption := 'UnitSwitcher - View ' + sKey;
|
|
|
|
|
|
|
|
CloseKey();
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FLoading := False;
|
|
|
|
FreeAndNil(pSettings);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.SaveSettings();
|
|
|
|
var
|
|
|
|
sKey: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with TUnSwRegistry.Create() do
|
|
|
|
try
|
|
|
|
FLoading := True;
|
|
|
|
RootKey := HKEY_CURRENT_USER;
|
|
|
|
|
|
|
|
if OpenIDEKey() then
|
|
|
|
begin
|
|
|
|
WriteBool('IncludeForms', chkForms.Checked);
|
|
|
|
WriteBool('IncludeDataModules', chkDataModules.Checked);
|
|
|
|
WriteBool('IncludeProjectSource', chkProjectSource.Checked);
|
|
|
|
|
|
|
|
if FFormsOnly then
|
|
|
|
sKey := 'Forms'
|
|
|
|
else
|
|
|
|
sKey := 'Units';
|
|
|
|
|
|
|
|
WriteInteger(sKey + 'DialogWidth', Self.ClientWidth);
|
|
|
|
WriteInteger(sKey + 'DialogHeight', Self.ClientHeight);
|
|
|
|
|
|
|
|
CloseKey();
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FLoading := False;
|
|
|
|
Free();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
procedure TfrmUnSwDialog.edtSearchChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
FInputFilter.Filter := edtSearch.Text;
|
|
|
|
UpdateList();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.edtSearchKeyDown(Sender: TObject; var Key: Word;
|
|
|
|
Shift: TShiftState);
|
|
|
|
begin
|
2006-01-06 20:39:08 +00:00
|
|
|
if (Shift = []) and (Key in [VK_UP, VK_DOWN, VK_PRIOR, VK_NEXT]) then
|
|
|
|
lstUnits.Perform(WM_KEYDOWN, Key, 0);
|
2006-01-05 06:03:24 +00:00
|
|
|
end;
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
procedure TfrmUnSwDialog.TypeFilterChange(Sender: TObject);
|
|
|
|
begin
|
2006-01-05 21:14:36 +00:00
|
|
|
if not FLoading then
|
|
|
|
UpdateTypeFilter();
|
2006-01-05 21:04:59 +00:00
|
|
|
end;
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.lstUnitsData(Control: TWinControl; Index: Integer;
|
|
|
|
var Data: string);
|
|
|
|
begin
|
|
|
|
Data := FInputFilteredList[Index].Name;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TfrmUnSwDialog.lstUnitsDrawItem(Control: TWinControl; Index: Integer;
|
|
|
|
Rect: TRect; State: TOwnerDrawState);
|
|
|
|
var
|
2006-01-05 21:04:59 +00:00
|
|
|
pUnit: TUnSwUnit;
|
2006-01-05 06:03:24 +00:00
|
|
|
rText: TRect;
|
|
|
|
sText: String;
|
|
|
|
|
|
|
|
begin
|
|
|
|
with TListBox(Control) do
|
|
|
|
begin
|
2006-01-05 21:04:59 +00:00
|
|
|
pUnit := FInputFilteredList[Index];
|
2006-01-06 05:57:45 +00:00
|
|
|
if FFormsOnly and (pUnit is TUnSwModuleUnit) then
|
|
|
|
sText := TUnSwModuleUnit(pUnit).FormName
|
|
|
|
else
|
|
|
|
sText := pUnit.Name;
|
2006-01-05 21:04:59 +00:00
|
|
|
|
2006-01-05 06:03:24 +00:00
|
|
|
if odSelected in State then
|
|
|
|
begin
|
|
|
|
Canvas.Brush.Color := clHighlight;
|
|
|
|
Canvas.Font.Color := clHighlightText;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
Canvas.Brush.Color := clWindow;
|
|
|
|
Canvas.Font.Color := clWindowText;
|
|
|
|
end;
|
|
|
|
Canvas.FillRect(Rect);
|
|
|
|
|
|
|
|
rText := Rect;
|
|
|
|
InflateRect(rText, -2, -2);
|
|
|
|
|
2006-01-05 21:04:59 +00:00
|
|
|
pUnit.AcceptVisitor(FIconVisitor);
|
|
|
|
ilsTypes.Draw(Canvas, rText.Left, rText.Top, FIconVisitor.ImageIndex);
|
2006-01-05 06:03:24 +00:00
|
|
|
|
|
|
|
Inc(rText.Left, ilsTypes.Width + 4);
|
|
|
|
DrawText(Canvas.Handle, PChar(sText), Length(sText), rText, DT_SINGLELINE or
|
|
|
|
DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|