Mercurial > projects > dwt-addons
annotate dwtx/jface/text/contentassist/PopupCloser.d @ 200:eb3414669eb0 default tip
fix for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:09:57 +0100 |
parents | c3583c6ec027 |
children |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.contentassist.PopupCloser; | |
14 | |
131 | 15 import dwtx.jface.text.contentassist.ContentAssistEvent; // packageimport |
16 import dwtx.jface.text.contentassist.Helper; // packageimport | |
17 import dwtx.jface.text.contentassist.IContentAssistant; // packageimport | |
18 import dwtx.jface.text.contentassist.CompletionProposal; // packageimport | |
19 import dwtx.jface.text.contentassist.ICompletionProposalExtension5; // packageimport | |
20 import dwtx.jface.text.contentassist.IContextInformationValidator; // packageimport | |
21 import dwtx.jface.text.contentassist.IContentAssistListener; // packageimport | |
22 import dwtx.jface.text.contentassist.ICompletionProposalExtension6; // packageimport | |
23 import dwtx.jface.text.contentassist.ICompletionListener; // packageimport | |
24 import dwtx.jface.text.contentassist.ICompletionProposalExtension2; // packageimport | |
25 import dwtx.jface.text.contentassist.IContentAssistantExtension4; // packageimport | |
26 import dwtx.jface.text.contentassist.ContextInformation; // packageimport | |
27 import dwtx.jface.text.contentassist.ICompletionProposalExtension3; // packageimport | |
28 import dwtx.jface.text.contentassist.ContextInformationValidator; // packageimport | |
29 import dwtx.jface.text.contentassist.ICompletionProposal; // packageimport | |
30 import dwtx.jface.text.contentassist.IContentAssistProcessor; // packageimport | |
31 import dwtx.jface.text.contentassist.AdditionalInfoController; // packageimport | |
32 import dwtx.jface.text.contentassist.IContextInformationPresenter; // packageimport | |
33 import dwtx.jface.text.contentassist.ICompletionProposalExtension4; // packageimport | |
34 import dwtx.jface.text.contentassist.ICompletionListenerExtension; // packageimport | |
35 import dwtx.jface.text.contentassist.ContextInformationPopup; // packageimport | |
36 import dwtx.jface.text.contentassist.IContextInformationExtension; // packageimport | |
37 import dwtx.jface.text.contentassist.IContentAssistantExtension2; // packageimport | |
38 import dwtx.jface.text.contentassist.ContentAssistSubjectControlAdapter; // packageimport | |
39 import dwtx.jface.text.contentassist.CompletionProposalPopup; // packageimport | |
40 import dwtx.jface.text.contentassist.ICompletionProposalExtension; // packageimport | |
41 import dwtx.jface.text.contentassist.IContextInformation; // packageimport | |
42 import dwtx.jface.text.contentassist.IContentAssistantExtension3; // packageimport | |
43 import dwtx.jface.text.contentassist.ContentAssistant; // packageimport | |
44 import dwtx.jface.text.contentassist.IContentAssistantExtension; // packageimport | |
45 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport | |
46 | |
47 | |
129 | 48 import dwt.dwthelper.utils; |
49 | |
50 | |
51 | |
52 import dwt.DWT; | |
53 import dwt.events.FocusEvent; | |
54 import dwt.events.FocusListener; | |
55 import dwt.events.SelectionEvent; | |
56 import dwt.events.SelectionListener; | |
57 import dwt.events.ShellAdapter; | |
58 import dwt.events.ShellEvent; | |
59 import dwt.widgets.Control; | |
60 import dwt.widgets.Display; | |
61 import dwt.widgets.Event; | |
62 import dwt.widgets.Listener; | |
63 import dwt.widgets.ScrollBar; | |
64 import dwt.widgets.Shell; | |
65 import dwt.widgets.Table; | |
66 import dwtx.jface.internal.text.DelayedInputChangeListener; | |
67 import dwtx.jface.internal.text.InformationControlReplacer; | |
68 import dwtx.jface.text.IDelayedInputChangeProvider; | |
69 import dwtx.jface.text.IInformationControl; | |
70 import dwtx.jface.text.IInformationControlExtension5; | |
71 import dwtx.jface.text.IInputChangedListener; | |
72 | |
73 | |
74 /** | |
75 * A generic closer class used to monitor various | |
76 * interface events in order to determine whether | |
77 * a content assistant should be terminated and all | |
78 * associated windows be closed. | |
79 */ | |
80 class PopupCloser : ShellAdapter , FocusListener, SelectionListener, Listener { | |
81 | |
82 /** The content assistant to be monitored. */ | |
83 private ContentAssistant fContentAssistant; | |
84 /** The table of a selector popup opened by the content assistant. */ | |
85 private Table fTable; | |
86 /** The scroll bar of the table for the selector popup. */ | |
87 private ScrollBar fScrollbar; | |
88 /** Indicates whether the scroll bar thumb has been grabbed. */ | |
89 private bool fScrollbarClicked= false; | |
90 /** | |
91 * The shell on which some listeners are registered. | |
92 * @since 3.1 | |
93 */ | |
94 private Shell fShell; | |
95 /** | |
96 * The display on which some filters are registered. | |
97 * @since 3.4 | |
98 */ | |
99 private Display fDisplay; | |
100 /** | |
101 * The additional info controller, or <code>null</code>. | |
102 * @since 3.4 | |
103 */ | |
104 private AdditionalInfoController fAdditionalInfoController; | |
105 | |
106 /** | |
107 * Installs this closer on the given table opened by the given content assistant. | |
108 * | |
109 * @param contentAssistant the content assistant | |
110 * @param table the table to be tracked | |
111 */ | |
112 public void install(ContentAssistant contentAssistant, Table table) { | |
113 install(contentAssistant, table, null); | |
114 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
115 |
129 | 116 /** |
117 * Installs this closer on the given table opened by the given content assistant. | |
118 * | |
119 * @param contentAssistant the content assistant | |
120 * @param table the table to be tracked | |
121 * @param additionalInfoController the additional info controller, or <code>null</code> | |
122 * @since 3.4 | |
123 */ | |
124 public void install(ContentAssistant contentAssistant, Table table, AdditionalInfoController additionalInfoController) { | |
125 fContentAssistant= contentAssistant; | |
126 fTable= table; | |
127 fAdditionalInfoController= additionalInfoController; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
128 |
129 | 129 if (Helper.okToUse(fTable)) { |
130 fShell= fTable.getShell(); | |
131 fDisplay= fShell.getDisplay(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
132 |
129 | 133 fShell.addShellListener(this); |
134 fTable.addFocusListener(this); | |
135 fScrollbar= fTable.getVerticalBar(); | |
136 if (fScrollbar !is null) | |
137 fScrollbar.addSelectionListener(this); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
138 |
129 | 139 fDisplay.addFilter(DWT.Activate, this); |
140 fDisplay.addFilter(DWT.MouseWheel, this); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
141 |
129 | 142 fDisplay.addFilter(DWT.Deactivate, this); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
143 |
129 | 144 fDisplay.addFilter(DWT.MouseUp, this); |
145 } | |
146 } | |
147 | |
148 /** | |
149 * Uninstalls this closer if previously installed. | |
150 */ | |
151 public void uninstall() { | |
152 fContentAssistant= null; | |
153 if (Helper.okToUse(fShell)) | |
154 fShell.removeShellListener(this); | |
155 fShell= null; | |
156 if (Helper.okToUse(fScrollbar)) | |
157 fScrollbar.removeSelectionListener(this); | |
158 if (Helper.okToUse(fTable)) | |
159 fTable.removeFocusListener(this); | |
160 if (fDisplay !is null && ! fDisplay.isDisposed()) { | |
161 fDisplay.removeFilter(DWT.Activate, this); | |
162 fDisplay.removeFilter(DWT.MouseWheel, this); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
163 |
129 | 164 fDisplay.removeFilter(DWT.Deactivate, this); |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
165 |
129 | 166 fDisplay.removeFilter(DWT.MouseUp, this); |
167 } | |
168 } | |
169 | |
170 /* | |
171 * @see dwt.events.SelectionListener#widgetSelected(dwt.events.SelectionEvent) | |
172 */ | |
173 public void widgetSelected(SelectionEvent e) { | |
174 fScrollbarClicked= true; | |
175 } | |
176 | |
177 /* | |
178 * @see dwt.events.SelectionListener#widgetDefaultSelected(dwt.events.SelectionEvent) | |
179 */ | |
180 public void widgetDefaultSelected(SelectionEvent e) { | |
181 fScrollbarClicked= true; | |
182 } | |
183 | |
184 /* | |
185 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent) | |
186 */ | |
187 public void focusGained(FocusEvent e) { | |
188 } | |
189 | |
190 /* | |
191 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent) | |
192 */ | |
158 | 193 public void focusLost(FocusEvent e) { |
129 | 194 fScrollbarClicked= false; |
195 Display d= fTable.getDisplay(); | |
158 | 196 d.asyncExec(dgRunnable((FocusEvent e_) { |
197 if (Helper.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant !is null) | |
198 fContentAssistant.popupFocusLost(e_); | |
199 }, e )); | |
129 | 200 } |
201 | |
202 /* | |
203 * @see dwt.events.ShellAdapter#shellDeactivated(dwt.events.ShellEvent) | |
204 * @since 3.1 | |
205 */ | |
206 public void shellDeactivated(ShellEvent e) { | |
207 if (fContentAssistant !is null && ! fContentAssistant.hasProposalPopupFocus()) | |
162 | 208 fContentAssistant.hide_package(); |
129 | 209 } |
210 | |
211 | |
212 /* | |
213 * @see dwt.events.ShellAdapter#shellClosed(dwt.events.ShellEvent) | |
214 * @since 3.1 | |
215 */ | |
216 public void shellClosed(ShellEvent e) { | |
217 if (fContentAssistant !is null) | |
162 | 218 fContentAssistant.hide_package(); |
129 | 219 } |
220 | |
221 /* | |
222 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event) | |
223 * @since 3.4 | |
224 */ | |
225 public void handleEvent(Event event) { | |
226 switch (event.type) { | |
227 case DWT.Activate: | |
228 case DWT.MouseWheel: | |
229 if (fAdditionalInfoController is null) | |
230 return; | |
231 if (event.widget is fShell || event.widget is fTable || event.widget is fScrollbar) | |
232 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
233 |
129 | 234 if (fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer() is null) |
162 | 235 fAdditionalInfoController.hideInformationControl_package(); |
129 | 236 else if (!fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) { |
237 IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2(); | |
238 // During isReplaceInProgress(), events can come from the replacing information control | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
239 if (cast(Control)event.widget && cast(IInformationControlExtension5)infoControl ) { |
134 | 240 Control control= cast(Control) event.widget; |
241 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) infoControl; | |
129 | 242 if (!(iControl5.containsControl(control))) |
162 | 243 fAdditionalInfoController.hideInformationControl_package(); |
129 | 244 else if (event.type is DWT.MouseWheel) |
245 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(false); | |
246 } else if (infoControl !is null && infoControl.isFocusControl()) { | |
247 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true); | |
248 } | |
249 } | |
250 break; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
251 |
129 | 252 case DWT.MouseUp: |
253 if (fAdditionalInfoController is null || fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) | |
254 break; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
255 if (cast(Control)event.widget) { |
134 | 256 Control control= cast(Control) event.widget; |
129 | 257 IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2(); |
138 | 258 if ( cast(IInformationControlExtension5)infoControl ) { |
134 | 259 final IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) infoControl; |
129 | 260 if (iControl5.containsControl(control)) { |
138 | 261 if ( cast(IDelayedInputChangeProvider)infoControl ) { |
134 | 262 final IDelayedInputChangeProvider delayedICP= cast(IDelayedInputChangeProvider) infoControl; |
129 | 263 final IInputChangedListener inputChangeListener= new DelayedInputChangeListener(delayedICP, fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer()); |
264 delayedICP.setDelayedInputChangeListener(inputChangeListener); | |
265 // cancel automatic input updating after a small timeout: | |
135 | 266 control.getShell().getDisplay().timerExec(1000, new class() Runnable { |
129 | 267 public void run() { |
268 delayedICP.setDelayedInputChangeListener(null); | |
269 } | |
270 }); | |
271 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
272 |
129 | 273 // XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212392 : |
135 | 274 control.getShell().getDisplay().asyncExec(new class() Runnable { |
129 | 275 public void run() { |
276 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true); | |
277 } | |
278 }); | |
279 } | |
280 } | |
281 } | |
282 break; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
283 |
129 | 284 case DWT.Deactivate: |
285 if (fAdditionalInfoController is null) | |
286 break; | |
287 InformationControlReplacer replacer= fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer(); | |
288 if (replacer !is null && fContentAssistant !is null) { | |
289 IInformationControl iControl= replacer.getCurrentInformationControl2(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
290 if (cast(Control)event.widget && cast(IInformationControlExtension5)iControl ) { |
134 | 291 Control control= cast(Control) event.widget; |
292 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) iControl; | |
129 | 293 if (iControl5.containsControl(control)) { |
135 | 294 control.getDisplay().asyncExec(new class() Runnable { |
129 | 295 public void run() { |
296 if (fContentAssistant !is null && ! fContentAssistant.hasProposalPopupFocus()) | |
162 | 297 fContentAssistant.hide_package(); |
129 | 298 } |
299 }); | |
300 } | |
301 } | |
302 } | |
303 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
162
diff
changeset
|
304 default: |
129 | 305 } |
306 } | |
307 } |