fix wxGenericFileDialog::Get{Path,Directory,Filename}() functions which were completely broken by wxFileCtrl patch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49058 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2007-10-05 23:54:40 +00:00
parent 2826ef0c63
commit 398eebb155
4 changed files with 70 additions and 70 deletions

View File

@ -17,6 +17,7 @@
#include "wx/panel.h"
#include "wx/listctrl.h"
#include "wx/filectrl.h"
#include "wx/filename.h"
class WXDLLIMPEXP_FWD_CORE wxCheckBox;
class WXDLLIMPEXP_FWD_CORE wxChoice;
@ -247,6 +248,12 @@ public:
void GoToParentDir();
void GoToHomeDir();
// get the directory currently shown in the control: this can be different
// from GetDirectory() if the user entered a full path (with a path other
// than the one currently shown in the control) in the text control
// manually
wxString GetShownDirectory() const { return m_list->GetDir(); }
wxFileListCtrl *GetFileList() { return m_list; }
void ChangeToReportMode() { m_list->ChangeToReportMode(); }
@ -264,9 +271,11 @@ private:
void DoSetFilterIndex( int filterindex );
void UpdateControls();
wxString DoGetFilename( const bool fullPath ) const;
// the first of these methods can only be used for the controls with single
// selection (i.e. without wxFC_MULTIPLE style), the second one in any case
wxFileName DoGetFileName() const;
void DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const;
wxString GetProperFileListDir() const;
int m_style;

View File

@ -61,13 +61,27 @@ public:
virtual ~wxGenericFileDialog();
virtual void SetMessage(const wxString& message) { SetTitle(message); }
virtual void SetPath(const wxString& path);
virtual void SetFilterIndex(int filterIndex);
virtual void SetWildcard(const wxString& wildCard);
virtual void SetPath(const wxString& path)
{ m_filectrl->SetPath(path); }
virtual void SetFilterIndex(int filterIndex)
{ m_filectrl->SetFilterIndex(filterIndex); }
virtual void SetWildcard(const wxString& wildCard)
{ m_filectrl->SetWildcard(wildCard); }
// for multiple file selection
virtual void GetPaths(wxArrayString& paths) const;
virtual void GetFilenames(wxArrayString& files) const;
virtual wxString GetPath() const
{ return m_filectrl->GetPath(); }
virtual void GetPaths(wxArrayString& paths) const
{ return m_filectrl->GetPaths(paths); }
virtual wxString GetDirectory() const
{ return m_filectrl->GetDirectory(); }
virtual wxString GetFilename() const
{ return m_filectrl->GetFilename(); }
virtual void GetFilenames(wxArrayString& files) const
{ return m_filectrl->GetFilenames(files); }
virtual wxString GetWildcard() const
{ return m_filectrl->GetWildcard(); }
virtual int GetFilterIndex() const
{ return m_filectrl->GetFilterIndex(); }
// implementation only from now on
// -------------------------------

View File

