Refactor: display file selector dialog from within member function in wxFileProperty
By moving the code to display file selector dialog from wxPGFileDialogAdapter to wxFileProperty we can encapsulate the operation of showing the dialog because all required parameters are stored in the corresponding data members and there is no need to use call generic GetAttribute() function to retrieve them. This also helps in making wxFileProperty attributes built-ones in the future.
This commit is contained in:
@@ -1913,43 +1913,16 @@ bool wxDirProperty::DoSetAttribute( const wxString& name, wxVariant& value )
|
||||
|
||||
bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid* propGrid, wxPGProperty* property )
|
||||
{
|
||||
wxString path;
|
||||
int indFilter = -1;
|
||||
wxFileProperty* prop = wxDynamicCast(property, wxFileProperty);
|
||||
wxCHECK_MSG( prop, false, "Function called for incompatible property" );
|
||||
|
||||
wxFileProperty* fileProp = wxDynamicCast(property, wxFileProperty);
|
||||
if ( fileProp )
|
||||
wxString value = prop->GetValueAsString(0);
|
||||
if ( prop->DisplayEditorDialog(propGrid, value) )
|
||||
{
|
||||
wxFileName filename = fileProp->GetValue().GetString();
|
||||
path = filename.GetPath();
|
||||
indFilter = fileProp->m_indFilter;
|
||||
|
||||
if ( path.empty() && !fileProp->m_basePath.empty() )
|
||||
path = fileProp->m_basePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxFileName fn(property->GetValue().GetString());
|
||||
path = fn.GetPath();
|
||||
}
|
||||
|
||||
wxFileDialog dlg( propGrid->GetPanel(),
|
||||
property->GetAttribute(wxPG_FILE_DIALOG_TITLE, _("Choose a file")),
|
||||
property->GetAttribute(wxPG_FILE_INITIAL_PATH, path),
|
||||
wxEmptyString,
|
||||
property->GetAttribute(wxPG_FILE_WILDCARD, wxALL_FILES),
|
||||
property->GetAttributeAsLong(wxPG_FILE_DIALOG_STYLE, 0),
|
||||
wxDefaultPosition );
|
||||
|
||||
if ( indFilter >= 0 )
|
||||
dlg.SetFilterIndex( indFilter );
|
||||
|
||||
if ( dlg.ShowModal() == wxID_OK )
|
||||
{
|
||||
if ( fileProp )
|
||||
fileProp->m_indFilter = dlg.GetFilterIndex();
|
||||
SetValue( dlg.GetPath() );
|
||||
SetValue(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2156,6 +2129,34 @@ bool wxFileProperty::DoSetAttribute( const wxString& name, wxVariant& value )
|
||||
return wxPGProperty::DoSetAttribute(name, value);
|
||||
}
|
||||
|
||||
bool wxFileProperty::DisplayEditorDialog(wxPropertyGrid* propGrid, wxString& value)
|
||||
{
|
||||
wxFileName filename = value;
|
||||
wxString path = filename.GetPath();
|
||||
|
||||
if ( path.empty() && !m_basePath.empty() )
|
||||
path = m_basePath;
|
||||
|
||||
wxFileDialog dlg(propGrid->GetPanel(),
|
||||
m_dlgTitle.empty() ? _("Choose a file") : m_dlgTitle,
|
||||
m_initialPath.empty() ? path : m_initialPath,
|
||||
value,
|
||||
m_wildcard.empty() ? wxALL_FILES : m_wildcard,
|
||||
m_dlgStyle,
|
||||
wxDefaultPosition);
|
||||
|
||||
if ( m_indFilter >= 0 )
|
||||
dlg.SetFilterIndex(m_indFilter);
|
||||
|
||||
if ( dlg.ShowModal() == wxID_OK )
|
||||
{
|
||||
m_indFilter = dlg.GetFilterIndex();
|
||||
value = dlg.GetPath();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// wxPGLongStringDialogAdapter
|
||||
// -----------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user