1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFileDialog
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "filedlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #error wxFileDialog currently only supports unix
27 #include "wx/filedlg.h"
31 #include "wx/msgdlg.h"
33 #include "wx/bmpbuttn.h"
34 #include "wx/tokenzr.h"
37 #include "wx/tooltip.h"
40 #include <sys/types.h>
48 #include "wx/generic/home.xpm"
49 #include "wx/generic/listview.xpm"
50 #include "wx/generic/repview.xpm"
51 #include "wx/generic/new_dir.xpm"
52 #include "wx/generic/dir_up.xpm"
55 static char * folder_xpm
[] = {
56 /* width height ncolors chars_per_pixel */
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
88 int ListCompare( long data1
, long data2
, long WXUNUSED(data
) )
90 wxFileData
*fd1
= (wxFileData
*)data1
;
91 wxFileData
*fd2
= (wxFileData
*)data2
;
92 if (fd1
->GetName() == wxT("..")) return -1;
93 if (fd2
->GetName() == wxT("..")) return 1;
94 if (fd1
->IsDir() && !fd2
->IsDir()) return -1;
95 if (fd2
->IsDir() && !fd1
->IsDir()) return 1;
96 return wxStrcmp( fd1
->GetName(), fd2
->GetName() );
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
103 IMPLEMENT_DYNAMIC_CLASS(wxFileData
,wxObject
);
105 wxFileData::wxFileData( const wxString
&name
, const wxString
&fname
)
111 stat( m_fileName
.fn_str(), &buff
);
113 lstat( m_fileName
.fn_str(), &lbuff
);
115 struct tm
*t
= localtime( &lbuff
.st_mtime
);
116 // struct passwd *user = getpwuid( buff.st_uid );
117 // struct group *grp = getgrgid( buff.st_gid );
119 m_isDir
= S_ISDIR( buff
.st_mode
);
120 m_isLink
= S_ISLNK( lbuff
.st_mode
);
121 m_isExe
= ((buff
.st_mode
& S_IXUSR
) == S_IXUSR
);
123 m_size
= buff
.st_size
;
126 m_minute
= t
->tm_min
;
127 m_month
= t
->tm_mon
+1;
131 m_permissions
.sprintf( wxT("%c%c%c"),
132 ((( buff
.st_mode
& S_IRUSR
) == S_IRUSR
) ? wxT('r') : wxT('-')),
133 ((( buff
.st_mode
& S_IWUSR
) == S_IWUSR
) ? wxT('w') : wxT('-')),
134 ((( buff
.st_mode
& S_IXUSR
) == S_IXUSR
) ? wxT('x') : wxT('-')) );
137 wxString
wxFileData::GetName() const
142 wxString
wxFileData::GetFullName() const
147 wxString
wxFileData::GetHint() const
149 wxString s
= m_fileName
;
151 if (m_isDir
) s
+= _("<DIR> ");
152 else if (m_isLink
) s
+= _("<LINK> ");
155 s
+= LongToString( m_size
);
158 s
+= IntToString( m_day
);
160 s
+= IntToString( m_month
);
162 s
+= IntToString( m_year
);
164 s
+= IntToString( m_hour
);
166 s
+= IntToString( m_minute
);
172 wxString
wxFileData::GetEntry( int num
)
181 if (m_isDir
) s
= _("<DIR>");
182 else if (m_isLink
) s
= _("<LINK>");
183 else s
= LongToString( m_size
);
186 if (m_day
< 10) s
= wxT("0"); else s
= wxT("");
187 s
+= IntToString( m_day
);
189 if (m_month
< 10) s
+= wxT("0");
190 s
+= IntToString( m_month
);
192 if (m_year
< 10) s
+= wxT("0"); // this should happen real soon...
193 s
+= IntToString( m_year
);
196 if (m_hour
< 10) s
= wxT("0"); else s
= wxT("");
197 s
+= IntToString( m_hour
);
199 if (m_minute
< 10) s
+= wxT("0");
200 s
+= IntToString( m_minute
);
212 bool wxFileData::IsDir()
217 bool wxFileData::IsExe()
222 bool wxFileData::IsLink()
227 long wxFileData::GetSize()
232 void wxFileData::SetNewName( const wxString
&name
, const wxString
&fname
)
238 void wxFileData::MakeItem( wxListItem
&item
)
240 item
.m_text
= m_name
;
241 item
.m_colour
= wxBLACK
;
242 if (IsExe()) item
.m_colour
= wxRED
;
243 if (IsDir()) item
.m_colour
= wxBLUE
;
244 if (IsDir()) item
.m_image
= 0; else item
.m_image
= -1;
247 wxColour
*dg
= wxTheColourDatabase
->FindColour( "MEDIUM GREY" );
250 item
.m_data
= (long)this;
253 //-----------------------------------------------------------------------------
255 //-----------------------------------------------------------------------------
257 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
);
259 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
)
260 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
)
261 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
)
264 wxFileCtrl::wxFileCtrl()
266 m_dirName
= wxT("/");
267 m_showHidden
= FALSE
;
270 wxFileCtrl::wxFileCtrl( wxWindow
*win
, wxWindowID id
,
271 const wxString
&dirName
, const wxString
&wild
,
272 const wxPoint
&pos
, const wxSize
&size
,
273 long style
, const wxValidator
&validator
, const wxString
&name
) :
274 wxListCtrl( win
, id
, pos
, size
, style
, validator
, name
)
276 wxImageList
*imageList
= new wxImageList( 16, 16 );
277 imageList
->Add( wxBitmap( folder_xpm
) );
278 SetImageList( imageList
, wxIMAGE_LIST_SMALL
);
282 m_showHidden
= FALSE
;
286 void wxFileCtrl::ChangeToListMode()
288 SetSingleStyle( wxLC_LIST
);
292 void wxFileCtrl::ChangeToReportMode()
294 SetSingleStyle( wxLC_REPORT
);
298 void wxFileCtrl::ChangeToIconMode()
300 SetSingleStyle( wxLC_ICON
);
304 void wxFileCtrl::ShowHidden( bool show
)
310 long wxFileCtrl::Add( wxFileData
*fd
, wxListItem
&item
)
313 item
.m_mask
= wxLIST_MASK_TEXT
+ wxLIST_MASK_DATA
+ wxLIST_MASK_IMAGE
;
314 fd
->MakeItem( item
);
315 long my_style
= GetWindowStyleFlag();
316 if (my_style
& wxLC_REPORT
)
318 ret
= InsertItem( item
);
319 for (int i
= 1; i
< 5; i
++) SetItem( item
.m_itemId
, i
, fd
->GetEntry( i
) );
321 else if (my_style
& wxLC_LIST
)
323 ret
= InsertItem( item
);
328 void wxFileCtrl::Update()
331 long my_style
= GetWindowStyleFlag();
332 if (my_style
& wxLC_REPORT
)
334 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, 130 );
335 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
336 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 55 );
337 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 );
338 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 );
340 wxFileData
*fd
= (wxFileData
*) NULL
;
345 if (m_dirName
!= wxT("/"))
347 wxString
p( wxPathOnly(m_dirName
) );
348 if (p
.IsEmpty()) p
= wxT("/");
349 fd
= new wxFileData( wxT(".."), p
);
354 wxString res
= m_dirName
+ wxT("/*");
355 wxString
f( wxFindFirstFile( res
.GetData(), wxDIR
) );
358 res
= wxFileNameFromPath( f
);
359 fd
= new wxFileData( res
, f
);
360 wxString s
= fd
->GetName();
361 if (m_showHidden
|| (s
[0] != wxT('.')))
366 f
= wxFindNextFile();
369 res
= m_dirName
+ wxT("/") + m_wild
;
370 f
= wxFindFirstFile( res
.GetData(), wxFILE
);
373 res
= wxFileNameFromPath( f
);
374 fd
= new wxFileData( res
, f
);
375 wxString s
= fd
->GetName();
376 if (m_showHidden
|| (s
[0] != wxT('.')))
381 f
= wxFindNextFile();
384 SortItems( ListCompare
, 0 );
387 void wxFileCtrl::SetWild( const wxString
&wild
)
393 void wxFileCtrl::MakeDir()
395 wxString
new_name( wxT("NewName") );
396 wxString
path( m_dirName
);
399 if (wxFileExists(path
))
401 // try NewName0, NewName1 etc.
404 new_name
= _("NewName");
406 num
.Printf( wxT("%d"), i
);
413 } while (wxFileExists(path
));
419 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
424 wxFileData
*fd
= new wxFileData( new_name
, path
);
428 int id
= Add( fd
, item
);
432 SortItems( ListCompare
, 0 );
433 id
= FindItem( 0, (long)fd
);
439 void wxFileCtrl::GoToParentDir()
441 if (m_dirName
!= wxT("/"))
443 wxString
fname( wxFileNameFromPath(m_dirName
) );
444 m_dirName
= wxPathOnly( m_dirName
);
445 if (m_dirName
.IsEmpty()) m_dirName
= wxT("/");
447 int id
= FindItem( 0, fname
);
450 SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
456 void wxFileCtrl::GoToHomeDir()
458 wxString s
= wxGetUserHome( wxString() );
461 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
465 void wxFileCtrl::GoToDir( const wxString
&dir
)
469 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
473 void wxFileCtrl::GetDir( wxString
&dir
)
478 void wxFileCtrl::OnListDeleteItem( wxListEvent
&event
)
480 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
484 void wxFileCtrl::OnListEndLabelEdit( wxListEvent
&event
)
486 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
489 if ((event
.GetLabel().IsEmpty()) ||
490 (event
.GetLabel() == _(".")) ||
491 (event
.GetLabel() == _("..")) ||
492 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
494 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
500 wxString
new_name( wxPathOnly( fd
->GetFullName() ) );
501 new_name
+= wxT("/");
502 new_name
+= event
.GetLabel();
506 if (wxFileExists(new_name
))
508 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
513 if (wxRenameFile(fd
->GetFullName(),new_name
))
515 fd
->SetNewName( new_name
, event
.GetLabel() );
516 SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
517 EnsureVisible( event
.GetItem() );
521 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
527 //-----------------------------------------------------------------------------
529 //-----------------------------------------------------------------------------
531 #define ID_LIST_MODE wxID_FILEDLGG
532 #define ID_REPORT_MODE wxID_FILEDLGG + 1
533 #define ID_UP_DIR wxID_FILEDLGG + 5
534 #define ID_PARENT_DIR wxID_FILEDLGG + 6
535 #define ID_NEW_DIR wxID_FILEDLGG + 7
536 #define ID_CHOICE wxID_FILEDLGG + 8
537 #define ID_TEXT wxID_FILEDLGG + 9
538 #define ID_LIST_CTRL wxID_FILEDLGG + 10
539 #define ID_ACTIVATED wxID_FILEDLGG + 11
541 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
543 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
)
544 EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
)
545 EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
)
546 EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
)
547 EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
)
548 EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
)
549 EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
)
550 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
)
551 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
)
552 EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoice
)
553 EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
)
556 wxFileDialog::wxFileDialog(wxWindow
*parent
,
557 const wxString
& message
,
558 const wxString
& defaultDir
,
559 const wxString
& defaultFile
,
560 const wxString
& wildCard
,
562 const wxPoint
& pos
) :
563 wxDialog( parent
, -1, message
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
568 m_dialogStyle
= style
;
573 m_dir
= getcwd( buf
, sizeof(buf
) );
577 m_path
+= defaultFile
;
578 m_fileName
= defaultFile
;
579 m_wildCard
= wildCard
;
582 // interpret wildcards
584 if (m_wildCard
.IsEmpty())
585 m_wildCard
= _("All files (*)|*");
587 wxStringTokenizer
tokens( m_wildCard
, wxT("|") );
589 wxString firstWildText
;
590 if (tokens
.CountTokens() == 1)
592 firstWildText
= tokens
.GetNextToken();
593 firstWild
= firstWildText
;
597 wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
598 firstWildText
= tokens
.GetNextToken();
599 firstWild
= tokens
.GetNextToken();
604 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
606 wxBoxSizer
*buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
610 but
= new wxBitmapButton( this, ID_LIST_MODE
, wxBitmap( listview_xpm
) );
612 but
->SetToolTip( _("View files as a list view") );
614 buttonsizer
->Add( but
, 0, wxALL
, 5 );
616 but
= new wxBitmapButton( this, ID_REPORT_MODE
, wxBitmap( repview_xpm
) );
618 but
->SetToolTip( _("View files as a detailed view") );
620 buttonsizer
->Add( but
, 0, wxALL
, 5 );
622 buttonsizer
->Add( 30, 5, 1 );
624 but
= new wxBitmapButton( this, ID_UP_DIR
, wxBitmap( dir_up_xpm
) );
626 but
->SetToolTip( _("Go to parent directory") );
628 buttonsizer
->Add( but
, 0, wxALL
, 5 );
630 but
= new wxBitmapButton( this, ID_PARENT_DIR
, wxBitmap(home_xpm
) );
632 but
->SetToolTip( _("Go to home directory") );
634 buttonsizer
->Add( but
, 0, wxALL
, 5);
636 buttonsizer
->Add( 20, 20 );
638 but
= new wxBitmapButton( this, ID_NEW_DIR
, wxBitmap(new_dir_xpm
) );
640 but
->SetToolTip( _("Create new directory") );
642 buttonsizer
->Add( but
, 0, wxALL
, 5 );
644 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 5 );
646 wxBoxSizer
*staticsizer
= new wxBoxSizer( wxHORIZONTAL
);
647 staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 );
648 m_static
= new wxStaticText( this, -1, m_dir
);
649 staticsizer
->Add( m_static
, 1 );
650 mainsizer
->Add( staticsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 );
652 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
, wxSize(440,180),
653 wxLC_LIST
| wxSUNKEN_BORDER
| wxLC_SINGLE_SEL
);
654 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
656 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
657 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
658 textsizer
->Add( m_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
659 textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
660 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
662 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
663 m_choice
= new wxChoice( this, ID_CHOICE
);
664 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 );
665 choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 10 );
666 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
668 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
669 while (tokens
.HasMoreTokens())
671 firstWildText
= tokens
.GetNextToken();
672 firstWild
= tokens
.GetNextToken();
673 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
675 m_choice
->SetSelection( 0 );
677 SetAutoLayout( TRUE
);
678 SetSizer( mainsizer
);
680 mainsizer
->Fit( this );
681 mainsizer
->SetSizeHints( this );
685 if (m_fileName
.IsEmpty())
693 wxFileDialog::~wxFileDialog()
697 void wxFileDialog::OnChoice( wxCommandEvent
&event
)
699 wxString
*str
= (wxString
*) m_choice
->GetClientData( event
.GetInt() );
700 m_list
->SetWild( *str
);
703 void wxFileDialog::OnActivated( wxListEvent
&event
)
705 HandleAction( event
.m_item
.m_text
);
708 void wxFileDialog::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
710 wxCommandEvent
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
711 cevent
.SetEventObject( this );
712 GetEventHandler()->ProcessEvent( cevent
);
715 void wxFileDialog::OnSelected( wxListEvent
&event
)
717 if (FindFocus() != m_list
) return;
719 wxString
filename( event
.m_item
.m_text
);
720 if (filename
== wxT("..")) return;
723 m_list
->GetDir( dir
);
724 if (dir
!= wxT("/")) dir
+= wxT("/");
726 if (wxDirExists(dir
)) return;
728 m_text
->SetValue( filename
);
731 void wxFileDialog::HandleAction( const wxString
&fn
)
733 wxString
filename( fn
);
735 m_list
->GetDir( dir
);
736 if (filename
.IsEmpty()) return;
737 if (filename
== wxT(".")) return;
739 if (filename
== wxT(".."))
741 m_list
->GoToParentDir();
743 m_list
->GetDir( dir
);
744 m_static
->SetLabel( dir
);
748 if (filename
== wxT("~"))
750 m_list
->GoToHomeDir();
752 m_list
->GetDir( dir
);
753 m_static
->SetLabel( dir
);
757 if (filename
[0] == wxT('~'))
759 filename
.Remove( 0, 1 );
760 wxString
tmp( wxGetUserHome() );
766 if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) ||
767 (filename
.Find(wxT('?')) != wxNOT_FOUND
))
769 if (filename
.Find(wxT('/')) != wxNOT_FOUND
)
771 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK
| wxICON_ERROR
);
774 m_list
->SetWild( filename
);
778 if (dir
!= wxT("/")) dir
+= wxT("/");
779 if (filename
[0] != wxT('/'))
785 if (wxDirExists(filename
))
787 m_list
->GoToDir( filename
);
788 m_list
->GetDir( dir
);
789 m_static
->SetLabel( dir
);
793 if ( (m_dialogStyle
& wxSAVE
) && (m_dialogStyle
& wxOVERWRITE_PROMPT
) )
795 if (wxFileExists( filename
))
798 msg
.Printf( _("File '%s' already exists, do you really want to "
799 "overwrite it?"), filename
.c_str() );
801 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
805 else if ( (m_dialogStyle
& wxOPEN
) && (m_dialogStyle
& wxFILE_MUST_EXIST
) )
807 if ( !wxFileExists( filename
) )
809 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
| wxICON_ERROR
);
816 wxCommandEvent event
;
817 wxDialog::OnOK(event
);
820 void wxFileDialog::OnListOk( wxCommandEvent
&WXUNUSED(event
) )
822 HandleAction( m_text
->GetValue() );
825 void wxFileDialog::OnList( wxCommandEvent
&WXUNUSED(event
) )
827 m_list
->ChangeToListMode();
831 void wxFileDialog::OnReport( wxCommandEvent
&WXUNUSED(event
) )
833 m_list
->ChangeToReportMode();
837 void wxFileDialog::OnUp( wxCommandEvent
&WXUNUSED(event
) )
839 m_list
->GoToParentDir();
842 m_list
->GetDir( dir
);
843 m_static
->SetLabel( dir
);
846 void wxFileDialog::OnHome( wxCommandEvent
&WXUNUSED(event
) )
848 m_list
->GoToHomeDir();
851 m_list
->GetDir( dir
);
852 m_static
->SetLabel( dir
);
855 void wxFileDialog::OnNew( wxCommandEvent
&WXUNUSED(event
) )
860 void wxFileDialog::SetPath( const wxString
& path
)
862 // not only set the full path but also update filename and dir
867 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
870 m_fileName
+= wxT(".");
876 // ----------------------------------------------------------------------------
878 // ----------------------------------------------------------------------------
881 wxFileSelectorEx(const wxChar
*message
,
882 const wxChar
*default_path
,
883 const wxChar
*default_filename
,
884 int *WXUNUSED(indexDefaultExtension
),
885 const wxChar
*wildcard
,
890 // TODO: implement this somehow
891 return wxFileSelector(message
, default_path
, default_filename
, wxT(""),
892 wildcard
, flags
, parent
, x
, y
);
895 wxString
wxFileSelector( const wxChar
*title
,
896 const wxChar
*defaultDir
, const wxChar
*defaultFileName
,
897 const wxChar
*defaultExtension
, const wxChar
*filter
, int flags
,
898 wxWindow
*parent
, int x
, int y
)
901 if ( defaultExtension
&& !filter
)
902 filter2
= wxString(wxT("*.")) + wxString(defaultExtension
) ;
906 wxString defaultDirString
;
908 defaultDirString
= defaultDir
;
910 wxString defaultFilenameString
;
912 defaultFilenameString
= defaultFileName
;
914 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
916 if ( fileDialog
.ShowModal() == wxID_OK
)
918 return fileDialog
.GetPath();
922 return wxEmptyString
;
926 wxString
wxLoadFileSelector( const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
, wxWindow
*parent
)
928 wxChar
*ext
= (wxChar
*)extension
;
931 wxString str
= _("Load %s file");
932 wxSprintf(prompt
, str
, what
);
934 if (*ext
== wxT('.')) ext
++;
936 wxSprintf(wild
, wxT("*.%s"), ext
);
938 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);
941 wxString
wxSaveFileSelector(const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
,
944 wxChar
*ext
= (wxChar
*)extension
;
947 wxString str
= _("Save %s file");
948 wxSprintf(prompt
, str
, what
);
950 if (*ext
== wxT('.')) ext
++;
952 wxSprintf(wild
, wxT("*.%s"), ext
);
954 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);