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");
165 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
167 if (response.empty())
168 response = _("(no log message)");
169 log = vcs->checkIn(to_utf8(response));
171 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
177 string LyXVC::checkOut()
179 //RCS allows checkOut only in ReadOnly mode
180 if (vcs->toggleReadOnlyEnabled() && !owner_->isReadonly()) return string();
182 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
183 return vcs->checkOut();
187 string LyXVC::repoUpdate()
189 LYXERR(Debug::LYXVC, "LyXVC: repoUpdate");
190 return vcs->repoUpdate();
194 string LyXVC::lockingToggle()
196 LYXERR(Debug::LYXVC, "LyXVC: toggle locking property");
197 return vcs->lockingToggle();
203 LYXERR(Debug::LYXVC, "LyXVC: revert");
205 docstring const file = owner_->fileName().displayName(20);
206 docstring text = bformat(_("Reverting to the stored version of the "
207 "document %1$s will lose all current changes.\n\n"
208 "Do you want to revert to the older version?"), file);
209 int const ret = Alert::prompt(_("Revert to stored version of document?"),
210 text, 0, 1, _("&Revert"), _("&Cancel"));
217 void LyXVC::undoLast()
223 void LyXVC::toggleReadOnly()
225 if (!vcs->toggleReadOnlyEnabled())
228 switch (vcs->status()) {
230 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
234 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
243 bool LyXVC::inUse() const
251 //string const & LyXVC::version() const
253 // return vcs->version();
257 string const LyXVC::versionString() const
259 return vcs->versionString();
263 string const & LyXVC::locker() const
265 return vcs->locker();
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 bool LyXVC::checkOutEnabled() const
287 return vcs && vcs->checkOutEnabled();
291 bool LyXVC::checkInEnabled() const
293 return vcs && vcs->checkInEnabled();
297 bool LyXVC::lockingToggleEnabled() const
299 return vcs && vcs->lockingToggleEnabled();
303 bool LyXVC::undoLastEnabled() const
305 return vcs && vcs->undoLastEnabled();