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 & fn)
64 // Check if file is under RCS
65 if (!RCS::find_file(fn).empty())
67 if (!CVS::find_file(fn).empty())
73 void LyXVC::buffer(Buffer * buf)
79 void LyXVC::registrer()
81 // it is very likely here that the vcs is not created yet...
82 // so... we use RCS as default, later this should perhaps be
85 vcs = new RCS(owner_->fileName());
89 // If the document is changed, we might want to save it
90 if (!vcs->owner()->isLyxClean() &&
91 AskQuestion(_("Changes in document:"),
92 MakeDisplayPath(vcs->owner()->fileName(), 50),
93 _("Save document and proceed?"))) {
94 vcs->owner()->getUser()->owner()
95 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
98 // Maybe the save fails, or we answered "no". In both cases,
99 // the document will be dirty, and we abort.
100 if (!vcs->owner()->isLyxClean()) {
104 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
105 pair<bool, string> tmp = askForText(_("LyX VC: Initial description"),
106 _("(no initial description)"));
107 if (!tmp.first || tmp.second.empty()) {
108 // should we insist on checking tmp.second.empty()?
109 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
110 WriteAlert(_("Info"),
111 _("This document has NOT been registered."));
115 vcs->registrer(tmp.second);
119 void LyXVC::checkIn()
121 // If the document is changed, we might want to save it
122 if (!vcs->owner()->isLyxClean() &&
123 AskQuestion(_("Changes in document:"),
124 MakeDisplayPath(vcs->owner()->fileName(), 50),
125 _("Save document and proceed?"))) {
126 vcs->owner()->getUser()->owner()
127 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
130 // Maybe the save fails, or we answered "no". In both cases,
131 // the document will be dirty, and we abort.
132 if (!vcs->owner()->isLyxClean()) {
136 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
137 pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
139 if (tmp.second.empty()) {
140 tmp.second = _("(no log message)");
142 vcs->checkIn(tmp.second);
144 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
149 void LyXVC::checkOut()
151 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
152 if (!vcs->owner()->isLyxClean()
153 && !AskQuestion(_("Changes in document:"),
154 MakeDisplayPath(vcs->owner()->fileName(), 50),
155 _("Ignore changes and proceed with check out?"))) {
166 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
167 // Here we should check if the buffer is dirty. And if it is
168 // we should warn the user that reverting will discard all
169 // changes made since the last check in.
170 if (AskQuestion(_("When you revert, you will loose all changes made"),
171 _("to the document since the last check in."),
172 _("Do you still want to do it?"))) {
179 void LyXVC::undoLast()
185 void LyXVC::toggleReadOnly()
187 switch (vcs->stat()) {
189 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
193 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
202 if (vcs) return true;
207 string const & LyXVC::version() const
209 return vcs->version();
213 string const & LyXVC::locker() const
215 return vcs->locker();
219 // This is a hack anyway so I'll put it here in the mean time.
220 void LyXVC::logClose(FL_OBJECT * obj, long)
222 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
223 fl_hide_form(This->browser->LaTeXLog);
227 // and, hack over hack, here is a C wrapper :)
228 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
230 LyXVC::logClose(ob, data);
234 void LyXVC::logUpdate(FL_OBJECT * obj, long)
236 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
240 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
242 LyXVC::logUpdate(ob, data);
246 void LyXVC::viewLog(string const & fil)
248 static int ow = -1, oh;
252 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
254 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
255 browser->LaTeXLog->u_vdata = this;
256 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
257 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
260 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
262 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
263 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
264 obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
265 idex(_("Update|#Uu")));
266 fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
267 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
268 fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
270 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
273 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
274 fl_add_browser_line(browser->browser_latexlog,
275 _("No VC History!"));
277 if (browser->LaTeXLog->visible) {
278 fl_raise_form(browser->LaTeXLog);
280 fl_show_form(browser->LaTeXLog,
281 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
284 ow = browser->LaTeXLog->w;
285 oh = browser->LaTeXLog->h;
287 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
292 void LyXVC::showLog()
294 string tmpf = tmpnam(0);
297 unlink(tmpf.c_str());