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