]>
git.saurik.com Git - wxWidgets.git/blob - user/wxFile/dirctrl.cpp
2 * Author: Robert Roebling
4 * Copyright: (C) 1997,1998 Robert Roebling
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the wxWindows Licence, which
8 * you have received with this library (see Licence.htm).
13 #pragma implementation "dirctrl.h"
17 #include "wx/gdicmn.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 IMPLEMENT_DYNAMIC_CLASS(wxDirInfo
,wxObject
)
27 wxDirInfo::wxDirInfo( const wxString
&path
)
31 if (m_path
== "/") m_name
="The Computer";
33 if (m_path
== "/home")
42 if (m_path
== "/proc") m_name
= "Info Filesystem";
44 if (m_path
== "/mnt") m_name
= "Mounted Devices";
46 if (m_path
== "/usr/X11R6") m_name
= "User X11";
48 if (m_path
== "/usr") m_name
= "User";
50 if (m_path
== "/var") m_name
= "Variables";
52 if (m_path
== "/usr/local") m_name
= "User local";
54 if (m_path
== "/mnt") m_name
= "Mounted Devices";
56 m_name
= wxFileNameFromPath( m_path
);
59 wxString
wxDirInfo::GetName(void) const
64 wxString
wxDirInfo::GetPath(void) const
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
73 IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl
,wxTreeCtrl
)
75 BEGIN_EVENT_TABLE(wxDirCtrl
,wxTreeCtrl
)
76 EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem
)
77 EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem
)
78 EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem
)
81 wxDirCtrl::wxDirCtrl(void)
86 wxDirCtrl::wxDirCtrl(wxWindow
*parent
, const wxWindowID id
, const wxString
&WXUNUSED(dir
),
87 const wxPoint
& pos
, const wxSize
& size
,
88 const long style
, const wxString
& name
)
90 wxTreeCtrl( parent
, id
, pos
, size
, style
, name
)
95 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
96 item
.m_text
= "Sections";
98 m_rootId
= InsertItem( 0, item
);
100 SetDropTarget( new wxFileDropTarget() );
103 void wxDirCtrl::OnExpandItem( const wxTreeEvent
&event
)
105 if (event
.m_item
.m_itemId
== m_rootId
)
109 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
112 wxDirInfo
*info
= new wxDirInfo( "/" );
113 item
.m_text
= info
->GetName();
114 item
.m_data
= (long)info
;
115 InsertItem( m_rootId
, item
);
117 info
= new wxDirInfo( "/home" );
118 item
.m_text
= info
->GetName();
119 item
.m_data
= (long)info
;
120 InsertItem( m_rootId
, item
);
122 info
= new wxDirInfo( "/mnt" );
123 item
.m_text
= info
->GetName();
124 item
.m_data
= (long)info
;
125 InsertItem( m_rootId
, item
);
127 info
= new wxDirInfo( "/usr" );
128 item
.m_text
= info
->GetName();
129 item
.m_data
= (long)info
;
130 InsertItem( m_rootId
, item
);
132 info
= new wxDirInfo( "/usr/X11R6" );
133 item
.m_text
= info
->GetName();
134 item
.m_data
= (long)info
;
135 InsertItem( m_rootId
, item
);
137 info
= new wxDirInfo( "/usr/local" );
138 item
.m_text
= info
->GetName();
139 item
.m_data
= (long)info
;
140 InsertItem( m_rootId
, item
);
142 info
= new wxDirInfo( "/var" );
143 item
.m_text
= info
->GetName();
144 item
.m_data
= (long)info
;
145 InsertItem( m_rootId
, item
);
147 info
= new wxDirInfo( "/proc" );
148 item
.m_text
= info
->GetName();
149 item
.m_data
= (long)info
;
150 InsertItem( m_rootId
, item
);
155 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
159 wxString search
,path
,filename
;
161 search
= info
->GetPath();
164 path
= wxFindFirstFile( search
, wxDIR
);
165 while (!path
.IsNull())
167 filename
= wxFileNameFromPath( path
);
168 if (m_showHidden
|| (filename
[0] != '.'))
170 if ((filename
!= ".") &&
171 (filename
!= "..") &&
173 (path
!= "/usr/X11R6") &&
174 (path
!= "/usr/local") &&
182 slist
.Add( path
); // ref counting in action !
184 path
= wxFindNextFile();
187 for (uint i
= 0; i
< slist
.Count(); i
++)
191 path
= wxFindFirstFile( search
, wxDIR
);
193 wxDirInfo
*child
= new wxDirInfo( slist
[i
] );
195 item
.m_mask
= wxTREE_MASK_TEXT
| wxTREE_MASK_CHILDREN
| wxTREE_MASK_DATA
;
196 item
.m_text
= child
->GetName();
198 if (!path
.IsNull()) item
.m_children
= 1;
199 item
.m_data
= (long)child
;
200 InsertItem( event
.m_item
.m_itemId
, item
);
204 void wxDirCtrl::OnCollapseItem( const wxTreeEvent
&event
)
206 DeleteChildren( event
.m_item
.m_itemId
);
209 void wxDirCtrl::OnDeleteItem( const wxTreeEvent
&event
)
211 wxDirInfo
*info
= (wxDirInfo
*)event
.m_item
.m_data
;
212 if (info
) delete info
;