X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6daf794895df62114204499c0c1d54f902be189..0616b8382daeca5373484e5a22ec1f322c025c95:/src/generic/filedlgg.cpp diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index c7b18c9f42..6dfcb6a234 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -31,17 +31,19 @@ #include "wx/msgdlg.h" #include "wx/sizer.h" #include "wx/bmpbuttn.h" +#include "wx/tokenzr.h" #if wxUSE_TOOLTIPS #include "wx/tooltip.h" #endif -#include "sys/types.h" -#include "sys/stat.h" -#include "dirent.h" -#include "pwd.h" -#include "grp.h" -#include "time.h" +#include +#include +#include +#include +#include +#include +#include #include "wx/generic/home.xpm" #include "wx/generic/listview.xpm" @@ -344,8 +346,8 @@ void wxFileCtrl::Update() item.m_itemId++; } - wxString res = m_dirName + _T("/") + m_wild; - wxString f( wxFindFirstFile( res.GetData(), 0 ) ); + wxString res = m_dirName + _T("/*"); + wxString f( wxFindFirstFile( res.GetData(), wxDIR ) ); while (!f.IsEmpty()) { res = wxFileNameFromPath( f ); @@ -358,6 +360,22 @@ void wxFileCtrl::Update() } f = wxFindNextFile(); } + + res = m_dirName + _T("/") + m_wild; + f = wxFindFirstFile( res.GetData(), wxFILE ); + while (!f.IsEmpty()) + { + res = wxFileNameFromPath( f ); + fd = new wxFileData( res, f ); + wxString s = fd->GetName(); + if (m_showHidden || (s[0] != _T('.'))) + { + Add( fd, item ); + item.m_itemId++; + } + f = wxFindNextFile(); + } + SortItems( ListCompare, 0 ); } @@ -505,12 +523,15 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) // wxFileDialog //----------------------------------------------------------------------------- -#define ID_LIST_CTRL 5010 -#define ID_LIST_MODE 5000 -#define ID_REPORT_MODE 5001 -#define ID_UP_DIR 5005 -#define ID_PARENT_DIR 5006 -#define ID_NEW_DIR 5007 +#define ID_LIST_MODE wxID_FILEDLGG +#define ID_REPORT_MODE wxID_FILEDLGG + 1 +#define ID_UP_DIR wxID_FILEDLGG + 5 +#define ID_PARENT_DIR wxID_FILEDLGG + 6 +#define ID_NEW_DIR wxID_FILEDLGG + 7 +#define ID_CHOICE wxID_FILEDLGG + 8 +#define ID_TEXT wxID_FILEDLGG + 9 +#define ID_LIST_CTRL wxID_FILEDLGG + 10 +#define ID_ACTIVATED wxID_FILEDLGG + 11 IMPLEMENT_DYNAMIC_CLASS(wxFileDialog,wxDialog) @@ -523,6 +544,8 @@ BEGIN_EVENT_TABLE(wxFileDialog,wxDialog) EVT_BUTTON(wxID_OK, wxFileDialog::OnListOk) EVT_LIST_ITEM_SELECTED(ID_LIST_CTRL, wxFileDialog::OnSelected) EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated) + EVT_CHOICE(ID_CHOICE,wxFileDialog::OnChoice) + EVT_TEXT_ENTER(ID_TEXT,wxFileDialog::OnTextEnter) END_EVENT_TABLE() wxFileDialog::wxFileDialog(wxWindow *parent, @@ -532,14 +555,18 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& wildCard, long style, const wxPoint& pos ) : - wxDialog( parent, -1, message, pos, wxDefaultSize, style | wxRESIZE_BORDER ) + wxDialog( parent, -1, message, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ) { wxBeginBusyCursor(); m_message = message; m_dialogStyle = style; m_dir = defaultDir; - if (m_dir.IsEmpty()) m_dir = wxGetUserHome(); + if (m_dir.IsEmpty()) + { + char buf[200]; + m_dir = getcwd( buf, sizeof(buf) ); + } m_path = defaultDir; m_path += _T("/"); m_path += defaultFile; @@ -547,6 +574,28 @@ wxFileDialog::wxFileDialog(wxWindow *parent, m_wildCard = wildCard; m_filterIndex = 0; + // interpret wildcards + + if (m_wildCard.IsEmpty()) + m_wildCard = _("All files (*)|*"); + + wxStringTokenizer tokens( m_wildCard, _T("|") ); + wxString firstWild; + wxString firstWildText; + if (tokens.CountTokens() == 1) + { + firstWildText = tokens.GetNextToken(); + firstWild = firstWildText; + } + else + { + wxASSERT_MSG( tokens.CountTokens() % 2 == 0, _T("Wrong file type descripition") ); + firstWildText = tokens.GetNextToken(); + firstWild = tokens.GetNextToken(); + } + + // layout + wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer *buttonsizer = new wxBoxSizer( wxHORIZONTAL ); @@ -589,22 +638,36 @@ wxFileDialog::wxFileDialog(wxWindow *parent, mainsizer->Add( buttonsizer, 0, wxALL | wxEXPAND, 5 ); - m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, "*", wxDefaultPosition, wxSize(440,180), + wxBoxSizer *staticsizer = new wxBoxSizer( wxHORIZONTAL ); + staticsizer->Add( new wxStaticText( this, -1, _("Current directory:") ), 0, wxRIGHT, 10 ); + m_static = new wxStaticText( this, -1, m_dir ); + staticsizer->Add( m_static, 1 ); + mainsizer->Add( staticsizer, 0, wxEXPAND | wxLEFT|wxRIGHT|wxBOTTOM, 10 ); + + m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition, wxSize(440,180), wxLC_LIST | wxSUNKEN_BORDER | wxLC_SINGLE_SEL ); mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 ); wxBoxSizer *textsizer = new wxBoxSizer( wxHORIZONTAL ); - m_text = new wxTextCtrl( this, -1, m_fileName ); + m_text = new wxTextCtrl( this, ID_TEXT, m_fileName, wxDefaultPosition, wxDefaultSize, wxPROCESS_ENTER ); textsizer->Add( m_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); textsizer->Add( new wxButton( this, wxID_OK, _("OK") ), 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); mainsizer->Add( textsizer, 0, wxEXPAND ); wxBoxSizer *choicesizer = new wxBoxSizer( wxHORIZONTAL ); - m_choice = new wxChoice( this, -1 ); - m_choice->Append( "*.txt" ); + m_choice = new wxChoice( this, ID_CHOICE ); choicesizer->Add( m_choice, 1, wxCENTER|wxALL, 10 ); choicesizer->Add( new wxButton( this, wxID_CANCEL, _("Cancel") ), 0, wxCENTER | wxALL, 10 ); mainsizer->Add( choicesizer, 0, wxEXPAND ); + + m_choice->Append( firstWildText, (void*) new wxString( firstWild ) ); + while (tokens.HasMoreTokens()) + { + firstWildText = tokens.GetNextToken(); + firstWild = tokens.GetNextToken(); + m_choice->Append( firstWildText, (void*) new wxString( firstWild ) ); + } + m_choice->SetSelection( 0 ); SetAutoLayout( TRUE ); SetSizer( mainsizer ); @@ -613,12 +676,25 @@ wxFileDialog::wxFileDialog(wxWindow *parent, mainsizer->SetSizeHints( this ); Centre( wxBOTH ); - - m_list->SetFocus(); + + if (m_fileName.IsEmpty()) + m_list->SetFocus(); + else + m_text->SetFocus(); wxEndBusyCursor(); } +wxFileDialog::~wxFileDialog() +{ +} + +void wxFileDialog::OnChoice( wxCommandEvent &event ) +{ + wxString *str = (wxString*) m_choice->GetClientData( event.GetInt() ); + m_list->SetWild( *str ); +} + void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) ) { wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); @@ -626,9 +702,17 @@ void wxFileDialog::OnActivated( wxListEvent &WXUNUSED(event) ) GetEventHandler()->ProcessEvent( cevent ); } +void wxFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) ) +{ + wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); + cevent.SetEventObject( this ); + GetEventHandler()->ProcessEvent( cevent ); +} + void wxFileDialog::OnSelected( wxListEvent &event ) { - m_text->SetValue( event.m_item.m_text ); + if (FindFocus() == m_list) + m_text->SetValue( event.m_item.m_text ); } void wxFileDialog::OnListOk( wxCommandEvent &event ) @@ -637,22 +721,63 @@ void wxFileDialog::OnListOk( wxCommandEvent &event ) wxString dir; m_list->GetDir( dir ); if (filename.IsEmpty()) return; + if (filename == _T(".")) return; if (filename == _T("..")) { m_list->GoToParentDir(); m_list->SetFocus(); + m_list->GetDir( dir ); + m_static->SetLabel( dir ); + return; + } + + if (filename == _T("~")) + { + m_list->GoToHomeDir(); + m_list->SetFocus(); + m_list->GetDir( dir ); + m_static->SetLabel( dir ); + return; + } + + if (filename[0] == _T('~')) + { + filename.Remove( 0, 1 ); + wxString tmp( wxGetUserHome() ); + tmp += _T('/'); + tmp += filename; + filename = tmp; + } + + if ((filename.Find(_T('*')) != wxNOT_FOUND) || + (filename.Find(_T('?')) != wxNOT_FOUND)) + { + if (filename.Find(_T('/')) != wxNOT_FOUND) + { + wxMessageBox(_("Illegal file specification."), _("Error"), wxOK | wxICON_ERROR ); + return; + } + m_list->SetWild( filename ); return; } if (dir != _T("/")) dir += _T("/"); - dir += filename; - filename = dir; + if (filename[0] != _T('/')) + { + dir += filename; + filename = dir; + } if (wxDirExists(filename)) { m_list->GoToDir( filename ); - m_text->SetValue( _T("") ); + if (filename == _T("/")) + m_text->SetValue( _T("") ); + else + m_text->SetValue( _T("..") ); + m_list->GetDir( dir ); + m_static->SetLabel( dir ); return; } @@ -672,8 +797,7 @@ void wxFileDialog::OnListOk( wxCommandEvent &event ) { if ( !wxFileExists( filename ) ) { - wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK); - + wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK | wxICON_ERROR ); return; } } @@ -698,12 +822,18 @@ void wxFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) ) { m_list->GoToParentDir(); m_list->SetFocus(); + wxString dir; + m_list->GetDir( dir ); + m_static->SetLabel( dir ); } void wxFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) ) { m_list->GoToHomeDir(); m_list->SetFocus(); + wxString dir; + m_list->GetDir( dir ); + m_static->SetLabel( dir ); } void wxFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) )