fixed more bugs in SetDirectory/Path/Filename() and centralized m_static update code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17418 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -140,6 +140,7 @@ class wxFileCtrl : public wxListCtrl
|
|||||||
public:
|
public:
|
||||||
wxFileCtrl();
|
wxFileCtrl();
|
||||||
wxFileCtrl( wxWindow *win,
|
wxFileCtrl( wxWindow *win,
|
||||||
|
wxStaticText *labelDir,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString &wild,
|
const wxString &wild,
|
||||||
bool showHidden,
|
bool showHidden,
|
||||||
@@ -183,6 +184,9 @@ private:
|
|||||||
wxWindow *m_goToParentControl;
|
wxWindow *m_goToParentControl;
|
||||||
wxWindow *m_newDirControl;
|
wxWindow *m_newDirControl;
|
||||||
|
|
||||||
|
// the label showing the current directory
|
||||||
|
wxStaticText *m_labelDir;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileCtrl);
|
DECLARE_DYNAMIC_CLASS(wxFileCtrl);
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
@@ -605,6 +609,7 @@ wxFileCtrl::wxFileCtrl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxFileCtrl::wxFileCtrl(wxWindow *win,
|
wxFileCtrl::wxFileCtrl(wxWindow *win,
|
||||||
|
wxStaticText *labelDir,
|
||||||
wxWindowID id,
|
wxWindowID id,
|
||||||
const wxString& wild,
|
const wxString& wild,
|
||||||
bool showHidden,
|
bool showHidden,
|
||||||
@@ -625,6 +630,8 @@ wxFileCtrl::wxFileCtrl(wxWindow *win,
|
|||||||
m_goToParentControl =
|
m_goToParentControl =
|
||||||
m_newDirControl = NULL;
|
m_newDirControl = NULL;
|
||||||
|
|
||||||
|
m_labelDir = labelDir;
|
||||||
|
|
||||||
m_showHidden = showHidden;
|
m_showHidden = showHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -886,6 +893,8 @@ void wxFileCtrl::GoToDir( const wxString &dir )
|
|||||||
UpdateFiles();
|
UpdateFiles();
|
||||||
SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
SetItemState( 0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
||||||
EnsureVisible( 0 );
|
EnsureVisible( 0 );
|
||||||
|
|
||||||
|
m_labelDir->SetLabel(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileCtrl::GetDir( wxString &dir )
|
void wxFileCtrl::GetDir( wxString &dir )
|
||||||
@@ -1065,7 +1074,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
}
|
}
|
||||||
if ( firstWild.Left( 2 ) == wxT("*.") )
|
if ( firstWild.Left( 2 ) == wxT("*.") )
|
||||||
m_filterExtension = firstWild.Mid( 1 );
|
m_filterExtension = firstWild.Mid( 1 );
|
||||||
if ( m_filterExtension == ".*" ) m_filterExtension = wxEmptyString;
|
if ( m_filterExtension == ".*" )
|
||||||
|
m_filterExtension = wxEmptyString;
|
||||||
|
|
||||||
// layout
|
// layout
|
||||||
|
|
||||||
@@ -1136,7 +1146,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent,
|
|||||||
if ( !(m_dialogStyle & wxMULTIPLE) )
|
if ( !(m_dialogStyle & wxMULTIPLE) )
|
||||||
style2 |= wxLC_SINGLE_SEL;
|
style2 |= wxLC_SINGLE_SEL;
|
||||||
|
|
||||||
m_list = new wxFileCtrl( this, ID_LIST_CTRL, firstWild, ms_lastShowHidden,
|
m_list = new wxFileCtrl( this, m_static, ID_LIST_CTRL,
|
||||||
|
firstWild, ms_lastShowHidden,
|
||||||
wxDefaultPosition, wxSize(540,200),
|
wxDefaultPosition, wxSize(540,200),
|
||||||
style2);
|
style2);
|
||||||
|
|
||||||
@@ -1221,6 +1232,7 @@ wxFileDialog::~wxFileDialog()
|
|||||||
int wxFileDialog::ShowModal()
|
int wxFileDialog::ShowModal()
|
||||||
{
|
{
|
||||||
m_list->GoToDir(m_dir);
|
m_list->GoToDir(m_dir);
|
||||||
|
m_text->SetValue(m_fileName);
|
||||||
|
|
||||||
return wxDialog::ShowModal();
|
return wxDialog::ShowModal();
|
||||||
}
|
}
|
||||||
@@ -1298,8 +1310,6 @@ void wxFileDialog::HandleAction( const wxString &fn )
|
|||||||
{
|
{
|
||||||
m_list->GoToParentDir();
|
m_list->GoToParentDir();
|
||||||
m_list->SetFocus();
|
m_list->SetFocus();
|
||||||
m_list->GetDir( dir );
|
|
||||||
m_static->SetLabel( dir );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1308,8 +1318,6 @@ void wxFileDialog::HandleAction( const wxString &fn )
|
|||||||
{
|
{
|
||||||
m_list->GoToHomeDir();
|
m_list->GoToHomeDir();
|
||||||
m_list->SetFocus();
|
m_list->SetFocus();
|
||||||
m_list->GetDir( dir );
|
|
||||||
m_static->SetLabel( dir );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1346,18 +1354,29 @@ void wxFileDialog::HandleAction( const wxString &fn )
|
|||||||
if (wxDirExists(filename))
|
if (wxDirExists(filename))
|
||||||
{
|
{
|
||||||
m_list->GoToDir( filename );
|
m_list->GoToDir( filename );
|
||||||
m_list->GetDir( dir );
|
|
||||||
m_static->SetLabel( dir );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// append the default extension to the filename if it doesn't have any
|
||||||
if ( (m_dialogStyle & wxSAVE) && (m_dialogStyle & wxOVERWRITE_PROMPT) )
|
//
|
||||||
|
// VZ: the logic of testing for !wxFileExists() only for the open file
|
||||||
|
// dialog is not entirely clear to me, why don't we allow saving to a
|
||||||
|
// file without extension as well?
|
||||||
|
if ( !(m_dialogStyle & wxOPEN) || !wxFileExists(filename) )
|
||||||
{
|
{
|
||||||
if (filename.Find( wxT('.') ) == wxNOT_FOUND ||
|
wxString ext;
|
||||||
filename.AfterLast( wxT('.') ).Find( wxFILE_SEP_PATH ) != wxNOT_FOUND)
|
wxSplitPath(filename, NULL, NULL, &ext);
|
||||||
filename << m_filterExtension;
|
if ( ext.empty() )
|
||||||
if (wxFileExists( filename ))
|
{
|
||||||
|
// append the first extension of the filter string
|
||||||
|
filename += m_filterExtension.BeforeFirst(_T(';'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check that the file [doesn't] exist if necessary
|
||||||
|
if ( (m_dialogStyle & wxSAVE) &&
|
||||||
|
(m_dialogStyle & wxOVERWRITE_PROMPT) &&
|
||||||
|
wxFileExists( filename ) )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.Printf( _("File '%s' already exists, do you really want to "
|
msg.Printf( _("File '%s' already exists, do you really want to "
|
||||||
@@ -1366,22 +1385,12 @@ void wxFileDialog::HandleAction( const wxString &fn )
|
|||||||
if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
|
if (wxMessageBox(msg, _("Confirm"), wxYES_NO) != wxYES)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
else if ( (m_dialogStyle & wxOPEN) &&
|
||||||
else if ( m_dialogStyle & wxOPEN )
|
(m_dialogStyle & wxFILE_MUST_EXIST) &&
|
||||||
|
!wxFileExists(filename) )
|
||||||
{
|
{
|
||||||
if ( !wxFileExists( filename ) )
|
wxMessageBox(_("Please choose an existing file."), _("Error"),
|
||||||
if (filename.Find( wxT('.') ) == wxNOT_FOUND ||
|
wxOK | wxICON_ERROR );
|
||||||
filename.AfterLast( wxT('.') ).Find( wxFILE_SEP_PATH ) != wxNOT_FOUND)
|
|
||||||
filename << m_filterExtension;
|
|
||||||
|
|
||||||
if ( m_dialogStyle & wxFILE_MUST_EXIST )
|
|
||||||
{
|
|
||||||
if ( !wxFileExists( filename ) )
|
|
||||||
{
|
|
||||||
wxMessageBox(_("Please choose an existing file."), _("Error"), wxOK | wxICON_ERROR );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPath( filename );
|
SetPath( filename );
|
||||||
@@ -1425,20 +1434,12 @@ void wxFileDialog::OnUp( wxCommandEvent &WXUNUSED(event) )
|
|||||||
{
|
{
|
||||||
m_list->GoToParentDir();
|
m_list->GoToParentDir();
|
||||||
m_list->SetFocus();
|
m_list->SetFocus();
|
||||||
wxString dir;
|
|
||||||
m_list->GetDir( dir );
|
|
||||||
m_static->SetLabel( dir );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) )
|
void wxFileDialog::OnHome( wxCommandEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
m_list->GoToHomeDir();
|
m_list->GoToHomeDir();
|
||||||
m_list->SetFocus();
|
m_list->SetFocus();
|
||||||
wxString dir;
|
|
||||||
m_list->GetDir( dir );
|
|
||||||
m_static->SetLabel( dir );
|
|
||||||
|
|
||||||
m_text->SetFocus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) )
|
void wxFileDialog::OnNew( wxCommandEvent &WXUNUSED(event) )
|
||||||
|
Reference in New Issue
Block a user