]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_unix.C
hopefully fix tex2lyx linking.
[lyx.git] / src / support / os_unix.C
index 8c556da25303c6b1b516125a97619530dfbe2ae7..fb266089fc9bb87a0688127842e14ca14a2d41eb 100644 (file)
 #include <config.h>
 
 #include "support/os.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
 
+#ifdef __APPLE__
+#include <Carbon/Carbon.h>
+#endif
 
 using std::string;
 
 
-namespace {
-
-string binpath_;
-string binname_;
-string tmpdir_;
-
-}
-
 namespace lyx {
 namespace support {
 namespace os {
 
-void init(int * /*argc*/, char ** argv[])
-{
-       static bool initialized = false;
-       if (initialized)
-               return;
-       initialized = true;
-
-       string tmp = *argv[0];
-       binname_ = OnlyFilename(tmp);
-       tmp = ExpandPath(tmp); // This expands ./ and ~/
-       if (!is_absolute_path(tmp)) {
-               string binsearchpath = GetEnvPath("PATH");
-               // This will make "src/lyx" work always :-)
-               binsearchpath += ";.";
-               tmp = FileOpenSearch(binsearchpath, tmp);
-       }
-
-       tmp = MakeAbsPath(OnlyPath(tmp));
-
-       // In case we are running in place and compiled with shared libraries
-       if (suffixIs(tmp, "/.libs/"))
-               tmp.erase(tmp.length() - 6, string::npos);
-       binpath_ = tmp;
-}
-
-
-void warn(string const & /*mesg*/)
-{
-       return;
-}
+void init(int, char *[])
+{}
 
 
 string current_root()
@@ -90,19 +55,31 @@ string::size_type common_path(string const & p1, string const & p2)
 }
 
 
-string slashify_path(string const & p)
+string external_path(string const & p)
 {
        return p;
 }
 
 
-string external_path(string const & p)
+string internal_path(string const & p)
 {
        return p;
 }
 
 
-string internal_path(string const & p)
+string external_path_list(string const & p)
+{
+       return p;
+}
+
+
+string internal_path_list(string const & p)
+{
+       return p;
+}
+
+
+string latex_path(string const & p)
 {
        return p;
 }
@@ -120,33 +97,91 @@ char const * popen_read_mode()
 }
 
 
-string binpath()
+string const & nulldev()
 {
-       return binpath_;
+       static string const nulldev_ = "/dev/null";
+       return nulldev_;
 }
 
 
-string binname()
+shell_type shell()
 {
-       return binname_;
+       return UNIX;
 }
 
 
-void setTmpDir(string const & p)
+char path_separator()
 {
-       tmpdir_ = p;
+       return ':';
 }
 
 
-string getTmpDir()
+void windows_style_tex_paths(bool)
+{}
+
+bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
 {
-       return tmpdir_;
+#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
 }
 
 
-shell_type shell()
+bool autoOpenFile(string const & filename, auto_open_mode const mode)
 {
-       return UNIX;
+#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