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;
45 // for the sake of boost::scoped_ptr
50 bool LyXVC::file_found_hook(string const & fn)
53 // Check if file is under RCS
54 if (!(found_file = RCS::find_file(fn)).empty()) {
55 vcs.reset(new RCS(found_file));
59 // Check if file is under CVS
60 if (!(found_file = CVS::find_file(fn)).empty()) {
61 vcs.reset(new CVS(found_file, fn));
65 // file is not under any VCS.
70 bool LyXVC::file_not_found_hook(string const & fn)
72 // Check if file is under RCS
73 if (!RCS::find_file(fn).empty())
75 if (!CVS::find_file(fn).empty())
81 void LyXVC::buffer(Buffer * buf)
87 void LyXVC::registrer()
89 string const filename = owner_->fileName();
91 // there must be a file to save
92 if (!IsFileReadable(filename)) {
93 Alert::error(_("Document not saved"),
94 _("You must save the document "
95 "before it can be registered."));
99 // it is very likely here that the vcs is not created yet...
101 string const cvs_entries = "CVS/Entries";
103 if (IsFileReadable(cvs_entries)) {
105 << "LyXVC: registering "
106 << MakeDisplayPath(filename)
107 << " with CVS" << endl;
108 vcs.reset(new CVS(cvs_entries, filename));
112 << "LyXVC: registering "
113 << MakeDisplayPath(filename)
114 << " with RCS" << endl;
115 vcs.reset(new RCS(filename));
121 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
122 pair<bool, string> tmp =
123 Alert::askForText(_("LyX VC: Initial description"),
124 _("(no initial description)"));
125 if (!tmp.first || tmp.second.empty()) {
126 // should we insist on checking tmp.second.empty()?
127 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
131 vcs->registrer(tmp.second);
135 void LyXVC::checkIn()
138 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
139 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
141 if (tmp.second.empty()) {
142 tmp.second = _("(no log message)");
144 vcs->checkIn(tmp.second);
146 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
151 void LyXVC::checkOut()
153 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
161 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
163 string const file = MakeDisplayPath(owner_->fileName(), 20);
164 string 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" << endl;
189 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
198 if (vcs) return true;
203 //string const & LyXVC::version() const
205 // return vcs->version();
208 string const LyXVC::versionString() const
210 return vcs->versionString();
214 string const & LyXVC::locker() const
216 return vcs->locker();
220 string const LyXVC::getLogFile() const
225 string tmpf = tempName(string(), "lyxvclog");
227 lyxerr[Debug::LYXVC] << "Could not generate logfile "
231 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;