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>
45 #ifdef HAVE_SYS_TIME_H
46 # include <sys/time.h>
52 using lyx::frontend::WorkArea;
55 using lyx::support::bformat;
56 using lyx::support::makeDisplayPath;
57 using lyx::support::onlyFilename;
62 using lyx::frontend::ControlCommandBuffer;
64 string current_layout;
69 toolbars_(new Toolbars(*this)),
70 autosave_timeout_(new Timeout(5000)),
71 dialogs_(new Dialogs(*this)),
72 controlcommand_(new ControlCommandBuffer(*this))
74 // Start autosave timer
76 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
77 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
78 autosave_timeout_->start();
88 void LyXView::setWorkArea(WorkArea * work_area)
90 work_area_ = work_area;
94 void LyXView::redrawWorkArea()
101 WorkArea * LyXView::workArea()
107 Buffer * LyXView::buffer() const
109 return work_area_->bufferView().buffer();
113 void LyXView::setBuffer(Buffer * b)
115 if (work_area_->bufferView().buffer())
119 getDialogs().hideBufferDependent();
121 work_area_->bufferView().setBuffer(b);
123 if (work_area_->bufferView().buffer()) {
124 // Buffer-dependent dialogs should be updated or
125 // hidden. This should go here because some dialogs (eg ToC)
126 // require bv_->text.
127 getDialogs().updateBufferDependent(true);
128 connectBuffer(*work_area_->bufferView().buffer());
133 updateLayoutChoice();
139 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
141 if (work_area_->bufferView().buffer())
144 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
148 updateLayoutChoice();
151 connectBuffer(*work_area_->bufferView().buffer());
152 showErrorList("Parse");
159 void LyXView::connectBuffer(Buffer & buf)
161 if (errorsConnection_.connected())
166 boost::bind(&LyXView::showErrorList, this, _1));
170 boost::bind(&LyXView::message, this, _1));
174 boost::bind(&LyXView::busy, this, _1));
177 buf.updateTitles.connect(
178 boost::bind(&LyXView::updateWindowTitle, this));
181 buf.resetAutosaveTimers.connect(
182 boost::bind(&LyXView::resetAutosaveTimer, this));
184 readonlyConnection_ =
185 buf.readonly.connect(
186 boost::bind(&LyXView::showReadonly, this, _1));
190 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
194 void LyXView::disconnectBuffer()
196 messageConnection_.disconnect();
197 busyConnection_.disconnect();
198 titleConnection_.disconnect();
199 timerConnection_.disconnect();
200 readonlyConnection_.disconnect();
201 closingConnection_.disconnect();
202 layout_changed_connection_.disconnect();
206 void LyXView::connectBufferView(BufferView & bv)
208 show_dialog_connection_ = bv.showDialog.connect(
209 boost::bind(&LyXView::showDialog, this, _1));
210 show_dialog_with_data_connection_ = bv.showDialogWithData.connect(
211 boost::bind(&LyXView::showDialogWithData, this, _1, _2));
212 show_inset_dialog_connection_ = bv.showInsetDialog.connect(
213 boost::bind(&LyXView::showInsetDialog, this, _1, _2, _3));
214 update_dialog_connection_ = bv.updateDialog.connect(
215 boost::bind(&LyXView::updateDialog, this, _1, _2));
216 layout_changed_connection_ = bv.layoutChanged.connect(
217 boost::bind(&Toolbars::setLayout, toolbars_.get(), _1));
221 void LyXView::disconnectBufferView()
223 show_dialog_connection_.disconnect();
224 show_dialog_with_data_connection_.disconnect();
225 show_inset_dialog_connection_.disconnect();
226 update_dialog_connection_.disconnect();
230 void LyXView::showErrorList(string const & error_type)
232 ErrorList & el = buffer()->errorList(error_type);
234 getDialogs().show("errorlist", error_type);
239 void LyXView::showDialog(string const & name)
241 getDialogs().show(name);
245 void LyXView::showDialogWithData(string const & name, string const & data)
247 getDialogs().show(name, data);
251 void LyXView::showInsetDialog(string const & name, string const & data,
254 getDialogs().show(name, data, inset);
258 void LyXView::updateDialog(string const & name, string const & data)
260 if (getDialogs().visible(name))
261 getDialogs().update(name, data);
265 void LyXView::showReadonly(bool)
268 getDialogs().updateBufferDependent(false);
272 BufferView * LyXView::view() const
274 return &work_area_->bufferView();
278 void LyXView::updateToolbars()
280 bool const math = work_area_->bufferView().cursor().inMathed();
282 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
283 toolbars_->update(math, table);
284 // update redaonly status of open dialogs. This could also be in
285 // updateMenubar(), but since updateToolbars() and updateMenubar()
286 // are always called together it is only here.
287 getDialogs().checkStatus();
291 void LyXView::updateMenubar()
297 void LyXView::autoSave()
299 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
301 if (view()->buffer()) {
307 void LyXView::resetAutosaveTimer()
310 autosave_timeout_->restart();
314 void LyXView::updateLayoutChoice()
316 // Don't show any layouts without a buffer
317 if (!view()->buffer()) {
318 toolbars_->clearLayoutList();
322 // Update the layout display
323 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
324 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
327 if (work_area_->bufferView().cursor().inMathed())
330 string const & layout =
331 work_area_->bufferView().cursor().paragraph().layout()->name();
333 if (layout != current_layout) {
334 toolbars_->setLayout(layout);
335 current_layout = layout;
340 void LyXView::updateWindowTitle()
342 static docstring last_title = lyx::from_ascii("LyX");
343 docstring maximize_title = lyx::from_ascii("LyX");
344 docstring minimize_title = lyx::from_ascii("LyX");
346 if (view()->buffer()) {
347 string const cur_title = buffer()->fileName();
348 if (!cur_title.empty()) {
349 maximize_title += ": " + makeDisplayPath(cur_title, 30);
350 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
351 if (!buffer()->isClean()) {
352 maximize_title += _(" (changed)");
353 minimize_title += lyx::char_type('*');
355 if (buffer()->isReadonly())
356 maximize_title += _(" (read only)");
360 if (maximize_title != last_title) {
361 setWindowTitle(maximize_title, minimize_title);
362 last_title = maximize_title;
367 void LyXView::dispatch(FuncRequest const & cmd)
369 theLyXFunc().setLyXView(this);
374 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
376 Buffer const * buffer_ptr = 0;
378 buffer_ptr = work_area_->bufferView().buffer();
380 work_area_->bufferView().update(Update::Force);