LCL: TShellTreeview: using overrides instead of events

git-svn-id: trunk@22147 -
This commit is contained in:
mattias 2009-10-13 16:10:07 +00:00
parent f40bb559e0
commit 55264e4666

View File

@ -50,14 +50,13 @@ type
FShellListView: TCustomShellListView; FShellListView: TCustomShellListView;
{ Setters and getters } { Setters and getters }
procedure SetShellListView(const Value: TCustomShellListView); procedure SetShellListView(const Value: TCustomShellListView);
{ Other internal methods }
procedure HandleOnExpanding(Sender: TObject; Node: TTreeNode; var AllowExpansion: Boolean);
procedure HandleSelectionChanged(Sender: TObject);
protected protected
{ Other methods specific to Lazarus } { Other methods specific to Lazarus }
function PopulateTreeNodeWithFiles( function PopulateTreeNodeWithFiles(
ANode: TTreeNode; ANodePath: string): Boolean; ANode: TTreeNode; ANodePath: string): Boolean;
procedure PopulateWithBaseFiles; procedure PopulateWithBaseFiles;
procedure DoSelectionChanged; override;
function CanExpand(Node: TTreeNode): Boolean; override;
public public
{ Basic methods } { Basic methods }
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -304,20 +303,12 @@ begin
Value.ShellTreeView := Self; Value.ShellTreeView := Self;
end; end;
procedure TCustomShellTreeView.HandleOnExpanding(Sender: TObject; function TCustomShellTreeView.CanExpand(Node: TTreeNode): Boolean;
Node: TTreeNode; var AllowExpansion: Boolean);
begin begin
Result:=inherited CanExpand(Node);
if not Result then exit;
Node.DeleteChildren; Node.DeleteChildren;
AllowExpansion := PopulateTreeNodeWithFiles(Node, GetPathFromNode(Node)); Result := PopulateTreeNodeWithFiles(Node, GetPathFromNode(Node));
end;
procedure TCustomShellTreeView.HandleSelectionChanged(Sender: TObject);
begin
if Assigned(FShellListView) then
begin
FShellListView.Root := GetPathFromNode(Selected);
FShellListView.Refresh; // Repaint
end;
end; end;
constructor TCustomShellTreeView.Create(AOwner: TComponent); constructor TCustomShellTreeView.Create(AOwner: TComponent);
@ -328,11 +319,6 @@ begin
ObjectTypes:= [otFolders]; ObjectTypes:= [otFolders];
// Necessary event handlers
OnExpanding := @HandleOnExpanding;
OnSelectionChanged := @HandleSelectionChanged;
// Populates the base dirs // Populates the base dirs
PopulateWithBaseFiles(); PopulateWithBaseFiles();
@ -434,7 +420,7 @@ begin
end; end;
procedure TCustomShellTreeView.PopulateWithBaseFiles; procedure TCustomShellTreeView.PopulateWithBaseFiles;
{$if defined(windows) and not defined(wince)} {$if defined(windows) and not defined(wince)}
const const
DRIVE_UNKNOWN = 0; DRIVE_UNKNOWN = 0;
DRIVE_NO_ROOT_DIR = 1; DRIVE_NO_ROOT_DIR = 1;
@ -468,14 +454,21 @@ begin
Inc(pDrive, 4); Inc(pDrive, 4);
end; end;
end; end;
{$else} {$else}
begin begin
// avoids crashes in the IDE by not populating during design // avoids crashes in the IDE by not populating during design
if (csDesigning in ComponentState) then Exit; if (csDesigning in ComponentState) then Exit;
PopulateTreeNodeWithFiles(nil, GetBasePath()); PopulateTreeNodeWithFiles(nil, GetBasePath());
end; end;
{$endif} {$endif}
procedure TCustomShellTreeView.DoSelectionChanged;
begin
inherited DoSelectionChanged;
if Assigned(FShellListView) then
FShellListView.Root := GetPathFromNode(Selected);
end;
function TCustomShellTreeView.GetPathFromNode(ANode: TTreeNode): string; function TCustomShellTreeView.GetPathFromNode(ANode: TTreeNode): string;
var var