]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.C
Remove quite a few compiler warnings:
[lyx.git] / src / frontends / LyXView.C
1 /**
2  * \file LyXView.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "LyXView.h"
15 #include "Gui.h"
16 #include "Dialogs.h"
17 #include "Timeout.h"
18 #include "Toolbars.h"
19 #include "Menubar.h"
20 #include "WorkArea.h"
21
22 #include "buffer.h"
23 #include "bufferparams.h"
24 #include "BufferView.h"
25 #include "bufferview_funcs.h"
26 #include "cursor.h"
27 #include "debug.h"
28 #include "funcrequest.h"
29 #include "gettext.h"
30 #include "intl.h"
31 #include "lyx_cb.h"
32 #include "lyxfunc.h"
33 #include "lyxrc.h"
34 #include "lyxtext.h"
35 #include "MenuBackend.h"
36 #include "paragraph.h"
37
38 #include "controllers/ControlCommandBuffer.h"
39
40 #include "support/filetools.h" // OnlyFilename()
41
42 #include <boost/bind.hpp>
43
44 #ifdef HAVE_SYS_TIME_H
45 # include <sys/time.h>
46 #endif
47 #ifdef HAVE_UNISTD_H
48 # include <unistd.h>
49 #endif
50
51 using lyx::frontend::Gui;
52 using lyx::frontend::WorkArea;
53
54 using lyx::support::makeDisplayPath;
55 using lyx::support::onlyFilename;
56
57 using std::endl;
58 using std::string;
59
60 using lyx::frontend::ControlCommandBuffer;
61
62 string current_layout;
63
64 Gui & LyXView::gui()
65 {
66         return owner_;
67 }
68
69
70 LyXView::LyXView(Gui & owner)
71         : work_area_(0),
72           owner_(owner),
73           toolbars_(new Toolbars(*this)),
74           intl_(new Intl),
75           autosave_timeout_(new Timeout(5000)),
76           lyxfunc_(new LyXFunc(this)),
77           dialogs_(new Dialogs(*this)),
78           controlcommand_(new ControlCommandBuffer(*this))
79 {
80         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
81 }
82
83
84 void LyXView::setWorkArea(WorkArea * work_area)
85 {
86         work_area_ = work_area;
87 }
88
89
90 LyXView::~LyXView()
91 {
92 }
93
94
95 void LyXView::init()
96 {
97         updateLayoutChoice();
98         updateMenubar();
99
100         // Start autosave timer
101         if (lyxrc.autosave) {
102                 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
103                 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
104                 autosave_timeout_->start();
105         }
106
107         intl_->initKeyMapper(lyxrc.use_kbmap);
108 }
109
110
111 Buffer * LyXView::buffer() const
112 {
113         return work_area_->bufferView().buffer();
114 }
115
116
117 BufferView * LyXView::view() const
118 {
119         return &work_area_->bufferView();
120 }
121
122
123 void LyXView::setLayout(string const & layout)
124 {
125         toolbars_->setLayout(layout);
126 }
127
128
129 void LyXView::updateToolbars()
130 {
131         bool const math = work_area_->bufferView().cursor().inMathed();
132         bool const table =
133                 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
134         toolbars_->update(math, table);
135         // update redaonly status of open dialogs. This could also be in
136         // updateMenubar(), but since updateToolbars() and updateMenubar()
137         // are always called together it is only here.
138         getDialogs().checkStatus();
139 }
140
141
142 void LyXView::updateMenubar()
143 {
144         menubar_->update();
145 }
146
147
148 void LyXView::autoSave()
149 {
150         lyxerr[Debug::INFO] << "Running autoSave()" << endl;
151
152         if (view()->available()) {
153                 ::autoSave(view());
154         }
155 }
156
157
158 void LyXView::resetAutosaveTimer()
159 {
160         if (lyxrc.autosave)
161                 autosave_timeout_->restart();
162 }
163
164
165 void LyXView::updateLayoutChoice()
166 {
167         // Don't show any layouts without a buffer
168         if (!view()->buffer()) {
169                 toolbars_->clearLayoutList();
170                 return;
171         }
172
173         // Update the layout display
174         if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
175                 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
176         }
177
178         if (work_area_->bufferView().cursor().inMathed())
179                 return;
180
181         string const & layout =
182                 work_area_->bufferView().cursor().paragraph().layout()->name();
183
184         if (layout != current_layout) {
185                 toolbars_->setLayout(layout);
186                 current_layout = layout;
187         }
188 }
189
190
191 void LyXView::updateWindowTitle()
192 {
193         static string last_title = "LyX";
194         string maximize_title = "LyX";
195         string minimize_title = "LyX";
196
197         if (view()->available()) {
198                 string const cur_title = buffer()->fileName();
199                 if (!cur_title.empty()) {
200                         maximize_title += ": " + makeDisplayPath(cur_title, 30);
201                         minimize_title = onlyFilename(cur_title);
202                         if (!buffer()->isClean()) {
203                                 maximize_title += _(" (changed)");
204                                 minimize_title += '*';
205                         }
206                         if (buffer()->isReadonly())
207                                 maximize_title += _(" (read only)");
208                 }
209         }
210
211         if (maximize_title != last_title) {
212                 setWindowTitle(maximize_title, minimize_title);
213                 last_title = maximize_title;
214         }
215 }
216
217
218 void LyXView::dispatch(FuncRequest const & cmd)
219 {
220         getLyXFunc().dispatch(cmd);
221 }
222
223
224 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
225 {
226         Buffer const * buffer_ptr = 0;
227         if (inset) {
228                 buffer_ptr = work_area_->bufferView().buffer();
229                 // No FitCursor:
230                 work_area_->bufferView().update(Update::Force);
231         }
232         return buffer_ptr;
233 }