3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
23 #include "bufferparams.h"
24 #include "BufferView.h"
25 #include "bufferview_funcs.h"
28 #include "errorlist.h"
29 #include "funcrequest.h"
36 #include "MenuBackend.h"
37 #include "paragraph.h"
39 #include "controllers/ControlCommandBuffer.h"
41 #include "support/lstrings.h"
42 #include "support/filetools.h" // OnlyFilename()
44 #include <boost/bind.hpp>
46 #ifdef HAVE_SYS_TIME_H
47 # include <sys/time.h>
53 using lyx::frontend::Gui;
54 using lyx::frontend::WorkArea;
57 using lyx::support::bformat;
58 using lyx::support::makeDisplayPath;
59 using lyx::support::onlyFilename;
64 using lyx::frontend::ControlCommandBuffer;
66 string current_layout;
74 LyXView::LyXView(Gui & owner)
77 toolbars_(new Toolbars(*this)),
78 autosave_timeout_(new Timeout(5000)),
79 lyxfunc_(new LyXFunc(this)),
80 dialogs_(new Dialogs(*this)),
81 controlcommand_(new ControlCommandBuffer(*this))
83 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
92 void LyXView::setWorkArea(WorkArea * work_area)
94 work_area_ = work_area;
98 void LyXView::redrawWorkArea()
100 work_area_->redraw();
105 WorkArea * LyXView::workArea()
113 updateLayoutChoice();
116 // Start autosave timer
117 if (lyxrc.autosave) {
118 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
119 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
120 autosave_timeout_->start();
125 Buffer * LyXView::buffer() const
127 return work_area_->bufferView().buffer();
131 void LyXView::setBuffer(Buffer * b)
133 if (work_area_->bufferView().buffer())
137 getDialogs().hideBufferDependent();
139 work_area_->bufferView().setBuffer(b);
141 if (work_area_->bufferView().buffer()) {
142 // Buffer-dependent dialogs should be updated or
143 // hidden. This should go here because some dialogs (eg ToC)
144 // require bv_->text.
145 getDialogs().updateBufferDependent(true);
146 connectBuffer(*work_area_->bufferView().buffer());
151 updateLayoutChoice();
157 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
159 if (work_area_->bufferView().buffer())
162 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
166 updateLayoutChoice();
169 connectBuffer(*work_area_->bufferView().buffer());
170 showErrorList("Parse");
177 void LyXView::connectBuffer(Buffer & buf)
179 if (errorsConnection_.connected())
184 boost::bind(&LyXView::showErrorList, this, _1));
188 boost::bind(&LyXView::message, this, _1));
192 boost::bind(&LyXView::busy, this, _1));
195 buf.updateTitles.connect(
196 boost::bind(&LyXView::updateWindowTitle, this));
199 buf.resetAutosaveTimers.connect(
200 boost::bind(&LyXView::resetAutosaveTimer, this));
202 readonlyConnection_ =
203 buf.readonly.connect(
204 boost::bind(&LyXView::showReadonly, this, _1));
208 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
212 void LyXView::disconnectBuffer()
214 messageConnection_.disconnect();
215 busyConnection_.disconnect();
216 titleConnection_.disconnect();
217 timerConnection_.disconnect();
218 readonlyConnection_.disconnect();
219 closingConnection_.disconnect();
223 void LyXView::connectBufferView(BufferView & bv)
225 show_dialog_connection_ = bv.showDialog.connect(
226 boost::bind(&LyXView::showDialog, this, _1));
227 show_dialog_with_data_connection_ = bv.showDialogWithData.connect(
228 boost::bind(&LyXView::showDialogWithData, this, _1, _2));
229 show_inset_dialog_connection_ = bv.showInsetDialog.connect(
230 boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3));
231 update_dialog_connection_ = bv.updateDialog.connect(
232 boost::bind(&LyXView::updateDialog, this, _1, _2));
236 void LyXView::disconnectBufferView()
238 show_dialog_connection_.disconnect();
239 show_dialog_with_data_connection_.disconnect();
240 show_inset_dialog_connection_.disconnect();
241 update_dialog_connection_.disconnect();
245 void LyXView::showErrorList(string const & error_type)
247 ErrorList & el = buffer()->errorList(error_type);
249 getDialogs().show("errorlist", error_type);
254 void LyXView::showDialog(string const & name)
256 getDialogs().show(name);
260 void LyXView::showDialogWithData(string const & name,
263 getDialogs().show(name, data);
267 void LyXView::showInsetDialog(string const & name, string const & data,
270 getDialogs().show(name, data, 0);
274 void LyXView::updateDialog(string const & name, string const & data)
276 if (getDialogs().visible(name))
277 getDialogs().update(name, data);
281 void LyXView::showReadonly(bool)
284 getDialogs().updateBufferDependent(false);
288 BufferView * LyXView::view() const
290 return &work_area_->bufferView();
294 void LyXView::setLayout(string const & layout)
296 toolbars_->setLayout(layout);
300 void LyXView::updateToolbars()
302 bool const math = work_area_->bufferView().cursor().inMathed();
304 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
305 toolbars_->update(math, table);
306 // update redaonly status of open dialogs. This could also be in
307 // updateMenubar(), but since updateToolbars() and updateMenubar()
308 // are always called together it is only here.
309 getDialogs().checkStatus();
313 void LyXView::updateMenubar()
319 void LyXView::autoSave()
321 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
323 if (view()->buffer()) {
329 void LyXView::resetAutosaveTimer()
332 autosave_timeout_->restart();
336 void LyXView::updateLayoutChoice()
338 // Don't show any layouts without a buffer
339 if (!view()->buffer()) {
340 toolbars_->clearLayoutList();
344 // Update the layout display
345 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
346 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
349 if (work_area_->bufferView().cursor().inMathed())
352 string const & layout =
353 work_area_->bufferView().cursor().paragraph().layout()->name();
355 if (layout != current_layout) {
356 toolbars_->setLayout(layout);
357 current_layout = layout;
362 void LyXView::updateWindowTitle()
364 static docstring last_title = lyx::from_ascii("LyX");
365 docstring maximize_title = lyx::from_ascii("LyX");
366 docstring minimize_title = lyx::from_ascii("LyX");
368 if (view()->buffer()) {
369 string const cur_title = buffer()->fileName();
370 if (!cur_title.empty()) {
371 maximize_title += lyx::from_ascii(": ") + makeDisplayPath(cur_title, 30);
372 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
373 if (!buffer()->isClean()) {
374 maximize_title += _(" (changed)");
375 minimize_title += lyx::char_type('*');
377 if (buffer()->isReadonly())
378 maximize_title += _(" (read only)");
382 if (maximize_title != last_title) {
383 setWindowTitle(maximize_title, minimize_title);
384 last_title = maximize_title;
389 void LyXView::dispatch(FuncRequest const & cmd)
391 getLyXFunc().dispatch(cmd);
395 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
397 Buffer const * buffer_ptr = 0;
399 buffer_ptr = work_area_->bufferView().buffer();
401 work_area_->bufferView().update(Update::Force);