Adds the possibility to link a TFilterComboBox to a TShellListView. Adds a TFilterComboBox to wince dialogs

git-svn-id: trunk@21268 -
This commit is contained in:
sekelsenmat 2009-08-17 19:58:12 +00:00
parent d6ec04681b
commit caf480d8bc
3 changed files with 75 additions and 17 deletions

View File

@ -35,7 +35,8 @@ interface
{$endif}
uses
Classes, SysUtils, StdCtrls, FileUtil, Masks, Graphics;
Classes, SysUtils, StdCtrls, FileUtil, Masks, Graphics,
ShellCtrls;
Type
@ -136,13 +137,17 @@ Type
property Visible;
end;
{ TFilterComboBox }
{ TCustomFilterComboBox }
TFilterComboBox = class(TCustomComboBox)
TCustomFilterComboBox = class(TCustomComboBox)
private
FFilter: string;
FShellListView: TShellListView;
function GetMask: string;
procedure SetFilter(const AValue: string);
procedure SetShellListView(const AValue: TShellListView);
protected
procedure Select; override;
public
{ Base methods }
constructor Create(TheOwner: TComponent); override;
@ -152,6 +157,10 @@ Type
AStrings: TStrings; AClearStrings, AAddDescription, AAddFilter: Boolean);
{ properties }
property Mask: string read GetMask; // Can be used to conect to other controls
property ShellListView: TShellListView read FShellListView write SetShellListView;
end;
TFilterComboBox = class(TCustomFilterComboBox)
published
{ properties }
property Align;
@ -468,9 +477,9 @@ begin
inherited Destroy;
end;
{ TFilterComboBox }
{ TCustomFilterComboBox }
function TFilterComboBox.GetMask: string;
function TCustomFilterComboBox.GetMask: string;
var
FilterList: TStrings;
begin
@ -478,9 +487,9 @@ begin
FilterList := TStringList.Create;
try
TFilterComboBox.ConvertFilterToStrings(FFilter, FilterList, True, False, True);
TCustomFilterComboBox.ConvertFilterToStrings(FFilter, FilterList, True, False, True);
if (ItemIndex >= 0) and (ItemIndex <= FilterList.Count) then
if (ItemIndex >= 0) and (ItemIndex < FilterList.Count) then
begin
Result := FilterList[ItemIndex];
end;
@ -489,7 +498,7 @@ begin
end;
end;
procedure TFilterComboBox.SetFilter(const AValue: string);
procedure TCustomFilterComboBox.SetFilter(const AValue: string);
begin
if AValue = FFilter then Exit;
@ -500,6 +509,24 @@ begin
ItemIndex := 0;
end;
procedure TCustomFilterComboBox.SetShellListView(const AValue: TShellListView);
begin
if FShellListView=AValue then exit;
FShellListView:=AValue;
if FShellListView <> nil then
FShellListView.Mask := Mask;
end;
procedure TCustomFilterComboBox.Select;
begin
if FShellListView <> nil then
FShellListView.Mask := Mask;
inherited Select;
end;
{------------------------------------------------------------------------------
This is a parser that converts LCL filter strings to a TStringList
@ -520,7 +547,7 @@ Binaries (*.exe)
Adapted from the converter initially created for QtWSDialogs.pas
------------------------------------------------------------------------------}
class procedure TFilterComboBox.ConvertFilterToStrings(AFilter: string;
class procedure TCustomFilterComboBox.ConvertFilterToStrings(AFilter: string;
AStrings: TStrings; AClearStrings, AAddDescription, AAddFilter: Boolean);
var
ParserState, Position, i: Integer;
@ -556,14 +583,14 @@ begin
end;
end;
constructor TFilterComboBox.Create(TheOwner: TComponent);
constructor TCustomFilterComboBox.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
Text := '';
end;
destructor TFilterComboBox.Destroy;
destructor TCustomFilterComboBox.Destroy;
begin
inherited Destroy;

View File

@ -113,6 +113,7 @@ type
OkButton: TBitBtn;
CancelButton: TBitBtn;
SaveEdit: TEdit;
FilterComboBox: TFilterComboBox;
// Communication fields
LCLDialog: TFileDialog;
constructor Create(AOwner: TComponent; ALCLDialog: TFileDialog);
@ -216,6 +217,18 @@ begin
SaveEdit.Width := Width;
SaveEdit.Align := alBottom;
end;
// TFilterComboBox
FilterComboBox := TFilterComboBox.Create(Self);
FilterComboBox.Parent := Self;
FilterComboBox.Left := 0;
FilterComboBox.Height := 20;
FilterComboBox.Top := Height - Panel.Height - FilterComboBox.Height;
if SaveEdit <> nil then Dec(FilterComboBox.Top, SaveEdit.Height);
FilterComboBox.Width := Width;
FilterComboBox.Align := alBottom;
FilterComboBox.Filter := LCLDialog.Filter;
FilterComboBox.ShellListView := ShellListView;
end;
procedure TWinCEFileDialogForm.HandleOkClick(ASender: TObject);

View File

@ -66,7 +66,7 @@ type
{ Methods specific to Lazarus - useful for other classes }
class function GetBasePath: string;
class procedure GetFilesInDir(const ABaseDir: string;
AObjectTypes: TObjectTypes; AResult: TStrings);
AMask: string; AObjectTypes: TObjectTypes; AResult: TStrings);
{ Other methods specific to Lazarus }
function GetPathFromNode(ANode: TTreeNode): string;
@ -137,10 +137,12 @@ type
TCustomShellListView = class(TCustomListView)
private
FMask: string;
FObjectTypes: TObjectTypes;
FRoot: string;
FShellTreeView: TCustomShellTreeView;
{ Setters and getters }
procedure SetMask(const AValue: string);
procedure SetShellTreeView(const Value: TCustomShellTreeView);
procedure SetRoot(const Value: string);
{ Other internal methods }
@ -155,6 +157,7 @@ type
{ Methods specific to Lazarus }
function GetPathFromItem(ANode: TListItem): string;
{ Properties }
property Mask: string read FMask write SetMask; // Can be used to conect to other controls
property ObjectTypes: TObjectTypes read FObjectTypes write FObjectTypes;
property Root: string read FRoot write SetRoot;
property ShellTreeView: TCustomShellTreeView read FShellTreeView write SetShellTreeView;
@ -344,15 +347,19 @@ end;
Finds all files/directories directly inside a directory.
Does not recurse inside subdirectories. }
class procedure TCustomShellTreeView.GetFilesInDir(const ABaseDir: string;
AObjectTypes: TObjectTypes; AResult: TStrings);
AMask: string; AObjectTypes: TObjectTypes; AResult: TStrings);
var
DirInfo: TSearchRec;
FindResult: Integer;
IsDirectory, IsValidDirectory, IsHidden, AddFile: Boolean;
ObjectData: TObject;
SearchStr: string;
MaskStr: string;
begin
SearchStr := IncludeTrailingPathDelimiter(ABaseDir) + AllFilesMask;
if Trim(AMask) = '' then MaskStr := AllFilesMask
else MaskStr := AMask;
SearchStr := IncludeTrailingPathDelimiter(ABaseDir) + MaskStr;
FindResult := FindFirst(SearchStr, faAnyFile, DirInfo);
@ -412,7 +419,7 @@ var
begin
Files := TStringList.Create;
try
GetFilesInDir(ANodePath, FObjectTypes, Files);
GetFilesInDir(ANodePath, AllFilesMask, FObjectTypes, Files);
Result := Files.Count > 0;
@ -514,6 +521,17 @@ begin
if Value.ShellListView <> Self then Value.ShellListView := Self;
end;
procedure TCustomShellListView.SetMask(const AValue: string);
begin
if AValue <> FMask then
begin
FMask := AValue;
Clear;
Items.Clear;
PopulateWithRoot();
end;
end;
procedure TCustomShellListView.SetRoot(const Value: string);
begin
if FRoot <> Value then
@ -586,11 +604,11 @@ begin
if (csDesigning in ComponentState) then Exit;
// Check inputs
if FRoot = '' then Exit;
if Trim(FRoot) = '' then Exit;
Files := TStringList.Create;
try
TCustomShellTreeView.GetFilesInDir(FRoot, FObjectTypes, Files);
TCustomShellTreeView.GetFilesInDir(FRoot, FMask, FObjectTypes, Files);
for i := 0 to Files.Count - 1 do
begin