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)"));
169 if (vcs->isCheckInWithConfirmation())
170 ok = Alert::askForText(response, _("LyX VC: Log Message"));
172 if (response.empty())
175 response = subst(response, from_utf8("\""), from_utf8("\\\""));
176 log = vcs->checkIn(to_utf8(response));
178 // Reserve empty string for cancel button
180 log = to_utf8(empty);
182 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
188 string LyXVC::checkOut()
190 //RCS allows checkOut only in ReadOnly mode
191 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
194 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
195 return vcs->checkOut();
199 string LyXVC::repoUpdate()
201 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
202 return vcs->repoUpdate();
206 string LyXVC::lockingToggle()
208 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
209 return vcs->lockingToggle();
215 LYXERR(Debug::LYXVC, "LyXVC: revert");
217 docstring const file = owner_->fileName().displayName(20);
218 docstring text = bformat(_("Reverting to the stored version of the "
219 "document %1$s will lose all current changes.\n\n"
220 "Do you want to revert to the older version?"), file);
222 if (vcs->isRevertWithConfirmation())
223 ret = Alert::prompt(_("Revert to stored version of document?"),
224 text, 0, 1, _("&Revert"), _("&Cancel"));
226 return ret == 0 && vcs->revert();
230 void LyXVC::undoLast()
236 void LyXVC::toggleReadOnly()
238 if (!vcs->toggleReadOnlyEnabled())
241 switch (vcs->status()) {
243 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
247 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
256 bool LyXVC::inUse() const
264 string const LyXVC::versionString() const
266 return vcs->versionString();
270 bool LyXVC::locking() const
272 return vcs->status() != VCS::NOLOCKING;
276 string const LyXVC::getLogFile() const
281 FileName const tmpf = FileName::tempName("lyxvclog");
283 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
286 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
288 return tmpf.absFileName();
292 string LyXVC::revisionInfo(RevisionInfo const info) const
297 return vcs->revisionInfo(info);
301 bool LyXVC::checkOutEnabled() const
303 return vcs && vcs->checkOutEnabled();
307 bool LyXVC::checkInEnabled() const
309 return vcs && vcs->checkInEnabled();
313 bool LyXVC::lockingToggleEnabled() const
315 return vcs && vcs->lockingToggleEnabled();
319 bool LyXVC::undoLastEnabled() const
321 return vcs && vcs->undoLastEnabled();
325 bool LyXVC::repoUpdateEnabled() const
327 return vcs && vcs->repoUpdateEnabled();
331 bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
333 return vcs && vcs->prepareFileRevision(rev, f);
337 bool LyXVC::prepareFileRevisionEnabled()
339 return vcs && vcs->prepareFileRevisionEnabled();