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, owner_));
56 // Check if file is under CVS
57 if (!(found_file = CVS::findFile(fn)).empty()) {
58 vcs.reset(new CVS(found_file, owner_));
61 // Check if file is under SVN
62 if (!(found_file = SVN::findFile(fn)).empty()) {
63 vcs.reset(new SVN(found_file, owner_));
67 // file is not under any VCS.
73 bool LyXVC::file_not_found_hook(FileName const & fn)
75 // Check if file is under RCS.
76 // This happens if we are trying to load non existent
77 // file on disk, but existent in ,v version.
78 // Seems there is no reasonable scenario for adding implementation
79 // of retrieve for cvs or svn.
80 if (!RCS::findFile(fn).empty()) {
81 docstring const file = makeDisplayPath(fn.absFileName(), 20);
82 docstring const text =
83 bformat(_("Do you want to retrieve the document"
84 " %1$s from version control?"), file);
85 int const ret = Alert::prompt(_("Retrieve from version control?"),
86 text, 0, 1, _("&Retrieve"), _("&Cancel"));
89 // How can we know _how_ to do the checkout?
90 // With the current VC support it has to be an RCS
91 // file since CVS and SVN do not have special ,v files.
100 void LyXVC::setBuffer(Buffer * buf)
106 bool LyXVC::registrer()
108 FileName const filename = owner_->fileName();
110 // there must be a file to save
111 if (!filename.isReadableFile()) {
112 Alert::error(_("Document not saved"),
113 _("You must save the document "
114 "before it can be registered."));
118 // it is very likely here that the vcs is not created yet...
120 //check in the root directory of the document
121 FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
122 FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
124 if (svn_entries.isReadableFile()) {
125 LYXERR(Debug::LYXVC, "LyXVC: registering "
126 << to_utf8(filename.displayName()) << " with SVN");
127 vcs.reset(new SVN(cvs_entries, owner_));
129 } else if (cvs_entries.isReadableFile()) {
130 LYXERR(Debug::LYXVC, "LyXVC: registering "
131 << to_utf8(filename.displayName()) << " with CVS");
132 vcs.reset(new CVS(cvs_entries, owner_));
135 LYXERR(Debug::LYXVC, "LyXVC: registering "
136 << to_utf8(filename.displayName()) << " with RCS");
137 vcs.reset(new RCS(FileName(), owner_));
141 LYXERR(Debug::LYXVC, "LyXVC: registrer");
143 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
144 _("(no initial description)"));
146 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
150 if (response.empty())
151 response = _("(no initial description)");
152 vcs->registrer(to_utf8(response));
157 string LyXVC::checkIn()
159 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
160 docstring empty(_("(no log message)"));
164 if (vcs->isCheckInWithConfirmation())
165 ok = Alert::askForText(response, _("LyX VC: Log Message"));
167 if (response.empty())
170 response = subst(response, from_utf8("\""), from_utf8("\\\""));
171 log = vcs->checkIn(to_utf8(response));
173 // Reserve empty string for cancel button
175 log = to_utf8(empty);
177 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
183 string LyXVC::checkOut()
185 //RCS allows checkOut only in ReadOnly mode
186 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
189 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
190 return vcs->checkOut();
194 string LyXVC::repoUpdate()
196 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
197 return vcs->repoUpdate();
201 string LyXVC::lockingToggle()
203 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
204 return vcs->lockingToggle();
210 LYXERR(Debug::LYXVC, "LyXVC: revert");
212 docstring const file = owner_->fileName().displayName(20);
213 docstring text = bformat(_("Reverting to the stored version of the "
214 "document %1$s will lose all current changes.\n\n"
215 "Do you want to revert to the older version?"), file);
217 if (vcs->isRevertWithConfirmation())
218 ret = Alert::prompt(_("Revert to stored version of document?"),
219 text, 0, 1, _("&Revert"), _("&Cancel"));
221 return ret == 0 && vcs->revert();
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();