+ return m_path;
+}
+
+int wxGenericDirDialog::ShowModal()
+{
+ //m_input->SetValue( m_path );
+ return wxDialog::ShowModal();
+}
+
+void wxGenericDirDialog::OnTreeSelected( wxTreeEvent &event )
+{
+ if (!m_dirCtrl)
+ return;
+
+ wxDirItemDataEx *data = (wxDirItemDataEx*)m_dirCtrl->GetTreeCtrl()->GetItemData(event.GetItem());
+ if (data)
+ m_input->SetValue( data->m_path );
+};
+
+void wxGenericDirDialog::OnTreeKeyDown( wxTreeEvent &WXUNUSED(event) )
+{
+ if (!m_dirCtrl)
+ return;
+
+ wxDirItemDataEx *data = (wxDirItemDataEx*)m_dirCtrl->GetTreeCtrl()->GetItemData(m_dirCtrl->GetTreeCtrl()->GetSelection());
+ if (data)
+ m_input->SetValue( data->m_path );
+};
+
+void wxGenericDirDialog::OnNew( wxCommandEvent& WXUNUSED(event) )
+{
+ wxTreeItemId id = m_dirCtrl->GetTreeCtrl()->GetSelection();
+ if ((id == m_dirCtrl->GetTreeCtrl()->GetRootItem()) ||
+ (m_dirCtrl->GetTreeCtrl()->GetParent(id) == m_dirCtrl->GetTreeCtrl()->GetRootItem()))
+ {
+ wxMessageDialog msg(this, _("You cannot add a new directory to this section."),
+ _("Create directory"), wxOK | wxICON_INFORMATION );
+ msg.ShowModal();
+ return;
+ }
+
+ wxTreeItemId parent = id ; // m_dirCtrl->GetTreeCtrl()->GetParent( id );
+ wxDirItemDataEx *data = (wxDirItemDataEx*)m_dirCtrl->GetTreeCtrl()->GetItemData( parent );
+ wxASSERT( data );
+
+ wxString new_name( wxT("NewName") );
+ wxString path( data->m_path );
+ if (path.Last() != wxFILE_SEP_PATH)
+ path += wxFILE_SEP_PATH;
+ path += new_name;
+ if (wxFileExists(path))
+ {
+ // try NewName0, NewName1 etc.
+ int i = 0;
+ do {
+ new_name = wxT("NewName");
+ wxString num;
+ num.Printf( wxT("%d"), i );
+ new_name += num;
+
+ path = data->m_path;
+ if (path.Last() != wxFILE_SEP_PATH)
+ path += wxFILE_SEP_PATH;
+ path += new_name;
+ i++;
+ } while (wxFileExists(path));
+ }
+
+ wxLogNull log;
+ if (!wxMkdir(path))
+ {
+ wxMessageDialog dialog(this, _("Operation not permitted."), _("Error"), wxOK | wxICON_ERROR );
+ dialog.ShowModal();
+ return;
+ }
+
+ wxDirItemDataEx *new_data = new wxDirItemDataEx( path, new_name, TRUE );
+
+ // TODO: THIS CODE DOESN'T WORK YET. We need to avoid duplication of the first child
+ // of the parent.
+ wxTreeItemId new_id = m_dirCtrl->GetTreeCtrl()->AppendItem( parent, new_name, 0, 0, new_data );
+ m_dirCtrl->GetTreeCtrl()->EnsureVisible( new_id );
+ m_dirCtrl->GetTreeCtrl()->EditLabel( new_id );