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