]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 649590 ] fixes bug 611264: wxFileDialog entry
authorJulian Smart <julian@anthemion.co.uk>
Mon, 9 Dec 2002 10:44:13 +0000 (10:44 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Mon, 9 Dec 2002 10:44:13 +0000 (10:44 +0000)
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

include/wx/generic/filedlgg.h
src/generic/filedlgg.cpp

index 41e4ba171a51d22942d09a5928301f85c194c393..9dacc71243466e9e638716b013601fb76d158752 100644 (file)
@@ -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 );
index c542229e50cb79a75d140065a231155931a1e435..ba237ba999268b3f321b4943cd856ec28668545c 100644 (file)
@@ -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 )