Better behaviour on NT (no dialogs when searching drives)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7844 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2000-07-26 14:08:39 +00:00
parent 031dfec8d4
commit ad9cd15cb0

View File

@@ -288,6 +288,37 @@ static const int ID_CANCEL = 1003;
static const int ID_NEW = 1004; static const int ID_NEW = 1004;
//static const int ID_CHECK = 1005; //static const int ID_CHECK = 1005;
#ifdef __WXMSW__
static bool wxIsDriveAvailable(const wxString dirName)
{
#ifdef __WIN32__
UINT errorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
#endif
bool success = TRUE;
// Check if this is a root directory and if so,
// whether the drive is avaiable.
if (dirName.Len() == 3 && dirName[1] == wxT(':'))
{
wxString dirNameLower(dirName.Lower());
int currentDrive = _getdrive();
int thisDrive = (int) (dirNameLower[0] - 'a' + 1) ;
int err = _chdrive( thisDrive ) ;
_chdrive( currentDrive );
if (err == -1)
{
success = FALSE;
}
}
#ifdef __WIN32__
(void) SetErrorMode(errorMode);
#endif
return success;
}
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxDirItemDataEx // wxDirItemDataEx
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -319,7 +350,24 @@ void wxDirItemDataEx::SetNewDirName( wxString path )
bool wxDirItemDataEx::HasSubDirs() bool wxDirItemDataEx::HasSubDirs()
{ {
wxString search = m_path + wxT("/*"); if (m_path.IsEmpty())
return TRUE;
// On WIN32, must check if this volume is mounted or
// we get an error dialog for e.g. drive a:
#ifdef __WIN32__
if (!wxIsDriveAvailable(m_path))
return FALSE;
#endif
wxString search = m_path;
if (m_path.Last() != wxFILE_SEP_PATH)
{
search += wxString(wxFILE_SEP_PATH);
}
search += wxT("*");
wxLogNull log; wxLogNull log;
wxString path = wxFindFirstFile( search, wxDIR ); wxString path = wxFindFirstFile( search, wxDIR );
return (bool)(!path.IsNull()); return (bool)(!path.IsNull());
@@ -513,9 +561,6 @@ void wxGenericDirCtrl::SetupSections()
int drive; int drive;
int currentDrive; int currentDrive;
/* Save current drive. */
currentDrive = _getdrive();
/* If we can switch to the drive, it exists. */ /* If we can switch to the drive, it exists. */
for( drive = 1; drive <= 26; drive++ ) for( drive = 1; drive <= 26; drive++ )
{ {
@@ -523,15 +568,12 @@ void wxGenericDirCtrl::SetupSections()
path.Printf(wxT("%c:\\"), (char) (drive + 'a' - 1)); path.Printf(wxT("%c:\\"), (char) (drive + 'a' - 1));
name.Printf(wxT("(%c:)"), (char) (drive + 'a' - 1)); name.Printf(wxT("(%c:)"), (char) (drive + 'a' - 1));
if( !_chdrive( drive ) ) if (wxIsDriveAvailable(path))
{ {
AddSection(path, name); AddSection(path, name);
} }
} }
/* Restore original drive.*/
_chdrive( currentDrive );
#endif #endif
#else #else
@@ -581,7 +623,7 @@ void wxGenericDirCtrl::OnEndEditItem(wxTreeEvent &event)
wxASSERT( data ); wxASSERT( data );
wxString new_name( wxPathOnly( data->m_path ) ); wxString new_name( wxPathOnly( data->m_path ) );
new_name += wxT("/"); new_name += wxString(wxFILE_SEP_PATH);
new_name += event.GetLabel(); new_name += event.GetLabel();
wxLogNull log; wxLogNull log;
@@ -658,20 +700,12 @@ void wxGenericDirCtrl::ExpandDir(wxTreeItemId parentId)
#ifdef __WXMSW__ #ifdef __WXMSW__
// Check if this is a root directory and if so, // Check if this is a root directory and if so,
// whether the drive is avaiable. // whether the drive is avaiable.
if (dirName.Len() == 3 && dirName[1] == wxT(':')) if (!wxIsDriveAvailable(dirName))
{ {
int currentDrive = _getdrive(); data->m_isExpanded = FALSE;
int thisDrive = (int) (dirName[0] - 'a' + 1) ; wxMessageBox(wxT("Sorry, this drive is not available."));
int err = _chdrive( thisDrive ) ; return;
_chdrive( currentDrive ); }
if (err == -1)
{
data->m_isExpanded = FALSE;
wxMessageBox(wxT("Sorry, this drive is not available."));
return;
}
}
#endif #endif
// This may take a longish time. Go to busy cursor // This may take a longish time. Go to busy cursor