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;
52 string current_layout;
57 autosave_timeout_(new Timeout(5000)),
58 lyxfunc_(new LyXFunc(this)),
59 dialogs_(new Dialogs(*this)),
60 controlcommand_(new ControlCommandBuffer(*this))
62 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
76 // Start autosave timer
78 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
79 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
80 autosave_timeout_->start();
83 intl_->InitKeyMapper(lyxrc.use_kbmap);
87 Buffer * LyXView::buffer() const
89 return bufferview_->buffer();
93 boost::shared_ptr<BufferView> const & LyXView::view() const
99 void LyXView::setLayout(string const & layout)
101 toolbar_->setLayout(layout);
105 void LyXView::updateToolbar()
107 bool const math = mathcursor;
109 !getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled();
110 toolbar_->update(math, table);
114 void LyXView::updateMenubar()
120 void LyXView::autoSave()
122 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
124 if (view()->available()) {
125 ::AutoSave(view().get());
130 void LyXView::resetAutosaveTimer()
133 autosave_timeout_->restart();
137 void LyXView::updateLayoutChoice()
139 // don't show any layouts without a buffer
140 if (!view()->buffer()) {
141 toolbar_->clearLayoutList();
145 // update the layout display
146 if (toolbar_->updateLayoutList(buffer()->params().textclass)) {
147 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
150 string const & layout =
151 bufferview_->getLyXText()->cursor.par()->layout()->name();
153 if (layout != current_layout) {
154 toolbar_->setLayout(layout);
155 current_layout = layout;
160 void LyXView::updateWindowTitle()
162 static string last_title = "LyX";
163 string maximize_title = "LyX";
164 string minimize_title = "LyX";
166 if (view()->available()) {
167 string const cur_title = buffer()->fileName();
168 if (!cur_title.empty()) {
169 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
170 minimize_title = OnlyFilename(cur_title);
171 if (!buffer()->isClean()) {
172 maximize_title += _(" (changed)");
173 minimize_title += '*';
175 if (buffer()->isReadonly())
176 maximize_title += _(" (read only)");
180 if (maximize_title != last_title) {
181 setWindowTitle(maximize_title, minimize_title);
182 last_title = maximize_title;
187 void LyXView::dispatch(FuncRequest const & req)
189 // substitute the correct BufferView here
191 r.setView(view().get());
192 getLyXFunc().dispatch(r);