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"
25 #include "funcrequest.h"
32 #include "MenuBackend.h"
33 #include "paragraph.h"
35 #include "controllers/ControlCommandBuffer.h"
37 #include "mathed/math_cursor.h"
39 #include "support/filetools.h" // OnlyFilename()
41 #include <boost/bind.hpp>
46 using lyx::support::MakeDisplayPath;
47 using lyx::support::OnlyFilename;
53 string current_layout;
58 autosave_timeout_(new Timeout(5000)),
59 lyxfunc_(new LyXFunc(this)),
60 dialogs_(new Dialogs(*this)),
61 controlcommand_(new ControlCommandBuffer(*this))
63 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
77 // Start autosave timer
79 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
80 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
81 autosave_timeout_->start();
84 intl_->InitKeyMapper(lyxrc.use_kbmap);
88 Buffer * LyXView::buffer() const
90 return bufferview_->buffer();
94 boost::shared_ptr<BufferView> const & LyXView::view() const
100 void LyXView::setLayout(string const & layout)
102 toolbar_->setLayout(layout);
106 void LyXView::updateToolbar()
108 bool const math = mathcursor;
110 !getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).disabled();
111 toolbar_->update(math, table);
115 void LyXView::updateMenubar()
121 void LyXView::autoSave()
123 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
125 if (view()->available()) {
126 ::AutoSave(view().get());
131 void LyXView::resetAutosaveTimer()
134 autosave_timeout_->restart();
138 void LyXView::updateLayoutChoice()
140 // don't show any layouts without a buffer
141 if (!view()->buffer()) {
142 toolbar_->clearLayoutList();
146 // update the layout display
147 if (toolbar_->updateLayoutList(buffer()->params().textclass)) {
148 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
151 string const & layout =
152 bufferview_->getLyXText()->cursor.par()->layout()->name();
154 if (layout != current_layout) {
155 toolbar_->setLayout(layout);
156 current_layout = layout;
161 void LyXView::updateWindowTitle()
163 static string last_title = "LyX";
164 string maximize_title = "LyX";
165 string minimize_title = "LyX";
167 if (view()->available()) {
168 string const cur_title = buffer()->fileName();
169 if (!cur_title.empty()) {
170 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
171 minimize_title = OnlyFilename(cur_title);
172 if (!buffer()->isClean()) {
173 maximize_title += _(" (changed)");
174 minimize_title += '*';
176 if (buffer()->isReadonly())
177 maximize_title += _(" (read only)");
181 if (maximize_title != last_title) {
182 setWindowTitle(maximize_title, minimize_title);
183 last_title = maximize_title;
188 void LyXView::dispatch(FuncRequest const & req)
190 // substitute the correct BufferView here
192 r.setView(view().get());
193 getLyXFunc().dispatch(r);