-void wxDirDialog::doSize()
-{
- /* Figure out height of DirCtrl, which is what is left over by
- * the textctrl and the buttons. Manually, because I can't seem
- * to get the constraints stuff to do this */
- int w,h,h2;
-
- GetClientSize(&w, &h);
- m_input->GetSize(&w,&h2); h -= h2;
- m_ok->GetSize(&w, &h2); h -= h2;
- //m_check->GetSize(&w, &h2); h -= h2;
- h -= 20;
-
- wxLayoutConstraints *c = new wxLayoutConstraints;
- c->left.SameAs (this, wxLeft,5);
- c->right.SameAs (this, wxRight,5);
- c->height.Absolute (h);
- c->top.SameAs (this, wxTop,5);
- m_dir->SetConstraints(c);
-
- c = new wxLayoutConstraints;
- c->left.SameAs (this, wxLeft,5);
- c->right.SameAs (this, wxRight,5);
- c->height.AsIs ();
- c->top.Below (m_dir,5);
- m_input->SetConstraints(c);
-
- /* c = new wxLayoutConstraints;
- c->left.SameAs (this, wxLeft,5);
- c->right.SameAs (this, wxRight,5);
- c->height.AsIs ();
- c->top.Below (m_input,5);
- m_check->SetConstraints(c); */
-
- c = new wxLayoutConstraints;
- c->width.SameAs (m_cancel, wxWidth);
- c->height.AsIs ();
- c->top.Below (m_input,5);
- c->centreX.PercentOf (this, wxWidth, 25);
- m_ok->SetConstraints(c);
-
- c = new wxLayoutConstraints;
- c->width.SameAs (m_cancel, wxWidth);
- c->height.AsIs ();
- c->top.Below (m_input,5);
- c->bottom.SameAs (this, wxBottom, 5);
- c->centreX.PercentOf (this, wxWidth, 50);
- m_new->SetConstraints(c);
-
- c = new wxLayoutConstraints;
- c->width.AsIs ();
- c->height.AsIs ();
- c->top.Below (m_input,5);
- c->centreX.PercentOf (this, wxWidth, 75);
- m_cancel->SetConstraints(c);
-
- Layout();
+ wxBeginBusyCursor();
+
+ wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+
+ // 1) dir ctrl
+ m_dir = new wxDirCtrl( this, ID_DIRCTRL, "/",
+ wxDefaultPosition,
+ wxSize(200,200),
+ wxTR_HAS_BUTTONS |
+ wxSUNKEN_BORDER |
+ wxTR_EDIT_LABELS );
+ topsizer->Add( m_dir, 1, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
+
+ // 2) text ctrl
+ m_input = new wxTextCtrl( this, ID_TEXTCTRL, m_path, wxDefaultPosition );
+ topsizer->Add( m_input, 0, wxTOP|wxLEFT|wxRIGHT | wxEXPAND, 10 );
+
+ // m_check = new wxCheckBox( this, ID_CHECK, _("Show hidden") );
+ // m_check->SetValue(TRUE);
+
+#if wxUSE_STATLINE
+ // 3) static line
+ topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
+#endif
+
+ // 4) buttons
+ wxSizer* buttonsizer = new wxBoxSizer( wxHORIZONTAL );
+ m_ok = new wxButton( this, ID_OK, _("OK") );
+ buttonsizer->Add( m_ok, 0, wxLEFT|wxRIGHT, 10 );
+ m_cancel = new wxButton( this, ID_CANCEL, _("Cancel") );
+ buttonsizer->Add( m_cancel, 0, wxLEFT|wxRIGHT, 10 );
+ m_new = new wxButton( this, ID_NEW, _("New...") );
+ buttonsizer->Add( m_new, 0, wxLEFT|wxRIGHT, 10 );
+
+ topsizer->Add( buttonsizer, 0, wxALL | wxCENTER, 10 );
+
+ m_ok->SetDefault();
+ m_dir->SetFocus();
+
+ SetAutoLayout( TRUE );
+ SetSizer( topsizer );
+
+ topsizer->SetSizeHints( this );
+ topsizer->Fit( this );
+
+ Centre( wxBOTH );
+
+ if (m_path == wxT("~"))
+ wxGetHomeDir( &m_path );
+
+ // choose the directory corresponding to defaultPath in the tree
+ // VZ: using wxStringTokenizer is probably unsafe here (escaped slashes
+ // will not be processed correctly...)
+ wxStringTokenizer tk(m_path, wxFILE_SEP_PATH, wxTOKEN_STRTOK);
+
+ wxString path;
+
+ long cookie = 0;
+ // default to root dir
+ wxTreeItemId item = m_dir->GetFirstChild(m_dir->GetRootItem(), cookie);
+
+ if (!m_path.IsEmpty() && (m_path != wxT("/")) && (m_dir->m_paths.Count() > 1))
+ {
+ size_t count = m_dir->m_paths.GetCount();
+ for ( size_t i=1; i<count; i++)
+ {
+ if (m_path.Find( m_dir->m_paths[i] ) == 0)
+ {
+ path = m_dir->m_paths[i];
+
+ for (size_t j = 0; j < i; j++)
+ item = m_dir->GetNextChild(m_dir->GetRootItem(), cookie);
+
+ wxStringTokenizer tk2(path, wxFILE_SEP_PATH, wxTOKEN_STRTOK);
+ for (size_t h = 0; h < tk2.CountTokens(); h++)
+ tk.GetNextToken();
+
+ break;
+ }
+ }
+ }
+ while ( tk.HasMoreTokens() && item.IsOk() )
+ {
+ path << wxFILE_SEP_PATH << tk.GetNextToken();
+
+ m_dir->Expand(item);
+
+ wxTreeItemId child = m_dir->GetFirstChild(item, cookie);
+ while ( child.IsOk() )
+ {
+ wxDirItemData *data = (wxDirItemData*)m_dir->GetItemData(child);
+ if ( data->m_path == path )
+ break;
+
+ child = m_dir->GetNextChild(item, cookie);
+ }
+
+ item = child;
+ }
+
+ if ( item.IsOk() )
+ {
+ m_dir->Expand(item);
+ m_dir->SelectItem(item);
+ m_dir->EnsureVisible(item);
+ }
+
+ wxEndBusyCursor();