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"
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;
42 namespace Alert = frontend::Alert;
51 // for the sake of boost::scoped_ptr
56 bool LyXVC::file_found_hook(FileName const & fn)
59 // Check if file is under RCS
60 if (!(found_file = RCS::find_file(fn)).empty()) {
61 vcs.reset(new RCS(found_file));
65 // Check if file is under CVS
66 if (!(found_file = CVS::find_file(fn)).empty()) {
67 vcs.reset(new CVS(found_file, fn));
71 // file is not under any VCS.
76 bool LyXVC::file_not_found_hook(FileName const & fn)
78 // Check if file is under RCS
79 if (!RCS::find_file(fn).empty())
81 if (!CVS::find_file(fn).empty())
87 void LyXVC::setBuffer(Buffer * buf)
93 void LyXVC::registrer()
95 FileName const filename = owner_->fileName();
97 // there must be a file to save
98 if (!filename.isFileReadable()) {
99 Alert::error(_("Document not saved"),
100 _("You must save the document "
101 "before it can be registered."));
105 // it is very likely here that the vcs is not created yet...
107 FileName const cvs_entries(makeAbsPath("CVS/Entries"));
109 if (cvs_entries.isFileReadable()) {
110 LYXERR(Debug::LYXVC, "LyXVC: registering "
111 << to_utf8(filename.displayName()) << " with CVS");
112 vcs.reset(new CVS(cvs_entries, filename));
115 LYXERR(Debug::LYXVC, "LyXVC: registering "
116 << to_utf8(filename.displayName()) << " with RCS");
117 vcs.reset(new RCS(filename));
123 LYXERR(Debug::LYXVC, "LyXVC: registrer");
125 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
126 _("(no initial description)"));
127 if (!ok || response.empty()) {
128 // should we insist on checking response.empty()?
129 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
133 vcs->registrer(to_utf8(response));
137 void LyXVC::checkIn()
139 LYXERR(Debug::LYXVC, "LyXVC: checkIn");
141 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
143 if (response.empty())
144 response = _("(no log message)");
145 vcs->checkIn(to_utf8(response));
147 LYXERR(Debug::LYXVC, "LyXVC: user cancelled");
152 void LyXVC::checkOut()
154 LYXERR(Debug::LYXVC, "LyXVC: checkOut");
161 LYXERR(Debug::LYXVC, "LyXVC: revert");
163 docstring const file = owner_->fileName().displayName(20);
164 docstring text = bformat(_("Reverting to the stored version of the "
165 "document %1$s will lose all current changes.\n\n"
166 "Do you want to revert to the saved version?"), file);
167 int const ret = Alert::prompt(_("Revert to stored version of document?"),
168 text, 0, 1, _("&Revert"), _("&Cancel"));
175 void LyXVC::undoLast()
181 void LyXVC::toggleReadOnly()
183 switch (vcs->status()) {
185 LYXERR(Debug::LYXVC, "LyXVC: toggle to locked");
189 LYXERR(Debug::LYXVC, "LyXVC: toggle to unlocked");
204 //string const & LyXVC::version() const
206 // return vcs->version();
210 string const LyXVC::versionString() const
212 return vcs->versionString();
216 string const & LyXVC::locker() const
218 return vcs->locker();
222 string const LyXVC::getLogFile() const
227 FileName const tmpf(tempName(FileName(), "lyxvclog"));
229 LYXERR(Debug::LYXVC, "Could not generate logfile " << tmpf);
232 LYXERR(Debug::LYXVC, "Generating logfile " << tmpf);
234 return tmpf.absFilename();