]> git.lyx.org Git - lyx.git/blob - src/support/path.h
Fix the line-delete-forward bug?
[lyx.git] / src / support / path.h
1 // -*- C++ -*-
2 #ifndef PATH_H
3 #define PATH_H
4
5 #include "LString.h"
6 #include "support/filetools.h"
7 #include "lyxlib.h"
8
9 #ifdef __GNUG__
10 #pragma interface
11 #endif
12
13 ///
14 class Path {
15 public:
16         ///
17         explicit
18         Path(string const & path)
19                 : popped_(false)
20         {
21                 if (!path.empty()) { 
22                         pushedDir_ = GetCWD();
23                         if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
24                                 // should throw an exception
25                                 // throw DirChangeError();
26                                 // The use of WriteFSAlert makes this
27                                 // impossible to inline.
28                                 //WriteFSAlert(_("Error: Could not change to directory: "), 
29                                 //           path);
30                         }
31                 } else {
32                         popped_ = true;
33                 }
34         }
35         ///
36         ~Path()
37         {
38                 if (!popped_) pop();
39         }
40         ///
41         int pop();
42 private:
43         ///
44         bool popped_;
45         ///
46         string pushedDir_;
47 };
48
49 // To avoid the wrong usage:
50 // Path("/tmp");   // wrong
51 // Path p("/tmp");  // right
52 // we add this macro:
53 #define Path(x) unnamed_Path;
54 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
55
56 #endif