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
);
115 lstat( m_fileName
.fn_str(), &lbuff
);
116 m_isLink
= S_ISLNK( lbuff
.st_mode
);
117 struct tm
*t
= localtime( &lbuff
.st_mtime
);
120 struct tm
*t
= localtime( &buff
.st_mtime
);
123 // struct passwd *user = getpwuid( buff.st_uid );
124 // struct group *grp = getgrgid( buff.st_gid );
126 m_isDir
= S_ISDIR( buff
.st_mode
);
127 m_isExe
= ((buff
.st_mode
& S_IXUSR
) == S_IXUSR
);
129 m_size
= buff
.st_size
;
132 m_minute
= t
->tm_min
;
133 m_month
= t
->tm_mon
+1;
137 m_permissions
.sprintf( wxT("%c%c%c"),
138 ((( buff
.st_mode
& S_IRUSR
) == S_IRUSR
) ? wxT('r') : wxT('-')),
139 ((( buff
.st_mode
& S_IWUSR
) == S_IWUSR
) ? wxT('w') : wxT('-')),
140 ((( buff
.st_mode
& S_IXUSR
) == S_IXUSR
) ? wxT('x') : wxT('-')) );
143 wxString
wxFileData::GetName() const
148 wxString
wxFileData::GetFullName() const
153 wxString
wxFileData::GetHint() const
155 wxString s
= m_fileName
;
157 if (m_isDir
) s
+= _("<DIR> ");
158 else if (m_isLink
) s
+= _("<LINK> ");
161 s
+= LongToString( m_size
);
164 s
+= IntToString( m_day
);
166 s
+= IntToString( m_month
);
168 s
+= IntToString( m_year
);
170 s
+= IntToString( m_hour
);
172 s
+= IntToString( m_minute
);
178 wxString
wxFileData::GetEntry( int num
)
187 if (m_isDir
) s
= _("<DIR>");
188 else if (m_isLink
) s
= _("<LINK>");
189 else s
= LongToString( m_size
);
192 if (m_day
< 10) s
= wxT("0"); else s
= wxT("");
193 s
+= IntToString( m_day
);
195 if (m_month
< 10) s
+= wxT("0");
196 s
+= IntToString( m_month
);
198 if (m_year
< 10) s
+= wxT("0"); // this should happen real soon...
199 s
+= IntToString( m_year
);
202 if (m_hour
< 10) s
= wxT("0"); else s
= wxT("");
203 s
+= IntToString( m_hour
);
205 if (m_minute
< 10) s
+= wxT("0");
206 s
+= IntToString( m_minute
);
218 bool wxFileData::IsDir()
223 bool wxFileData::IsExe()
228 bool wxFileData::IsLink()
233 long wxFileData::GetSize()
238 void wxFileData::SetNewName( const wxString
&name
, const wxString
&fname
)
244 void wxFileData::MakeItem( wxListItem
&item
)
246 item
.m_text
= m_name
;
247 item
.m_colour
= wxBLACK
;
248 if (IsExe()) item
.m_colour
= wxRED
;
249 if (IsDir()) item
.m_colour
= wxBLUE
;
250 if (IsDir()) item
.m_image
= 0; else item
.m_image
= -1;
253 wxColour
*dg
= wxTheColourDatabase
->FindColour( "MEDIUM GREY" );
256 item
.m_data
= (long)this;
259 //-----------------------------------------------------------------------------
261 //-----------------------------------------------------------------------------
263 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
);
265 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
)
266 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
)
267 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
)
270 wxFileCtrl::wxFileCtrl()
272 m_dirName
= wxT("/");
273 m_showHidden
= FALSE
;
276 wxFileCtrl::wxFileCtrl( wxWindow
*win
, wxWindowID id
,
277 const wxString
&dirName
, const wxString
&wild
,
278 const wxPoint
&pos
, const wxSize
&size
,
279 long style
, const wxValidator
&validator
, const wxString
&name
) :
280 wxListCtrl( win
, id
, pos
, size
, style
, validator
, name
)
282 wxImageList
*imageList
= new wxImageList( 16, 16 );
283 imageList
->Add( wxBitmap( folder_xpm
) );
284 SetImageList( imageList
, wxIMAGE_LIST_SMALL
);
288 m_showHidden
= FALSE
;
292 void wxFileCtrl::ChangeToListMode()
294 SetSingleStyle( wxLC_LIST
);
298 void wxFileCtrl::ChangeToReportMode()
300 SetSingleStyle( wxLC_REPORT
);
304 void wxFileCtrl::ChangeToIconMode()
306 SetSingleStyle( wxLC_ICON
);
310 void wxFileCtrl::ShowHidden( bool show
)
316 long wxFileCtrl::Add( wxFileData
*fd
, wxListItem
&item
)
319 item
.m_mask
= wxLIST_MASK_TEXT
+ wxLIST_MASK_DATA
+ wxLIST_MASK_IMAGE
;
320 fd
->MakeItem( item
);
321 long my_style
= GetWindowStyleFlag();
322 if (my_style
& wxLC_REPORT
)
324 ret
= InsertItem( item
);
325 for (int i
= 1; i
< 5; i
++) SetItem( item
.m_itemId
, i
, fd
->GetEntry( i
) );
327 else if (my_style
& wxLC_LIST
)
329 ret
= InsertItem( item
);
334 void wxFileCtrl::Update()
337 long my_style
= GetWindowStyleFlag();
338 if (my_style
& wxLC_REPORT
)
340 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, 130 );
341 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
342 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 55 );
343 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 );
344 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 );
346 wxFileData
*fd
= (wxFileData
*) NULL
;
351 if (m_dirName
!= wxT("/"))
353 wxString
p( wxPathOnly(m_dirName
) );
354 if (p
.IsEmpty()) p
= wxT("/");
355 fd
= new wxFileData( wxT(".."), p
);
360 wxString res
= m_dirName
+ wxT("/*");
361 wxString
f( wxFindFirstFile( res
.GetData(), wxDIR
) );
364 res
= wxFileNameFromPath( f
);
365 fd
= new wxFileData( res
, f
);
366 wxString s
= fd
->GetName();
367 if (m_showHidden
|| (s
[0] != wxT('.')))
372 f
= wxFindNextFile();
375 res
= m_dirName
+ wxT("/") + m_wild
;
376 f
= wxFindFirstFile( res
.GetData(), wxFILE
);
379 res
= wxFileNameFromPath( f
);
380 fd
= new wxFileData( res
, f
);
381 wxString s
= fd
->GetName();
382 if (m_showHidden
|| (s
[0] != wxT('.')))
387 f
= wxFindNextFile();
390 SortItems( ListCompare
, 0 );
393 void wxFileCtrl::SetWild( const wxString
&wild
)
399 void wxFileCtrl::MakeDir()
401 wxString
new_name( wxT("NewName") );
402 wxString
path( m_dirName
);
405 if (wxFileExists(path
))
407 // try NewName0, NewName1 etc.
410 new_name
= _("NewName");
412 num
.Printf( wxT("%d"), i
);
419 } while (wxFileExists(path
));
425 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
430 wxFileData
*fd
= new wxFileData( new_name
, path
);
434 int id
= Add( fd
, item
);
438 SortItems( ListCompare
, 0 );
439 id
= FindItem( 0, (long)fd
);
445 void wxFileCtrl::GoToParentDir()
447 if (m_dirName
!= wxT("/"))
449 wxString
fname( wxFileNameFromPath(m_dirName
) );
450 m_dirName
= wxPathOnly( m_dirName
);
451 if (m_dirName
.IsEmpty()) m_dirName
= wxT("/");
453 int id
= FindItem( 0, fname
);
456 SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
462 void wxFileCtrl::GoToHomeDir()
464 wxString s
= wxGetUserHome( wxString() );
467 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
471 void wxFileCtrl::GoToDir( const wxString
&dir
)
475 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
479 void wxFileCtrl::GetDir( wxString
&dir
)
484 void wxFileCtrl::OnListDeleteItem( wxListEvent
&event
)
486 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
490 void wxFileCtrl::OnListEndLabelEdit( wxListEvent
&event
)
492 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
495 if ((event
.GetLabel().IsEmpty()) ||
496 (event
.GetLabel() == _(".")) ||
497 (event
.GetLabel() == _("..")) ||
498 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
500 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
506 wxString
new_name( wxPathOnly( fd
->GetFullName() ) );
507 new_name
+= wxT("/");
508 new_name
+= event
.GetLabel();
512 if (wxFileExists(new_name
))
514 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
519 if (wxRenameFile(fd
->GetFullName(),new_name
))
521 fd
->SetNewName( new_name
, event
.GetLabel() );
522 SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
523 EnsureVisible( event
.GetItem() );
527 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
533 //-----------------------------------------------------------------------------
535 //-----------------------------------------------------------------------------
537 #define ID_LIST_MODE wxID_FILEDLGG
538 #define ID_REPORT_MODE wxID_FILEDLGG + 1
539 #define ID_UP_DIR wxID_FILEDLGG + 5
540 #define ID_PARENT_DIR wxID_FILEDLGG + 6
541 #define ID_NEW_DIR wxID_FILEDLGG + 7
542 #define ID_CHOICE wxID_FILEDLGG + 8
543 #define ID_TEXT wxID_FILEDLGG + 9
544 #define ID_LIST_CTRL wxID_FILEDLGG + 10
545 #define ID_ACTIVATED wxID_FILEDLGG + 11
546 #define ID_CHECK wxID_FILEDLGG + 12
548 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
550 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
)
551 EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
)
552 EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
)
553 EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
)
554 EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
)
555 EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
)
556 EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
)
557 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
)
558 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
)
559 EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoice
)
560 EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
)
561 EVT_CHECKBOX(ID_CHECK
,wxFileDialog::OnCheck
)
564 wxFileDialog::wxFileDialog(wxWindow
*parent
,
565 const wxString
& message
,
566 const wxString
& defaultDir
,
567 const wxString
& defaultFile
,
568 const wxString
& wildCard
,
570 const wxPoint
& pos
) :
571 wxDialog( parent
, -1, message
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
576 m_dialogStyle
= style
;
581 m_dir
= getcwd( buf
, sizeof(buf
) );
585 m_path
+= defaultFile
;
586 m_fileName
= defaultFile
;
587 m_wildCard
= wildCard
;
590 // interpret wildcards
592 if (m_wildCard
.IsEmpty())
593 m_wildCard
= _("All files (*)|*");
595 wxStringTokenizer
tokens( m_wildCard
, wxT("|") );
597 wxString firstWildText
;
598 if (tokens
.CountTokens() == 1)
600 firstWildText
= tokens
.GetNextToken();
601 firstWild
= firstWildText
;
605 wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
606 firstWildText
= tokens
.GetNextToken();
607 firstWild
= tokens
.GetNextToken();
612 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
614 wxBoxSizer
*buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
618 but
= new wxBitmapButton( this, ID_LIST_MODE
, wxBitmap( listview_xpm
) );
620 but
->SetToolTip( _("View files as a list view") );
622 buttonsizer
->Add( but
, 0, wxALL
, 5 );
624 but
= new wxBitmapButton( this, ID_REPORT_MODE
, wxBitmap( repview_xpm
) );
626 but
->SetToolTip( _("View files as a detailed view") );
628 buttonsizer
->Add( but
, 0, wxALL
, 5 );
630 buttonsizer
->Add( 30, 5, 1 );
632 but
= new wxBitmapButton( this, ID_UP_DIR
, wxBitmap( dir_up_xpm
) );
634 but
->SetToolTip( _("Go to parent directory") );
636 buttonsizer
->Add( but
, 0, wxALL
, 5 );
638 but
= new wxBitmapButton( this, ID_PARENT_DIR
, wxBitmap(home_xpm
) );
640 but
->SetToolTip( _("Go to home directory") );
642 buttonsizer
->Add( but
, 0, wxALL
, 5);
644 buttonsizer
->Add( 20, 20 );
646 but
= new wxBitmapButton( this, ID_NEW_DIR
, wxBitmap(new_dir_xpm
) );
648 but
->SetToolTip( _("Create new directory") );
650 buttonsizer
->Add( but
, 0, wxALL
, 5 );
652 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 5 );
654 wxBoxSizer
*staticsizer
= new wxBoxSizer( wxHORIZONTAL
);
655 staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 );
656 m_static
= new wxStaticText( this, -1, m_dir
);
657 staticsizer
->Add( m_static
, 1 );
658 mainsizer
->Add( staticsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 );
660 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
, wxSize(440,180),
661 wxLC_LIST
| wxSUNKEN_BORDER
| wxLC_SINGLE_SEL
);
662 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
664 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
665 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
666 textsizer
->Add( m_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
667 textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
668 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
670 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
671 m_choice
= new wxChoice( this, ID_CHOICE
);
672 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 );
673 m_check
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") );
674 m_check
->SetValue( FALSE
);
675 choicesizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 10 );
676 choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 10 );
677 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
679 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
680 while (tokens
.HasMoreTokens())
682 firstWildText
= tokens
.GetNextToken();
683 firstWild
= tokens
.GetNextToken();
684 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
686 m_choice
->SetSelection( 0 );
688 SetAutoLayout( TRUE
);
689 SetSizer( mainsizer
);
691 mainsizer
->Fit( this );
692 mainsizer
->SetSizeHints( this );
696 if (m_fileName
.IsEmpty())
704 wxFileDialog::~wxFileDialog()
708 void wxFileDialog::OnChoice( wxCommandEvent
&event
)
710 wxString
*str
= (wxString
*) m_choice
->GetClientData( event
.GetInt() );
711 m_list
->SetWild( *str
);
714 void wxFileDialog::OnCheck( wxCommandEvent
&event
)
716 m_list
->ShowHidden( event
.GetInt() );
719 void wxFileDialog::OnActivated( wxListEvent
&event
)
721 HandleAction( event
.m_item
.m_text
);
724 void wxFileDialog::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
726 wxCommandEvent
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
727 cevent
.SetEventObject( this );
728 GetEventHandler()->ProcessEvent( cevent
);
731 void wxFileDialog::OnSelected( wxListEvent
&event
)
733 if (FindFocus() != m_list
) return;
735 wxString
filename( event
.m_item
.m_text
);
736 if (filename
== wxT("..")) return;
739 m_list
->GetDir( dir
);
740 if (dir
!= wxT("/")) dir
+= wxT("/");
742 if (wxDirExists(dir
)) return;
744 m_text
->SetValue( filename
);
747 void wxFileDialog::HandleAction( const wxString
&fn
)
749 wxString
filename( fn
);
751 m_list
->GetDir( dir
);
752 if (filename
.IsEmpty()) return;
753 if (filename
== wxT(".")) return;
755 if (filename
== wxT(".."))
757 m_list
->GoToParentDir();
759 m_list
->GetDir( dir
);
760 m_static
->SetLabel( dir
);
764 if (filename
== wxT("~"))
766 m_list
->GoToHomeDir();
768 m_list
->GetDir( dir
);
769 m_static
->SetLabel( dir
);
773 if (filename
[0] == wxT('~'))
775 filename
.Remove( 0, 1 );
776 wxString
tmp( wxGetUserHome() );
782 if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) ||
783 (filename
.Find(wxT('?')) != wxNOT_FOUND
))
785 if (filename
.Find(wxT('/')) != wxNOT_FOUND
)
787 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK
| wxICON_ERROR
);
790 m_list
->SetWild( filename
);
794 if (dir
!= wxT("/")) dir
+= wxT("/");
795 if (filename
[0] != wxT('/'))
801 if (wxDirExists(filename
))
803 m_list
->GoToDir( filename
);
804 m_list
->GetDir( dir
);
805 m_static
->SetLabel( dir
);
809 if ( (m_dialogStyle
& wxSAVE
) && (m_dialogStyle
& wxOVERWRITE_PROMPT
) )
811 if (wxFileExists( filename
))
814 msg
.Printf( _("File '%s' already exists, do you really want to "
815 "overwrite it?"), filename
.c_str() );
817 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
821 else if ( (m_dialogStyle
& wxOPEN
) && (m_dialogStyle
& wxFILE_MUST_EXIST
) )
823 if ( !wxFileExists( filename
) )
825 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
| wxICON_ERROR
);
832 wxCommandEvent event
;
833 wxDialog::OnOK(event
);
836 void wxFileDialog::OnListOk( wxCommandEvent
&WXUNUSED(event
) )
838 HandleAction( m_text
->GetValue() );
841 void wxFileDialog::OnList( wxCommandEvent
&WXUNUSED(event
) )
843 m_list
->ChangeToListMode();
847 void wxFileDialog::OnReport( wxCommandEvent
&WXUNUSED(event
) )
849 m_list
->ChangeToReportMode();
853 void wxFileDialog::OnUp( wxCommandEvent
&WXUNUSED(event
) )
855 m_list
->GoToParentDir();
858 m_list
->GetDir( dir
);
859 m_static
->SetLabel( dir
);
862 void wxFileDialog::OnHome( wxCommandEvent
&WXUNUSED(event
) )
864 m_list
->GoToHomeDir();
867 m_list
->GetDir( dir
);
868 m_static
->SetLabel( dir
);
871 void wxFileDialog::OnNew( wxCommandEvent
&WXUNUSED(event
) )
876 void wxFileDialog::SetPath( const wxString
& path
)
878 // not only set the full path but also update filename and dir
883 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
886 m_fileName
+= wxT(".");
892 // ----------------------------------------------------------------------------
894 // ----------------------------------------------------------------------------
897 wxFileSelectorEx(const wxChar
*message
,
898 const wxChar
*default_path
,
899 const wxChar
*default_filename
,
900 int *WXUNUSED(indexDefaultExtension
),
901 const wxChar
*wildcard
,
906 // TODO: implement this somehow
907 return wxFileSelector(message
, default_path
, default_filename
, wxT(""),
908 wildcard
, flags
, parent
, x
, y
);
911 wxString
wxFileSelector( const wxChar
*title
,
912 const wxChar
*defaultDir
, const wxChar
*defaultFileName
,
913 const wxChar
*defaultExtension
, const wxChar
*filter
, int flags
,
914 wxWindow
*parent
, int x
, int y
)
917 if ( defaultExtension
&& !filter
)
918 filter2
= wxString(wxT("*.")) + wxString(defaultExtension
) ;
922 wxString defaultDirString
;
924 defaultDirString
= defaultDir
;
926 wxString defaultFilenameString
;
928 defaultFilenameString
= defaultFileName
;
930 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
932 if ( fileDialog
.ShowModal() == wxID_OK
)
934 return fileDialog
.GetPath();
938 return wxEmptyString
;
942 wxString
wxLoadFileSelector( const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
, wxWindow
*parent
)
944 wxChar
*ext
= (wxChar
*)extension
;
947 wxString str
= _("Load %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
);
957 wxString
wxSaveFileSelector(const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
,
960 wxChar
*ext
= (wxChar
*)extension
;
963 wxString str
= _("Save %s file");
964 wxSprintf(prompt
, str
, what
);
966 if (*ext
== wxT('.')) ext
++;
968 wxSprintf(wild
, wxT("*.%s"), ext
);
970 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);