2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
19 #include "minibuffer.h"
25 #include "MenuBackend.h"
26 #include "bufferview_funcs.h" // CurrentState()
29 #include "BufferView.h"
30 #include "lyxtextclasslist.h"
32 #include "frontends/Dialogs.h"
33 #include "frontends/Toolbar.h"
34 #include "frontends/Timeout.h"
35 #include "frontends/Menubar.h"
37 #include "support/filetools.h" // OnlyFilename()
44 extern void AutoSave(BufferView *);
45 extern void QuitLyX();
47 string current_layout;
52 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
53 lyxfunc = new LyXFunc(this);
57 // Give the timeout some default sensible value.
58 autosave_timeout = new Timeout(5000);
60 dialogs_ = new Dialogs(this);
61 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
73 delete autosave_timeout;
78 void LyXView::resize()
84 /// returns the buffer currently shown in the main form.
85 Buffer * LyXView::buffer() const
87 return bufferview->buffer();
91 BufferView * LyXView::view() const
97 Toolbar * LyXView::getToolbar() const
103 void LyXView::setLayout(string const & layout)
105 toolbar->setLayout(layout);
109 void LyXView::updateToolbar()
115 LyXFunc * LyXView::getLyXFunc() const
121 MiniBuffer * LyXView::getMiniBuffer() const
127 void LyXView::message(string const & str)
129 minibuffer->message(str);
133 void LyXView::messagePush(string const & str)
135 minibuffer->messagePush(str);
139 void LyXView::messagePop()
141 minibuffer->messagePop();
145 Menubar * LyXView::getMenubar() const
151 void LyXView::updateMenubar()
153 if ((!view() || !view()->buffer())
154 && menubackend.hasMenu("main_nobuffer"))
155 menubar->set("main_nobuffer");
157 menubar->set("main");
162 Intl * LyXView::getIntl() const
168 // Callback for autosave timer
169 void LyXView::AutoSave()
171 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
172 if (view()->available())
177 /// Reset autosave timer
178 void LyXView::resetAutosaveTimer()
181 autosave_timeout->restart();
185 void LyXView::invalidateLayoutChoice()
191 void LyXView::updateLayoutChoice()
193 // This has a side-effect that the layouts are not showed when no
194 // document is loaded.
195 if (!view() || !view()->buffer()) {
196 toolbar->clearLayoutList();
200 // Update the layout display
201 if (last_textclass != int(buffer()->params.textclass)) {
202 toolbar->updateLayoutList(true);
203 last_textclass = int(buffer()->params.textclass);
204 current_layout = textclasslist[last_textclass].defaultLayoutName();
206 toolbar->updateLayoutList(false);
209 string const & layout =
210 bufferview->getLyXText()->cursor.par()->layout();
212 if (layout != current_layout) {
213 toolbar->setLayout(layout);
214 current_layout = layout;
219 // Updates the title of the window with the filename of the current document
220 void LyXView::updateWindowTitle()
222 static string last_title = "LyX";
223 string title = "LyX";
224 string icon_title = "LyX";
226 if (view()->available()) {
227 string const cur_title = buffer()->fileName();
228 if (!cur_title.empty()) {
229 title += ": " + MakeDisplayPath(cur_title, 30);
230 if (!buffer()->isLyxClean())
231 title += _(" (Changed)");
232 if (buffer()->isReadonly())
233 title += _(" (read only)");
234 /* Show only the filename if it's available. */
235 icon_title = OnlyFilename(cur_title);
238 if (title != last_title) {
239 setWindowTitle(title, icon_title);
245 void LyXView::showState()
247 message(currentState(view()));