]> git.lyx.org Git - lyx.git/blob - src/lyxvc.C
fix typo that put too many include paths for most people
[lyx.git] / src / lyxvc.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "lyxvc.h"
8 #include "vc-backend.h"
9 #include "debug.h"
10 #include "buffer.h"
11 #include "BufferView.h"
12 #include "gettext.h"
13 #include "LyXView.h"
14 #include "lyxfunc.h"
15
16 #include "frontends/Alert.h"
17
18 #include "support/filetools.h"
19 #include "support/lyxlib.h"
20
21 #include <unistd.h>
22
23 using std::endl;
24 using std::pair;
25
26 LyXVC::LyXVC()
27 {
28         vcs = 0;
29         owner_ = 0;
30 }
31
32
33 LyXVC::~LyXVC()
34 {
35         delete vcs;
36 }
37
38
39 bool LyXVC::file_found_hook(string const & fn)
40 {
41         string found_file;
42         // Check if file is under RCS
43         if (!(found_file = RCS::find_file(fn)).empty()) {
44                 vcs = new RCS(found_file);
45                 vcs->owner(owner_);
46                 return true;
47         }
48         // Check if file is under CVS
49         if (!(found_file = CVS::find_file(fn)).empty()) {
50                 vcs = new CVS(found_file, fn);
51                 vcs->owner(owner_);
52                 return true;
53         }
54         // file is not under any VCS.
55         return false;
56 }
57
58
59 bool LyXVC::file_not_found_hook(string const & fn)
60 {
61         // Check if file is under RCS
62         if (!RCS::find_file(fn).empty())
63                 return true;
64         if (!CVS::find_file(fn).empty())
65                 return true;
66         return false;
67 }
68
69
70 void LyXVC::buffer(Buffer * buf)
71 {
72         owner_ = buf;
73 }
74
75
76 void LyXVC::registrer()
77 {
78         // it is very likely here that the vcs is not created yet...
79         if (!vcs) {
80                 string const cvs_entries = "CVS/Entries";
81
82                 if (IsFileReadable(cvs_entries)) {
83                         lyxerr[Debug::LYXVC]
84                                 << "LyXVC: registering "
85                                 << MakeDisplayPath(owner_->fileName())
86                                 << " with CVS" << endl;
87                         vcs = new CVS(cvs_entries, owner_->fileName());
88
89                 } else {
90                         lyxerr[Debug::LYXVC]
91                                 << "LyXVC: registering "
92                                 << MakeDisplayPath(owner_->fileName())
93                                 << " with RCS" << endl;
94                         vcs = new RCS(owner_->fileName());
95                 }
96
97                 vcs->owner(owner_);
98         }
99
100         // If the document is changed, we might want to save it
101         if (!vcs->owner()->isLyxClean() &&
102             Alert::askQuestion(_("Changes in document:"),
103                         MakeDisplayPath(vcs->owner()->fileName(), 50),
104                         _("Save document and proceed?"))) {
105                 vcs->owner()->getUser()->owner()
106                         ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
107         }
108
109         // Maybe the save fails, or we answered "no". In both cases,
110         // the document will be dirty, and we abort.
111         if (!vcs->owner()->isLyxClean()) {
112                 return;
113         }
114
115         lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
116         pair<bool, string> tmp =
117                 Alert::askForText(_("LyX VC: Initial description"),
118                            _("(no initial description)"));
119         if (!tmp.first || tmp.second.empty()) {
120                 // should we insist on checking tmp.second.empty()?
121                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
122                 Alert::alert(_("Info"),
123                            _("This document has NOT been registered."));
124                 return;
125         }
126
127         vcs->registrer(tmp.second);
128 }
129
130
131 void LyXVC::checkIn()
132 {
133         // If the document is changed, we might want to save it
134         if (!vcs->owner()->isLyxClean() &&
135             Alert::askQuestion(_("Changes in document:"),
136                         MakeDisplayPath(vcs->owner()->fileName(), 50),
137                         _("Save document and proceed?"))) {
138                 vcs->owner()->getUser()->owner()
139                         ->getLyXFunc()->dispatch(LFUN_MENUWRITE);
140         }
141
142         // Maybe the save fails, or we answered "no". In both cases,
143         // the document will be dirty, and we abort.
144         if (!vcs->owner()->isLyxClean()) {
145                 return;
146         }
147
148         lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
149         pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
150         if (tmp.first) {
151                 if (tmp.second.empty()) {
152                         tmp.second = _("(no log message)");
153                 }
154                 vcs->checkIn(tmp.second);
155         } else {
156                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
157         }
158 }
159
160
161 void LyXVC::checkOut()
162 {
163         lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
164         if (!vcs->owner()->isLyxClean()
165             && !Alert::askQuestion(_("Changes in document:"),
166                            MakeDisplayPath(vcs->owner()->fileName(), 50),
167                            _("Ignore changes and proceed with check out?"))) {
168                 return;
169         }
170
171         vcs->checkOut();
172
173 }
174
175
176 void LyXVC::revert()
177 {
178         lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
179         // Here we should check if the buffer is dirty. And if it is
180         // we should warn the user that reverting will discard all
181         // changes made since the last check in.
182         if (Alert::askQuestion(_("When you revert, you will loose all changes made"),
183                         _("to the document since the last check in."),
184                         _("Do you still want to do it?"))) {
185
186                 vcs->revert();
187         }
188 }
189
190
191 void LyXVC::undoLast()
192 {
193         vcs->undoLast();
194 }
195
196
197 void LyXVC::toggleReadOnly()
198 {
199         switch (vcs->status()) {
200         case VCS::UNLOCKED:
201                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
202                 checkOut();
203                 break;
204         case VCS::LOCKED:
205                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
206                 checkIn();
207                 break;
208         }
209 }
210
211
212 bool LyXVC::inUse()
213 {
214         if (vcs) return true;
215         return false;
216 }
217
218
219 //string const & LyXVC::version() const
220 //{
221 //      return vcs->version();
222 //}
223
224 string const LyXVC::versionString() const
225 {
226         return vcs->versionString();
227 }
228
229
230 string const & LyXVC::locker() const
231 {
232         return vcs->locker();
233 }
234
235
236 const string LyXVC::getLogFile() const
237 {
238         if (!vcs)
239                 return string();
240
241         string tmpf = lyx::tempName(string(), "lyxvclog");
242         lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
243         vcs->getLog(tmpf);
244         return tmpf;
245 }