]> git.lyx.org Git - lyx.git/blob - src/support/path.h
removed a warning from screen and added CFLAGS in lyx.spec.in.
[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
11 class Path {
12 public:
13         ///
14         Path(string const & path)
15                 : popped_(false)
16         {
17                 if (!path.empty()) { 
18                         pushedDir_ = GetCWD();
19                         if (pushedDir_.empty() || chdir(path.c_str())) {
20                                 WriteFSAlert(_("Error: Could not change to directory: "), 
21                                              path);
22                         }
23                 } else {
24                         popped_ = true;
25                 }
26         }
27         ///
28         ~Path()
29         {
30                 if (!popped_) pop();
31         }
32         ///
33         int pop()
34         {
35                 if (popped_) {
36                         WriteFSAlert(_("Error: Dir already popped: "),
37                                      pushedDir_);
38                         return 0;
39                 }
40                 if (chdir(pushedDir_.c_str())) {
41                         WriteFSAlert(
42                                 _("Error: Could not change to directory: "), 
43                                 pushedDir_);
44                 }
45                 popped_ = true;
46                 return 0;
47         }
48 private:
49         ///
50         bool popped_;
51         ///
52         string pushedDir_;
53 };
54
55 #endif