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;
138 m_permissions
.sprintf( wxT("%c%c%c"),
139 ((( buff
.st_mode
& S_IRUSR
) == S_IRUSR
) ? wxT('r') : wxT('-')),
140 ((( buff
.st_mode
& S_IWUSR
) == S_IWUSR
) ? wxT('w') : wxT('-')),
141 ((( buff
.st_mode
& S_IXUSR
) == S_IXUSR
) ? wxT('x') : wxT('-')) );
144 wxString
wxFileData::GetName() const
149 wxString
wxFileData::GetFullName() const
154 wxString
wxFileData::GetHint() const
156 wxString s
= m_fileName
;
158 if (m_isDir
) s
+= _("<DIR> ");
159 else if (m_isLink
) s
+= _("<LINK> ");
162 s
+= LongToString( m_size
);
165 s
+= IntToString( m_day
);
167 s
+= IntToString( m_month
);
169 s
+= IntToString( m_year
);
171 s
+= IntToString( m_hour
);
173 s
+= IntToString( m_minute
);
179 wxString
wxFileData::GetEntry( int num
)
191 if (m_isDir
) s
= _("<DIR>");
192 else if (m_isLink
) s
= _("<LINK>");
193 else s
= LongToString( m_size
);
198 if (m_day
< 10) s
= wxT("0"); else s
= wxT("");
199 s
+= IntToString( m_day
);
201 if (m_month
< 10) s
+= wxT("0");
202 s
+= IntToString( m_month
);
204 s
+= IntToString( m_year
);
209 if (m_hour
< 10) s
= wxT("0"); else s
= wxT("");
210 s
+= IntToString( m_hour
);
212 if (m_minute
< 10) s
+= wxT("0");
213 s
+= IntToString( m_minute
);
226 bool wxFileData::IsDir()
231 bool wxFileData::IsExe()
236 bool wxFileData::IsLink()
241 long wxFileData::GetSize()
246 void wxFileData::SetNewName( const wxString
&name
, const wxString
&fname
)
252 void wxFileData::MakeItem( wxListItem
&item
)
254 item
.m_text
= m_name
;
255 item
.ClearAttributes();
256 if (IsExe()) item
.SetTextColour(*wxRED
);
257 if (IsDir()) item
.SetTextColour(*wxBLUE
);
258 item
.m_image
= IsDir() ? 0 : -1;
261 wxColour
*dg
= wxTheColourDatabase
->FindColour( "MEDIUM GREY" );
262 item
.SetTextColour(*dg
);
264 item
.m_data
= (long)this;
267 //-----------------------------------------------------------------------------
269 //-----------------------------------------------------------------------------
271 IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl
,wxListCtrl
);
273 BEGIN_EVENT_TABLE(wxFileCtrl
,wxListCtrl
)
274 EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem
)
275 EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit
)
278 wxFileCtrl::wxFileCtrl()
280 m_dirName
= wxT("/");
281 m_showHidden
= FALSE
;
284 wxFileCtrl::wxFileCtrl( wxWindow
*win
, wxWindowID id
,
285 const wxString
&dirName
, const wxString
&wild
,
286 const wxPoint
&pos
, const wxSize
&size
,
287 long style
, const wxValidator
&validator
, const wxString
&name
) :
288 wxListCtrl( win
, id
, pos
, size
, style
, validator
, name
)
290 wxImageList
*imageList
= new wxImageList( 16, 16 );
291 imageList
->Add( wxBitmap( folder_xpm
) );
292 SetImageList( imageList
, wxIMAGE_LIST_SMALL
);
296 m_showHidden
= FALSE
;
300 void wxFileCtrl::ChangeToListMode()
302 SetSingleStyle( wxLC_LIST
);
306 void wxFileCtrl::ChangeToReportMode()
308 SetSingleStyle( wxLC_REPORT
);
312 void wxFileCtrl::ChangeToIconMode()
314 SetSingleStyle( wxLC_ICON
);
318 void wxFileCtrl::ShowHidden( bool show
)
324 long wxFileCtrl::Add( wxFileData
*fd
, wxListItem
&item
)
327 item
.m_mask
= wxLIST_MASK_TEXT
+ wxLIST_MASK_DATA
+ wxLIST_MASK_IMAGE
;
328 fd
->MakeItem( item
);
329 long my_style
= GetWindowStyleFlag();
330 if (my_style
& wxLC_REPORT
)
332 ret
= InsertItem( item
);
333 for (int i
= 1; i
< 5; i
++) SetItem( item
.m_itemId
, i
, fd
->GetEntry( i
) );
335 else if (my_style
& wxLC_LIST
)
337 ret
= InsertItem( item
);
342 void wxFileCtrl::Update()
345 long my_style
= GetWindowStyleFlag();
346 if (my_style
& wxLC_REPORT
)
348 InsertColumn( 0, _("Name"), wxLIST_FORMAT_LEFT
, 130 );
349 InsertColumn( 1, _("Size"), wxLIST_FORMAT_LEFT
, 60 );
350 InsertColumn( 2, _("Date"), wxLIST_FORMAT_LEFT
, 65 );
351 InsertColumn( 3, _("Time"), wxLIST_FORMAT_LEFT
, 50 );
352 InsertColumn( 4, _("Permissions"), wxLIST_FORMAT_LEFT
, 120 );
354 wxFileData
*fd
= (wxFileData
*) NULL
;
359 if (m_dirName
!= wxT("/"))
361 wxString
p( wxPathOnly(m_dirName
) );
362 if (p
.IsEmpty()) p
= wxT("/");
363 fd
= new wxFileData( wxT(".."), p
);
368 wxString res
= m_dirName
+ wxT("/*");
369 wxString
f( wxFindFirstFile( res
.GetData(), wxDIR
) );
372 res
= wxFileNameFromPath( f
);
373 fd
= new wxFileData( res
, f
);
374 wxString s
= fd
->GetName();
375 if (m_showHidden
|| (s
[0] != wxT('.')))
380 f
= wxFindNextFile();
383 res
= m_dirName
+ wxT("/") + m_wild
;
384 f
= wxFindFirstFile( res
.GetData(), wxFILE
);
387 res
= wxFileNameFromPath( f
);
388 fd
= new wxFileData( res
, f
);
389 wxString s
= fd
->GetName();
390 if (m_showHidden
|| (s
[0] != wxT('.')))
395 f
= wxFindNextFile();
398 SortItems( ListCompare
, 0 );
400 SetColumnWidth( 1, wxLIST_AUTOSIZE
);
401 SetColumnWidth( 2, wxLIST_AUTOSIZE
);
402 SetColumnWidth( 3, wxLIST_AUTOSIZE
);
405 void wxFileCtrl::SetWild( const wxString
&wild
)
411 void wxFileCtrl::MakeDir()
413 wxString
new_name( wxT("NewName") );
414 wxString
path( m_dirName
);
417 if (wxFileExists(path
))
419 // try NewName0, NewName1 etc.
422 new_name
= _("NewName");
424 num
.Printf( wxT("%d"), i
);
431 } while (wxFileExists(path
));
437 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
442 wxFileData
*fd
= new wxFileData( new_name
, path
);
446 long id
= Add( fd
, item
);
450 SortItems( ListCompare
, 0 );
451 id
= FindItem( 0, (long)fd
);
457 void wxFileCtrl::GoToParentDir()
459 if (m_dirName
!= wxT("/"))
461 wxString
fname( wxFileNameFromPath(m_dirName
) );
462 m_dirName
= wxPathOnly( m_dirName
);
463 if (m_dirName
.IsEmpty()) m_dirName
= wxT("/");
465 long id
= FindItem( 0, fname
);
468 SetItemState( id
, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
474 void wxFileCtrl::GoToHomeDir()
476 wxString s
= wxGetUserHome( wxString() );
479 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
483 void wxFileCtrl::GoToDir( const wxString
&dir
)
487 SetItemState( 0, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
491 void wxFileCtrl::GetDir( wxString
&dir
)
496 void wxFileCtrl::OnListDeleteItem( wxListEvent
&event
)
498 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
502 void wxFileCtrl::OnListEndLabelEdit( wxListEvent
&event
)
504 wxFileData
*fd
= (wxFileData
*)event
.m_item
.m_data
;
507 if ((event
.GetLabel().IsEmpty()) ||
508 (event
.GetLabel() == _(".")) ||
509 (event
.GetLabel() == _("..")) ||
510 (event
.GetLabel().First( wxT("/") ) != wxNOT_FOUND
))
512 wxMessageDialog
dialog(this, _("Illegal directory name."), _("Error"), wxOK
| wxICON_ERROR
);
518 wxString
new_name( wxPathOnly( fd
->GetFullName() ) );
519 new_name
+= wxT("/");
520 new_name
+= event
.GetLabel();
524 if (wxFileExists(new_name
))
526 wxMessageDialog
dialog(this, _("File name exists already."), _("Error"), wxOK
| wxICON_ERROR
);
531 if (wxRenameFile(fd
->GetFullName(),new_name
))
533 fd
->SetNewName( new_name
, event
.GetLabel() );
534 SetItemState( event
.GetItem(), wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
535 EnsureVisible( event
.GetItem() );
539 wxMessageDialog
dialog(this, _("Operation not permitted."), _("Error"), wxOK
| wxICON_ERROR
);
545 //-----------------------------------------------------------------------------
547 //-----------------------------------------------------------------------------
549 #define ID_LIST_MODE wxID_FILEDLGG
550 #define ID_REPORT_MODE wxID_FILEDLGG + 1
551 #define ID_UP_DIR wxID_FILEDLGG + 5
552 #define ID_PARENT_DIR wxID_FILEDLGG + 6
553 #define ID_NEW_DIR wxID_FILEDLGG + 7
554 #define ID_CHOICE wxID_FILEDLGG + 8
555 #define ID_TEXT wxID_FILEDLGG + 9
556 #define ID_LIST_CTRL wxID_FILEDLGG + 10
557 #define ID_ACTIVATED wxID_FILEDLGG + 11
558 #define ID_CHECK wxID_FILEDLGG + 12
560 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog
,wxDialog
)
562 BEGIN_EVENT_TABLE(wxFileDialog
,wxDialog
)
563 EVT_BUTTON(ID_LIST_MODE
, wxFileDialog::OnList
)
564 EVT_BUTTON(ID_REPORT_MODE
, wxFileDialog::OnReport
)
565 EVT_BUTTON(ID_UP_DIR
, wxFileDialog::OnUp
)
566 EVT_BUTTON(ID_PARENT_DIR
, wxFileDialog::OnHome
)
567 EVT_BUTTON(ID_NEW_DIR
, wxFileDialog::OnNew
)
568 EVT_BUTTON(wxID_OK
, wxFileDialog::OnListOk
)
569 EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL
, wxFileDialog::OnSelected
)
570 EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL
, wxFileDialog::OnActivated
)
571 EVT_CHOICE(ID_CHOICE
,wxFileDialog::OnChoice
)
572 EVT_TEXT_ENTER(ID_TEXT
,wxFileDialog::OnTextEnter
)
573 EVT_CHECKBOX(ID_CHECK
,wxFileDialog::OnCheck
)
576 wxFileDialog::wxFileDialog(wxWindow
*parent
,
577 const wxString
& message
,
578 const wxString
& defaultDir
,
579 const wxString
& defaultFile
,
580 const wxString
& wildCard
,
582 const wxPoint
& pos
) :
583 wxDialog( parent
, -1, message
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
)
588 m_dialogStyle
= style
;
590 if ((m_dialogStyle
& wxMULTIPLE
) && !(m_dialogStyle
& wxOPEN
))
591 m_dialogStyle
|= wxOPEN
;
594 if ((m_dir
.IsEmpty()) || (m_dir
== wxT(".")))
597 m_dir
= getcwd( buf
, sizeof(buf
) );
601 m_path
+= defaultFile
;
602 m_fileName
= defaultFile
;
603 m_wildCard
= wildCard
;
606 // interpret wildcards
608 if (m_wildCard
.IsEmpty())
609 m_wildCard
= _("All files (*)|*");
611 wxStringTokenizer
tokens( m_wildCard
, wxT("|") );
613 wxString firstWildText
;
614 if (tokens
.CountTokens() == 1)
616 firstWildText
= tokens
.GetNextToken();
617 firstWild
= firstWildText
;
621 wxASSERT_MSG( tokens
.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
622 firstWildText
= tokens
.GetNextToken();
623 firstWild
= tokens
.GetNextToken();
628 wxBoxSizer
*mainsizer
= new wxBoxSizer( wxVERTICAL
);
630 wxBoxSizer
*buttonsizer
= new wxBoxSizer( wxHORIZONTAL
);
634 but
= new wxBitmapButton( this, ID_LIST_MODE
, wxBitmap( listview_xpm
) );
636 but
->SetToolTip( _("View files as a list view") );
638 buttonsizer
->Add( but
, 0, wxALL
, 5 );
640 but
= new wxBitmapButton( this, ID_REPORT_MODE
, wxBitmap( repview_xpm
) );
642 but
->SetToolTip( _("View files as a detailed view") );
644 buttonsizer
->Add( but
, 0, wxALL
, 5 );
646 buttonsizer
->Add( 30, 5, 1 );
648 but
= new wxBitmapButton( this, ID_UP_DIR
, wxBitmap( dir_up_xpm
) );
650 but
->SetToolTip( _("Go to parent directory") );
652 buttonsizer
->Add( but
, 0, wxALL
, 5 );
654 but
= new wxBitmapButton( this, ID_PARENT_DIR
, wxBitmap(home_xpm
) );
656 but
->SetToolTip( _("Go to home directory") );
658 buttonsizer
->Add( but
, 0, wxALL
, 5);
660 buttonsizer
->Add( 20, 20 );
662 but
= new wxBitmapButton( this, ID_NEW_DIR
, wxBitmap(new_dir_xpm
) );
664 but
->SetToolTip( _("Create new directory") );
666 buttonsizer
->Add( but
, 0, wxALL
, 5 );
668 mainsizer
->Add( buttonsizer
, 0, wxALL
| wxEXPAND
, 5 );
670 wxBoxSizer
*staticsizer
= new wxBoxSizer( wxHORIZONTAL
);
671 staticsizer
->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT
, 10 );
672 m_static
= new wxStaticText( this, -1, m_dir
);
673 staticsizer
->Add( m_static
, 1 );
674 mainsizer
->Add( staticsizer
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxBOTTOM
, 10 );
676 if (m_dialogStyle
& wxMULTIPLE
)
677 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
,
678 wxSize(440,180), wxLC_LIST
| wxSUNKEN_BORDER
);
680 m_list
= new wxFileCtrl( this, ID_LIST_CTRL
, m_dir
, firstWild
, wxDefaultPosition
,
681 wxSize(440,180), wxLC_LIST
| wxSUNKEN_BORDER
| wxLC_SINGLE_SEL
);
682 mainsizer
->Add( m_list
, 1, wxEXPAND
| wxLEFT
|wxRIGHT
, 10 );
684 wxBoxSizer
*textsizer
= new wxBoxSizer( wxHORIZONTAL
);
685 m_text
= new wxTextCtrl( this, ID_TEXT
, m_fileName
, wxDefaultPosition
, wxDefaultSize
, wxPROCESS_ENTER
);
686 textsizer
->Add( m_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
687 textsizer
->Add( new wxButton( this, wxID_OK
, _("OK") ), 0, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
688 mainsizer
->Add( textsizer
, 0, wxEXPAND
);
690 wxBoxSizer
*choicesizer
= new wxBoxSizer( wxHORIZONTAL
);
691 m_choice
= new wxChoice( this, ID_CHOICE
);
692 choicesizer
->Add( m_choice
, 1, wxCENTER
|wxALL
, 10 );
693 m_check
= new wxCheckBox( this, ID_CHECK
, _("Show hidden files") );
694 m_check
->SetValue( FALSE
);
695 choicesizer
->Add( m_check
, 0, wxCENTER
|wxALL
, 10 );
696 choicesizer
->Add( new wxButton( this, wxID_CANCEL
, _("Cancel") ), 0, wxCENTER
| wxALL
, 10 );
697 mainsizer
->Add( choicesizer
, 0, wxEXPAND
);
699 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
700 while (tokens
.HasMoreTokens())
702 firstWildText
= tokens
.GetNextToken();
703 firstWild
= tokens
.GetNextToken();
704 m_choice
->Append( firstWildText
, (void*) new wxString( firstWild
) );
706 m_choice
->SetSelection( 0 );
708 SetAutoLayout( TRUE
);
709 SetSizer( mainsizer
);
711 mainsizer
->Fit( this );
712 mainsizer
->SetSizeHints( this );
716 if (m_fileName
.IsEmpty())
724 wxFileDialog::~wxFileDialog()
728 void wxFileDialog::OnChoice( wxCommandEvent
&event
)
730 int index
= (int)event
.GetInt();
731 wxString
*str
= (wxString
*) m_choice
->GetClientData( index
);
732 m_list
->SetWild( *str
);
733 m_filterIndex
= index
;
736 void wxFileDialog::OnCheck( wxCommandEvent
&event
)
738 m_list
->ShowHidden( event
.GetInt() != 0 );
741 void wxFileDialog::OnActivated( wxListEvent
&event
)
743 HandleAction( event
.m_item
.m_text
);
746 void wxFileDialog::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
748 wxCommandEvent
cevent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_OK
);
749 cevent
.SetEventObject( this );
750 GetEventHandler()->ProcessEvent( cevent
);
753 void wxFileDialog::OnSelected( wxListEvent
&event
)
755 if (FindFocus() != m_list
) return;
757 wxString
filename( event
.m_item
.m_text
);
758 if (filename
== wxT("..")) return;
761 m_list
->GetDir( dir
);
762 if (dir
!= wxT("/")) dir
+= wxT("/");
764 if (wxDirExists(dir
)) return;
766 m_text
->SetValue( filename
);
769 void wxFileDialog::HandleAction( const wxString
&fn
)
771 wxString
filename( fn
);
773 m_list
->GetDir( dir
);
774 if (filename
.IsEmpty()) return;
775 if (filename
== wxT(".")) return;
777 if (filename
== wxT(".."))
779 m_list
->GoToParentDir();
781 m_list
->GetDir( dir
);
782 m_static
->SetLabel( dir
);
786 if (filename
== wxT("~"))
788 m_list
->GoToHomeDir();
790 m_list
->GetDir( dir
);
791 m_static
->SetLabel( dir
);
795 if (filename
[0] == wxT('~'))
797 filename
.Remove( 0, 1 );
798 wxString
tmp( wxGetUserHome() );
804 if ((filename
.Find(wxT('*')) != wxNOT_FOUND
) ||
805 (filename
.Find(wxT('?')) != wxNOT_FOUND
))
807 if (filename
.Find(wxT('/')) != wxNOT_FOUND
)
809 wxMessageBox(_("Illegal file specification."), _("Error"), wxOK
| wxICON_ERROR
);
812 m_list
->SetWild( filename
);
816 if (dir
!= wxT("/")) dir
+= wxT("/");
817 if (filename
[0] != wxT('/'))
823 if (wxDirExists(filename
))
825 m_list
->GoToDir( filename
);
826 m_list
->GetDir( dir
);
827 m_static
->SetLabel( dir
);
831 if ( (m_dialogStyle
& wxSAVE
) && (m_dialogStyle
& wxOVERWRITE_PROMPT
) )
833 if (wxFileExists( filename
))
836 msg
.Printf( _("File '%s' already exists, do you really want to "
837 "overwrite it?"), filename
.c_str() );
839 if (wxMessageBox(msg
, _("Confirm"), wxYES_NO
) != wxYES
)
843 else if ( (m_dialogStyle
& wxOPEN
) && (m_dialogStyle
& wxFILE_MUST_EXIST
) )
845 if ( !wxFileExists( filename
) )
847 wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK
| wxICON_ERROR
);
854 wxCommandEvent event
;
855 wxDialog::OnOK(event
);
858 void wxFileDialog::OnListOk( wxCommandEvent
&WXUNUSED(event
) )
860 HandleAction( m_text
->GetValue() );
863 void wxFileDialog::OnList( wxCommandEvent
&WXUNUSED(event
) )
865 m_list
->ChangeToListMode();
869 void wxFileDialog::OnReport( wxCommandEvent
&WXUNUSED(event
) )
871 m_list
->ChangeToReportMode();
875 void wxFileDialog::OnUp( wxCommandEvent
&WXUNUSED(event
) )
877 m_list
->GoToParentDir();
880 m_list
->GetDir( dir
);
881 m_static
->SetLabel( dir
);
884 void wxFileDialog::OnHome( wxCommandEvent
&WXUNUSED(event
) )
886 m_list
->GoToHomeDir();
889 m_list
->GetDir( dir
);
890 m_static
->SetLabel( dir
);
893 void wxFileDialog::OnNew( wxCommandEvent
&WXUNUSED(event
) )
898 void wxFileDialog::SetPath( const wxString
& path
)
900 // not only set the full path but also update filename and dir
905 wxSplitPath(path
, &m_dir
, &m_fileName
, &ext
);
908 m_fileName
+= wxT(".");
914 void wxFileDialog::GetPaths( wxArrayString
& paths
) const
917 if (m_list
->GetSelectedItemCount() == 0)
919 paths
.Add( GetPath() );
923 paths
.Alloc( m_list
->GetSelectedItemCount() );
926 m_list
->GetDir( dir
);
927 if (dir
!= wxT("/")) dir
+= wxT("/");
930 item
.m_mask
= wxLIST_MASK_TEXT
;
932 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
933 while ( item
.m_itemId
!= -1 ) {
934 m_list
->GetItem( item
);
935 paths
.Add( dir
+ item
.m_text
);
936 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
+ 1,
937 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
941 void wxFileDialog::GetFilenames(wxArrayString
& files
) const
944 if (m_list
->GetSelectedItemCount() == 0)
946 files
.Add( GetFilename() );
949 files
.Alloc( m_list
->GetSelectedItemCount() );
952 item
.m_mask
= wxLIST_MASK_TEXT
;
954 item
.m_itemId
= m_list
->GetNextItem( -1, wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
955 while ( item
.m_itemId
!= -1 ) {
956 m_list
->GetItem( item
);
957 files
.Add( item
.m_text
);
958 item
.m_itemId
= m_list
->GetNextItem( item
.m_itemId
+ 1,
959 wxLIST_NEXT_ALL
, wxLIST_STATE_SELECTED
);
963 // ----------------------------------------------------------------------------
965 // ----------------------------------------------------------------------------
968 wxFileSelectorEx(const wxChar
*message
,
969 const wxChar
*default_path
,
970 const wxChar
*default_filename
,
971 int *WXUNUSED(indexDefaultExtension
),
972 const wxChar
*wildcard
,
977 // TODO: implement this somehow
978 return wxFileSelector(message
, default_path
, default_filename
, wxT(""),
979 wildcard
, flags
, parent
, x
, y
);
982 wxString
wxFileSelector( const wxChar
*title
,
983 const wxChar
*defaultDir
, const wxChar
*defaultFileName
,
984 const wxChar
*defaultExtension
, const wxChar
*filter
, int flags
,
985 wxWindow
*parent
, int x
, int y
)
988 if ( defaultExtension
&& !filter
)
989 filter2
= wxString(wxT("*.")) + wxString(defaultExtension
) ;
993 wxString defaultDirString
;
995 defaultDirString
= defaultDir
;
997 wxString defaultFilenameString
;
999 defaultFilenameString
= defaultFileName
;
1001 wxFileDialog
fileDialog( parent
, title
, defaultDirString
, defaultFilenameString
, filter2
, flags
, wxPoint(x
, y
) );
1003 if ( fileDialog
.ShowModal() == wxID_OK
)
1005 return fileDialog
.GetPath();
1009 return wxEmptyString
;
1013 wxString
wxLoadFileSelector( const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
, wxWindow
*parent
)
1015 wxChar
*ext
= (wxChar
*)extension
;
1018 wxString str
= _("Load %s file");
1019 wxSprintf(prompt
, str
, what
);
1021 if (*ext
== wxT('.')) ext
++;
1023 wxSprintf(wild
, wxT("*.%s"), ext
);
1025 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);
1028 wxString
wxSaveFileSelector(const wxChar
*what
, const wxChar
*extension
, const wxChar
*default_name
,
1031 wxChar
*ext
= (wxChar
*)extension
;
1034 wxString str
= _("Save %s file");
1035 wxSprintf(prompt
, str
, what
);
1037 if (*ext
== wxT('.')) ext
++;
1039 wxSprintf(wild
, wxT("*.%s"), ext
);
1041 return wxFileSelector (prompt
, (const wxChar
*) NULL
, default_name
, ext
, wild
, 0, parent
);