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"
29 using lyx::support::bformat;
30 using lyx::support::isFileReadable;
31 using lyx::support::makeDisplayPath;
32 using lyx::support::tempName;
40 namespace Alert = lyx::frontend::Alert;
49 // for the sake of boost::scoped_ptr
54 bool LyXVC::file_found_hook(string const & fn)
57 // Check if file is under RCS
58 if (!(found_file = RCS::find_file(fn)).empty()) {
59 vcs.reset(new RCS(found_file));
63 // Check if file is under CVS
64 if (!(found_file = CVS::find_file(fn)).empty()) {
65 vcs.reset(new CVS(found_file, fn));
69 // file is not under any VCS.
74 bool LyXVC::file_not_found_hook(string const & fn)
76 // Check if file is under RCS
77 if (!RCS::find_file(fn).empty())
79 if (!CVS::find_file(fn).empty())
85 void LyXVC::buffer(Buffer * buf)
91 void LyXVC::registrer()
93 string const filename = owner_->fileName();
95 // there must be a file to save
96 if (!isFileReadable(filename)) {
97 Alert::error(_("Document not saved"),
98 _("You must save the document "
99 "before it can be registered."));
103 // it is very likely here that the vcs is not created yet...
105 string const cvs_entries = "CVS/Entries";
107 if (isFileReadable(cvs_entries)) {
109 << "LyXVC: registering "
110 << lyx::to_utf8(makeDisplayPath(filename))
111 << " with CVS" << endl;
112 vcs.reset(new CVS(cvs_entries, filename));
116 << "LyXVC: registering "
117 << lyx::to_utf8(makeDisplayPath(filename))
118 << " with RCS" << endl;
119 vcs.reset(new RCS(filename));
125 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
126 pair<bool, docstring> tmp =
127 Alert::askForText(_("LyX VC: Initial description"),
128 _("(no initial description)"));
129 if (!tmp.first || tmp.second.empty()) {
130 // should we insist on checking tmp.second.empty()?
131 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
135 vcs->registrer(lyx::to_utf8(tmp.second));
139 void LyXVC::checkIn()
142 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
143 pair<bool, docstring> tmp = Alert::askForText(_("LyX VC: Log Message"));
145 if (tmp.second.empty()) {
146 tmp.second = _("(no log message)");
148 vcs->checkIn(lyx::to_utf8(tmp.second));
150 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
155 void LyXVC::checkOut()
157 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
165 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
167 docstring const file = makeDisplayPath(owner_->fileName(), 20);
168 docstring text = bformat(_("Reverting to the stored version of the "
169 "document %1$s will lose all current changes.\n\n"
170 "Do you want to revert to the saved version?"), file);
171 int const ret = Alert::prompt(_("Revert to stored version of document?"),
172 text, 0, 1, _("&Revert"), _("&Cancel"));
179 void LyXVC::undoLast()
185 void LyXVC::toggleReadOnly()
187 switch (vcs->status()) {
189 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
193 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
202 if (vcs) return true;
207 //string const & LyXVC::version() const
209 // return vcs->version();
212 string const LyXVC::versionString() const
214 return vcs->versionString();
218 string const & LyXVC::locker() const
220 return vcs->locker();
224 string const LyXVC::getLogFile() const
229 string tmpf = tempName(string(), "lyxvclog");
231 lyxerr[Debug::LYXVC] << "Could not generate logfile "
235 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;