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