7 #include FORMS_H_LOCATION
10 #include "lyx_gui_misc.h"
11 #include "bufferlist.h"
12 #include "support/syscall.h"
13 #include "support/path.h"
14 #include "support/filetools.h"
15 #include "support/FileInfo.h"
19 #include "latexoptions.h"
21 extern BufferList bufferlist;
22 extern void MenuWrite(Buffer *);
27 backend = UNKNOWN_VCS;
36 if (browser->LaTeXLog->visible)
37 fl_hide_form(browser->LaTeXLog);
38 fl_free_form(browser->LaTeXLog);
43 bool LyXVC::file_found_hook(string const & fn)
47 // Check if *,v exists.
49 lyxerr[Debug::LYXVC] << "Checking if file is under vc: "
51 if (f.newFile(tmp).readable()) {
52 lyxerr[Debug::LYXVC] << "Yes it is under vc." << endl;
58 // Check if RCS/*,v exists.
59 tmp = AddName(AddPath(OnlyPath(fn), "RCS"), fn);
61 lyxerr[Debug::LYXVC] << "Checking if file is under vc: "
63 if (f.newFile(tmp).readable()) {
64 lyxerr[Debug::LYXVC] << "Yes it is under vc."<< endl;
71 // If either one, return true
73 // file is not under any VCS.
78 bool LyXVC::file_not_found_hook(string const &)
80 // file is not under any VCS.
85 void LyXVC::scanMaster()
87 lyxerr[Debug::LYXVC] << "LyXVC: This file is a VC file." << endl;
93 bool read_enough = false;
94 while (lex.IsOK() && !read_enough) {
96 token = lex.GetString();
98 lyxerr[Debug::LYXVC] <<"LyXVC::scanMaster: current lex text: `"
99 << token << "'" << endl;
103 else if (token == "head") {
106 string tmv = strip(lex.GetString(), ';');
108 } else if (contains(token, "access")
109 || contains(token, "symbols")
110 || contains(token, "strict")) {
112 } else if (contains(token, "locks")) {
114 if (contains(token, ";")) {
122 s1 = strip(tmpt = lex.GetString(), ';');
123 // tmp is now in the format <user>:<version>
124 s1 = split(s1, s2, ':');
125 // s2 is user, and s1 is version
131 } while (!contains(tmpt, ";"));
133 } else if (token == "comment") {
134 // we don't need to read any further than this.
139 << "LyXVC::scanMaster(): unexpected token"
146 void LyXVC::setBuffer(Buffer * buf)
153 // I will probably add some backend_xxxx functions later to perform the
154 // version control system specific commands. Something like:
155 // void backend_revert(<params>) {
156 // if (backend == "RCS") {
157 // } else if (backend == "CVS") {
158 // } else if (backend == "SCCS") {
161 // But for 0.12 we will only support RCS.
164 void LyXVC::registrer()
166 // If the document is changed, we might want to save it
167 if (!_owner->isLyxClean() &&
168 AskQuestion(_("Changes in document:"),
169 MakeDisplayPath(_owner->getFileName(),50),
170 _("Save document and proceed?"))) {
174 // Maybe the save fails, or we answered "no". In both cases,
175 // the document will be dirty, and we abort.
176 if (!_owner->isLyxClean()) {
180 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
181 string tmp = askForText(_("LyX VC: Initial description"),
182 _("(no initial description)"));
184 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
185 WriteAlert(_("Info"), _("This document has NOT been registered."));
188 string cmd = "ci -q -u -i -t-\"";
191 cmd += OnlyFilename(_owner->getFileName());
194 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
198 void LyXVC::checkIn()
200 // If the document is changed, we might want to save it
201 if (!_owner->isLyxClean() &&
202 AskQuestion(_("Changes in document:"),
203 MakeDisplayPath(_owner->getFileName(),50),
204 _("Save document and proceed?"))) {
208 // Maybe the save fails, or we answered "no". In both cases,
209 // the document will be dirty, and we abort.
210 if (!_owner->isLyxClean()) {
214 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
215 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
216 string tmp = askForText(_("LyX VC: Log Message"));
217 if (tmp.empty()) tmp = "(no log msg)";
218 doVCCommand("ci -q -u -m\"" + tmp + "\" \""
219 + OnlyFilename(_owner->getFileName()) + "\"");
220 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
224 void LyXVC::checkOut()
226 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
227 if (!_owner->isLyxClean()
228 && !AskQuestion(_("Changes in document:"),
229 MakeDisplayPath(_owner->getFileName(),50),
230 _("Ignore changes and proceed with check out?"))) {
234 _owner->markLyxClean();
235 doVCCommand("co -q -l \""
236 + OnlyFilename(_owner->getFileName()) + "\"");
237 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
243 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
244 // Here we should check if the buffer is dirty. And if it is
245 // we should warn the user that reverting will discard all
246 // changes made since the last check in.
247 if (AskQuestion(_("When you revert, you will loose all changes made"),
248 _("to the document since the last check in."),
249 _("Do you still want to do it?"))) {
251 doVCCommand("co -f -u" + getVersion() + " \""
252 + OnlyFilename(_owner->getFileName()) + "\"");
253 // We ignore changes and just reload!
254 _owner->markLyxClean();
255 _owner->getUser()->getOwner()->
256 getLyXFunc()->Dispatch("buffer-reload");
261 void LyXVC::undoLast()
263 lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
264 doVCCommand("rcs -o" + getVersion() + " \""
265 + OnlyFilename(_owner->getFileName()) + "\"");
269 void LyXVC::toggleReadOnly()
290 string const LyXVC::getVersion() const
296 string const LyXVC::getLocker() const
301 // This is a hack anyway so I'll put it here in the mean time.
302 void LyXVC::logClose(FL_OBJECT * obj, long)
304 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
305 fl_hide_form(This->browser->LaTeXLog);
308 // and, hack over hack, here is a C wrapper :)
309 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
311 LyXVC::logClose(ob, data);
315 void LyXVC::logUpdate(FL_OBJECT * obj, long)
317 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
321 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
323 LyXVC::logUpdate(ob, data);
327 void LyXVC::viewLog(string const & fil)
329 static int ow = -1, oh;
333 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
335 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
336 browser->LaTeXLog->u_vdata = this;
337 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
338 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER, 10, 10, 450, 320, "");
339 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30, _("Close"));
340 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
341 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
342 obj = fl_add_button(FL_NORMAL_BUTTON,370,340,90,30,
343 idex(_("Update|#Uu")));
344 fl_set_button_shortcut(obj,scex(_("Update|#Uu")),1);
345 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
346 fl_set_object_callback(obj, C_LyXVC_logUpdate,0);
348 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
351 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
352 fl_add_browser_line(browser->browser_latexlog, _("No RCS History!"));
354 if (browser->LaTeXLog->visible) {
355 fl_raise_form(browser->LaTeXLog);
357 fl_show_form(browser->LaTeXLog,
358 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
361 ow = browser->LaTeXLog->w;
362 oh = browser->LaTeXLog->h;
364 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
369 void LyXVC::showLog()
371 string tmpf = tmpnam(0);
372 doVCCommand("rlog \""
373 + OnlyFilename(_owner->getFileName()) + "\" > " + tmpf);
375 unlink(tmpf.c_str());
379 int LyXVC::doVCCommand(string const & cmd)
381 lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
383 Path p(_owner->filepath);
384 int ret = one.startscript(Systemcalls::System, cmd);