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);
40 bool LyXVC::file_found_hook(string const & fn)
43 // Check if file is under RCS
44 if (!(found_file = RCS::find_file(fn)).empty()) {
45 vcs = new RCS(found_file);
49 // Check if file is under CVS
50 if (!(found_file = CVS::find_file(fn)).empty()) {
51 vcs = new CVS(found_file, fn);
55 // file is not under any VCS.
60 bool LyXVC::file_not_found_hook(string const & fn)
62 // Check if file is under RCS
63 if (!RCS::find_file(fn).empty())
65 if (!CVS::find_file(fn).empty())
71 void LyXVC::buffer(Buffer * buf)
77 void LyXVC::registrer()
79 // it is very likely here that the vcs is not created yet...
80 // so... we use RCS as default, later this should perhaps be
83 vcs = new RCS(owner_->fileName());
87 // If the document is changed, we might want to save it
88 if (!vcs->owner()->isLyxClean() &&
89 AskQuestion(_("Changes in document:"),
90 MakeDisplayPath(vcs->owner()->fileName(), 50),
91 _("Save document and proceed?"))) {
92 vcs->owner()->getUser()->owner()
93 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
96 // Maybe the save fails, or we answered "no". In both cases,
97 // the document will be dirty, and we abort.
98 if (!vcs->owner()->isLyxClean()) {
102 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
103 pair<bool, string> tmp = askForText(_("LyX VC: Initial description"),
104 _("(no initial description)"));
105 if (!tmp.first || tmp.second.empty()) {
106 // should we insist on checking tmp.second.empty()?
107 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
108 WriteAlert(_("Info"),
109 _("This document has NOT been registered."));
113 vcs->registrer(tmp.second);
117 void LyXVC::checkIn()
119 // If the document is changed, we might want to save it
120 if (!vcs->owner()->isLyxClean() &&
121 AskQuestion(_("Changes in document:"),
122 MakeDisplayPath(vcs->owner()->fileName(), 50),
123 _("Save document and proceed?"))) {
124 vcs->owner()->getUser()->owner()
125 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
128 // Maybe the save fails, or we answered "no". In both cases,
129 // the document will be dirty, and we abort.
130 if (!vcs->owner()->isLyxClean()) {
134 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
135 pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
137 if (tmp.second.empty()) {
138 tmp.second = _("(no log message)");
140 vcs->checkIn(tmp.second);
142 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
147 void LyXVC::checkOut()
149 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
150 if (!vcs->owner()->isLyxClean()
151 && !AskQuestion(_("Changes in document:"),
152 MakeDisplayPath(vcs->owner()->fileName(), 50),
153 _("Ignore changes and proceed with check out?"))) {
164 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
165 // Here we should check if the buffer is dirty. And if it is
166 // we should warn the user that reverting will discard all
167 // changes made since the last check in.
168 if (AskQuestion(_("When you revert, you will loose all changes made"),
169 _("to the document since the last check in."),
170 _("Do you still want to do it?"))) {
177 void LyXVC::undoLast()
183 void LyXVC::toggleReadOnly()
185 switch (vcs->stat()) {
187 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
191 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
200 if (vcs) return true;
205 string const & LyXVC::version() const
207 return vcs->version();
211 string const & LyXVC::locker() const
213 return vcs->locker();
217 // This is a hack anyway so I'll put it here in the mean time.
218 void LyXVC::logClose(FL_OBJECT * obj, long)
220 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
221 fl_hide_form(This->browser->LaTeXLog);
225 // and, hack over hack, here is a C wrapper :)
226 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
228 LyXVC::logClose(ob, data);
232 void LyXVC::logUpdate(FL_OBJECT * obj, long)
234 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
238 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
240 LyXVC::logUpdate(ob, data);
244 void LyXVC::viewLog(string const & fil)
246 static int ow = -1, oh;
250 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
252 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
253 browser->LaTeXLog->u_vdata = this;
254 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
255 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
258 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
260 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
261 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
262 obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
263 idex(_("Update|#Uu")));
264 fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
265 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
266 fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
268 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
271 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
272 fl_add_browser_line(browser->browser_latexlog,
273 _("No VC History!"));
275 if (browser->LaTeXLog->visible) {
276 fl_raise_form(browser->LaTeXLog);
278 fl_show_form(browser->LaTeXLog,
279 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
282 ow = browser->LaTeXLog->w;
283 oh = browser->LaTeXLog->h;
285 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
290 void LyXVC::showLog()
292 string tmpf = tmpnam(0);
295 unlink(tmpf.c_str());