]> git.lyx.org Git - lyx.git/blob - src/LyXView.C
Angus Custom Export patch and removal of unused files from repository.
[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 #if 0
62         dialogs_->hideBufferDependent
63                 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
64         Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
65         Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
66 #endif
67 }
68
69
70 LyXView::~LyXView()
71 {
72         delete menubar;
73         delete toolbar;
74         delete bufferview;
75         delete minibuffer;
76         delete lyxfunc;
77         delete intl;
78         delete autosave_timeout;
79         delete dialogs_;
80 }
81
82
83 void LyXView::resize() 
84 {
85         view()->resize();
86 }
87
88
89 /// returns the buffer currently shown in the main form.
90 Buffer * LyXView::buffer() const
91 {
92         return bufferview->buffer();
93 }
94
95
96 BufferView * LyXView::view() const
97 {
98         return bufferview;
99 }
100
101
102 Toolbar * LyXView::getToolbar() const
103 {
104         return toolbar;
105 }
106
107
108 void LyXView::setLayout(string const & layout)
109 {
110         toolbar->setLayout(layout);
111 }
112
113
114 void LyXView::updateToolbar()
115 {
116         toolbar->update();
117 }
118
119
120 LyXFunc * LyXView::getLyXFunc() const
121 {
122         return lyxfunc;
123 }
124
125
126 MiniBuffer * LyXView::getMiniBuffer() const
127 {
128         return minibuffer;
129 }
130
131
132 void LyXView::message(string const & str)
133 {
134         minibuffer->message(str);
135 }
136
137
138 void LyXView::messagePush(string const & str)
139 {
140         minibuffer->messagePush(str);
141 }
142
143
144 void LyXView::messagePop()
145 {
146         minibuffer->messagePop();
147 }
148
149
150 Menubar * LyXView::getMenubar() const
151 {
152         return menubar;
153 }
154
155
156 void LyXView::updateMenubar() 
157 {
158         if ((!view() || !view()->buffer())
159             && menubackend.hasMenu("main_nobuffer"))
160                 menubar->set("main_nobuffer");
161         else
162                 menubar->set("main");
163         menubar->update();
164 }
165
166
167 Intl * LyXView::getIntl() const
168 {
169         return intl;
170 }
171
172
173 // Callback for autosave timer
174 void LyXView::AutoSave()
175 {
176         lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
177         if (view()->available())
178                 ::AutoSave(view());
179 }
180
181
182 /// Reset autosave timer
183 void LyXView::resetAutosaveTimer()
184 {
185         if (lyxrc.autosave)
186                 autosave_timeout->restart();
187 }
188
189
190 void LyXView::invalidateLayoutChoice()
191 {
192         last_textclass = -1;
193 }
194
195
196 void LyXView::updateLayoutChoice()
197 {
198         // This has a side-effect that the layouts are not showed when no
199         // document is loaded.
200         if (!view() || !view()->buffer()) {
201                 toolbar->clearLayoutList();
202                 return; 
203         }
204
205         // Update the layout display
206         if (last_textclass != int(buffer()->params.textclass)) {
207                 toolbar->updateLayoutList(true);
208                 last_textclass = int(buffer()->params.textclass);
209                 current_layout = textclasslist[last_textclass].defaultLayoutName();
210         } else {
211                 toolbar->updateLayoutList(false);
212         }
213
214         string const & layout =
215                 bufferview->getLyXText()->cursor.par()->layout();
216
217         if (layout != current_layout) {
218                 toolbar->setLayout(layout);
219                 current_layout = layout;
220         }
221 }
222
223
224 // Updates the title of the window with the filename of the current document
225 void LyXView::updateWindowTitle()
226 {
227         static string last_title = "LyX";
228         string title = "LyX";
229         string icon_title = "LyX";
230
231         if (view()->available()) {
232                 string const cur_title = buffer()->fileName();
233                 if (!cur_title.empty()) {
234                         title += ": " + MakeDisplayPath(cur_title, 30);
235                         if (!buffer()->isLyxClean())
236                                 title += _(" (Changed)");
237                         if (buffer()->isReadonly())
238                                 title += _(" (read only)");
239                         /* Show only the filename if it's available. */
240                         icon_title = OnlyFilename(cur_title);
241                 }
242         }
243         if (title != last_title) {
244                 setWindowTitle(title, icon_title);
245                 last_title = title;
246         }
247 }
248
249
250 void LyXView::showState()
251 {
252         message(currentState(view()));
253 }