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