Improve wxFileCtrl::SetFilename() and SetPath() consistency.
Don't allow specifying the directory in the former and do check for the directory existence in the latter. Also update the file shown in the dialog in SetFilename(). Closes #16685.
This commit is contained in:
committed by
Vadim Zeitlin
parent
9a44b109bf
commit
178e9c9335
@@ -114,6 +114,7 @@ All (GUI):
|
|||||||
- Harmonize wxMenuEvent handling between all major ports.
|
- Harmonize wxMenuEvent handling between all major ports.
|
||||||
- Fix wxPGChoices copy ctor (Snoits).
|
- Fix wxPGChoices copy ctor (Snoits).
|
||||||
- Show how to handle files on command line in docview sample (Neil Mayhew).
|
- Show how to handle files on command line in docview sample (Neil Mayhew).
|
||||||
|
- Improve wxFileCtrl::SetFilename() and SetPath() (Kevin B. McCarty).
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -181,8 +181,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
Changes to a certain directory and selects a certain file.
|
Changes to a certain directory and selects a certain file.
|
||||||
|
|
||||||
In case the filename specified isn't found/couldn't be shown with
|
If @a path includes the directory part, it must exist, otherwise @false
|
||||||
currently selected filter, false is returned.
|
is returned and nothing else is done.
|
||||||
|
|
||||||
@return Returns @true on success, @false otherwise
|
@return Returns @true on success, @false otherwise
|
||||||
*/
|
*/
|
||||||
|
@@ -1145,15 +1145,16 @@ bool wxGenericFileCtrl::SetDirectory( const wxString& dir )
|
|||||||
|
|
||||||
bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
||||||
{
|
{
|
||||||
const long item = m_list->FindItem( -1, name );
|
wxString dir, fn, ext;
|
||||||
|
wxFileName::SplitPath(name, &dir, &fn, &ext);
|
||||||
if ( item == -1 ) // file not found either because it doesn't exist or the
|
wxCHECK_MSG( dir.empty(), false,
|
||||||
// current filter doesn't show it.
|
wxS( "can't specify directory component to SetFilename" ) );
|
||||||
return false;
|
|
||||||
|
|
||||||
m_noSelChgEvent = true;
|
m_noSelChgEvent = true;
|
||||||
|
|
||||||
// Deselect selected items
|
m_text->ChangeValue( name );
|
||||||
|
|
||||||
|
// Deselect previously selected items
|
||||||
{
|
{
|
||||||
const int numSelectedItems = m_list->GetSelectedItemCount();
|
const int numSelectedItems = m_list->GetSelectedItemCount();
|
||||||
|
|
||||||
@@ -1172,8 +1173,14 @@ bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select new filename if it's in the list
|
||||||
|
long item = m_list->FindItem(wxNOT_FOUND, name);
|
||||||
|
|
||||||
|
if ( item != wxNOT_FOUND )
|
||||||
|
{
|
||||||
m_list->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
m_list->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
||||||
m_list->EnsureVisible( item );
|
m_list->EnsureVisible( item );
|
||||||
|
}
|
||||||
|
|
||||||
m_noSelChgEvent = false;
|
m_noSelChgEvent = false;
|
||||||
|
|
||||||
@@ -1436,12 +1443,15 @@ void wxGenericFileCtrl::HandleAction( const wxString &fn )
|
|||||||
|
|
||||||
bool wxGenericFileCtrl::SetPath( const wxString& path )
|
bool wxGenericFileCtrl::SetPath( const wxString& path )
|
||||||
{
|
{
|
||||||
if ( !wxFileName::FileExists( ( path ) ) )
|
wxString dir, fn, ext;
|
||||||
|
wxFileName::SplitPath(path, &dir, &fn, &ext);
|
||||||
|
|
||||||
|
if ( !dir.empty() && !wxFileName::DirExists(dir) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
wxString ext;
|
m_dir = dir;
|
||||||
wxFileName::SplitPath( path, &m_dir, &m_fileName, &ext );
|
m_fileName = fn;
|
||||||
if ( !ext.empty() )
|
if ( !ext.empty() || path.Last() == '.' )
|
||||||
{
|
{
|
||||||
m_fileName += wxT( "." );
|
m_fileName += wxT( "." );
|
||||||
m_fileName += ext;
|
m_fileName += ext;
|
||||||
|
Reference in New Issue
Block a user