]> git.lyx.org Git - lyx.git/blobdiff - src/support/path.h
fix typo that put too many include paths for most people
[lyx.git] / src / support / path.h
index 532e808d4f819a9d95a365d5e910c63a3db48152..7059b1a285d325c9def93a6388612889e6dd3582 100644 (file)
@@ -2,24 +2,32 @@
 #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 "filetools.h"
 #include "lyxlib.h"
+#include <boost/utility.hpp>
 
-class Path {
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+///
+class Path : boost::noncopyable {
 public:
        ///
+       explicit
        Path(string const & path)
                : popped_(false)
        {
-               if (!path.empty()) { 
-                       pushedDir_ = GetCWD();
-                       if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
-                               WriteFSAlert(_("Error: Could not change to directory: "), 
-                                            path);
+               if (!path.empty()) {
+                       pushedDir_ = lyx::getcwd(); // GetCWD();
+                       if (pushedDir_.empty() || lyx::chdir(path)) {
+                               // should throw an exception
+                               // throw DirChangeError();
+                               // The use of Alert::err_alert makes this
+                               // impossible to inline.
+                               //Alert::err_alert(_("Error: Could not change to directory: "),
+                               //           path);
                        }
                } else {
                        popped_ = true;
@@ -31,21 +39,7 @@ public:
                if (!popped_) pop();
        }
        ///
-       int pop()
-       {
-               if (popped_) {
-                       WriteFSAlert(_("Error: Dir already popped: "),
-                                    pushedDir_);
-                       return 0;
-               }
-               if (lyx::chdir(pushedDir_.c_str())) {
-                       WriteFSAlert(
-                               _("Error: Could not change to directory: "), 
-                               pushedDir_);
-               }
-               popped_ = true;
-               return 0;
-       }
+       int pop();
 private:
        ///
        bool popped_;
@@ -53,4 +47,12 @@ 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