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