From: Julian Smart Date: Mon, 9 Dec 2002 10:44:13 +0000 (+0000) Subject: Applied patch [ 649590 ] fixes bug 611264: wxFileDialog entry X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/df4131711384a17b827ab4b964dbabc6af2aa5da Applied patch [ 649590 ] fixes bug 611264: wxFileDialog entry In bug 611264 I reported that typing a filename into a multiple selection file dialog failed. The file returned was "..". I discovered that this was because the previous directory folder came up automatically selected when the dialog was created. Then, I discovered a related bug. If any file or folder was selected, then that was the file which was returned regardless of what was typed in. To fix the problem I added an EVT_TEXT handler which deselects everything that is selected when the user types. The handler does not deselect anything unless the user actually types something. This patch implements the fix. John Skiff git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18144 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 41e4ba171a..9dacc71243 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -91,6 +91,7 @@ public: void OnNew( wxCommandEvent &event ); void OnChoiceFilter( wxCommandEvent &event ); void OnTextEnter( wxCommandEvent &event ); + void OnTextChange( wxCommandEvent &event ); void OnCheck( wxCommandEvent &event ); void HandleAction( const wxString &fn ); diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index c542229e50..ba237ba999 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -1005,6 +1005,7 @@ BEGIN_EVENT_TABLE(wxFileDialog,wxDialog) EVT_LIST_ITEM_ACTIVATED(ID_LIST_CTRL, wxFileDialog::OnActivated) EVT_CHOICE(ID_CHOICE,wxFileDialog::OnChoiceFilter) EVT_TEXT_ENTER(ID_TEXT,wxFileDialog::OnTextEnter) + EVT_TEXT(ID_TEXT,wxFileDialog::OnTextChange) EVT_CHECKBOX(ID_CHECK,wxFileDialog::OnCheck) END_EVENT_TABLE() @@ -1285,6 +1286,27 @@ void wxFileDialog::OnTextEnter( wxCommandEvent &WXUNUSED(event) ) GetEventHandler()->ProcessEvent( cevent ); } +static bool ignoreChanges = FALSE; + +void wxFileDialog::OnTextChange( wxCommandEvent &WXUNUSED(event) ) +{ + if (!ignoreChanges) + { + // Clear selections. Otherwise when the user types in a value they may + // not get the file whose name they typed. + if (m_list->GetSelectedItemCount() > 0) + { + long item = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, + wxLIST_STATE_SELECTED); + while ( item != -1 ) + { + m_list->SetItemState(item,0, wxLIST_STATE_SELECTED); + item = m_list->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + } + } + } +} + void wxFileDialog::OnSelected( wxListEvent &event ) { wxString filename( event.m_item.m_text ); @@ -1297,7 +1319,9 @@ void wxFileDialog::OnSelected( wxListEvent &event ) dir += filename; if (wxDirExists(dir)) return; + ignoreChanges = TRUE; m_text->SetValue( filename ); + ignoreChanges = FALSE; } void wxFileDialog::HandleAction( const wxString &fn )