From 48f0a4b68183247fc6069397eac323d84b40c202 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 29 May 2006 16:41:31 +0000 Subject: [PATCH] * src/support/os_unix.C (canAutoOpenFile, autoOpenFile): add support for Mac OS X. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@13960 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/ChangeLog | 5 ++++ src/support/os_unix.C | 58 +++++++++++++++++++++++++++++++++++++++++-- status.14x | 6 ++--- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 3069964ec3..33a803fe00 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2006-05-29 Jean-Marc Lasgouttes + + * os_unix.C (canAutoOpenFile, autoOpenFile): add support for Mac + OS X. + 2006-05-16 Bo Peng * Makefile.am: under win32, link against shlwapi.dll. diff --git a/src/support/os_unix.C b/src/support/os_unix.C index 1ad2b14212..8991288404 100644 --- a/src/support/os_unix.C +++ b/src/support/os_unix.C @@ -14,6 +14,10 @@ #include "support/os.h" +#ifdef __APPLE__ +#include +#endif + using std::string; @@ -115,19 +119,69 @@ 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 + // silence compiler warnings + (void)ext; + (void)mode; + // 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; + OSStatus status = + FSPathMakeRef((UInt8 *) filename.c_str(), &fileref, NULL); + if (status != 0) + return false; + + LSRolesMask role = (mode == VIEW) ? kLSRolesViewer : kLSRolesEditor; + FSRef outAppRef; + + 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 + // silence compiler warnings + (void)filename; + (void)mode; + // currently, no default viewer is tried for non-windows system // support for KDE/Gnome/Macintosh may be added later return false; +#endif } } // namespace os diff --git a/status.14x b/status.14x index a38ed5be79..932c062db3 100644 --- a/status.14x +++ b/status.14x @@ -19,6 +19,9 @@ What's new ** Updates +- LyX now automatically uses file viewers and editors set at OS level + [Windows and Mac OS X only]. + - Update Hungarian localization of the interface. - Update translations of documentation for German (all) and Hungarian @@ -82,9 +85,6 @@ What's new - Don't jump back to previous cursor position when trying to click on an inset (bug 2526). -- LyX now automatically uses file viewers and editors set at OS level - [windows only]. - - Automatically use fonts in the fonts/ subdirectory of LyX support directory in windows.