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.
|
||||
- Fix wxPGChoices copy ctor (Snoits).
|
||||
- Show how to handle files on command line in docview sample (Neil Mayhew).
|
||||
- Improve wxFileCtrl::SetFilename() and SetPath() (Kevin B. McCarty).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@@ -180,9 +180,9 @@ public:
|
||||
|
||||
/**
|
||||
Changes to a certain directory and selects a certain file.
|
||||
|
||||
In case the filename specified isn't found/couldn't be shown with
|
||||
currently selected filter, false is returned.
|
||||
|
||||
If @a path includes the directory part, it must exist, otherwise @false
|
||||
is returned and nothing else is done.
|
||||
|
||||
@return Returns @true on success, @false otherwise
|
||||
*/
|
||||
|
@@ -1145,15 +1145,16 @@ bool wxGenericFileCtrl::SetDirectory( const wxString& dir )
|
||||
|
||||
bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
||||
{
|
||||
const long item = m_list->FindItem( -1, name );
|
||||
|
||||
if ( item == -1 ) // file not found either because it doesn't exist or the
|
||||
// current filter doesn't show it.
|
||||
return false;
|
||||
wxString dir, fn, ext;
|
||||
wxFileName::SplitPath(name, &dir, &fn, &ext);
|
||||
wxCHECK_MSG( dir.empty(), false,
|
||||
wxS( "can't specify directory component to SetFilename" ) );
|
||||
|
||||
m_noSelChgEvent = true;
|
||||
|
||||
// Deselect selected items
|
||||
m_text->ChangeValue( name );
|
||||
|
||||
// Deselect previously selected items
|
||||
{
|
||||
const int numSelectedItems = m_list->GetSelectedItemCount();
|
||||
|
||||
@@ -1172,8 +1173,14 @@ bool wxGenericFileCtrl::SetFilename( const wxString& name )
|
||||
}
|
||||
}
|
||||
|
||||
m_list->SetItemState( item, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
||||
m_list->EnsureVisible( item );
|
||||
// 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->EnsureVisible( item );
|
||||
}
|
||||
|
||||
m_noSelChgEvent = false;
|
||||
|
||||
@@ -1436,12 +1443,15 @@ void wxGenericFileCtrl::HandleAction( const wxString &fn )
|
||||
|
||||
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;
|
||||
|
||||
wxString ext;
|
||||
wxFileName::SplitPath( path, &m_dir, &m_fileName, &ext );
|
||||
if ( !ext.empty() )
|
||||
m_dir = dir;
|
||||
m_fileName = fn;
|
||||
if ( !ext.empty() || path.Last() == '.' )
|
||||
{
|
||||
m_fileName += wxT( "." );
|
||||
m_fileName += ext;
|
||||
|
Reference in New Issue
Block a user