]> git.lyx.org Git - lyx.git/blob - src/LyXView.C
fix typo that put too many include paths for most people
[lyx.git] / src / LyXView.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2001 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "LyXView.h"
18 #include "minibuffer.h"
19 #include "debug.h"
20 #include "intl.h"
21 #include "lyxrc.h"
22 #include "lyxtext.h"
23 #include "buffer.h"
24 #include "MenuBackend.h"
25 #include "bufferview_funcs.h" // CurrentState()
26 #include "gettext.h"
27 #include "lyxfunc.h"
28 #include "BufferView.h"
29 #include "lyxtextclasslist.h"
30
31 #include "frontends/Dialogs.h"
32 #include "frontends/Toolbar.h"
33 #include "frontends/Timeout.h"
34 #include "frontends/Menubar.h"
35
36 #include "support/filetools.h"        // OnlyFilename()
37
38 #include <sys/time.h>
39 #include <unistd.h>
40
41 using std::endl;
42
43 extern void AutoSave(BufferView *);
44 extern void QuitLyX();
45
46 string current_layout;
47
48
49 LyXView::LyXView()
50 {
51         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
52         lyxfunc = new LyXFunc(this);
53
54         intl = new Intl;
55
56         // Give the timeout some default sensible value.
57         autosave_timeout = new Timeout(5000);
58
59         dialogs_ = new Dialogs(this);
60         Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
61 }
62
63
64 LyXView::~LyXView()
65 {
66         delete menubar;
67         delete toolbar;
68         delete bufferview;
69         delete minibuffer;
70         delete lyxfunc;
71         delete intl;
72         delete autosave_timeout;
73         delete dialogs_;
74 }
75
76
77 void LyXView::resize()
78 {
79         view()->resize();
80 }
81
82
83 /// returns the buffer currently shown in the main form.
84 Buffer * LyXView::buffer() const
85 {
86         return bufferview->buffer();
87 }
88
89
90 BufferView * LyXView::view() const
91 {
92         return bufferview;
93 }
94
95
96 Toolbar * LyXView::getToolbar() const
97 {
98         return toolbar;
99 }
100
101
102 void LyXView::setLayout(string const & layout)
103 {
104         toolbar->setLayout(layout);
105 }
106
107
108 void LyXView::updateToolbar()
109 {
110         toolbar->update();
111 }
112
113
114 LyXFunc * LyXView::getLyXFunc() const
115 {
116         return lyxfunc;
117 }
118
119
120 MiniBuffer * LyXView::getMiniBuffer() const
121 {
122         return minibuffer;
123 }
124
125
126 void LyXView::message(string const & str)
127 {
128         minibuffer->message(str);
129 }
130
131
132 void LyXView::messagePush(string const & str)
133 {
134         minibuffer->messagePush(str);
135 }
136
137
138 void LyXView::messagePop()
139 {
140         minibuffer->messagePop();
141 }
142
143
144 Menubar * LyXView::getMenubar() const
145 {
146         return menubar;
147 }
148
149
150 void LyXView::updateMenubar()
151 {
152         if ((!view() || !view()->buffer())
153             && menubackend.hasMenu("main_nobuffer"))
154                 menubar->set("main_nobuffer");
155         else
156                 menubar->set("main");
157         menubar->update();
158 }
159
160
161 Intl * LyXView::getIntl() const
162 {
163         return intl;
164 }
165
166
167 // Callback for autosave timer
168 void LyXView::AutoSave()
169 {
170         lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
171         if (view()->available())
172                 ::AutoSave(view());
173 }
174
175
176 /// Reset autosave timer
177 void LyXView::resetAutosaveTimer()
178 {
179         if (lyxrc.autosave)
180                 autosave_timeout->restart();
181 }
182
183
184 void LyXView::invalidateLayoutChoice()
185 {
186         last_textclass = -1;
187 }
188
189
190 void LyXView::updateLayoutChoice()
191 {
192         // This has a side-effect that the layouts are not showed when no
193         // document is loaded.
194         if (!view() || !view()->buffer()) {
195                 toolbar->clearLayoutList();
196                 return;
197         }
198
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();
204         } else {
205                 toolbar->updateLayoutList(false);
206         }
207
208         string const & layout =
209                 bufferview->getLyXText()->cursor.par()->layout();
210
211         if (layout != current_layout) {
212                 toolbar->setLayout(layout);
213                 current_layout = layout;
214         }
215 }
216
217
218 // Updates the title of the window with the filename of the current document
219 void LyXView::updateWindowTitle()
220 {
221         static string last_title = "LyX";
222         string title = "LyX";
223         string icon_title = "LyX";
224
225         if (view()->available()) {
226                 string const cur_title = buffer()->fileName();
227                 if (!cur_title.empty()) {
228                         title += ": " + MakeDisplayPath(cur_title, 30);
229                         if (!buffer()->isLyxClean())
230                                 title += _(" (Changed)");
231                         if (buffer()->isReadonly())
232                                 title += _(" (read only)");
233                         /* Show only the filename if it's available. */
234                         icon_title = OnlyFilename(cur_title);
235                 }
236         }
237         if (title != last_title) {
238                 setWindowTitle(title, icon_title);
239                 last_title = title;
240         }
241 }
242
243
244 void LyXView::showState()
245 {
246         message(currentState(view()));
247 }