>>>>> "Bennett" == Bennett Helm <[EMAIL PROTECTED]> writes:
Bennett> Well ... I'm laid up sick at the moment and won't be able to Bennett> do anything today. And then I'm (still) swamped with work, so Bennett> I won't have a lot of time to work on it. But most Bennett> importantly, I don't understand what I'd need to do. Bennett> It really would help me if you could at least outline what Bennett> I'd need to do, and I'll have a look. OK, I read the documentation and came up with the following patch, which is probably partly bogus. I think this is supposed to do what we need. Could you try to turn it into working code? JMarc
Index: src/support/os_unix.C =================================================================== --- src/support/os_unix.C (revision 13918) +++ src/support/os_unix.C (working copy) @@ -14,6 +14,11 @@ #include "support/os.h" +#ifdef __APPLE__ +#include <Files.h> +#include <LSInfo.h> +#endif + using std::string; @@ -115,19 +120,58 @@ char path_separator() void cygwin_path_fix(bool) {} -bool canAutoOpenFile(string const & /*ext*/, auto_open_mode const /*mode*/) +bool canAutoOpenFile(string const & ext, auto_open_mode const mode) { +#ifdef __APPLE__ +// Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/ + CFStringRef cfs_ext = CFStringCreateWithBytes(kCFAllocatorDefault, + (UInt8 *) ext.c_str(), ext.length(), + kCFStringEncodingISOLatin1, false); + LSRolesMask role = (mode = VIEW) ? kLSRolesViewer : kLSRolesEditor; + FSRef outAppRef; + OSStatus status = + LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, + cfs_ext, role, &outAppRef, NULL); + CFRelease(cfs_ext); + + return status != kLSApplicationNotFoundErr; +#else // currently, no default viewer is tried for non-windows system // support for KDE/Gnome/Macintosh may be added later return false; +#endif } -bool autoOpenFile(string const & /*filename*/, auto_open_mode const /*mode*/) +bool autoOpenFile(string const & filename, auto_open_mode const mode) { +#ifdef __APPLE__ +// Reference: http://developer.apple.com/documentation/Carbon/Reference/LaunchServicesReference/ + FSRef fileref = FSPathMakeRef((UInt8 *) filename.c_str(), + filename.length(), NULL); + LSRolesMask role = (mode = VIEW) ? kLSRolesViewer : kLSRolesEditor; + FSRef outAppRef; + + OSStatus status = + LSGetApplicationForItem(&fileref, role, outAppRef, NULL); + if (status == kLSApplicationNotFoundErr) + return false; + + LSLaunchFSRefSpec inLaunchSpec; + inLaunchSpec.appRef = outAppRef; + inLaunchSpec.numDocs = 1; + inLaunchSpec.itemRefs = &fileref; + inLaunchSpec.passThruParams = NULL; + inLaunchSpec.launchFlags = kLSLaunchDefaults; + inLaunchSpec.asyncRefCon = NULL; + status = LSOpenFromRefSpec(&inLaunchSpec, NULL); + + return status != kLSApplicationNotFoundErr; +#else // currently, no default viewer is tried for non-windows system // support for KDE/Gnome/Macintosh may be added later return false; +#endif } } // namespace os