]> git.lyx.org Git - lyx.git/blob - src/support/path.h
in addition to the changes mentioned in ChangeLog, there is the usual batch of whites...
[lyx.git] / src / support / path.h
1 // -*- C++ -*-
2 #ifndef PATH_H
3 #define PATH_H
4
5 #include <unistd.h>
6 #include "LString.h"
7 #include "gettext.h"
8 #include "support/filetools.h"
9 #include "lyx_gui_misc.h"
10 #include "lyxlib.h"
11
12 class Path {
13 public:
14         ///
15         Path(string const & path)
16                 : popped_(false)
17         {
18                 if (!path.empty()) { 
19                         pushedDir_ = GetCWD();
20                         if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
21                                 WriteFSAlert(_("Error: Could not change to directory: "), 
22                                              path);
23                         }
24                 } else {
25                         popped_ = true;
26                 }
27         }
28         ///
29         ~Path()
30         {
31                 if (!popped_) pop();
32         }
33         ///
34         int pop()
35         {
36                 if (popped_) {
37                         WriteFSAlert(_("Error: Dir already popped: "),
38                                      pushedDir_);
39                         return 0;
40                 }
41                 if (lyx::chdir(pushedDir_.c_str())) {
42                         WriteFSAlert(
43                                 _("Error: Could not change to directory: "), 
44                                 pushedDir_);
45                 }
46                 popped_ = true;
47                 return 0;
48         }
49 private:
50         ///
51         bool popped_;
52         ///
53         string pushedDir_;
54 };
55
56 #endif