was added.
+2.9.4:
+------
+
+All (GUI):
+
+- Added wxFilePickerCtrl::SetInitialDirectory().
+
+
2.9.3: (released 2011-12-14)
------
wxFileDirPickerWidgetBase() { }
virtual ~wxFileDirPickerWidgetBase() { }
+ // Path here is the name of the selected file or directory.
wxString GetPath() const { return m_path; }
virtual void SetPath(const wxString &str) { m_path=str; }
+ // Set the directory to open the file browse dialog at initially.
+ virtual void SetInitialDirectory(const wxString& dir) = 0;
+
// returns the picker widget cast to wxControl
virtual wxControl *AsControl() = 0;
wxString GetPath() const;
void SetPath(const wxString &str);
+ // Set the directory to open the file browse dialog at initially.
+ void SetInitialDirectory(const wxString& dir)
+ {
+ m_pickerIface->SetInitialDirectory(dir);
+ }
+
public: // internal functions
void UpdatePickerFromTextCtrl();
virtual wxEventType GetEventType() const = 0;
+ virtual void SetInitialDirectory(const wxString& dir);
+
public:
bool Create(wxWindow *parent, wxWindowID id,
// just doesn't make sense to use picker styles for wxButton anyhow
long m_pickerStyle;
+ // Initial directory set by SetInitialDirectory() call or empty.
+ wxString m_initialDir;
+
private:
// common part of all ctors
void Init() { m_pickerStyle = -1; }
return filedlgstyle;
}
- virtual wxDialog *CreateDialog()
- {
- wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
- wxEmptyString, wxEmptyString,
- m_wildcard, GetDialogStyle());
-
- // this sets both the default folder and the default file of the dialog
- p->SetPath(m_path);
- return p;
- }
+ virtual wxDialog *CreateDialog();
wxEventType GetEventType() const
{ return wxEVT_COMMAND_FILEPICKER_CHANGED; }
void UpdatePathFromDialog(wxDialog *p)
{ m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
+ // Set the initial directory for the dialog but without overriding the
+ // directory of the currently selected file, if any.
+ void DoSetInitialDirectory(wxFileDialog* dialog, const wxString& dir);
+
private:
DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
};
return dirdlgstyle;
}
- virtual wxDialog *CreateDialog()
- {
- return new wxDirDialog(GetDialogParent(), m_message, m_path,
- GetDialogStyle());
- }
+ virtual wxDialog *CreateDialog();
wxEventType GetEventType() const
{ return wxEVT_COMMAND_DIRPICKER_CHANGED; }
void OnDialogOK(wxCommandEvent &);
virtual void SetPath(const wxString &str);
+ virtual void SetInitialDirectory(const wxString& dir);
// see macro defined above
FILEDIRBTN_OVERRIDES
}
virtual void SetPath(const wxString &str);
+ virtual void SetInitialDirectory(const wxString& dir);
// see macro defined above
FILEDIRBTN_OVERRIDES
*/
void SetFileName(const wxFileName& filename);
+ /**
+ Set the directory to show when starting to browse for files.
+
+ This function is mostly useful for the file picker controls which have
+ no selection initially to configure the directory that should be shown
+ if the user starts browsing for files as otherwise the directory of
+ initially selected file is used, which is usually the desired
+ behaviour and so the directory specified by this function is ignored in
+ this case.
+
+ @since 2.9.4
+ */
+ void SetInitialDirectory(const wxString& dir);
+
/**
Sets the absolute path of the currently selected file.
This must be a valid file if the @c wxFLP_FILE_MUST_EXIST style was given.
*/
void SetDirName(const wxFileName& dirname);
+ /**
+ Set the directory to show when starting to browse for directories.
+
+ This function is mostly useful for the directory picker controls which
+ have no selection initially to configure the directory that should be
+ shown if the user starts browsing for directories as otherwise the
+ initially selected directory is used, which is usually the desired
+ behaviour and so the directory specified by this function is ignored in
+ this case.
+
+ @since 2.9.4
+ */
+ void SetInitialDirectory(const wxString& dir);
+
/**
Sets the absolute path of (the default converter uses current locale's
charset)the currently selected directory.
#include "wx/app.h"
#include "wx/log.h"
#include "wx/radiobox.h"
+ #include "wx/textctrl.h"
#endif
#include "wx/artprov.h"
enum
{
PickerPage_Reset = wxID_HIGHEST,
- PickerPage_Dir
+ PickerPage_Dir,
+ PickerPage_SetDir
};
void OnDirChange(wxFileDirPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
void OnButtonReset(wxCommandEvent &ev);
+ void OnButtonSetDir(wxCommandEvent &ev);
+
// the picker
wxDirPickerCtrl *m_dirPicker;
*m_chkDirChangeDir,
*m_chkDirMustExist,
*m_chkSmall;
+ wxTextCtrl *m_textInitialDir;
+
wxBoxSizer *m_sizer;
private:
BEGIN_EVENT_TABLE(DirPickerWidgetsPage, WidgetsPage)
EVT_BUTTON(PickerPage_Reset, DirPickerWidgetsPage::OnButtonReset)
+ EVT_BUTTON(PickerPage_SetDir, DirPickerWidgetsPage::OnButtonSetDir)
EVT_DIRPICKER_CHANGED(PickerPage_Dir, DirPickerWidgetsPage::OnDirChange)
m_chkSmall = CreateCheckBoxAndAddToSizer(dirbox, "&Small version", false);
boxleft->Add(dirbox, 0, wxALL|wxGROW, 5);
+ boxleft->Add(CreateSizerWithTextAndButton
+ (
+ PickerPage_SetDir,
+ "&Initial directory",
+ wxID_ANY,
+ &m_textInitialDir
+ ), wxSizerFlags().Expand().Border());
+
+ boxleft->AddSpacer(10);
+
boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// event handlers
// ----------------------------------------------------------------------------
+void DirPickerWidgetsPage::OnButtonSetDir(wxCommandEvent& WXUNUSED(event))
+{
+ m_dirPicker->SetInitialDirectory(m_textInitialDir->GetValue());
+}
+
void DirPickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
#include "wx/app.h"
#include "wx/log.h"
#include "wx/radiobox.h"
+ #include "wx/textctrl.h"
#endif
#include "wx/artprov.h"
enum
{
PickerPage_Reset = wxID_HIGHEST,
- PickerPage_File
+ PickerPage_File,
+ PickerPage_SetDir
};
void OnFileChange(wxFileDirPickerEvent &ev);
void OnCheckBox(wxCommandEvent &ev);
void OnButtonReset(wxCommandEvent &ev);
+ void OnButtonSetDir(wxCommandEvent &ev);
// the picker
*m_chkFileChangeDir,
*m_chkSmall;
wxRadioBox *m_radioFilePickerMode;
+ wxTextCtrl *m_textInitialDir;
wxBoxSizer *m_sizer;
BEGIN_EVENT_TABLE(FilePickerWidgetsPage, WidgetsPage)
EVT_BUTTON(PickerPage_Reset, FilePickerWidgetsPage::OnButtonReset)
+ EVT_BUTTON(PickerPage_SetDir, FilePickerWidgetsPage::OnButtonSetDir)
EVT_FILEPICKER_CHANGED(PickerPage_File, FilePickerWidgetsPage::OnFileChange)
boxleft->Add(filebox, 0, wxALL|wxGROW, 5);
+ boxleft->Add(CreateSizerWithTextAndButton
+ (
+ PickerPage_SetDir,
+ "&Initial directory",
+ wxID_ANY,
+ &m_textInitialDir
+ ), wxSizerFlags().Expand().Border());
+
+ boxleft->AddSpacer(10);
+
boxleft->Add(new wxButton(this, PickerPage_Reset, wxT("&Reset")),
0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// event handlers
// ----------------------------------------------------------------------------
+void FilePickerWidgetsPage::OnButtonSetDir(wxCommandEvent& WXUNUSED(event))
+{
+ m_filePicker->SetInitialDirectory(m_textInitialDir->GetValue());
+}
+
void FilePickerWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
{
Reset();
#if wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
+#include "wx/filename.h"
#include "wx/filepicker.h"
#include "wx/scopedptr.h"
}
}
+void wxGenericFileDirButton::SetInitialDirectory(const wxString& dir)
+{
+ m_initialDir = dir;
+}
+
+// ----------------------------------------------------------------------------
+// wxGenericFileutton
+// ----------------------------------------------------------------------------
+
+void
+wxGenericFileButton::DoSetInitialDirectory(wxFileDialog* dialog,
+ const wxString& dir)
+{
+ if ( m_path.find_first_of(wxFileName::GetPathSeparators()) ==
+ wxString::npos )
+ {
+ dialog->SetDirectory(dir);
+ }
+}
+
+wxDialog *wxGenericFileButton::CreateDialog()
+{
+ wxFileDialog* const dialog = new wxFileDialog
+ (
+ GetDialogParent(),
+ m_message,
+ wxEmptyString,
+ wxEmptyString,
+ m_wildcard,
+ GetDialogStyle()
+ );
+
+ // this sets both the default folder and the default file of the dialog
+ dialog->SetPath(m_path);
+
+ // If there is no default file or if it doesn't have any path, use the
+ // explicitly set initial directory.
+ if ( !m_initialDir.empty() )
+ DoSetInitialDirectory(dialog, m_initialDir);
+
+ return dialog;
+}
+
+// ----------------------------------------------------------------------------
+// wxGenericDirButton
+// ----------------------------------------------------------------------------
+
+wxDialog *wxGenericDirButton::CreateDialog()
+{
+ wxDirDialog* const dialog = new wxDirDialog
+ (
+ GetDialogParent(),
+ m_message,
+ m_path.empty() ? m_initialDir : m_path,
+ GetDialogStyle()
+ );
+ return dialog;
+}
+
#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
UpdateDialogPath(m_dialog);
}
+void wxFileButton::SetInitialDirectory(const wxString& dir)
+{
+ if (m_dialog)
+ DoSetInitialDirectory(static_cast<wxFileDialog*>(m_dialog), dir);
+ else
+ wxGenericFileButton::SetInitialDirectory(dir);
+}
+
#endif // wxUSE_FILEPICKERCTRL && defined(__WXGTK26__)
UpdateDialogPath(m_dialog);
}
+void wxDirButton::SetInitialDirectory(const wxString& dir)
+{
+ if (m_dialog)
+ {
+ if (m_path.empty())
+ static_cast<wxDirDialog*>(m_dialog)->SetPath(dir);
+ }
+ else
+ wxGenericDirButton::SetInitialDirectory(dir);
+}
+
#endif // wxUSE_DIRPICKERCTRL && defined(__WXGTK26__)