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.
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "bufferview_funcs.h"
26 #include "funcrequest.h"
33 #include "MenuBackend.h"
34 #include "paragraph.h"
36 #include "controllers/ControlCommandBuffer.h"
38 #include "support/filetools.h" // OnlyFilename()
40 #include <boost/bind.hpp>
42 #ifdef HAVE_SYS_TIME_H
43 # include <sys/time.h>
49 using lyx::support::MakeDisplayPath;
50 using lyx::support::OnlyFilename;
55 using lyx::frontend::ControlCommandBuffer;
57 string current_layout;
61 : toolbars_(new Toolbars(*this)),
63 autosave_timeout_(new Timeout(5000)),
64 lyxfunc_(new LyXFunc(this)),
65 dialogs_(new Dialogs(*this)),
66 controlcommand_(new ControlCommandBuffer(*this))
68 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
82 // Start autosave timer
84 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
85 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
86 autosave_timeout_->start();
89 intl_->InitKeyMapper(lyxrc.use_kbmap);
93 Buffer * LyXView::buffer() const
95 return bufferview_->buffer();
99 boost::shared_ptr<BufferView> const & LyXView::view() const
105 void LyXView::setLayout(string const & layout)
107 toolbars_->setLayout(layout);
111 void LyXView::updateToolbars()
113 bool const math = bufferview_->cursor().inMathed();
115 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
116 toolbars_->update(math, table);
117 // update redaonly status of open dialogs. This could also be in
118 // updateMenubar(), but since updateToolbars() and updateMenubar()
119 // are always called together it is only here.
120 getDialogs().checkStatus();
124 void LyXView::updateMenubar()
130 void LyXView::autoSave()
132 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
134 if (view()->available()) {
135 ::AutoSave(view().get());
140 void LyXView::resetAutosaveTimer()
143 autosave_timeout_->restart();
147 void LyXView::updateLayoutChoice()
149 // Don't show any layouts without a buffer
150 if (!view()->buffer()) {
151 toolbars_->clearLayoutList();
155 // Update the layout display
156 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
157 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
160 if (bufferview_->cursor().inMathed())
163 string const & layout =
164 bufferview_->cursor().paragraph().layout()->name();
166 if (layout != current_layout) {
167 toolbars_->setLayout(layout);
168 current_layout = layout;
173 void LyXView::updateWindowTitle()
175 static string last_title = "LyX";
176 string maximize_title = "LyX";
177 string minimize_title = "LyX";
179 if (view()->available()) {
180 string const cur_title = buffer()->fileName();
181 if (!cur_title.empty()) {
182 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
183 minimize_title = OnlyFilename(cur_title);
184 if (!buffer()->isClean()) {
185 maximize_title += _(" (changed)");
186 minimize_title += '*';
188 if (buffer()->isReadonly())
189 maximize_title += _(" (read only)");
193 if (maximize_title != last_title) {
194 setWindowTitle(maximize_title, minimize_title);
195 last_title = maximize_title;
200 void LyXView::dispatch(FuncRequest const & cmd)
202 getLyXFunc().dispatch(cmd);
206 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
208 Buffer const * buffer_ptr = 0;
210 buffer_ptr = bufferview_->buffer();
212 bufferview_->update(Update::Force);