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.
75 bool LyXVC::file_not_found_hook(FileName const & fn)
77 // Check if file is under RCS.
78 // This happens if we are trying to load non existent
79 // file on disk, but existent in ,v version.
80 // Seems there is no reasonable scenario for adding implementation
81 // of retrieve for cvs or svn.
82 if (!RCS::findFile(fn).empty()) {
83 docstring const file = makeDisplayPath(fn.absFileName(), 20);
84 docstring const text =
85 bformat(_("Do you want to retrieve the document"
86 " %1$s from version control?"), file);
87 int const ret = Alert::prompt(_("Retrieve from version control?"),
88 text, 0, 1, _("&Retrieve"), _("&Cancel"));
91 // How can we know _how_ to do the checkout?
92 // With the current VC support it has to be an RCS
93 // file since CVS and SVN do not have special ,v files.
102 void LyXVC::setBuffer(Buffer * buf)
108 bool LyXVC::registrer()
110 FileName const filename = owner_->fileName();
112 // there must be a file to save
113 if (!filename.isReadableFile()) {
114 Alert::error(_("Document not saved"),
115 _("You must save the document "
116 "before it can be registered."));
120 // it is very likely here that the vcs is not created yet...
122 //check in the root directory of the document
123 FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries");
124 FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries");
126 if (svn_entries.isReadableFile()) {
127 LYXERR(Debug::LYXVC, "LyXVC: registering "
128 << to_utf8(filename.displayName()) << " with SVN");
129 vcs.reset(new SVN(cvs_entries, filename));
131 } else if (cvs_entries.isReadableFile()) {
132 LYXERR(Debug::LYXVC, "LyXVC: registering "
133 << to_utf8(filename.displayName()) << " with CVS");
134 vcs.reset(new CVS(cvs_entries, filename));
137 LYXERR(Debug::LYXVC, "LyXVC: registering "
138 << to_utf8(filename.displayName()) << " with RCS");
139 vcs.reset(new RCS(FileName()));
145 LYXERR(Debug::LYXVC, "LyXVC: registrer");
147 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
148 _("(no initial description)"));
150 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
153 if (response.empty())
154 response = _("(no initial description)");
155 vcs->registrer(to_utf8(response));
160 string LyXVC::checkIn()
162 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
163 docstring empty(_("(no log message)"));
166 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
168 if (response.empty())
170 log = vcs->checkIn(to_utf8(response));
172 // Reserve empty string for cancel button
174 log = to_utf8(empty);
176 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
182 string LyXVC::checkOut()
184 //RCS allows checkOut only in ReadOnly mode
185 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly())
188 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
189 return vcs->checkOut();
193 string LyXVC::repoUpdate()
195 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
196 return vcs->repoUpdate();
200 string LyXVC::lockingToggle()
202 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
203 return vcs->lockingToggle();
209 LYXERR(Debug::LYXVC, "LyXVC: revert");
211 docstring const file = owner_->fileName().displayName(20);
212 docstring text = bformat(_("Reverting to the stored version of the "
213 "document %1$s will lose all current changes.\n\n"
214 "Do you want to revert to the older version?"), file);
215 int const ret = Alert::prompt(_("Revert to stored version of document?"),
216 text, 0, 1, _("&Revert"), _("&Cancel"));
223 void LyXVC::undoLast()
229 void LyXVC::toggleReadOnly()
231 if (!vcs->toggleReadOnlyEnabled())
234 switch (vcs->status()) {
236 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
240 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
249 bool LyXVC::inUse() const
257 string const LyXVC::versionString() const
259 return vcs->versionString();
263 bool LyXVC::locking() const
265 return vcs->status() != VCS::NOLOCKING;
269 string const LyXVC::getLogFile() const
274 FileName const tmpf = FileName::tempName("lyxvclog");
276 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
279 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
281 return tmpf.absFileName();
285 std::string LyXVC::revisionInfo(RevisionInfo const info)
290 return vcs->revisionInfo(info);
294 bool LyXVC::checkOutEnabled() const
296 return vcs && vcs->checkOutEnabled();
300 bool LyXVC::checkInEnabled() const
302 return vcs && vcs->checkInEnabled();
306 bool LyXVC::lockingToggleEnabled() const
308 return vcs && vcs->lockingToggleEnabled();
312 bool LyXVC::undoLastEnabled() const
314 return vcs && vcs->undoLastEnabled();
317 bool LyXVC::prepareFileRevision(string const & rev, std::string & f)
319 return vcs && vcs->prepareFileRevision(rev, f);
323 bool LyXVC::prepareFileRevisionEnabled()
325 return vcs && vcs->prepareFileRevisionEnabled();