Implement wxFileType::GetOpenCommand() in wxOSX.

This method used to work in 2.8 but was unimplemented in 2.9.

Restore more or less the old implementation using the data that we already
have in wxMimeTypesManager anyhow.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68563 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2011-08-05 19:02:26 +00:00
parent 7112cdd1f3
commit 59f495db65
3 changed files with 51 additions and 4 deletions

View File

@ -456,6 +456,7 @@ All (GUI):
OSX:
- Implement wxRegion::Equal() (Dr.Acula).
- Implement wxFileType::GetOpenCommand().
- wxGetOsVersion() now returns more sensible version numbers, e.g. 10 and 6
for OS X 10.6.

View File

@ -56,6 +56,7 @@ private:
bool GetMimeTypes(const wxString& uti, wxArrayString& mimeTypes);
bool GetIcon(const wxString& uti, wxIconLocation *iconLoc);
bool GetDescription(const wxString& uti, wxString *desc);
bool GetApplication(const wxString& uti, wxString *command);
// Structure to represent file types
typedef struct FileTypeData
@ -63,6 +64,7 @@ private:
wxArrayString extensions;
wxArrayString mimeTypes;
wxIconLocation iconLoc;
wxString application;
wxString description;
}
FileTypeInfo;
@ -95,9 +97,9 @@ public:
bool GetMimeTypes(wxArrayString& mimeTypes) const ;
bool GetIcon(wxIconLocation *iconLoc) const ;
bool GetDescription(wxString *desc) const ;
bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const;
// These functions are only stubs on Mac OS X
bool GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const;
bool GetPrintCommand(wxString *printCmd, const wxFileType::MessageParameters& params) const;
size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands, const wxFileType::MessageParameters& params) const;
bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE);

View File

@ -447,7 +447,11 @@ void wxMimeTypesManagerImpl::LoadDisplayDataForUti(const wxString& uti)
if( !bundle )
return;
// Get a all the document type data in this bundle
// Also get the open command while we have the bundle
wxCFStringRef cfsAppPath(CFURLCopyFileSystemPath(appUrl, kCFURLPOSIXPathStyle));
m_utiMap[ uti ].application = cfsAppPath.AsString();
// Get all the document type data in this bundle
CFTypeRef docTypeData;
docTypeData = CFBundleGetValueForInfoDictionaryKey( bundle, docTypesKey );
@ -587,6 +591,19 @@ bool wxMimeTypesManagerImpl::GetDescription(const wxString& uti, wxString *desc)
return true;
}
bool wxMimeTypesManagerImpl::GetApplication(const wxString& uti, wxString *command)
{
const UtiMap::const_iterator itr = m_utiMap.find( uti );
if( itr == m_utiMap.end() )
{
command->clear();
return false;
}
*command = itr->second.application;
return true;
}
/////////////////////////////////////////////////////////////////////////////
// The remaining functionality has not yet been implemented for OS X
@ -626,9 +643,36 @@ bool wxFileTypeImpl::GetDescription(wxString *desc) const
return m_manager->GetDescription( m_uti, desc );
}
bool wxFileTypeImpl::GetOpenCommand(wxString *WXUNUSED(openCmd), const wxFileType::MessageParameters& WXUNUSED(params)) const
namespace
{
return false;
// Helper function for GetOpenCommand(): returns the string surrounded by
// (singly) quotes if it contains spaces.
wxString QuoteIfNecessary(const wxString& path)
{
wxString result(path);
if ( path.find(' ') != wxString::npos )
{
result.insert(0, "'");
result.append("'");
}
return result;
}
} // anonymous namespace
bool wxFileTypeImpl::GetOpenCommand(wxString *openCmd, const wxFileType::MessageParameters& params) const
{
wxString application;
if ( !m_manager->GetApplication(m_uti, &application) )
return false;
*openCmd << QuoteIfNecessary(application)
<< ' ' << QuoteIfNecessary(params.GetFileName());
return true;
}
bool wxFileTypeImpl::GetPrintCommand(wxString *WXUNUSED(printCmd), const wxFileType::MessageParameters& WXUNUSED(params)) const