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::isFileReadable;
34 using support::makeDisplayPath;
35 using support::tempName;
41 namespace Alert = frontend::Alert;
50 // for the sake of boost::scoped_ptr
55 bool LyXVC::file_found_hook(string const & fn)
58 // Check if file is under RCS
59 if (!(found_file = RCS::find_file(fn)).empty()) {
60 vcs.reset(new RCS(found_file));
64 // Check if file is under CVS
65 if (!(found_file = CVS::find_file(fn)).empty()) {
66 vcs.reset(new CVS(found_file, fn));
70 // file is not under any VCS.
75 bool LyXVC::file_not_found_hook(string const & fn)
77 // Check if file is under RCS
78 if (!RCS::find_file(fn).empty())
80 if (!CVS::find_file(fn).empty())
86 void LyXVC::buffer(Buffer * buf)
92 void LyXVC::registrer()
94 string const filename = owner_->fileName();
96 // there must be a file to save
97 if (!isFileReadable(filename)) {
98 Alert::error(_("Document not saved"),
99 _("You must save the document "
100 "before it can be registered."));
104 // it is very likely here that the vcs is not created yet...
106 string const cvs_entries = "CVS/Entries";
108 if (isFileReadable(cvs_entries)) {
110 << "LyXVC: registering "
111 << to_utf8(makeDisplayPath(filename))
112 << " with CVS" << endl;
113 vcs.reset(new CVS(cvs_entries, filename));
117 << "LyXVC: registering "
118 << to_utf8(makeDisplayPath(filename))
119 << " with RCS" << endl;
120 vcs.reset(new RCS(filename));
126 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
127 pair<bool, docstring> tmp =
128 Alert::askForText(_("LyX VC: Initial description"),
129 _("(no initial description)"));
130 if (!tmp.first || tmp.second.empty()) {
131 // should we insist on checking tmp.second.empty()?
132 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
136 vcs->registrer(to_utf8(tmp.second));
140 void LyXVC::checkIn()
143 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
144 pair<bool, docstring> tmp = Alert::askForText(_("LyX VC: Log Message"));
146 if (tmp.second.empty()) {
147 tmp.second = _("(no log message)");
149 vcs->checkIn(to_utf8(tmp.second));
151 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
156 void LyXVC::checkOut()
158 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
166 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
168 docstring const file = makeDisplayPath(owner_->fileName(), 20);
169 docstring text = bformat(_("Reverting to the stored version of the "
170 "document %1$s will lose all current changes.\n\n"
171 "Do you want to revert to the saved version?"), file);
172 int const ret = Alert::prompt(_("Revert to stored version of document?"),
173 text, 0, 1, _("&Revert"), _("&Cancel"));
180 void LyXVC::undoLast()
186 void LyXVC::toggleReadOnly()
188 switch (vcs->status()) {
190 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
194 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
203 if (vcs) return true;
208 //string const & LyXVC::version() const
210 // return vcs->version();
213 string const LyXVC::versionString() const
215 return vcs->versionString();
219 string const & LyXVC::locker() const
221 return vcs->locker();
225 string const LyXVC::getLogFile() const
230 string tmpf = tempName(string(), "lyxvclog");
232 lyxerr[Debug::LYXVC] << "Could not generate logfile "
236 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;