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>
45 using lyx::support::MakeDisplayPath;
46 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 = bufferview_->cursor().inMathed();
109 !getLyXFunc().getStatus(FuncRequest(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 if (bufferview_->cursor().inMathed())
153 string const & layout =
154 bufferview_->cursor().paragraph().layout()->name();
156 if (layout != current_layout) {
157 toolbar_->setLayout(layout);
158 current_layout = layout;
163 void LyXView::updateWindowTitle()
165 static string last_title = "LyX";
166 string maximize_title = "LyX";
167 string minimize_title = "LyX";
169 if (view()->available()) {
170 string const cur_title = buffer()->fileName();
171 if (!cur_title.empty()) {
172 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
173 minimize_title = OnlyFilename(cur_title);
174 if (!buffer()->isClean()) {
175 maximize_title += _(" (changed)");
176 minimize_title += '*';
178 if (buffer()->isReadonly())
179 maximize_title += _(" (read only)");
183 if (maximize_title != last_title) {
184 setWindowTitle(maximize_title, minimize_title);
185 last_title = maximize_title;
190 void LyXView::dispatch(FuncRequest const & cmd)
192 getLyXFunc().dispatch(cmd);
196 Buffer const * const LyXView::updateInset(InsetOld const * inset) const
198 Buffer const * buffer_ptr = 0;
200 buffer_ptr = bufferview_->buffer();
201 bufferview_->update();