]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/filectrlg.cpp
Add buildbot configuration.
[wxWidgets.git] / src / generic / filectrlg.cpp
index 967221b7ee647715d19951a841e008cb2b3e5ad1..5427143e0121267ac1d39c42580bdc405979a05c 100644 (file)
@@ -224,7 +224,7 @@ void wxFileData::ReadData()
 
 #if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS))
     lstat( m_filePath.fn_str(), &buff );
-    m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
+    m_type |= S_ISLNK(buff.st_mode) ? is_link : 0;
 #else // no lstat()
     // only translate to file charset if we don't go by our
     // wxStat implementation
@@ -390,29 +390,27 @@ void wxFileData::MakeItem( wxListItem &item )
 }
 
 //-----------------------------------------------------------------------------
-//  wxFileList
+//  wxFileListCtrl
 //-----------------------------------------------------------------------------
 
-static bool ignoreChanges = false;
+IMPLEMENT_DYNAMIC_CLASS(wxFileListCtrl,wxListCtrl)
 
-IMPLEMENT_DYNAMIC_CLASS(wxFileList,wxListCtrl)
-
-BEGIN_EVENT_TABLE(wxFileList,wxListCtrl)
-    EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileList::OnListDeleteItem)
-    EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileList::OnListDeleteAllItems)
-    EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileList::OnListEndLabelEdit)
-    EVT_LIST_COL_CLICK(wxID_ANY, wxFileList::OnListColClick)
+BEGIN_EVENT_TABLE(wxFileListCtrl,wxListCtrl)
+    EVT_LIST_DELETE_ITEM(wxID_ANY, wxFileListCtrl::OnListDeleteItem)
+    EVT_LIST_DELETE_ALL_ITEMS(wxID_ANY, wxFileListCtrl::OnListDeleteAllItems)
+    EVT_LIST_END_LABEL_EDIT(wxID_ANY, wxFileListCtrl::OnListEndLabelEdit)
+    EVT_LIST_COL_CLICK(wxID_ANY, wxFileListCtrl::OnListColClick)
 END_EVENT_TABLE()
 
 
-wxFileList::wxFileList()
+wxFileListCtrl::wxFileListCtrl()
 {
     m_showHidden = false;
-    m_sort_foward = 1;
+    m_sort_forward = true;
     m_sort_field = wxFileData::FileList_Name;
 }
 
-wxFileList::wxFileList(wxWindow *win,
+wxFileListCtrl::wxFileListCtrl(wxWindow *win,
                        wxWindowID id,
                        const wxString& wild,
                        bool showHidden,
@@ -430,7 +428,7 @@ wxFileList::wxFileList(wxWindow *win,
 
     m_showHidden = showHidden;
 
-    m_sort_foward = 1;
+    m_sort_forward = true;
     m_sort_field = wxFileData::FileList_Name;
 
     m_dirName = wxT("*");
@@ -439,14 +437,14 @@ wxFileList::wxFileList(wxWindow *win,
         ChangeToReportMode();
 }
 
-void wxFileList::ChangeToListMode()
+void wxFileListCtrl::ChangeToListMode()
 {
     ClearAll();
     SetSingleStyle( wxLC_LIST );
     UpdateFiles();
 }
 
-void wxFileList::ChangeToReportMode()
+void wxFileListCtrl::ChangeToReportMode()
 {
     ClearAll();
     SetSingleStyle( wxLC_REPORT );
@@ -473,20 +471,20 @@ void wxFileList::ChangeToReportMode()
     UpdateFiles();
 }
 
-void wxFileList::ChangeToSmallIconMode()
+void wxFileListCtrl::ChangeToSmallIconMode()
 {
     ClearAll();
     SetSingleStyle( wxLC_SMALL_ICON );
     UpdateFiles();
 }
 
-void wxFileList::ShowHidden( bool show )
+void wxFileListCtrl::ShowHidden( bool show )
 {
     m_showHidden = show;
     UpdateFiles();
 }
 
-long wxFileList::Add( wxFileData *fd, wxListItem &item )
+long wxFileListCtrl::Add( wxFileData *fd, wxListItem &item )
 {
     long ret = -1;
     item.m_mask = wxLIST_MASK_TEXT + wxLIST_MASK_DATA + wxLIST_MASK_IMAGE;
@@ -505,7 +503,7 @@ long wxFileList::Add( wxFileData *fd, wxListItem &item )
     return ret;
 }
 
-void wxFileList::UpdateItem(const wxListItem &item)
+void wxFileListCtrl::UpdateItem(const wxListItem &item)
 {
     wxFileData *fd = (wxFileData*)GetItemData(item);
     wxCHECK_RET(fd, wxT("invalid filedata"));
@@ -522,7 +520,7 @@ void wxFileList::UpdateItem(const wxListItem &item)
     }
 }
 
-void wxFileList::UpdateFiles()
+void wxFileListCtrl::UpdateFiles()
 {
     // don't do anything before ShowModal() call which sets m_dirName
     if ( m_dirName == wxT("*") )
@@ -541,11 +539,23 @@ void wxFileList::UpdateFiles()
     {
         wxArrayString names, paths;
         wxArrayInt icons;
-        size_t n, count = wxGetAvailableDrives(paths, names, icons);
+        const size_t count = wxGetAvailableDrives(paths, names, icons);
 
-        for (n=0; n<count; n++)
+        for ( size_t n = 0; n < count; n++ )
         {
-            wxFileData *fd = new wxFileData(paths[n], names[n], wxFileData::is_drive, icons[n]);
+            // use paths[n] as the drive name too as our HandleAction() can't
+            // deal with the drive names (of the form "System (C:)") currently
+            // as it mistakenly treats them as file names
+            //
+            // it would be preferable to show names, and not paths, in the
+            // dialog just as the native dialog does but for this we must:
+            //  a) store the item type as item data and modify HandleAction()
+            //     to use it instead of wxDirExists() to check whether the item
+            //     is a directory
+            //  b) store the drives by their drive letters and not their
+            //     descriptions as otherwise it's pretty confusing to the user
+            wxFileData *fd = new wxFileData(paths[n], paths[n],
+                                            wxFileData::is_drive, icons[n]);
             if (Add(fd, item) != -1)
                 item.m_itemId++;
             else
@@ -626,10 +636,10 @@ void wxFileList::UpdateFiles()
         }
     }
 
-    SortItems(m_sort_field, m_sort_foward);
+    SortItems(m_sort_field, m_sort_forward);
 }
 
-void wxFileList::SetWild( const wxString &wild )
+void wxFileListCtrl::SetWild( const wxString &wild )
 {
     if (wild.Find(wxT('|')) != wxNOT_FOUND)
         return;
@@ -638,7 +648,7 @@ void wxFileList::SetWild( const wxString &wild )
     UpdateFiles();
 }
 
-void wxFileList::MakeDir()
+void wxFileListCtrl::MakeDir()
 {
     wxString new_name( _("NewName") );
     wxString path( m_dirName );
@@ -677,7 +687,7 @@ void wxFileList::MakeDir()
 
     if (id != -1)
     {
-        SortItems(m_sort_field, m_sort_foward);
+        SortItems(m_sort_field, m_sort_forward);
         id = FindItem( 0, wxPtrToUInt(fd) );
         EnsureVisible( id );
         EditLabel( id );
@@ -686,7 +696,7 @@ void wxFileList::MakeDir()
         delete fd;
 }
 
-void wxFileList::GoToParentDir()
+void wxFileListCtrl::GoToParentDir()
 {
     if (!IsTopMostDir(m_dirName))
     {
@@ -709,35 +719,31 @@ void wxFileList::GoToParentDir()
         long id = FindItem( 0, fname );
         if (id != wxNOT_FOUND)
         {
-            ignoreChanges = true;
             SetItemState( id, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
             EnsureVisible( id );
-            ignoreChanges = false;
         }
     }
 }
 
-void wxFileList::GoToHomeDir()
+void wxFileListCtrl::GoToHomeDir()
 {
     wxString s = wxGetUserHome( wxString() );
     GoToDir(s);
 }
 
-void wxFileList::GoToDir( const wxString &dir )
+void wxFileListCtrl::GoToDir( const wxString &dir )
 {
     if (!wxDirExists(dir)) return;
 
     m_dirName = dir;
     UpdateFiles();
 
-    ignoreChanges = true;
     SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
-    ignoreChanges = false;
 
     EnsureVisible( 0 );
 }
 
-void wxFileList::FreeItemData(wxListItem& item)
+void wxFileListCtrl::FreeItemData(wxListItem& item)
 {
     if ( item.m_data )
     {
@@ -748,17 +754,17 @@ void wxFileList::FreeItemData(wxListItem& item)
     }
 }
 
-void wxFileList::OnListDeleteItem( wxListEvent &event )
+void wxFileListCtrl::OnListDeleteItem( wxListEvent &event )
 {
     FreeItemData(event.m_item);
 }
 
-void wxFileList::OnListDeleteAllItems( wxListEvent & WXUNUSED(event) )
+void wxFileListCtrl::OnListDeleteAllItems( wxListEvent & WXUNUSED(event) )
 {
     FreeAllItemsData();
 }
 
-void wxFileList::FreeAllItemsData()
+void wxFileListCtrl::FreeAllItemsData()
 {
     wxListItem item;
     item.m_mask = wxLIST_MASK_DATA;
@@ -772,7 +778,7 @@ void wxFileList::FreeAllItemsData()
     }
 }
 
-void wxFileList::OnListEndLabelEdit( wxListEvent &event )
+void wxFileListCtrl::OnListEndLabelEdit( wxListEvent &event )
 {
     wxFileData *fd = (wxFileData*)event.m_item.m_data;
     wxASSERT( fd );
@@ -805,9 +811,7 @@ void wxFileList::OnListEndLabelEdit( wxListEvent &event )
     {
         fd->SetNewName( new_name, event.GetLabel() );
 
-        ignoreChanges = true;
         SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
-        ignoreChanges = false;
 
         UpdateItem( event.GetItem() );
         EnsureVisible( event.GetItem() );
@@ -820,7 +824,7 @@ void wxFileList::OnListEndLabelEdit( wxListEvent &event )
     }
 }
 
-void wxFileList::OnListColClick( wxListEvent &event )
+void wxFileListCtrl::OnListColClick( wxListEvent &event )
 {
     int col = event.GetColumn();
 
@@ -834,17 +838,17 @@ void wxFileList::OnListColClick( wxListEvent &event )
     }
 
     if ((wxFileData::fileListFieldType)col == m_sort_field)
-        m_sort_foward = !m_sort_foward;
+        m_sort_forward = !m_sort_forward;
     else
         m_sort_field = (wxFileData::fileListFieldType)col;
 
-    SortItems(m_sort_field, m_sort_foward);
+    SortItems(m_sort_field, m_sort_forward);
 }
 
-void wxFileList::SortItems(wxFileData::fileListFieldType field, bool forward)
+void wxFileListCtrl::SortItems(wxFileData::fileListFieldType field, bool forward)
 {
     m_sort_field = field;
-    m_sort_foward = forward;
+    m_sort_forward = forward;
     const long sort_dir = forward ? 1 : -1;
 
     switch (m_sort_field)
@@ -868,11 +872,11 @@ void wxFileList::SortItems(wxFileData::fileListFieldType field, bool forward)
     }
 }
 
-wxFileList::~wxFileList()
+wxFileListCtrl::~wxFileListCtrl()
 {
     // Normally the data are freed via an EVT_LIST_DELETE_ALL_ITEMS event and
-    // wxFileList::OnListDeleteAllItems. But if the event is generated after
-    // the destruction of the wxFileList we need to free any data here:
+    // wxFileListCtrl::OnListDeleteAllItems. But if the event is generated after
+    // the destruction of the wxFileListCtrl we need to free any data here:
     FreeAllItemsData();
 }
 
@@ -959,10 +963,10 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
     style2 |= wxSUNKEN_BORDER;
 #endif
 
-    m_list = new wxFileList( this, ID_FILELIST_CTRL,
-                             wxEmptyString, false,
-                             wxDefaultPosition, wxSize( 400, 140 ),
-                             style2 );
+    m_list = new wxFileListCtrl( this, ID_FILELIST_CTRL,
+                                 wxEmptyString, false,
+                                 wxDefaultPosition, wxSize( 400, 140 ),
+                                 style2 );
 
     m_text = new wxTextCtrl( this, ID_TEXT, wxEmptyString,
                              wxDefaultPosition, wxDefaultSize,