9 #include FORMS_H_LOCATION
11 #include "vc-backend.h"
13 #include "lyx_gui_misc.h"
16 #include "support/filetools.h"
32 if (browser->LaTeXLog->visible)
33 fl_hide_form(browser->LaTeXLog);
34 fl_free_form(browser->LaTeXLog);
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 &)
64 // file is not under any VCS.
69 void LyXVC::buffer(Buffer * buf)
75 void LyXVC::registrer()
77 // it is very likely here that the vcs is not created yet...
78 // so... we use RCS as default, later this should perhaps be
81 vcs = new RCS(owner_->fileName());
85 // If the document is changed, we might want to save it
86 if (!vcs->owner()->isLyxClean() &&
87 AskQuestion(_("Changes in document:"),
88 MakeDisplayPath(vcs->owner()->fileName(), 50),
89 _("Save document and proceed?"))) {
90 vcs->owner()->getUser()->owner()
91 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
94 // Maybe the save fails, or we answered "no". In both cases,
95 // the document will be dirty, and we abort.
96 if (!vcs->owner()->isLyxClean()) {
100 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
101 pair<bool, string> tmp = askForText(_("LyX VC: Initial description"),
102 _("(no initial description)"));
103 if (!tmp.first || tmp.second.empty()) {
104 // should we insist on checking tmp.second.empty()?
105 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
106 WriteAlert(_("Info"),
107 _("This document has NOT been registered."));
111 vcs->registrer(tmp.second);
115 void LyXVC::checkIn()
117 // If the document is changed, we might want to save it
118 if (!vcs->owner()->isLyxClean() &&
119 AskQuestion(_("Changes in document:"),
120 MakeDisplayPath(vcs->owner()->fileName(), 50),
121 _("Save document and proceed?"))) {
122 vcs->owner()->getUser()->owner()
123 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
126 // Maybe the save fails, or we answered "no". In both cases,
127 // the document will be dirty, and we abort.
128 if (!vcs->owner()->isLyxClean()) {
132 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
133 pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
135 if (tmp.second.empty()) {
136 tmp.second = _("(no log message)");
138 vcs->checkIn(tmp.second);
140 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
145 void LyXVC::checkOut()
147 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
148 if (!vcs->owner()->isLyxClean()
149 && !AskQuestion(_("Changes in document:"),
150 MakeDisplayPath(vcs->owner()->fileName(), 50),
151 _("Ignore changes and proceed with check out?"))) {
162 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
163 // Here we should check if the buffer is dirty. And if it is
164 // we should warn the user that reverting will discard all
165 // changes made since the last check in.
166 if (AskQuestion(_("When you revert, you will loose all changes made"),
167 _("to the document since the last check in."),
168 _("Do you still want to do it?"))) {
175 void LyXVC::undoLast()
181 void LyXVC::toggleReadOnly()
183 switch (vcs->stat()) {
185 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
189 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
198 if (vcs) return true;
203 string const & LyXVC::version() const
205 return vcs->version();
209 string const & LyXVC::locker() const
211 return vcs->locker();
215 // This is a hack anyway so I'll put it here in the mean time.
216 void LyXVC::logClose(FL_OBJECT * obj, long)
218 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
219 fl_hide_form(This->browser->LaTeXLog);
223 // and, hack over hack, here is a C wrapper :)
224 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
226 LyXVC::logClose(ob, data);
230 void LyXVC::logUpdate(FL_OBJECT * obj, long)
232 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
236 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
238 LyXVC::logUpdate(ob, data);
242 void LyXVC::viewLog(string const & fil)
244 static int ow = -1, oh;
248 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
250 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
251 browser->LaTeXLog->u_vdata = this;
252 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
253 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
256 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
258 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
259 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
260 obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
261 idex(_("Update|#Uu")));
262 fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
263 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
264 fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
266 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
269 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
270 fl_add_browser_line(browser->browser_latexlog,
271 _("No VC History!"));
273 if (browser->LaTeXLog->visible) {
274 fl_raise_form(browser->LaTeXLog);
276 fl_show_form(browser->LaTeXLog,
277 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
280 ow = browser->LaTeXLog->w;
281 oh = browser->LaTeXLog->h;
283 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
288 void LyXVC::showLog()
290 string tmpf = tmpnam(0);
293 unlink(tmpf.c_str());