Avoid overriding wxDirDialog::GetPath[s]() unnecessarily

Don't duplicate practically the same code in all ports, just add m_paths
itself to the base class. The only drawback of doing this is that it's
unused in the ports not (yet) using it, but this saves enough code in
the aggregate to be worth it.
This commit is contained in:
Vadim Zeitlin 2020-07-10 03:52:15 +02:00
parent 2b0323ebc8
commit a47fd95e45
7 changed files with 15 additions and 58 deletions

View File

@ -90,19 +90,20 @@ public:
virtual wxString GetMessage() const { return m_message; }
virtual wxString GetPath() const
{
wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" );
wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(),
"When using wxDD_MULTIPLE, must call GetPaths() instead" );
return m_path;
}
virtual void GetPaths(wxArrayString& paths) const
{
paths.clear();
paths.push_back(m_path);
paths = m_paths;
}
protected:
wxString m_message;
wxString m_path;
wxArrayString m_paths;
};

View File

@ -37,9 +37,7 @@ public:
public: // overrides from wxGenericDirDialog
wxString GetPath() const wxOVERRIDE;
void SetPath(const wxString& path) wxOVERRIDE;
void GetPaths(wxArrayString& paths) const wxOVERRIDE;
// Implementation only.
@ -56,8 +54,6 @@ protected:
private:
wxArrayString m_paths;
wxDECLARE_DYNAMIC_CLASS(wxDirDialog);
};

View File

@ -24,18 +24,9 @@ public:
void SetPath(const wxString& path) wxOVERRIDE;
// can be used only when wxDD_MULTIPLE flag is not set
wxString GetPath() const wxOVERRIDE;
// should be used only when wxDD_MULTIPLE flag is set
void GetPaths(wxArrayString& paths) const wxOVERRIDE;
virtual int ShowModal() wxOVERRIDE;
private:
// Used for wxDD_MULTIPLE
wxArrayString m_paths;
// The real implementations of ShowModal(), used for Windows versions
// before and since Vista.
int ShowSHBrowseForFolder(WXHWND owner);

View File

@ -51,10 +51,6 @@ public:
// only for compatibility with older versions
virtual void SetTitle(const wxString& title) wxOVERRIDE;
virtual wxString GetPath() const wxOVERRIDE;
virtual void GetPaths(wxArrayString& paths) const wxOVERRIDE;
#if wxOSX_USE_COCOA
virtual void ShowWindowModal() wxOVERRIDE;
virtual void ModalFinishedCallback(void* panel, int returnCode) wxOVERRIDE;
@ -72,7 +68,6 @@ private:
// Common part of all ctors.
void Init();
wxArrayString m_paths;
wxString m_title;
wxDECLARE_DYNAMIC_CLASS(wxDirDialog);

View File

@ -163,6 +163,11 @@ void wxDirDialog::GTKOnAccept()
wxSetWorkingDirectory(m_paths.Last());
}
if (!HasFlag(wxDD_MULTIPLE))
{
m_path = m_paths.Last();
}
EndDialog(wxID_OK);
}
@ -188,15 +193,4 @@ void wxDirDialog::SetPath(const wxString& dir)
}
}
wxString wxDirDialog::GetPath() const
{
wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" );
return m_paths.Last();
}
void wxDirDialog::GetPaths(wxArrayString& paths) const
{
paths = m_paths;
}
#endif // wxUSE_DIRDLG

View File

@ -151,19 +151,6 @@ void wxDirDialog::SetPath(const wxString& path)
}
}
wxString wxDirDialog::GetPath() const
{
wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxEmptyString,
"When using wxDD_MULTIPLE, must call GetPaths() instead" );
return m_path;
}
void wxDirDialog::GetPaths(wxArrayString& paths) const
{
paths = m_paths;
}
int wxDirDialog::ShowModal()
{
WX_HOOK_MODAL_DIALOG();
@ -293,7 +280,7 @@ int wxDirDialog::ShowIFileOpenDialog(WXHWND owner)
{
if ( !HasFlag(wxDD_MULTIPLE) )
{
m_path = m_paths.front();
m_path = m_paths.Last();
}
return wxID_OK;

View File

@ -157,6 +157,11 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
m_paths.Add([url fileSystemRepresentation]);
}
if ( !HasFlag(wxDD_MULTIPLE) )
{
m_path = m_paths.Last();
}
result = wxID_OK;
}
SetReturnCode(result);
@ -171,16 +176,4 @@ void wxDirDialog::SetTitle(const wxString &title)
wxDialog::SetTitle(title);
}
wxString wxDirDialog::GetPath() const
{
wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" );
return m_paths.Last();
}
void wxDirDialog::GetPaths(wxArrayString& paths) const
{
paths = m_paths;
}
#endif // wxUSE_DIRDLG