frmResTree.pas
上传用户:youjie821
上传日期:2013-01-27
资源大小:459k
文件大小:3k
源码类别:

PlugIns编程

开发平台:

Delphi

  1. unit frmResTree;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, hxFileRes, StdCtrls, ComCtrls, FileCtrl, hxClasses, ActnList, CSIntf;
  6. type
  7.   TResTreeForm = class(TForm)
  8.     TreeView1: TTreeView;
  9.     Button1: TButton;
  10.     Button2: TButton;
  11.     Button3: TButton;
  12.     ActionList1: TActionList;
  13.     actLoad: TAction;
  14.     actAdd: TAction;
  15.     actDelete: TAction;
  16.     Label1: TLabel;
  17.     Button4: TButton;
  18.     actRefresh: TAction;
  19.     procedure FormCreate(Sender: TObject);
  20.     procedure FormDestroy(Sender: TObject);
  21.     procedure actLoadExecute(Sender: TObject);
  22.     procedure actDeleteUpdate(Sender: TObject);
  23.     procedure actDeleteExecute(Sender: TObject);
  24.     procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
  25.     procedure actRefreshExecute(Sender: TObject);
  26.   private
  27.     { Private declarations }
  28.     FResTree: TResTree;
  29.     procedure RefreshTreeView(TreeView: TTreeView; Tree: TResTree);
  30.   public
  31.     { Public declarations }
  32.   end;
  33.   procedure ShowResTreeForm;
  34. implementation
  35. {$R *.dfm}
  36. procedure ShowResTreeForm;
  37. begin
  38.   with TResTreeForm.Create(nil) do
  39.   try
  40.     ShowModal;
  41.   finally
  42.     Free;
  43.   end;
  44. end;
  45. procedure TResTreeForm.FormCreate(Sender: TObject);
  46. begin
  47.   FResTree:= TResTree.Create;
  48. end;
  49. procedure TResTreeForm.FormDestroy(Sender: TObject);
  50. begin
  51.   FResTree.Free;
  52. end;
  53. procedure TResTreeForm.RefreshTreeView(TreeView: TTreeView; Tree: TResTree);
  54.   procedure TravelTree(Node: TNode; TreeNode: TTreeNode);
  55.   var
  56.     I: Integer;
  57.   begin
  58.     if Node = nil then Exit;
  59.     TreeNode:= TreeView.Items.AddChild(TreeNode, Node.Text);
  60.     TreeNode.Data:= Node;
  61.     //CodeSite.SendString(PResInfo(Node.Data)^.FileName, '');
  62.     for I:= 0 to Node.Count - 1 do
  63.       TravelTree(Node.Children[I], TreeNode);
  64.   end;
  65. var
  66.   I: Integer;
  67.   Node: TNode;
  68. begin
  69.   TreeView.Items.Clear;
  70.   Node:= Tree.RootNode;
  71.   for I:= 0 to Node.Count - 1 do
  72.     TravelTree(Node.Children[I], nil);
  73. end;
  74. procedure TResTreeForm.actLoadExecute(Sender: TObject);
  75. var
  76.   szDir: string;
  77. begin
  78.   if SelectDirectory('选择目录', 'E:', szDir) then
  79.   begin
  80.     FResTree.LoadFiles(szDir);
  81.     RefreshTreeView(TreeView1, FResTree);
  82.   end;
  83. end;
  84. procedure TResTreeForm.actDeleteUpdate(Sender: TObject);
  85. begin
  86.   (Sender as TAction).Enabled:= TreeView1.Selected <> nil;
  87. end;
  88. procedure TResTreeForm.actDeleteExecute(Sender: TObject);
  89. begin
  90.   FResTree.RemoveNode(TNode(TreeView1.Selected.Data));
  91.   //TreeView1.Items.Delete(TreeView1.Selected);
  92.   RefreshTreeView(TreeView1, FResTree);
  93. end;
  94. procedure TResTreeForm.TreeView1Change(Sender: TObject; Node: TTreeNode);
  95. begin
  96.   Label1.Caption:= IntToStr(FResTree.Count);
  97. end;
  98. procedure TResTreeForm.actRefreshExecute(Sender: TObject);
  99. begin
  100.   RefreshTreeView(TreeView1, FResTree);
  101. end;
  102. end.