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 extern void AutoSave(BufferView *);
46 extern void QuitLyX();
48 string current_layout;
53 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
55 lyxfunc_.reset(new LyXFunc(this));
56 intl_.reset(new Intl);
58 // Give the timeout some default sensible value.
59 autosave_timeout_.reset(new Timeout(5000));
61 dialogs_.reset(new Dialogs(this));
62 Dialogs::redrawGUI.connect(boost::bind(&LyXView::redraw, this));
71 void LyXView::resize()
77 Buffer * LyXView::buffer() const
79 return bufferview_->buffer();
83 BufferView * LyXView::view() const
85 return bufferview_.get();
89 Toolbar * LyXView::getToolbar() const
91 return toolbar_.get();
95 void LyXView::setLayout(string const & layout)
97 toolbar_->setLayout(layout);
101 void LyXView::updateToolbar()
107 LyXFunc * LyXView::getLyXFunc() const
109 return lyxfunc_.get();
113 MiniBuffer * LyXView::getMiniBuffer() const
115 return minibuffer_.get();
119 void LyXView::message(string const & str)
121 minibuffer_->message(str);
125 void LyXView::messagePush(string const & str)
127 minibuffer_->messagePush(str);
131 void LyXView::messagePop()
133 minibuffer_->messagePop();
137 Menubar * LyXView::getMenubar() const
139 return menubar_.get();
143 void LyXView::updateMenubar()
145 if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
146 menubar_->set("main_nobuffer");
148 menubar_->set("main");
155 Intl * LyXView::getIntl() const
161 void LyXView::AutoSave()
163 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
164 if (view()->available())
169 void LyXView::resetAutosaveTimer()
172 autosave_timeout_->restart();
176 void LyXView::invalidateLayoutChoice()
178 last_textclass_ = -1;
182 void LyXView::updateLayoutChoice()
184 // don't show any layouts without a buffer
185 if (!view()->buffer()) {
186 toolbar_->clearLayoutList();
190 // update the layout display
191 if (last_textclass_ != int(buffer()->params.textclass)) {
192 toolbar_->updateLayoutList(true);
193 last_textclass_ = int(buffer()->params.textclass);
194 current_layout = textclasslist[last_textclass_].defaultLayoutName();
196 toolbar_->updateLayoutList(false);
199 string const & layout =
200 bufferview_->getLyXText()->cursor.par()->layout();
202 if (layout != current_layout) {
203 toolbar_->setLayout(layout);
204 current_layout = layout;
209 void LyXView::updateWindowTitle()
211 static string last_title = "LyX";
212 string title = "LyX";
213 string icon_title = "LyX";
215 if (view()->available()) {
216 string const cur_title = buffer()->fileName();
217 if (!cur_title.empty()) {
218 title += ": " + MakeDisplayPath(cur_title, 30);
219 if (!buffer()->isLyxClean())
220 title += _(" (changed)");
221 if (buffer()->isReadonly())
222 title += _(" (read only)");
223 // Show only the filename if it's available
224 icon_title = OnlyFilename(cur_title);
228 if (title != last_title) {
229 setWindowTitle(title, icon_title);
235 void LyXView::showState()
237 message(currentState(view()));