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>
47 using lyx::support::MakeDisplayPath;
48 using lyx::support::OnlyFilename;
53 using lyx::frontend::ControlCommandBuffer;
55 string current_layout;
59 : toolbars_(new Toolbars(*this)),
61 autosave_timeout_(new Timeout(5000)),
62 lyxfunc_(new LyXFunc(this)),
63 dialogs_(new Dialogs(*this)),
64 controlcommand_(new ControlCommandBuffer(*this))
66 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
80 // Start autosave timer
82 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
83 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
84 autosave_timeout_->start();
87 intl_->InitKeyMapper(lyxrc.use_kbmap);
91 Buffer * LyXView::buffer() const
93 return bufferview_->buffer();
97 boost::shared_ptr<BufferView> const & LyXView::view() const
103 void LyXView::setLayout(string const & layout)
105 toolbars_->setLayout(layout);
109 void LyXView::updateToolbars()
111 bool const math = bufferview_->cursor().inMathed();
113 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
114 toolbars_->update(math, table);
118 void LyXView::updateMenubar()
124 void LyXView::autoSave()
126 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
128 if (view()->available()) {
129 ::AutoSave(view().get());
134 void LyXView::resetAutosaveTimer()
137 autosave_timeout_->restart();
141 void LyXView::updateLayoutChoice()
143 // don't show any layouts without a buffer
144 if (!view()->buffer()) {
145 toolbars_->clearLayoutList();
149 // update the layout display
150 if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
151 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
154 if (bufferview_->cursor().inMathed())
157 string const & layout =
158 bufferview_->cursor().paragraph().layout()->name();
160 if (layout != current_layout) {
161 toolbars_->setLayout(layout);
162 current_layout = layout;
167 void LyXView::updateWindowTitle()
169 static string last_title = "LyX";
170 string maximize_title = "LyX";
171 string minimize_title = "LyX";
173 if (view()->available()) {
174 string const cur_title = buffer()->fileName();
175 if (!cur_title.empty()) {
176 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
177 minimize_title = OnlyFilename(cur_title);
178 if (!buffer()->isClean()) {
179 maximize_title += _(" (changed)");
180 minimize_title += '*';
182 if (buffer()->isReadonly())
183 maximize_title += _(" (read only)");
187 if (maximize_title != last_title) {
188 setWindowTitle(maximize_title, minimize_title);
189 last_title = maximize_title;
194 void LyXView::dispatch(FuncRequest const & cmd)
196 getLyXFunc().dispatch(cmd);
200 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
202 Buffer const * buffer_ptr = 0;
204 buffer_ptr = bufferview_->buffer();
205 bufferview_->update();