4 #include "vc-backend.h"
7 #include "BufferView.h"
9 #include "funcrequest.h"
11 #include "frontends/Alert.h"
12 #include "frontends/LyXView.h"
14 #include "support/filetools.h"
15 #include "support/lyxlib.h"
16 #include "BoostFormat.h"
23 /* WARNING: Several of the vcs-> methods end up
24 * deleting this object via BufferView::reload() !
40 bool LyXVC::file_found_hook(string const & fn)
43 // Check if file is under RCS
44 if (!(found_file = RCS::find_file(fn)).empty()) {
45 vcs = new RCS(found_file);
49 // Check if file is under CVS
50 if (!(found_file = CVS::find_file(fn)).empty()) {
51 vcs = new CVS(found_file, fn);
55 // file is not under any VCS.
60 bool LyXVC::file_not_found_hook(string const & fn)
62 // Check if file is under RCS
63 if (!RCS::find_file(fn).empty())
65 if (!CVS::find_file(fn).empty())
71 void LyXVC::buffer(Buffer * buf)
77 bool LyXVC::ensureClean()
79 if (owner_->isClean())
82 string const file = MakeDisplayPath(owner_->fileName(), 30);
84 boost::format fmt(_("The document %1$s has unsaved changes.\n\nDo you want to save the document?"));
86 string text = fmt.str();
88 string text = _("The document ");
89 text += file + _(" has unsaved changes.\n\nDo you want to save the document?");
91 int const ret = Alert::prompt(_("Save changed document?"),
92 text, 0, _("&Save"), _("&Cancel"));
95 vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
98 return owner_->isClean();
102 void LyXVC::registrer()
104 string const filename = owner_->fileName();
106 // there must be a file to save
107 if (!IsFileReadable(filename)) {
108 Alert::error(_("Document not saved"),
109 _("You must save the document "
110 "before it can be registered."));
114 // it is very likely here that the vcs is not created yet...
116 string const cvs_entries = "CVS/Entries";
118 if (IsFileReadable(cvs_entries)) {
120 << "LyXVC: registering "
121 << MakeDisplayPath(filename)
122 << " with CVS" << endl;
123 vcs = new CVS(cvs_entries, filename);
127 << "LyXVC: registering "
128 << MakeDisplayPath(filename)
129 << " with RCS" << endl;
130 vcs = new RCS(filename);
136 // Maybe the save fails, or we answered "no". In both cases,
137 // the document will be dirty, and we abort.
141 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
142 pair<bool, string> tmp =
143 Alert::askForText(_("LyX VC: Initial description"),
144 _("(no initial description)"));
145 if (!tmp.first || tmp.second.empty()) {
146 // should we insist on checking tmp.second.empty()?
147 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
151 vcs->registrer(tmp.second);
155 void LyXVC::checkIn()
157 // If the document is changed, we might want to save it
158 if (!vcs->owner()->isClean()) {
159 vcs->owner()->getUser()->owner()
160 ->dispatch(FuncRequest(LFUN_MENUWRITE));
163 // Maybe the save fails, or we answered "no". In both cases,
164 // the document will be dirty, and we abort.
165 if (!vcs->owner()->isClean())
168 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
169 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
171 if (tmp.second.empty()) {
172 tmp.second = _("(no log message)");
174 vcs->checkIn(tmp.second);
176 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
181 void LyXVC::checkOut()
183 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
193 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
195 string const file = MakeDisplayPath(owner_->fileName(), 20);
197 boost::format fmt(_("Reverting to the stored version of the document %1$s will "
198 "lose all current changes.\n\nDo you want to revert to the saved version?"));
200 string text = fmt.str();
202 string text = _("Reverting to the stored version of the document ");
203 text += file + _(" will lose all current changes.\n\nDo you want to revert to the saved version?");
205 int const ret = Alert::prompt(_("Revert to stored version of document?"),
206 text, 1, _("&Revert"), _("&Cancel"));
213 void LyXVC::undoLast()
219 void LyXVC::toggleReadOnly()
221 switch (vcs->status()) {
223 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
227 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
236 if (vcs) return true;
241 //string const & LyXVC::version() const
243 // return vcs->version();
246 string const LyXVC::versionString() const
248 return vcs->versionString();
252 string const & LyXVC::locker() const
254 return vcs->locker();
258 const string LyXVC::getLogFile() const
263 string tmpf = lyx::tempName(string(), "lyxvclog");
264 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;