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());
148 setLayout(work_area_->bufferView().firstLayout());
153 updateLayoutChoice();
159 bool LyXView::loadLyXFile(string const & filename, bool tolastfiles)
161 if (work_area_->bufferView().buffer())
164 bool loaded = work_area_->bufferView().loadLyXFile(filename, tolastfiles);
168 updateLayoutChoice();
171 connectBuffer(*work_area_->bufferView().buffer());
172 setLayout(work_area_->bufferView().firstLayout());
173 showErrorList("Parse");
180 void LyXView::connectBuffer(Buffer & buf)
182 if (errorsConnection_.connected())
187 boost::bind(&LyXView::showErrorList, this, _1));
191 boost::bind(&LyXView::message, this, _1));
195 boost::bind(&LyXView::busy, this, _1));
198 buf.updateTitles.connect(
199 boost::bind(&LyXView::updateWindowTitle, this));
202 buf.resetAutosaveTimers.connect(
203 boost::bind(&LyXView::resetAutosaveTimer, this));
205 readonlyConnection_ =
206 buf.readonly.connect(
207 boost::bind(&LyXView::showReadonly, this, _1));
211 boost::bind(&LyXView::setBuffer, this, (Buffer *)0));
215 void LyXView::disconnectBuffer()
217 messageConnection_.disconnect();
218 busyConnection_.disconnect();
219 titleConnection_.disconnect();
220 timerConnection_.disconnect();
221 readonlyConnection_.disconnect();
222 closingConnection_.disconnect();
226 void LyXView::showErrorList(string const & error_type)
228 ErrorList & el = buffer()->errorList(error_type);
230 getDialogs().show("errorlist", error_type);
235 void LyXView::showReadonly(bool)
238 getDialogs().updateBufferDependent(false);
242 BufferView * LyXView::view() const
244 return &work_area_->bufferView();
248 void LyXView::setLayout(string const & layout)
250 toolbars_->setLayout(layout);
254 void LyXView::updateToolbars()
256 bool const math = work_area_->bufferView().cursor().inMathed();
258 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
259 toolbars_->update(math, table);
260 // update redaonly status of open dialogs. This could also be in
261 // updateMenubar(), but since updateToolbars() and updateMenubar()
262 // are always called together it is only here.
263 getDialogs().checkStatus();
267 void LyXView::updateMenubar()
273 void LyXView::autoSave()
275 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
277 if (view()->available()) {
283 void LyXView::resetAutosaveTimer()
286 autosave_timeout_->restart();
290 void LyXView::updateLayoutChoice()
292 // Don't show any layouts without a buffer
293 if (!view()->buffer()) {
294 toolbars_->clearLayoutList();
298 // Update the layout display
299 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
300 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
303 if (work_area_->bufferView().cursor().inMathed())
306 string const & layout =
307 work_area_->bufferView().cursor().paragraph().layout()->name();
309 if (layout != current_layout) {
310 toolbars_->setLayout(layout);
311 current_layout = layout;
316 void LyXView::updateWindowTitle()
318 static string last_title = "LyX";
319 string maximize_title = "LyX";
320 string minimize_title = "LyX";
322 if (view()->available()) {
323 string const cur_title = buffer()->fileName();
324 if (!cur_title.empty()) {
325 maximize_title += ": " + makeDisplayPath(cur_title, 30);
326 minimize_title = onlyFilename(cur_title);
327 if (!buffer()->isClean()) {
328 maximize_title += _(" (changed)");
329 minimize_title += '*';
331 if (buffer()->isReadonly())
332 maximize_title += _(" (read only)");
336 if (maximize_title != last_title) {
337 setWindowTitle(maximize_title, minimize_title);
338 last_title = maximize_title;
343 void LyXView::dispatch(FuncRequest const & cmd)
345 getLyXFunc().dispatch(cmd);
349 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
351 Buffer const * buffer_ptr = 0;
353 buffer_ptr = work_area_->bufferView().buffer();
355 work_area_->bufferView().update(Update::Force);