From 94f171bf9735d12c17d7cfdab3b2420b433b6c66 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 1 Apr 2000 11:38:04 +0000 Subject: [PATCH] wxDirDialog now opens the right dir folder git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dirdlgg.h | 2 ++ src/generic/dirdlgg.cpp | 40 ++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/include/wx/generic/dirdlgg.h b/include/wx/generic/dirdlgg.h index f318065faf..53135f57bb 100644 --- a/include/wx/generic/dirdlgg.h +++ b/include/wx/generic/dirdlgg.h @@ -118,6 +118,8 @@ public: void OnEndEditItem(wxTreeEvent &event ); protected: + friend class wxDirDialog; + void CreateItems(const wxTreeItemId &parent); void SetupSections(); wxArrayString m_paths, m_names; diff --git a/src/generic/dirdlgg.cpp b/src/generic/dirdlgg.cpp index 012bd8d418..a2c34d054d 100644 --- a/src/generic/dirdlgg.cpp +++ b/src/generic/dirdlgg.cpp @@ -211,8 +211,8 @@ void wxDirCtrl::SetupSections() wxGetHomeDir(&home); ADD_SECTION(home, _("My Home") ) ADD_SECTION(wxT("/mnt"), _("Mounted Devices") ) - ADD_SECTION(wxT("/usr"), _("User") ) ADD_SECTION(wxT("/usr/local"), _("User Local") ) + ADD_SECTION(wxT("/usr"), _("User") ) ADD_SECTION(wxT("/var"), _("Variables") ) ADD_SECTION(wxT("/etc"), _("Etcetera") ) ADD_SECTION(wxT("/tmp"), _("Temporary") ) @@ -263,7 +263,7 @@ void wxDirCtrl::OnEndEditItem(wxTreeEvent &event) if ((event.GetLabel().IsEmpty()) || (event.GetLabel() == _(".")) || (event.GetLabel() == _("..")) || - (event.GetLabel().First( wxT("/") ) != wxNOT_FOUND)) + (event.GetLabel().First( wxT("/") ) != wxNOT_FOUND)) { wxMessageDialog dialog(this, _("Illegal directory name."), _("Error"), wxOK | wxICON_ERROR ); dialog.ShowModal(); @@ -439,18 +439,40 @@ wxDirDialog::wxDirDialog(wxWindow *parent, 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(defaultPath, wxFILE_SEP_PATH, wxTOKEN_STRTOK); - - // we start from "My Computer" section because we're not sure to find the - // path among the predefined ones - ideally, we'd first look there and - // then do what we do now, but I don't have time to do it right now (VZ) - long cookie; - wxTreeItemId item = m_dir->GetFirstChild(m_dir->GetRootItem(), cookie); + 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; im_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();