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()) {
111 << "LyXVC: registering "
112 << to_utf8(filename.displayName())
113 << " with CVS" << endl;
114 vcs.reset(new CVS(cvs_entries, filename));
118 << "LyXVC: registering "
119 << to_utf8(filename.displayName())
120 << " with RCS" << endl;
121 vcs.reset(new RCS(filename));
127 LYXERR(Debug::LYXVC) << "LyXVC: registrer" << endl;
129 bool ok = Alert::askForText(response, _("LyX VC: Initial description"),
130 _("(no initial description)"));
131 if (!ok || response.empty()) {
132 // should we insist on checking response.empty()?
133 LYXERR(Debug::LYXVC) << "LyXVC: user cancelled" << endl;
137 vcs->registrer(to_utf8(response));
141 void LyXVC::checkIn()
144 LYXERR(Debug::LYXVC) << "LyXVC: checkIn" << endl;
146 bool ok = Alert::askForText(response, _("LyX VC: Log Message"));
148 if (response.empty())
149 response = _("(no log message)");
150 vcs->checkIn(to_utf8(response));
152 LYXERR(Debug::LYXVC) << "LyXVC: user cancelled" << endl;
157 void LyXVC::checkOut()
159 LYXERR(Debug::LYXVC) << "LyXVC: checkOut" << endl;
167 LYXERR(Debug::LYXVC) << "LyXVC: revert" << endl;
169 docstring const file = owner_->fileName().displayName(20);
170 docstring text = bformat(_("Reverting to the stored version of the "
171 "document %1$s will lose all current changes.\n\n"
172 "Do you want to revert to the saved version?"), file);
173 int const ret = Alert::prompt(_("Revert to stored version of document?"),
174 text, 0, 1, _("&Revert"), _("&Cancel"));
181 void LyXVC::undoLast()
187 void LyXVC::toggleReadOnly()
189 switch (vcs->status()) {
191 LYXERR(Debug::LYXVC) << "LyXVC: toggle to locked" << endl;
195 LYXERR(Debug::LYXVC) << "LyXVC: toggle to unlocked" << endl;
210 //string const & LyXVC::version() const
212 // return vcs->version();
216 string const LyXVC::versionString() const
218 return vcs->versionString();
222 string const & LyXVC::locker() const
224 return vcs->locker();
228 string const LyXVC::getLogFile() const
233 FileName const tmpf(tempName(FileName(), "lyxvclog"));
235 LYXERR(Debug::LYXVC) << "Could not generate logfile "
239 LYXERR(Debug::LYXVC) << "Generating logfile " << tmpf << endl;
241 return tmpf.absFilename();