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
20 #include "MenuBackend.h"
23 #include "funcrequest.h"
25 #include "BufferView.h"
26 #include "bufferview_funcs.h"
32 #include "controllers/ControlCommandBuffer.h"
33 #include "mathed/math_cursor.h"
35 #include "support/filetools.h" // OnlyFilename()
37 #include <boost/bind.hpp>
42 using namespace lyx::support;
45 string current_layout;
50 autosave_timeout_(new Timeout(5000)),
51 lyxfunc_(new LyXFunc(this)),
52 dialogs_(new Dialogs(*this)),
53 controlcommand_(new ControlCommandBuffer(*this))
55 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
69 // Start autosave timer
71 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
72 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
73 autosave_timeout_->start();
76 intl_->InitKeyMapper(lyxrc.use_kbmap);
80 Buffer * LyXView::buffer() const
82 return bufferview_->buffer();
86 boost::shared_ptr<BufferView> const & LyXView::view() const
92 void LyXView::setLayout(string const & layout)
94 toolbar_->setLayout(layout);
98 void LyXView::updateToolbar()
100 bool const math = mathcursor;
102 !getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled();
103 toolbar_->update(math, table);
107 void LyXView::updateMenubar()
113 void LyXView::autoSave()
115 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
117 if (view()->available()) {
118 ::AutoSave(view().get());
123 void LyXView::resetAutosaveTimer()
126 autosave_timeout_->restart();
130 void LyXView::updateLayoutChoice()
132 // don't show any layouts without a buffer
133 if (!view()->buffer()) {
134 toolbar_->clearLayoutList();
138 // update the layout display
139 if (toolbar_->updateLayoutList(buffer()->params.textclass)) {
140 current_layout = buffer()->params.getLyXTextClass().defaultLayoutName();
143 string const & layout =
144 bufferview_->getLyXText()->cursor.par()->layout()->name();
146 if (layout != current_layout) {
147 toolbar_->setLayout(layout);
148 current_layout = layout;
153 void LyXView::updateWindowTitle()
155 static string last_title = "LyX";
156 string maximize_title = "LyX";
157 string minimize_title = "LyX";
159 if (view()->available()) {
160 string const cur_title = buffer()->fileName();
161 if (!cur_title.empty()) {
162 maximize_title += ": " + MakeDisplayPath(cur_title, 30);
163 minimize_title = OnlyFilename(cur_title);
164 if (!buffer()->isClean()) {
165 maximize_title += _(" (changed)");
166 minimize_title += '*';
168 if (buffer()->isReadonly())
169 maximize_title += _(" (read only)");
173 if (maximize_title != last_title) {
174 setWindowTitle(maximize_title, minimize_title);
175 last_title = maximize_title;
180 void LyXView::dispatch(FuncRequest const & req)
182 // substitute the correct BufferView here
184 r.setView(view().get());
185 getLyXFunc().dispatch(r);