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"
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);
83 string text = bformat(_("The document %1$s has unsaved changes.\n\n"
84 "Do you want to save the document?"), file);
85 int const ret = Alert::prompt(_("Save changed document?"),
86 text, 0, 1, _("&Save"), _("&Cancel"));
89 vcs->owner()->getUser()->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
92 return owner_->isClean();
96 void LyXVC::registrer()
98 string const filename = owner_->fileName();
100 // there must be a file to save
101 if (!IsFileReadable(filename)) {
102 Alert::error(_("Document not saved"),
103 _("You must save the document "
104 "before it can be registered."));
108 // it is very likely here that the vcs is not created yet...
110 string const cvs_entries = "CVS/Entries";
112 if (IsFileReadable(cvs_entries)) {
114 << "LyXVC: registering "
115 << MakeDisplayPath(filename)
116 << " with CVS" << endl;
117 vcs = new CVS(cvs_entries, filename);
121 << "LyXVC: registering "
122 << MakeDisplayPath(filename)
123 << " with RCS" << endl;
124 vcs = new RCS(filename);
130 // Maybe the save fails, or we answered "no". In both cases,
131 // the document will be dirty, and we abort.
135 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
136 pair<bool, string> tmp =
137 Alert::askForText(_("LyX VC: Initial description"),
138 _("(no initial description)"));
139 if (!tmp.first || tmp.second.empty()) {
140 // should we insist on checking tmp.second.empty()?
141 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
145 vcs->registrer(tmp.second);
149 void LyXVC::checkIn()
151 // If the document is changed, we might want to save it
152 if (!vcs->owner()->isClean()) {
153 vcs->owner()->getUser()->owner()
154 ->dispatch(FuncRequest(LFUN_MENUWRITE));
157 // Maybe the save fails, or we answered "no". In both cases,
158 // the document will be dirty, and we abort.
159 if (!vcs->owner()->isClean())
162 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
163 pair<bool, string> tmp = Alert::askForText(_("LyX VC: Log Message"));
165 if (tmp.second.empty()) {
166 tmp.second = _("(no log message)");
168 vcs->checkIn(tmp.second);
170 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
175 void LyXVC::checkOut()
177 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
187 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
189 string const file = MakeDisplayPath(owner_->fileName(), 20);
190 string text = bformat(_("Reverting to the stored version of the "
191 "document %1$s will lose all current changes.\n\n"
192 "Do you want to revert to the saved version?"), file);
193 int const ret = Alert::prompt(_("Revert to stored version of document?"),
194 text, 0, 1, _("&Revert"), _("&Cancel"));
201 void LyXVC::undoLast()
207 void LyXVC::toggleReadOnly()
209 switch (vcs->status()) {
211 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
215 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
224 if (vcs) return true;
229 //string const & LyXVC::version() const
231 // return vcs->version();
234 string const LyXVC::versionString() const
236 return vcs->versionString();
240 string const & LyXVC::locker() const
242 return vcs->locker();
246 const string LyXVC::getLogFile() const
251 string tmpf = lyx::tempName(string(), "lyxvclog");
252 lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl;