-void wxDirCtrl::CreateItems(const wxTreeItemId &parent)
-{
- wxTreeItemId id;
- wxDirItemData *dir_item;
-
-// wxASSERT(m_paths.Count() == m_names.Count()); ?
-
- size_t count = m_paths.GetCount();
- for ( size_t i=0; i<count; i++)
- {
- dir_item = new wxDirItemData(m_paths[i],m_names[i]);
-#ifdef __WXMSW__
- id = AppendItem( parent, m_names[i], -1, -1, dir_item);
-#else
- id = AppendItem( parent, m_names[i], 0, -1, dir_item);
- SetItemImage( id, 1, wxTreeItemIcon_Expanded );
-#endif
- if (dir_item->m_hasSubDirs) SetItemHasChildren(id);
- }
-}
-
-void wxDirCtrl::OnBeginEditItem(wxTreeEvent &event)
-{
- // don't rename the main entry "Sections"
- if (event.GetItem() == m_rootId)
- {
- event.Veto();
- return;
- }
-
- // don't rename the individual sections
- if (GetParent( event.GetItem() ) == m_rootId)
- {
- event.Veto();
- return;
- }
-}
-
-void wxDirCtrl::OnEndEditItem(wxTreeEvent &event)
-{
- if ((event.GetLabel().IsEmpty()) ||
- (event.GetLabel() == _(".")) ||
- (event.GetLabel() == _("..")) ||
- (event.GetLabel().First( wxT("/") ) != wxNOT_FOUND))
- {
- wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- return;
- }
-
- wxTreeItemId id = event.GetItem();
- wxDirItemData *data = (wxDirItemData*)GetItemData( id );
- wxASSERT( data );
-
- wxString new_name( wxPathOnly( data->m_path ) );
- new_name += wxT("/");
- new_name += event.GetLabel();
-
- wxLogNull log;
-
- if (wxFileExists(new_name))
- {
- wxMessageDialog dialog(this, _("File name exists already."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- }
-
- if (wxRenameFile(data->m_path,new_name))
- {
- data->SetNewDirName( new_name );
- }
- else
- {
- wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
- dialog.ShowModal();
- event.Veto();
- }
-}
-
-void wxDirCtrl::OnExpandItem(wxTreeEvent &event)
-{
- if (event.GetItem() == m_rootId)
- {
- SetupSections();
- CreateItems(m_rootId);
- return;
- }
-
- // This may take a longish time. Go to busy cursor
- wxBeginBusyCursor();