#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;
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(); }
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;
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);
-
- // for multiple file selection
- virtual void GetPaths(wxArrayString& paths) const;
- virtual void GetFilenames(wxArrayString& files) const;
+ 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); }
+
+ 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
// -------------------------------
#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
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() )
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 );
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
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
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;
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