Mercurial > projects > dwt-addons
annotate dwtx/jface/text/contentassist/ContentAssistant.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 25f1f92fa3df |
children | 862b05e0334a |
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 * Guy Gurfinkel, guy.g@zend.com - [content assist][api] provide better access to ContentAssistant - https://bugs.eclipse.org/bugs/show_bug.cgi?id=169954 | |
11 * Anton Leherbauer (Wind River Systems) - [content assist][api] ContentAssistEvent should contain information about auto activation - https://bugs.eclipse.org/bugs/show_bug.cgi?id=193728 | |
12 * Port to the D programming language: | |
13 * Frank Benoit <benoit@tionex.de> | |
14 *******************************************************************************/ | |
15 module dwtx.jface.text.contentassist.ContentAssistant; | |
16 | |
131 | 17 import dwtx.jface.text.contentassist.ContentAssistEvent; // packageimport |
18 import dwtx.jface.text.contentassist.Helper; // packageimport | |
19 import dwtx.jface.text.contentassist.PopupCloser; // packageimport | |
20 import dwtx.jface.text.contentassist.IContentAssistant; // packageimport | |
21 import dwtx.jface.text.contentassist.CompletionProposal; // packageimport | |
22 import dwtx.jface.text.contentassist.ICompletionProposalExtension5; // packageimport | |
23 import dwtx.jface.text.contentassist.IContextInformationValidator; // packageimport | |
24 import dwtx.jface.text.contentassist.IContentAssistListener; // packageimport | |
25 import dwtx.jface.text.contentassist.ICompletionProposalExtension6; // packageimport | |
26 import dwtx.jface.text.contentassist.ICompletionListener; // packageimport | |
27 import dwtx.jface.text.contentassist.ICompletionProposalExtension2; // packageimport | |
28 import dwtx.jface.text.contentassist.IContentAssistantExtension4; // packageimport | |
29 import dwtx.jface.text.contentassist.ContextInformation; // packageimport | |
30 import dwtx.jface.text.contentassist.ICompletionProposalExtension3; // packageimport | |
31 import dwtx.jface.text.contentassist.ContextInformationValidator; // packageimport | |
32 import dwtx.jface.text.contentassist.ICompletionProposal; // packageimport | |
33 import dwtx.jface.text.contentassist.IContentAssistProcessor; // packageimport | |
34 import dwtx.jface.text.contentassist.AdditionalInfoController; // packageimport | |
35 import dwtx.jface.text.contentassist.IContextInformationPresenter; // packageimport | |
36 import dwtx.jface.text.contentassist.ICompletionProposalExtension4; // packageimport | |
37 import dwtx.jface.text.contentassist.ICompletionListenerExtension; // packageimport | |
38 import dwtx.jface.text.contentassist.ContextInformationPopup; // packageimport | |
39 import dwtx.jface.text.contentassist.IContextInformationExtension; // packageimport | |
40 import dwtx.jface.text.contentassist.IContentAssistantExtension2; // packageimport | |
41 import dwtx.jface.text.contentassist.ContentAssistSubjectControlAdapter; // packageimport | |
42 import dwtx.jface.text.contentassist.CompletionProposalPopup; // packageimport | |
43 import dwtx.jface.text.contentassist.ICompletionProposalExtension; // packageimport | |
44 import dwtx.jface.text.contentassist.IContextInformation; // packageimport | |
45 import dwtx.jface.text.contentassist.IContentAssistantExtension3; // packageimport | |
46 import dwtx.jface.text.contentassist.IContentAssistantExtension; // packageimport | |
47 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport | |
48 | |
129 | 49 import dwt.dwthelper.utils; |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
147
diff
changeset
|
50 import dwtx.dwtxhelper.Collection; |
158 | 51 import tango.core.Thread; |
129 | 52 |
53 import dwt.DWT; | |
54 import dwt.DWTError; | |
55 import dwt.custom.VerifyKeyListener; | |
56 import dwt.events.ControlEvent; | |
57 import dwt.events.ControlListener; | |
58 import dwt.events.DisposeEvent; | |
59 import dwt.events.DisposeListener; | |
60 import dwt.events.FocusEvent; | |
61 import dwt.events.FocusListener; | |
62 import dwt.events.KeyAdapter; | |
63 import dwt.events.KeyEvent; | |
64 import dwt.events.KeyListener; | |
65 import dwt.events.MouseEvent; | |
66 import dwt.events.MouseListener; | |
67 import dwt.events.TraverseEvent; | |
68 import dwt.events.TraverseListener; | |
69 import dwt.events.VerifyEvent; | |
70 import dwt.graphics.Color; | |
71 import dwt.graphics.Point; | |
72 import dwt.graphics.Rectangle; | |
73 import dwt.widgets.Control; | |
74 import dwt.widgets.Display; | |
75 import dwt.widgets.Event; | |
76 import dwt.widgets.Listener; | |
77 import dwt.widgets.Monitor; | |
78 import dwt.widgets.Shell; | |
79 import dwt.widgets.Widget; | |
80 import dwtx.core.commands.IHandler; | |
81 import dwtx.core.runtime.Assert; | |
82 import dwtx.core.runtime.ListenerList; | |
83 import dwtx.jface.bindings.keys.KeySequence; | |
84 import dwtx.jface.contentassist.IContentAssistSubjectControl; | |
85 import dwtx.jface.contentassist.ISubjectControlContentAssistProcessor; | |
86 import dwtx.jface.dialogs.IDialogSettings; | |
87 import dwtx.jface.preference.JFacePreferences; | |
88 import dwtx.jface.text.BadLocationException; | |
89 import dwtx.jface.text.IDocument; | |
90 import dwtx.jface.text.IDocumentExtension3; | |
91 import dwtx.jface.text.IEventConsumer; | |
92 import dwtx.jface.text.IInformationControlCreator; | |
93 import dwtx.jface.text.ITextViewer; | |
94 import dwtx.jface.text.IViewportListener; | |
95 import dwtx.jface.text.IWidgetTokenKeeper; | |
96 import dwtx.jface.text.IWidgetTokenKeeperExtension; | |
97 import dwtx.jface.text.IWidgetTokenOwner; | |
98 import dwtx.jface.text.IWidgetTokenOwnerExtension; | |
99 import dwtx.jface.text.TextUtilities; | |
100 import dwtx.jface.util.Geometry; | |
101 | |
102 | |
103 /** | |
104 * The standard implementation of the <code>IContentAssistant</code> interface. Usually, clients | |
105 * instantiate this class and configure it before using it. | |
106 */ | |
107 public class ContentAssistant : IContentAssistant, IContentAssistantExtension, IContentAssistantExtension2, IContentAssistantExtension3, IContentAssistantExtension4, IWidgetTokenKeeper, IWidgetTokenKeeperExtension { | |
158 | 108 |
109 | |
110 | |
129 | 111 /** |
112 * Content assist command identifier for 'select next proposal'. | |
158 | 113 * |
129 | 114 * @since 3.4 |
115 */ | |
147 | 116 public static const String SELECT_NEXT_PROPOSAL_COMMAND_ID= "dwtx.ui.edit.text.contentAssist.selectNextProposal"; //$NON-NLS-1$ |
129 | 117 /** |
118 * Content assist command identifier for 'select previous proposal'. | |
158 | 119 * |
129 | 120 * @since 3.4 |
121 */ | |
147 | 122 public static const String SELECT_PREVIOUS_PROPOSAL_COMMAND_ID= "dwtx.ui.edit.text.contentAssist.selectPreviousProposal"; //$NON-NLS-1$ |
158 | 123 |
129 | 124 |
125 /** | |
126 * A generic closer class used to monitor various interface events in order to determine whether | |
127 * content-assist should be terminated and all associated windows closed. | |
128 */ | |
129 class Closer : ControlListener, MouseListener, FocusListener, DisposeListener, IViewportListener { | |
130 | |
131 /** The shell that a <code>ControlListener</code> is registered with. */ | |
132 private Shell fShell; | |
133 /** | |
134 * The control that a <code>MouseListener</code>, a<code>FocusListener</code> and a | |
135 * <code>DisposeListener</code> are registered with. | |
136 */ | |
137 private Control fControl; | |
138 | |
139 /** | |
140 * Installs this closer on it's viewer's text widget. | |
141 */ | |
142 protected void install() { | |
143 Control control= fContentAssistSubjectControlAdapter.getControl(); | |
144 fControl= control; | |
145 if (Helper.okToUse(control)) { | |
146 | |
147 Shell shell= control.getShell(); | |
148 fShell= shell; | |
149 shell.addControlListener(this); | |
150 | |
151 control.addMouseListener(this); | |
152 control.addFocusListener(this); | |
153 | |
154 /* | |
155 * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of | |
156 * Internal Errors | |
157 */ | |
158 control.addDisposeListener(this); | |
159 } | |
160 if (fViewer !is null) | |
161 fViewer.addViewportListener(this); | |
162 } | |
163 | |
164 /** | |
165 * Uninstalls this closer from the viewer's text widget. | |
166 */ | |
167 protected void uninstall() { | |
168 Control shell= fShell; | |
169 fShell= null; | |
170 if (Helper.okToUse(shell)) | |
171 shell.removeControlListener(this); | |
172 | |
173 Control control= fControl; | |
174 fControl= null; | |
175 if (Helper.okToUse(control)) { | |
176 | |
177 control.removeMouseListener(this); | |
178 control.removeFocusListener(this); | |
179 | |
180 /* | |
181 * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of | |
182 * Internal Errors | |
183 */ | |
184 control.removeDisposeListener(this); | |
185 } | |
186 | |
187 if (fViewer !is null) | |
188 fViewer.removeViewportListener(this); | |
189 } | |
190 | |
191 /* | |
192 * @see ControlListener#controlResized(ControlEvent) | |
193 */ | |
194 public void controlResized(ControlEvent e) { | |
195 hide(); | |
196 } | |
197 | |
198 /* | |
199 * @see ControlListener#controlMoved(ControlEvent) | |
200 */ | |
201 public void controlMoved(ControlEvent e) { | |
202 hide(); | |
203 } | |
204 | |
205 /* | |
206 * @see MouseListener#mouseDown(MouseEvent) | |
207 */ | |
208 public void mouseDown(MouseEvent e) { | |
209 hide(); | |
210 } | |
211 | |
212 /* | |
213 * @see MouseListener#mouseUp(MouseEvent) | |
214 */ | |
215 public void mouseUp(MouseEvent e) { | |
216 } | |
217 | |
218 /* | |
219 * @see MouseListener#mouseDoubleClick(MouseEvent) | |
220 */ | |
221 public void mouseDoubleClick(MouseEvent e) { | |
222 hide(); | |
223 } | |
224 | |
225 /* | |
226 * @see FocusListener#focusGained(FocusEvent) | |
227 */ | |
228 public void focusGained(FocusEvent e) { | |
229 } | |
230 | |
231 /* | |
232 * @see FocusListener#focusLost(FocusEvent) | |
233 */ | |
234 public void focusLost(FocusEvent e) { | |
235 Control control= fControl; | |
236 if (Helper.okToUse(control)) { | |
237 Display d= control.getDisplay(); | |
238 if (d !is null) { | |
135 | 239 d.asyncExec(new class() Runnable { |
129 | 240 public void run() { |
241 if (!fProposalPopup.hasFocus() && (fContextInfoPopup is null || !fContextInfoPopup.hasFocus())) | |
242 hide(); | |
243 } | |
244 }); | |
245 } | |
246 } | |
247 } | |
248 | |
249 /* | |
250 * @seeDisposeListener#widgetDisposed(DisposeEvent) | |
251 */ | |
252 public void widgetDisposed(DisposeEvent e) { | |
253 /* | |
254 * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal | |
255 * Errors | |
256 */ | |
257 hide(); | |
258 } | |
259 | |
260 /* | |
261 * @see IViewportListener#viewportChanged(int) | |
262 */ | |
263 public void viewportChanged(int topIndex) { | |
264 hide(); | |
265 } | |
266 } | |
267 | |
268 /** | |
269 * An implementation of <code>IContentAssistListener</code>, this class is used to monitor | |
270 * key events in support of automatic activation of the content assistant. If enabled, the | |
271 * implementation utilizes a thread to watch for input characters matching the activation | |
272 * characters specified by the content assist processor, and if detected, will wait the | |
273 * indicated delay interval before activating the content assistant. | |
158 | 274 * |
129 | 275 * @since 3.4 protected, was added in 2.1 as private class |
276 */ | |
277 protected class AutoAssistListener : KeyAdapter , KeyListener, Runnable, VerifyKeyListener { | |
278 | |
279 private Thread fThread; | |
280 private bool fIsReset= false; | |
281 private Object fMutex= new Object(); | |
282 private int fShowStyle; | |
283 | |
146 | 284 private const static int SHOW_PROPOSALS= 1; |
285 private const static int SHOW_CONTEXT_INFO= 2; | |
129 | 286 |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
287 protected this() { |
129 | 288 } |
289 | |
290 protected void start(int showStyle) { | |
291 fShowStyle= showStyle; | |
158 | 292 fThread= new Thread(&run); |
293 fThread.name = JFaceTextMessages.getString("ContentAssistant.assist_delay_timer_name"); //$NON-NLS-1$ | |
129 | 294 fThread.start(); |
295 } | |
296 | |
297 public void run() { | |
298 try { | |
299 while (true) { | |
300 synchronized (fMutex) { | |
301 if (fAutoActivationDelay !is 0) | |
302 fMutex.wait(fAutoActivationDelay); | |
303 if (fIsReset) { | |
304 fIsReset= false; | |
305 continue; | |
306 } | |
307 } | |
308 showAssist(fShowStyle); | |
309 break; | |
310 } | |
311 } catch (InterruptedException e) { | |
312 } | |
313 fThread= null; | |
314 } | |
315 | |
316 protected void reset(int showStyle) { | |
317 synchronized (fMutex) { | |
318 fShowStyle= showStyle; | |
319 fIsReset= true; | |
320 fMutex.notifyAll(); | |
321 } | |
322 } | |
323 | |
324 protected void stop() { | |
325 Thread threadToStop= fThread; | |
326 if (threadToStop !is null && threadToStop.isAlive()) | |
327 threadToStop.interrupt(); | |
328 } | |
329 | |
330 private bool contains(char[] characters, char character) { | |
331 if (characters !is null) { | |
332 for (int i= 0; i < characters.length; i++) { | |
333 if (character is characters[i]) | |
334 return true; | |
335 } | |
336 } | |
337 return false; | |
338 } | |
339 | |
340 public void keyPressed(KeyEvent e) { | |
341 // Only act on typed characters and ignore modifier-only events | |
342 if (e.character is 0 && (e.keyCode & DWT.KEYCODE_BIT) is 0) | |
343 return; | |
158 | 344 |
129 | 345 if (e.character !is 0 && (e.stateMask is DWT.ALT)) |
346 return; | |
158 | 347 |
129 | 348 // Only act on characters that are trigger candidates. This |
349 // avoids computing the model selection on every keystroke | |
350 if (computeAllAutoActivationTriggers().indexOf(e.character) < 0) { | |
351 stop(); | |
352 return; | |
353 } | |
354 | |
355 int showStyle; | |
356 int pos= fContentAssistSubjectControlAdapter.getSelectedRange().x; | |
357 char[] activation; | |
358 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
359 activation= fContentAssistSubjectControlAdapter.getCompletionProposalAutoActivationCharacters(this.outer, pos); |
129 | 360 |
361 if (contains(activation, e.character) && !isProposalPopupActive()) | |
362 showStyle= SHOW_PROPOSALS; | |
363 else { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
364 activation= fContentAssistSubjectControlAdapter.getContextInformationAutoActivationCharacters(this.outer, pos); |
129 | 365 if (contains(activation, e.character) && !isContextInfoPopupActive()) |
366 showStyle= SHOW_CONTEXT_INFO; | |
367 else { | |
368 stop(); | |
369 return; | |
370 } | |
371 } | |
372 | |
373 if (fThread !is null && fThread.isAlive()) | |
374 reset(showStyle); | |
375 else | |
376 start(showStyle); | |
377 } | |
378 | |
379 /* | |
380 * @see dwt.custom.VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) | |
381 */ | |
382 public void verifyKey(VerifyEvent event) { | |
383 keyPressed(event); | |
384 } | |
385 | |
158 | 386 protected void showAssist(int showStyle) { |
129 | 387 final Control control= fContentAssistSubjectControlAdapter.getControl(); |
388 if (control is null) | |
389 return; | |
158 | 390 |
129 | 391 final Display d= control.getDisplay(); |
392 if (d is null) | |
393 return; | |
158 | 394 |
129 | 395 try { |
135 | 396 d.syncExec(new class() Runnable { |
129 | 397 public void run() { |
398 if (isProposalPopupActive()) | |
399 return; | |
158 | 400 |
129 | 401 if (control.isDisposed() || !control.isFocusControl()) |
402 return; | |
158 | 403 |
129 | 404 if (showStyle is SHOW_PROPOSALS) { |
405 if (!prepareToShowCompletions(true)) | |
406 return; | |
407 fProposalPopup.showProposals(true); | |
408 fLastAutoActivation= System.currentTimeMillis(); | |
409 } else if (showStyle is SHOW_CONTEXT_INFO && fContextInfoPopup !is null) { | |
410 promoteKeyListener(); | |
411 fContextInfoPopup.showContextProposals(true); | |
412 } | |
413 } | |
414 }); | |
415 } catch (DWTError e) { | |
416 } | |
417 } | |
418 } | |
419 | |
420 /** | |
421 * The layout manager layouts the various windows associated with the content assistant based on | |
422 * the settings of the content assistant. | |
423 */ | |
424 class LayoutManager : Listener { | |
425 | |
426 // Presentation types. | |
427 /** The presentation type for the proposal selection popup. */ | |
146 | 428 public const static int LAYOUT_PROPOSAL_SELECTOR= 0; |
129 | 429 /** The presentation type for the context selection popup. */ |
146 | 430 public const static int LAYOUT_CONTEXT_SELECTOR= 1; |
129 | 431 /** The presentation type for the context information hover . */ |
146 | 432 public const static int LAYOUT_CONTEXT_INFO_POPUP= 2; |
129 | 433 |
434 int fContextType= LAYOUT_CONTEXT_SELECTOR; | |
435 Shell[] fShells= new Shell[3]; | |
436 Object[] fPopups= new Object[3]; | |
437 | |
438 protected void add(Object popup, Shell shell, int type, int offset) { | |
439 Assert.isNotNull(popup); | |
440 Assert.isTrue(shell !is null && !shell.isDisposed()); | |
441 checkType(type); | |
442 | |
443 if (fShells[type] !is shell) { | |
444 if (fShells[type] !is null) | |
445 fShells[type].removeListener(DWT.Dispose, this); | |
446 shell.addListener(DWT.Dispose, this); | |
447 fShells[type]= shell; | |
448 } | |
449 | |
450 fPopups[type]= popup; | |
451 if (type is LAYOUT_CONTEXT_SELECTOR || type is LAYOUT_CONTEXT_INFO_POPUP) | |
452 fContextType= type; | |
453 | |
454 layout(type, offset); | |
455 adjustListeners(type); | |
456 } | |
457 | |
458 protected void checkType(int type) { | |
459 Assert.isTrue(type is LAYOUT_PROPOSAL_SELECTOR || | |
460 type is LAYOUT_CONTEXT_SELECTOR || type is LAYOUT_CONTEXT_INFO_POPUP); | |
461 } | |
462 | |
463 public void handleEvent(Event event) { | |
464 Widget source= event.widget; | |
465 source.removeListener(DWT.Dispose, this); | |
466 | |
467 int type= getShellType(source); | |
468 checkType(type); | |
469 fShells[type]= null; | |
470 | |
471 switch (type) { | |
472 case LAYOUT_PROPOSAL_SELECTOR: | |
473 if (fContextType is LAYOUT_CONTEXT_SELECTOR && | |
474 Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) { | |
475 // Restore event notification to the tip popup. | |
134 | 476 addContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR); |
129 | 477 } |
478 break; | |
479 | |
480 case LAYOUT_CONTEXT_SELECTOR: | |
481 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) { | |
482 if (fProposalPopupOrientation is PROPOSAL_STACKED) | |
483 layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset()); | |
484 // Restore event notification to the proposal popup. | |
134 | 485 addContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); |
129 | 486 } |
487 fContextType= LAYOUT_CONTEXT_INFO_POPUP; | |
488 break; | |
489 | |
490 case LAYOUT_CONTEXT_INFO_POPUP: | |
491 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) { | |
492 if (fContextInfoPopupOrientation is CONTEXT_INFO_BELOW) | |
493 layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset()); | |
494 } | |
495 fContextType= LAYOUT_CONTEXT_SELECTOR; | |
496 break; | |
497 } | |
498 } | |
499 | |
500 protected int getShellType(Widget shell) { | |
501 for (int i= 0; i < fShells.length; i++) { | |
502 if (fShells[i] is shell) | |
503 return i; | |
504 } | |
505 return -1; | |
506 } | |
507 | |
508 /** | |
509 * Layouts the popup defined by <code>type</code> at the given widget offset. | |
158 | 510 * |
129 | 511 * @param type the kind of popup to layout |
512 * @param offset the widget offset | |
513 */ | |
514 protected void layout(int type, int offset) { | |
515 switch (type) { | |
516 case LAYOUT_PROPOSAL_SELECTOR: | |
517 layoutProposalSelector(offset); | |
518 break; | |
519 case LAYOUT_CONTEXT_SELECTOR: | |
520 layoutContextSelector(offset); | |
521 break; | |
522 case LAYOUT_CONTEXT_INFO_POPUP: | |
523 layoutContextInfoPopup(offset); | |
524 break; | |
525 } | |
526 } | |
527 | |
528 protected void layoutProposalSelector(int offset) { | |
529 if (fContextType is LAYOUT_CONTEXT_INFO_POPUP && | |
530 fContextInfoPopupOrientation is CONTEXT_INFO_BELOW && | |
531 Helper.okToUse(fShells[LAYOUT_CONTEXT_INFO_POPUP])) { | |
532 // Stack proposal selector beneath the tip box. | |
533 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
534 Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP]; | |
535 shell.setLocation(getStackedLocation(shell, parent)); | |
536 } else if (fContextType !is LAYOUT_CONTEXT_SELECTOR || | |
537 !Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) { | |
538 // There are no other presentations to be concerned with, | |
539 // so place the proposal selector beneath the cursor line. | |
540 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
134 | 541 CompletionProposalPopup popup= cast(CompletionProposalPopup) fPopups[LAYOUT_PROPOSAL_SELECTOR]; |
129 | 542 shell.setBounds(computeBoundsBelowAbove(shell, shell.getSize(), offset, popup)); |
543 } else { | |
134 | 544 CompletionProposalPopup popup= (cast(CompletionProposalPopup) fPopups[LAYOUT_PROPOSAL_SELECTOR]); |
129 | 545 switch (fProposalPopupOrientation) { |
546 case PROPOSAL_REMOVE: { | |
547 // Remove the tip selector and place the | |
548 // proposal selector beneath the cursor line. | |
549 fShells[LAYOUT_CONTEXT_SELECTOR].dispose(); | |
550 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
551 shell.setBounds(computeBoundsBelowAbove(shell, shell.getSize(), offset, popup)); | |
552 break; | |
553 } | |
554 case PROPOSAL_OVERLAY: { | |
555 // Overlay the tip selector with the proposal selector. | |
556 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
557 shell.setBounds(computeBoundsBelowAbove(shell, shell.getSize(), offset, popup)); | |
558 break; | |
559 } | |
560 case PROPOSAL_STACKED: { | |
561 // Stack the proposal selector beneath the tip selector. | |
562 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
563 Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR]; | |
564 shell.setLocation(getStackedLocation(shell, parent)); | |
565 break; | |
566 } | |
567 } | |
568 } | |
569 } | |
570 | |
571 protected void layoutContextSelector(int offset) { | |
572 // Always place the context selector beneath the cursor line. | |
573 Shell shell= fShells[LAYOUT_CONTEXT_SELECTOR]; | |
574 shell.setBounds(computeBoundsBelowAbove(shell, shell.getSize(), offset, null)); | |
575 | |
576 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) { | |
577 switch (fProposalPopupOrientation) { | |
578 case PROPOSAL_REMOVE: | |
579 // Remove the proposal selector. | |
580 fShells[LAYOUT_PROPOSAL_SELECTOR].dispose(); | |
581 break; | |
582 | |
583 case PROPOSAL_OVERLAY: | |
584 // The proposal selector has been overlaid by the tip selector. | |
585 break; | |
586 | |
587 case PROPOSAL_STACKED: { | |
588 // Stack the proposal selector beneath the tip selector. | |
589 shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
590 Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR]; | |
591 shell.setLocation(getStackedLocation(shell, parent)); | |
592 break; | |
593 } | |
594 } | |
595 } | |
596 } | |
597 | |
598 protected void layoutContextInfoPopup(int offset) { | |
599 switch (fContextInfoPopupOrientation) { | |
600 case CONTEXT_INFO_ABOVE: { | |
601 // Place the popup above the cursor line. | |
602 Shell shell= fShells[LAYOUT_CONTEXT_INFO_POPUP]; | |
603 shell.setBounds(computeBoundsAboveBelow(shell, shell.getSize(), offset)); | |
604 break; | |
605 } | |
606 case CONTEXT_INFO_BELOW: { | |
607 // Place the popup beneath the cursor line. | |
608 Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP]; | |
609 parent.setBounds(computeBoundsBelowAbove(parent, parent.getSize(), offset, null)); | |
610 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) { | |
611 // Stack the proposal selector beneath the context info popup. | |
612 Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR]; | |
613 shell.setLocation(getStackedLocation(shell, parent)); | |
614 } | |
615 break; | |
616 } | |
617 } | |
618 } | |
619 | |
620 /** | |
621 * Moves <code>point</code> such that <code>rectangle</code> does not bleed outside of | |
622 * <code>bounds</code>. All coordinates must have the same reference. | |
158 | 623 * |
129 | 624 * @param point the point to move if needed |
625 * @param shellSize the size of the shell that may be moved | |
626 * @param bounds the bounds | |
627 * @since 3.3 | |
628 */ | |
629 protected void constrainLocation(Point point, Point shellSize, Rectangle bounds) { | |
630 if (point.x + shellSize.x > bounds.x + bounds.width) | |
631 point.x= bounds.x + bounds.width - shellSize.x; | |
632 | |
633 if (point.x < bounds.x) | |
634 point.x= bounds.x; | |
158 | 635 |
129 | 636 if (point.y + shellSize.y > bounds.y + bounds.height) |
637 point.y= bounds.y + bounds.height - shellSize.y; | |
158 | 638 |
129 | 639 if (point.y < bounds.y) |
640 point.y= bounds.y; | |
641 } | |
642 | |
643 protected Rectangle constrainHorizontally(Rectangle rect, Rectangle bounds) { | |
644 // clip width | |
645 if (rect.width > bounds.width) | |
646 rect.width= bounds.width; | |
158 | 647 |
129 | 648 if (rect.x + rect.width > bounds.x + bounds.width) |
649 rect.x= bounds.x + bounds.width - rect.width; | |
650 if (rect.x < bounds.x) | |
651 rect.x= bounds.x; | |
158 | 652 |
129 | 653 return rect; |
654 } | |
158 | 655 |
129 | 656 /** |
657 * Returns the display bounds for <code>shell</code> such that it appears right above | |
658 * <code>offset</code>, or below it if above is not suitable. The returned bounds lie | |
659 * within the monitor at the caret location and never overlap with the caret line. | |
158 | 660 * |
129 | 661 * @param shell the shell to compute the placement for |
662 * @param preferred the preferred size for <code>shell</code> | |
663 * @param offset the caret offset in the subject control | |
664 * @return the point right above <code>offset</code> in display coordinates | |
665 * @since 3.3 | |
666 */ | |
667 protected Rectangle computeBoundsAboveBelow(Shell shell, Point preferred, int offset) { | |
668 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); | |
669 Display display= subjectControl.getDisplay(); | |
670 Rectangle caret= getCaretRectangle(offset); | |
671 Monitor monitor= getClosestMonitor(display, caret); | |
672 Rectangle bounds= monitor.getClientArea(); | |
673 Geometry.moveInside(caret, bounds); | |
158 | 674 |
129 | 675 int spaceAbove= caret.y - bounds.y; |
676 int caretLowerY= caret.y + caret.height; | |
677 int spaceBelow= bounds.y + bounds.height - caretLowerY; | |
678 Rectangle rect; | |
679 if (spaceAbove >= preferred.y) | |
680 rect= new Rectangle(caret.x, caret.y - preferred.y, preferred.x, preferred.y); | |
681 else if (spaceBelow >= preferred.y) | |
682 rect= new Rectangle(caret.x, caretLowerY, preferred.x, preferred.y); | |
683 // we can't fit in the preferred size - squeeze into larger area | |
684 else if (spaceBelow <= spaceAbove) | |
685 rect= new Rectangle(caret.x, bounds.y, preferred.x, spaceAbove); | |
686 else | |
687 rect= new Rectangle(caret.x, caretLowerY, preferred.x, spaceBelow); | |
158 | 688 |
129 | 689 return constrainHorizontally(rect, bounds); |
690 } | |
162 | 691 package Rectangle computeBoundsAboveBelow_package(Shell shell, Point preferred, int offset) { |
692 return computeBoundsAboveBelow(shell, preferred, offset); | |
693 } | |
129 | 694 |
695 /** | |
696 * Returns the display bounds for <code>shell</code> such that it appears right below | |
697 * <code>offset</code>, or above it if below is not suitable. The returned bounds lie | |
698 * within the monitor at the caret location and never overlap with the caret line. | |
158 | 699 * |
129 | 700 * @param shell the shell to compute the placement for |
701 * @param preferred the preferred size for <code>shell</code> | |
702 * @param offset the caret offset in the subject control | |
703 * @param popup a popup to inform if the location was switched to above, <code>null</code> to do nothing | |
704 * @return the point right below <code>offset</code> in display coordinates | |
705 * @since 3.3 | |
706 */ | |
707 protected Rectangle computeBoundsBelowAbove(Shell shell, Point preferred, int offset, CompletionProposalPopup popup) { | |
708 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); | |
709 Display display= subjectControl.getDisplay(); | |
710 Rectangle caret= getCaretRectangle(offset); | |
711 Monitor monitor= getClosestMonitor(display, caret); | |
712 Rectangle bounds= monitor.getClientArea(); | |
713 Geometry.moveInside(caret, bounds); | |
714 | |
715 int threshold= popup is null ? Integer.MAX_VALUE : popup.getMinimalHeight(); | |
716 int spaceAbove= caret.y - bounds.y; | |
717 int spaceBelow= bounds.y + bounds.height - (caret.y + caret.height); | |
718 Rectangle rect; | |
719 bool switched= false; | |
720 if (spaceBelow >= preferred.y) | |
721 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, preferred.y); | |
722 // squeeze in below if we have at least threshold space | |
723 else if (spaceBelow >= threshold) | |
724 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, spaceBelow); | |
725 else if (spaceAbove >= preferred.y) { | |
726 rect= new Rectangle(caret.x, caret.y - preferred.y, preferred.x, preferred.y); | |
727 switched= true; | |
728 } else if (spaceBelow >= spaceAbove) { | |
729 // we can't fit in the preferred size - squeeze into larger area | |
730 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, spaceBelow); | |
731 } else { | |
732 rect= new Rectangle(caret.x, bounds.y, preferred.x, spaceAbove); | |
733 switched= true; | |
734 } | |
158 | 735 |
129 | 736 if (popup !is null) |
737 popup.switchedPositionToAbove(switched); | |
158 | 738 |
129 | 739 return constrainHorizontally(rect, bounds); |
740 } | |
162 | 741 package Rectangle computeBoundsBelowAbove_package(Shell shell, Point preferred, int offset, CompletionProposalPopup popup) { |
742 return computeBoundsBelowAbove(shell, preferred, offset, popup ); | |
743 } | |
129 | 744 |
745 private Rectangle getCaretRectangle(int offset) { | |
746 Point location= fContentAssistSubjectControlAdapter.getLocationAtOffset(offset); | |
747 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); | |
748 Point controlSize= subjectControl.getSize(); | |
749 constrainLocation(location, new Point(0, 0), new Rectangle(0, 0, controlSize.x, controlSize.y)); | |
750 location= subjectControl.toDisplay(location); | |
751 Rectangle subjectRectangle= new Rectangle(location.x, location.y, 1, fContentAssistSubjectControlAdapter.getLineHeight()); | |
752 return subjectRectangle; | |
753 } | |
158 | 754 |
129 | 755 protected Point getStackedLocation(Shell shell, Shell parent) { |
756 Point p= parent.getLocation(); | |
757 Point size= parent.getSize(); | |
758 p.x += size.x / 4; | |
759 p.y += size.y; | |
760 | |
761 p= parent.toDisplay(p); | |
762 | |
763 Point shellSize= shell.getSize(); | |
764 Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0)); | |
765 Rectangle displayBounds= monitor.getClientArea(); | |
766 constrainLocation(p, shellSize, displayBounds); | |
767 | |
768 return p; | |
769 } | |
770 | |
771 protected void adjustListeners(int type) { | |
772 switch (type) { | |
773 case LAYOUT_PROPOSAL_SELECTOR: | |
774 if (fContextType is LAYOUT_CONTEXT_SELECTOR && | |
775 Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) | |
776 // Disable event notification to the tip selector. | |
134 | 777 removeContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR); |
129 | 778 break; |
779 case LAYOUT_CONTEXT_SELECTOR: | |
780 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) | |
781 // Disable event notification to the proposal selector. | |
134 | 782 removeContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); |
129 | 783 break; |
784 case LAYOUT_CONTEXT_INFO_POPUP: | |
785 break; | |
786 } | |
787 } | |
158 | 788 |
129 | 789 /** |
790 * Copied from dwtx.jface.window.Window. | |
791 * Returns the monitor whose client area contains the given point. If no | |
792 * monitor contains the point, returns the monitor that is closest to the | |
793 * point. If this is ever made public, it should be moved into a separate | |
794 * utility class. | |
158 | 795 * |
129 | 796 * @param toSearch |
797 * point to find (display coordinates) | |
798 * @param rectangle | |
799 * rectangle to find (display coordinates) | |
800 * @return the monitor closest to the given point | |
801 * @since 3.3 | |
802 */ | |
803 private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) { | |
804 int closest = Integer.MAX_VALUE; | |
805 | |
806 Point toFind= Geometry.centerPoint(rectangle); | |
807 Monitor[] monitors = toSearch.getMonitors(); | |
808 Monitor result = monitors[0]; | |
809 | |
810 for (int idx = 0; idx < monitors.length; idx++) { | |
811 Monitor current = monitors[idx]; | |
812 | |
813 Rectangle clientArea = current.getClientArea(); | |
814 | |
815 if (clientArea.contains(toFind)) { | |
816 return current; | |
817 } | |
818 | |
819 int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); | |
820 if (distance < closest) { | |
821 closest = distance; | |
822 result = current; | |
823 } | |
824 } | |
825 | |
826 return result; | |
827 } | |
828 } | |
829 | |
830 /** | |
831 * Internal key listener and event consumer. | |
832 */ | |
833 class InternalListener : VerifyKeyListener, IEventConsumer { | |
834 | |
835 /** | |
836 * Verifies key events by notifying the registered listeners. Each listener is allowed to | |
837 * indicate that the event has been handled and should not be further processed. | |
838 * | |
839 * @param e the verify event | |
840 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) | |
841 */ | |
842 public void verifyKey(VerifyEvent e) { | |
158 | 843 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); |
129 | 844 for (int i= 0; i < listeners.length; i++) { |
845 if (listeners[i] !is null) { | |
846 if (!listeners[i].verifyKey(e) || !e.doit) | |
847 break; | |
848 } | |
849 } | |
850 if (fAutoAssistListener !is null) | |
851 fAutoAssistListener.keyPressed(e); | |
852 } | |
853 | |
854 /* | |
855 * @see IEventConsumer#processEvent | |
856 */ | |
857 public void processEvent(VerifyEvent event) { | |
858 | |
859 installKeyListener(); | |
860 | |
158 | 861 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); |
129 | 862 for (int i= 0; i < listeners.length; i++) { |
863 if (listeners[i] !is null) { | |
864 listeners[i].processEvent(event); | |
865 if (!event.doit) | |
866 return; | |
867 } | |
868 } | |
869 } | |
870 } | |
871 | |
872 /** | |
873 * Dialog store constants. | |
874 * | |
875 * @since 3.0 | |
876 */ | |
147 | 877 public static const String STORE_SIZE_X= "size.x"; //$NON-NLS-1$ |
878 public static const String STORE_SIZE_Y= "size.y"; //$NON-NLS-1$ | |
129 | 879 |
880 // Content-Assist Listener types | |
881 final static int CONTEXT_SELECTOR= 0; | |
882 final static int PROPOSAL_SELECTOR= 1; | |
883 final static int CONTEXT_INFO_POPUP= 2; | |
884 | |
885 /** | |
886 * The popup priority: > linked position proposals and hover pop-ups. Default value: | |
887 * <code>20</code>; | |
888 * | |
889 * @since 3.0 | |
890 */ | |
147 | 891 public static const int WIDGET_PRIORITY= 20; |
129 | 892 |
147 | 893 private static const int DEFAULT_AUTO_ACTIVATION_DELAY= 500; |
129 | 894 |
895 private IInformationControlCreator fInformationControlCreator; | |
896 private int fAutoActivationDelay= DEFAULT_AUTO_ACTIVATION_DELAY; | |
897 private bool fIsAutoActivated= false; | |
898 private bool fIsAutoInserting= false; | |
899 private int fProposalPopupOrientation= PROPOSAL_OVERLAY; | |
900 private int fContextInfoPopupOrientation= CONTEXT_INFO_ABOVE; | |
901 private Map fProcessors; | |
902 | |
903 /** | |
904 * The partitioning. | |
905 * | |
906 * @since 3.0 | |
907 */ | |
908 private String fPartitioning; | |
909 | |
910 private Color fContextInfoPopupBackground; | |
911 private Color fContextInfoPopupForeground; | |
912 private Color fContextSelectorBackground; | |
913 private Color fContextSelectorForeground; | |
914 private Color fProposalSelectorBackground; | |
915 private Color fProposalSelectorForeground; | |
916 | |
917 private ITextViewer fViewer; | |
918 private String fLastErrorMessage; | |
919 | |
920 private Closer fCloser; | |
921 LayoutManager fLayoutManager; | |
922 private AutoAssistListener fAutoAssistListener; | |
923 private InternalListener fInternalListener; | |
924 private CompletionProposalPopup fProposalPopup; | |
925 private ContextInformationPopup fContextInfoPopup; | |
926 | |
927 /** | |
928 * Flag which tells whether a verify key listener is hooked. | |
929 * | |
930 * @since 3.0 | |
931 */ | |
932 private bool fVerifyKeyListenerHooked= false; | |
162 | 933 private IContentAssistListener[] fListeners; |
129 | 934 /** |
935 * The content assist subject control. | |
936 * | |
937 * @since 3.0 | |
938 */ | |
939 private IContentAssistSubjectControl fContentAssistSubjectControl; | |
940 /** | |
941 * The content assist subject control's shell. | |
942 * | |
943 * @since 3.2 | |
944 */ | |
945 private Shell fContentAssistSubjectControlShell; | |
946 /** | |
947 * The content assist subject control's shell traverse listener. | |
948 * | |
949 * @since 3.2 | |
950 */ | |
951 private TraverseListener fCASCSTraverseListener; | |
952 /** | |
953 * The content assist subject control adapter. | |
954 * | |
955 * @since 3.0 | |
956 */ | |
957 private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter; | |
958 /** | |
959 * The dialog settings for the control's bounds. | |
960 * | |
961 * @since 3.0 | |
962 */ | |
963 private IDialogSettings fDialogSettings; | |
964 /** | |
965 * Prefix completion setting. | |
966 * | |
967 * @since 3.0 | |
968 */ | |
969 private bool fIsPrefixCompletionEnabled= false; | |
970 /** | |
971 * The list of completion listeners. | |
972 * | |
973 * @since 3.2 | |
974 */ | |
162 | 975 private ListenerList fCompletionListeners; |
129 | 976 /** |
977 * The message to display at the bottom of the proposal popup. | |
978 * | |
979 * @since 3.2 | |
980 */ | |
981 private String fMessage= ""; //$NON-NLS-1$ | |
982 /** | |
983 * The cycling mode property. | |
984 * | |
985 * @since 3.2 | |
986 */ | |
987 private bool fIsRepetitionMode= false; | |
988 /** | |
989 * The show empty property. | |
990 * | |
991 * @since 3.2 | |
992 */ | |
993 private bool fShowEmptyList= false; | |
994 /** | |
995 * The message line property. | |
996 * | |
997 * @since 3.2 | |
998 */ | |
999 private bool fIsStatusLineVisible; | |
1000 /** | |
1001 * The last system time when auto activation performed. | |
158 | 1002 * |
129 | 1003 * @since 3.2 |
1004 */ | |
1005 private long fLastAutoActivation= Long.MIN_VALUE; | |
1006 /** | |
1007 * The iteration key sequence to listen for, or <code>null</code>. | |
1008 * | |
1009 * @since 3.2 | |
1010 */ | |
1011 private KeySequence fRepeatedInvocationKeySequence; | |
158 | 1012 |
129 | 1013 /** |
1014 * Maps handler to command identifiers. | |
158 | 1015 * |
129 | 1016 * @since 3.4 |
1017 */ | |
1018 private Map fHandlers; | |
158 | 1019 |
129 | 1020 /** |
1021 * Tells whether colored labels support is enabled. | |
158 | 1022 * |
129 | 1023 * @since 3.4 |
1024 */ | |
1025 private bool fIsColoredLabelsSupportEnabled= false; | |
1026 | |
1027 | |
1028 /** | |
1029 * Creates a new content assistant. The content assistant is not automatically activated, | |
1030 * overlays the completion proposals with context information list if necessary, and shows the | |
1031 * context information above the location at which it was activated. If auto activation will be | |
1032 * enabled, without further configuration steps, this content assistant is activated after a 500 | |
1033 * milliseconds delay. It uses the default partitioning. | |
1034 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
1035 public this() { |
162 | 1036 fListeners= new IContentAssistListener[4]; |
1037 fCompletionListeners= new ListenerList(ListenerList.IDENTITY); | |
129 | 1038 fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING; |
1039 } | |
1040 | |
1041 /** | |
1042 * Sets the document partitioning this content assistant is using. | |
1043 * | |
1044 * @param partitioning the document partitioning for this content assistant | |
1045 * @since 3.0 | |
1046 */ | |
1047 public void setDocumentPartitioning(String partitioning) { | |
1048 Assert.isNotNull(partitioning); | |
1049 fPartitioning= partitioning; | |
1050 } | |
1051 | |
1052 /* | |
1053 * @see dwtx.jface.text.contentassist.IContentAssistantExtension#getDocumentPartitioning() | |
1054 * @since 3.0 | |
1055 */ | |
1056 public String getDocumentPartitioning() { | |
1057 return fPartitioning; | |
1058 } | |
1059 | |
1060 /** | |
1061 * Registers a given content assist processor for a particular content type. If there is already | |
1062 * a processor registered for this type, the new processor is registered instead of the old one. | |
1063 * | |
1064 * @param processor the content assist processor to register, or <code>null</code> to remove | |
1065 * an existing one | |
1066 * @param contentType the content type under which to register | |
1067 */ | |
1068 public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType) { | |
1069 | |
1070 Assert.isNotNull(contentType); | |
1071 | |
1072 if (fProcessors is null) | |
1073 fProcessors= new HashMap(); | |
1074 | |
1075 if (processor is null) | |
1076 fProcessors.remove(contentType); | |
1077 else | |
1078 fProcessors.put(contentType, processor); | |
1079 } | |
1080 | |
1081 /* | |
1082 * @see IContentAssistant#getContentAssistProcessor | |
1083 */ | |
1084 public IContentAssistProcessor getContentAssistProcessor(String contentType) { | |
1085 if (fProcessors is null) | |
1086 return null; | |
1087 | |
134 | 1088 return cast(IContentAssistProcessor) fProcessors.get(contentType); |
129 | 1089 } |
1090 | |
1091 /** | |
1092 * Computes the sorted set of all auto activation trigger characters. | |
1093 * | |
1094 * @return the sorted set of all auto activation trigger characters | |
1095 * @since 3.1 | |
1096 */ | |
1097 private String computeAllAutoActivationTriggers() { | |
1098 if (fProcessors is null) | |
1099 return ""; //$NON-NLS-1$ | |
1100 | |
1101 StringBuffer buf= new StringBuffer(5); | |
1102 Iterator iter= fProcessors.entrySet().iterator(); | |
1103 while (iter.hasNext()) { | |
134 | 1104 Entry entry= cast(Entry) iter.next(); |
1105 IContentAssistProcessor processor= cast(IContentAssistProcessor) entry.getValue(); | |
129 | 1106 char[] triggers= processor.getCompletionProposalAutoActivationCharacters(); |
1107 if (triggers !is null) | |
1108 buf.append(triggers); | |
1109 triggers= processor.getContextInformationAutoActivationCharacters(); | |
1110 if (triggers !is null) | |
1111 buf.append(triggers); | |
1112 } | |
1113 return buf.toString(); | |
1114 } | |
1115 | |
1116 /** | |
1117 * Enables the content assistant's auto activation mode. | |
1118 * | |
1119 * @param enabled indicates whether auto activation is enabled or not | |
1120 */ | |
1121 public void enableAutoActivation(bool enabled) { | |
1122 fIsAutoActivated= enabled; | |
1123 manageAutoActivation(fIsAutoActivated); | |
1124 } | |
1125 | |
1126 /** | |
1127 * Enables the content assistant's auto insertion mode. If enabled, the content assistant | |
1128 * inserts a proposal automatically if it is the only proposal. In the case of ambiguities, the | |
1129 * user must make the choice. | |
1130 * | |
1131 * @param enabled indicates whether auto insertion is enabled or not | |
1132 * @since 2.0 | |
1133 */ | |
1134 public void enableAutoInsert(bool enabled) { | |
1135 fIsAutoInserting= enabled; | |
1136 } | |
1137 | |
1138 /** | |
1139 * Returns whether this content assistant is in the auto insertion mode or not. | |
1140 * | |
1141 * @return <code>true</code> if in auto insertion mode | |
1142 * @since 2.0 | |
1143 */ | |
1144 bool isAutoInserting() { | |
1145 return fIsAutoInserting; | |
1146 } | |
1147 | |
1148 /** | |
1149 * Installs and uninstall the listeners needed for auto activation. | |
1150 * | |
1151 * @param start <code>true</code> if listeners must be installed, <code>false</code> if they | |
1152 * must be removed | |
1153 * @since 2.0 | |
1154 */ | |
1155 private void manageAutoActivation(bool start) { | |
1156 if (start) { | |
1157 | |
1158 if ((fContentAssistSubjectControlAdapter !is null) && fAutoAssistListener is null) { | |
1159 fAutoAssistListener= createAutoAssistListener(); | |
1160 // For details see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 | |
1161 if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) | |
1162 fContentAssistSubjectControlAdapter.appendVerifyKeyListener(fAutoAssistListener); | |
1163 else | |
1164 fContentAssistSubjectControlAdapter.addKeyListener(fAutoAssistListener); | |
1165 } | |
1166 | |
1167 } else if (fAutoAssistListener !is null) { | |
1168 // For details see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 | |
1169 if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) | |
1170 fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fAutoAssistListener); | |
1171 else | |
1172 fContentAssistSubjectControlAdapter.removeKeyListener(fAutoAssistListener); | |
1173 fAutoAssistListener= null; | |
1174 } | |
1175 } | |
1176 | |
1177 /** | |
1178 * This method allows subclasses to provide their own {@link AutoAssistListener}. | |
158 | 1179 * |
129 | 1180 * @return a new auto assist listener |
1181 * @since 3.4 | |
1182 */ | |
1183 protected AutoAssistListener createAutoAssistListener() { | |
1184 return new AutoAssistListener(); | |
1185 } | |
1186 | |
1187 /** | |
1188 * Sets the delay after which the content assistant is automatically invoked if the cursor is | |
1189 * behind an auto activation character. | |
1190 * | |
1191 * @param delay the auto activation delay | |
1192 */ | |
1193 public void setAutoActivationDelay(int delay) { | |
1194 fAutoActivationDelay= delay; | |
1195 } | |
1196 | |
1197 /** | |
1198 * Gets the delay after which the content assistant is automatically invoked if the cursor is | |
1199 * behind an auto activation character. | |
158 | 1200 * |
129 | 1201 * @return the auto activation delay |
1202 * @since 3.4 | |
1203 */ | |
1204 public int getAutoActivationDelay() { | |
1205 return fAutoActivationDelay; | |
1206 } | |
1207 | |
1208 /** | |
1209 * Sets the proposal pop-ups' orientation. The following values may be used: | |
1210 * <ul> | |
1211 * <li>PROPOSAL_OVERLAY<p> | |
1212 * proposal popup windows should overlay each other | |
1213 * </li> | |
1214 * <li>PROPOSAL_REMOVE<p> | |
1215 * any currently shown proposal popup should be closed | |
1216 * </li> | |
1217 * <li>PROPOSAL_STACKED<p> | |
1218 * proposal popup windows should be vertical stacked, with no overlap, | |
1219 * beneath the line containing the current cursor location | |
1220 * </li> | |
1221 * </ul> | |
1222 * | |
1223 * @param orientation the popup's orientation | |
1224 */ | |
1225 public void setProposalPopupOrientation(int orientation) { | |
1226 fProposalPopupOrientation= orientation; | |
1227 } | |
1228 | |
1229 /** | |
1230 * Sets the context information popup's orientation. | |
1231 * The following values may be used: | |
1232 * <ul> | |
1233 * <li>CONTEXT_ABOVE<p> | |
1234 * context information popup should always appear above the line containing | |
1235 * the current cursor location | |
1236 * </li> | |
1237 * <li>CONTEXT_BELOW<p> | |
1238 * context information popup should always appear below the line containing | |
1239 * the current cursor location | |
1240 * </li> | |
1241 * </ul> | |
1242 * | |
1243 * @param orientation the popup's orientation | |
1244 */ | |
1245 public void setContextInformationPopupOrientation(int orientation) { | |
1246 fContextInfoPopupOrientation= orientation; | |
1247 } | |
1248 | |
1249 /** | |
1250 * Sets the context information popup's background color. | |
1251 * | |
1252 * @param background the background color | |
1253 */ | |
1254 public void setContextInformationPopupBackground(Color background) { | |
1255 fContextInfoPopupBackground= background; | |
1256 } | |
1257 | |
1258 /** | |
1259 * Returns the background of the context information popup. | |
1260 * | |
1261 * @return the background of the context information popup | |
1262 * @since 2.0 | |
1263 */ | |
1264 Color getContextInformationPopupBackground() { | |
1265 return fContextInfoPopupBackground; | |
1266 } | |
1267 | |
1268 /** | |
1269 * Sets the context information popup's foreground color. | |
1270 * | |
1271 * @param foreground the foreground color | |
1272 * @since 2.0 | |
1273 */ | |
1274 public void setContextInformationPopupForeground(Color foreground) { | |
1275 fContextInfoPopupForeground= foreground; | |
1276 } | |
1277 | |
1278 /** | |
1279 * Returns the foreground of the context information popup. | |
158 | 1280 * |
129 | 1281 * |
1282 * @return the foreground of the context information popup | |
1283 * @since 2.0 | |
1284 */ | |
1285 Color getContextInformationPopupForeground() { | |
1286 return fContextInfoPopupForeground; | |
1287 } | |
1288 | |
1289 /** | |
1290 * Sets the proposal selector's background color. | |
1291 * <p> | |
1292 * <strong>Note:</strong> As of 3.4, you should only call this | |
1293 * method if you want to override the {@link JFacePreferences#CONTENT_ASSIST_BACKGROUND_COLOR}. | |
1294 * </p> | |
1295 * | |
1296 * @param background the background color | |
1297 * @since 2.0 | |
1298 */ | |
1299 public void setProposalSelectorBackground(Color background) { | |
1300 fProposalSelectorBackground= background; | |
1301 } | |
1302 | |
1303 /** | |
1304 * Returns the custom background color of the proposal selector. | |
1305 * | |
1306 * @return the background of the proposal selector or <code>null</code> if not set | |
1307 * @since 2.0 | |
1308 */ | |
1309 Color getProposalSelectorBackground() { | |
1310 return fProposalSelectorBackground; | |
1311 } | |
1312 | |
1313 /** | |
1314 * Sets the proposal's foreground color. | |
1315 * <p> | |
1316 * <strong>Note:</strong> As of 3.4, you should only call this | |
1317 * method if you want to override the {@link JFacePreferences#CONTENT_ASSIST_FOREGROUND_COLOR}. | |
1318 * </p> | |
1319 * | |
1320 * @param foreground the foreground color | |
1321 * @since 2.0 | |
1322 */ | |
1323 public void setProposalSelectorForeground(Color foreground) { | |
1324 fProposalSelectorForeground= foreground; | |
1325 } | |
1326 | |
1327 /** | |
1328 * Returns the custom foreground color of the proposal selector. | |
1329 * | |
1330 * @return the foreground of the proposal selector or <code>null</code> if not set | |
1331 * @since 2.0 | |
1332 */ | |
1333 Color getProposalSelectorForeground() { | |
1334 return fProposalSelectorForeground; | |
1335 } | |
1336 | |
1337 /** | |
1338 * Sets the context selector's background color. | |
1339 * | |
1340 * @param background the background color | |
1341 * @since 2.0 | |
1342 */ | |
1343 public void setContextSelectorBackground(Color background) { | |
1344 fContextSelectorBackground= background; | |
1345 } | |
1346 | |
1347 /** | |
1348 * Returns the background of the context selector. | |
1349 * | |
1350 * @return the background of the context selector | |
1351 * @since 2.0 | |
1352 */ | |
1353 Color getContextSelectorBackground() { | |
1354 return fContextSelectorBackground; | |
1355 } | |
1356 | |
1357 /** | |
1358 * Sets the context selector's foreground color. | |
1359 * | |
1360 * @param foreground the foreground color | |
1361 * @since 2.0 | |
1362 */ | |
1363 public void setContextSelectorForeground(Color foreground) { | |
1364 fContextSelectorForeground= foreground; | |
1365 } | |
1366 | |
1367 /** | |
1368 * Returns the foreground of the context selector. | |
1369 * | |
1370 * @return the foreground of the context selector | |
1371 * @since 2.0 | |
1372 */ | |
1373 Color getContextSelectorForeground() { | |
1374 return fContextSelectorForeground; | |
1375 } | |
1376 | |
1377 /** | |
1378 * Sets the information control creator for the additional information control. | |
1379 * | |
1380 * @param creator the information control creator for the additional information control | |
1381 * @since 2.0 | |
1382 */ | |
1383 public void setInformationControlCreator(IInformationControlCreator creator) { | |
1384 fInformationControlCreator= creator; | |
1385 } | |
1386 | |
1387 /* | |
1388 * @see IControlContentAssistant#install(IContentAssistSubjectControl) | |
1389 * @since 3.0 | |
1390 */ | |
1391 protected void install(IContentAssistSubjectControl contentAssistSubjectControl) { | |
1392 fContentAssistSubjectControl= contentAssistSubjectControl; | |
1393 fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl); | |
1394 install(); | |
1395 } | |
1396 | |
1397 /* | |
1398 * @see IContentAssist#install | |
1399 * @since 3.0 | |
1400 */ | |
1401 public void install(ITextViewer textViewer) { | |
1402 fViewer= textViewer; | |
1403 fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fViewer); | |
1404 install(); | |
1405 } | |
1406 | |
1407 protected void install() { | |
1408 | |
1409 fLayoutManager= new LayoutManager(); | |
1410 fInternalListener= new InternalListener(); | |
1411 | |
1412 AdditionalInfoController controller= null; | |
1413 if (fInformationControlCreator !is null) { | |
1414 int delay= fAutoActivationDelay; | |
1415 if (delay is 0) | |
1416 delay= DEFAULT_AUTO_ACTIVATION_DELAY; | |
1417 delay= Math.round(delay * 1.5f); | |
1418 controller= new AdditionalInfoController(fInformationControlCreator, delay); | |
1419 } | |
1420 | |
1421 fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this); | |
1422 fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller); | |
1423 | |
1424 registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT)); | |
1425 registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS)); | |
1426 | |
1427 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) { | |
1428 fContentAssistSubjectControlShell= fContentAssistSubjectControlAdapter.getControl().getShell(); | |
135 | 1429 fCASCSTraverseListener= new class() TraverseListener { |
129 | 1430 public void keyTraversed(TraverseEvent e) { |
1431 if (e.detail is DWT.TRAVERSE_ESCAPE && isProposalPopupActive()) | |
1432 e.doit= false; | |
1433 } | |
1434 }; | |
1435 fContentAssistSubjectControlShell.addTraverseListener(fCASCSTraverseListener); | |
1436 } | |
1437 | |
1438 manageAutoActivation(fIsAutoActivated); | |
1439 } | |
1440 | |
1441 /* | |
1442 * @see IContentAssist#uninstall | |
1443 */ | |
1444 public void uninstall() { | |
1445 hide(); | |
1446 manageAutoActivation(false); | |
158 | 1447 |
129 | 1448 if (fHandlers !is null) { |
1449 fHandlers.clear(); | |
1450 fHandlers= null; | |
1451 } | |
1452 | |
1453 if (fCloser !is null) { | |
1454 fCloser.uninstall(); | |
1455 fCloser= null; | |
1456 } | |
1457 | |
1458 if (Helper.okToUse(fContentAssistSubjectControlShell)) | |
1459 fContentAssistSubjectControlShell.removeTraverseListener(fCASCSTraverseListener); | |
1460 fCASCSTraverseListener= null; | |
1461 fContentAssistSubjectControlShell= null; | |
1462 | |
1463 fViewer= null; | |
1464 fContentAssistSubjectControl= null; | |
1465 fContentAssistSubjectControlAdapter= null; | |
1466 } | |
1467 | |
1468 /** | |
1469 * Adds the given shell of the specified type to the layout. Valid types are defined by | |
1470 * <code>LayoutManager</code>. | |
1471 * | |
1472 * @param popup a content assist popup | |
1473 * @param shell the shell of the content-assist popup | |
1474 * @param type the type of popup | |
1475 * @param visibleOffset the offset at which to layout the popup relative to the offset of the | |
1476 * viewer's visible region | |
1477 * @since 2.0 | |
1478 */ | |
1479 void addToLayout(Object popup, Shell shell, int type, int visibleOffset) { | |
1480 fLayoutManager.add(popup, shell, type, visibleOffset); | |
1481 } | |
1482 | |
1483 /** | |
1484 * Layouts the registered popup of the given type relative to the given offset. The offset is | |
1485 * relative to the offset of the viewer's visible region. Valid types are defined by | |
1486 * <code>LayoutManager</code>. | |
1487 * | |
1488 * @param type the type of popup to layout | |
1489 * @param visibleOffset the offset at which to layout relative to the offset of the viewer's | |
1490 * visible region | |
1491 * @since 2.0 | |
1492 */ | |
1493 void layout(int type, int visibleOffset) { | |
1494 fLayoutManager.layout(type, visibleOffset); | |
1495 } | |
158 | 1496 |
129 | 1497 /** |
1498 * Returns the layout manager. | |
158 | 1499 * |
129 | 1500 * @return the layout manager |
1501 * @since 3.3 | |
1502 */ | |
1503 LayoutManager getLayoutManager() { | |
1504 return fLayoutManager; | |
1505 } | |
1506 | |
1507 /** | |
1508 * Notifies the controller that a popup has lost focus. | |
1509 * | |
1510 * @param e the focus event | |
1511 */ | |
1512 void popupFocusLost(FocusEvent e) { | |
1513 fCloser.focusLost(e); | |
1514 } | |
1515 | |
1516 /** | |
1517 * Returns the offset of the selection relative to the offset of the visible region. | |
1518 * | |
1519 * @return the offset of the selection relative to the offset of the visible region | |
1520 * @since 2.0 | |
1521 */ | |
1522 int getSelectionOffset() { | |
1523 return fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; | |
1524 } | |
1525 | |
1526 /** | |
1527 * Returns whether the widget token could be acquired. The following are valid listener types: | |
1528 * <ul> | |
1529 * <li>AUTO_ASSIST</li> | |
1530 * <li>CONTEXT_SELECTOR</li> | |
1531 * <li>PROPOSAL_SELECTOR</li> | |
1532 * <li>CONTEXT_INFO_POPUP</li> | |
1533 * </ul> | |
1534 * | |
1535 * @param type the listener type for which to acquire | |
1536 * @return <code>true</code> if the widget token could be acquired | |
1537 * @since 2.0 | |
1538 */ | |
1539 private bool acquireWidgetToken(int type) { | |
1540 switch (type) { | |
1541 case CONTEXT_SELECTOR: | |
1542 case PROPOSAL_SELECTOR: | |
138 | 1543 if ( cast(IWidgetTokenOwnerExtension)fContentAssistSubjectControl ) { |
134 | 1544 IWidgetTokenOwnerExtension extension= cast(IWidgetTokenOwnerExtension) fContentAssistSubjectControl; |
129 | 1545 return extension.requestWidgetToken(this, WIDGET_PRIORITY); |
138 | 1546 } else if ( cast(IWidgetTokenOwner)fContentAssistSubjectControl ) { |
134 | 1547 IWidgetTokenOwner owner= cast(IWidgetTokenOwner) fContentAssistSubjectControl; |
129 | 1548 return owner.requestWidgetToken(this); |
138 | 1549 } else if ( cast(IWidgetTokenOwnerExtension)fViewer ) { |
134 | 1550 IWidgetTokenOwnerExtension extension= cast(IWidgetTokenOwnerExtension) fViewer; |
129 | 1551 return extension.requestWidgetToken(this, WIDGET_PRIORITY); |
138 | 1552 } else if ( cast(IWidgetTokenOwner)fViewer ) { |
134 | 1553 IWidgetTokenOwner owner= cast(IWidgetTokenOwner) fViewer; |
129 | 1554 return owner.requestWidgetToken(this); |
1555 } | |
1556 } | |
1557 return true; | |
1558 } | |
1559 | |
1560 /** | |
1561 * Registers a content assist listener. The following are valid listener types: | |
1562 * <ul> | |
1563 * <li>AUTO_ASSIST</li> | |
1564 * <li>CONTEXT_SELECTOR</li> | |
1565 * <li>PROPOSAL_SELECTOR</li> | |
1566 * <li>CONTEXT_INFO_POPUP</li> | |
1567 * </ul> | |
1568 * Returns whether the listener could be added successfully. A listener can not be added if the | |
1569 * widget token could not be acquired. | |
1570 * | |
1571 * @param listener the listener to register | |
1572 * @param type the type of listener | |
1573 * @return <code>true</code> if the listener could be added | |
1574 */ | |
1575 bool addContentAssistListener(IContentAssistListener listener, int type) { | |
1576 | |
1577 if (acquireWidgetToken(type)) { | |
1578 | |
1579 fListeners[type]= listener; | |
1580 | |
1581 if (fCloser is null && getNumberOfListeners() is 1) { | |
1582 fCloser= new Closer(); | |
1583 fCloser.install(); | |
1584 fContentAssistSubjectControlAdapter.setEventConsumer(fInternalListener); | |
1585 installKeyListener(); | |
1586 } else | |
1587 promoteKeyListener(); | |
1588 return true; | |
1589 } | |
1590 | |
1591 return false; | |
1592 } | |
1593 | |
1594 /** | |
1595 * Re-promotes the key listener to the first position, using prependVerifyKeyListener. This | |
1596 * ensures no other instance is filtering away the keystrokes underneath, if we've been up for a | |
1597 * while (e.g. when the context info is showing. | |
1598 * | |
1599 * @since 3.0 | |
1600 */ | |
1601 private void promoteKeyListener() { | |
1602 uninstallVerifyKeyListener(); | |
1603 installKeyListener(); | |
1604 } | |
1605 | |
1606 /** | |
1607 * Installs a key listener on the text viewer's widget. | |
1608 */ | |
1609 private void installKeyListener() { | |
1610 if (!fVerifyKeyListenerHooked) { | |
1611 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) { | |
1612 fVerifyKeyListenerHooked= fContentAssistSubjectControlAdapter.prependVerifyKeyListener(fInternalListener); | |
1613 } | |
1614 } | |
1615 } | |
1616 | |
1617 /** | |
1618 * Releases the previously acquired widget token if the token is no longer necessary. The | |
1619 * following are valid listener types: | |
1620 * <ul> | |
1621 * <li>AUTO_ASSIST</li> | |
1622 * <li>CONTEXT_SELECTOR</li> | |
1623 * <li>PROPOSAL_SELECTOR</li> | |
1624 * <li>CONTEXT_INFO_POPUP</li> | |
1625 * </ul> | |
1626 * | |
1627 * @param type the listener type | |
1628 * @since 2.0 | |
1629 */ | |
1630 private void releaseWidgetToken(int type) { | |
1631 if (fListeners[CONTEXT_SELECTOR] is null && fListeners[PROPOSAL_SELECTOR] is null) { | |
1632 IWidgetTokenOwner owner= null; | |
138 | 1633 if ( cast(IWidgetTokenOwner)fContentAssistSubjectControl ) |
134 | 1634 owner= cast(IWidgetTokenOwner) fContentAssistSubjectControl; |
138 | 1635 else if ( cast(IWidgetTokenOwner)fViewer ) |
134 | 1636 owner= cast(IWidgetTokenOwner) fViewer; |
129 | 1637 if (owner !is null) |
1638 owner.releaseWidgetToken(this); | |
1639 } | |
1640 } | |
1641 | |
1642 /** | |
1643 * Unregisters a content assist listener. | |
1644 * | |
1645 * @param listener the listener to unregister | |
1646 * @param type the type of listener | |
1647 * @see #addContentAssistListener(IContentAssistListener, int) | |
1648 */ | |
1649 void removeContentAssistListener(IContentAssistListener listener, int type) { | |
1650 fListeners[type]= null; | |
1651 | |
1652 if (getNumberOfListeners() is 0) { | |
1653 | |
1654 if (fCloser !is null) { | |
1655 fCloser.uninstall(); | |
1656 fCloser= null; | |
1657 } | |
1658 | |
1659 uninstallVerifyKeyListener(); | |
1660 fContentAssistSubjectControlAdapter.setEventConsumer(null); | |
1661 } | |
1662 | |
1663 releaseWidgetToken(type); | |
1664 } | |
1665 | |
1666 /** | |
1667 * Uninstall the key listener from the text viewer's widget. | |
1668 * | |
1669 * @since 3.0 | |
1670 */ | |
1671 private void uninstallVerifyKeyListener() { | |
1672 if (fVerifyKeyListenerHooked) { | |
1673 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) | |
1674 fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fInternalListener); | |
1675 fVerifyKeyListenerHooked= false; | |
1676 } | |
1677 } | |
1678 | |
1679 /** | |
1680 * Returns the number of listeners. | |
1681 * | |
1682 * @return the number of listeners | |
1683 * @since 2.0 | |
1684 */ | |
1685 private int getNumberOfListeners() { | |
1686 int count= 0; | |
1687 for (int i= 0; i <= CONTEXT_INFO_POPUP; i++) { | |
1688 if (fListeners[i] !is null) | |
1689 ++count; | |
1690 } | |
1691 return count; | |
1692 } | |
1693 | |
1694 /* | |
1695 * @see IContentAssist#showPossibleCompletions | |
1696 */ | |
1697 public String showPossibleCompletions() { | |
1698 if (!prepareToShowCompletions(false)) | |
1699 return null; | |
1700 if (fIsPrefixCompletionEnabled) | |
1701 return fProposalPopup.incrementalComplete(); | |
1702 return fProposalPopup.showProposals(false); | |
1703 } | |
1704 | |
1705 /* | |
1706 * @see dwtx.jface.text.contentassist.IContentAssistantExtension#completePrefix() | |
1707 * @since 3.0 | |
1708 */ | |
1709 public String completePrefix() { | |
1710 if (!prepareToShowCompletions(false)) | |
1711 return null; | |
1712 return fProposalPopup.incrementalComplete(); | |
1713 } | |
1714 | |
1715 /** | |
1716 * Prepares to show content assist proposals. It returns false if auto activation has kicked in | |
1717 * recently. | |
158 | 1718 * |
129 | 1719 * @param isAutoActivated whether completion was triggered by auto activation |
1720 * @return <code>true</code> if the caller should continue and show the proposals, | |
1721 * <code>false</code> otherwise. | |
1722 * @since 3.2 | |
1723 */ | |
1724 private bool prepareToShowCompletions(bool isAutoActivated) { | |
1725 long current= System.currentTimeMillis(); | |
1726 int gracePeriod= Math.max(fAutoActivationDelay, 200); | |
1727 if (current < fLastAutoActivation + gracePeriod) | |
1728 return false; | |
158 | 1729 |
129 | 1730 promoteKeyListener(); |
1731 fireSessionBeginEvent(isAutoActivated); | |
1732 return true; | |
1733 } | |
1734 | |
1735 /** | |
1736 * Callback to signal this content assistant that the presentation of the possible completions | |
1737 * has been stopped. | |
1738 * | |
1739 * @since 2.1 | |
1740 */ | |
1741 protected void possibleCompletionsClosed() { | |
1742 fLastAutoActivation= Long.MIN_VALUE; | |
1743 storeCompletionProposalPopupSize(); | |
1744 } | |
162 | 1745 package void possibleCompletionsClosed_package() { |
1746 possibleCompletionsClosed(); | |
1747 } | |
129 | 1748 |
1749 /* | |
1750 * @see IContentAssist#showContextInformation | |
1751 */ | |
1752 public String showContextInformation() { | |
1753 promoteKeyListener(); | |
1754 if (fContextInfoPopup !is null) | |
1755 return fContextInfoPopup.showContextProposals(false); | |
1756 return null; | |
1757 } | |
1758 | |
1759 /** | |
1760 * Callback to signal this content assistant that the presentation of the context information | |
1761 * has been stopped. | |
1762 * | |
1763 * @since 2.1 | |
1764 */ | |
1765 protected void contextInformationClosed() { | |
1766 } | |
162 | 1767 package void contextInformationClosed_package() { |
1768 contextInformationClosed(); | |
1769 } | |
129 | 1770 |
1771 /** | |
1772 * Requests that the specified context information to be shown. | |
1773 * | |
1774 * @param contextInformation the context information to be shown | |
1775 * @param offset the offset to which the context information refers to | |
1776 * @since 2.0 | |
1777 */ | |
1778 void showContextInformation(IContextInformation contextInformation, int offset) { | |
1779 if (fContextInfoPopup !is null) | |
1780 fContextInfoPopup.showContextInformation(contextInformation, offset); | |
1781 } | |
1782 | |
1783 /** | |
1784 * Returns the current content assist error message. | |
1785 * | |
1786 * @return an error message or <code>null</code> if no error has occurred | |
1787 */ | |
1788 String getErrorMessage() { | |
1789 return fLastErrorMessage; | |
1790 } | |
1791 | |
1792 /** | |
1793 * Returns the content assist processor for the content type of the specified document position. | |
1794 * | |
1795 * @param viewer the text viewer | |
1796 * @param offset a offset within the document | |
1797 * @return a content-assist processor or <code>null</code> if none exists | |
1798 * @since 3.0 | |
1799 */ | |
1800 private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) { | |
1801 try { | |
1802 | |
1803 IDocument document= viewer.getDocument(); | |
1804 String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); | |
1805 | |
1806 return getContentAssistProcessor(type); | |
1807 | |
1808 } catch (BadLocationException x) { | |
1809 } | |
1810 | |
1811 return null; | |
1812 } | |
1813 | |
1814 /** | |
1815 * Returns the content assist processor for the content type of the specified document position. | |
1816 * | |
1817 * @param contentAssistSubjectControl the content assist subject control | |
1818 * @param offset a offset within the document | |
1819 * @return a content-assist processor or <code>null</code> if none exists | |
1820 * @since 3.0 | |
1821 */ | |
1822 private IContentAssistProcessor getProcessor(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1823 try { | |
1824 | |
1825 IDocument document= contentAssistSubjectControl.getDocument(); | |
1826 String type; | |
1827 if (document !is null) | |
1828 type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); | |
1829 else | |
1830 type= IDocument.DEFAULT_CONTENT_TYPE; | |
1831 | |
1832 return getContentAssistProcessor(type); | |
1833 | |
1834 } catch (BadLocationException x) { | |
1835 } | |
1836 | |
1837 return null; | |
1838 } | |
1839 | |
1840 /** | |
1841 * Returns an array of completion proposals computed based on the specified document position. | |
1842 * The position is used to determine the appropriate content assist processor to invoke. | |
1843 * | |
1844 * @param contentAssistSubjectControl the content assist subject control | |
1845 * @param offset a document offset | |
1846 * @return an array of completion proposals | |
1847 * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) | |
1848 * @since 3.0 | |
1849 */ | |
1850 ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1851 fLastErrorMessage= null; | |
1852 | |
1853 ICompletionProposal[] result= null; | |
1854 | |
1855 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
138 | 1856 if ( cast(ISubjectControlContentAssistProcessor)p ) { |
134 | 1857 result= (cast(ISubjectControlContentAssistProcessor) p).computeCompletionProposals(contentAssistSubjectControl, offset); |
129 | 1858 fLastErrorMessage= p.getErrorMessage(); |
1859 } | |
1860 | |
1861 return result; | |
1862 } | |
1863 | |
1864 /** | |
1865 * Returns an array of completion proposals computed based on the specified document position. | |
1866 * The position is used to determine the appropriate content assist processor to invoke. | |
1867 * | |
1868 * @param viewer the viewer for which to compute the proposals | |
1869 * @param offset a document offset | |
1870 * @return an array of completion proposals or <code>null</code> if no proposals are possible | |
1871 * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) | |
1872 */ | |
1873 ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { | |
1874 fLastErrorMessage= null; | |
1875 | |
1876 ICompletionProposal[] result= null; | |
1877 | |
1878 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1879 if (p !is null) { | |
1880 result= p.computeCompletionProposals(viewer, offset); | |
1881 fLastErrorMessage= p.getErrorMessage(); | |
1882 } | |
1883 | |
1884 return result; | |
1885 } | |
1886 | |
1887 /** | |
1888 * Returns an array of context information objects computed based on the specified document | |
1889 * position. The position is used to determine the appropriate content assist processor to | |
1890 * invoke. | |
1891 * | |
1892 * @param viewer the viewer for which to compute the context information | |
1893 * @param offset a document offset | |
1894 * @return an array of context information objects | |
1895 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) | |
1896 */ | |
1897 IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { | |
1898 fLastErrorMessage= null; | |
1899 | |
1900 IContextInformation[] result= null; | |
1901 | |
1902 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1903 if (p !is null) { | |
1904 result= p.computeContextInformation(viewer, offset); | |
1905 fLastErrorMessage= p.getErrorMessage(); | |
1906 } | |
1907 | |
1908 return result; | |
1909 } | |
1910 | |
1911 /** | |
1912 * Returns an array of context information objects computed based on the specified document | |
1913 * position. The position is used to determine the appropriate content assist processor to | |
1914 * invoke. | |
1915 * | |
1916 * @param contentAssistSubjectControl the content assist subject control | |
1917 * @param offset a document offset | |
1918 * @return an array of context information objects | |
1919 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) | |
1920 * @since 3.0 | |
1921 */ | |
1922 IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1923 fLastErrorMessage= null; | |
1924 | |
1925 IContextInformation[] result= null; | |
1926 | |
1927 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
138 | 1928 if ( cast(ISubjectControlContentAssistProcessor)p ) { |
134 | 1929 result= (cast(ISubjectControlContentAssistProcessor) p).computeContextInformation(contentAssistSubjectControl, offset); |
129 | 1930 fLastErrorMessage= p.getErrorMessage(); |
1931 } | |
1932 | |
1933 return result; | |
1934 } | |
1935 | |
1936 /** | |
1937 * Returns the context information validator that should be used to determine when the currently | |
1938 * displayed context information should be dismissed. The position is used to determine the | |
1939 * appropriate content assist processor to invoke. | |
1940 * | |
1941 * @param viewer the text viewer | |
1942 * @param offset a document offset | |
1943 * @return an validator | |
1944 * @see IContentAssistProcessor#getContextInformationValidator() | |
1945 * @since 3.0 | |
1946 */ | |
1947 IContextInformationValidator getContextInformationValidator(ITextViewer viewer, int offset) { | |
1948 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1949 return p !is null ? p.getContextInformationValidator() : null; | |
1950 } | |
1951 | |
1952 /** | |
1953 * Returns the context information validator that should be used to determine when the currently | |
1954 * displayed context information should be dismissed. The position is used to determine the | |
1955 * appropriate content assist processor to invoke. | |
1956 * | |
1957 * @param contentAssistSubjectControl the content assist subject control | |
1958 * @param offset a document offset | |
1959 * @return an validator | |
1960 * @see IContentAssistProcessor#getContextInformationValidator() | |
1961 * @since 3.0 | |
1962 */ | |
1963 IContextInformationValidator getContextInformationValidator(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1964 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
1965 return p !is null ? p.getContextInformationValidator() : null; | |
1966 } | |
1967 | |
1968 /** | |
1969 * Returns the context information presenter that should be used to display context information. | |
1970 * The position is used to determine the appropriate content assist processor to invoke. | |
1971 * | |
1972 * @param viewer the text viewer | |
1973 * @param offset a document offset | |
1974 * @return a presenter | |
1975 * @since 2.0 | |
1976 */ | |
1977 IContextInformationPresenter getContextInformationPresenter(ITextViewer viewer, int offset) { | |
1978 IContextInformationValidator validator= getContextInformationValidator(viewer, offset); | |
138 | 1979 if ( cast(IContextInformationPresenter)validator ) |
134 | 1980 return cast(IContextInformationPresenter) validator; |
129 | 1981 return null; |
1982 } | |
1983 | |
1984 /** | |
1985 * Returns the context information presenter that should be used to display context information. | |
1986 * The position is used to determine the appropriate content assist processor to invoke. | |
1987 * | |
1988 * @param contentAssistSubjectControl the content assist subject control | |
1989 * @param offset a document offset | |
1990 * @return a presenter | |
1991 * @since 3.0 | |
1992 */ | |
1993 IContextInformationPresenter getContextInformationPresenter(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1994 IContextInformationValidator validator= getContextInformationValidator(contentAssistSubjectControl, offset); | |
138 | 1995 if ( cast(IContextInformationPresenter)validator ) |
134 | 1996 return cast(IContextInformationPresenter) validator; |
129 | 1997 return null; |
1998 } | |
1999 | |
2000 /** | |
2001 * Returns the characters which when typed by the user should automatically initiate proposing | |
2002 * completions. The position is used to determine the appropriate content assist processor to | |
2003 * invoke. | |
2004 * | |
2005 * @param contentAssistSubjectControl the content assist subject control | |
2006 * @param offset a document offset | |
2007 * @return the auto activation characters | |
2008 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() | |
2009 * @since 3.0 | |
2010 */ | |
2011 char[] getCompletionProposalAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
2012 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
2013 return p !is null ? p.getCompletionProposalAutoActivationCharacters() : null; | |
2014 } | |
2015 | |
2016 /** | |
2017 * Returns the characters which when typed by the user should automatically initiate proposing | |
2018 * completions. The position is used to determine the appropriate content assist processor to | |
2019 * invoke. | |
2020 * | |
2021 * @param viewer the text viewer | |
2022 * @param offset a document offset | |
2023 * @return the auto activation characters | |
2024 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() | |
2025 */ | |
2026 char[] getCompletionProposalAutoActivationCharacters(ITextViewer viewer, int offset) { | |
2027 IContentAssistProcessor p= getProcessor(viewer, offset); | |
2028 return p !is null ? p.getCompletionProposalAutoActivationCharacters() : null; | |
2029 } | |
2030 | |
2031 /** | |
2032 * Returns the characters which when typed by the user should automatically initiate the | |
2033 * presentation of context information. The position is used to determine the appropriate | |
2034 * content assist processor to invoke. | |
2035 * | |
2036 * @param viewer the text viewer | |
2037 * @param offset a document offset | |
2038 * @return the auto activation characters | |
2039 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() | |
2040 * @since 3.0 | |
2041 */ | |
2042 char[] getContextInformationAutoActivationCharacters(ITextViewer viewer, int offset) { | |
2043 IContentAssistProcessor p= getProcessor(viewer, offset); | |
2044 return p !is null ? p.getContextInformationAutoActivationCharacters() : null; | |
2045 } | |
2046 | |
2047 /** | |
2048 * Returns the characters which when typed by the user should automatically initiate the | |
2049 * presentation of context information. The position is used to determine the appropriate | |
2050 * content assist processor to invoke. | |
2051 * | |
2052 * @param contentAssistSubjectControl the content assist subject control | |
2053 * @param offset a document offset | |
2054 * @return the auto activation characters | |
2055 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() | |
2056 * @since 3.0 | |
2057 */ | |
2058 char[] getContextInformationAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
2059 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
2060 return p !is null ? p.getContextInformationAutoActivationCharacters() : null; | |
2061 } | |
2062 | |
2063 /* | |
2064 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner) | |
2065 * @since 2.0 | |
2066 */ | |
2067 public bool requestWidgetToken(IWidgetTokenOwner owner) { | |
2068 return false; | |
2069 } | |
2070 | |
2071 /* | |
2072 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, | |
2073 * int) | |
2074 * @since 3.0 | |
2075 */ | |
2076 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) { | |
2077 if (priority > WIDGET_PRIORITY) { | |
2078 hide(); | |
2079 return true; | |
2080 } | |
2081 return false; | |
2082 } | |
2083 | |
2084 /* | |
2085 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#setFocus(dwtx.jface.text.IWidgetTokenOwner) | |
2086 * @since 3.0 | |
2087 */ | |
2088 public bool setFocus(IWidgetTokenOwner owner) { | |
2089 if (fProposalPopup !is null) { | |
2090 fProposalPopup.setFocus(); | |
2091 return fProposalPopup.hasFocus(); | |
2092 } | |
2093 return false; | |
2094 } | |
2095 | |
2096 /** | |
2097 * Hides any open pop-ups. | |
2098 * | |
2099 * @since 3.0 | |
2100 */ | |
2101 protected void hide() { | |
2102 if (fProposalPopup !is null) | |
2103 fProposalPopup.hide(); | |
2104 | |
2105 if (fContextInfoPopup !is null) | |
2106 fContextInfoPopup.hide(); | |
2107 } | |
162 | 2108 package void hide_package() { |
2109 hide(); | |
2110 } | |
129 | 2111 |
2112 // ------ control's size handling dialog settings ------ | |
2113 | |
2114 /** | |
2115 * Tells this information control manager to open the information control with the values | |
2116 * contained in the given dialog settings and to store the control's last valid size in the | |
2117 * given dialog settings. | |
2118 * <p> | |
2119 * Note: This API is only valid if the information control implements | |
2120 * {@link dwtx.jface.text.IInformationControlExtension3}. Not following this restriction | |
2121 * will later result in an {@link UnsupportedOperationException}. | |
2122 * </p> | |
2123 * <p> | |
2124 * The constants used to store the values are: | |
2125 * <ul> | |
2126 * <li>{@link ContentAssistant#STORE_SIZE_X}</li> | |
2127 * <li>{@link ContentAssistant#STORE_SIZE_Y}</li> | |
2128 * </ul> | |
2129 * </p> | |
2130 * | |
2131 * @param dialogSettings | |
2132 * @since 3.0 | |
2133 */ | |
2134 public void setRestoreCompletionProposalSize(IDialogSettings dialogSettings) { | |
2135 Assert.isTrue(dialogSettings !is null); | |
2136 fDialogSettings= dialogSettings; | |
2137 } | |
2138 | |
2139 /** | |
2140 * Stores the content assist pop-up's size. | |
2141 */ | |
2142 protected void storeCompletionProposalPopupSize() { | |
2143 if (fDialogSettings is null || fProposalPopup is null) | |
2144 return; | |
2145 | |
2146 Point size= fProposalPopup.getSize(); | |
2147 if (size is null) | |
2148 return; | |
2149 | |
2150 fDialogSettings.put(STORE_SIZE_X, size.x); | |
2151 fDialogSettings.put(STORE_SIZE_Y, size.y); | |
2152 } | |
2153 | |
2154 /** | |
2155 * Restores the content assist pop-up's size. | |
2156 * | |
2157 * @return the stored size | |
2158 * @since 3.0 | |
2159 */ | |
2160 protected Point restoreCompletionProposalPopupSize() { | |
2161 if (fDialogSettings is null) | |
2162 return null; | |
2163 | |
2164 Point size= new Point(-1, -1); | |
2165 | |
2166 try { | |
2167 size.x= fDialogSettings.getInt(STORE_SIZE_X); | |
2168 size.y= fDialogSettings.getInt(STORE_SIZE_Y); | |
2169 } catch (NumberFormatException ex) { | |
2170 size.x= -1; | |
2171 size.y= -1; | |
2172 } | |
2173 | |
2174 // sanity check | |
2175 if (size.x is -1 && size.y is -1) | |
2176 return null; | |
2177 | |
2178 Rectangle maxBounds= null; | |
2179 if (fContentAssistSubjectControl !is null && Helper.okToUse(fContentAssistSubjectControl.getControl())) | |
2180 maxBounds= fContentAssistSubjectControl.getControl().getDisplay().getBounds(); | |
2181 else { | |
2182 // fallback | |
2183 Display display= Display.getCurrent(); | |
2184 if (display is null) | |
2185 display= Display.getDefault(); | |
2186 if (display !is null && !display.isDisposed()) | |
2187 maxBounds= display.getBounds(); | |
2188 } | |
2189 | |
2190 if (size.x > -1 && size.y > -1) { | |
2191 if (maxBounds !is null) { | |
2192 size.x= Math.min(size.x, maxBounds.width); | |
2193 size.y= Math.min(size.y, maxBounds.height); | |
2194 } | |
2195 | |
2196 // Enforce an absolute minimal size | |
2197 size.x= Math.max(size.x, 30); | |
2198 size.y= Math.max(size.y, 30); | |
2199 } | |
2200 | |
2201 return size; | |
2202 } | |
162 | 2203 package Point restoreCompletionProposalPopupSize_package() { |
2204 return restoreCompletionProposalPopupSize(); | |
2205 } | |
129 | 2206 |
2207 /** | |
2208 * Sets the prefix completion property. If enabled, content assist delegates completion to | |
2209 * prefix completion. | |
2210 * | |
2211 * @param enabled <code>true</code> to enable prefix completion, <code>false</code> to | |
2212 * disable | |
2213 */ | |
2214 public void enablePrefixCompletion(bool enabled) { | |
2215 fIsPrefixCompletionEnabled= enabled; | |
2216 } | |
158 | 2217 |
129 | 2218 /** |
2219 * Returns the prefix completion state. | |
158 | 2220 * |
129 | 2221 * @return <code>true</code> if prefix completion is enabled, <code>false</code> otherwise |
2222 * @since 3.2 | |
2223 */ | |
2224 bool isPrefixCompletionEnabled() { | |
2225 return fIsPrefixCompletionEnabled; | |
2226 } | |
2227 | |
2228 /** | |
2229 * Returns whether the content assistant proposal popup has the focus. | |
2230 * | |
2231 * @return <code>true</code> if the proposal popup has the focus | |
2232 * @since 3.0 | |
2233 */ | |
2234 public bool hasProposalPopupFocus() { | |
2235 return fProposalPopup.hasFocus(); | |
2236 } | |
2237 | |
2238 /* | |
2239 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#addCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) | |
2240 * @since 3.2 | |
2241 */ | |
2242 public void addCompletionListener(ICompletionListener listener) { | |
2243 Assert.isLegal(listener !is null); | |
2244 fCompletionListeners.add(listener); | |
2245 } | |
2246 | |
2247 /* | |
2248 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#removeCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) | |
2249 * @since 3.2 | |
2250 */ | |
2251 public void removeCompletionListener(ICompletionListener listener) { | |
2252 fCompletionListeners.remove(listener); | |
2253 } | |
2254 | |
2255 /** | |
2256 * Fires a session begin event to all registered {@link ICompletionListener}s. | |
158 | 2257 * |
129 | 2258 * @param isAutoActivated <code>true</code> if this session was triggered by auto activation |
2259 * @since 3.2 | |
2260 */ | |
2261 void fireSessionBeginEvent(bool isAutoActivated) { | |
2262 if (fContentAssistSubjectControlAdapter !is null && !isProposalPopupActive()) { | |
2263 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2264 ContentAssistEvent event= new ContentAssistEvent(this, processor, isAutoActivated); | |
2265 Object[] listeners= fCompletionListeners.getListeners(); | |
2266 for (int i= 0; i < listeners.length; i++) { | |
134 | 2267 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2268 listener.assistSessionStarted(event); |
2269 } | |
2270 } | |
2271 } | |
158 | 2272 |
129 | 2273 /** |
2274 * Fires a session restart event to all registered {@link ICompletionListener}s. | |
2275 * | |
2276 * @since 3.4 | |
2277 */ | |
2278 void fireSessionRestartEvent() { | |
2279 if (fContentAssistSubjectControlAdapter !is null) { | |
2280 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2281 ContentAssistEvent event= new ContentAssistEvent(this, processor); | |
2282 Object[] listeners= fCompletionListeners.getListeners(); | |
2283 for (int i= 0; i < listeners.length; i++) { | |
134 | 2284 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
138 | 2285 if ( cast(ICompletionListenerExtension)listener ) |
134 | 2286 (cast(ICompletionListenerExtension)listener).assistSessionRestarted(event); |
129 | 2287 } |
2288 } | |
2289 } | |
2290 | |
2291 /** | |
2292 * Fires a session end event to all registered {@link ICompletionListener}s. | |
2293 * | |
2294 * @since 3.2 | |
2295 */ | |
2296 void fireSessionEndEvent() { | |
2297 if (fContentAssistSubjectControlAdapter !is null) { | |
2298 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2299 ContentAssistEvent event= new ContentAssistEvent(this, processor); | |
2300 Object[] listeners= fCompletionListeners.getListeners(); | |
2301 for (int i= 0; i < listeners.length; i++) { | |
134 | 2302 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2303 listener.assistSessionEnded(event); |
2304 } | |
2305 } | |
2306 } | |
2307 | |
2308 /* | |
2309 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setRepeatedInvocationMode(bool) | |
2310 * @since 3.2 | |
2311 */ | |
2312 public void setRepeatedInvocationMode(bool cycling) { | |
2313 fIsRepetitionMode= cycling; | |
2314 } | |
2315 | |
2316 /** | |
2317 * Returns <code>true</code> if repeated invocation mode is enabled, <code>false</code> | |
2318 * otherwise. | |
2319 * | |
2320 * @return <code>true</code> if repeated invocation mode is enabled, <code>false</code> | |
2321 * otherwise | |
2322 * @since 3.2 | |
2323 */ | |
2324 bool isRepeatedInvocationMode() { | |
2325 return fIsRepetitionMode; | |
2326 } | |
2327 | |
2328 /* | |
2329 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setShowEmptyList(bool) | |
2330 * @since 3.2 | |
2331 */ | |
2332 public void setShowEmptyList(bool showEmpty) { | |
2333 fShowEmptyList= showEmpty; | |
2334 } | |
2335 | |
2336 /** | |
2337 * Returns <code>true</code> if empty lists should be displayed, <code>false</code> | |
2338 * otherwise. | |
2339 * | |
2340 * @return <code>true</code> if empty lists should be displayed, <code>false</code> | |
2341 * otherwise | |
2342 * @since 3.2 | |
2343 */ | |
2344 bool isShowEmptyList() { | |
2345 return fShowEmptyList; | |
2346 } | |
2347 | |
2348 /* | |
2349 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setStatusLineVisible(bool) | |
2350 * @since 3.2 | |
2351 */ | |
2352 public void setStatusLineVisible(bool show) { | |
2353 fIsStatusLineVisible= show; | |
2354 if (fProposalPopup !is null) | |
2355 fProposalPopup.setStatusLineVisible(show); | |
2356 } | |
2357 | |
2358 /** | |
2359 * Returns <code>true</code> if a message line should be displayed, <code>false</code> | |
2360 * otherwise. | |
2361 * | |
2362 * @return <code>true</code> if a message line should be displayed, <code>false</code> | |
2363 * otherwise | |
2364 * @since 3.2 | |
2365 */ | |
2366 bool isStatusLineVisible() { | |
2367 return fIsStatusLineVisible; | |
2368 } | |
2369 | |
2370 /* | |
2371 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setStatusMessage(java.lang.String) | |
2372 * @since 3.2 | |
2373 */ | |
2374 public void setStatusMessage(String message) { | |
2375 Assert.isLegal(message !is null); | |
2376 fMessage= message; | |
2377 if (fProposalPopup !is null) | |
2378 fProposalPopup.setMessage(message); | |
2379 } | |
2380 | |
2381 /** | |
2382 * Returns the affordance caption for the cycling affordance at the bottom of the pop-up. | |
2383 * | |
2384 * @return the affordance caption for the cycling affordance at the bottom of the pop-up | |
2385 * @since 3.2 | |
2386 */ | |
2387 String getStatusMessage() { | |
2388 return fMessage; | |
2389 } | |
2390 | |
2391 /* | |
2392 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setEmptyMessage(java.lang.String) | |
2393 * @since 3.2 | |
2394 */ | |
2395 public void setEmptyMessage(String message) { | |
2396 Assert.isLegal(message !is null); | |
2397 if (fProposalPopup !is null) | |
2398 fProposalPopup.setEmptyMessage(message); | |
2399 } | |
2400 | |
2401 /** | |
2402 * Fires a selection event, see {@link ICompletionListener}. | |
2403 * | |
2404 * @param proposal the selected proposal, possibly <code>null</code> | |
2405 * @param smartToggle true if the smart toggle is on | |
2406 * @since 3.2 | |
2407 */ | |
2408 void fireSelectionEvent(ICompletionProposal proposal, bool smartToggle) { | |
2409 Object[] listeners= fCompletionListeners.getListeners(); | |
2410 for (int i= 0; i < listeners.length; i++) { | |
134 | 2411 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2412 listener.selectionChanged(proposal, smartToggle); |
2413 } | |
2414 } | |
2415 | |
2416 /* | |
2417 * @see dwtx.jface.text.contentassist.IContentAssistantExtension3#setInvocationTrigger(dwtx.jface.bindings.keys.KeySequence) | |
2418 * @since 3.2 | |
2419 */ | |
2420 public void setRepeatedInvocationTrigger(KeySequence sequence) { | |
2421 fRepeatedInvocationKeySequence= sequence; | |
2422 } | |
2423 | |
2424 /** | |
2425 * Returns the repeated invocation key sequence. | |
158 | 2426 * |
129 | 2427 * @return the repeated invocation key sequence or <code>null</code>, if none |
2428 * @since 3.2 | |
2429 */ | |
2430 KeySequence getRepeatedInvocationKeySequence() { | |
2431 return fRepeatedInvocationKeySequence; | |
2432 } | |
158 | 2433 |
129 | 2434 /** |
2435 * Returns whether proposal popup is active. | |
158 | 2436 * |
129 | 2437 * @return <code>true</code> if the proposal popup is active, <code>false</code> otherwise |
2438 * @since 3.4 | |
2439 */ | |
2440 protected bool isProposalPopupActive(){ | |
2441 return fProposalPopup !is null && fProposalPopup.isActive(); | |
2442 } | |
2443 | |
2444 /** | |
2445 * Returns whether the context information popup is active. | |
158 | 2446 * |
129 | 2447 * @return <code>true</code> if the context information popup is active, <code>false</code> otherwise |
2448 * @since 3.4 | |
2449 */ | |
2450 protected bool isContextInfoPopupActive(){ | |
2451 return fContextInfoPopup !is null && fContextInfoPopup.isActive(); | |
2452 } | |
2453 | |
2454 /** | |
2455 * {@inheritDoc} | |
158 | 2456 * |
129 | 2457 * @since 3.4 |
2458 */ | |
2459 public final IHandler getHandler(String commandId) { | |
2460 if (fHandlers is null) | |
2461 throw new IllegalStateException(); | |
2462 | |
134 | 2463 IHandler handler= cast(IHandler)fHandlers.get(commandId); |
129 | 2464 if (handler !is null) |
2465 return handler; | |
158 | 2466 |
129 | 2467 Assert.isLegal(false); |
2468 return null; | |
2469 } | |
2470 | |
2471 /** | |
2472 * Registers the given handler under the given command identifier. | |
158 | 2473 * |
129 | 2474 * @param commandId the command identifier |
2475 * @param handler the handler | |
2476 * @since 3.4 | |
2477 */ | |
2478 protected final void registerHandler(String commandId, IHandler handler) { | |
2479 if (fHandlers is null) | |
2480 fHandlers= new HashMap(2); | |
2481 fHandlers.put(commandId, handler); | |
2482 } | |
2483 | |
2484 /** | |
2485 * Tells whether the support for colored labels is enabled. | |
158 | 2486 * |
129 | 2487 * @return <code>true</code> if the support for colored labels is enabled, <code>false</code> otherwise |
2488 * @since 3.4 | |
2489 */ | |
2490 bool isColoredLabelsSupportEnabled() { | |
2491 return fIsColoredLabelsSupportEnabled; | |
2492 } | |
2493 | |
2494 /** | |
2495 * Enables the support for colored labels in the proposal popup. | |
2496 * <p>Completion proposals can implement {@link ICompletionProposalExtension6} | |
2497 * to provide colored proposal labels.</p> | |
158 | 2498 * |
129 | 2499 * @param isEnabled if <code>true</code> the support for colored labels is enabled in the proposal popup |
2500 * @since 3.4 | |
2501 */ | |
2502 public void enableColoredLabels(bool isEnabled) { | |
2503 fIsColoredLabelsSupportEnabled= isEnabled; | |
2504 } | |
2505 | |
2506 } |