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())
88 void LyXVC::setBuffer(Buffer * buf)
94 bool LyXVC::registrer()
96 FileName const filename = owner_->fileName();
98 // there must be a file to save
99 if (!filename.isReadableFile()) {
100 Alert::error(_("Document not saved"),
101 _("You must save the document "
102 "before it can be registered."));
106 // it is very likely here that the vcs is not created yet...
108 //check in the root directory of the document
109 FileName const cvs_entries(onlyPath(filename.absFilename()) + "/CVS/Entries");
110 FileName const svn_entries(onlyPath(filename.absFilename()) + "/.svn/entries");
112 if (svn_entries.isReadableFile()) {
113 LYXERR(Debug::LYXVC, "LyXVC: registering "
114 << to_utf8(filename.displayName()) << " with SVN");
115 vcs.reset(new SVN(cvs_entries, filename));
117 } else if (cvs_entries.isReadableFile()) {
118 LYXERR(Debug::LYXVC, "LyXVC: registering "
119 << to_utf8(filename.displayName()) << " with CVS");
120 vcs.reset(new CVS(cvs_entries, filename));
123 LYXERR(Debug::LYXVC, "LyXVC: registering "
124 << to_utf8(filename.displayName()) << " with RCS");
125 vcs.reset(new RCS(FileName()));
131 LYXERR(Debug::LYXVC, "LyXVC: registrer");
133 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
134 _("(no initial description)"));
136 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
139 if (response.empty())
140 response = _("(no initial description)");
141 vcs->registrer(to_utf8(response));
146 string LyXVC::checkIn()
148 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
151 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
153 if (response.empty())
154 response = _("(no log message)");
155 log = vcs->checkIn(to_utf8(response));
157 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
163 string LyXVC::checkOut()
165 //RCS allows checkOut only in ReadOnly mode
166 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly()) return string();
168 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
169 return vcs->checkOut();
175 LYXERR(Debug::LYXVC, "LyXVC: revert");
177 docstring const file = owner_->fileName().displayName(20);
178 docstring text = bformat(_("Reverting to the stored version of the "
179 "document %1$s will lose all current changes.\n\n"
180 "Do you want to revert to the older version?"), file);
181 int const ret = Alert::prompt(_("Revert to stored version of document?"),
182 text, 0, 1, _("&Revert"), _("&Cancel"));
189 void LyXVC::undoLast()
195 void LyXVC::toggleReadOnly()
197 if (!vcs->toggleReadOnlyEnabled())
200 switch (vcs->status()) {
202 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
206 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
221 //string const & LyXVC::version() const
223 // return vcs->version();
227 string const LyXVC::versionString() const
229 return vcs->versionString();
233 string const & LyXVC::locker() const
235 return vcs->locker();
239 string const LyXVC::getLogFile() const
244 FileName const tmpf = FileName::tempName("lyxvclog");
246 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
249 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
251 return tmpf.absFilename();
255 bool LyXVC::checkOutEnabled()
257 return vcs && vcs->checkOutEnabled();
261 bool LyXVC::checkInEnabled()
263 return vcs && vcs->checkInEnabled();
267 bool LyXVC::undoLastEnabled()
269 return vcs && vcs->undoLastEnabled();