3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
10 * \author André Pönitz
13 * Full author contact details are available in file CREDITS.
19 #include "VCBackend.h"
22 #include "frontends/alert.h"
24 #include "support/debug.h"
25 #include "support/filetools.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
30 using namespace lyx::support;
34 namespace Alert = frontend::Alert;
43 // for the sake of boost::scoped_ptr
48 bool LyXVC::file_found_hook(FileName const & fn)
51 // Check if file is under RCS
52 if (!(found_file = RCS::findFile(fn)).empty()) {
53 vcs.reset(new RCS(found_file));
57 // Check if file is under CVS
58 if (!(found_file = CVS::findFile(fn)).empty()) {
59 vcs.reset(new CVS(found_file, fn));
63 // Check if file is under SVN
64 if (!(found_file = SVN::findFile(fn)).empty()) {
65 vcs.reset(new SVN(found_file, fn));
70 // file is not under any VCS.
76 bool LyXVC::file_not_found_hook(FileName const & fn)
78 // Check if file is under RCS.
79 // This happens if we are trying to load non existent
80 // file on disk, but existent in ,v version.
81 // Seems there is no reasonable scenario for adding implementation
82 // of retrieve for cvs or svn.
83 if (!RCS::findFile(fn).empty()) {
84 docstring const file = makeDisplayPath(fn.absFileName(), 20);
85 docstring const text =
86 bformat(_("Do you want to retrieve the document"
87 " %1$s from version control?"), file);
88 int const ret = Alert::prompt(_("Retrieve from version control?"),
89 text, 0, 1, _("&Retrieve"), _("&Cancel"));
92 // How can we know _how_ to do the checkout?
93 // With the current VC support it has to be an RCS
94 // file since CVS and SVN do not have special ,v files.
103 void LyXVC::setBuffer(Buffer * buf)
109 bool LyXVC::registrer()
111 FileName const filename = owner_->fileName();
113 // there must be a file to save
114 if (!filename.isReadableFile()) {
115 Alert::error(_("Document not saved"),
116 _("You must save the document "
117 "before it can be registered."));
121 // it is very likely here that the vcs is not created yet...
123 //check in the root directory of the document
124 FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
125 FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
127 if (svn_entries.isReadableFile()) {
128 LYXERR(Debug::LYXVC, "LyXVC: registering "
129 << to_utf8(filename.displayName()) << " with SVN");
130 vcs.reset(new SVN(cvs_entries, filename));
132 } else if (cvs_entries.isReadableFile()) {
133 LYXERR(Debug::LYXVC, "LyXVC: registering "
134 << to_utf8(filename.displayName()) << " with CVS");
135 vcs.reset(new CVS(cvs_entries, filename));
138 LYXERR(Debug::LYXVC, "LyXVC: registering "
139 << to_utf8(filename.displayName()) << " with RCS");
140 vcs.reset(new RCS(FileName()));
146 LYXERR(Debug::LYXVC, "LyXVC: registrer");
148 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
149 _("(no initial description)"));
151 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
155 if (response.empty())
156 response = _("(no initial description)");
157 vcs->registrer(to_utf8(response));
162 string LyXVC::checkIn()
164 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
165 docstring empty(_("(no log message)"));
168 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
170 if (response.empty())
172 log = vcs->checkIn(to_utf8(response));
174 // Reserve empty string for cancel button
176 log = to_utf8(empty);
178 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
184 string LyXVC::checkOut()
186 //RCS allows checkOut only in ReadOnly mode
187 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
190 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
191 return vcs->checkOut();
195 string LyXVC::repoUpdate()
197 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
198 return vcs->repoUpdate();
202 string LyXVC::lockingToggle()
204 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
205 return vcs->lockingToggle();
211 LYXERR(Debug::LYXVC, "LyXVC: revert");
213 docstring const file = owner_->fileName().displayName(20);
214 docstring text = bformat(_("Reverting to the stored version of the "
215 "document %1$s will lose all current changes.\n\n"
216 "Do you want to revert to the older version?"), file);
217 int const ret = Alert::prompt(_("Revert to stored version of document?"),
218 text, 0, 1, _("&Revert"), _("&Cancel"));
225 void LyXVC::undoLast()
231 void LyXVC::toggleReadOnly()
233 if (!vcs->toggleReadOnlyEnabled())
236 switch (vcs->status()) {
238 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
242 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
251 bool LyXVC::inUse() const
259 string const LyXVC::versionString() const
261 return vcs->versionString();
265 bool LyXVC::locking() const
267 return vcs->status() != VCS::NOLOCKING;
271 string const LyXVC::getLogFile() const
276 FileName const tmpf = FileName::tempName("lyxvclog");
278 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
281 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
283 return tmpf.absFileName();
287 string LyXVC::revisionInfo(RevisionInfo const info) const
292 return vcs->revisionInfo(info);
296 bool LyXVC::checkOutEnabled() const
298 return vcs && vcs->checkOutEnabled();
302 bool LyXVC::checkInEnabled() const
304 return vcs && vcs->checkInEnabled();
308 bool LyXVC::lockingToggleEnabled() const
310 return vcs && vcs->lockingToggleEnabled();
314 bool LyXVC::undoLastEnabled() const
316 return vcs && vcs->undoLastEnabled();
320 bool LyXVC::repoUpdateEnabled() const
322 return vcs && vcs->repoUpdateEnabled();
326 bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
328 return vcs && vcs->prepareFileRevision(rev, f);
332 bool LyXVC::prepareFileRevisionEnabled()
334 return vcs && vcs->prepareFileRevisionEnabled();