9 #include FORMS_H_LOCATION
11 #include "vc-backend.h"
13 #include "lyx_gui_misc.h"
16 #include "support/filetools.h"
17 #include "support/lyxlib.h"
35 if (browser->LaTeXLog->visible)
36 fl_hide_form(browser->LaTeXLog);
37 fl_free_form(browser->LaTeXLog);
43 bool LyXVC::file_found_hook(string const & fn)
46 // Check if file is under RCS
47 if (!(found_file = RCS::find_file(fn)).empty()) {
48 vcs = new RCS(found_file);
52 // Check if file is under CVS
53 if (!(found_file = CVS::find_file(fn)).empty()) {
54 vcs = new CVS(found_file, fn);
58 // file is not under any VCS.
63 bool LyXVC::file_not_found_hook(string const & fn)
65 // Check if file is under RCS
66 if (!RCS::find_file(fn).empty())
68 if (!CVS::find_file(fn).empty())
74 void LyXVC::buffer(Buffer * buf)
80 void LyXVC::registrer()
82 // it is very likely here that the vcs is not created yet...
83 // so... we use RCS as default, later this should perhaps be
86 vcs = new RCS(owner_->fileName());
90 // If the document is changed, we might want to save it
91 if (!vcs->owner()->isLyxClean() &&
92 AskQuestion(_("Changes in document:"),
93 MakeDisplayPath(vcs->owner()->fileName(), 50),
94 _("Save document and proceed?"))) {
95 vcs->owner()->getUser()->owner()
96 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
99 // Maybe the save fails, or we answered "no". In both cases,
100 // the document will be dirty, and we abort.
101 if (!vcs->owner()->isLyxClean()) {
105 lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
106 pair<bool, string> tmp =
107 askForText(_("LyX VC: Initial description"),
108 _("(no initial description)"));
109 if (!tmp.first || tmp.second.empty()) {
110 // should we insist on checking tmp.second.empty()?
111 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
112 WriteAlert(_("Info"),
113 _("This document has NOT been registered."));
117 vcs->registrer(tmp.second);
121 void LyXVC::checkIn()
123 // If the document is changed, we might want to save it
124 if (!vcs->owner()->isLyxClean() &&
125 AskQuestion(_("Changes in document:"),
126 MakeDisplayPath(vcs->owner()->fileName(), 50),
127 _("Save document and proceed?"))) {
128 vcs->owner()->getUser()->owner()
129 ->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
132 // Maybe the save fails, or we answered "no". In both cases,
133 // the document will be dirty, and we abort.
134 if (!vcs->owner()->isLyxClean()) {
138 lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
139 pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
141 if (tmp.second.empty()) {
142 tmp.second = _("(no log message)");
144 vcs->checkIn(tmp.second);
146 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
151 void LyXVC::checkOut()
153 lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
154 if (!vcs->owner()->isLyxClean()
155 && !AskQuestion(_("Changes in document:"),
156 MakeDisplayPath(vcs->owner()->fileName(), 50),
157 _("Ignore changes and proceed with check out?"))) {
168 lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
169 // Here we should check if the buffer is dirty. And if it is
170 // we should warn the user that reverting will discard all
171 // changes made since the last check in.
172 if (AskQuestion(_("When you revert, you will loose all changes made"),
173 _("to the document since the last check in."),
174 _("Do you still want to do it?"))) {
181 void LyXVC::undoLast()
187 void LyXVC::toggleReadOnly()
189 switch (vcs->status()) {
191 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
195 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
204 if (vcs) return true;
209 string const & LyXVC::version() const
211 return vcs->version();
215 string const & LyXVC::locker() const
217 return vcs->locker();
221 // This is a hack anyway so I'll put it here in the mean time.
222 void LyXVC::logClose(FL_OBJECT * obj, long)
224 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
225 fl_hide_form(This->browser->LaTeXLog);
229 // and, hack over hack, here is a C wrapper :)
230 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
232 LyXVC::logClose(ob, data);
236 void LyXVC::logUpdate(FL_OBJECT * obj, long)
238 LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
242 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
244 LyXVC::logUpdate(ob, data);
248 void LyXVC::viewLog(string const & fil)
250 static int ow = -1, oh;
254 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
256 browser->LaTeXLog = fl_bgn_form(FL_NO_BOX, 470, 380);
257 browser->LaTeXLog->u_vdata = this;
258 obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 380, "");
259 browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER,
262 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
264 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
265 fl_set_object_callback(obj, C_LyXVC_logClose, 0);
266 obj = fl_add_button(FL_NORMAL_BUTTON, 370, 340, 90, 30,
267 idex(_("Update|#Uu")));
268 fl_set_button_shortcut(obj, scex(_("Update|#Uu")), 1);
269 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
270 fl_set_object_callback(obj, C_LyXVC_logUpdate, 0);
272 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
275 if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
276 fl_add_browser_line(browser->browser_latexlog,
277 _("No VC History!"));
279 if (browser->LaTeXLog->visible) {
280 fl_raise_form(browser->LaTeXLog);
282 fl_show_form(browser->LaTeXLog,
283 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
286 ow = browser->LaTeXLog->w;
287 oh = browser->LaTeXLog->h;
289 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
294 void LyXVC::showLog()
296 string tmpf = lyx::tempName(string(), "lyxvclog");