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