]> git.lyx.org Git - lyx.git/blob - src/frontends/LyXView.C
dociterator dont inherit from std::vector and updates
[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 "Dialogs.h"
16 #include "Timeout.h"
17 #include "Toolbars.h"
18 #include "Menubar.h"
19
20 #include "buffer.h"
21 #include "bufferparams.h"
22 #include "BufferView.h"
23 #include "bufferview_funcs.h"
24 #include "cursor.h"
25 #include "debug.h"
26 #include "funcrequest.h"
27 #include "gettext.h"
28 #include "intl.h"
29 #include "lyx_cb.h"
30 #include "lyxfunc.h"
31 #include "lyxrc.h"
32 #include "lyxtext.h"
33 #include "MenuBackend.h"
34 #include "paragraph.h"
35
36 #include "controllers/ControlCommandBuffer.h"
37
38 #include "support/filetools.h" // OnlyFilename()
39
40 #include <boost/bind.hpp>
41
42 #include <sys/time.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46
47 using lyx::support::MakeDisplayPath;
48 using lyx::support::OnlyFilename;
49
50 using std::endl;
51 using std::string;
52
53 using lyx::frontend::ControlCommandBuffer;
54
55 string current_layout;
56
57
58 LyXView::LyXView()
59         : toolbars_(new Toolbars(*this)),
60           intl_(new Intl),
61           autosave_timeout_(new Timeout(5000)),
62           lyxfunc_(new LyXFunc(this)),
63           dialogs_(new Dialogs(*this)),
64           controlcommand_(new ControlCommandBuffer(*this))
65 {
66         lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
67 }
68
69
70 LyXView::~LyXView()
71 {
72 }
73
74
75 void LyXView::init()
76 {
77         updateLayoutChoice();
78         updateMenubar();
79
80         // Start autosave timer
81         if (lyxrc.autosave) {
82                 autosave_timeout_->timeout.connect(boost::bind(&LyXView::autoSave, this));
83                 autosave_timeout_->setTimeout(lyxrc.autosave * 1000);
84                 autosave_timeout_->start();
85         }
86
87         intl_->InitKeyMapper(lyxrc.use_kbmap);
88 }
89
90
91 Buffer * LyXView::buffer() const
92 {
93         return bufferview_->buffer();
94 }
95
96
97 boost::shared_ptr<BufferView> const & LyXView::view() const
98 {
99         return bufferview_;
100 }
101
102
103 void LyXView::setLayout(string const & layout)
104 {
105         toolbars_->setLayout(layout);
106 }
107
108
109 void LyXView::updateToolbars()
110 {
111         bool const math = bufferview_->cursor().inMathed();
112         bool const table =
113                 getLyXFunc().getStatus(FuncRequest(LFUN_LAYOUT_TABULAR)).enabled();
114         toolbars_->update(math, table);
115 }
116
117
118 void LyXView::updateMenubar()
119 {
120         menubar_->update();
121 }
122
123
124 void LyXView::autoSave()
125 {
126         lyxerr[Debug::INFO] << "Running autoSave()" << endl;
127
128         if (view()->available()) {
129                 ::AutoSave(view().get());
130         }
131 }
132
133
134 void LyXView::resetAutosaveTimer()
135 {
136         if (lyxrc.autosave)
137                 autosave_timeout_->restart();
138 }
139
140
141 void LyXView::updateLayoutChoice()
142 {
143         // Don't show any layouts without a buffer
144         if (!view()->buffer()) {
145                 toolbars_->clearLayoutList();
146                 return;
147         }
148
149         // Update the layout display
150         if (toolbars_->updateLayoutList(buffer()->params().textclass)) {
151                 current_layout = buffer()->params().getLyXTextClass().defaultLayoutName();
152         }
153
154         if (bufferview_->cursor().inMathed())
155                 return;
156
157         string const & layout =
158                 bufferview_->cursor().paragraph().layout()->name();
159
160         if (layout != current_layout) {
161                 toolbars_->setLayout(layout);
162                 current_layout = layout;
163         }
164 }
165
166
167 void LyXView::updateWindowTitle()
168 {
169         static string last_title = "LyX";
170         string maximize_title = "LyX";
171         string minimize_title = "LyX";
172
173         if (view()->available()) {
174                 string const cur_title = buffer()->fileName();
175                 if (!cur_title.empty()) {
176                         maximize_title += ": " + MakeDisplayPath(cur_title, 30);
177                         minimize_title = OnlyFilename(cur_title);
178                         if (!buffer()->isClean()) {
179                                 maximize_title += _(" (changed)");
180                                 minimize_title += '*';
181                         }
182                         if (buffer()->isReadonly())
183                                 maximize_title += _(" (read only)");
184                 }
185         }
186
187         if (maximize_title != last_title) {
188                 setWindowTitle(maximize_title, minimize_title);
189                 last_title = maximize_title;
190         }
191 }
192
193
194 void LyXView::dispatch(FuncRequest const & cmd)
195 {
196         getLyXFunc().dispatch(cmd);
197 }
198
199
200 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
201 {
202         Buffer const * buffer_ptr = 0;
203         if (inset) {
204                 buffer_ptr = bufferview_->buffer();
205                 bufferview_->update();
206         }
207         return buffer_ptr;
208 }