]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.C
Create a grfx::Loader class and so move large chunks of code out of
[lyx.git] / src / frontends / LyXView.C
1 /**
2  * \file LyXView.C
3  * Copyright 1995-2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Lars Gullik Bjornes
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "LyXView.h"
17 #include "MiniBuffer.h"
18 #include "debug.h"
19 #include "intl.h"
20 #include "lyxrc.h"
21 #include "lyxtext.h"
22 #include "buffer.h"
23 #include "MenuBackend.h"
24 #include "gettext.h"
25 #include "lyxfunc.h"
26 #include "lyx_cb.h"
27 #include "BufferView.h"
28 #include "bufferview_funcs.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 <boost/bind.hpp>
39
40 #include <sys/time.h>
41 #include <unistd.h>
42
43 using std::endl;
44
45 string current_layout;
46
47
48 LyXView::LyXView()
49 {
50         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
51
52         lyxfunc_.reset(new LyXFunc(this));
53         intl_.reset(new Intl);
54
55         // Give the timeout some default sensible value.
56         autosave_timeout_.reset(new Timeout(5000));
57
58         dialogs_.reset(new Dialogs(this));
59 }
60
61
62 LyXView::~LyXView()
63 {
64 }
65
66
67 void LyXView::init()
68 {
69         updateLayoutChoice();
70         updateMenubar();
71
72         // Start autosave timer
73         if (lyxrc.autosave) {
74                 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
75                 autosave_timeout_->start();
76         }
77
78         intl_->InitKeyMapper(lyxrc.use_kbmap);
79 }
80
81
82 Buffer * LyXView::buffer() const
83 {
84         return bufferview_->buffer();
85 }
86
87
88 BufferView * LyXView::view() const
89 {
90         return bufferview_.get();
91 }
92
93
94 Toolbar * LyXView::getToolbar() const
95 {
96         return toolbar_.get();
97 }
98
99
100 void LyXView::setLayout(string const & layout)
101 {
102         toolbar_->setLayout(layout);
103 }
104
105
106 void LyXView::updateToolbar()
107 {
108         toolbar_->update();
109 }
110
111
112 LyXFunc * LyXView::getLyXFunc() const
113 {
114         return lyxfunc_.get();
115 }
116
117
118 MiniBuffer * LyXView::getMiniBuffer() const
119 {
120         return minibuffer_.get();
121 }
122
123
124 void LyXView::message(string const & str)
125 {
126         minibuffer_->message(str);
127 }
128
129
130 void LyXView::messagePush(string const & str)
131 {
132         minibuffer_->messagePush(str);
133 }
134
135
136 void LyXView::messagePop()
137 {
138         minibuffer_->messagePop();
139 }
140
141
142 Menubar * LyXView::getMenubar() const
143 {
144         return menubar_.get();
145 }
146
147
148 void LyXView::updateMenubar()
149 {
150         if (!view()->buffer() && menubackend.hasMenu("main_nobuffer")) {
151                 menubar_->set("main_nobuffer");
152         } else {
153                 menubar_->set("main");
154         }
155
156         menubar_->update();
157 }
158
159
160 Intl * LyXView::getIntl() const
161 {
162         return intl_.get();
163 }
164
165
166 void LyXView::autoSave()
167 {
168         lyxerr[Debug::INFO] << "Running autoSave()" << endl;
169
170         if (view()->available()) {
171                 ::AutoSave(view());
172         }
173 }
174
175
176 void LyXView::resetAutosaveTimer()
177 {
178         if (lyxrc.autosave)
179                 autosave_timeout_->restart();
180 }
181
182
183 void LyXView::updateLayoutChoice()
184 {
185         // don't show any layouts without a buffer
186         if (!view()->buffer()) {
187                 toolbar_->clearLayoutList();
188                 return;
189         }
190
191         // update the layout display
192         if (toolbar_->updateLayoutList(buffer()->params.textclass)) {
193                 current_layout = textclasslist[buffer()->params.textclass].defaultLayoutName();
194         }
195
196         string const & layout =
197                 bufferview_->getLyXText()->cursor.par()->layout()->name();
198
199         if (layout != current_layout) {
200                 toolbar_->setLayout(layout);
201                 current_layout = layout;
202         }
203 }
204
205
206 void LyXView::updateWindowTitle()
207 {
208         static string last_title = "LyX";
209         string title = "LyX";
210         string icon_title = "LyX";
211
212         if (view()->available()) {
213                 string const cur_title = buffer()->fileName();
214                 if (!cur_title.empty()) {
215                         title += ": " + MakeDisplayPath(cur_title, 30);
216                         if (!buffer()->isLyxClean())
217                                 title += _(" (changed)");
218                         if (buffer()->isReadonly())
219                                 title += _(" (read only)");
220                         // Show only the filename if it's available
221                         icon_title = OnlyFilename(cur_title);
222                 }
223         }
224
225         if (title != last_title) {
226                 setWindowTitle(title, icon_title);
227                 last_title = title;
228         }
229 }
230
231
232 void LyXView::showState()
233 {
234         message(currentState(view()));
235 }