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"
34 using support::bformat;
35 using support::FileName;
36 using support::makeAbsPath;
37 using support::tempName;
39 namespace Alert = frontend::Alert;
48 // for the sake of boost::scoped_ptr
53 bool LyXVC::file_found_hook(FileName const & fn)
56 // Check if file is under RCS
57 if (!(found_file = RCS::findFile(fn)).empty()) {
58 vcs.reset(new RCS(found_file));
62 // Check if file is under CVS
63 if (!(found_file = CVS::findFile(fn)).empty()) {
64 vcs.reset(new CVS(found_file, fn));
68 // file is not under any VCS.
73 bool LyXVC::file_not_found_hook(FileName const & fn)
75 // Check if file is under RCS
76 if (!RCS::findFile(fn).empty())
78 if (!CVS::findFile(fn).empty())
84 void LyXVC::setBuffer(Buffer * buf)
90 void LyXVC::registrer()
92 FileName const filename = owner_->fileName();
94 // there must be a file to save
95 if (!filename.isReadableFile()) {
96 Alert::error(_("Document not saved"),
97 _("You must save the document "
98 "before it can be registered."));
102 // it is very likely here that the vcs is not created yet...
104 FileName const cvs_entries(makeAbsPath("CVS/Entries"));
106 if (cvs_entries.isReadableFile()) {
107 LYXERR(Debug::LYXVC, "LyXVC: registering "
108 << to_utf8(filename.displayName()) << " with CVS");
109 vcs.reset(new CVS(cvs_entries, filename));
112 LYXERR(Debug::LYXVC, "LyXVC: registering "
113 << to_utf8(filename.displayName()) << " with RCS");
114 vcs.reset(new RCS(filename));
120 LYXERR(Debug::LYXVC, "LyXVC: registrer");
122 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
123 _("(no initial description)"));
124 if (!ok || response.empty()) {
125 // should we insist on checking response.empty()?
126 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
130 vcs->registrer(to_utf8(response));
134 void LyXVC::checkIn()
136 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
138 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
140 if (response.empty())
141 response = _("(no log message)");
142 vcs->checkIn(to_utf8(response));
144 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
149 void LyXVC::checkOut()
151 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
158 LYXERR(Debug::LYXVC, "LyXVC: revert");
160 docstring const file = owner_->fileName().displayName(20);
161 docstring text = bformat(_("Reverting to the stored version of the "
162 "document %1$s will lose all current changes.\n\n"
163 "Do you want to revert to the saved version?"), file);
164 int const ret = Alert::prompt(_("Revert to stored version of document?"),
165 text, 0, 1, _("&Revert"), _("&Cancel"));
172 void LyXVC::undoLast()
178 void LyXVC::toggleReadOnly()
180 switch (vcs->status()) {
182 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
186 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
201 //string const & LyXVC::version() const
203 // return vcs->version();
207 string const LyXVC::versionString() const
209 return vcs->versionString();
213 string const & LyXVC::locker() const
215 return vcs->locker();
219 string const LyXVC::getLogFile() const
224 FileName const tmpf(tempName(FileName(), "lyxvclog"));
226 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
229 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
231 return tmpf.absFilename();