]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.C
29a4a141c797ee71b291a55b1d1c3ef6869bbb93
[lyx.git] / src / frontends / controllers / Dialog.C
1 // -*- C++ -*-
2 /**
3  * \file Dialog.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include "Dialog.h"
15
16 #include "ButtonController.h"
17 #include "BCView.h"
18 #include "support/LAssert.h"
19
20
21 Dialog::Dialog(LyXView & lv, string const & name)
22         : is_closing_(false), kernel_(lv), name_(name),
23           bc_ptr_(new ButtonController)
24 {}
25
26
27 Dialog::~Dialog()
28 {}
29
30
31 void Dialog::ApplyButton()
32 {
33         apply();
34         bc().apply();
35 }
36
37
38 void Dialog::OKButton()
39 {
40         is_closing_ = true;
41         apply();
42         is_closing_ = false;
43         hide();
44         bc().ok();
45 }
46
47
48 void Dialog::CancelButton()
49 {
50         hide();
51         bc().cancel();
52 }
53
54
55 void Dialog::RestoreButton()
56 {
57         // Tell the kernel that a request to refresh the dialog's contents
58         // has been received. It's up to the kernel to supply the necessary
59         // info by calling Dialog::update().
60         kernel().updateDialog(name_);
61         bc().restore();
62 }
63
64
65 void Dialog::show(string const & data)
66 {
67         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
68                 return;
69
70         controller().initialiseParams(data);
71         bc().readOnly(kernel().isBufferReadonly());
72         view().show();
73
74         // The widgets may not be valid, so refresh the button controller
75         bc().refresh();
76 }
77
78
79 void Dialog::update(string const & data)
80 {
81         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
82                 return;
83
84         controller().initialiseParams(data);
85
86         bc().readOnly(kernel().isBufferReadonly());
87         view().update();
88
89         // The widgets may not be valid, so refresh the button controller
90         bc().refresh();
91 }
92
93
94 void Dialog::hide()
95 {
96         if (!view().isVisible())
97                 return;
98
99         controller().clearParams();
100         view().hide();
101 }
102
103
104 void Dialog::apply()
105 {
106         if (kernel().isBufferReadonly())
107                 return;
108
109         view().apply();
110         controller().dispatchParams();
111
112         if (controller().disconnectOnApply() && !is_closing_) {
113                 kernel().disconnect(name());
114                 controller().initialiseParams(string());
115                 view().update();
116         }
117 }
118
119
120 bool Dialog::isVisible() const
121 {
122         return view().isVisible();
123 }
124
125
126 void Dialog::redraw()
127 {
128         view().redraw();
129 }
130
131
132 ButtonController & Dialog::bc() const
133 {
134         lyx::Assert(bc_ptr_.get());
135         return *bc_ptr_.get();
136 }
137
138
139 Dialog::Controller & Dialog::controller() const
140 {
141         lyx::Assert(controller_ptr_.get());
142         return *controller_ptr_.get();
143 }
144
145
146 Dialog::View & Dialog::view() const
147 {
148         lyx::Assert(view_ptr_.get());
149         return *view_ptr_.get();
150 }
151
152
153 void Dialog::setController(Controller * i)
154 {
155         lyx::Assert(i && !controller_ptr_.get());
156         controller_ptr_.reset(i);
157 }
158
159
160 void Dialog::setView(View * v)
161 {
162         lyx::Assert(v && !view_ptr_.get());
163         view_ptr_.reset(v);
164 }