@ -28,7 +28,6 @@
#include "wx/filedlg.h"
#endif
#include "wx/filename.h"
#include "wx/clntdata.h"
#include "wx/file.h" // for wxS_IXXX constants only
#include "wx/generic/dirctrlg.h" // for wxFileIconsTable
@ -1031,34 +1030,61 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
return true;
}
// NB: there is an unfortunate mismatch between wxFileName and wxFileDialog
// method names but our GetDirectory() does correspond to wxFileName::
// GetPath() while our GetPath() is wxFileName::GetFullPath()
wxString wxGenericFileCtrl::GetPath() const
{
return DoGetFilename( true );
wxASSERT_MSG ( !(m_style & wxFC_MULTIPLE), "use GetPaths() instead" );
return DoGetFileName().GetFullPath();
}
wxString wxGenericFileCtrl::GetFilename() const
{
return DoGetFilename( false );
wxASSERT_MSG ( !(m_style & wxFC_MULTIPLE), "use GetFilenames() instead" );
return DoGetFileName().GetFullName();
}
wxString wxGenericFileCtrl::DoGetFilename( const bool fullPath ) const
wxString wxGenericFileCtrl::GetDirectory() const
{
wxASSERT_MSG( ( m_style & wxFC_MULTIPLE ) == 0,
wxT( "With controls that has wxFC_MULTIPLE style " )
wxT( "use GetFilenames/GetPaths to get all filenames/paths selected" ) );
// don't check for wxFC_MULTIPLE here, this one is probably safe to call in
// any case as it can be always taken to mean "current directory"
return DoGetFileName().GetPath();
}
const wxString value = m_text->GetValue();
wxFileName wxGenericFileCtrl::DoGetFileName() const
{
wxFileName fn;
if ( !value.empty() )
return value;
return fullPath ? ( GetProperFileListDir() + value ) : value;
wxString value = m_text->GetValue();
if ( value.empty() )
{
// nothing in the text control, get the selected file from the list
wxListItem item;
item.m_itemId = m_list->GetNextItem(-1, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
m_list->GetItem(item);
fn.Assign(m_list->GetDir(), item.m_text);
}
else // user entered the value
{
// the path can be either absolute or relative
fn.Assign(value);
if ( fn.IsRelative() )
fn.MakeAbsolute(m_list->GetDir());
}
return fn;
}
void wxGenericFileCtrl::DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const
{
filenames.Empty();
const wxString dir = GetProperFileListDir();
const wxString dir = m_list->GetDir();
const wxString value = m_text->GetValue();
if ( !value.empty() )
@ -1105,11 +1131,6 @@ bool wxGenericFileCtrl::SetDirectory( const wxString& dir )
return wxFileName( dir ).SameAs( m_list->GetDir() );
}
wxString wxGenericFileCtrl::GetDirectory() const
{
return m_list->GetDir();
}
bool wxGenericFileCtrl::SetFilename( const wxString& name )
{
const long item = m_list->FindItem( -1, name );
@ -1444,17 +1465,4 @@ void wxGenericFileCtrl::GoToHomeDir()
UpdateControls();
}
wxString wxGenericFileCtrl::GetProperFileListDir() const
{
wxString dir = m_list->GetDir();
#ifdef __UNIX__
if ( dir != wxT( "/" ) )
#elif defined(__WXWINCE__)
if ( dir != wxT( "/" ) && dir != wxT( "\\" ) )
#endif
dir += wxFILE_SEP_PATH;
return dir;
}
#endif // wxUSE_FILECTRL

View File

@ -198,9 +198,6 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
if ((len > 1) && (wxEndsWithPathSeparator(m_dir)))
m_dir.Remove( len-1, 1 );
m_path = m_dir;
m_path += wxFILE_SEP_PATH;
m_path += defaultFile;
m_filterExtension = wxEmptyString;
// layout
@ -350,16 +347,6 @@ bool wxGenericFileDialog::Show( bool show )
return wxDialog::Show( show );
}
void wxGenericFileDialog::SetWildcard(const wxString& wildCard)
{
m_filectrl->SetWildcard(wildCard);
}
void wxGenericFileDialog::SetFilterIndex( int filterindex )
{
m_filectrl->SetFilterIndex(filterindex);
}
void wxGenericFileDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
{
wxArrayString selectedFiles;
@ -413,30 +400,12 @@ void wxGenericFileDialog::OnFileActivated( wxFileCtrlEvent &WXUNUSED(event) )
OnOk( dummy );
}
void wxGenericFileDialog::SetPath( const wxString& path )
{
// not only set the full path but also update filename and dir
m_path = path;
m_filectrl->SetPath(path);
}
void wxGenericFileDialog::GetPaths( wxArrayString& paths ) const
{
m_filectrl->GetPaths(paths);
}
void wxGenericFileDialog::GetFilenames(wxArrayString& files) const
{
m_filectrl->GetFilenames(files);
}
void wxGenericFileDialog::OnUpdateButtonsUI(wxUpdateUIEvent& event)
{
// surprisingly, we can be called before m_filectrl is set in Create() as
// wxFileCtrl ctor itself can generate idle events, so we need this test
if ( m_filectrl )
event.Enable( !IsTopMostDir(m_filectrl->GetDirectory()) );
event.Enable( !IsTopMostDir(m_filectrl->GetShownDirectory()) );
}
#ifdef wxHAS_GENERIC_FILEDIALOG