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::fileInVC(FileName const & fn)
50 if (!RCS::findFile(fn).empty())
52 if (!CVS::findFile(fn).empty())
54 if (!SVN::findFile(fn).empty())
60 bool LyXVC::file_found_hook(FileName const & fn)
63 // Check if file is under RCS
64 if (!(found_file = RCS::findFile(fn)).empty()) {
65 vcs.reset(new RCS(found_file, owner_));
68 // Check if file is under CVS
69 if (!(found_file = CVS::findFile(fn)).empty()) {
70 vcs.reset(new CVS(found_file, owner_));
73 // Check if file is under SVN
74 if (!(found_file = SVN::findFile(fn)).empty()) {
75 vcs.reset(new SVN(found_file, owner_));
79 // file is not under any VCS.
85 bool LyXVC::file_not_found_hook(FileName const & fn)
87 // Check if file is under RCS.
88 // This happens if we are trying to load non existent
89 // file on disk, but existent in ,v version.
90 bool foundRCS = !RCS::findFile(fn).empty();
91 bool foundCVS = foundRCS ? false : !CVS::findFile(fn).empty();
92 bool foundSVN = (foundRCS || foundCVS) ? false : !SVN::findFile(fn).empty();
93 if (foundRCS || foundCVS || foundSVN) {
94 docstring const file = makeDisplayPath(fn.absFileName(), 20);
95 docstring const text =
96 bformat(_("Do you want to retrieve the document"
97 " %1$s from version control?"), file);
98 int const ret = Alert::prompt(_("Retrieve from version control?"),
99 text, 0, 1, _("&Retrieve"), _("&Cancel"));
102 // Since the retrieve commands are implemented using
103 // more general update commands we need to ensure that
104 // we do not change an existing file by accident.
108 return RCS::retrieve(fn);
110 return CVS::retrieve(fn);
112 return SVN::retrieve(fn);
119 void LyXVC::setBuffer(Buffer * buf)
125 bool LyXVC::registrer()
127 FileName const filename = owner_->fileName();
129 // there must be a file to save
130 if (!filename.isReadableFile()) {
131 Alert::error(_("Document not saved"),
132 _("You must save the document "
133 "before it can be registered."));
137 // it is very likely here that the vcs is not created yet...
139 //check in the root directory of the document
140 FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
141 FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
143 if (svn_entries.isReadableFile()) {
144 LYXERR(Debug::LYXVC, "LyXVC: registering "
145 << to_utf8(filename.displayName()) << " with SVN");
146 vcs.reset(new SVN(cvs_entries, owner_));
148 } else if (cvs_entries.isReadableFile()) {
149 LYXERR(Debug::LYXVC, "LyXVC: registering "
150 << to_utf8(filename.displayName()) << " with CVS");
151 vcs.reset(new CVS(cvs_entries, owner_));
154 LYXERR(Debug::LYXVC, "LyXVC: registering "
155 << to_utf8(filename.displayName()) << " with RCS");
156 vcs.reset(new RCS(FileName(), owner_));
160 LYXERR(Debug::LYXVC, "LyXVC: registrer");
162 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
163 _("(no initial description)"));
165 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
169 if (response.empty())
170 response = _("(no initial description)");
171 vcs->registrer(to_utf8(response));
176 string LyXVC::checkIn()
178 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
179 docstring empty(_("(no log message)"));
183 if (vcs->isCheckInWithConfirmation())
184 ok = Alert::askForText(response, _("LyX VC: Log Message"));
186 if (response.empty())
189 response = subst(response, from_utf8("\""), from_utf8("\\\""));
190 log = vcs->checkIn(to_utf8(response));
192 // Reserve empty string for cancel button
194 log = to_utf8(empty);
196 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
202 string LyXVC::checkOut()
204 //RCS allows checkOut only in ReadOnly mode
205 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
208 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
209 return vcs->checkOut();
213 string LyXVC::repoUpdate()
215 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
216 return vcs->repoUpdate();
220 string LyXVC::lockingToggle()
222 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
223 return vcs->lockingToggle();
229 LYXERR(Debug::LYXVC, "LyXVC: revert");
231 docstring const file = owner_->fileName().displayName(20);
232 docstring text = bformat(_("Reverting to the stored version of the "
233 "document %1$s will lose all current changes.\n\n"
234 "Do you want to revert to the older version?"), file);
236 if (vcs->isRevertWithConfirmation())
237 ret = Alert::prompt(_("Revert to stored version of document?"),
238 text, 0, 1, _("&Revert"), _("&Cancel"));
240 return ret == 0 && vcs->revert();
244 void LyXVC::undoLast()
250 void LyXVC::toggleReadOnly()
252 if (!vcs->toggleReadOnlyEnabled())
255 switch (vcs->status()) {
257 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
261 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
270 bool LyXVC::inUse() const
278 string const LyXVC::versionString() const
280 return vcs->versionString();
284 bool LyXVC::locking() const
286 return vcs->status() != VCS::NOLOCKING;
290 string const LyXVC::getLogFile() const
295 FileName const tmpf = FileName::tempName("lyxvclog");
297 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
300 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
302 return tmpf.absFileName();
306 string LyXVC::revisionInfo(RevisionInfo const info) const
311 return vcs->revisionInfo(info);
315 bool LyXVC::checkOutEnabled() const
317 return vcs && vcs->checkOutEnabled();
321 bool LyXVC::checkInEnabled() const
323 return vcs && vcs->checkInEnabled();
327 bool LyXVC::lockingToggleEnabled() const
329 return vcs && vcs->lockingToggleEnabled();
333 bool LyXVC::undoLastEnabled() const
335 return vcs && vcs->undoLastEnabled();
339 bool LyXVC::repoUpdateEnabled() const
341 return vcs && vcs->repoUpdateEnabled();
345 bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
347 return vcs && vcs->prepareFileRevision(rev, f);
351 bool LyXVC::prepareFileRevisionEnabled()
353 return vcs && vcs->prepareFileRevisionEnabled();