diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CocoaUtils.h | 3 | ||||
-rw-r--r-- | src/CocoaUtils.mm | 6 | ||||
-rw-r--r-- | src/parsersettings.cc | 23 |
3 files changed, 26 insertions, 6 deletions
diff --git a/src/CocoaUtils.h b/src/CocoaUtils.h index 8543d84..ad5518b 100644 --- a/src/CocoaUtils.h +++ b/src/CocoaUtils.h @@ -1,10 +1,13 @@ #ifndef COCOAUTILS_H_ #define COCOAUTILS_H_ +#include <string> + class CocoaUtils { public: static void endApplication(); + static std::string documentsPath(); }; #endif diff --git a/src/CocoaUtils.mm b/src/CocoaUtils.mm index 2ac8aef..295ceb9 100644 --- a/src/CocoaUtils.mm +++ b/src/CocoaUtils.mm @@ -1,5 +1,6 @@ #include "CocoaUtils.h" #import <Foundation/Foundation.h> +#include <stdio.h> void CocoaUtils::endApplication() { @@ -7,3 +8,8 @@ void CocoaUtils::endApplication() postNotificationName:@"NSApplicationWillTerminateNotification" object:nil]; } + +std::string CocoaUtils::documentsPath() +{ + return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]); +} diff --git a/src/parsersettings.cc b/src/parsersettings.cc index 3dda132..54f9713 100644 --- a/src/parsersettings.cc +++ b/src/parsersettings.cc @@ -2,7 +2,9 @@ #include <boost/filesystem.hpp> #include <boost/foreach.hpp> #include "boosty.h" +#include <boost/algorithm/string.hpp> #include <qglobal.h> // Needed for Q_ defines - move the offending code somewhere else +#include "CocoaUtils.h" namespace fs = boost::filesystem; @@ -28,15 +30,24 @@ std::string locate_file(const std::string &filename) void parser_init(const std::string &applicationpath) { - // Add path from OPENSCADPATH before adding built-in paths - const char *openscadpath = getenv("OPENSCADPATH"); - if (openscadpath) { - add_librarydir(boosty::absolute(fs::path(openscadpath)).string()); + // Add paths from OPENSCADPATH before adding built-in paths + const char *openscadpaths = getenv("OPENSCADPATH"); + if (openscadpaths) { + std::string paths(openscadpaths); + typedef boost::split_iterator<std::string::iterator> string_split_iterator; + for (string_split_iterator it = + make_split_iterator(paths, first_finder(":", boost::is_iequal())); + it != string_split_iterator(); + ++it) { + add_librarydir(boosty::absolute(fs::path(boost::copy_range<std::string>(*it))).string()); + } } - // FIXME: Support specifying more than one path in OPENSCADPATH // FIXME: Add ~/.openscad/libraries - // FIXME: Add ~/Documents/OpenSCAD/libraries on Mac? +#ifdef __APPLE__ + fs::path docdir(CocoaUtils::documentsPath()); + add_librarydir(boosty::stringy(docdir / "OpenSCAD" / "libraries")); +#endif std::string librarydir; fs::path libdir(applicationpath); |