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:
@@ -17,6 +17,7 @@
|
|||||||
#include "wx/panel.h"
|
#include "wx/panel.h"
|
||||||
#include "wx/listctrl.h"
|
#include "wx/listctrl.h"
|
||||||
#include "wx/filectrl.h"
|
#include "wx/filectrl.h"
|
||||||
|
#include "wx/filename.h"
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxCheckBox;
|
class WXDLLIMPEXP_FWD_CORE wxCheckBox;
|
||||||
class WXDLLIMPEXP_FWD_CORE wxChoice;
|
class WXDLLIMPEXP_FWD_CORE wxChoice;
|
||||||
@@ -247,6 +248,12 @@ public:
|
|||||||
void GoToParentDir();
|
void GoToParentDir();
|
||||||
void GoToHomeDir();
|
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; }
|
wxFileListCtrl *GetFileList() { return m_list; }
|
||||||
|
|
||||||
void ChangeToReportMode() { m_list->ChangeToReportMode(); }
|
void ChangeToReportMode() { m_list->ChangeToReportMode(); }
|
||||||
@@ -264,9 +271,11 @@ private:
|
|||||||
|
|
||||||
void DoSetFilterIndex( int filterindex );
|
void DoSetFilterIndex( int filterindex );
|
||||||
void UpdateControls();
|
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;
|
void DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const;
|
||||||
wxString GetProperFileListDir() const;
|
|
||||||
|
|
||||||
int m_style;
|
int m_style;
|
||||||
|
|
||||||
|
@@ -61,13 +61,27 @@ public:
|
|||||||
virtual ~wxGenericFileDialog();
|
virtual ~wxGenericFileDialog();
|
||||||
|
|
||||||
virtual void SetMessage(const wxString& message) { SetTitle(message); }
|
virtual void SetMessage(const wxString& message) { SetTitle(message); }
|
||||||
virtual void SetPath(const wxString& path);
|
virtual void SetPath(const wxString& path)
|
||||||
virtual void SetFilterIndex(int filterIndex);
|
{ m_filectrl->SetPath(path); }
|
||||||
virtual void SetWildcard(const wxString& wildCard);
|
virtual void SetFilterIndex(int filterIndex)
|
||||||
|
{ m_filectrl->SetFilterIndex(filterIndex); }
|
||||||
|
virtual void SetWildcard(const wxString& wildCard)
|
||||||
|
{ m_filectrl->SetWildcard(wildCard); }
|
||||||
|
|
||||||
// for multiple file selection
|
virtual wxString GetPath() const
|
||||||
virtual void GetPaths(wxArrayString& paths) const;
|
{ return m_filectrl->GetPath(); }
|
||||||
virtual void GetFilenames(wxArrayString& files) const;
|
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
|
// implementation only from now on
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
@@ -28,7 +28,6 @@
|
|||||||
#include "wx/filedlg.h"
|
#include "wx/filedlg.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/filename.h"
|
|
||||||
#include "wx/clntdata.h"
|
#include "wx/clntdata.h"
|
||||||
#include "wx/file.h" // for wxS_IXXX constants only
|
#include "wx/file.h" // for wxS_IXXX constants only
|
||||||
#include "wx/generic/dirctrlg.h" // for wxFileIconsTable
|
#include "wx/generic/dirctrlg.h" // for wxFileIconsTable
|
||||||
@@ -1031,34 +1030,61 @@ bool wxGenericFileCtrl::Create( wxWindow *parent,
|
|||||||
return true;
|
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
|
wxString wxGenericFileCtrl::GetPath() const
|
||||||
{
|
{
|
||||||
return DoGetFilename( true );
|
wxASSERT_MSG ( !(m_style & wxFC_MULTIPLE), "use GetPaths() instead" );
|
||||||
|
|
||||||
|
return DoGetFileName().GetFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxGenericFileCtrl::GetFilename() const
|
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,
|
// don't check for wxFC_MULTIPLE here, this one is probably safe to call in
|
||||||
wxT( "With controls that has wxFC_MULTIPLE style " )
|
// any case as it can be always taken to mean "current directory"
|
||||||
wxT( "use GetFilenames/GetPaths to get all filenames/paths selected" ) );
|
return DoGetFileName().GetPath();
|
||||||
|
}
|
||||||
|
|
||||||
const wxString value = m_text->GetValue();
|
wxFileName wxGenericFileCtrl::DoGetFileName() const
|
||||||
|
{
|
||||||
|
wxFileName fn;
|
||||||
|
|
||||||
if ( !value.empty() )
|
wxString value = m_text->GetValue();
|
||||||
return value;
|
if ( value.empty() )
|
||||||
return fullPath ? ( GetProperFileListDir() + value ) : value;
|
{
|
||||||
|
// 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
|
void wxGenericFileCtrl::DoGetFilenames( wxArrayString& filenames, const bool fullPath ) const
|
||||||
{
|
{
|
||||||
filenames.Empty();
|
filenames.Empty();
|
||||||
|
|
||||||
const wxString dir = GetProperFileListDir();
|
const wxString dir = m_list->GetDir();
|
||||||
const wxString value = m_text->GetValue();
|
const wxString value = m_text->GetValue();
|
||||||
|
|
||||||
if ( !value.empty() )
|
if ( !value.empty() )
|
||||||
@@ -1105,11 +1131,6 @@ bool wxGenericFileCtrl::SetDirectory( const wxString& dir )
|
|||||||
return wxFileName( dir ).SameAs( m_list->GetDir() );
|
return wxFileName( dir ).SameAs( m_list->GetDir() );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxGenericFileCtrl::GetDirectory() const
|
|
||||||
{
|
|
||||||
return m_list->GetDir();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
||||||
{
|
{
|
||||||
const long item = m_list->FindItem( -1, name );
|
const long item = m_list->FindItem( -1, name );
|
||||||
@@ -1444,17 +1465,4 @@ void wxGenericFileCtrl::GoToHomeDir()
|
|||||||
UpdateControls();
|
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
|
#endif // wxUSE_FILECTRL
|
||||||
|
@@ -198,9 +198,6 @@ bool wxGenericFileDialog::Create( wxWindow *parent,
|
|||||||
if ((len > 1) && (wxEndsWithPathSeparator(m_dir)))
|
if ((len > 1) && (wxEndsWithPathSeparator(m_dir)))
|
||||||
m_dir.Remove( len-1, 1 );
|
m_dir.Remove( len-1, 1 );
|
||||||
|
|
||||||
m_path = m_dir;
|
|
||||||
m_path += wxFILE_SEP_PATH;
|
|
||||||
m_path += defaultFile;
|
|
||||||
m_filterExtension = wxEmptyString;
|
m_filterExtension = wxEmptyString;
|
||||||
|
|
||||||
// layout
|
// layout
|
||||||
@@ -350,16 +347,6 @@ bool wxGenericFileDialog::Show( bool show )
|
|||||||
return wxDialog::Show( 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) )
|
void wxGenericFileDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxArrayString selectedFiles;
|
wxArrayString selectedFiles;
|
||||||
@@ -413,30 +400,12 @@ void wxGenericFileDialog::OnFileActivated( wxFileCtrlEvent &WXUNUSED(event) )
|
|||||||
OnOk( dummy );
|
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)
|
void wxGenericFileDialog::OnUpdateButtonsUI(wxUpdateUIEvent& event)
|
||||||
{
|
{
|
||||||
// surprisingly, we can be called before m_filectrl is set in Create() as
|
// 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
|
// wxFileCtrl ctor itself can generate idle events, so we need this test
|
||||||
if ( m_filectrl )
|
if ( m_filectrl )
|
||||||
event.Enable( !IsTopMostDir(m_filectrl->GetDirectory()) );
|
event.Enable( !IsTopMostDir(m_filectrl->GetShownDirectory()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef wxHAS_GENERIC_FILEDIALOG
|
#ifdef wxHAS_GENERIC_FILEDIALOG
|
||||||
|
Reference in New Issue
Block a user