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"
20 #include "support/debug.h"
22 #include "support/gettext.h"
24 #include "frontends/alert.h"
26 #include "support/filetools.h"
27 #include "support/lstrings.h"
28 #include "support/lyxlib.h"
31 using namespace lyx::support;
35 namespace Alert = frontend::Alert;
44 // for the sake of boost::scoped_ptr
49 bool LyXVC::file_found_hook(FileName const & fn)
52 // Check if file is under RCS
53 if (!(found_file = RCS::findFile(fn)).empty()) {
54 vcs.reset(new RCS(found_file));
58 // Check if file is under CVS
59 if (!(found_file = CVS::findFile(fn)).empty()) {
60 vcs.reset(new CVS(found_file, fn));
64 // file is not under any VCS.
69 bool LyXVC::file_not_found_hook(FileName const & fn)
71 // Check if file is under RCS
72 if (!RCS::findFile(fn).empty())
74 if (!CVS::findFile(fn).empty())
80 void LyXVC::setBuffer(Buffer * buf)
86 void LyXVC::registrer()
88 FileName const filename = owner_->fileName();
90 // there must be a file to save
91 if (!filename.isReadableFile()) {
92 Alert::error(_("Document not saved"),
93 _("You must save the document "
94 "before it can be registered."));
98 // it is very likely here that the vcs is not created yet...
100 FileName const cvs_entries(makeAbsPath("CVS/Entries"));
102 if (cvs_entries.isReadableFile()) {
103 LYXERR(Debug::LYXVC, "LyXVC: registering "
104 << to_utf8(filename.displayName()) << " with CVS");
105 vcs.reset(new CVS(cvs_entries, filename));
108 LYXERR(Debug::LYXVC, "LyXVC: registering "
109 << to_utf8(filename.displayName()) << " with RCS");
110 vcs.reset(new RCS(filename));
116 LYXERR(Debug::LYXVC, "LyXVC: registrer");
118 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
119 _("(no initial description)"));
120 if (!ok || response.empty()) {
121 // should we insist on checking response.empty()?
122 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
126 vcs->registrer(to_utf8(response));
130 void LyXVC::checkIn()
132 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
134 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
136 if (response.empty())
137 response = _("(no log message)");
138 vcs->checkIn(to_utf8(response));
140 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
145 void LyXVC::checkOut()
147 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
154 LYXERR(Debug::LYXVC, "LyXVC: revert");
156 docstring const file = owner_->fileName().displayName(20);
157 docstring text = bformat(_("Reverting to the stored version of the "
158 "document %1$s will lose all current changes.\n\n"
159 "Do you want to revert to the saved version?"), file);
160 int const ret = Alert::prompt(_("Revert to stored version of document?"),
161 text, 0, 1, _("&Revert"), _("&Cancel"));
168 void LyXVC::undoLast()
174 void LyXVC::toggleReadOnly()
176 switch (vcs->status()) {
178 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
182 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
197 //string const & LyXVC::version() const
199 // return vcs->version();
203 string const LyXVC::versionString() const
205 return vcs->versionString();
209 string const & LyXVC::locker() const
211 return vcs->locker();
215 string const LyXVC::getLogFile() const
220 FileName const tmpf = FileName::tempName("lyxvclog");
222 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
225 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
227 return tmpf.absFilename();