+ Glib::ustring realdir = dir;
+
+ /* this little tangled mess is a result of 4 things:
+
+ 1) GtkFileChooser vomits when given a non-absolute directory
+ argument to set_current_folder()
+ 2) canonicalize_file_name() doesn't exist on OS X
+ 3) linux man page for realpath() says "do not use this function"
+ 4) canonicalize_file_name() & realpath() have entirely
+ different semantics on OS X and Linux when given
+ a non-existent path.
+
+ as result of all this, we take two distinct pathways through the code.
+ */
+
+
+#ifdef __APPLE__
+
+ char buf[PATH_MAX];
+
+ if(realpath (dir.c_str(), buf) != 0) {
+ if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
+ realdir = Glib::path_get_dirname (realdir);
+ }
+ m_folder->set_current_folder (realdir);
+ engine_page_session_folder = realdir;
+ }
+
+
+#else
+ char* res;
+ if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
+ realdir = Glib::path_get_dirname (realdir);
+ cerr << "didn't exist, use " << realdir << endl;
+ }
+
+ if ((res = canonicalize_file_name (realdir.c_str())) != 0) {
+ cerr << "canonical, use " << res << endl;
+ m_folder->set_current_folder (res);
+ engine_page_session_folder = res;
+ free (res);
+ }
+
+#endif
+