]> git.lyx.org Git - lyx.git/blob - src/support/path.h
fix the smallcaps drawing, move xfont metrics functions out from LyXFont, move non...
[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         Path(string const & path)
18                 : popped_(false)
19         {
20                 if (!path.empty()) { 
21                         pushedDir_ = GetCWD();
22                         if (pushedDir_.empty() || lyx::chdir(path.c_str())) {
23                                 // should throw an exception
24                                 // throw DirChangeError();
25                                 // The use of WriteFSAlert makes this
26                                 // impossible to inline.
27                                 //WriteFSAlert(_("Error: Could not change to directory: "), 
28                                 //           path);
29                         }
30                 } else {
31                         popped_ = true;
32                 }
33         }
34         ///
35         ~Path()
36         {
37                 if (!popped_) pop();
38         }
39         ///
40         int pop();
41 private:
42         ///
43         bool popped_;
44         ///
45         string pushedDir_;
46 };
47
48 // To avoid the wrong usage:
49 // Path("/tmp");   // wrong
50 // Path p("/tmp");  // right
51 // we add this macro:
52 #define Path(x) unnamed_Path;
53 // Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
54
55 #endif