Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Somali/EnvControl/ResourceSecretary.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 95 - (show annotations) (download)
Sun Nov 28 06:24:47 2010 UTC (13 years, 5 months ago) by juan
File size: 3629 byte(s)
mod ExplorerForm with able to open dirTree
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows.Forms;
6 using System.IO;
7
8 namespace Somali.EnvControl
9 {
10 class ResourceSecretary : Somali.Base.BaseSecretary
11 {
12 private string _explrDirPath = String.Empty;
13 private TreeNode _explrTree = null;
14
15 public ResourceSecretary()
16 {
17 }
18
19 public TreeNode GetExplorerTree( string dirPath )
20 {
21
22 //try
23 //{
24 // Directory.GetFiles( dirPath, "*", SearchOption.AllDirectories );
25 //}
26 //catch ( UnauthorizedAccessException e )
27 //{
28 // MessageBox.Show( "参照権限がありません。\n" + e.Message );
29 // return null;
30 //}
31
32 DirectoryInfo dirInfo = new DirectoryInfo( dirPath );
33 TreeNode root = new TreeNode( dirInfo.Name );
34 root.ImageIndex = (int)ExplorerForm.NodeIcon.FolderClose;
35 root.SelectedImageIndex = (int)ExplorerForm.NodeIcon.FolderOpen;
36 root.Nodes.Add( "dummy" );
37
38 this._explrDirPath = dirInfo.Parent != null ? dirInfo.Parent.FullName : String.Empty;
39 this._explrTree = root;
40 return root;
41 }
42
43 public void ExpandExplorerNode( TreeNode treeNode )
44 {
45 if ( treeNode == null )
46 {
47 throw new ArgumentNullException();
48 }
49
50 if ( this._explrTree.TreeView.Equals( treeNode.TreeView ) )
51 {
52 ExpandNode( this._explrDirPath, treeNode );
53 }
54 else
55 {
56 throw new ArgumentException();
57 }
58 }
59
60 private void ExpandNode( string dirPath, TreeNode treeNode )
61 {
62 treeNode.Nodes.Clear();
63
64 string path = dirPath + (dirPath.Equals( String.Empty ) ? String.Empty : @"\") + treeNode.FullPath;
65 DirectoryInfo dirInfo = new DirectoryInfo( path );
66 if ( dirInfo.Exists )
67 {
68 try
69 {
70 DirectoryInfo[] subDir = dirInfo.GetDirectories();
71 foreach ( DirectoryInfo di in subDir )
72 {
73 if ( (di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden )
74 {
75 TreeNode node = treeNode.Nodes.Add( di.Name );
76 node.ImageIndex = (int)ExplorerForm.NodeIcon.FolderClose;
77 node.SelectedImageIndex = (int)ExplorerForm.NodeIcon.FolderOpen;
78
79 node.Nodes.Add( "dummy" );
80 }
81 }
82
83 FileInfo[] files = dirInfo.GetFiles();
84 foreach ( FileInfo fi in files )
85 {
86 if ( (fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden )
87 {
88 TreeNode node = treeNode.Nodes.Add( fi.Name );
89 // TODO:拡張子によるアイコンの変更
90 node.ImageIndex = node.SelectedImageIndex = (int)ExplorerForm.NodeIcon.FilePlain;
91 }
92 }
93 }
94 catch ( UnauthorizedAccessException e )
95 {
96 MessageBox.Show( "参照権限がありません。\n" + e.Message );
97 }
98 }
99 }
100
101 }
102 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26