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"
19 using namespace lyx::support;
25 /* WARNING: Several of the vcs-> methods end up
26 * deleting this object via BufferView::reload() !
42 bool LyXVC::file_found_hook(string const & fn)
45 // Check if file is under RCS
46 if (!(found_file = RCS::find_file(fn)).empty()) {
47 vcs = new RCS(found_file);
51 // Check if file is under CVS
52 if (!(found_file = CVS::find_file(fn)).empty()) {
53 vcs = new CVS(found_file, fn);
57 // file is not under any VCS.
62 bool LyXVC::file_not_found_hook(string const & fn)
64 // Check if file is under RCS
65 if (!RCS::find_file(fn).empty())
67 if (!CVS::find_file(fn).empty())
73 void LyXVC::buffer(Buffer * buf)
79 bool LyXVC::ensureClean()
81 if (owner_->isClean())
84 string const file = MakeDisplayPath(owner_->fileName(), 30);
85 string text = bformat(_("The document %1$s has unsaved changes.\n\n"
86 "Do you want to save the document?"), file);
87 int const ret = Alert::prompt(_("Save changed document?"),
88 text, 0, 1, _("&Save"), _("&Cancel"));
91 vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
94 return owner_->isClean();
98 void LyXVC::registrer()
100 string const filename = owner_->fileName();
102 // there must be a file to save
103 if (!IsFileReadable(filename)) {
104 Alert::error(_("Document not saved"),
105 _("You must save the document "
106 "before it can be registered."));
110 // it is very likely here that the vcs is not created yet...
112 string const cvs_entries = "CVS/Entries";
114 if (IsFileReadable(cvs_entries)) {
116 << "LyXVC: registering "
117 << MakeDisplayPath(filename)
118 << " with CVS" << endl;
119 vcs = new CVS(cvs_entries, filename);
123 << "LyXVC: registering "
124 << MakeDisplayPath(filename)
125 << " with RCS" << endl;
126 vcs = new RCS(filename);
132 // Maybe the save fails, or we answered "no". In both cases,
133 // the document will be dirty, and we abort.
137 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
138 pair<bool, string> tmp =
139 Alert::askForText(_("LyX VC: Initial description"),
140 _("(no initial description)"));
141 if (!tmp.first || tmp.second.empty()) {
142 // should we insist on checking tmp.second.empty()?
143 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
147 vcs->registrer(tmp.second);
151 void LyXVC::checkIn()
153 // If the document is changed, we might want to save it
154 if (!vcs->owner()->isClean()) {
155 vcs->owner()->getUser()->owner()
156 ->dispatch(FuncRequest(LFUN_MENUWRITE));
159 // Maybe the save fails, or we answered "no". In both cases,
160 // the document will be dirty, and we abort.
161 if (!vcs->owner()->isClean())
164 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
165 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
167 if (tmp.second.empty()) {
168 tmp.second = _("(no log message)");
170 vcs->checkIn(tmp.second);
172 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
177 void LyXVC::checkOut()
179 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
189 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
191 string const file = MakeDisplayPath(owner_->fileName(), 20);
192 string text = bformat(_("Reverting to the stored version of the "
193 "document %1$s will lose all current changes.\n\n"
194 "Do you want to revert to the saved version?"), file);
195 int const ret = Alert::prompt(_("Revert to stored version of document?"),
196 text, 0, 1, _("&Revert"), _("&Cancel"));
203 void LyXVC::undoLast()
209 void LyXVC::toggleReadOnly()
211 switch (vcs->status()) {
213 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
217 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
226 if (vcs) return true;
231 //string const & LyXVC::version() const
233 // return vcs->version();
236 string const LyXVC::versionString() const
238 return vcs->versionString();
242 string const & LyXVC::locker() const
244 return vcs->locker();
248 string const LyXVC::getLogFile() const
253 string tmpf = tempName(string(), "lyxvclog");
254 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;