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 if (IsExe()) item
.SetTextColour(*wxRED
);
248 if (IsDir()) item
.SetTextColour(*wxBLUE
);
249 item
.m_image
= IsDir() ? 0 : -1;
252 wxColour
*dg
= wxTheColourDatabase
->FindColour( "MEDIUM GREY" );
253 item
.SetTextColour(*dg
);
255 item
.m_data
= (long)this;
258 //-----------------------------------------------------------------------------
260 //-----------------------------------------------------------------------------
262 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
);
264 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
)
265 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
)
266 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
)
269 wxFileCtrl::wxFileCtrl()
271 m_dirName
= wxT("/");
272 m_showHidden
= FALSE
;
275 wxFileCtrl::wxFileCtrl( wxWindow
*win
, wxWindowID id
,
276 const wxString
&dirName
, const wxString
&wild
,
277 const wxPoint
&pos
, const wxSize
&size
,
278 long style
, const wxValidator
&validator
, const wxString
&name
) :
279 wxListCtrl( win
, id
, pos
, size
, style
, validator
, name
)
281 wxImageList
*imageList
= new wxImageList( 16, 16 );
282 imageList
->Add( wxBitmap( folder_xpm
) );
283 SetImageList( imageList
, wxIMAGE_LIST_SMALL
);
287 m_showHidden
= FALSE
;
291 void wxFileCtrl::ChangeToListMode()
293 SetSingleStyle( wxLC_LIST
);
297 void wxFileCtrl::ChangeToReportMode()
299 SetSingleStyle( wxLC_REPORT
);
303 void wxFileCtrl::ChangeToIconMode()
305 SetSingleStyle( wxLC_ICON
);
309 void wxFileCtrl::ShowHidden( bool show
)
315 long wxFileCtrl::Add( wxFileData
*fd
, wxListItem
&item
)
318 item
.m_mask
= wxLIST_MASK_TEXT
+ wxLIST_MASK_DATA
+ wxLIST_MASK_IMAGE
;
319 fd
->MakeItem( item
);
320 long my_style
= GetWindowStyleFlag();
321 if (my_style
& wxLC_REPORT
)
323 ret
= InsertItem( item
);
324 for (int i
= 1; i
< 5; i
++) SetItem( item
.m_itemId
, i
, fd
->GetEntry( i
) );
326 else if (my_style
& wxLC_LIST
)
328 ret
= InsertItem( item
);
333 void wxFileCtrl::Update()
336 long my_style
= GetWindowStyleFlag();
337 if (my_style
& wxLC_REPORT
)
339 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, 130 );
340 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
341 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 55 );
342 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 );
343 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 );
345 wxFileData
*fd
= (wxFileData
*) NULL
;
350 if (m_dirName
!= wxT("/"))
352 wxString
p( wxPathOnly(m_dirName
) );
353 if (p
.IsEmpty()) p
= wxT("/");
354 fd
= new wxFileData( wxT(".."), p
);
359 wxString res
= m_dirName
+ wxT("/*");
360 wxString
f( wxFindFirstFile( res
.GetData(), wxDIR
) );
363 res
= wxFileNameFromPath( f
);
364 fd
= new wxFileData( res
, f
);
365 wxString s
= fd
->GetName();
366 if (m_showHidden
|| (s
[0] != wxT('.')))
371 f
= wxFindNextFile();
374 res
= m_dirName
+ wxT("/") + m_wild
;
375 f
= wxFindFirstFile( res
.GetData(), wxFILE
);
378 res
= wxFileNameFromPath( f
);
379 fd
= new wxFileData( res
, f
);
380 wxString s
= fd
->GetName();
381 if (m_showHidden
|| (s
[0] != wxT('.')))
386 f
= wxFindNextFile();
389 SortItems( ListCompare
, 0 );
392 void wxFileCtrl::SetWild( const wxString
&wild
)
398 void wxFileCtrl::MakeDir()
400 wxString
new_name( wxT("NewName") );
401 wxString
path( m_dirName
);
404 if (wxFileExists(path
))
406 // try NewName0, NewName1 etc.
409 new_name
= _("NewName");
411 num
.Printf( wxT("%d"), i
);
418 } while (wxFileExists(path
));
424 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
429 wxFileData
*fd
= new wxFileData( new_name
, path
);
433 int id
= Add( fd
, item
);
437 SortItems( ListCompare
, 0 );
438 id
= FindItem( 0, (long)fd
);
444 void wxFileCtrl::GoToParentDir()
446 if (m_dirName
!= wxT("/"))
448 wxString
fname( wxFileNameFromPath(m_dirName
) );
449 m_dirName
= wxPathOnly( m_dirName
);
450 if (m_dirName
.IsEmpty()) m_dirName
= wxT("/");
452 int id
= FindItem( 0, fname
);
455 SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
461 void wxFileCtrl::GoToHomeDir()
463 wxString s
= wxGetUserHome( wxString() );
466 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
470 void wxFileCtrl::GoToDir( const wxString
&dir
)
474 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
478 void wxFileCtrl::GetDir( wxString
&dir
)
483 void wxFileCtrl::OnListDeleteItem( wxListEvent
&event
)
485 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
489 void wxFileCtrl::OnListEndLabelEdit( wxListEvent
&event
)
491 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
494 if ((event
.GetLabel().IsEmpty()) ||
495 (event
.GetLabel() == _(".")) ||
496 (event
.GetLabel() == _("..")) ||
497 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
499 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
505 wxString
new_name( wxPathOnly( fd
->GetFullName() ) );
506 new_name
+= wxT("/");
507 new_name
+= event
.GetLabel();
511 if (wxFileExists(new_name
))
513 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
518 if (wxRenameFile(fd
->GetFullName(),new_name
))
520 fd
->SetNewName( new_name
, event
.GetLabel() );
521 SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
522 EnsureVisible( event
.GetItem() );
526 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
532 //-----------------------------------------------------------------------------
534 //-----------------------------------------------------------------------------
536 #define ID_LIST_MODE wxID_FILEDLGG
537 #define ID_REPORT_MODE wxID_FILEDLGG + 1
538 #define ID_UP_DIR wxID_FILEDLGG + 5
539 #define ID_PARENT_DIR wxID_FILEDLGG + 6
540 #define ID_NEW_DIR wxID_FILEDLGG + 7
541 #define ID_CHOICE wxID_FILEDLGG + 8
542 #define ID_TEXT wxID_FILEDLGG + 9
543 #define ID_LIST_CTRL wxID_FILEDLGG + 10
544 #define ID_ACTIVATED wxID_FILEDLGG + 11
545 #define ID_CHECK wxID_FILEDLGG + 12
547 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
549 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
)
550 EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
)
551 EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
)
552 EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
)
553 EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
)
554 EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
)
555 EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
)
556 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
)
557 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
)
558 EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoice
)
559 EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
)
560 EVT_CHECKBOX(ID_CHECK
,wxFileDialog::OnCheck
)
563 wxFileDialog::wxFileDialog(wxWindow
*parent
,
564 const wxString
& message
,
565 const wxString
& defaultDir
,
566 const wxString
& defaultFile
,
567 const wxString
& wildCard
,
569 const wxPoint
& pos
) :
570 wxDialog( parent
, -1, message
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
575 m_dialogStyle
= style
;
577 if ((m_dialogStyle
& wxMULTIPLE
) && !(m_dialogStyle
& wxOPEN
))
578 m_dialogStyle
&= ~wxMULTIPLE
;
584 m_dir
= getcwd( buf
, sizeof(buf
) );
588 m_path
+= defaultFile
;
589 m_fileName
= defaultFile
;
590 m_wildCard
= wildCard
;
593 // interpret wildcards
595 if (m_wildCard
.IsEmpty())
596 m_wildCard
= _("All files (*)|*");
598 wxStringTokenizer
tokens( m_wildCard
, wxT("|") );
600 wxString firstWildText
;
601 if (tokens
.CountTokens() == 1)
603 firstWildText
= tokens
.GetNextToken();
604 firstWild
= firstWildText
;
608 wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
609 firstWildText
= tokens
.GetNextToken();
610 firstWild
= tokens
.GetNextToken();
615 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
617 wxBoxSizer
*buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
621 but
= new wxBitmapButton( this, ID_LIST_MODE
, wxBitmap( listview_xpm
) );
623 but
->SetToolTip( _("View files as a list view") );
625 buttonsizer
->Add( but
, 0, wxALL
, 5 );
627 but
= new wxBitmapButton( this, ID_REPORT_MODE
, wxBitmap( repview_xpm
) );
629 but
->SetToolTip( _("View files as a detailed view") );
631 buttonsizer
->Add( but
, 0, wxALL
, 5 );
633 buttonsizer
->Add( 30, 5, 1 );
635 but
= new wxBitmapButton( this, ID_UP_DIR
, wxBitmap( dir_up_xpm
) );
637 but
->SetToolTip( _("Go to parent directory") );
639 buttonsizer
->Add( but
, 0, wxALL
, 5 );
641 but
= new wxBitmapButton( this, ID_PARENT_DIR
, wxBitmap(home_xpm
) );
643 but
->SetToolTip( _("Go to home directory") );
645 buttonsizer
->Add( but
, 0, wxALL
, 5);
647 buttonsizer
->Add( 20, 20 );
649 but
= new wxBitmapButton( this, ID_NEW_DIR
, wxBitmap(new_dir_xpm
) );
651 but
->SetToolTip( _("Create new directory") );
653 buttonsizer
->Add( but
, 0, wxALL
, 5 );
655 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 5 );
657 wxBoxSizer
*staticsizer
= new wxBoxSizer( wxHORIZONTAL
);
658 staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 );
659 m_static
= new wxStaticText( this, -1, m_dir
);
660 staticsizer
->Add( m_static
, 1 );
661 mainsizer
->Add( staticsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 );
663 if (m_dialogStyle
& wxMULTIPLE
)
664 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
,
665 wxSize(440,180), wxLC_LIST
| wxSUNKEN_BORDER
);
667 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
,
668 wxSize(440,180), wxLC_LIST
| wxSUNKEN_BORDER
| wxLC_SINGLE_SEL
);
669 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
671 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
672 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
673 textsizer
->Add( m_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
674 textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
675 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
677 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
678 m_choice
= new wxChoice( this, ID_CHOICE
);
679 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 );
680 m_check
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") );
681 m_check
->SetValue( FALSE
);
682 choicesizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 10 );
683 choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 10 );
684 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
686 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
687 while (tokens
.HasMoreTokens())
689 firstWildText
= tokens
.GetNextToken();
690 firstWild
= tokens
.GetNextToken();
691 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
693 m_choice
->SetSelection( 0 );
695 SetAutoLayout( TRUE
);
696 SetSizer( mainsizer
);
698 mainsizer
->Fit( this );
699 mainsizer
->SetSizeHints( this );
703 if (m_fileName
.IsEmpty())
711 wxFileDialog::~wxFileDialog()
715 void wxFileDialog::OnChoice( wxCommandEvent
&event
)
717 wxString
*str
= (wxString
*) m_choice
->GetClientData( event
.GetInt() );
718 m_list
->SetWild( *str
);
719 m_filterIndex
= event
.GetInt();
722 void wxFileDialog::OnCheck( wxCommandEvent
&event
)
724 m_list
->ShowHidden( event
.GetInt() );
727 void wxFileDialog::OnActivated( wxListEvent
&event
)
729 HandleAction( event
.m_item
.m_text
);
732 void wxFileDialog::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
734 wxCommandEvent
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
735 cevent
.SetEventObject( this );
736 GetEventHandler()->ProcessEvent( cevent
);
739 void wxFileDialog::OnSelected( wxListEvent
&event
)
741 if (FindFocus() != m_list
) return;
743 wxString
filename( event
.m_item
.m_text
);
744 if (filename
== wxT("..")) return;
747 m_list
->GetDir( dir
);
748 if (dir
!= wxT("/")) dir
+= wxT("/");
750 if (wxDirExists(dir
)) return;
752 m_text
->SetValue( filename
);
755 void wxFileDialog::HandleAction( const wxString
&fn
)
757 wxString
filename( fn
);
759 m_list
->GetDir( dir
);
760 if (filename
.IsEmpty()) return;
761 if (filename
== wxT(".")) return;
763 if (filename
== wxT(".."))
765 m_list
->GoToParentDir();
767 m_list
->GetDir( dir
);
768 m_static
->SetLabel( dir
);
772 if (filename
== wxT("~"))
774 m_list
->GoToHomeDir();
776 m_list
->GetDir( dir
);
777 m_static
->SetLabel( dir
);
781 if (filename
[0] == wxT('~'))
783 filename
.Remove( 0, 1 );
784 wxString
tmp( wxGetUserHome() );
790 if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) ||
791 (filename
.Find(wxT('?')) != wxNOT_FOUND
))
793 if (filename
.Find(wxT('/')) != wxNOT_FOUND
)
795 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK
| wxICON_ERROR
);
798 m_list
->SetWild( filename
);
802 if (dir
!= wxT("/")) dir
+= wxT("/");
803 if (filename
[0] != wxT('/'))
809 if (wxDirExists(filename
))
811 m_list
->GoToDir( filename
);
812 m_list
->GetDir( dir
);
813 m_static
->SetLabel( dir
);
817 if ( (m_dialogStyle
& wxSAVE
) && (m_dialogStyle
& wxOVERWRITE_PROMPT
) )
819 if (wxFileExists( filename
))
822 msg
.Printf( _("File '%s' already exists, do you really want to "
823 "overwrite it?"), filename
.c_str() );
825 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
829 else if ( (m_dialogStyle
& wxOPEN
) && (m_dialogStyle
& wxFILE_MUST_EXIST
) )
831 if ( !wxFileExists( filename
) )
833 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
| wxICON_ERROR
);
840 wxCommandEvent event
;
841 wxDialog::OnOK(event
);
844 void wxFileDialog::OnListOk( wxCommandEvent
&WXUNUSED(event
) )
846 HandleAction( m_text
->GetValue() );
849 void wxFileDialog::OnList( wxCommandEvent
&WXUNUSED(event
) )
851 m_list
->ChangeToListMode();
855 void wxFileDialog::OnReport( wxCommandEvent
&WXUNUSED(event
) )
857 m_list
->ChangeToReportMode();
861 void wxFileDialog::OnUp( wxCommandEvent
&WXUNUSED(event
) )
863 m_list
->GoToParentDir();
866 m_list
->GetDir( dir
);
867 m_static
->SetLabel( dir
);
870 void wxFileDialog::OnHome( wxCommandEvent
&WXUNUSED(event
) )
872 m_list
->GoToHomeDir();
875 m_list
->GetDir( dir
);
876 m_static
->SetLabel( dir
);
879 void wxFileDialog::OnNew( wxCommandEvent
&WXUNUSED(event
) )
884 void wxFileDialog::SetPath( const wxString
& path
)
886 // not only set the full path but also update filename and dir
891 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
894 m_fileName
+= wxT(".");
900 void wxFileDialog::GetPaths( wxArrayString
& paths
) const
903 paths
.Alloc( m_list
->GetSelectedItemCount() );
906 m_list
->GetDir( dir
);
907 if (dir
!= wxT("/")) dir
+= wxT("/");
910 item
.m_mask
= wxLIST_MASK_TEXT
;
912 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
913 while ( item
.m_itemId
!= -1 ) {
914 m_list
->GetItem( item
);
915 paths
.Add( dir
+ item
.m_text
);
916 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
+ 1,
917 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
921 void wxFileDialog::GetFilenames(wxArrayString
& files
) const
924 files
.Alloc( m_list
->GetSelectedItemCount() );
927 item
.m_mask
= wxLIST_MASK_TEXT
;
929 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
930 while ( item
.m_itemId
!= -1 ) {
931 m_list
->GetItem( item
);
932 files
.Add( item
.m_text
);
933 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
+ 1,
934 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
938 // ----------------------------------------------------------------------------
940 // ----------------------------------------------------------------------------
943 wxFileSelectorEx(const wxChar
*message
,
944 const wxChar
*default_path
,
945 const wxChar
*default_filename
,
946 int *WXUNUSED(indexDefaultExtension
),
947 const wxChar
*wildcard
,
952 // TODO: implement this somehow
953 return wxFileSelector(message
, default_path
, default_filename
, wxT(""),
954 wildcard
, flags
, parent
, x
, y
);
957 wxString
wxFileSelector( const wxChar
*title
,
958 const wxChar
*defaultDir
, const wxChar
*defaultFileName
,
959 const wxChar
*defaultExtension
, const wxChar
*filter
, int flags
,
960 wxWindow
*parent
, int x
, int y
)
963 if ( defaultExtension
&& !filter
)
964 filter2
= wxString(wxT("*.")) + wxString(defaultExtension
) ;
968 wxString defaultDirString
;
970 defaultDirString
= defaultDir
;
972 wxString defaultFilenameString
;
974 defaultFilenameString
= defaultFileName
;
976 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
978 if ( fileDialog
.ShowModal() == wxID_OK
)
980 return fileDialog
.GetPath();
984 return wxEmptyString
;
988 wxString
wxLoadFileSelector( const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
, wxWindow
*parent
)
990 wxChar
*ext
= (wxChar
*)extension
;
993 wxString str
= _("Load %s file");
994 wxSprintf(prompt
, str
, what
);
996 if (*ext
== wxT('.')) ext
++;
998 wxSprintf(wild
, wxT("*.%s"), ext
);
1000 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);
1003 wxString
wxSaveFileSelector(const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
,
1006 wxChar
*ext
= (wxChar
*)extension
;
1009 wxString str
= _("Save %s file");
1010 wxSprintf(prompt
, str
, what
);
1012 if (*ext
== wxT('.')) ext
++;
1014 wxSprintf(wild
, wxT("*.%s"), ext
);
1016 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);