]>
Commit | Line | Data |
---|---|---|
81169710 | 1 | ////////////////////////////////////////////////////////////////////////////// |
8b17ba72 | 2 | // Name: filedlgg.cpp |
23254b13 | 3 | // Purpose: wxGenericFileDialog |
8b17ba72 RR |
4 | // Author: Robert Roebling |
5 | // Modified by: | |
6 | // Created: 12/12/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robert Roebling | |
65571936 | 9 | // Licence: wxWindows licence |
8b17ba72 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
8b17ba72 RR |
13 | #pragma implementation "filedlgg.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
4e1901b7 | 23 | #if wxUSE_FILEDLG |
1e6feb95 | 24 | |
06cc1fb9 | 25 | // NOTE : it probably also supports MAC, untested |
144cf6da | 26 | #if !defined(__UNIX__) && !defined(__DOS__) && !defined(__WIN32__) && !defined(__OS2__) |
23254b13 | 27 | #error wxGenericFileDialog currently only supports Unix, win32 and DOS |
8b17ba72 RR |
28 | #endif |
29 | ||
04dbb646 VZ |
30 | #include "wx/checkbox.h" |
31 | #include "wx/textctrl.h" | |
32 | #include "wx/choice.h" | |
33 | #include "wx/checkbox.h" | |
34 | #include "wx/stattext.h" | |
8b17ba72 RR |
35 | #include "wx/debug.h" |
36 | #include "wx/log.h" | |
37 | #include "wx/intl.h" | |
38 | #include "wx/msgdlg.h" | |
39 | #include "wx/sizer.h" | |
0b855868 | 40 | #include "wx/bmpbuttn.h" |
cae5359f | 41 | #include "wx/tokenzr.h" |
eaf40b23 | 42 | #include "wx/config.h" |
48fe8374 | 43 | #include "wx/imaglist.h" |
5e673a6a | 44 | #include "wx/dir.h" |
60d2cc25 | 45 | #include "wx/artprov.h" |
1142c837 | 46 | #include "wx/settings.h" |
1265e13d | 47 | #include "wx/file.h" // for wxS_IXXX constants only |
23254b13 JS |
48 | #include "wx/filedlg.h" // wxOPEN, wxSAVE... |
49 | #include "wx/generic/filedlgg.h" | |
06cc1fb9 | 50 | #include "wx/generic/dirctrlg.h" // for wxFileIconsTable |
8b17ba72 | 51 | |
e6daf794 RR |
52 | #if wxUSE_TOOLTIPS |
53 | #include "wx/tooltip.h" | |
54 | #endif | |
55 | ||
ac2def68 RR |
56 | #include <sys/types.h> |
57 | #include <sys/stat.h> | |
4894ae18 VS |
58 | |
59 | #ifdef __UNIX__ | |
60 | #include <dirent.h> | |
61 | #include <pwd.h> | |
62 | #ifndef __VMS | |
63 | # include <grp.h> | |
64 | #endif | |
65 | #endif | |
66 | ||
6a8c7c70 VS |
67 | #ifdef __WINDOWS__ |
68 | #include "wx/msw/wrapwin.h" | |
69 | #include "wx/msw/mslu.h" | |
70 | #endif | |
71 | ||
4894ae18 VS |
72 | #ifdef __WATCOMC__ |
73 | #include <direct.h> | |
27df579a | 74 | #endif |
4894ae18 | 75 | |
7a82dabc | 76 | #include <time.h> |
099d4217 | 77 | #if defined(__UNIX__) || defined(__DOS__) |
ac2def68 | 78 | #include <unistd.h> |
099d4217 | 79 | #endif |
8b17ba72 | 80 | |
655cf310 | 81 | // ---------------------------------------------------------------------------- |
06cc1fb9 | 82 | // private functions |
655cf310 VS |
83 | // ---------------------------------------------------------------------------- |
84 | ||
06cc1fb9 | 85 | static |
7a1e00a1 | 86 | int wxCALLBACK wxFileDataNameCompare( long data1, long data2, long data) |
655cf310 | 87 | { |
06cc1fb9 JS |
88 | wxFileData *fd1 = (wxFileData*)data1; |
89 | wxFileData *fd2 = (wxFileData*)data2; | |
90 | if (fd1->GetFileName() == wxT("..")) return -data; | |
91 | if (fd2->GetFileName() == wxT("..")) return data; | |
92 | if (fd1->IsDir() && !fd2->IsDir()) return -data; | |
93 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
94 | return data*wxStrcmp( fd1->GetFileName(), fd2->GetFileName() ); | |
655cf310 VS |
95 | } |
96 | ||
c8c0e54c | 97 | static |
7a1e00a1 | 98 | int wxCALLBACK wxFileDataSizeCompare( long data1, long data2, long data) |
23254b13 JS |
99 | { |
100 | wxFileData *fd1 = (wxFileData*)data1; | |
101 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
102 | if (fd1->GetFileName() == wxT("..")) return -data; |
103 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
104 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
105 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
06cc1fb9 JS |
106 | if (fd1->IsLink() && !fd2->IsLink()) return -data; |
107 | if (fd2->IsLink() && !fd1->IsLink()) return data; | |
108 | return data*(fd1->GetSize() - fd2->GetSize()); | |
23254b13 JS |
109 | } |
110 | ||
111 | static | |
7a1e00a1 | 112 | int wxCALLBACK wxFileDataTypeCompare( long data1, long data2, long data) |
23254b13 JS |
113 | { |
114 | wxFileData *fd1 = (wxFileData*)data1; | |
115 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
116 | if (fd1->GetFileName() == wxT("..")) return -data; |
117 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
118 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
119 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
120 | if (fd1->IsLink() && !fd2->IsLink()) return -data; | |
121 | if (fd2->IsLink() && !fd1->IsLink()) return data; | |
b600ed13 | 122 | return data*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() ); |
23254b13 JS |
123 | } |
124 | ||
125 | static | |
7a1e00a1 | 126 | int wxCALLBACK wxFileDataTimeCompare( long data1, long data2, long data) |
23254b13 JS |
127 | { |
128 | wxFileData *fd1 = (wxFileData*)data1; | |
129 | wxFileData *fd2 = (wxFileData*)data2; | |
06cc1fb9 JS |
130 | if (fd1->GetFileName() == wxT("..")) return -data; |
131 | if (fd2->GetFileName() == wxT("..")) return data; | |
23254b13 JS |
132 | if (fd1->IsDir() && !fd2->IsDir()) return -data; |
133 | if (fd2->IsDir() && !fd1->IsDir()) return data; | |
134 | ||
b600ed13 | 135 | return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? int(data) : -int(data); |
c8c0e54c VZ |
136 | } |
137 | ||
144cf6da | 138 | #if defined(__UNIX__) && !defined(__OS2__) |
5e673a6a VS |
139 | #define IsTopMostDir(dir) (dir == wxT("/")) |
140 | #endif | |
141 | ||
144cf6da | 142 | #if defined(__DOS__) || defined(__WINDOWS__) || defined (__OS2__) |
abc2a4cc | 143 | #define IsTopMostDir(dir) (dir.empty()) |
5e673a6a VS |
144 | #endif |
145 | ||
4f5c180e | 146 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 | 147 | // defined in src/generic/dirctrlg.cpp |
37fd1c97 VS |
148 | extern bool wxIsDriveAvailable(const wxString& dirName); |
149 | #endif | |
150 | ||
06cc1fb9 JS |
151 | // defined in src/generic/dirctrlg.cpp |
152 | extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, wxArrayInt &icon_ids); | |
153 | ||
8b17ba72 RR |
154 | //----------------------------------------------------------------------------- |
155 | // wxFileData | |
156 | //----------------------------------------------------------------------------- | |
157 | ||
06cc1fb9 | 158 | wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id ) |
8b17ba72 | 159 | { |
ca9fb418 | 160 | Init(); |
06cc1fb9 JS |
161 | m_fileName = fileName; |
162 | m_filePath = filePath; | |
23254b13 | 163 | m_type = type; |
06cc1fb9 | 164 | m_image = image_id; |
7a82dabc | 165 | |
b600ed13 VZ |
166 | ReadData(); |
167 | } | |
168 | ||
ca9fb418 VZ |
169 | void wxFileData::Init() |
170 | { | |
171 | m_size = 0; | |
172 | m_type = wxFileData::is_file; | |
173 | m_image = wxFileIconsTable::file; | |
174 | } | |
175 | ||
81169710 VZ |
176 | void wxFileData::Copy( const wxFileData& fileData ) |
177 | { | |
178 | m_fileName = fileData.GetFileName(); | |
179 | m_filePath = fileData.GetFilePath(); | |
180 | m_size = fileData.GetSize(); | |
181 | m_dateTime = fileData.GetDateTime(); | |
182 | m_permissions = fileData.GetPermissions(); | |
183 | m_type = fileData.GetType(); | |
ca9fb418 | 184 | m_image = fileData.GetImageId(); |
81169710 VZ |
185 | } |
186 | ||
b600ed13 VZ |
187 | void wxFileData::ReadData() |
188 | { | |
06cc1fb9 | 189 | if (IsDrive()) |
37fd1c97 | 190 | { |
23254b13 JS |
191 | m_size = 0; |
192 | return; | |
193 | } | |
194 | ||
144cf6da | 195 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 | 196 | // c:\.. is a drive don't stat it |
567be187 | 197 | if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5)) |
23254b13 JS |
198 | { |
199 | m_type = is_drive; | |
37fd1c97 VS |
200 | m_size = 0; |
201 | return; | |
202 | } | |
7f04165e | 203 | #endif // __DOS__ || __WINDOWS__ |
c8c0e54c | 204 | |
8115f9e7 | 205 | wxStructStat buff; |
479cd5de | 206 | |
144cf6da | 207 | #if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS)) |
06cc1fb9 | 208 | lstat( m_filePath.fn_str(), &buff ); |
23254b13 | 209 | m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0; |
7f04165e | 210 | #else // no lstat() |
f3660dcb SC |
211 | // only translate to file charset if we don't go by our |
212 | // wxStat implementation | |
213 | #ifndef wxNEED_WX_UNISTD_H | |
214 | wxStat( m_filePath.fn_str() , &buff ); | |
215 | #else | |
06cc1fb9 | 216 | wxStat( m_filePath, &buff ); |
f3660dcb | 217 | #endif |
9f2d09aa RR |
218 | #endif |
219 | ||
23254b13 JS |
220 | m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0; |
221 | m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0; | |
8b17ba72 | 222 | |
06cc1fb9 JS |
223 | // try to get a better icon |
224 | if (m_image == wxFileIconsTable::file) | |
225 | { | |
ca65c044 WS |
226 | if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND) |
227 | { | |
1d529ef7 | 228 | m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.'))); |
ca65c044 WS |
229 | } else if (IsExe()) |
230 | { | |
06cc1fb9 | 231 | m_image = wxFileIconsTable::executable; |
ca65c044 | 232 | } |
06cc1fb9 JS |
233 | } |
234 | ||
254a2129 | 235 | m_size = (long)buff.st_size; |
8b17ba72 | 236 | |
06cc1fb9 | 237 | m_dateTime = buff.st_mtime; |
8b17ba72 | 238 | |
06cc1fb9 JS |
239 | #if defined(__UNIX__) |
240 | m_permissions.Printf(_T("%c%c%c%c%c%c%c%c%c"), | |
7f04165e VZ |
241 | buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'), |
242 | buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'), | |
06cc1fb9 JS |
243 | buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'), |
244 | buff.st_mode & wxS_IRGRP ? _T('r') : _T('-'), | |
245 | buff.st_mode & wxS_IWGRP ? _T('w') : _T('-'), | |
246 | buff.st_mode & wxS_IXGRP ? _T('x') : _T('-'), | |
247 | buff.st_mode & wxS_IROTH ? _T('r') : _T('-'), | |
248 | buff.st_mode & wxS_IWOTH ? _T('w') : _T('-'), | |
249 | buff.st_mode & wxS_IXOTH ? _T('x') : _T('-')); | |
250 | #elif defined(__WIN32__) | |
567be187 | 251 | DWORD attribs = GetFileAttributes(m_filePath); |
06cc1fb9 JS |
252 | if (attribs != (DWORD)-1) |
253 | { | |
254 | m_permissions.Printf(_T("%c%c%c%c"), | |
255 | attribs & FILE_ATTRIBUTE_ARCHIVE ? _T('A') : _T(' '), | |
256 | attribs & FILE_ATTRIBUTE_READONLY ? _T('R') : _T(' '), | |
257 | attribs & FILE_ATTRIBUTE_HIDDEN ? _T('H') : _T(' '), | |
258 | attribs & FILE_ATTRIBUTE_SYSTEM ? _T('S') : _T(' ')); | |
259 | } | |
260 | #endif | |
8b17ba72 RR |
261 | } |
262 | ||
b600ed13 | 263 | wxString wxFileData::GetFileType() const |
8b17ba72 | 264 | { |
06cc1fb9 JS |
265 | if (IsDir()) |
266 | return _("<DIR>"); | |
267 | else if (IsLink()) | |
268 | return _("<LINK>"); | |
269 | else if (IsDrive()) | |
270 | return _("<DRIVE>"); | |
ca65c044 | 271 | else if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND) |
06cc1fb9 | 272 | return m_fileName.AfterLast(wxT('.')); |
8b17ba72 | 273 | |
06cc1fb9 | 274 | return wxEmptyString; |
8b17ba72 RR |
275 | } |
276 | ||
06cc1fb9 | 277 | wxString wxFileData::GetModificationTime() const |
23254b13 | 278 | { |
06cc1fb9 JS |
279 | // want time as 01:02 so they line up nicely, no %r in WIN32 |
280 | return m_dateTime.FormatDate() + wxT(" ") + m_dateTime.Format(wxT("%I:%M:%S %p")); | |
23254b13 JS |
281 | } |
282 | ||
8b17ba72 RR |
283 | wxString wxFileData::GetHint() const |
284 | { | |
06cc1fb9 | 285 | wxString s = m_filePath; |
2b5f62a0 | 286 | s += wxT(" "); |
b8985048 | 287 | |
23254b13 | 288 | if (IsDir()) |
b8985048 | 289 | s += _("<DIR>"); |
23254b13 | 290 | else if (IsLink()) |
b8985048 | 291 | s += _("<LINK>"); |
23254b13 | 292 | else if (IsDrive()) |
b8985048 VZ |
293 | s += _("<DRIVE>"); |
294 | else // plain file | |
295 | s += wxString::Format( _("%ld bytes"), m_size ); | |
296 | ||
297 | s += wxT(' '); | |
298 | ||
299 | if ( !IsDrive() ) | |
23254b13 | 300 | { |
b8985048 VZ |
301 | s << GetModificationTime() |
302 | << wxT(" ") | |
303 | << m_permissions; | |
8b17ba72 | 304 | } |
23254b13 | 305 | |
8b17ba72 RR |
306 | return s; |
307 | }; | |
308 | ||
23254b13 | 309 | wxString wxFileData::GetEntry( fileListFieldType num ) const |
8b17ba72 RR |
310 | { |
311 | wxString s; | |
9cedab37 | 312 | switch ( num ) |
8b17ba72 | 313 | { |
9cedab37 | 314 | case FileList_Name: |
06cc1fb9 | 315 | s = m_fileName; |
8b17ba72 | 316 | break; |
9cedab37 | 317 | |
06cc1fb9 JS |
318 | case FileList_Size: |
319 | if (!IsDir() && !IsLink() && !IsDrive()) | |
9cedab37 | 320 | s.Printf(_T("%ld"), m_size); |
8b17ba72 | 321 | break; |
9cedab37 | 322 | |
06cc1fb9 | 323 | case FileList_Type: |
b600ed13 | 324 | s = GetFileType(); |
8b17ba72 | 325 | break; |
8b17ba72 | 326 | |
9cedab37 | 327 | case FileList_Time: |
23254b13 | 328 | if (!IsDrive()) |
06cc1fb9 | 329 | s = GetModificationTime(); |
9cedab37 | 330 | break; |
8b17ba72 | 331 | |
06cc1fb9 | 332 | #if defined(__UNIX__) || defined(__WIN32__) |
9cedab37 VZ |
333 | case FileList_Perm: |
334 | s = m_permissions; | |
335 | break; | |
06cc1fb9 | 336 | #endif // defined(__UNIX__) || defined(__WIN32__) |
8b17ba72 | 337 | |
9cedab37 VZ |
338 | default: |
339 | wxFAIL_MSG( _T("unexpected field in wxFileData::GetEntry()") ); | |
340 | } | |
8b17ba72 | 341 | |
9cedab37 | 342 | return s; |
8b17ba72 RR |
343 | } |
344 | ||
06cc1fb9 | 345 | void wxFileData::SetNewName( const wxString &filePath, const wxString &fileName ) |
8b17ba72 | 346 | { |
06cc1fb9 JS |
347 | m_fileName = fileName; |
348 | m_filePath = filePath; | |
8b17ba72 RR |
349 | } |
350 | ||
351 | void wxFileData::MakeItem( wxListItem &item ) | |
352 | { | |
06cc1fb9 | 353 | item.m_text = m_fileName; |
9b00bb16 | 354 | item.ClearAttributes(); |
9cedab37 VZ |
355 | if (IsExe()) |
356 | item.SetTextColour(*wxRED); | |
357 | if (IsDir()) | |
358 | item.SetTextColour(*wxBLUE); | |
48fe8374 | 359 | |
06cc1fb9 | 360 | item.m_image = m_image; |
655cf310 | 361 | |
8b17ba72 RR |
362 | if (IsLink()) |
363 | { | |
564a150b VZ |
364 | wxColour dg = wxTheColourDatabase->Find( _T("MEDIUM GREY") ); |
365 | if ( dg.Ok() ) | |
366 | item.SetTextColour(dg); | |
8b17ba72 RR |
367 | } |
368 | item.m_data = (long)this; | |
369 | } | |
c8c0e54c | 370 | |
8b17ba72 RR |
371 | //----------------------------------------------------------------------------- |
372 | // wxFileCtrl | |
373 | //----------------------------------------------------------------------------- | |
374 | ||
d84afea9 | 375 | IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl) |
8b17ba72 RR |
376 | |
377 | BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl) | |
ca65c044 WS |
378 | EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileCtrl::OnListDeleteItem) |
379 | EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileCtrl::OnListDeleteAllItems) | |
380 | EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileCtrl::OnListEndLabelEdit) | |
381 | EVT_LIST_COL_CLICK(wxID_ANY, wxFileCtrl::OnListColClick) | |
8b17ba72 RR |
382 | END_EVENT_TABLE() |
383 | ||
655cf310 | 384 | |
8b17ba72 RR |
385 | wxFileCtrl::wxFileCtrl() |
386 | { | |
ca65c044 | 387 | m_showHidden = false; |
23254b13 JS |
388 | m_sort_foward = 1; |
389 | m_sort_field = wxFileData::FileList_Name; | |
8b17ba72 RR |
390 | } |
391 | ||
9cedab37 VZ |
392 | wxFileCtrl::wxFileCtrl(wxWindow *win, |
393 | wxWindowID id, | |
394 | const wxString& wild, | |
395 | bool showHidden, | |
396 | const wxPoint& pos, | |
397 | const wxSize& size, | |
398 | long style, | |
399 | const wxValidator &validator, | |
5e673a6a | 400 | const wxString &name) |
9cedab37 VZ |
401 | : wxListCtrl(win, id, pos, size, style, validator, name), |
402 | m_wild(wild) | |
8b17ba72 | 403 | { |
06cc1fb9 | 404 | wxImageList *imageList = wxTheFileIconsTable->GetSmallImageList(); |
655cf310 | 405 | |
0b855868 | 406 | SetImageList( imageList, wxIMAGE_LIST_SMALL ); |
c8c0e54c | 407 | |
9cedab37 | 408 | m_showHidden = showHidden; |
23254b13 JS |
409 | |
410 | m_sort_foward = 1; | |
411 | m_sort_field = wxFileData::FileList_Name; | |
412 | ||
413 | m_dirName = wxT("*"); | |
414 | ||
415 | if (style & wxLC_REPORT) | |
416 | ChangeToReportMode(); | |
8b17ba72 RR |
417 | } |
418 | ||
419 | void wxFileCtrl::ChangeToListMode() | |
420 | { | |
23254b13 | 421 | ClearAll(); |
8b17ba72 | 422 | SetSingleStyle( wxLC_LIST ); |
8f4fcc4e | 423 | UpdateFiles(); |
8b17ba72 RR |
424 | } |
425 | ||
426 | void wxFileCtrl::ChangeToReportMode() | |
427 | { | |
23254b13 | 428 | ClearAll(); |
8b17ba72 | 429 | SetSingleStyle( wxLC_REPORT ); |
23254b13 | 430 | |
06cc1fb9 JS |
431 | // do this since WIN32 does mm/dd/yy UNIX does mm/dd/yyyy |
432 | // don't hardcode since mm/dd is dd/mm elsewhere | |
23254b13 | 433 | int w, h; |
06cc1fb9 JS |
434 | wxDateTime dt(22, wxDateTime::Dec, 2002, 22, 22, 22); |
435 | wxString txt = dt.FormatDate() + wxT("22") + dt.Format(wxT("%I:%M:%S %p")); | |
436 | GetTextExtent(txt, &w, &h); | |
437 | ||
438 | InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, w ); | |
439 | InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, w/2 ); | |
440 | InsertColumn( 2, _("Type"), wxLIST_FORMAT_LEFT, w/2 ); | |
441 | InsertColumn( 3, _("Modified"), wxLIST_FORMAT_LEFT, w ); | |
442 | #if defined(__UNIX__) | |
443 | GetTextExtent(wxT("Permissions 2"), &w, &h); | |
444 | InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, w ); | |
445 | #elif defined(__WIN32__) | |
446 | GetTextExtent(wxT("Attributes 2"), &w, &h); | |
447 | InsertColumn( 4, _("Attributes"), wxLIST_FORMAT_LEFT, w ); | |
23254b13 JS |
448 | #endif |
449 | ||
8f4fcc4e | 450 | UpdateFiles(); |
8b17ba72 RR |
451 | } |
452 | ||
06cc1fb9 | 453 | void wxFileCtrl::ChangeToSmallIconMode() |
8b17ba72 | 454 | { |
23254b13 | 455 | ClearAll(); |
06cc1fb9 | 456 | SetSingleStyle( wxLC_SMALL_ICON ); |
8f4fcc4e | 457 | UpdateFiles(); |
8b17ba72 RR |
458 | } |
459 | ||
460 | void wxFileCtrl::ShowHidden( bool show ) | |
461 | { | |
462 | m_showHidden = show; | |
8f4fcc4e | 463 | UpdateFiles(); |
8b17ba72 RR |
464 | } |
465 | ||
0b855868 RR |
466 | long wxFileCtrl::Add( wxFileData *fd, wxListItem &item ) |
467 | { | |
468 | long ret = -1; | |
469 | item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE; | |
470 | fd->MakeItem( item ); | |
471 | long my_style = GetWindowStyleFlag(); | |
472 | if (my_style & wxLC_REPORT) | |
473 | { | |
474 | ret = InsertItem( item ); | |
23254b13 JS |
475 | for (int i = 1; i < wxFileData::FileList_Max; i++) |
476 | SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) ); | |
0b855868 | 477 | } |
06cc1fb9 | 478 | else if ((my_style & wxLC_LIST) || (my_style & wxLC_SMALL_ICON)) |
0b855868 RR |
479 | { |
480 | ret = InsertItem( item ); | |
c8c0e54c | 481 | } |
0b855868 RR |
482 | return ret; |
483 | } | |
484 | ||
b600ed13 VZ |
485 | void wxFileCtrl::UpdateItem(const wxListItem &item) |
486 | { | |
487 | wxFileData *fd = (wxFileData*)GetItemData(item); | |
488 | wxCHECK_RET(fd, wxT("invalid filedata")); | |
489 | ||
490 | fd->ReadData(); | |
491 | ||
492 | SetItemText(item, fd->GetFileName()); | |
c3627a00 | 493 | SetItemImage(item, fd->GetImageId()); |
b600ed13 VZ |
494 | |
495 | if (GetWindowStyleFlag() & wxLC_REPORT) | |
496 | { | |
497 | for (int i = 1; i < wxFileData::FileList_Max; i++) | |
498 | SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) ); | |
499 | } | |
500 | } | |
501 | ||
8f4fcc4e | 502 | void wxFileCtrl::UpdateFiles() |
c8c0e54c | 503 | { |
2b5f62a0 | 504 | // don't do anything before ShowModal() call which sets m_dirName |
23254b13 | 505 | if ( m_dirName == wxT("*") ) |
2b5f62a0 VZ |
506 | return; |
507 | ||
37fd1c97 | 508 | wxBusyCursor bcur; // this may take a while... |
7a82dabc | 509 | |
23254b13 | 510 | DeleteAllItems(); |
7a82dabc | 511 | |
8b17ba72 | 512 | wxListItem item; |
8b17ba72 RR |
513 | item.m_itemId = 0; |
514 | item.m_col = 0; | |
0b855868 | 515 | |
144cf6da | 516 | #if defined(__WINDOWS__) || defined(__DOS__) || defined(__WXMAC__) || defined(__OS2__) |
37fd1c97 | 517 | if ( IsTopMostDir(m_dirName) ) |
abc2a4cc | 518 | { |
06cc1fb9 JS |
519 | wxArrayString names, paths; |
520 | wxArrayInt icons; | |
521 | size_t n, count = wxGetAvailableDrives(paths, names, icons); | |
522 | ||
523 | for (n=0; n<count; n++) | |
abc2a4cc | 524 | { |
999836aa | 525 | wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]); |
81169710 | 526 | if (Add(fd, item) != -1) |
37fd1c97 | 527 | item.m_itemId++; |
81169710 VZ |
528 | else |
529 | delete fd; | |
37fd1c97 | 530 | } |
abc2a4cc | 531 | } |
5e673a6a | 532 | else |
06cc1fb9 | 533 | #endif // defined(__DOS__) || defined(__WINDOWS__) |
8b17ba72 | 534 | { |
5e673a6a VS |
535 | // Real directory... |
536 | if ( !IsTopMostDir(m_dirName) ) | |
8b17ba72 | 537 | { |
5e673a6a | 538 | wxString p(wxPathOnly(m_dirName)); |
144cf6da | 539 | #if defined(__UNIX__) && !defined(__OS2__) |
abc2a4cc | 540 | if (p.empty()) p = wxT("/"); |
06cc1fb9 | 541 | #endif // __UNIX__ |
999836aa | 542 | wxFileData *fd = new wxFileData(p, wxT(".."), wxFileData::is_dir, wxFileIconsTable::folder); |
81169710 | 543 | if (Add(fd, item) != -1) |
8b17ba72 | 544 | item.m_itemId++; |
81169710 VZ |
545 | else |
546 | delete fd; | |
8b17ba72 | 547 | } |
c8c0e54c | 548 | |
5e673a6a | 549 | wxString dirname(m_dirName); |
144cf6da | 550 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
5e673a6a VS |
551 | if (dirname.length() == 2 && dirname[1u] == wxT(':')) |
552 | dirname << wxT('\\'); | |
144cf6da | 553 | #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
5e673a6a VS |
554 | wxDir dir(dirname); |
555 | ||
556 | if ( dir.IsOpened() ) | |
cae5359f | 557 | { |
23254b13 JS |
558 | wxString dirPrefix(dirname); |
559 | if (dirPrefix.Last() != wxFILE_SEP_PATH) | |
560 | dirPrefix += wxFILE_SEP_PATH; | |
561 | ||
5e673a6a | 562 | int hiddenFlag = m_showHidden ? wxDIR_HIDDEN : 0; |
7a82dabc | 563 | |
5e673a6a VS |
564 | bool cont; |
565 | wxString f; | |
566 | ||
567 | // Get the directories first (not matched against wildcards): | |
568 | cont = dir.GetFirst(&f, wxEmptyString, wxDIR_DIRS | hiddenFlag); | |
569 | while (cont) | |
551adc4b | 570 | { |
999836aa | 571 | wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_dir, wxFileIconsTable::folder); |
81169710 | 572 | if (Add(fd, item) != -1) |
551adc4b | 573 | item.m_itemId++; |
81169710 VZ |
574 | else |
575 | delete fd; | |
576 | ||
5e673a6a VS |
577 | cont = dir.GetNext(&f); |
578 | } | |
579 | ||
7a82dabc | 580 | // Tokenize the wildcard string, so we can handle more than 1 |
5e673a6a VS |
581 | // search pattern in a wildcard. |
582 | wxStringTokenizer tokenWild(m_wild, wxT(";")); | |
583 | while ( tokenWild.HasMoreTokens() ) | |
584 | { | |
7a82dabc | 585 | cont = dir.GetFirst(&f, tokenWild.GetNextToken(), |
5e673a6a VS |
586 | wxDIR_FILES | hiddenFlag); |
587 | while (cont) | |
588 | { | |
999836aa | 589 | wxFileData *fd = new wxFileData(dirPrefix + f, f, wxFileData::is_file, wxFileIconsTable::file); |
81169710 | 590 | if (Add(fd, item) != -1) |
5e673a6a | 591 | item.m_itemId++; |
81169710 VZ |
592 | else |
593 | delete fd; | |
594 | ||
5e673a6a VS |
595 | cont = dir.GetNext(&f); |
596 | } | |
551adc4b | 597 | } |
cae5359f | 598 | } |
cae5359f | 599 | } |
c8c0e54c | 600 | |
06cc1fb9 | 601 | SortItems(m_sort_field, m_sort_foward); |
8b17ba72 RR |
602 | } |
603 | ||
0b855868 | 604 | void wxFileCtrl::SetWild( const wxString &wild ) |
8b17ba72 | 605 | { |
06cc1fb9 JS |
606 | if (wild.Find(wxT('|')) != wxNOT_FOUND) |
607 | return; | |
608 | ||
0b855868 | 609 | m_wild = wild; |
8f4fcc4e | 610 | UpdateFiles(); |
0b855868 RR |
611 | } |
612 | ||
613 | void wxFileCtrl::MakeDir() | |
614 | { | |
5e673a6a | 615 | wxString new_name( _("NewName") ); |
0b855868 | 616 | wxString path( m_dirName ); |
75ec8bd4 | 617 | path += wxFILE_SEP_PATH; |
0b855868 RR |
618 | path += new_name; |
619 | if (wxFileExists(path)) | |
8b17ba72 | 620 | { |
0b855868 RR |
621 | // try NewName0, NewName1 etc. |
622 | int i = 0; | |
c8c0e54c | 623 | do { |
0b855868 | 624 | new_name = _("NewName"); |
c8c0e54c | 625 | wxString num; |
223d09f6 | 626 | num.Printf( wxT("%d"), i ); |
c8c0e54c VZ |
627 | new_name += num; |
628 | ||
0b855868 | 629 | path = m_dirName; |
75ec8bd4 | 630 | path += wxFILE_SEP_PATH; |
0b855868 | 631 | path += new_name; |
c8c0e54c VZ |
632 | i++; |
633 | } while (wxFileExists(path)); | |
8b17ba72 | 634 | } |
c8c0e54c | 635 | |
0b855868 | 636 | wxLogNull log; |
c8c0e54c | 637 | if (!wxMkdir(path)) |
8b17ba72 | 638 | { |
0b855868 | 639 | wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 640 | dialog.ShowModal(); |
0b855868 | 641 | return; |
8b17ba72 | 642 | } |
8b17ba72 | 643 | |
06cc1fb9 | 644 | wxFileData *fd = new wxFileData( path, new_name, wxFileData::is_dir, wxFileIconsTable::folder ); |
0b855868 RR |
645 | wxListItem item; |
646 | item.m_itemId = 0; | |
647 | item.m_col = 0; | |
13111b2a | 648 | long id = Add( fd, item ); |
c8c0e54c | 649 | |
0b855868 RR |
650 | if (id != -1) |
651 | { | |
06cc1fb9 | 652 | SortItems(m_sort_field, m_sort_foward); |
c8c0e54c | 653 | id = FindItem( 0, (long)fd ); |
0b855868 RR |
654 | EnsureVisible( id ); |
655 | EditLabel( id ); | |
656 | } | |
81169710 VZ |
657 | else |
658 | delete fd; | |
8b17ba72 RR |
659 | } |
660 | ||
661 | void wxFileCtrl::GoToParentDir() | |
662 | { | |
5e673a6a | 663 | if (!IsTopMostDir(m_dirName)) |
8b17ba72 | 664 | { |
353f41cb | 665 | size_t len = m_dirName.Len(); |
083f7497 | 666 | if (wxEndsWithPathSeparator(m_dirName)) |
353f41cb | 667 | m_dirName.Remove( len-1, 1 ); |
c8c0e54c | 668 | wxString fname( wxFileNameFromPath(m_dirName) ); |
0b855868 | 669 | m_dirName = wxPathOnly( m_dirName ); |
144cf6da | 670 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
abc2a4cc | 671 | if (!m_dirName.empty()) |
23254b13 JS |
672 | { |
673 | if (m_dirName.Last() == wxT('.')) | |
ca65c044 | 674 | m_dirName = wxEmptyString; |
23254b13 JS |
675 | } |
676 | #elif defined(__UNIX__) | |
abc2a4cc | 677 | if (m_dirName.empty()) |
5e673a6a VS |
678 | m_dirName = wxT("/"); |
679 | #endif | |
8f4fcc4e | 680 | UpdateFiles(); |
13111b2a | 681 | long id = FindItem( 0, fname ); |
abc2a4cc | 682 | if (id != wxNOT_FOUND) |
c8c0e54c VZ |
683 | { |
684 | SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
685 | EnsureVisible( id ); | |
686 | } | |
8b17ba72 RR |
687 | } |
688 | } | |
689 | ||
690 | void wxFileCtrl::GoToHomeDir() | |
691 | { | |
692 | wxString s = wxGetUserHome( wxString() ); | |
5e673a6a | 693 | GoToDir(s); |
8b17ba72 RR |
694 | } |
695 | ||
696 | void wxFileCtrl::GoToDir( const wxString &dir ) | |
697 | { | |
06cc1fb9 JS |
698 | if (!wxDirExists(dir)) return; |
699 | ||
8b17ba72 | 700 | m_dirName = dir; |
8f4fcc4e | 701 | UpdateFiles(); |
e6daf794 RR |
702 | SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
703 | EnsureVisible( 0 ); | |
8b17ba72 RR |
704 | } |
705 | ||
81169710 | 706 | void wxFileCtrl::FreeItemData(wxListItem& item) |
8b17ba72 | 707 | { |
81169710 VZ |
708 | if ( item.m_data ) |
709 | { | |
710 | wxFileData *fd = (wxFileData*)item.m_data; | |
711 | delete fd; | |
712 | ||
713 | item.m_data = 0; | |
714 | } | |
8b17ba72 RR |
715 | } |
716 | ||
7a82dabc VZ |
717 | void wxFileCtrl::OnListDeleteItem( wxListEvent &event ) |
718 | { | |
719 | FreeItemData(event.m_item); | |
720 | } | |
721 | ||
a3a363f6 | 722 | void wxFileCtrl::OnListDeleteAllItems( wxListEvent & WXUNUSED(event) ) |
81169710 VZ |
723 | { |
724 | FreeAllItemsData(); | |
725 | } | |
726 | ||
7a82dabc | 727 | void wxFileCtrl::FreeAllItemsData() |
12c1b46a RR |
728 | { |
729 | wxListItem item; | |
730 | item.m_mask = wxLIST_MASK_DATA; | |
731 | ||
732 | item.m_itemId = GetNextItem( -1, wxLIST_NEXT_ALL ); | |
92da8bde | 733 | while ( item.m_itemId != -1 ) |
12c1b46a RR |
734 | { |
735 | GetItem( item ); | |
7a82dabc | 736 | FreeItemData(item); |
12c1b46a RR |
737 | item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL ); |
738 | } | |
739 | } | |
740 | ||
0b855868 | 741 | void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) |
8b17ba72 RR |
742 | { |
743 | wxFileData *fd = (wxFileData*)event.m_item.m_data; | |
0b855868 | 744 | wxASSERT( fd ); |
c8c0e54c | 745 | |
abc2a4cc | 746 | if ((event.GetLabel().empty()) || |
0b855868 RR |
747 | (event.GetLabel() == _(".")) || |
748 | (event.GetLabel() == _("..")) || | |
75ec8bd4 | 749 | (event.GetLabel().First( wxFILE_SEP_PATH ) != wxNOT_FOUND)) |
8b17ba72 | 750 | { |
0b855868 | 751 | wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 752 | dialog.ShowModal(); |
0b855868 | 753 | event.Veto(); |
c8c0e54c | 754 | return; |
8b17ba72 | 755 | } |
c8c0e54c | 756 | |
06cc1fb9 | 757 | wxString new_name( wxPathOnly( fd->GetFilePath() ) ); |
75ec8bd4 | 758 | new_name += wxFILE_SEP_PATH; |
0b855868 | 759 | new_name += event.GetLabel(); |
c8c0e54c | 760 | |
0b855868 | 761 | wxLogNull log; |
c8c0e54c | 762 | |
0b855868 | 763 | if (wxFileExists(new_name)) |
8b17ba72 | 764 | { |
0b855868 | 765 | wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 766 | dialog.ShowModal(); |
0b855868 | 767 | event.Veto(); |
8b17ba72 | 768 | } |
c8c0e54c | 769 | |
06cc1fb9 | 770 | if (wxRenameFile(fd->GetFilePath(),new_name)) |
8b17ba72 | 771 | { |
0b855868 | 772 | fd->SetNewName( new_name, event.GetLabel() ); |
c8c0e54c | 773 | SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
b600ed13 | 774 | UpdateItem( event.GetItem() ); |
0b855868 | 775 | EnsureVisible( event.GetItem() ); |
8b17ba72 RR |
776 | } |
777 | else | |
778 | { | |
0b855868 | 779 | wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR ); |
c8c0e54c | 780 | dialog.ShowModal(); |
0b855868 | 781 | event.Veto(); |
8b17ba72 | 782 | } |
8b17ba72 RR |
783 | } |
784 | ||
23254b13 JS |
785 | void wxFileCtrl::OnListColClick( wxListEvent &event ) |
786 | { | |
787 | int col = event.GetColumn(); | |
788 | ||
789 | switch (col) | |
790 | { | |
791 | case wxFileData::FileList_Name : | |
06cc1fb9 | 792 | case wxFileData::FileList_Size : |
23254b13 | 793 | case wxFileData::FileList_Type : |
23254b13 JS |
794 | case wxFileData::FileList_Time : break; |
795 | default : return; | |
796 | } | |
797 | ||
798 | if ((wxFileData::fileListFieldType)col == m_sort_field) | |
06cc1fb9 | 799 | m_sort_foward = !m_sort_foward; |
23254b13 JS |
800 | else |
801 | m_sort_field = (wxFileData::fileListFieldType)col; | |
802 | ||
06cc1fb9 | 803 | SortItems(m_sort_field, m_sort_foward); |
23254b13 JS |
804 | } |
805 | ||
806 | void wxFileCtrl::SortItems(wxFileData::fileListFieldType field, bool foward) | |
807 | { | |
808 | m_sort_field = field; | |
06cc1fb9 JS |
809 | m_sort_foward = foward; |
810 | long sort_dir = foward ? 1 : -1; | |
23254b13 JS |
811 | |
812 | switch (m_sort_field) | |
813 | { | |
814 | case wxFileData::FileList_Name : | |
815 | { | |
06cc1fb9 JS |
816 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataNameCompare, sort_dir); |
817 | break; | |
818 | } | |
819 | case wxFileData::FileList_Size : | |
820 | { | |
821 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataSizeCompare, sort_dir); | |
23254b13 JS |
822 | break; |
823 | } | |
824 | case wxFileData::FileList_Type : | |
825 | { | |
06cc1fb9 | 826 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTypeCompare, sort_dir); |
23254b13 JS |
827 | break; |
828 | } | |
23254b13 JS |
829 | case wxFileData::FileList_Time : |
830 | { | |
06cc1fb9 | 831 | wxListCtrl::SortItems((wxListCtrlCompare)wxFileDataTimeCompare, sort_dir); |
23254b13 JS |
832 | break; |
833 | } | |
834 | default : break; | |
835 | } | |
836 | } | |
837 | ||
7a82dabc VZ |
838 | wxFileCtrl::~wxFileCtrl() |
839 | { | |
118322a3 WS |
840 | // Normally the data are freed via an EVT_LIST_DELETE_ALL_ITEMS event and |
841 | // wxFileCtrl::OnListDeleteAllItems. But if the event is generated after | |
842 | // the destruction of the wxFileCtrl we need to free any data here: | |
843 | FreeAllItemsData(); | |
7a82dabc VZ |
844 | } |
845 | ||
8b17ba72 | 846 | //----------------------------------------------------------------------------- |
23254b13 | 847 | // wxGenericFileDialog |
8b17ba72 RR |
848 | //----------------------------------------------------------------------------- |
849 | ||
5e673a6a VS |
850 | #define ID_LIST_MODE (wxID_FILEDLGG ) |
851 | #define ID_REPORT_MODE (wxID_FILEDLGG + 1) | |
852 | #define ID_UP_DIR (wxID_FILEDLGG + 5) | |
853 | #define ID_PARENT_DIR (wxID_FILEDLGG + 6) | |
854 | #define ID_NEW_DIR (wxID_FILEDLGG + 7) | |
855 | #define ID_CHOICE (wxID_FILEDLGG + 8) | |
856 | #define ID_TEXT (wxID_FILEDLGG + 9) | |
857 | #define ID_LIST_CTRL (wxID_FILEDLGG + 10) | |
858 | #define ID_ACTIVATED (wxID_FILEDLGG + 11) | |
859 | #define ID_CHECK (wxID_FILEDLGG + 12) | |
8b17ba72 | 860 | |
f74172ab | 861 | IMPLEMENT_DYNAMIC_CLASS(wxGenericFileDialog, wxFileDialogBase) |
23254b13 JS |
862 | |
863 | BEGIN_EVENT_TABLE(wxGenericFileDialog,wxDialog) | |
864 | EVT_BUTTON(ID_LIST_MODE, wxGenericFileDialog::OnList) | |
865 | EVT_BUTTON(ID_REPORT_MODE, wxGenericFileDialog::OnReport) | |
866 | EVT_BUTTON(ID_UP_DIR, wxGenericFileDialog::OnUp) | |
867 | EVT_BUTTON(ID_PARENT_DIR, wxGenericFileDialog::OnHome) | |
868 | EVT_BUTTON(ID_NEW_DIR, wxGenericFileDialog::OnNew) | |
869 | EVT_BUTTON(wxID_OK, wxGenericFileDialog::OnListOk) | |
870 | EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxGenericFileDialog::OnSelected) | |
871 | EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxGenericFileDialog::OnActivated) | |
872 | EVT_CHOICE(ID_CHOICE,wxGenericFileDialog::OnChoiceFilter) | |
873 | EVT_TEXT_ENTER(ID_TEXT,wxGenericFileDialog::OnTextEnter) | |
874 | EVT_TEXT(ID_TEXT,wxGenericFileDialog::OnTextChange) | |
875 | EVT_CHECKBOX(ID_CHECK,wxGenericFileDialog::OnCheck) | |
8b17ba72 RR |
876 | END_EVENT_TABLE() |
877 | ||
23254b13 | 878 | long wxGenericFileDialog::ms_lastViewStyle = wxLC_LIST; |
ca65c044 | 879 | bool wxGenericFileDialog::ms_lastShowHidden = false; |
655cf310 | 880 | |
23254b13 | 881 | wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, |
9cedab37 VZ |
882 | const wxString& message, |
883 | const wxString& defaultDir, | |
884 | const wxString& defaultFile, | |
885 | const wxString& wildCard, | |
886 | long style, | |
4e1901b7 RR |
887 | const wxPoint& pos, |
888 | bool bypassGenericImpl ) | |
f74172ab | 889 | :wxFileDialogBase(parent, message, defaultDir, defaultFile, wildCard, style, pos) |
8b17ba72 | 890 | { |
4e1901b7 | 891 | m_bypassGenericImpl = bypassGenericImpl; |
abc2a4cc | 892 | |
4e1901b7 RR |
893 | if (!m_bypassGenericImpl) |
894 | Create( parent, message, defaultDir, defaultFile, wildCard, style, pos ); | |
895 | } | |
896 | ||
897 | bool wxGenericFileDialog::Create( wxWindow *parent, | |
abc2a4cc WS |
898 | const wxString& message, |
899 | const wxString& WXUNUSED(defaultDir), | |
900 | const wxString& defaultFile, | |
901 | const wxString& wildCard, | |
902 | long WXUNUSED(style), | |
903 | const wxPoint& pos ) | |
4e1901b7 RR |
904 | { |
905 | if (!wxDialog::Create( parent, wxID_ANY, message, pos, wxDefaultSize, | |
906 | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )) | |
907 | { | |
908 | return false; | |
909 | } | |
f74172ab | 910 | |
ca65c044 | 911 | if (wxConfig::Get(false)) |
eaf40b23 | 912 | { |
e7d9c398 | 913 | wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ViewStyle"), |
9cedab37 | 914 | &ms_lastViewStyle); |
e7d9c398 | 915 | wxConfig::Get()->Read(wxT("/wxWindows/wxFileDialog/ShowHidden"), |
9cedab37 | 916 | &ms_lastShowHidden); |
eaf40b23 VS |
917 | } |
918 | ||
9cedab37 VZ |
919 | if (m_dialogStyle == 0) |
920 | m_dialogStyle = wxOPEN; | |
7941ba11 | 921 | if ((m_dialogStyle & wxMULTIPLE ) && !(m_dialogStyle & wxOPEN)) |
9b00bb16 | 922 | m_dialogStyle |= wxOPEN; |
479cd5de | 923 | |
353f41cb | 924 | if ((m_dir.empty()) || (m_dir == wxT("."))) |
ac2def68 | 925 | { |
75ec8bd4 | 926 | m_dir = wxGetCwd(); |
ac2def68 | 927 | } |
7a82dabc | 928 | |
353f41cb | 929 | size_t len = m_dir.Len(); |
083f7497 | 930 | if ((len > 1) && (wxEndsWithPathSeparator(m_dir))) |
353f41cb RR |
931 | m_dir.Remove( len-1, 1 ); |
932 | ||
933 | m_path = m_dir; | |
75ec8bd4 | 934 | m_path += wxFILE_SEP_PATH; |
8b17ba72 | 935 | m_path += defaultFile; |
655cf310 | 936 | m_filterExtension = wxEmptyString; |
c8c0e54c | 937 | |
cae5359f | 938 | // layout |
4f5c180e | 939 | |
2b5f62a0 | 940 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
c8c0e54c | 941 | |
8b17ba72 | 942 | wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); |
c8c0e54c | 943 | |
8b17ba72 | 944 | wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); |
c8c0e54c | 945 | |
e6daf794 | 946 | wxBitmapButton *but; |
c8c0e54c | 947 | |
7a82dabc | 948 | but = new wxBitmapButton(this, ID_LIST_MODE, |
36668b35 | 949 | wxArtProvider::GetBitmap(wxART_LIST_VIEW, wxART_BUTTON)); |
e6daf794 RR |
950 | #if wxUSE_TOOLTIPS |
951 | but->SetToolTip( _("View files as a list view") ); | |
952 | #endif | |
953 | buttonsizer->Add( but, 0, wxALL, 5 ); | |
c8c0e54c | 954 | |
60d2cc25 | 955 | but = new wxBitmapButton(this, ID_REPORT_MODE, |
36668b35 | 956 | wxArtProvider::GetBitmap(wxART_REPORT_VIEW, wxART_BUTTON)); |
e6daf794 RR |
957 | #if wxUSE_TOOLTIPS |
958 | but->SetToolTip( _("View files as a detailed view") ); | |
959 | #endif | |
960 | buttonsizer->Add( but, 0, wxALL, 5 ); | |
c8c0e54c | 961 | |
0b855868 | 962 | buttonsizer->Add( 30, 5, 1 ); |
e6daf794 | 963 | |
06cc1fb9 | 964 | m_upDirButton = new wxBitmapButton(this, ID_UP_DIR, |
36668b35 | 965 | wxArtProvider::GetBitmap(wxART_GO_DIR_UP, wxART_BUTTON)); |
e6daf794 | 966 | #if wxUSE_TOOLTIPS |
06cc1fb9 | 967 | m_upDirButton->SetToolTip( _("Go to parent directory") ); |
e6daf794 | 968 | #endif |
06cc1fb9 | 969 | buttonsizer->Add( m_upDirButton, 0, wxALL, 5 ); |
c8c0e54c | 970 | |
37fd1c97 | 971 | #ifndef __DOS__ // VS: Home directory is meaningless in MS-DOS... |
60d2cc25 | 972 | but = new wxBitmapButton(this, ID_PARENT_DIR, |
36668b35 | 973 | wxArtProvider::GetBitmap(wxART_GO_HOME, wxART_BUTTON)); |
e6daf794 RR |
974 | #if wxUSE_TOOLTIPS |
975 | but->SetToolTip( _("Go to home directory") ); | |
976 | #endif | |
977 | buttonsizer->Add( but, 0, wxALL, 5); | |
c8c0e54c | 978 | |
e6daf794 | 979 | buttonsizer->Add( 20, 20 ); |
75ec8bd4 | 980 | #endif //!__DOS__ |
c8c0e54c | 981 | |
06cc1fb9 | 982 | m_newDirButton = new wxBitmapButton(this, ID_NEW_DIR, |
36668b35 | 983 | wxArtProvider::GetBitmap(wxART_NEW_DIR, wxART_BUTTON)); |
e6daf794 | 984 | #if wxUSE_TOOLTIPS |
06cc1fb9 | 985 | m_newDirButton->SetToolTip( _("Create new directory") ); |
e6daf794 | 986 | #endif |
06cc1fb9 | 987 | buttonsizer->Add( m_newDirButton, 0, wxALL, 5 ); |
c8c0e54c | 988 | |
2b5f62a0 | 989 | if (is_pda) |
c15521c6 RR |
990 | mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 0 ); |
991 | else | |
992 | mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); | |
c8c0e54c | 993 | |
9c884972 | 994 | wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); |
2b5f62a0 | 995 | if (is_pda) |
ca65c044 WS |
996 | staticsizer->Add( new wxStaticText( this, wxID_ANY, _("Current directory:") ), 0, wxRIGHT, 10 ); |
997 | m_static = new wxStaticText( this, wxID_ANY, m_dir ); | |
9c884972 RR |
998 | staticsizer->Add( m_static, 1 ); |
999 | mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); | |
1000 | ||
cd6b752b | 1001 | long style2 = ms_lastViewStyle | wxSUNKEN_BORDER; |
9cedab37 | 1002 | if ( !(m_dialogStyle & wxMULTIPLE) ) |
cd6b752b | 1003 | style2 |= wxLC_SINGLE_SEL; |
9cedab37 | 1004 | |
23254b13 | 1005 | m_list = new wxFileCtrl( this, ID_LIST_CTRL, |
9548f380 | 1006 | wxEmptyString, ms_lastShowHidden, |
9cedab37 | 1007 | wxDefaultPosition, wxSize(540,200), |
cd6b752b | 1008 | style2); |
9cedab37 | 1009 | |
2b5f62a0 | 1010 | if (is_pda) |
c15521c6 | 1011 | { |
41fecb44 VS |
1012 | // PDAs have a different screen layout |
1013 | mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 5 ); | |
1014 | ||
41fecb44 VS |
1015 | wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); |
1016 | m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); | |
1017 | textsizer->Add( m_text, 1, wxCENTER | wxALL, 5 ); | |
1018 | mainsizer->Add( textsizer, 0, wxEXPAND ); | |
1019 | ||
ca06ee0d RR |
1020 | m_check = NULL; |
1021 | m_choice = new wxChoice( this, ID_CHOICE ); | |
1022 | textsizer->Add( m_choice, 1, wxCENTER|wxALL, 5 ); | |
41fecb44 VS |
1023 | |
1024 | buttonsizer = new wxBoxSizer( wxHORIZONTAL ); | |
5f7bcb48 VS |
1025 | buttonsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxALL, 5 ); |
1026 | buttonsizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 5 ); | |
41fecb44 | 1027 | mainsizer->Add( buttonsizer, 0, wxALIGN_RIGHT ); |
c15521c6 RR |
1028 | } |
1029 | else | |
1030 | { | |
41fecb44 VS |
1031 | mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); |
1032 | ||
1033 | wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); | |
1034 | m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); | |
1035 | textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); | |
5f7bcb48 | 1036 | textsizer->Add( new wxButton( this, wxID_OK ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); |
41fecb44 VS |
1037 | mainsizer->Add( textsizer, 0, wxEXPAND ); |
1038 | ||
1039 | wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); | |
1040 | m_choice = new wxChoice( this, ID_CHOICE ); | |
1041 | choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); | |
1042 | m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden files") ); | |
9cedab37 | 1043 | m_check->SetValue( ms_lastShowHidden ); |
41fecb44 | 1044 | choicesizer->Add( m_check, 0, wxCENTER|wxALL, 10 ); |
5f7bcb48 | 1045 | choicesizer->Add( new wxButton( this, wxID_CANCEL ), 0, wxCENTER | wxALL, 10 ); |
41fecb44 | 1046 | mainsizer->Add( choicesizer, 0, wxEXPAND ); |
c15521c6 | 1047 | } |
24f932d2 | 1048 | |
b4cfe261 | 1049 | SetWildcard(wildCard); |
8b17ba72 | 1050 | |
ca65c044 | 1051 | SetAutoLayout( true ); |
8b17ba72 | 1052 | SetSizer( mainsizer ); |
c8c0e54c | 1053 | |
8b17ba72 RR |
1054 | mainsizer->Fit( this ); |
1055 | mainsizer->SetSizeHints( this ); | |
48fe8374 | 1056 | |
8b17ba72 | 1057 | Centre( wxBOTH ); |
ed58dbea | 1058 | |
9cedab37 | 1059 | m_text->SetFocus(); |
abc2a4cc | 1060 | |
4e1901b7 | 1061 | return true; |
8b17ba72 RR |
1062 | } |
1063 | ||
23254b13 | 1064 | wxGenericFileDialog::~wxGenericFileDialog() |
cae5359f | 1065 | { |
4e1901b7 | 1066 | if (!m_bypassGenericImpl) |
eaf40b23 | 1067 | { |
4e1901b7 RR |
1068 | if (wxConfig::Get(false)) |
1069 | { | |
1070 | wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ViewStyle"), | |
1071 | ms_lastViewStyle); | |
1072 | wxConfig::Get()->Write(wxT("/wxWindows/wxFileDialog/ShowHidden"), | |
1073 | ms_lastShowHidden); | |
1074 | } | |
c5ef41d3 | 1075 | |
4e1901b7 RR |
1076 | const int count = m_choice->GetCount(); |
1077 | for ( int i = 0; i < count; i++ ) | |
1078 | { | |
1079 | delete (wxString *)m_choice->GetClientData(i); | |
1080 | } | |
c5ef41d3 | 1081 | } |
cae5359f RR |
1082 | } |
1083 | ||
23254b13 | 1084 | int wxGenericFileDialog::ShowModal() |
9cedab37 VZ |
1085 | { |
1086 | m_list->GoToDir(m_dir); | |
06cc1fb9 | 1087 | UpdateControls(); |
2b5f62a0 | 1088 | m_text->SetValue(m_fileName); |
9cedab37 VZ |
1089 | |
1090 | return wxDialog::ShowModal(); | |
1091 | } | |
1092 | ||
16dce3b3 RR |
1093 | bool wxGenericFileDialog::Show( bool show ) |
1094 | { | |
1095 | if (show) | |
1096 | { | |
1097 | m_list->GoToDir(m_dir); | |
1098 | UpdateControls(); | |
1099 | m_text->SetValue(m_fileName); | |
1100 | } | |
1101 | ||
1102 | return wxDialog::Show( show ); | |
1103 | } | |
1104 | ||
23254b13 | 1105 | void wxGenericFileDialog::DoSetFilterIndex(int filterindex) |
2b5f62a0 VZ |
1106 | { |
1107 | wxString *str = (wxString*) m_choice->GetClientData( filterindex ); | |
1108 | m_list->SetWild( *str ); | |
1109 | m_filterIndex = filterindex; | |
1110 | if ( str->Left(2) == wxT("*.") ) | |
1111 | { | |
787d22ec JS |
1112 | m_filterExtension = str->Mid(1); |
1113 | if (m_filterExtension == _T(".*")) | |
2b5f62a0 VZ |
1114 | m_filterExtension.clear(); |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | m_filterExtension.clear(); | |
1119 | } | |
1120 | } | |
1121 | ||
b4cfe261 VZ |
1122 | void wxGenericFileDialog::SetWildcard(const wxString& wildCard) |
1123 | { | |
1124 | wxFileDialogBase::SetWildcard(wildCard); | |
1125 | ||
1126 | wxArrayString wildDescriptions, wildFilters; | |
1127 | const size_t count = wxParseCommonDialogsFilter(m_wildCard, | |
1128 | wildDescriptions, | |
1129 | wildFilters); | |
1130 | wxCHECK_RET( count, wxT("wxFileDialog: bad wildcard string") ); | |
1131 | ||
1132 | m_choice->Clear(); | |
1133 | for ( size_t n = 0; n < count; n++ ) | |
1134 | { | |
1135 | m_choice->Append( wildDescriptions[n], new wxString( wildFilters[n] ) ); | |
1136 | } | |
1137 | ||
1138 | SetFilterIndex( 0 ); | |
1139 | } | |
1140 | ||
23254b13 | 1141 | void wxGenericFileDialog::SetFilterIndex( int filterindex ) |
04ea7f93 RR |
1142 | { |
1143 | m_choice->SetSelection( filterindex ); | |
2b5f62a0 VZ |
1144 | |
1145 | DoSetFilterIndex(filterindex); | |
04ea7f93 RR |
1146 | } |
1147 | ||
23254b13 | 1148 | void wxGenericFileDialog::OnChoiceFilter( wxCommandEvent &event ) |
cae5359f | 1149 | { |
2b5f62a0 | 1150 | DoSetFilterIndex((int)event.GetInt()); |
cae5359f RR |
1151 | } |
1152 | ||
23254b13 | 1153 | void wxGenericFileDialog::OnCheck( wxCommandEvent &event ) |
bf9e3e73 | 1154 | { |
9cedab37 | 1155 | m_list->ShowHidden( (ms_lastShowHidden = event.GetInt() != 0) ); |
bf9e3e73 RR |
1156 | } |
1157 | ||
23254b13 | 1158 | void wxGenericFileDialog::OnActivated( wxListEvent &event ) |
8b17ba72 | 1159 | { |
e1811a01 | 1160 | HandleAction( event.m_item.m_text ); |
8b17ba72 RR |
1161 | } |
1162 | ||
23254b13 | 1163 | void wxGenericFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) ) |
cae5359f RR |
1164 | { |
1165 | wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); | |
1166 | cevent.SetEventObject( this ); | |
1167 | GetEventHandler()->ProcessEvent( cevent ); | |
1168 | } | |
1169 | ||
ca65c044 | 1170 | static bool ignoreChanges = false; |
df413171 | 1171 | |
23254b13 | 1172 | void wxGenericFileDialog::OnTextChange( wxCommandEvent &WXUNUSED(event) ) |
df413171 JS |
1173 | { |
1174 | if (!ignoreChanges) | |
1175 | { | |
1176 | // Clear selections. Otherwise when the user types in a value they may | |
1177 | // not get the file whose name they typed. | |
1178 | if (m_list->GetSelectedItemCount() > 0) | |
1179 | { | |
7f04165e | 1180 | long item = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, |
df413171 JS |
1181 | wxLIST_STATE_SELECTED); |
1182 | while ( item != -1 ) | |
7f04165e | 1183 | { |
df413171 JS |
1184 | m_list->SetItemState(item,0, wxLIST_STATE_SELECTED); |
1185 | item = m_list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); | |
7f04165e | 1186 | } |
df413171 JS |
1187 | } |
1188 | } | |
1189 | } | |
1190 | ||
23254b13 | 1191 | void wxGenericFileDialog::OnSelected( wxListEvent &event ) |
8b17ba72 | 1192 | { |
e1811a01 | 1193 | wxString filename( event.m_item.m_text ); |
223d09f6 | 1194 | if (filename == wxT("..")) return; |
479cd5de | 1195 | |
06cc1fb9 | 1196 | wxString dir = m_list->GetDir(); |
5e673a6a VS |
1197 | if (!IsTopMostDir(dir)) |
1198 | dir += wxFILE_SEP_PATH; | |
e1811a01 RR |
1199 | dir += filename; |
1200 | if (wxDirExists(dir)) return; | |
479cd5de | 1201 | |
ca65c044 | 1202 | ignoreChanges = true; |
e1811a01 | 1203 | m_text->SetValue( filename ); |
ca65c044 | 1204 | ignoreChanges = false; |
8b17ba72 RR |
1205 | } |
1206 | ||
23254b13 | 1207 | void wxGenericFileDialog::HandleAction( const wxString &fn ) |
8b17ba72 | 1208 | { |
e1811a01 | 1209 | wxString filename( fn ); |
06cc1fb9 | 1210 | wxString dir = m_list->GetDir(); |
abc2a4cc | 1211 | if (filename.empty()) return; |
223d09f6 | 1212 | if (filename == wxT(".")) return; |
c8c0e54c | 1213 | |
b600ed13 VZ |
1214 | // "some/place/" means they want to chdir not try to load "place" |
1215 | bool want_dir = filename.Last() == wxFILE_SEP_PATH; | |
1216 | if (want_dir) | |
1217 | filename = filename.RemoveLast(); | |
1218 | ||
223d09f6 | 1219 | if (filename == wxT("..")) |
0b855868 RR |
1220 | { |
1221 | m_list->GoToParentDir(); | |
1222 | m_list->SetFocus(); | |
06cc1fb9 | 1223 | UpdateControls(); |
c8c0e54c | 1224 | return; |
0b855868 RR |
1225 | } |
1226 | ||
75ec8bd4 | 1227 | #ifdef __UNIX__ |
223d09f6 | 1228 | if (filename == wxT("~")) |
ed58dbea RR |
1229 | { |
1230 | m_list->GoToHomeDir(); | |
1231 | m_list->SetFocus(); | |
06cc1fb9 | 1232 | UpdateControls(); |
c8c0e54c | 1233 | return; |
ed58dbea | 1234 | } |
c8c0e54c | 1235 | |
b600ed13 | 1236 | if (filename.BeforeFirst(wxT('/')) == wxT("~")) |
ed58dbea | 1237 | { |
71f2fb52 | 1238 | filename = wxString(wxGetUserHome()) + filename.Remove(0, 1); |
ed58dbea | 1239 | } |
75ec8bd4 | 1240 | #endif // __UNIX__ |
ed58dbea | 1241 | |
223d09f6 KB |
1242 | if ((filename.Find(wxT('*')) != wxNOT_FOUND) || |
1243 | (filename.Find(wxT('?')) != wxNOT_FOUND)) | |
cae5359f | 1244 | { |
75ec8bd4 | 1245 | if (filename.Find(wxFILE_SEP_PATH) != wxNOT_FOUND) |
c8c0e54c VZ |
1246 | { |
1247 | wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR ); | |
1248 | return; | |
1249 | } | |
1250 | m_list->SetWild( filename ); | |
1251 | return; | |
cae5359f RR |
1252 | } |
1253 | ||
5e673a6a VS |
1254 | if (!IsTopMostDir(dir)) |
1255 | dir += wxFILE_SEP_PATH; | |
1256 | if (!wxIsAbsolutePath(filename)) | |
ed58dbea RR |
1257 | { |
1258 | dir += filename; | |
1259 | filename = dir; | |
1260 | } | |
c8c0e54c | 1261 | |
8b17ba72 RR |
1262 | if (wxDirExists(filename)) |
1263 | { | |
1264 | m_list->GoToDir( filename ); | |
06cc1fb9 | 1265 | UpdateControls(); |
c8c0e54c | 1266 | return; |
8b17ba72 | 1267 | } |
c8c0e54c | 1268 | |
b600ed13 VZ |
1269 | // they really wanted a dir, but it doesn't exist |
1270 | if (want_dir) | |
1271 | { | |
1272 | wxMessageBox(_("Directory doesn't exist."), _("Error"), | |
1273 | wxOK | wxICON_ERROR ); | |
1274 | return; | |
1275 | } | |
1276 | ||
2b5f62a0 VZ |
1277 | // append the default extension to the filename if it doesn't have any |
1278 | // | |
1279 | // VZ: the logic of testing for !wxFileExists() only for the open file | |
1280 | // dialog is not entirely clear to me, why don't we allow saving to a | |
1281 | // file without extension as well? | |
1282 | if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) ) | |
8b17ba72 | 1283 | { |
f74172ab | 1284 | filename = AppendExtension(filename, m_filterExtension); |
8b17ba72 | 1285 | } |
2b5f62a0 VZ |
1286 | |
1287 | // check that the file [doesn't] exist if necessary | |
1288 | if ( (m_dialogStyle & wxSAVE) && | |
1289 | (m_dialogStyle & wxOVERWRITE_PROMPT) && | |
1290 | wxFileExists( filename ) ) | |
8b17ba72 | 1291 | { |
2b5f62a0 | 1292 | wxString msg; |
88d6c988 | 1293 | msg.Printf( _("File '%s' already exists, do you really want to overwrite it?"), filename.c_str() ); |
655cf310 | 1294 | |
2b5f62a0 VZ |
1295 | if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES) |
1296 | return; | |
1297 | } | |
1298 | else if ( (m_dialogStyle & wxOPEN) && | |
1299 | (m_dialogStyle & wxFILE_MUST_EXIST) && | |
1300 | !wxFileExists(filename) ) | |
1301 | { | |
1302 | wxMessageBox(_("Please choose an existing file."), _("Error"), | |
1303 | wxOK | wxICON_ERROR ); | |
8b17ba72 RR |
1304 | } |
1305 | ||
1306 | SetPath( filename ); | |
479cd5de | 1307 | |
3f6638b8 | 1308 | // change to the directory where the user went if asked |
fda09b3f | 1309 | if ( m_dialogStyle & wxCHANGE_DIR ) |
3f6638b8 VZ |
1310 | { |
1311 | wxString cwd; | |
1312 | wxSplitPath(filename, &cwd, NULL, NULL); | |
1313 | ||
0b98a252 | 1314 | if ( cwd != wxGetCwd() ) |
3f6638b8 VZ |
1315 | { |
1316 | wxSetWorkingDirectory(cwd); | |
1317 | } | |
1318 | } | |
1319 | ||
9b7e522a RR |
1320 | wxCommandEvent event; |
1321 | wxDialog::OnOK(event); | |
e1811a01 RR |
1322 | } |
1323 | ||
23254b13 | 1324 | void wxGenericFileDialog::OnListOk( wxCommandEvent &WXUNUSED(event) ) |
e1811a01 RR |
1325 | { |
1326 | HandleAction( m_text->GetValue() ); | |
8b17ba72 RR |
1327 | } |
1328 | ||
23254b13 | 1329 | void wxGenericFileDialog::OnList( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1330 | { |
1331 | m_list->ChangeToListMode(); | |
9cedab37 | 1332 | ms_lastViewStyle = wxLC_LIST; |
0b855868 | 1333 | m_list->SetFocus(); |
8b17ba72 RR |
1334 | } |
1335 | ||
23254b13 | 1336 | void wxGenericFileDialog::OnReport( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1337 | { |
1338 | m_list->ChangeToReportMode(); | |
9cedab37 | 1339 | ms_lastViewStyle = wxLC_REPORT; |
0b855868 | 1340 | m_list->SetFocus(); |
8b17ba72 RR |
1341 | } |
1342 | ||
23254b13 | 1343 | void wxGenericFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1344 | { |
1345 | m_list->GoToParentDir(); | |
0b855868 | 1346 | m_list->SetFocus(); |
06cc1fb9 | 1347 | UpdateControls(); |
8b17ba72 RR |
1348 | } |
1349 | ||
23254b13 | 1350 | void wxGenericFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) ) |
8b17ba72 RR |
1351 | { |
1352 | m_list->GoToHomeDir(); | |
0b855868 | 1353 | m_list->SetFocus(); |
06cc1fb9 | 1354 | UpdateControls(); |
0b855868 RR |
1355 | } |
1356 | ||
23254b13 | 1357 | void wxGenericFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) ) |
0b855868 RR |
1358 | { |
1359 | m_list->MakeDir(); | |
8b17ba72 RR |
1360 | } |
1361 | ||
23254b13 | 1362 | void wxGenericFileDialog::SetPath( const wxString& path ) |
8b17ba72 RR |
1363 | { |
1364 | // not only set the full path but also update filename and dir | |
1365 | m_path = path; | |
9cedab37 | 1366 | if ( !path.empty() ) |
8b17ba72 RR |
1367 | { |
1368 | wxString ext; | |
1369 | wxSplitPath(path, &m_dir, &m_fileName, &ext); | |
9cedab37 | 1370 | if (!ext.empty()) |
c8c0e54c | 1371 | { |
223d09f6 | 1372 | m_fileName += wxT("."); |
8b17ba72 | 1373 | m_fileName += ext; |
c8c0e54c | 1374 | } |
8b17ba72 RR |
1375 | } |
1376 | } | |
c8c0e54c | 1377 | |
23254b13 | 1378 | void wxGenericFileDialog::GetPaths( wxArrayString& paths ) const |
7941ba11 RR |
1379 | { |
1380 | paths.Empty(); | |
28c9c76e RR |
1381 | if (m_list->GetSelectedItemCount() == 0) |
1382 | { | |
1383 | paths.Add( GetPath() ); | |
1384 | return; | |
1385 | } | |
479cd5de | 1386 | |
7941ba11 RR |
1387 | paths.Alloc( m_list->GetSelectedItemCount() ); |
1388 | ||
06cc1fb9 | 1389 | wxString dir = m_list->GetDir(); |
5e673a6a | 1390 | #ifdef __UNIX__ |
7a82dabc | 1391 | if (dir != wxT("/")) |
5e673a6a VS |
1392 | #endif |
1393 | dir += wxFILE_SEP_PATH; | |
7941ba11 RR |
1394 | |
1395 | wxListItem item; | |
1396 | item.m_mask = wxLIST_MASK_TEXT; | |
1397 | ||
1398 | item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); | |
92da8bde | 1399 | while ( item.m_itemId != -1 ) |
68df5777 | 1400 | { |
7941ba11 RR |
1401 | m_list->GetItem( item ); |
1402 | paths.Add( dir + item.m_text ); | |
68df5777 | 1403 | item.m_itemId = m_list->GetNextItem( item.m_itemId, |
7941ba11 RR |
1404 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); |
1405 | } | |
1406 | } | |
1407 | ||
23254b13 | 1408 | void wxGenericFileDialog::GetFilenames(wxArrayString& files) const |
7941ba11 RR |
1409 | { |
1410 | files.Empty(); | |
28c9c76e RR |
1411 | if (m_list->GetSelectedItemCount() == 0) |
1412 | { | |
1413 | files.Add( GetFilename() ); | |
1414 | return; | |
1415 | } | |
7941ba11 RR |
1416 | files.Alloc( m_list->GetSelectedItemCount() ); |
1417 | ||
1418 | wxListItem item; | |
1419 | item.m_mask = wxLIST_MASK_TEXT; | |
1420 | ||
1421 | item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); | |
92da8bde | 1422 | while ( item.m_itemId != -1 ) |
68df5777 | 1423 | { |
7941ba11 RR |
1424 | m_list->GetItem( item ); |
1425 | files.Add( item.m_text ); | |
68df5777 | 1426 | item.m_itemId = m_list->GetNextItem( item.m_itemId, |
7941ba11 RR |
1427 | wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); |
1428 | } | |
1429 | } | |
1430 | ||
06cc1fb9 JS |
1431 | void wxGenericFileDialog::UpdateControls() |
1432 | { | |
1433 | wxString dir = m_list->GetDir(); | |
1434 | m_static->SetLabel(dir); | |
1435 | ||
1436 | bool enable = !IsTopMostDir(dir); | |
1437 | m_upDirButton->Enable(enable); | |
1438 | ||
144cf6da | 1439 | #if defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 | 1440 | m_newDirButton->Enable(enable); |
144cf6da | 1441 | #endif // defined(__DOS__) || defined(__WINDOWS__) || defined(__OS2__) |
06cc1fb9 JS |
1442 | } |
1443 | ||
23254b13 | 1444 | #ifdef USE_GENERIC_FILEDIALOG |
655cf310 | 1445 | |
23254b13 | 1446 | IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog); |
655cf310 | 1447 | |
23254b13 JS |
1448 | #endif // USE_GENERIC_FILEDIALOG |
1449 | ||
4e1901b7 | 1450 | #endif // wxUSE_FILEDLG |
9cedab37 | 1451 |