]> git.lyx.org Git - lyx.git/blobdiff - src/support/path.h
small changes read ChangeLog
[lyx.git] / src / support / path.h
index ad5a905b4008aa0989d14c68835a515fad08de20..2a2dc0b2161c7695420f4de61de0d920df443181 100644 (file)
@@ -2,23 +2,31 @@
 #ifndef PATH_H
 #define PATH_H
 
-#include <unistd.h>
 #include "LString.h"
-#include "gettext.h"
 #include "support/filetools.h"
-#include "lyx_gui_misc.h"
+#include "lyxlib.h"
 
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+///
 class Path {
 public:
        ///
+       explicit
        Path(string const & path)
                : popped_(false)
        {
                if (!path.empty()) { 
                        pushedDir_ = GetCWD();
-                       if (pushedDir_.empty() || chdir(path.c_str())) {
-                               WriteFSAlert(_("Error: Could not change to directory: "), 
-                                            path);
+                       if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
+                               // should throw an exception
+                               // throw DirChangeError();
+                               // The use of WriteFSAlert makes this
+                               // impossible to inline.
+                               //WriteFSAlert(_("Error: Could not change to directory: "), 
+                               //           path);
                        }
                } else {
                        popped_ = true;
@@ -30,21 +38,7 @@ public:
                if (!popped_) pop();
        }
        ///
-       int pop()
-       {
-               if (popped_) {
-                       WriteFSAlert(_("Error: Dir already popped: "),
-                                    pushedDir_);
-                       return 0;
-               }
-               if (chdir(pushedDir_.c_str())) {
-                       WriteFSAlert(
-                               _("Error: Could not change to directory: "), 
-                               pushedDir_);
-               }
-               popped_ = true;
-               return 0;
-       }
+       int pop();
 private:
        ///
        bool popped_;
@@ -52,4 +46,11 @@ private:
        string pushedDir_;
 };
 
+// To avoid the wrong usage:
+// Path("/tmp");   // wrong
+// Path p("/tmp");  // right
+// we add this macro:
+#define Path(x) unnamed_Path;
+// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
+
 #endif