]> git.lyx.org Git - features.git/blob - src/pathstack.C
last updates from 1.0.4, no more updates expected from that branch now
[features.git] / src / pathstack.C
1 // lyx-stack.C : implementation of PathStack class
2 //   this file is part of LyX, the High Level Word Processor
3 //   copyright (C) 1995-1996, Matthias Ettrich and the LyX Team
4
5 #include <config.h>
6 #include <unistd.h>
7
8 #ifdef __GNUG__
9 #pragma implementation "pathstack.h"
10 #endif
11
12 #include "pathstack.h"
13 #include "filetools.h"
14 #include "error.h"
15 #include "LString.h"
16 #include "gettext.h"
17
18 // temporary hack
19 #include "lyx_gui_misc.h"
20
21 //      $Id: pathstack.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $ 
22
23 #if !defined(lint) && !defined(WITH_WARNINGS)
24 static char vcid[] = "$Id: pathstack.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
25 #endif /* lint */
26
27 // global path stack
28 PathStack lyxPathStack;
29
30 // Standard constructor
31 PathStack::PathStack(LString const & string)
32         : Path(string)
33 {
34         Next = NULL;
35 }
36
37 // Destructor
38 PathStack::~PathStack()
39 {
40         if (Next)
41                 delete Next;
42 }
43
44 // Changes to directory
45 int PathStack::PathPush(LString const & Path)
46 {
47         // checks path string validity
48         if (Path.empty()) return 1;
49
50         PathStack *NewNode;
51
52         // gets current directory and switch to new one
53         LString CurrentPath = GetCWD();
54         if ((CurrentPath.empty()) || chdir(Path.c_str())) {
55                 WriteFSAlert(_("Error: Could not change to directory: "), 
56                              Path);
57                 return 2;
58         }
59
60         lyxerr.debug("PathPush: " + Path);
61         // adds new node
62         NewNode = new PathStack(CurrentPath);
63         NewNode->Next = Next;
64         Next = NewNode;
65         return 0;
66 }
67
68 // Goes back to previous directory
69 int PathStack::PathPop()
70 {
71         // checks stack validity and extracts old node
72         PathStack *OldNode = Next;
73         if (!OldNode) {
74                 WriteAlert (_("LyX Internal Error:"), _("Path Stack underflow."));
75                 return 1;
76         }
77         Next = OldNode->Next;
78         OldNode->Next = NULL;
79
80         // switches to old directory
81         int Result = 0;
82         if (chdir(OldNode->Path.c_str())) {
83                 WriteFSAlert(_("Error: Could not change to directory: "), 
84                              Path);
85                 Result = 2;
86         }
87         lyxerr.debug("PathPop: " + OldNode->Path);
88         delete OldNode;
89
90         return Result;
91 }
92