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