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,
248 getDialogs().show(name, data);
252 void LyXView::showInsetDialog(string const & name, string const & data,
255 getDialogs().show(name, data, inset);
259 void LyXView::updateDialog(string const & name, string const & data)
261 if (getDialogs().visible(name))
262 getDialogs().update(name, data);
266 void LyXView::showReadonly(bool)
269 getDialogs().updateBufferDependent(false);
273 BufferView * LyXView::view() const
275 return &work_area_->bufferView();
279 void LyXView::updateToolbars()
281 bool const math = work_area_->bufferView().cursor().inMathed();
283 lyx::getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
284 toolbars_->update(math, table);
285 // update redaonly status of open dialogs. This could also be in
286 // updateMenubar(), but since updateToolbars() and updateMenubar()
287 // are always called together it is only here.
288 getDialogs().checkStatus();
292 void LyXView::updateMenubar()
298 void LyXView::autoSave()
300 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
302 if (view()->buffer()) {
308 void LyXView::resetAutosaveTimer()
311 autosave_timeout_->restart();
315 void LyXView::updateLayoutChoice()
317 // Don't show any layouts without a buffer
318 if (!view()->buffer()) {
319 toolbars_->clearLayoutList();
323 // Update the layout display
324 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
325 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
328 if (work_area_->bufferView().cursor().inMathed())
331 string const & layout =
332 work_area_->bufferView().cursor().paragraph().layout()->name();
334 if (layout != current_layout) {
335 toolbars_->setLayout(layout);
336 current_layout = layout;
341 void LyXView::updateWindowTitle()
343 static docstring last_title = lyx::from_ascii("LyX");
344 docstring maximize_title = lyx::from_ascii("LyX");
345 docstring minimize_title = lyx::from_ascii("LyX");
347 if (view()->buffer()) {
348 string const cur_title = buffer()->fileName();
349 if (!cur_title.empty()) {
350 maximize_title += ": " + makeDisplayPath(cur_title, 30);
351 minimize_title = lyx::from_utf8(onlyFilename(cur_title));
352 if (!buffer()->isClean()) {
353 maximize_title += _(" (changed)");
354 minimize_title += lyx::char_type('*');
356 if (buffer()->isReadonly())
357 maximize_title += _(" (read only)");
361 if (maximize_title != last_title) {
362 setWindowTitle(maximize_title, minimize_title);
363 last_title = maximize_title;
368 void LyXView::dispatch(FuncRequest const & cmd)
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);