]> git.saurik.com Git - wxWidgets.git/blame - user/wxFile/dirctrl.cpp
typo fixed
[wxWidgets.git] / user / wxFile / dirctrl.cpp
CommitLineData
c801d85f
KB
1/*
2 * Author: Robert Roebling
3 *
4 * Copyright: (C) 1997,1998 Robert Roebling
5 *
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).
9 *
10 */
11
12#ifdef __GNUG__
13#pragma implementation "dirctrl.h"
14#endif
15
16#include "dirctrl.h"
17#include "wx/gdicmn.h"
18#include "wx/utils.h"
e3e65dac 19#include "wx/dnd.h"
c801d85f
KB
20
21//-----------------------------------------------------------------------------
22// wxDirInfo
23//-----------------------------------------------------------------------------
24
25IMPLEMENT_DYNAMIC_CLASS(wxDirInfo,wxObject)
26
27wxDirInfo::wxDirInfo( const wxString &path )
28{
29 m_showHidden = FALSE;
30 m_path = path;
31 if (m_path == "/") m_name ="The Computer";
32 else
33 if (m_path == "/home")
34 {
35 m_name = "My Home";
e55ad60e
RR
36 m_path = "";
37 wxGetHomeDir( &m_path );
c801d85f
KB
38 }
39 else
40 if (m_path == "/proc") m_name = "Info Filesystem";
41 else
42 if (m_path == "/mnt") m_name = "Mounted Devices";
43 else
44 if (m_path == "/usr/X11R6") m_name = "User X11";
45 else
46 if (m_path == "/usr") m_name = "User";
47 else
48 if (m_path == "/var") m_name = "Variables";
49 else
50 if (m_path == "/usr/local") m_name = "User local";
51 else
52 if (m_path == "/mnt") m_name = "Mounted Devices";
53 else
54 m_name = wxFileNameFromPath( m_path );
55};
56
57wxString wxDirInfo::GetName(void) const
58{
59 return m_name;
60};
61
62wxString wxDirInfo::GetPath(void) const
63{
64 return m_path;
65};
66
67//-----------------------------------------------------------------------------
68// wxDirCtrl
69//-----------------------------------------------------------------------------
70
71IMPLEMENT_DYNAMIC_CLASS(wxDirCtrl,wxTreeCtrl)
72
73BEGIN_EVENT_TABLE(wxDirCtrl,wxTreeCtrl)
74 EVT_TREE_ITEM_EXPANDED (-1, wxDirCtrl::OnExpandItem)
4c681997 75 EVT_TREE_ITEM_COLLAPSED (-1, wxDirCtrl::OnCollapseItem)
c801d85f 76 EVT_TREE_DELETE_ITEM (-1, wxDirCtrl::OnDeleteItem)
c801d85f
KB
77END_EVENT_TABLE()
78
79wxDirCtrl::wxDirCtrl(void)
80{
81 m_showHidden = FALSE;
82};
83
4c681997 84wxDirCtrl::wxDirCtrl(wxWindow *parent, const wxWindowID id, const wxString &WXUNUSED(dir),
c801d85f
KB
85 const wxPoint& pos, const wxSize& size,
86 const long style, const wxString& name )
87 :
88 wxTreeCtrl( parent, id, pos, size, style, name )
89{
90 m_showHidden = FALSE;
91
92 wxTreeItem item;
93 item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
4c681997 94 item.m_text = "Sections";
c801d85f 95 item.m_children = 1;
4c681997 96 m_rootId = InsertItem( 0, item );
e3e65dac 97
e55ad60e 98// SetDropTarget( new wxFileDropTarget() );
4c681997
RR
99};
100
101void wxDirCtrl::OnExpandItem( const wxTreeEvent &event )
102{
103 if (event.m_item.m_itemId == m_rootId)
104 {
105
106 wxTreeItem item;
107 item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
108 item.m_children = 1;
109
110 wxDirInfo *info = new wxDirInfo( "/" );
111 item.m_text = info->GetName();
112 item.m_data = (long)info;
113 InsertItem( m_rootId, item );
c801d85f 114
4c681997
RR
115 info = new wxDirInfo( "/home" );
116 item.m_text = info->GetName();
117 item.m_data = (long)info;
118 InsertItem( m_rootId, item );
c801d85f 119
4c681997
RR
120 info = new wxDirInfo( "/mnt" );
121 item.m_text = info->GetName();
122 item.m_data = (long)info;
123 InsertItem( m_rootId, item );
c801d85f 124
4c681997
RR
125 info = new wxDirInfo( "/usr" );
126 item.m_text = info->GetName();
127 item.m_data = (long)info;
128 InsertItem( m_rootId, item );
c801d85f 129
4c681997
RR
130 info = new wxDirInfo( "/usr/X11R6" );
131 item.m_text = info->GetName();
132 item.m_data = (long)info;
133 InsertItem( m_rootId, item );
c801d85f 134
4c681997
RR
135 info = new wxDirInfo( "/usr/local" );
136 item.m_text = info->GetName();
137 item.m_data = (long)info;
138 InsertItem( m_rootId, item );
c801d85f 139
4c681997
RR
140 info = new wxDirInfo( "/var" );
141 item.m_text = info->GetName();
142 item.m_data = (long)info;
143 InsertItem( m_rootId, item );
c801d85f 144
4c681997
RR
145 info = new wxDirInfo( "/proc" );
146 item.m_text = info->GetName();
147 item.m_data = (long)info;
148 InsertItem( m_rootId, item );
149
150 return;
151 };
c801d85f 152
c801d85f
KB
153 wxDirInfo *info = (wxDirInfo *)event.m_item.m_data;
154 if (!info) return;
155
156 wxArrayString slist;
157 wxString search,path,filename;
158
159 search = info->GetPath();
160 search += "/*";
161
162 path = wxFindFirstFile( search, wxDIR );
163 while (!path.IsNull())
164 {
165 filename = wxFileNameFromPath( path );
166 if (m_showHidden || (filename[0] != '.'))
167 {
168 if ((filename != ".") &&
169 (filename != "..") &&
170 (path != "/home") &&
171 (path != "/usr/X11R6") &&
172 (path != "/usr/local") &&
173 (path != "/usr") &&
174 (path != "/var") &&
175 (path != "/home") &&
176 (path != "/proc") &&
177 (path != "/mnt")
178 )
e3e65dac
RR
179
180 slist.Add( path ); // ref counting in action !
c801d85f
KB
181 };
182 path = wxFindNextFile();
183 };
184
4c681997 185 for (uint i = 0; i < slist.Count(); i++)
c801d85f
KB
186 {
187 search = slist[i];
188 search += "/*";
189 path = wxFindFirstFile( search, wxDIR );
190
191 wxDirInfo *child = new wxDirInfo( slist[i] );
192 wxTreeItem item;
193 item.m_mask = wxTREE_MASK_TEXT | wxTREE_MASK_CHILDREN | wxTREE_MASK_DATA;
194 item.m_text = child->GetName();
195 item.m_children = 0;
196 if (!path.IsNull()) item.m_children = 1;
197 item.m_data = (long)child;
198 InsertItem( event.m_item.m_itemId, item );
199 };
200};
201
4c681997
RR
202void wxDirCtrl::OnCollapseItem( const wxTreeEvent &event )
203{
204 DeleteChildren( event.m_item.m_itemId );
205};
206
c801d85f
KB
207void wxDirCtrl::OnDeleteItem( const wxTreeEvent &event )
208{
209 wxDirInfo *info = (wxDirInfo *)event.m_item.m_data;
210 if (info) delete info;
211};