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"
33 using support::bformat;
34 using support::FileName;
35 using support::makeAbsPath;
36 using support::tempName;
40 namespace Alert = frontend::Alert;
49 // for the sake of boost::scoped_ptr
54 bool LyXVC::file_found_hook(FileName const & fn)
57 // Check if file is under RCS
58 if (!(found_file = RCS::findFile(fn)).empty()) {
59 vcs.reset(new RCS(found_file));
63 // Check if file is under CVS
64 if (!(found_file = CVS::findFile(fn)).empty()) {
65 vcs.reset(new CVS(found_file, fn));
69 // file is not under any VCS.
74 bool LyXVC::file_not_found_hook(FileName const & fn)
76 // Check if file is under RCS
77 if (!RCS::findFile(fn).empty())
79 if (!CVS::findFile(fn).empty())
85 void LyXVC::setBuffer(Buffer * buf)
91 void LyXVC::registrer()
93 FileName const filename = owner_->fileName();
95 // there must be a file to save
96 if (!filename.isReadableFile()) {
97 Alert::error(_("Document not saved"),
98 _("You must save the document "
99 "before it can be registered."));
103 // it is very likely here that the vcs is not created yet...
105 FileName const cvs_entries(makeAbsPath("CVS/Entries"));
107 if (cvs_entries.isReadableFile()) {
108 LYXERR(Debug::LYXVC, "LyXVC: registering "
109 << to_utf8(filename.displayName()) << " with CVS");
110 vcs.reset(new CVS(cvs_entries, filename));
113 LYXERR(Debug::LYXVC, "LyXVC: registering "
114 << to_utf8(filename.displayName()) << " with RCS");
115 vcs.reset(new RCS(filename));
121 LYXERR(Debug::LYXVC, "LyXVC: registrer");
123 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
124 _("(no initial description)"));
125 if (!ok || response.empty()) {
126 // should we insist on checking response.empty()?
127 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
131 vcs->registrer(to_utf8(response));
135 void LyXVC::checkIn()
137 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
139 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
141 if (response.empty())
142 response = _("(no log message)");
143 vcs->checkIn(to_utf8(response));
145 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
150 void LyXVC::checkOut()
152 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
159 LYXERR(Debug::LYXVC, "LyXVC: revert");
161 docstring const file = owner_->fileName().displayName(20);
162 docstring text = bformat(_("Reverting to the stored version of the "
163 "document %1$s will lose all current changes.\n\n"
164 "Do you want to revert to the saved version?"), file);
165 int const ret = Alert::prompt(_("Revert to stored version of document?"),
166 text, 0, 1, _("&Revert"), _("&Cancel"));
173 void LyXVC::undoLast()
179 void LyXVC::toggleReadOnly()
181 switch (vcs->status()) {
183 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
187 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
202 //string const & LyXVC::version() const
204 // return vcs->version();
208 string const LyXVC::versionString() const
210 return vcs->versionString();
214 string const & LyXVC::locker() const
216 return vcs->locker();
220 string const LyXVC::getLogFile() const
225 FileName const tmpf(tempName(FileName(), "lyxvclog"));
227 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
230 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
232 return tmpf.absFilename();