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 "vc-backend.h"
24 #include "frontends/Alert.h"
26 #include "support/filetools.h"
27 #include "support/lyxlib.h"
32 using support::bformat;
33 using support::FileName;
34 using support::isFileReadable;
35 using support::makeAbsPath;
36 using support::makeDisplayPath;
37 using support::tempName;
43 namespace Alert = frontend::Alert;
52 // for the sake of boost::scoped_ptr
57 bool LyXVC::file_found_hook(string const & fn)
60 // Check if file is under RCS
61 if (!(found_file = RCS::find_file(fn)).empty()) {
62 vcs.reset(new RCS(found_file));
66 // Check if file is under CVS
67 if (!(found_file = CVS::find_file(fn)).empty()) {
68 vcs.reset(new CVS(found_file, fn));
72 // file is not under any VCS.
77 bool LyXVC::file_not_found_hook(string const & fn)
79 // Check if file is under RCS
80 if (!RCS::find_file(fn).empty())
82 if (!CVS::find_file(fn).empty())
88 void LyXVC::buffer(Buffer * buf)
94 void LyXVC::registrer()
96 string const filename = owner_->fileName();
98 // there must be a file to save
99 if (!isFileReadable(FileName(makeAbsPath(filename)))) {
100 Alert::error(_("Document not saved"),
101 _("You must save the document "
102 "before it can be registered."));
106 // it is very likely here that the vcs is not created yet...
108 string const cvs_entries = "CVS/Entries";
110 if (isFileReadable(FileName(makeAbsPath(cvs_entries)))) {
112 << "LyXVC: registering "
113 << to_utf8(makeDisplayPath(filename))
114 << " with CVS" << endl;
115 vcs.reset(new CVS(cvs_entries, filename));
119 << "LyXVC: registering "
120 << to_utf8(makeDisplayPath(filename))
121 << " with RCS" << endl;
122 vcs.reset(new RCS(filename));
128 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
129 pair<bool, docstring> tmp =
130 Alert::askForText(_("LyX VC: Initial description"),
131 _("(no initial description)"));
132 if (!tmp.first || tmp.second.empty()) {
133 // should we insist on checking tmp.second.empty()?
134 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
138 vcs->registrer(to_utf8(tmp.second));
142 void LyXVC::checkIn()
145 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
146 pair<bool, docstring> tmp = Alert::askForText(_("LyX VC: Log Message"));
148 if (tmp.second.empty()) {
149 tmp.second = _("(no log message)");
151 vcs->checkIn(to_utf8(tmp.second));
153 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
158 void LyXVC::checkOut()
160 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
168 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
170 docstring const file = makeDisplayPath(owner_->fileName(), 20);
171 docstring text = bformat(_("Reverting to the stored version of the "
172 "document %1$s will lose all current changes.\n\n"
173 "Do you want to revert to the saved version?"), file);
174 int const ret = Alert::prompt(_("Revert to stored version of document?"),
175 text, 0, 1, _("&Revert"), _("&Cancel"));
182 void LyXVC::undoLast()
188 void LyXVC::toggleReadOnly()
190 switch (vcs->status()) {
192 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
196 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
205 if (vcs) return true;
210 //string const & LyXVC::version() const
212 // return vcs->version();
215 string const LyXVC::versionString() const
217 return vcs->versionString();
221 string const & LyXVC::locker() const
223 return vcs->locker();
227 string const LyXVC::getLogFile() const
232 string tmpf = tempName(string(), "lyxvclog");
234 lyxerr[Debug::LYXVC] << "Could not generate logfile "
238 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;