]> git.lyx.org Git - lyx.git/blob - src/lyxvc.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / lyxvc.C
1 #include <config.h>
2
3 #include "lyxvc.h"
4 #include "vc-backend.h"
5 #include "debug.h"
6 #include "buffer.h"
7 #include "gettext.h"
8 #include "funcrequest.h"
9
10 #include "frontends/Alert.h"
11 #include "frontends/LyXView.h"
12
13 #include "support/filetools.h"
14 #include "support/lyxlib.h"
15
16 #include <unistd.h>
17
18 using namespace lyx::support;
19
20 using std::endl;
21 using std::pair;
22
23
24 LyXVC::LyXVC()
25 {
26         vcs = 0;
27         owner_ = 0;
28 }
29
30
31 LyXVC::~LyXVC()
32 {
33         delete vcs;
34 }
35
36
37 bool LyXVC::file_found_hook(string const & fn)
38 {
39         string found_file;
40         // Check if file is under RCS
41         if (!(found_file = RCS::find_file(fn)).empty()) {
42                 vcs = new RCS(found_file);
43                 vcs->owner(owner_);
44                 return true;
45         }
46         // Check if file is under CVS
47         if (!(found_file = CVS::find_file(fn)).empty()) {
48                 vcs = new CVS(found_file, fn);
49                 vcs->owner(owner_);
50                 return true;
51         }
52         // file is not under any VCS.
53         return false;
54 }
55
56
57 bool LyXVC::file_not_found_hook(string const & fn)
58 {
59         // Check if file is under RCS
60         if (!RCS::find_file(fn).empty())
61                 return true;
62         if (!CVS::find_file(fn).empty())
63                 return true;
64         return false;
65 }
66
67
68 void LyXVC::buffer(Buffer * buf)
69 {
70         owner_ = buf;
71 }
72
73
74 void LyXVC::registrer()
75 {
76         string const filename = owner_->fileName();
77
78         // there must be a file to save
79         if (!IsFileReadable(filename)) {
80                 Alert::error(_("Document not saved"),
81                              _("You must save the document "
82                                "before it can be registered."));
83                 return;
84         }
85
86         // it is very likely here that the vcs is not created yet...
87         if (!vcs) {
88                 string const cvs_entries = "CVS/Entries";
89
90                 if (IsFileReadable(cvs_entries)) {
91                         lyxerr[Debug::LYXVC]
92                                 << "LyXVC: registering "
93                                 << MakeDisplayPath(filename)
94                                 << " with CVS" << endl;
95                         vcs = new CVS(cvs_entries, filename);
96
97                 } else {
98                         lyxerr[Debug::LYXVC]
99                                 << "LyXVC: registering "
100                                 << MakeDisplayPath(filename)
101                                 << " with RCS" << endl;
102                         vcs = new RCS(filename);
103                 }
104
105                 vcs->owner(owner_);
106         }
107
108         lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
109         pair<bool, string> tmp =
110                 Alert::askForText(_("LyX VC: Initial description"),
111                            _("(no initial description)"));
112         if (!tmp.first || tmp.second.empty()) {
113                 // should we insist on checking tmp.second.empty()?
114                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
115                 return;
116         }
117
118         vcs->registrer(tmp.second);
119 }
120
121
122 void LyXVC::checkIn()
123 {
124
125         lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
126         pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
127         if (tmp.first) {
128                 if (tmp.second.empty()) {
129                         tmp.second = _("(no log message)");
130                 }
131                 vcs->checkIn(tmp.second);
132         } else {
133                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
134         }
135 }
136
137
138 void LyXVC::checkOut()
139 {
140         lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
141
142         vcs->checkOut();
143 }
144
145
146 void LyXVC::revert()
147 {
148         lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
149
150         string const file = MakeDisplayPath(owner_->fileName(), 20);
151         string text = bformat(_("Reverting to the stored version of the "
152                 "document %1$s will lose all current changes.\n\n"
153                 "Do you want to revert to the saved version?"), file);
154         int const ret = Alert::prompt(_("Revert to stored version of document?"),
155                 text, 0, 1, _("&Revert"), _("&Cancel"));
156
157         if (ret == 0)
158                 vcs->revert();
159 }
160
161
162 void LyXVC::undoLast()
163 {
164         vcs->undoLast();
165 }
166
167
168 void LyXVC::toggleReadOnly()
169 {
170         switch (vcs->status()) {
171         case VCS::UNLOCKED:
172                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
173                 checkOut();
174                 break;
175         case VCS::LOCKED:
176                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
177                 checkIn();
178                 break;
179         }
180 }
181
182
183 bool LyXVC::inUse()
184 {
185         if (vcs) return true;
186         return false;
187 }
188
189
190 //string const & LyXVC::version() const
191 //{
192 //      return vcs->version();
193 //}
194
195 string const LyXVC::versionString() const
196 {
197         return vcs->versionString();
198 }
199
200
201 string const & LyXVC::locker() const
202 {
203         return vcs->locker();
204 }
205
206
207 string const LyXVC::getLogFile() const
208 {
209         if (!vcs)
210                 return string();
211
212         string tmpf = tempName(string(), "lyxvclog");
213         lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;
214         vcs->getLog(tmpf);
215         return tmpf;
216 }