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;
56 using lyx::support::bformat;
57 using lyx::support::makeDisplayPath;
58 using lyx::support::onlyFilename;
63 using lyx::frontend::ControlCommandBuffer;
65 string current_layout;
73 LyXView::LyXView(Gui & owner)
76 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;
91 void LyXView::setWorkArea(WorkArea * work_area)
93 work_area_ = work_area;
97 void LyXView::redrawWorkArea()
104 WorkArea * LyXView::workArea()
112 updateLayoutChoice();
115 // Start autosave timer
116 if (lyxrc.autosave) {
117 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
118 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
119 autosave_timeout_->start();
122 intl_->initKeyMapper(lyxrc.use_kbmap);
126 Buffer * LyXView::buffer() const
128 return work_area_->bufferView().buffer();
132 void LyXView::setBuffer(Buffer * b)
134 if (work_area_->bufferView().buffer())
138 getDialogs().hideBufferDependent();
140 work_area_->bufferView().setBuffer(b);
142 if (work_area_->bufferView().buffer()) {
143 // Buffer-dependent dialogs should be updated or
144 // hidden. This should go here because some dialogs (eg ToC)
145 // require bv_->text.
146 getDialogs().updateBufferDependent(true);
147 connectBuffer(*work_area_->bufferView().buffer());
152 updateLayoutChoice();
158 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
160 if (work_area_->bufferView().buffer())
163 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
167 updateLayoutChoice();
170 connectBuffer(*work_area_->bufferView().buffer());
171 showErrorList("Parse");
178 void LyXView::connectBuffer(Buffer & buf)
180 if (errorsConnection_.connected())
185 boost::bind(&LyXView::showErrorList, this, _1));
189 boost::bind(&LyXView::message, this, _1));
193 boost::bind(&LyXView::busy, this, _1));
196 buf.updateTitles.connect(
197 boost::bind(&LyXView::updateWindowTitle, this));
200 buf.resetAutosaveTimers.connect(
201 boost::bind(&LyXView::resetAutosaveTimer, this));
203 readonlyConnection_ =
204 buf.readonly.connect(
205 boost::bind(&LyXView::showReadonly, this, _1));
209 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
213 void LyXView::disconnectBuffer()
215 messageConnection_.disconnect();
216 busyConnection_.disconnect();
217 titleConnection_.disconnect();
218 timerConnection_.disconnect();
219 readonlyConnection_.disconnect();
220 closingConnection_.disconnect();
224 void LyXView::showErrorList(string const & error_type)
226 ErrorList & el = buffer()->errorList(error_type);
228 getDialogs().show("errorlist", error_type);
233 void LyXView::showReadonly(bool)
236 getDialogs().updateBufferDependent(false);
240 BufferView * LyXView::view() const
242 return &work_area_->bufferView();
246 void LyXView::setLayout(string const & layout)
248 toolbars_->setLayout(layout);
252 void LyXView::updateToolbars()
254 bool const math = work_area_->bufferView().cursor().inMathed();
256 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
257 toolbars_->update(math, table);
258 // update redaonly status of open dialogs. This could also be in
259 // updateMenubar(), but since updateToolbars() and updateMenubar()
260 // are always called together it is only here.
261 getDialogs().checkStatus();
265 void LyXView::updateMenubar()
271 void LyXView::autoSave()
273 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
275 if (view()->available()) {
281 void LyXView::resetAutosaveTimer()
284 autosave_timeout_->restart();
288 void LyXView::updateLayoutChoice()
290 // Don't show any layouts without a buffer
291 if (!view()->buffer()) {
292 toolbars_->clearLayoutList();
296 // Update the layout display
297 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
298 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
301 if (work_area_->bufferView().cursor().inMathed())
304 string const & layout =
305 work_area_->bufferView().cursor().paragraph().layout()->name();
307 if (layout != current_layout) {
308 toolbars_->setLayout(layout);
309 current_layout = layout;
314 void LyXView::updateWindowTitle()
316 static string last_title = "LyX";
317 string maximize_title = "LyX";
318 string minimize_title = "LyX";
320 if (view()->available()) {
321 string const cur_title = buffer()->fileName();
322 if (!cur_title.empty()) {
323 maximize_title += ": " + makeDisplayPath(cur_title, 30);
324 minimize_title = onlyFilename(cur_title);
325 if (!buffer()->isClean()) {
326 maximize_title += _(" (changed)");
327 minimize_title += '*';
329 if (buffer()->isReadonly())
330 maximize_title += _(" (read only)");
334 if (maximize_title != last_title) {
335 setWindowTitle(maximize_title, minimize_title);
336 last_title = maximize_title;
341 void LyXView::dispatch(FuncRequest const & cmd)
343 getLyXFunc().dispatch(cmd);
347 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
349 Buffer const * buffer_ptr = 0;
351 buffer_ptr = work_area_->bufferView().buffer();
353 work_area_->bufferView().update(Update::Force);