]> git.saurik.com Git - wxWidgets.git/blob - src/generic/filedlgg.cpp
EMX compilation,
[wxWidgets.git] / src / generic / filedlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: filedlgg.cpp
3 // Purpose: wxFileDialog
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 #ifdef __GNUG__
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 #ifndef __UNIX__
24 #error wxFileDialog currently only supports unix
25 #endif
26
27 #include "wx/filedlg.h"
28 #include "wx/debug.h"
29 #include "wx/log.h"
30 #include "wx/intl.h"
31 #include "wx/msgdlg.h"
32 #include "wx/sizer.h"
33 #include "wx/bmpbuttn.h"
34
35 #if wxUSE_TOOLTIPS
36 #include "wx/tooltip.h"
37 #endif
38
39 #include "sys/types.h"
40 #include "sys/stat.h"
41 #include "dirent.h"
42 #include "pwd.h"
43 #include "grp.h"
44 #include "time.h"
45
46 #include "wx/generic/home.xpm"
47 #include "wx/generic/listview.xpm"
48 #include "wx/generic/repview.xpm"
49 #include "wx/generic/new_dir.xpm"
50 #include "wx/generic/dir_up.xpm"
51
52 /* XPM */
53 static char * folder_xpm[] = {
54 /* width height ncolors chars_per_pixel */
55 "16 16 6 1",
56 /* colors */
57 " s None c None",
58 ". c #000000",
59 "+ c #c0c0c0",
60 "@ c #808080",
61 "# c #ffff00",
62 "$ c #ffffff",
63 /* pixels */
64 " ",
65 " @@@@@ ",
66 " @#+#+#@ ",
67 " @#+#+#+#@@@@@@ ",
68 " @$$$$$$$$$$$$@.",
69 " @$#+#+#+#+#+#@.",
70 " @$+#+#+#+#+#+@.",
71 " @$#+#+#+#+#+#@.",
72 " @$+#+#+#+#+#+@.",
73 " @$#+#+#+#+#+#@.",
74 " @$+#+#+#+#+#+@.",
75 " @$#+#+#+#+#+#@.",
76 " @@@@@@@@@@@@@@.",
77 " ..............",
78 " ",
79 " "};
80
81 //-----------------------------------------------------------------------------
82 // wxFileData
83 //-----------------------------------------------------------------------------
84
85 IMPLEMENT_DYNAMIC_CLASS(wxFileData,wxObject);
86
87 wxFileData::wxFileData( const wxString &name, const wxString &fname )
88 {
89 m_name = name;
90 m_fileName = fname;
91
92 struct stat buff;
93 stat( m_fileName.GetData(), &buff );
94 struct stat lbuff;
95 lstat( m_fileName.GetData(), &lbuff );
96
97 struct tm *t = localtime( &lbuff.st_mtime );
98 // struct passwd *user = getpwuid( buff.st_uid );
99 // struct group *grp = getgrgid( buff.st_gid );
100
101 m_isDir = S_ISDIR( buff.st_mode );
102 m_isLink = S_ISLNK( lbuff.st_mode );
103 m_isExe = ((buff.st_mode & S_IXUSR ) == S_IXUSR );
104
105 m_size = buff.st_size;
106
107 m_hour = t->tm_hour;
108 m_minute = t->tm_min;
109 m_month = t->tm_mon+1;
110 m_day = t->tm_mday;
111 m_year = t->tm_year;
112
113 m_permissions.sprintf( "%c%c%c",
114 ((( buff.st_mode & S_IRUSR ) == S_IRUSR ) ? 'r' : '-'),
115 ((( buff.st_mode & S_IWUSR ) == S_IWUSR ) ? 'w' : '-'),
116 ((( buff.st_mode & S_IXUSR ) == S_IXUSR ) ? 'x' : '-') );
117 }
118
119 wxString wxFileData::GetName() const
120 {
121 return m_name;
122 }
123
124 wxString wxFileData::GetFullName() const
125 {
126 return m_fileName;
127 }
128
129 wxString wxFileData::GetHint() const
130 {
131 wxString s = m_fileName;
132 s += " ";
133 if (m_isDir) s += _("<DIR> ");
134 else if (m_isLink) s += _("<LINK> ");
135 else
136 {
137 s += LongToString( m_size );
138 s += _(" bytes ");
139 }
140 s += IntToString( m_day );
141 s += _T(".");
142 s += IntToString( m_month );
143 s += _T(".");
144 s += IntToString( m_year );
145 s += _T(" ");
146 s += IntToString( m_hour );
147 s += _T(":");
148 s += IntToString( m_minute );
149 s += _T(" ");
150 s += m_permissions;
151 return s;
152 };
153
154 wxString wxFileData::GetEntry( const int num )
155 {
156 wxString s;
157 switch (num)
158 {
159 case 0:
160 s = m_name;
161 break;
162 case 1:
163 if (m_isDir) s = _("<DIR>");
164 else if (m_isLink) s = _("<LINK>");
165 else s = LongToString( m_size );
166 break;
167 case 2:
168 if (m_day < 10) s = _T("0"); else s = _T("");
169 s += IntToString( m_day );
170 s += _T(".");
171 if (m_month < 10) s += _T("0");
172 s += IntToString( m_month );
173 s += _T(".");
174 if (m_year < 10) s += _T("0"); // this should happen real soon...
175 s += IntToString( m_year );
176 break;
177 case 3:
178 if (m_hour < 10) s = _T("0"); else s = _T("");
179 s += IntToString( m_hour );
180 s += _T(":");
181 if (m_minute < 10) s += _T("0");
182 s += IntToString( m_minute );
183 break;
184 case 4:
185 s = m_permissions;
186 break;
187 default:
188 s = _T("No entry");
189 break;
190 }
191 return s;
192 }
193
194 bool wxFileData::IsDir()
195 {
196 return m_isDir;
197 }
198
199 bool wxFileData::IsExe()
200 {
201 return m_isExe;
202 }
203
204 bool wxFileData::IsLink()
205 {
206 return m_isLink;
207 }
208
209 long wxFileData::GetSize()
210 {
211 return m_size;
212 }
213
214 void wxFileData::SetNewName( const wxString &name, const wxString &fname )
215 {
216 m_name = name;
217 m_fileName = fname;
218 }
219
220 void wxFileData::MakeItem( wxListItem &item )
221 {
222 item.m_text = m_name;
223 item.m_colour = wxBLACK;
224 if (IsExe()) item.m_colour = wxRED;
225 if (IsDir()) item.m_colour = wxBLUE;
226 if (IsDir()) item.m_image = 0; else item.m_image = -1;
227 if (IsLink())
228 {
229 wxColour *dg = wxTheColourDatabase->FindColour( "MEDIUM GREY" );
230 item.m_colour = dg;
231 }
232 item.m_data = (long)this;
233 }
234
235 //-----------------------------------------------------------------------------
236 // wxFileCtrl
237 //-----------------------------------------------------------------------------
238
239 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl);
240
241 BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
242 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
243 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
244 END_EVENT_TABLE()
245
246 wxFileCtrl::wxFileCtrl()
247 {
248 m_dirName = _T("/");
249 m_showHidden = FALSE;
250 }
251
252 wxFileCtrl::wxFileCtrl( wxWindow *win, wxWindowID id,
253 const wxString &dirName, const wxString &wild,
254 const wxPoint &pos, const wxSize &size,
255 long style, const wxValidator &validator, const wxString &name ) :
256 wxListCtrl( win, id, pos, size, style, validator, name )
257 {
258 wxImageList *imageList = new wxImageList( 16, 16 );
259 imageList->Add( wxBitmap( folder_xpm ) );
260 SetImageList( imageList, wxIMAGE_LIST_SMALL );
261
262 m_dirName = dirName;
263 m_wild = wild;
264 m_showHidden = FALSE;
265 Update();
266 }
267
268 void wxFileCtrl::ChangeToListMode()
269 {
270 SetSingleStyle( wxLC_LIST );
271 Update();
272 }
273
274 void wxFileCtrl::ChangeToReportMode()
275 {
276 SetSingleStyle( wxLC_REPORT );
277 Update();
278 }
279
280 void wxFileCtrl::ChangeToIconMode()
281 {
282 SetSingleStyle( wxLC_ICON );
283 Update();
284 }
285
286 void wxFileCtrl::ShowHidden( bool show )
287 {
288 m_showHidden = show;
289 Update();
290 }
291
292 int ListCompare( const long data1, const long data2, const long WXUNUSED(data) )
293 {
294 wxFileData *fd1 = (wxFileData*)data1 ;
295 wxFileData *fd2 = (wxFileData*)data2 ;
296 if (fd1->GetName() == _T("..")) return -1;
297 if (fd2->GetName() == _T("..")) return 1;
298 if (fd1->IsDir() && !fd2->IsDir()) return -1;
299 if (fd2->IsDir() && !fd1->IsDir()) return 1;
300 return strcmp( fd1->GetName(), fd2->GetName() );
301 }
302
303 long wxFileCtrl::Add( wxFileData *fd, wxListItem &item )
304 {
305 long ret = -1;
306 item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
307 fd->MakeItem( item );
308 long my_style = GetWindowStyleFlag();
309 if (my_style & wxLC_REPORT)
310 {
311 ret = InsertItem( item );
312 for (int i = 1; i < 5; i++) SetItem( item.m_itemId, i, fd->GetEntry( i) );
313 }
314 else if (my_style & wxLC_LIST)
315 {
316 ret = InsertItem( item );
317 }
318 return ret;
319 }
320
321 void wxFileCtrl::Update()
322 {
323 ClearAll();
324 long my_style = GetWindowStyleFlag();
325 if (my_style & wxLC_REPORT)
326 {
327 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT, 130 );
328 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT, 60 );
329 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT, 55 );
330 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT, 50 );
331 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT, 120 );
332 }
333 wxFileData *fd = (wxFileData *) NULL;
334 wxListItem item;
335 item.m_itemId = 0;
336 item.m_col = 0;
337
338 if (m_dirName != _T("/"))
339 {
340 wxString p( wxPathOnly(m_dirName) );
341 if (p.IsEmpty()) p = _T("/");
342 fd = new wxFileData( _T(".."), p );
343 Add( fd, item );
344 item.m_itemId++;
345 }
346
347 wxString res = m_dirName + _T("/") + m_wild;
348 wxString f( wxFindFirstFile( res.GetData(), 0 ) );
349 while (!f.IsEmpty())
350 {
351 res = wxFileNameFromPath( f );
352 fd = new wxFileData( res, f );
353 wxString s = fd->GetName();
354 if (m_showHidden || (s[0] != _T('.')))
355 {
356 Add( fd, item );
357 item.m_itemId++;
358 }
359 f = wxFindNextFile();
360 }
361 SortItems( ListCompare, 0 );
362 }
363
364 void wxFileCtrl::SetWild( const wxString &wild )
365 {
366 m_wild = wild;
367 Update();
368 }
369
370 void wxFileCtrl::MakeDir()
371 {
372 wxString new_name( _T("NewName") );
373 wxString path( m_dirName );
374 path += _T( "/" );
375 path += new_name;
376 if (wxFileExists(path))
377 {
378 // try NewName0, NewName1 etc.
379 int i = 0;
380 do {
381 new_name = _("NewName");
382 wxString num;
383 num.Printf( _T("%d"), i );
384 new_name += num;
385
386 path = m_dirName;
387 path += _T("/");
388 path += new_name;
389 i++;
390 } while (wxFileExists(path));
391 }
392
393 wxLogNull log;
394 if (!wxMkdir(path))
395 {
396 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
397 dialog.ShowModal();
398 return;
399 }
400
401 wxFileData *fd = new wxFileData( new_name, path );
402 wxListItem item;
403 item.m_itemId = 0;
404 item.m_col = 0;
405 int id = Add( fd, item );
406
407 if (id != -1)
408 {
409 SortItems( ListCompare, 0 );
410 id = FindItem( 0, (long)fd );
411 EnsureVisible( id );
412 EditLabel( id );
413 }
414 }
415
416 void wxFileCtrl::GoToParentDir()
417 {
418 if (m_dirName != _T("/"))
419 {
420 wxString fname( wxFileNameFromPath(m_dirName) );
421 m_dirName = wxPathOnly( m_dirName );
422 if (m_dirName.IsEmpty()) m_dirName = _T("/");
423 Update();
424 int id = FindItem( 0, fname );
425 if (id != -1)
426 {
427 SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
428 EnsureVisible( id );
429 }
430 }
431 }
432
433 void wxFileCtrl::GoToHomeDir()
434 {
435 wxString s = wxGetUserHome( wxString() );
436 m_dirName = s;
437 Update();
438 SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
439 EnsureVisible( 0 );
440 }
441
442 void wxFileCtrl::GoToDir( const wxString &dir )
443 {
444 m_dirName = dir;
445 Update();
446 SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
447 EnsureVisible( 0 );
448 }
449
450 void wxFileCtrl::GetDir( wxString &dir )
451 {
452 dir = m_dirName;
453 }
454
455 void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
456 {
457 wxFileData *fd = (wxFileData*)event.m_item.m_data;
458 delete fd;
459 }
460
461 void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
462 {
463 wxFileData *fd = (wxFileData*)event.m_item.m_data;
464 wxASSERT( fd );
465
466 if ((event.GetLabel().IsEmpty()) ||
467 (event.GetLabel() == _(".")) ||
468 (event.GetLabel() == _("..")) ||
469 (event.GetLabel().First( _T("/") ) != wxNOT_FOUND))
470 {
471 wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
472 dialog.ShowModal();
473 event.Veto();
474 return;
475 }
476
477 wxString new_name( wxPathOnly( fd->GetFullName() ) );
478 new_name += _T("/");
479 new_name += event.GetLabel();
480
481 wxLogNull log;
482
483 if (wxFileExists(new_name))
484 {
485 wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
486 dialog.ShowModal();
487 event.Veto();
488 }
489
490 if (wxRenameFile(fd->GetFullName(),new_name))
491 {
492 fd->SetNewName( new_name, event.GetLabel() );
493 SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
494 EnsureVisible( event.GetItem() );
495 }
496 else
497 {
498 wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
499 dialog.ShowModal();
500 event.Veto();
501 }
502 }
503
504 //-----------------------------------------------------------------------------
505 // wxFileDialog
506 //-----------------------------------------------------------------------------
507
508 #define ID_LIST_CTRL 5010
509 #define ID_LIST_MODE 5000
510 #define ID_REPORT_MODE 5001
511 #define ID_UP_DIR 5005
512 #define ID_PARENT_DIR 5006
513 #define ID_NEW_DIR 5007
514
515 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog)
516
517 BEGIN_EVENT_TABLE(wxFileDialog,wxDialog)
518 EVT_BUTTON(ID_LIST_MODE, wxFileDialog::OnList)
519 EVT_BUTTON(ID_REPORT_MODE, wxFileDialog::OnReport)
520 EVT_BUTTON(ID_UP_DIR, wxFileDialog::OnUp)
521 EVT_BUTTON(ID_PARENT_DIR, wxFileDialog::OnHome)
522 EVT_BUTTON(ID_NEW_DIR, wxFileDialog::OnNew)
523 EVT_BUTTON(wxID_OK, wxFileDialog::OnListOk)
524 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxFileDialog::OnSelected)
525 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated)
526 END_EVENT_TABLE()
527
528 wxFileDialog::wxFileDialog(wxWindow *parent,
529 const wxString& message,
530 const wxString& defaultDir,
531 const wxString& defaultFile,
532 const wxString& wildCard,
533 long style,
534 const wxPoint& pos ) :
535 wxDialog( parent, -1, message, pos, wxDefaultSize, style | wxRESIZE_BORDER )
536 {
537 wxBeginBusyCursor();
538
539 m_message = message;
540 m_dialogStyle = style;
541 m_dir = defaultDir;
542 if (m_dir.IsEmpty()) m_dir = wxGetUserHome();
543 m_path = defaultDir;
544 m_path += _T("/");
545 m_path += defaultFile;
546 m_fileName = defaultFile;
547 m_wildCard = wildCard;
548 m_filterIndex = 0;
549
550 wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
551
552 wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL );
553
554 wxBitmapButton *but;
555
556 but = new wxBitmapButton( this, ID_LIST_MODE, wxBitmap( listview_xpm ) );
557 #if wxUSE_TOOLTIPS
558 but->SetToolTip( _("View files as a list view") );
559 #endif
560 buttonsizer->Add( but, 0, wxALL, 5 );
561
562 but = new wxBitmapButton( this, ID_REPORT_MODE, wxBitmap( repview_xpm ) );
563 #if wxUSE_TOOLTIPS
564 but->SetToolTip( _("View files as a detailed view") );
565 #endif
566 buttonsizer->Add( but, 0, wxALL, 5 );
567
568 buttonsizer->Add( 30, 5, 1 );
569
570 but = new wxBitmapButton( this, ID_UP_DIR, wxBitmap( dir_up_xpm ) );
571 #if wxUSE_TOOLTIPS
572 but->SetToolTip( _("Go to parent directory") );
573 #endif
574 buttonsizer->Add( but, 0, wxALL, 5 );
575
576 but = new wxBitmapButton( this, ID_PARENT_DIR, wxBitmap(home_xpm) );
577 #if wxUSE_TOOLTIPS
578 but->SetToolTip( _("Go to home directory") );
579 #endif
580 buttonsizer->Add( but, 0, wxALL, 5);
581
582 buttonsizer->Add( 20, 20 );
583
584 but = new wxBitmapButton( this, ID_NEW_DIR, wxBitmap(new_dir_xpm) );
585 #if wxUSE_TOOLTIPS
586 but->SetToolTip( _("Create new directory") );
587 #endif
588 buttonsizer->Add( but, 0, wxALL, 5 );
589
590 mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 );
591
592 m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, "*", wxDefaultPosition, wxSize(440,180),
593 wxLC_LIST | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
594 mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
595
596 wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL );
597 m_text = new wxTextCtrl( this, -1, m_fileName );
598 textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
599 textsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
600 mainsizer->Add( textsizer, 0, wxEXPAND );
601
602 wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL );
603 m_choice = new wxChoice( this, -1 );
604 m_choice->Append( "*.txt" );
605 choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 );
606 choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 );
607 mainsizer->Add( choicesizer, 0, wxEXPAND );
608
609 SetAutoLayout( TRUE );
610 SetSizer( mainsizer );
611
612 mainsizer->Fit( this );
613 mainsizer->SetSizeHints( this );
614
615 Centre( wxBOTH );
616
617 m_list->SetFocus();
618
619 wxEndBusyCursor();
620 }
621
622 void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) )
623 {
624 wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
625 cevent.SetEventObject( this );
626 GetEventHandler()->ProcessEvent( cevent );
627 }
628
629 void wxFileDialog::OnSelected( wxListEvent &event )
630 {
631 m_text->SetValue( event.m_item.m_text );
632 }
633
634 void wxFileDialog::OnListOk( wxCommandEvent &event )
635 {
636 wxString filename( m_text->GetValue() );
637 wxString dir;
638 m_list->GetDir( dir );
639 if (filename.IsEmpty()) return;
640
641 if (filename == _T(".."))
642 {
643 m_list->GoToParentDir();
644 m_list->SetFocus();
645 return;
646 }
647
648 if (dir != _T("/")) dir += _T("/");
649 dir += filename;
650 filename = dir;
651
652 if (wxDirExists(filename))
653 {
654 m_list->GoToDir( filename );
655 m_text->SetValue( _T("") );
656 return;
657 }
658
659 if ( (m_dialogStyle & wxSAVE) && (m_dialogStyle & wxOVERWRITE_PROMPT) )
660 {
661 if (wxFileExists( filename ))
662 {
663 wxString msg;
664 msg.Printf( _("File '%s' already exists, do you really want to "
665 "overwrite it?"), filename.c_str() );
666
667 if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
668 return;
669 }
670 }
671 else if ( (m_dialogStyle & wxOPEN) && (m_dialogStyle & wxFILE_MUST_EXIST) )
672 {
673 if ( !wxFileExists( filename ) )
674 {
675 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK);
676
677 return;
678 }
679 }
680
681 SetPath( filename );
682 event.Skip();
683 }
684
685 void wxFileDialog::OnList( wxCommandEvent &WXUNUSED(event) )
686 {
687 m_list->ChangeToListMode();
688 m_list->SetFocus();
689 }
690
691 void wxFileDialog::OnReport( wxCommandEvent &WXUNUSED(event) )
692 {
693 m_list->ChangeToReportMode();
694 m_list->SetFocus();
695 }
696
697 void wxFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) )
698 {
699 m_list->GoToParentDir();
700 m_list->SetFocus();
701 }
702
703 void wxFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) )
704 {
705 m_list->GoToHomeDir();
706 m_list->SetFocus();
707 }
708
709 void wxFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) )
710 {
711 m_list->MakeDir();
712 }
713
714 void wxFileDialog::SetPath( const wxString& path )
715 {
716 // not only set the full path but also update filename and dir
717 m_path = path;
718 if ( !!path )
719 {
720 wxString ext;
721 wxSplitPath(path, &m_dir, &m_fileName, &ext);
722 if (!ext.IsEmpty())
723 {
724 m_fileName += _T(".");
725 m_fileName += ext;
726 }
727 }
728 }
729
730 // ----------------------------------------------------------------------------
731 // global functions
732 // ----------------------------------------------------------------------------
733
734 wxString
735 wxFileSelectorEx(const wxChar *message,
736 const wxChar *default_path,
737 const wxChar *default_filename,
738 int *indexDefaultExtension,
739 const wxChar *wildcard,
740 int flags,
741 wxWindow *parent,
742 int x, int y)
743 {
744 // TODO: implement this somehow
745 return wxFileSelector(message, default_path, default_filename, _T(""),
746 wildcard, flags, parent, x, y);
747 }
748
749 wxString wxFileSelector( const wxChar *title,
750 const wxChar *defaultDir, const wxChar *defaultFileName,
751 const wxChar *defaultExtension, const wxChar *filter, int flags,
752 wxWindow *parent, int x, int y )
753 {
754 wxString filter2;
755 if ( defaultExtension && !filter )
756 filter2 = wxString(_T("*.")) + wxString(defaultExtension) ;
757 else if ( filter )
758 filter2 = filter;
759
760 wxString defaultDirString;
761 if (defaultDir)
762 defaultDirString = defaultDir;
763
764 wxString defaultFilenameString;
765 if (defaultFileName)
766 defaultFilenameString = defaultFileName;
767
768 wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) );
769
770 if ( fileDialog.ShowModal() == wxID_OK )
771 {
772 return fileDialog.GetPath();
773 }
774 else
775 {
776 return wxEmptyString;
777 }
778 }
779
780 wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent )
781 {
782 wxChar *ext = (wxChar *)extension;
783
784 wxChar prompt[50];
785 wxString str = _("Load %s file");
786 wxSprintf(prompt, str, what);
787
788 if (*ext == _T('.')) ext++;
789 wxChar wild[60];
790 wxSprintf(wild, _T("*.%s"), ext);
791
792 return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
793 }
794
795 wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name,
796 wxWindow *parent )
797 {
798 wxChar *ext = (wxChar *)extension;
799
800 wxChar prompt[50];
801 wxString str = _("Save %s file");
802 wxSprintf(prompt, str, what);
803
804 if (*ext == _T('.')) ext++;
805 wxChar wild[60];
806 wxSprintf(wild, _T("*.%s"), ext);
807
808 return wxFileSelector (prompt, (const wxChar *) NULL, default_name, ext, wild, 0, parent);
809 }
810