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