7 #include FORMS_H_LOCATION
10 #include "lyx_gui_misc.h"
11 #include "bufferlist.h"
12 #include "support/syscall.h"
13 #include "pathstack.h"
14 #include "support/filetools.h"
15 #include "support/FileInfo.h"
19 #include "latexoptions.h"
21 extern BufferList bufferlist;
22 extern void MenuWrite(Buffer *);
25 extern bool gsworking();
30 backend = UNKNOWN_VCS;
39 if (browser->LaTeXLog->visible)
40 fl_hide_form(browser->LaTeXLog);
41 fl_free_form(browser->LaTeXLog);
46 bool LyXVC::file_found_hook(string const & fn)
50 // Check if *,v exists.
52 lyxerr.debug(string("Checking if file is under vc: ") + tmp, Error::LYXVC);
53 if (f.newFile(tmp).readable()) {
54 lyxerr.debug("Yes it is under vc.", Error::LYXVC);
60 // Check if RCS/*,v exists.
61 tmp = AddName(AddPath(OnlyPath(fn), "RCS"), fn);
63 lyxerr.debug("Checking if file is under vc: " + tmp, Error::LYXVC);
64 if (f.newFile(tmp).readable()) {
65 lyxerr.debug("Yes it is under vc.", Error::LYXVC);
72 // If either one, return true
74 // file is not under any VCS.
79 bool LyXVC::file_not_found_hook(string const &)
81 // file is not under any VCS.
86 void LyXVC::scanMaster()
88 lyxerr.debug("LyXVC: This file is a VC file.", Error::LYXVC);
94 bool read_enough = false;
95 while (lex.IsOK() && !read_enough) {
97 token = lex.GetString();
99 lyxerr.debug("LyXVC::scanMaster: current lex text: `"
100 +token+"'", Error::LYXVC);
104 else if (token == "head") {
107 string tmv = strip(lex.GetString(), ';');
109 } else if (contains(token, "access")
110 || contains(token, "symbols")
111 || contains(token, "strict")) {
113 } else if (contains(token, "locks")) {
115 if (contains(token, ";")) {
123 s1 = strip(tmpt = lex.GetString(), ';');
124 // tmp is now in the format <user>:<version>
125 s1 = split(s1, s2, ':');
126 // s2 is user, and s1 is version
132 } while (!contains(tmpt, ";"));
134 } else if (token == "comment") {
135 // we don't need to read any further than this.
139 lyxerr.debug("LyXVC::scanMaster(): unexpected token", Error::LYXVC);
145 void LyXVC::setBuffer(Buffer *buf)
152 // I will probably add some backend_xxxx functions later to perform the
153 // version control system specific commands. Something like:
154 // void backend_revert(<params>) {
155 // if (backend == "RCS") {
156 // } else if (backend == "CVS") {
157 // } else if (backend == "SCCS") {
160 // But for 0.12 we will only support RCS.
163 void LyXVC::registrer()
165 // If the document is changed, we might want to save it
166 if (!_owner->isLyxClean() &&
167 AskQuestion(_("Changes in document:"),
168 MakeDisplayPath(_owner->getFileName(),50),
169 _("Save document and proceed?"))) {
173 // Maybe the save fails, or we answered "no". In both cases,
174 // the document will be dirty, and we abort.
175 if (!_owner->isLyxClean()) {
179 lyxerr.debug("LyXVC: registrer", Error::LYXVC);
180 string tmp = askForText(_("LyX VC: Initial description"),
181 _("(no initial description)"));
183 lyxerr.debug("LyXVC: user cancelled", Error::LYXVC);
184 WriteAlert(_("Info"), _("This document has NOT been registered."));
187 string cmd = "ci -q -u -i -t-\"";
190 cmd += OnlyFilename(_owner->getFileName());
193 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
197 void LyXVC::checkIn()
199 // If the document is changed, we might want to save it
200 if (!_owner->isLyxClean() &&
201 AskQuestion(_("Changes in document:"),
202 MakeDisplayPath(_owner->getFileName(),50),
203 _("Save document and proceed?"))) {
207 // Maybe the save fails, or we answered "no". In both cases,
208 // the document will be dirty, and we abort.
209 if (!_owner->isLyxClean()) {
213 lyxerr.debug("LyXVC: checkIn", Error::LYXVC);
214 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
215 string tmp = askForText(_("LyX VC: Log Message"));
216 if (tmp.empty()) tmp = "(no log msg)";
217 doVCCommand("ci -q -u -m\"" + tmp + "\" \""
218 + OnlyFilename(_owner->getFileName()) + "\"");
219 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
223 void LyXVC::checkOut()
225 lyxerr.debug("LyXVC: checkOut", Error::LYXVC);
226 if (!_owner->isLyxClean()
227 && !AskQuestion(_("Changes in document:"),
228 MakeDisplayPath(_owner->getFileName(),50),
229 _("Ignore changes and proceed with check out?"))) {
233 _owner->markLyxClean();
234 doVCCommand("co -q -l \""
235 + OnlyFilename(_owner->getFileName()) + "\"");
236 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
242 lyxerr.debug("LyXVC: revert", Error::LYXVC);
243 // Here we should check if the buffer is dirty. And if it is
244 // we should warn the user that reverting will discard all
245 // changes made since the last check in.
246 if (AskQuestion(_("When you revert, you will loose all changes made"),
247 _("to the document since the last check in."),
248 _("Do you still want to do it?"))) {
250 doVCCommand("co -f -u" + getVersion() + " \""
251 + OnlyFilename(_owner->getFileName()) + "\"");
252 // We ignore changes and just reload!
253 _owner->markLyxClean();
254 _owner->getUser()->getOwner()->
255 getLyXFunc()->Dispatch("buffer-reload");
260 void LyXVC::undoLast()
262 lyxerr.debug("LyXVC: undoLast", Error::LYXVC);
263 doVCCommand("rcs -o" + getVersion() + " \""
264 + OnlyFilename(_owner->getFileName()) + "\"");
268 void LyXVC::toggleReadOnly()
289 string const LyXVC::getVersion() const
295 string const LyXVC::getLocker() const
300 // This is a hack anyway so I'll put it here in the mean time.
301 void LyXVC::logClose(FL_OBJECT *obj, long)
303 LyXVC *This = (LyXVC*)obj->form->u_vdata;
304 fl_hide_form(This->browser->LaTeXLog);
308 void LyXVC::logUpdate(FL_OBJECT *obj, long)
310 LyXVC *This = (LyXVC*)obj->form->u_vdata;
315 void LyXVC::viewLog(string const & fil)
319 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
321 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
322 browser->LaTeXLog->u_vdata = (void*)this;
323 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
324 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER, 10, 10, 450, 320, "");
325 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30, _("Close"));
326 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
327 fl_set_object_callback(obj, logClose, 0);
328 obj = fl_add_button(FL_NORMAL_BUTTON,370,340,90,30,
329 idex(_("Update|#Uu")));
330 fl_set_button_shortcut(obj,scex(_("Update|#Uu")),1);
331 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
332 fl_set_object_callback(obj,logUpdate,0);
334 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
337 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
338 fl_add_browser_line(browser->browser_latexlog, _("No RCS History!"));
340 if (browser->LaTeXLog->visible) {
341 fl_raise_form(browser->LaTeXLog);
343 fl_show_form(browser->LaTeXLog,
344 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
350 void LyXVC::showLog()
352 // This I really don't like, but we'll look at this problem
353 // in 0.13. Then we can make a clean solution.
356 WriteAlert(_("Sorry, can't do this while"
357 " pictures are being rendered."),
358 _("Please wait a few seconds for"
359 " this to finish and try again."),
360 _("(or kill runaway gs processes"
361 " by hand and try again.)"));
364 extern pid_t isp_pid; // from spellchecker.C
366 WriteAlert(_("Can't do this while the"
367 " spellchecker is running."),
368 _("Stop the spellchecker first."));
372 string tmpf = tmpnam(0);
373 doVCCommand("rlog \""
374 + OnlyFilename(_owner->getFileName()) + "\" > " + tmpf);
376 unlink(tmpf.c_str());
380 int LyXVC::doVCCommand(string const & cmd)
382 lyxerr.debug("doVCCommand: " + cmd, Error::LYXVC);
384 PathPush(_owner->filepath);
385 int ret = one.Startscript(Systemcalls::System, cmd);