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.
22 #include "bufferparams.h"
23 #include "BufferView.h"
24 #include "bufferview_funcs.h"
27 #include "errorlist.h"
28 #include "funcrequest.h"
35 #include "MenuBackend.h"
36 #include "paragraph.h"
38 #include "controllers/ControlCommandBuffer.h"
40 #include "support/lstrings.h"
41 #include "support/filetools.h" // OnlyFilename()
43 #include <boost/bind.hpp>
48 #ifdef HAVE_SYS_TIME_H
49 # include <sys/time.h>
55 using lyx::frontend::WorkArea;
58 using lyx::support::bformat;
59 using lyx::support::makeDisplayPath;
60 using lyx::support::onlyFilename;
65 using lyx::frontend::ControlCommandBuffer;
67 string current_layout;
72 toolbars_(new Toolbars(*this)),
73 autosave_timeout_(new Timeout(5000)),
74 dialogs_(new Dialogs(*this)),
75 controlcommand_(new ControlCommandBuffer(*this))
77 // Start autosave timer
79 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
80 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
81 autosave_timeout_->start();
91 void LyXView::setWorkArea(WorkArea * work_area)
93 work_area_ = work_area;
97 void LyXView::redrawWorkArea()
104 WorkArea * LyXView::workArea()
110 Buffer * LyXView::buffer() const
112 return work_area_->bufferView().buffer();
116 void LyXView::setBuffer(Buffer * b)
118 if (work_area_->bufferView().buffer())
122 getDialogs().hideBufferDependent();
124 work_area_->bufferView().setBuffer(b);
126 if (work_area_->bufferView().buffer()) {
127 // Buffer-dependent dialogs should be updated or
128 // hidden. This should go here because some dialogs (eg ToC)
129 // require bv_->text.
130 getDialogs().updateBufferDependent(true);
131 connectBuffer(*work_area_->bufferView().buffer());
136 updateLayoutChoice();
142 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
144 if (work_area_->bufferView().buffer())
147 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
151 updateLayoutChoice();
154 connectBuffer(*work_area_->bufferView().buffer());
155 showErrorList("Parse");
162 void LyXView::connectBuffer(Buffer & buf)
164 if (errorsConnection_.connected())
169 boost::bind(&LyXView::showErrorList, this, _1));
173 boost::bind(&LyXView::message, this, _1));
177 boost::bind(&LyXView::busy, this, _1));
180 buf.updateTitles.connect(
181 boost::bind(&LyXView::updateWindowTitle, this));
184 buf.resetAutosaveTimers.connect(
185 boost::bind(&LyXView::resetAutosaveTimer, this));
187 readonlyConnection_ =
188 buf.readonly.connect(
189 boost::bind(&LyXView::showReadonly, this, _1));
193 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
197 void LyXView::disconnectBuffer()
199 messageConnection_.disconnect();
200 busyConnection_.disconnect();
201 titleConnection_.disconnect();
202 timerConnection_.disconnect();
203 readonlyConnection_.disconnect();
204 closingConnection_.disconnect();
205 layout_changed_connection_.disconnect();
209 void LyXView::connectBufferView(BufferView & bv)
211 show_dialog_connection_ = bv.showDialog.connect(
212 boost::bind(&LyXView::showDialog, this, _1));
213 show_dialog_with_data_connection_ = bv.showDialogWithData.connect(
214 boost::bind(&LyXView::showDialogWithData, this, _1, _2));
215 show_inset_dialog_connection_ = bv.showInsetDialog.connect(
216 boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3));
217 update_dialog_connection_ = bv.updateDialog.connect(
218 boost::bind(&LyXView::updateDialog, this, _1, _2));
219 layout_changed_connection_ = bv.layoutChanged.connect(
220 boost::bind(&Toolbars::setLayout, toolbars_.get(), _1));
224 void LyXView::disconnectBufferView()
226 show_dialog_connection_.disconnect();
227 show_dialog_with_data_connection_.disconnect();
228 show_inset_dialog_connection_.disconnect();
229 update_dialog_connection_.disconnect();
233 void LyXView::showErrorList(string const & error_type)
235 ErrorList & el = buffer()->errorList(error_type);
237 getDialogs().show("errorlist", error_type);
242 void LyXView::showDialog(string const & name)
244 getDialogs().show(name);
248 void LyXView::showDialogWithData(string const & name, string const & data)
250 getDialogs().show(name, data);
254 void LyXView::showInsetDialog(string const & name, string const & data,
257 getDialogs().show(name, data, inset);
261 void LyXView::updateDialog(string const & name, string const & data)
263 if (getDialogs().visible(name))
264 getDialogs().update(name, data);
268 void LyXView::showReadonly(bool)
271 getDialogs().updateBufferDependent(false);
275 BufferView * LyXView::view() const
277 return &work_area_->bufferView();
281 void LyXView::updateToolbars()
283 bool const math = work_area_->bufferView().cursor().inMathed();
285 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
286 toolbars_->update(math, table);
287 // update redaonly status of open dialogs. This could also be in
288 // updateMenubar(), but since updateToolbars() and updateMenubar()
289 // are always called together it is only here.
290 getDialogs().checkStatus();
294 void LyXView::updateMenubar()
300 void LyXView::autoSave()
302 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
304 if (view()->buffer())
305 lyx::autoSave(view());
309 void LyXView::resetAutosaveTimer()
312 autosave_timeout_->restart();
316 void LyXView::updateLayoutChoice()
318 // Don't show any layouts without a buffer
319 if (!view()->buffer()) {
320 toolbars_->clearLayoutList();
324 // Update the layout display
325 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
326 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
329 if (work_area_->bufferView().cursor().inMathed())
332 string const & layout =
333 work_area_->bufferView().cursor().paragraph().layout()->name();
335 if (layout != current_layout) {
336 toolbars_->setLayout(layout);
337 current_layout = layout;
342 void LyXView::updateWindowTitle()
344 static docstring last_title = lyx::from_ascii("LyX");
345 docstring maximize_title = lyx::from_ascii("LyX");
346 docstring minimize_title = lyx::from_ascii("LyX");
348 if (view()->buffer()) {
349 string const cur_title = buffer()->fileName();
350 if (!cur_title.empty()) {
351 maximize_title += ": " + makeDisplayPath(cur_title, 30);
352 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
353 if (!buffer()->isClean()) {
354 maximize_title += _(" (changed)");
355 minimize_title += lyx::char_type('*');
357 if (buffer()->isReadonly())
358 maximize_title += _(" (read only)");
362 if (maximize_title != last_title) {
363 setWindowTitle(maximize_title, minimize_title);
364 last_title = maximize_title;
369 void LyXView::dispatch(FuncRequest const & cmd)
371 theLyXFunc().setLyXView(this);
376 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
378 Buffer const * buffer_ptr = 0;
380 buffer_ptr = work_area_->bufferView().buffer();
382 work_area_->bufferView().update(Update::Force);