Prefer file types with a defined open command in Unix wxMimeTypesManager.
It can happen that more than one file type maps to the given extension, in this case prefer the one which has an open command defined for it as it is typically more useful. See #16703. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78241 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
13cae6fbb2
commit
2d3ef92acc
@ -830,6 +830,7 @@ wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ex
|
||||
|
||||
InitIfNeeded();
|
||||
|
||||
wxFileType* fileTypeFallback = NULL;
|
||||
size_t count = m_aExtensions.GetCount();
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
{
|
||||
@ -844,12 +845,32 @@ wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ex
|
||||
wxFileType *fileType = new wxFileType;
|
||||
fileType->m_impl->Init(this, n);
|
||||
|
||||
return fileType;
|
||||
// See if this one has a known open-command. If not, keep
|
||||
// looking for another one that does, as a file that can't be
|
||||
// opened is not very useful, but store this one as a fallback.
|
||||
wxString type, desc, open;
|
||||
fileType->GetMimeType(&type);
|
||||
fileType->GetDescription(&desc);
|
||||
wxFileType::MessageParameters params("filename."+ext, type);
|
||||
if ( fileType->GetOpenCommand(&open, params) )
|
||||
{
|
||||
delete fileTypeFallback;
|
||||
return fileType;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Override the previous fallback, if any, with the new
|
||||
// one: we consider that later entries have priority.
|
||||
delete fileTypeFallback;
|
||||
fileTypeFallback = fileType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
// If we couldn't find a filetype with a known open-command, return any
|
||||
// without one
|
||||
return fileTypeFallback;
|
||||
}
|
||||
|
||||
wxFileType * wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
|
||||
|
Loading…
Reference in New Issue
Block a user