]> git.lyx.org Git - lyx.git/blob - src/lyxvc.C
get rid of turds, no.po update and remove some warnings
[lyx.git] / src / lyxvc.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <unistd.h>
8
9 #include FORMS_H_LOCATION
10 #include "lyxvc.h"
11 #include "vc-backend.h"
12 #include "debug.h"
13 #include "lyx_gui_misc.h"
14 #include "buffer.h"
15 #include "gettext.h"
16 #include "support/filetools.h"
17 #include "support/lyxlib.h"
18 #include "lyxfunc.h"
19 #include "LyXView.h"
20
21 using std::endl;
22 using std::pair;
23
24 LyXVC::LyXVC()
25 {
26         vcs = 0;
27         browser = 0;
28         owner_ = 0;
29 }
30
31
32 LyXVC::~LyXVC()
33 {
34         if (browser) {
35                 if (browser->LaTeXLog->visible)
36                         fl_hide_form(browser->LaTeXLog);
37                 fl_free_form(browser->LaTeXLog);
38         }
39         delete vcs;
40 }
41
42
43 bool LyXVC::file_found_hook(string const & fn)
44 {
45         string found_file;
46         // Check if file is under RCS
47         if (!(found_file = RCS::find_file(fn)).empty()) {
48                 vcs = new RCS(found_file);
49                 vcs->owner(owner_);
50                 return true;
51         }
52         // Check if file is under CVS
53         if (!(found_file = CVS::find_file(fn)).empty()) {
54                 vcs = new CVS(found_file, fn);
55                 vcs->owner(owner_);
56                 return true;
57         }
58         // file is not under any VCS.
59         return false;
60 }
61
62
63 bool LyXVC::file_not_found_hook(string const & fn)
64 {
65         // Check if file is under RCS
66         if (!RCS::find_file(fn).empty())
67                 return true;
68         if (!CVS::find_file(fn).empty())
69                 return true;
70         return false;
71 }
72
73
74 void LyXVC::buffer(Buffer * buf)
75 {
76         owner_ = buf;
77 }
78
79
80 void LyXVC::registrer()
81 {
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
84         // a lyxrc option.
85         if (!vcs) {
86                 vcs = new RCS(owner_->fileName());
87                 vcs->owner(owner_);
88         }
89         
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);
97         }
98
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()) {
102                 return;
103         }
104
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."));
114                 return;
115         }
116         
117         vcs->registrer(tmp.second);
118 }
119
120
121 void LyXVC::checkIn()
122 {
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);
130         }
131
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()) {
135                 return;
136         }
137
138         lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
139         pair<bool, string> tmp = askForText(_("LyX VC: Log Message"));
140         if (tmp.first) {
141                 if (tmp.second.empty()) {
142                         tmp.second = _("(no log message)");
143                 }
144                 vcs->checkIn(tmp.second);
145         } else {
146                 lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
147         }
148 }
149
150
151 void LyXVC::checkOut()
152 {
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?"))) {
158                 return;
159         }
160
161         vcs->checkOut();
162         
163 }
164
165
166 void LyXVC::revert()
167 {
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?"))) {
175
176                 vcs->revert();
177         }
178 }
179
180
181 void LyXVC::undoLast()
182 {
183         vcs->undoLast();
184 }
185
186
187 void LyXVC::toggleReadOnly()
188 {
189         switch (vcs->status()) {
190         case VCS::UNLOCKED:
191                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to locked" << endl;
192                 checkOut();
193                 break;
194         case VCS::LOCKED:
195                 lyxerr[Debug::LYXVC] << "LyXVC: toggle to unlocked" << endl;
196                 checkIn();
197                 break;
198         }
199 }
200
201
202 bool LyXVC::inUse()
203 {
204         if (vcs) return true;
205         return false;
206 }
207
208
209 string const & LyXVC::version() const
210 {
211         return vcs->version();
212 }
213
214
215 string const & LyXVC::locker() const
216 {
217         return vcs->locker();
218 }
219
220
221 // This is a hack anyway so I'll put it here in the mean time.
222 void LyXVC::logClose(FL_OBJECT * obj, long)
223 {
224         LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
225         fl_hide_form(This->browser->LaTeXLog);
226 }
227
228
229 // and, hack over hack, here is a C wrapper :)
230 extern "C" void C_LyXVC_logClose(FL_OBJECT * ob, long data)
231 {
232         LyXVC::logClose(ob, data);
233 }
234
235
236 void LyXVC::logUpdate(FL_OBJECT * obj, long)
237 {
238         LyXVC * This = static_cast<LyXVC*>(obj->form->u_vdata);
239         This->showLog();
240 }
241
242 extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
243 {
244         LyXVC::logUpdate(ob, data);
245 }
246
247
248 void LyXVC::viewLog(string const & fil)
249 {
250         static int ow = -1, oh;
251
252         if (!browser) {
253                 FL_OBJECT * obj;
254                 browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
255                 
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,
260                                                            10, 10,
261                                                            450, 320, "");
262                 obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30,
263                                     _("Close"));
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);
271                 fl_end_form();
272                 fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
273         }
274
275         if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
276                 fl_add_browser_line(browser->browser_latexlog,
277                                     _("No VC History!"));
278         
279         if (browser->LaTeXLog->visible) {
280                 fl_raise_form(browser->LaTeXLog);
281         } else {
282                 fl_show_form(browser->LaTeXLog,
283                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
284                              _("VC History"));
285                 if (ow < 0) {
286                         ow = browser->LaTeXLog->w;
287                         oh = browser->LaTeXLog->h;
288                 }
289                 fl_set_form_minsize(browser->LaTeXLog, ow, oh);
290         }
291 }
292
293
294 void LyXVC::showLog()
295 {
296         string tmpf = lyx::tempName(string(), "lyxvclog");
297         vcs->getLog(tmpf);
298         viewLog(tmpf);
299         lyx::unlink(tmpf);
300 }