9 #include FORMS_H_LOCATION
11 #include "vc-backend.h"
13 #include "lyx_gui_misc.h"
16 #include "support/filetools.h"
34 if (browser->LaTeXLog->visible)
35 fl_hide_form(browser->LaTeXLog);
36 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 =
106 askForText(_("LyX VC: Initial description"),
107 _("(no initial description)"));
108 if (!tmp.first || tmp.second.empty()) {
109 // should we insist on checking tmp.second.empty()?
110 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
111 WriteAlert(_("Info"),
112 _("This document has NOT been registered."));
116 vcs->registrer(tmp.second);
120 void LyXVC::checkIn()
122 // If the document is changed, we might want to save it
123 if (!vcs->owner()->isLyxClean() &&
124 AskQuestion(_("Changes in document:"),
125 MakeDisplayPath(vcs->owner()->fileName(), 50),
126 _("Save document and proceed?"))) {
127 vcs->owner()->getUser()->owner()
128 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
131 // Maybe the save fails, or we answered "no". In both cases,
132 // the document will be dirty, and we abort.
133 if (!vcs->owner()->isLyxClean()) {
137 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
138 pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
140 if (tmp.second.empty()) {
141 tmp.second = _("(no log message)");
143 vcs->checkIn(tmp.second);
145 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
150 void LyXVC::checkOut()
152 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
153 if (!vcs->owner()->isLyxClean()
154 && !AskQuestion(_("Changes in document:"),
155 MakeDisplayPath(vcs->owner()->fileName(), 50),
156 _("Ignore changes and proceed with check out?"))) {
167 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
168 // Here we should check if the buffer is dirty. And if it is
169 // we should warn the user that reverting will discard all
170 // changes made since the last check in.
171 if (AskQuestion(_("When you revert, you will loose all changes made"),
172 _("to the document since the last check in."),
173 _("Do you still want to do it?"))) {
180 void LyXVC::undoLast()
186 void LyXVC::toggleReadOnly()
188 switch (vcs->status()) {
190 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
194 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
203 if (vcs) return true;
208 string const & LyXVC::version() const
210 return vcs->version();
214 string const & LyXVC::locker() const
216 return vcs->locker();
220 // This is a hack anyway so I'll put it here in the mean time.
221 void LyXVC::logClose(FL_OBJECT * obj, long)
223 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
224 fl_hide_form(This->browser->LaTeXLog);
228 // and, hack over hack, here is a C wrapper :)
229 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
231 LyXVC::logClose(ob, data);
235 void LyXVC::logUpdate(FL_OBJECT * obj, long)
237 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
241 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
243 LyXVC::logUpdate(ob, data);
247 void LyXVC::viewLog(string const & fil)
249 static int ow = -1, oh;
253 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
255 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
256 browser->LaTeXLog->u_vdata = this;
257 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
258 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
261 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
263 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
264 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
265 obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
266 idex(_("Update|#Uu")));
267 fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
268 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
269 fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
271 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
274 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
275 fl_add_browser_line(browser->browser_latexlog,
276 _("No VC History!"));
278 if (browser->LaTeXLog->visible) {
279 fl_raise_form(browser->LaTeXLog);
281 fl_show_form(browser->LaTeXLog,
282 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
285 ow = browser->LaTeXLog->w;
286 oh = browser->LaTeXLog->h;
288 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
293 void LyXVC::showLog()
295 string tmpf = tmpnam(0);
298 unlink(tmpf.c_str());