3 * Copyright 1995-2002 the LyX Team
4 * Read the file COPYING
6 * \author Lars Gullik Bjornes
7 * \author John Levon <moz@compsoc.man.ac.uk>
13 #pragma implementation
17 #include "minibuffer.h"
23 #include "MenuBackend.h"
27 #include "BufferView.h"
28 #include "bufferview_funcs.h"
29 #include "lyxtextclasslist.h"
31 #include "frontends/Dialogs.h"
32 #include "frontends/Toolbar.h"
33 #include "frontends/Timeout.h"
34 #include "frontends/Menubar.h"
36 #include "support/filetools.h" // OnlyFilename()
38 #include <boost/bind.hpp>
45 string current_layout;
50 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
52 lyxfunc_.reset(new LyXFunc(this));
53 intl_.reset(new Intl);
55 // Give the timeout some default sensible value.
56 autosave_timeout_.reset(new Timeout(5000));
58 dialogs_.reset(new Dialogs(this));
69 // Set the textclass choice
70 invalidateLayoutChoice();
74 // Start autosave timer
76 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
77 autosave_timeout_->start();
80 intl_->InitKeyMapper(lyxrc.use_kbmap);
84 Buffer * LyXView::buffer() const
86 return bufferview_->buffer();
90 BufferView * LyXView::view() const
92 return bufferview_.get();
96 Toolbar * LyXView::getToolbar() const
98 return toolbar_.get();
102 void LyXView::setLayout(string const & layout)
104 toolbar_->setLayout(layout);
108 void LyXView::updateToolbar()
114 LyXFunc * LyXView::getLyXFunc() const
116 return lyxfunc_.get();
120 MiniBuffer * LyXView::getMiniBuffer() const
122 return minibuffer_.get();
126 void LyXView::message(string const & str)
128 minibuffer_->message(str);
132 void LyXView::messagePush(string const & str)
134 minibuffer_->messagePush(str);
138 void LyXView::messagePop()
140 minibuffer_->messagePop();
144 Menubar * LyXView::getMenubar() const
146 return menubar_.get();
150 void LyXView::updateMenubar()
152 if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
153 menubar_->set("main_nobuffer");
155 menubar_->set("main");
162 Intl * LyXView::getIntl() const
168 void LyXView::autoSave()
170 lyxerr[Debug::INFO] << "Running autoSave()" << endl;
172 if (view()->available()) {
178 void LyXView::resetAutosaveTimer()
181 autosave_timeout_->restart();
185 void LyXView::invalidateLayoutChoice()
187 last_textclass_ = -1;
191 void LyXView::updateLayoutChoice()
193 // don't show any layouts without a buffer
194 if (!view()->buffer()) {
195 toolbar_->clearLayoutList();
199 // update the layout display
200 if (last_textclass_ != int(buffer()->params.textclass)) {
201 toolbar_->updateLayoutList(true);
202 last_textclass_ = int(buffer()->params.textclass);
203 current_layout = textclasslist[last_textclass_].defaultLayoutName();
205 toolbar_->updateLayoutList(false);
208 string const & layout =
209 bufferview_->getLyXText()->cursor.par()->layout();
211 if (layout != current_layout) {
212 toolbar_->setLayout(layout);
213 current_layout = layout;
218 void LyXView::updateWindowTitle()
220 static string last_title = "LyX";
221 string title = "LyX";
222 string icon_title = "LyX";
224 if (view()->available()) {
225 string const cur_title = buffer()->fileName();
226 if (!cur_title.empty()) {
227 title += ": " + MakeDisplayPath(cur_title, 30);
228 if (!buffer()->isLyxClean())
229 title += _(" (changed)");
230 if (buffer()->isReadonly())
231 title += _(" (read only)");
232 // Show only the filename if it's available
233 icon_title = OnlyFilename(cur_title);
237 if (title != last_title) {
238 setWindowTitle(title, icon_title);
244 void LyXView::showState()
246 message(currentState(view()));