7 #include FORMS_H_LOCATION
10 #include "lyx_gui_misc.h"
11 #include "bufferlist.h"
13 #include "pathstack.h"
14 #include "filetools.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(LString const & fn)
50 // Check if *,v exists.
52 lyxerr.debug(LString("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(LString 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 LString tmv = lex.GetString();
110 } else if (token.contains("access")
111 || token.contains("symbols")
112 || token.contains("strict")) {
114 } else if (token.contains("locks")) {
116 if (token.contains(";")) {
121 LString tmpt, s1, s2;
124 tmpt = lex.GetString();
127 // tmp is now in the format <user>:<version>
129 // s2 is user, and s1 is version
135 } while (!tmpt.contains(";"));
137 } else if (token == "comment") {
138 // we don't need to read any further than this.
142 lyxerr.debug("LyXVC::scanMaster(): unexpected token", Error::LYXVC);
148 void LyXVC::setBuffer(Buffer *buf)
155 // I will probably add some backend_xxxx functions later to perform the
156 // version control system specific commands. Something like:
157 // void backend_revert(<params>) {
158 // if (backend == "RCS") {
159 // } else if (backend == "CVS") {
160 // } else if (backend == "SCCS") {
163 // But for 0.12 we will only support RCS.
166 void LyXVC::registrer()
168 // If the document is changed, we might want to save it
169 if (!_owner->isLyxClean() &&
170 AskQuestion(_("Changes in document:"),
171 MakeDisplayPath(_owner->getFileName(),50),
172 _("Save document and proceed?"))) {
176 // Maybe the save fails, or we answered "no". In both cases,
177 // the document will be dirty, and we abort.
178 if (!_owner->isLyxClean()) {
182 lyxerr.debug("LyXVC: registrer", Error::LYXVC);
183 LString tmp = askForText(_("LyX VC: Initial description"),
184 _("(no initial description)"));
186 lyxerr.debug("LyXVC: user cancelled", Error::LYXVC);
187 WriteAlert(_("Info"), _("This document has NOT been registered."));
190 LString cmd = "ci -q -u -i -t-\"";
193 cmd += OnlyFilename(_owner->getFileName());
196 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
200 void LyXVC::checkIn()
202 // If the document is changed, we might want to save it
203 if (!_owner->isLyxClean() &&
204 AskQuestion(_("Changes in document:"),
205 MakeDisplayPath(_owner->getFileName(),50),
206 _("Save document and proceed?"))) {
210 // Maybe the save fails, or we answered "no". In both cases,
211 // the document will be dirty, and we abort.
212 if (!_owner->isLyxClean()) {
216 lyxerr.debug("LyXVC: checkIn", Error::LYXVC);
217 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
218 LString tmp = askForText(_("LyX VC: Log Message"));
219 if (tmp.empty()) tmp = "(no log msg)";
220 doVCCommand("ci -q -u -m\"" + tmp + "\" \""
221 + OnlyFilename(_owner->getFileName()) + "\"");
222 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
226 void LyXVC::checkOut()
228 lyxerr.debug("LyXVC: checkOut", Error::LYXVC);
229 if (!_owner->isLyxClean()
230 && !AskQuestion(_("Changes in document:"),
231 MakeDisplayPath(_owner->getFileName(),50),
232 _("Ignore changes and proceed with check out?"))) {
236 _owner->markLyxClean();
237 doVCCommand("co -q -l \""
238 + OnlyFilename(_owner->getFileName()) + "\"");
239 _owner->getUser()->getOwner()->getLyXFunc()->Dispatch("buffer-reload");
245 lyxerr.debug("LyXVC: revert", Error::LYXVC);
246 // Here we should check if the buffer is dirty. And if it is
247 // we should warn the user that reverting will discard all
248 // changes made since the last check in.
249 if (AskQuestion(_("When you revert, you will loose all changes made"),
250 _("to the document since the last check in."),
251 _("Do you still want to do it?"))) {
253 doVCCommand("co -f -u" + getVersion() + " \""
254 + OnlyFilename(_owner->getFileName()) + "\"");
255 // We ignore changes and just reload!
256 _owner->markLyxClean();
257 _owner->getUser()->getOwner()->
258 getLyXFunc()->Dispatch("buffer-reload");
263 void LyXVC::undoLast()
265 lyxerr.debug("LyXVC: undoLast", Error::LYXVC);
266 doVCCommand("rcs -o" + getVersion() + " \""
267 + OnlyFilename(_owner->getFileName()) + "\"");
271 void LyXVC::toggleReadOnly()
292 LString const LyXVC::getVersion() const
298 LString const LyXVC::getLocker() const
303 // This is a hack anyway so I'll put it here in the mean time.
304 void LyXVC::logClose(FL_OBJECT *obj, long)
306 LyXVC *This = (LyXVC*)obj->form->u_vdata;
307 fl_hide_form(This->browser->LaTeXLog);
311 void LyXVC::logUpdate(FL_OBJECT *obj, long)
313 LyXVC *This = (LyXVC*)obj->form->u_vdata;
318 void LyXVC::viewLog(LString const & fil)
322 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
324 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
325 browser->LaTeXLog->u_vdata = (void*)this;
326 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
327 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER, 10, 10, 450, 320, "");
328 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30, _("Close"));
329 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
330 fl_set_object_callback(obj, logClose, 0);
331 obj = fl_add_button(FL_NORMAL_BUTTON,370,340,90,30,
332 idex(_("Update|#Uu")));
333 fl_set_button_shortcut(obj,scex(_("Update|#Uu")),1);
334 fl_set_object_lsize(obj,FL_NORMAL_SIZE);
335 fl_set_object_callback(obj,logUpdate,0);
337 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, NULL);
340 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
341 fl_add_browser_line(browser->browser_latexlog, _("No RCS History!"));
343 if (browser->LaTeXLog->visible) {
344 fl_raise_form(browser->LaTeXLog);
346 fl_show_form(browser->LaTeXLog,
347 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
353 void LyXVC::showLog()
355 // This I really don't like, but we'll look at this problem
356 // in 0.13. Then we can make a clean solution.
359 WriteAlert(_("Sorry, can't do this while"
360 " pictures are being rendered."),
361 _("Please wait a few seconds for"
362 " this to finish and try again."),
363 _("(or kill runaway gs processes"
364 " by hand and try again.)"));
367 extern pid_t isp_pid; // from spellchecker.C
369 WriteAlert(_("Can't do this while the"
370 " spellchecker is running."),
371 _("Stop the spellchecker first."));
375 LString tmpf = tmpnam(NULL);
376 doVCCommand("rlog \""
377 + OnlyFilename(_owner->getFileName()) + "\" > " + tmpf);
379 unlink(tmpf.c_str());
383 int LyXVC::doVCCommand(LString const & cmd)
385 lyxerr.debug("doVCCommand: " + cmd, Error::LYXVC);
387 PathPush(_owner->filepath);
388 int ret = one.Startscript(Systemcalls::System, cmd);