Mercurial > projects > dwt-addons
annotate dwtx/jface/text/contentassist/ContentAssistant.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | f70d9508c95c |
children | 1a5b8f8129df |
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 } | |
691 | |
692 /** | |
693 * Returns the display bounds for <code>shell</code> such that it appears right below | |
694 * <code>offset</code>, or above it if below is not suitable. The returned bounds lie | |
695 * within the monitor at the caret location and never overlap with the caret line. | |
158 | 696 * |
129 | 697 * @param shell the shell to compute the placement for |
698 * @param preferred the preferred size for <code>shell</code> | |
699 * @param offset the caret offset in the subject control | |
700 * @param popup a popup to inform if the location was switched to above, <code>null</code> to do nothing | |
701 * @return the point right below <code>offset</code> in display coordinates | |
702 * @since 3.3 | |
703 */ | |
704 protected Rectangle computeBoundsBelowAbove(Shell shell, Point preferred, int offset, CompletionProposalPopup popup) { | |
705 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); | |
706 Display display= subjectControl.getDisplay(); | |
707 Rectangle caret= getCaretRectangle(offset); | |
708 Monitor monitor= getClosestMonitor(display, caret); | |
709 Rectangle bounds= monitor.getClientArea(); | |
710 Geometry.moveInside(caret, bounds); | |
711 | |
712 int threshold= popup is null ? Integer.MAX_VALUE : popup.getMinimalHeight(); | |
713 int spaceAbove= caret.y - bounds.y; | |
714 int spaceBelow= bounds.y + bounds.height - (caret.y + caret.height); | |
715 Rectangle rect; | |
716 bool switched= false; | |
717 if (spaceBelow >= preferred.y) | |
718 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, preferred.y); | |
719 // squeeze in below if we have at least threshold space | |
720 else if (spaceBelow >= threshold) | |
721 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, spaceBelow); | |
722 else if (spaceAbove >= preferred.y) { | |
723 rect= new Rectangle(caret.x, caret.y - preferred.y, preferred.x, preferred.y); | |
724 switched= true; | |
725 } else if (spaceBelow >= spaceAbove) { | |
726 // we can't fit in the preferred size - squeeze into larger area | |
727 rect= new Rectangle(caret.x, caret.y + caret.height, preferred.x, spaceBelow); | |
728 } else { | |
729 rect= new Rectangle(caret.x, bounds.y, preferred.x, spaceAbove); | |
730 switched= true; | |
731 } | |
158 | 732 |
129 | 733 if (popup !is null) |
734 popup.switchedPositionToAbove(switched); | |
158 | 735 |
129 | 736 return constrainHorizontally(rect, bounds); |
737 } | |
738 | |
739 private Rectangle getCaretRectangle(int offset) { | |
740 Point location= fContentAssistSubjectControlAdapter.getLocationAtOffset(offset); | |
741 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); | |
742 Point controlSize= subjectControl.getSize(); | |
743 constrainLocation(location, new Point(0, 0), new Rectangle(0, 0, controlSize.x, controlSize.y)); | |
744 location= subjectControl.toDisplay(location); | |
745 Rectangle subjectRectangle= new Rectangle(location.x, location.y, 1, fContentAssistSubjectControlAdapter.getLineHeight()); | |
746 return subjectRectangle; | |
747 } | |
158 | 748 |
129 | 749 protected Point getStackedLocation(Shell shell, Shell parent) { |
750 Point p= parent.getLocation(); | |
751 Point size= parent.getSize(); | |
752 p.x += size.x / 4; | |
753 p.y += size.y; | |
754 | |
755 p= parent.toDisplay(p); | |
756 | |
757 Point shellSize= shell.getSize(); | |
758 Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0)); | |
759 Rectangle displayBounds= monitor.getClientArea(); | |
760 constrainLocation(p, shellSize, displayBounds); | |
761 | |
762 return p; | |
763 } | |
764 | |
765 protected void adjustListeners(int type) { | |
766 switch (type) { | |
767 case LAYOUT_PROPOSAL_SELECTOR: | |
768 if (fContextType is LAYOUT_CONTEXT_SELECTOR && | |
769 Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) | |
770 // Disable event notification to the tip selector. | |
134 | 771 removeContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR); |
129 | 772 break; |
773 case LAYOUT_CONTEXT_SELECTOR: | |
774 if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) | |
775 // Disable event notification to the proposal selector. | |
134 | 776 removeContentAssistListener(cast(IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR); |
129 | 777 break; |
778 case LAYOUT_CONTEXT_INFO_POPUP: | |
779 break; | |
780 } | |
781 } | |
158 | 782 |
129 | 783 /** |
784 * Copied from dwtx.jface.window.Window. | |
785 * Returns the monitor whose client area contains the given point. If no | |
786 * monitor contains the point, returns the monitor that is closest to the | |
787 * point. If this is ever made public, it should be moved into a separate | |
788 * utility class. | |
158 | 789 * |
129 | 790 * @param toSearch |
791 * point to find (display coordinates) | |
792 * @param rectangle | |
793 * rectangle to find (display coordinates) | |
794 * @return the monitor closest to the given point | |
795 * @since 3.3 | |
796 */ | |
797 private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) { | |
798 int closest = Integer.MAX_VALUE; | |
799 | |
800 Point toFind= Geometry.centerPoint(rectangle); | |
801 Monitor[] monitors = toSearch.getMonitors(); | |
802 Monitor result = monitors[0]; | |
803 | |
804 for (int idx = 0; idx < monitors.length; idx++) { | |
805 Monitor current = monitors[idx]; | |
806 | |
807 Rectangle clientArea = current.getClientArea(); | |
808 | |
809 if (clientArea.contains(toFind)) { | |
810 return current; | |
811 } | |
812 | |
813 int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind); | |
814 if (distance < closest) { | |
815 closest = distance; | |
816 result = current; | |
817 } | |
818 } | |
819 | |
820 return result; | |
821 } | |
822 } | |
823 | |
824 /** | |
825 * Internal key listener and event consumer. | |
826 */ | |
827 class InternalListener : VerifyKeyListener, IEventConsumer { | |
828 | |
829 /** | |
830 * Verifies key events by notifying the registered listeners. Each listener is allowed to | |
831 * indicate that the event has been handled and should not be further processed. | |
832 * | |
833 * @param e the verify event | |
834 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) | |
835 */ | |
836 public void verifyKey(VerifyEvent e) { | |
158 | 837 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); |
129 | 838 for (int i= 0; i < listeners.length; i++) { |
839 if (listeners[i] !is null) { | |
840 if (!listeners[i].verifyKey(e) || !e.doit) | |
841 break; | |
842 } | |
843 } | |
844 if (fAutoAssistListener !is null) | |
845 fAutoAssistListener.keyPressed(e); | |
846 } | |
847 | |
848 /* | |
849 * @see IEventConsumer#processEvent | |
850 */ | |
851 public void processEvent(VerifyEvent event) { | |
852 | |
853 installKeyListener(); | |
854 | |
158 | 855 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); |
129 | 856 for (int i= 0; i < listeners.length; i++) { |
857 if (listeners[i] !is null) { | |
858 listeners[i].processEvent(event); | |
859 if (!event.doit) | |
860 return; | |
861 } | |
862 } | |
863 } | |
864 } | |
865 | |
866 /** | |
867 * Dialog store constants. | |
868 * | |
869 * @since 3.0 | |
870 */ | |
147 | 871 public static const String STORE_SIZE_X= "size.x"; //$NON-NLS-1$ |
872 public static const String STORE_SIZE_Y= "size.y"; //$NON-NLS-1$ | |
129 | 873 |
874 // Content-Assist Listener types | |
875 final static int CONTEXT_SELECTOR= 0; | |
876 final static int PROPOSAL_SELECTOR= 1; | |
877 final static int CONTEXT_INFO_POPUP= 2; | |
878 | |
879 /** | |
880 * The popup priority: > linked position proposals and hover pop-ups. Default value: | |
881 * <code>20</code>; | |
882 * | |
883 * @since 3.0 | |
884 */ | |
147 | 885 public static const int WIDGET_PRIORITY= 20; |
129 | 886 |
147 | 887 private static const int DEFAULT_AUTO_ACTIVATION_DELAY= 500; |
129 | 888 |
889 private IInformationControlCreator fInformationControlCreator; | |
890 private int fAutoActivationDelay= DEFAULT_AUTO_ACTIVATION_DELAY; | |
891 private bool fIsAutoActivated= false; | |
892 private bool fIsAutoInserting= false; | |
893 private int fProposalPopupOrientation= PROPOSAL_OVERLAY; | |
894 private int fContextInfoPopupOrientation= CONTEXT_INFO_ABOVE; | |
895 private Map fProcessors; | |
896 | |
897 /** | |
898 * The partitioning. | |
899 * | |
900 * @since 3.0 | |
901 */ | |
902 private String fPartitioning; | |
903 | |
904 private Color fContextInfoPopupBackground; | |
905 private Color fContextInfoPopupForeground; | |
906 private Color fContextSelectorBackground; | |
907 private Color fContextSelectorForeground; | |
908 private Color fProposalSelectorBackground; | |
909 private Color fProposalSelectorForeground; | |
910 | |
911 private ITextViewer fViewer; | |
912 private String fLastErrorMessage; | |
913 | |
914 private Closer fCloser; | |
915 LayoutManager fLayoutManager; | |
916 private AutoAssistListener fAutoAssistListener; | |
917 private InternalListener fInternalListener; | |
918 private CompletionProposalPopup fProposalPopup; | |
919 private ContextInformationPopup fContextInfoPopup; | |
920 | |
921 /** | |
922 * Flag which tells whether a verify key listener is hooked. | |
923 * | |
924 * @since 3.0 | |
925 */ | |
926 private bool fVerifyKeyListenerHooked= false; | |
927 private IContentAssistListener[] fListeners= new IContentAssistListener[4]; | |
928 /** | |
929 * The content assist subject control. | |
930 * | |
931 * @since 3.0 | |
932 */ | |
933 private IContentAssistSubjectControl fContentAssistSubjectControl; | |
934 /** | |
935 * The content assist subject control's shell. | |
936 * | |
937 * @since 3.2 | |
938 */ | |
939 private Shell fContentAssistSubjectControlShell; | |
940 /** | |
941 * The content assist subject control's shell traverse listener. | |
942 * | |
943 * @since 3.2 | |
944 */ | |
945 private TraverseListener fCASCSTraverseListener; | |
946 /** | |
947 * The content assist subject control adapter. | |
948 * | |
949 * @since 3.0 | |
950 */ | |
951 private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter; | |
952 /** | |
953 * The dialog settings for the control's bounds. | |
954 * | |
955 * @since 3.0 | |
956 */ | |
957 private IDialogSettings fDialogSettings; | |
958 /** | |
959 * Prefix completion setting. | |
960 * | |
961 * @since 3.0 | |
962 */ | |
963 private bool fIsPrefixCompletionEnabled= false; | |
964 /** | |
965 * The list of completion listeners. | |
966 * | |
967 * @since 3.2 | |
968 */ | |
969 private ListenerList fCompletionListeners= new ListenerList(ListenerList.IDENTITY); | |
970 /** | |
971 * The message to display at the bottom of the proposal popup. | |
972 * | |
973 * @since 3.2 | |
974 */ | |
975 private String fMessage= ""; //$NON-NLS-1$ | |
976 /** | |
977 * The cycling mode property. | |
978 * | |
979 * @since 3.2 | |
980 */ | |
981 private bool fIsRepetitionMode= false; | |
982 /** | |
983 * The show empty property. | |
984 * | |
985 * @since 3.2 | |
986 */ | |
987 private bool fShowEmptyList= false; | |
988 /** | |
989 * The message line property. | |
990 * | |
991 * @since 3.2 | |
992 */ | |
993 private bool fIsStatusLineVisible; | |
994 /** | |
995 * The last system time when auto activation performed. | |
158 | 996 * |
129 | 997 * @since 3.2 |
998 */ | |
999 private long fLastAutoActivation= Long.MIN_VALUE; | |
1000 /** | |
1001 * The iteration key sequence to listen for, or <code>null</code>. | |
1002 * | |
1003 * @since 3.2 | |
1004 */ | |
1005 private KeySequence fRepeatedInvocationKeySequence; | |
158 | 1006 |
129 | 1007 /** |
1008 * Maps handler to command identifiers. | |
158 | 1009 * |
129 | 1010 * @since 3.4 |
1011 */ | |
1012 private Map fHandlers; | |
158 | 1013 |
129 | 1014 /** |
1015 * Tells whether colored labels support is enabled. | |
158 | 1016 * |
129 | 1017 * @since 3.4 |
1018 */ | |
1019 private bool fIsColoredLabelsSupportEnabled= false; | |
1020 | |
1021 | |
1022 /** | |
1023 * Creates a new content assistant. The content assistant is not automatically activated, | |
1024 * overlays the completion proposals with context information list if necessary, and shows the | |
1025 * context information above the location at which it was activated. If auto activation will be | |
1026 * enabled, without further configuration steps, this content assistant is activated after a 500 | |
1027 * milliseconds delay. It uses the default partitioning. | |
1028 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
1029 public this() { |
129 | 1030 fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING; |
1031 } | |
1032 | |
1033 /** | |
1034 * Sets the document partitioning this content assistant is using. | |
1035 * | |
1036 * @param partitioning the document partitioning for this content assistant | |
1037 * @since 3.0 | |
1038 */ | |
1039 public void setDocumentPartitioning(String partitioning) { | |
1040 Assert.isNotNull(partitioning); | |
1041 fPartitioning= partitioning; | |
1042 } | |
1043 | |
1044 /* | |
1045 * @see dwtx.jface.text.contentassist.IContentAssistantExtension#getDocumentPartitioning() | |
1046 * @since 3.0 | |
1047 */ | |
1048 public String getDocumentPartitioning() { | |
1049 return fPartitioning; | |
1050 } | |
1051 | |
1052 /** | |
1053 * Registers a given content assist processor for a particular content type. If there is already | |
1054 * a processor registered for this type, the new processor is registered instead of the old one. | |
1055 * | |
1056 * @param processor the content assist processor to register, or <code>null</code> to remove | |
1057 * an existing one | |
1058 * @param contentType the content type under which to register | |
1059 */ | |
1060 public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType) { | |
1061 | |
1062 Assert.isNotNull(contentType); | |
1063 | |
1064 if (fProcessors is null) | |
1065 fProcessors= new HashMap(); | |
1066 | |
1067 if (processor is null) | |
1068 fProcessors.remove(contentType); | |
1069 else | |
1070 fProcessors.put(contentType, processor); | |
1071 } | |
1072 | |
1073 /* | |
1074 * @see IContentAssistant#getContentAssistProcessor | |
1075 */ | |
1076 public IContentAssistProcessor getContentAssistProcessor(String contentType) { | |
1077 if (fProcessors is null) | |
1078 return null; | |
1079 | |
134 | 1080 return cast(IContentAssistProcessor) fProcessors.get(contentType); |
129 | 1081 } |
1082 | |
1083 /** | |
1084 * Computes the sorted set of all auto activation trigger characters. | |
1085 * | |
1086 * @return the sorted set of all auto activation trigger characters | |
1087 * @since 3.1 | |
1088 */ | |
1089 private String computeAllAutoActivationTriggers() { | |
1090 if (fProcessors is null) | |
1091 return ""; //$NON-NLS-1$ | |
1092 | |
1093 StringBuffer buf= new StringBuffer(5); | |
1094 Iterator iter= fProcessors.entrySet().iterator(); | |
1095 while (iter.hasNext()) { | |
134 | 1096 Entry entry= cast(Entry) iter.next(); |
1097 IContentAssistProcessor processor= cast(IContentAssistProcessor) entry.getValue(); | |
129 | 1098 char[] triggers= processor.getCompletionProposalAutoActivationCharacters(); |
1099 if (triggers !is null) | |
1100 buf.append(triggers); | |
1101 triggers= processor.getContextInformationAutoActivationCharacters(); | |
1102 if (triggers !is null) | |
1103 buf.append(triggers); | |
1104 } | |
1105 return buf.toString(); | |
1106 } | |
1107 | |
1108 /** | |
1109 * Enables the content assistant's auto activation mode. | |
1110 * | |
1111 * @param enabled indicates whether auto activation is enabled or not | |
1112 */ | |
1113 public void enableAutoActivation(bool enabled) { | |
1114 fIsAutoActivated= enabled; | |
1115 manageAutoActivation(fIsAutoActivated); | |
1116 } | |
1117 | |
1118 /** | |
1119 * Enables the content assistant's auto insertion mode. If enabled, the content assistant | |
1120 * inserts a proposal automatically if it is the only proposal. In the case of ambiguities, the | |
1121 * user must make the choice. | |
1122 * | |
1123 * @param enabled indicates whether auto insertion is enabled or not | |
1124 * @since 2.0 | |
1125 */ | |
1126 public void enableAutoInsert(bool enabled) { | |
1127 fIsAutoInserting= enabled; | |
1128 } | |
1129 | |
1130 /** | |
1131 * Returns whether this content assistant is in the auto insertion mode or not. | |
1132 * | |
1133 * @return <code>true</code> if in auto insertion mode | |
1134 * @since 2.0 | |
1135 */ | |
1136 bool isAutoInserting() { | |
1137 return fIsAutoInserting; | |
1138 } | |
1139 | |
1140 /** | |
1141 * Installs and uninstall the listeners needed for auto activation. | |
1142 * | |
1143 * @param start <code>true</code> if listeners must be installed, <code>false</code> if they | |
1144 * must be removed | |
1145 * @since 2.0 | |
1146 */ | |
1147 private void manageAutoActivation(bool start) { | |
1148 if (start) { | |
1149 | |
1150 if ((fContentAssistSubjectControlAdapter !is null) && fAutoAssistListener is null) { | |
1151 fAutoAssistListener= createAutoAssistListener(); | |
1152 // For details see https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 | |
1153 if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) | |
1154 fContentAssistSubjectControlAdapter.appendVerifyKeyListener(fAutoAssistListener); | |
1155 else | |
1156 fContentAssistSubjectControlAdapter.addKeyListener(fAutoAssistListener); | |
1157 } | |
1158 | |
1159 } else if (fAutoAssistListener !is null) { | |
1160 // For details see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=49212 | |
1161 if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener()) | |
1162 fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fAutoAssistListener); | |
1163 else | |
1164 fContentAssistSubjectControlAdapter.removeKeyListener(fAutoAssistListener); | |
1165 fAutoAssistListener= null; | |
1166 } | |
1167 } | |
1168 | |
1169 /** | |
1170 * This method allows subclasses to provide their own {@link AutoAssistListener}. | |
158 | 1171 * |
129 | 1172 * @return a new auto assist listener |
1173 * @since 3.4 | |
1174 */ | |
1175 protected AutoAssistListener createAutoAssistListener() { | |
1176 return new AutoAssistListener(); | |
1177 } | |
1178 | |
1179 /** | |
1180 * Sets the delay after which the content assistant is automatically invoked if the cursor is | |
1181 * behind an auto activation character. | |
1182 * | |
1183 * @param delay the auto activation delay | |
1184 */ | |
1185 public void setAutoActivationDelay(int delay) { | |
1186 fAutoActivationDelay= delay; | |
1187 } | |
1188 | |
1189 /** | |
1190 * Gets the delay after which the content assistant is automatically invoked if the cursor is | |
1191 * behind an auto activation character. | |
158 | 1192 * |
129 | 1193 * @return the auto activation delay |
1194 * @since 3.4 | |
1195 */ | |
1196 public int getAutoActivationDelay() { | |
1197 return fAutoActivationDelay; | |
1198 } | |
1199 | |
1200 /** | |
1201 * Sets the proposal pop-ups' orientation. The following values may be used: | |
1202 * <ul> | |
1203 * <li>PROPOSAL_OVERLAY<p> | |
1204 * proposal popup windows should overlay each other | |
1205 * </li> | |
1206 * <li>PROPOSAL_REMOVE<p> | |
1207 * any currently shown proposal popup should be closed | |
1208 * </li> | |
1209 * <li>PROPOSAL_STACKED<p> | |
1210 * proposal popup windows should be vertical stacked, with no overlap, | |
1211 * beneath the line containing the current cursor location | |
1212 * </li> | |
1213 * </ul> | |
1214 * | |
1215 * @param orientation the popup's orientation | |
1216 */ | |
1217 public void setProposalPopupOrientation(int orientation) { | |
1218 fProposalPopupOrientation= orientation; | |
1219 } | |
1220 | |
1221 /** | |
1222 * Sets the context information popup's orientation. | |
1223 * The following values may be used: | |
1224 * <ul> | |
1225 * <li>CONTEXT_ABOVE<p> | |
1226 * context information popup should always appear above the line containing | |
1227 * the current cursor location | |
1228 * </li> | |
1229 * <li>CONTEXT_BELOW<p> | |
1230 * context information popup should always appear below the line containing | |
1231 * the current cursor location | |
1232 * </li> | |
1233 * </ul> | |
1234 * | |
1235 * @param orientation the popup's orientation | |
1236 */ | |
1237 public void setContextInformationPopupOrientation(int orientation) { | |
1238 fContextInfoPopupOrientation= orientation; | |
1239 } | |
1240 | |
1241 /** | |
1242 * Sets the context information popup's background color. | |
1243 * | |
1244 * @param background the background color | |
1245 */ | |
1246 public void setContextInformationPopupBackground(Color background) { | |
1247 fContextInfoPopupBackground= background; | |
1248 } | |
1249 | |
1250 /** | |
1251 * Returns the background of the context information popup. | |
1252 * | |
1253 * @return the background of the context information popup | |
1254 * @since 2.0 | |
1255 */ | |
1256 Color getContextInformationPopupBackground() { | |
1257 return fContextInfoPopupBackground; | |
1258 } | |
1259 | |
1260 /** | |
1261 * Sets the context information popup's foreground color. | |
1262 * | |
1263 * @param foreground the foreground color | |
1264 * @since 2.0 | |
1265 */ | |
1266 public void setContextInformationPopupForeground(Color foreground) { | |
1267 fContextInfoPopupForeground= foreground; | |
1268 } | |
1269 | |
1270 /** | |
1271 * Returns the foreground of the context information popup. | |
158 | 1272 * |
129 | 1273 * |
1274 * @return the foreground of the context information popup | |
1275 * @since 2.0 | |
1276 */ | |
1277 Color getContextInformationPopupForeground() { | |
1278 return fContextInfoPopupForeground; | |
1279 } | |
1280 | |
1281 /** | |
1282 * Sets the proposal selector's background color. | |
1283 * <p> | |
1284 * <strong>Note:</strong> As of 3.4, you should only call this | |
1285 * method if you want to override the {@link JFacePreferences#CONTENT_ASSIST_BACKGROUND_COLOR}. | |
1286 * </p> | |
1287 * | |
1288 * @param background the background color | |
1289 * @since 2.0 | |
1290 */ | |
1291 public void setProposalSelectorBackground(Color background) { | |
1292 fProposalSelectorBackground= background; | |
1293 } | |
1294 | |
1295 /** | |
1296 * Returns the custom background color of the proposal selector. | |
1297 * | |
1298 * @return the background of the proposal selector or <code>null</code> if not set | |
1299 * @since 2.0 | |
1300 */ | |
1301 Color getProposalSelectorBackground() { | |
1302 return fProposalSelectorBackground; | |
1303 } | |
1304 | |
1305 /** | |
1306 * Sets the proposal's foreground color. | |
1307 * <p> | |
1308 * <strong>Note:</strong> As of 3.4, you should only call this | |
1309 * method if you want to override the {@link JFacePreferences#CONTENT_ASSIST_FOREGROUND_COLOR}. | |
1310 * </p> | |
1311 * | |
1312 * @param foreground the foreground color | |
1313 * @since 2.0 | |
1314 */ | |
1315 public void setProposalSelectorForeground(Color foreground) { | |
1316 fProposalSelectorForeground= foreground; | |
1317 } | |
1318 | |
1319 /** | |
1320 * Returns the custom foreground color of the proposal selector. | |
1321 * | |
1322 * @return the foreground of the proposal selector or <code>null</code> if not set | |
1323 * @since 2.0 | |
1324 */ | |
1325 Color getProposalSelectorForeground() { | |
1326 return fProposalSelectorForeground; | |
1327 } | |
1328 | |
1329 /** | |
1330 * Sets the context selector's background color. | |
1331 * | |
1332 * @param background the background color | |
1333 * @since 2.0 | |
1334 */ | |
1335 public void setContextSelectorBackground(Color background) { | |
1336 fContextSelectorBackground= background; | |
1337 } | |
1338 | |
1339 /** | |
1340 * Returns the background of the context selector. | |
1341 * | |
1342 * @return the background of the context selector | |
1343 * @since 2.0 | |
1344 */ | |
1345 Color getContextSelectorBackground() { | |
1346 return fContextSelectorBackground; | |
1347 } | |
1348 | |
1349 /** | |
1350 * Sets the context selector's foreground color. | |
1351 * | |
1352 * @param foreground the foreground color | |
1353 * @since 2.0 | |
1354 */ | |
1355 public void setContextSelectorForeground(Color foreground) { | |
1356 fContextSelectorForeground= foreground; | |
1357 } | |
1358 | |
1359 /** | |
1360 * Returns the foreground of the context selector. | |
1361 * | |
1362 * @return the foreground of the context selector | |
1363 * @since 2.0 | |
1364 */ | |
1365 Color getContextSelectorForeground() { | |
1366 return fContextSelectorForeground; | |
1367 } | |
1368 | |
1369 /** | |
1370 * Sets the information control creator for the additional information control. | |
1371 * | |
1372 * @param creator the information control creator for the additional information control | |
1373 * @since 2.0 | |
1374 */ | |
1375 public void setInformationControlCreator(IInformationControlCreator creator) { | |
1376 fInformationControlCreator= creator; | |
1377 } | |
1378 | |
1379 /* | |
1380 * @see IControlContentAssistant#install(IContentAssistSubjectControl) | |
1381 * @since 3.0 | |
1382 */ | |
1383 protected void install(IContentAssistSubjectControl contentAssistSubjectControl) { | |
1384 fContentAssistSubjectControl= contentAssistSubjectControl; | |
1385 fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl); | |
1386 install(); | |
1387 } | |
1388 | |
1389 /* | |
1390 * @see IContentAssist#install | |
1391 * @since 3.0 | |
1392 */ | |
1393 public void install(ITextViewer textViewer) { | |
1394 fViewer= textViewer; | |
1395 fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fViewer); | |
1396 install(); | |
1397 } | |
1398 | |
1399 protected void install() { | |
1400 | |
1401 fLayoutManager= new LayoutManager(); | |
1402 fInternalListener= new InternalListener(); | |
1403 | |
1404 AdditionalInfoController controller= null; | |
1405 if (fInformationControlCreator !is null) { | |
1406 int delay= fAutoActivationDelay; | |
1407 if (delay is 0) | |
1408 delay= DEFAULT_AUTO_ACTIVATION_DELAY; | |
1409 delay= Math.round(delay * 1.5f); | |
1410 controller= new AdditionalInfoController(fInformationControlCreator, delay); | |
1411 } | |
1412 | |
1413 fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this); | |
1414 fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller); | |
1415 | |
1416 registerHandler(SELECT_NEXT_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_NEXT)); | |
1417 registerHandler(SELECT_PREVIOUS_PROPOSAL_COMMAND_ID, fProposalPopup.createProposalSelectionHandler(CompletionProposalPopup.ProposalSelectionHandler.SELECT_PREVIOUS)); | |
1418 | |
1419 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) { | |
1420 fContentAssistSubjectControlShell= fContentAssistSubjectControlAdapter.getControl().getShell(); | |
135 | 1421 fCASCSTraverseListener= new class() TraverseListener { |
129 | 1422 public void keyTraversed(TraverseEvent e) { |
1423 if (e.detail is DWT.TRAVERSE_ESCAPE && isProposalPopupActive()) | |
1424 e.doit= false; | |
1425 } | |
1426 }; | |
1427 fContentAssistSubjectControlShell.addTraverseListener(fCASCSTraverseListener); | |
1428 } | |
1429 | |
1430 manageAutoActivation(fIsAutoActivated); | |
1431 } | |
1432 | |
1433 /* | |
1434 * @see IContentAssist#uninstall | |
1435 */ | |
1436 public void uninstall() { | |
1437 hide(); | |
1438 manageAutoActivation(false); | |
158 | 1439 |
129 | 1440 if (fHandlers !is null) { |
1441 fHandlers.clear(); | |
1442 fHandlers= null; | |
1443 } | |
1444 | |
1445 if (fCloser !is null) { | |
1446 fCloser.uninstall(); | |
1447 fCloser= null; | |
1448 } | |
1449 | |
1450 if (Helper.okToUse(fContentAssistSubjectControlShell)) | |
1451 fContentAssistSubjectControlShell.removeTraverseListener(fCASCSTraverseListener); | |
1452 fCASCSTraverseListener= null; | |
1453 fContentAssistSubjectControlShell= null; | |
1454 | |
1455 fViewer= null; | |
1456 fContentAssistSubjectControl= null; | |
1457 fContentAssistSubjectControlAdapter= null; | |
1458 } | |
1459 | |
1460 /** | |
1461 * Adds the given shell of the specified type to the layout. Valid types are defined by | |
1462 * <code>LayoutManager</code>. | |
1463 * | |
1464 * @param popup a content assist popup | |
1465 * @param shell the shell of the content-assist popup | |
1466 * @param type the type of popup | |
1467 * @param visibleOffset the offset at which to layout the popup relative to the offset of the | |
1468 * viewer's visible region | |
1469 * @since 2.0 | |
1470 */ | |
1471 void addToLayout(Object popup, Shell shell, int type, int visibleOffset) { | |
1472 fLayoutManager.add(popup, shell, type, visibleOffset); | |
1473 } | |
1474 | |
1475 /** | |
1476 * Layouts the registered popup of the given type relative to the given offset. The offset is | |
1477 * relative to the offset of the viewer's visible region. Valid types are defined by | |
1478 * <code>LayoutManager</code>. | |
1479 * | |
1480 * @param type the type of popup to layout | |
1481 * @param visibleOffset the offset at which to layout relative to the offset of the viewer's | |
1482 * visible region | |
1483 * @since 2.0 | |
1484 */ | |
1485 void layout(int type, int visibleOffset) { | |
1486 fLayoutManager.layout(type, visibleOffset); | |
1487 } | |
158 | 1488 |
129 | 1489 /** |
1490 * Returns the layout manager. | |
158 | 1491 * |
129 | 1492 * @return the layout manager |
1493 * @since 3.3 | |
1494 */ | |
1495 LayoutManager getLayoutManager() { | |
1496 return fLayoutManager; | |
1497 } | |
1498 | |
1499 /** | |
1500 * Notifies the controller that a popup has lost focus. | |
1501 * | |
1502 * @param e the focus event | |
1503 */ | |
1504 void popupFocusLost(FocusEvent e) { | |
1505 fCloser.focusLost(e); | |
1506 } | |
1507 | |
1508 /** | |
1509 * Returns the offset of the selection relative to the offset of the visible region. | |
1510 * | |
1511 * @return the offset of the selection relative to the offset of the visible region | |
1512 * @since 2.0 | |
1513 */ | |
1514 int getSelectionOffset() { | |
1515 return fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x; | |
1516 } | |
1517 | |
1518 /** | |
1519 * Returns whether the widget token could be acquired. The following are valid listener types: | |
1520 * <ul> | |
1521 * <li>AUTO_ASSIST</li> | |
1522 * <li>CONTEXT_SELECTOR</li> | |
1523 * <li>PROPOSAL_SELECTOR</li> | |
1524 * <li>CONTEXT_INFO_POPUP</li> | |
1525 * </ul> | |
1526 * | |
1527 * @param type the listener type for which to acquire | |
1528 * @return <code>true</code> if the widget token could be acquired | |
1529 * @since 2.0 | |
1530 */ | |
1531 private bool acquireWidgetToken(int type) { | |
1532 switch (type) { | |
1533 case CONTEXT_SELECTOR: | |
1534 case PROPOSAL_SELECTOR: | |
138 | 1535 if ( cast(IWidgetTokenOwnerExtension)fContentAssistSubjectControl ) { |
134 | 1536 IWidgetTokenOwnerExtension extension= cast(IWidgetTokenOwnerExtension) fContentAssistSubjectControl; |
129 | 1537 return extension.requestWidgetToken(this, WIDGET_PRIORITY); |
138 | 1538 } else if ( cast(IWidgetTokenOwner)fContentAssistSubjectControl ) { |
134 | 1539 IWidgetTokenOwner owner= cast(IWidgetTokenOwner) fContentAssistSubjectControl; |
129 | 1540 return owner.requestWidgetToken(this); |
138 | 1541 } else if ( cast(IWidgetTokenOwnerExtension)fViewer ) { |
134 | 1542 IWidgetTokenOwnerExtension extension= cast(IWidgetTokenOwnerExtension) fViewer; |
129 | 1543 return extension.requestWidgetToken(this, WIDGET_PRIORITY); |
138 | 1544 } else if ( cast(IWidgetTokenOwner)fViewer ) { |
134 | 1545 IWidgetTokenOwner owner= cast(IWidgetTokenOwner) fViewer; |
129 | 1546 return owner.requestWidgetToken(this); |
1547 } | |
1548 } | |
1549 return true; | |
1550 } | |
1551 | |
1552 /** | |
1553 * Registers a content assist listener. The following are valid listener types: | |
1554 * <ul> | |
1555 * <li>AUTO_ASSIST</li> | |
1556 * <li>CONTEXT_SELECTOR</li> | |
1557 * <li>PROPOSAL_SELECTOR</li> | |
1558 * <li>CONTEXT_INFO_POPUP</li> | |
1559 * </ul> | |
1560 * Returns whether the listener could be added successfully. A listener can not be added if the | |
1561 * widget token could not be acquired. | |
1562 * | |
1563 * @param listener the listener to register | |
1564 * @param type the type of listener | |
1565 * @return <code>true</code> if the listener could be added | |
1566 */ | |
1567 bool addContentAssistListener(IContentAssistListener listener, int type) { | |
1568 | |
1569 if (acquireWidgetToken(type)) { | |
1570 | |
1571 fListeners[type]= listener; | |
1572 | |
1573 if (fCloser is null && getNumberOfListeners() is 1) { | |
1574 fCloser= new Closer(); | |
1575 fCloser.install(); | |
1576 fContentAssistSubjectControlAdapter.setEventConsumer(fInternalListener); | |
1577 installKeyListener(); | |
1578 } else | |
1579 promoteKeyListener(); | |
1580 return true; | |
1581 } | |
1582 | |
1583 return false; | |
1584 } | |
1585 | |
1586 /** | |
1587 * Re-promotes the key listener to the first position, using prependVerifyKeyListener. This | |
1588 * ensures no other instance is filtering away the keystrokes underneath, if we've been up for a | |
1589 * while (e.g. when the context info is showing. | |
1590 * | |
1591 * @since 3.0 | |
1592 */ | |
1593 private void promoteKeyListener() { | |
1594 uninstallVerifyKeyListener(); | |
1595 installKeyListener(); | |
1596 } | |
1597 | |
1598 /** | |
1599 * Installs a key listener on the text viewer's widget. | |
1600 */ | |
1601 private void installKeyListener() { | |
1602 if (!fVerifyKeyListenerHooked) { | |
1603 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) { | |
1604 fVerifyKeyListenerHooked= fContentAssistSubjectControlAdapter.prependVerifyKeyListener(fInternalListener); | |
1605 } | |
1606 } | |
1607 } | |
1608 | |
1609 /** | |
1610 * Releases the previously acquired widget token if the token is no longer necessary. The | |
1611 * following are valid listener types: | |
1612 * <ul> | |
1613 * <li>AUTO_ASSIST</li> | |
1614 * <li>CONTEXT_SELECTOR</li> | |
1615 * <li>PROPOSAL_SELECTOR</li> | |
1616 * <li>CONTEXT_INFO_POPUP</li> | |
1617 * </ul> | |
1618 * | |
1619 * @param type the listener type | |
1620 * @since 2.0 | |
1621 */ | |
1622 private void releaseWidgetToken(int type) { | |
1623 if (fListeners[CONTEXT_SELECTOR] is null && fListeners[PROPOSAL_SELECTOR] is null) { | |
1624 IWidgetTokenOwner owner= null; | |
138 | 1625 if ( cast(IWidgetTokenOwner)fContentAssistSubjectControl ) |
134 | 1626 owner= cast(IWidgetTokenOwner) fContentAssistSubjectControl; |
138 | 1627 else if ( cast(IWidgetTokenOwner)fViewer ) |
134 | 1628 owner= cast(IWidgetTokenOwner) fViewer; |
129 | 1629 if (owner !is null) |
1630 owner.releaseWidgetToken(this); | |
1631 } | |
1632 } | |
1633 | |
1634 /** | |
1635 * Unregisters a content assist listener. | |
1636 * | |
1637 * @param listener the listener to unregister | |
1638 * @param type the type of listener | |
1639 * @see #addContentAssistListener(IContentAssistListener, int) | |
1640 */ | |
1641 void removeContentAssistListener(IContentAssistListener listener, int type) { | |
1642 fListeners[type]= null; | |
1643 | |
1644 if (getNumberOfListeners() is 0) { | |
1645 | |
1646 if (fCloser !is null) { | |
1647 fCloser.uninstall(); | |
1648 fCloser= null; | |
1649 } | |
1650 | |
1651 uninstallVerifyKeyListener(); | |
1652 fContentAssistSubjectControlAdapter.setEventConsumer(null); | |
1653 } | |
1654 | |
1655 releaseWidgetToken(type); | |
1656 } | |
1657 | |
1658 /** | |
1659 * Uninstall the key listener from the text viewer's widget. | |
1660 * | |
1661 * @since 3.0 | |
1662 */ | |
1663 private void uninstallVerifyKeyListener() { | |
1664 if (fVerifyKeyListenerHooked) { | |
1665 if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) | |
1666 fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fInternalListener); | |
1667 fVerifyKeyListenerHooked= false; | |
1668 } | |
1669 } | |
1670 | |
1671 /** | |
1672 * Returns the number of listeners. | |
1673 * | |
1674 * @return the number of listeners | |
1675 * @since 2.0 | |
1676 */ | |
1677 private int getNumberOfListeners() { | |
1678 int count= 0; | |
1679 for (int i= 0; i <= CONTEXT_INFO_POPUP; i++) { | |
1680 if (fListeners[i] !is null) | |
1681 ++count; | |
1682 } | |
1683 return count; | |
1684 } | |
1685 | |
1686 /* | |
1687 * @see IContentAssist#showPossibleCompletions | |
1688 */ | |
1689 public String showPossibleCompletions() { | |
1690 if (!prepareToShowCompletions(false)) | |
1691 return null; | |
1692 if (fIsPrefixCompletionEnabled) | |
1693 return fProposalPopup.incrementalComplete(); | |
1694 return fProposalPopup.showProposals(false); | |
1695 } | |
1696 | |
1697 /* | |
1698 * @see dwtx.jface.text.contentassist.IContentAssistantExtension#completePrefix() | |
1699 * @since 3.0 | |
1700 */ | |
1701 public String completePrefix() { | |
1702 if (!prepareToShowCompletions(false)) | |
1703 return null; | |
1704 return fProposalPopup.incrementalComplete(); | |
1705 } | |
1706 | |
1707 /** | |
1708 * Prepares to show content assist proposals. It returns false if auto activation has kicked in | |
1709 * recently. | |
158 | 1710 * |
129 | 1711 * @param isAutoActivated whether completion was triggered by auto activation |
1712 * @return <code>true</code> if the caller should continue and show the proposals, | |
1713 * <code>false</code> otherwise. | |
1714 * @since 3.2 | |
1715 */ | |
1716 private bool prepareToShowCompletions(bool isAutoActivated) { | |
1717 long current= System.currentTimeMillis(); | |
1718 int gracePeriod= Math.max(fAutoActivationDelay, 200); | |
1719 if (current < fLastAutoActivation + gracePeriod) | |
1720 return false; | |
158 | 1721 |
129 | 1722 promoteKeyListener(); |
1723 fireSessionBeginEvent(isAutoActivated); | |
1724 return true; | |
1725 } | |
1726 | |
1727 /** | |
1728 * Callback to signal this content assistant that the presentation of the possible completions | |
1729 * has been stopped. | |
1730 * | |
1731 * @since 2.1 | |
1732 */ | |
1733 protected void possibleCompletionsClosed() { | |
1734 fLastAutoActivation= Long.MIN_VALUE; | |
1735 storeCompletionProposalPopupSize(); | |
1736 } | |
1737 | |
1738 /* | |
1739 * @see IContentAssist#showContextInformation | |
1740 */ | |
1741 public String showContextInformation() { | |
1742 promoteKeyListener(); | |
1743 if (fContextInfoPopup !is null) | |
1744 return fContextInfoPopup.showContextProposals(false); | |
1745 return null; | |
1746 } | |
1747 | |
1748 /** | |
1749 * Callback to signal this content assistant that the presentation of the context information | |
1750 * has been stopped. | |
1751 * | |
1752 * @since 2.1 | |
1753 */ | |
1754 protected void contextInformationClosed() { | |
1755 } | |
1756 | |
1757 /** | |
1758 * Requests that the specified context information to be shown. | |
1759 * | |
1760 * @param contextInformation the context information to be shown | |
1761 * @param offset the offset to which the context information refers to | |
1762 * @since 2.0 | |
1763 */ | |
1764 void showContextInformation(IContextInformation contextInformation, int offset) { | |
1765 if (fContextInfoPopup !is null) | |
1766 fContextInfoPopup.showContextInformation(contextInformation, offset); | |
1767 } | |
1768 | |
1769 /** | |
1770 * Returns the current content assist error message. | |
1771 * | |
1772 * @return an error message or <code>null</code> if no error has occurred | |
1773 */ | |
1774 String getErrorMessage() { | |
1775 return fLastErrorMessage; | |
1776 } | |
1777 | |
1778 /** | |
1779 * Returns the content assist processor for the content type of the specified document position. | |
1780 * | |
1781 * @param viewer the text viewer | |
1782 * @param offset a offset within the document | |
1783 * @return a content-assist processor or <code>null</code> if none exists | |
1784 * @since 3.0 | |
1785 */ | |
1786 private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) { | |
1787 try { | |
1788 | |
1789 IDocument document= viewer.getDocument(); | |
1790 String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); | |
1791 | |
1792 return getContentAssistProcessor(type); | |
1793 | |
1794 } catch (BadLocationException x) { | |
1795 } | |
1796 | |
1797 return null; | |
1798 } | |
1799 | |
1800 /** | |
1801 * Returns the content assist processor for the content type of the specified document position. | |
1802 * | |
1803 * @param contentAssistSubjectControl the content assist subject control | |
1804 * @param offset a offset within the document | |
1805 * @return a content-assist processor or <code>null</code> if none exists | |
1806 * @since 3.0 | |
1807 */ | |
1808 private IContentAssistProcessor getProcessor(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1809 try { | |
1810 | |
1811 IDocument document= contentAssistSubjectControl.getDocument(); | |
1812 String type; | |
1813 if (document !is null) | |
1814 type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true); | |
1815 else | |
1816 type= IDocument.DEFAULT_CONTENT_TYPE; | |
1817 | |
1818 return getContentAssistProcessor(type); | |
1819 | |
1820 } catch (BadLocationException x) { | |
1821 } | |
1822 | |
1823 return null; | |
1824 } | |
1825 | |
1826 /** | |
1827 * Returns an array of completion proposals computed based on the specified document position. | |
1828 * The position is used to determine the appropriate content assist processor to invoke. | |
1829 * | |
1830 * @param contentAssistSubjectControl the content assist subject control | |
1831 * @param offset a document offset | |
1832 * @return an array of completion proposals | |
1833 * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) | |
1834 * @since 3.0 | |
1835 */ | |
1836 ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1837 fLastErrorMessage= null; | |
1838 | |
1839 ICompletionProposal[] result= null; | |
1840 | |
1841 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
138 | 1842 if ( cast(ISubjectControlContentAssistProcessor)p ) { |
134 | 1843 result= (cast(ISubjectControlContentAssistProcessor) p).computeCompletionProposals(contentAssistSubjectControl, offset); |
129 | 1844 fLastErrorMessage= p.getErrorMessage(); |
1845 } | |
1846 | |
1847 return result; | |
1848 } | |
1849 | |
1850 /** | |
1851 * Returns an array of completion proposals computed based on the specified document position. | |
1852 * The position is used to determine the appropriate content assist processor to invoke. | |
1853 * | |
1854 * @param viewer the viewer for which to compute the proposals | |
1855 * @param offset a document offset | |
1856 * @return an array of completion proposals or <code>null</code> if no proposals are possible | |
1857 * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int) | |
1858 */ | |
1859 ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { | |
1860 fLastErrorMessage= null; | |
1861 | |
1862 ICompletionProposal[] result= null; | |
1863 | |
1864 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1865 if (p !is null) { | |
1866 result= p.computeCompletionProposals(viewer, offset); | |
1867 fLastErrorMessage= p.getErrorMessage(); | |
1868 } | |
1869 | |
1870 return result; | |
1871 } | |
1872 | |
1873 /** | |
1874 * Returns an array of context information objects computed based on the specified document | |
1875 * position. The position is used to determine the appropriate content assist processor to | |
1876 * invoke. | |
1877 * | |
1878 * @param viewer the viewer for which to compute the context information | |
1879 * @param offset a document offset | |
1880 * @return an array of context information objects | |
1881 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) | |
1882 */ | |
1883 IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { | |
1884 fLastErrorMessage= null; | |
1885 | |
1886 IContextInformation[] result= null; | |
1887 | |
1888 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1889 if (p !is null) { | |
1890 result= p.computeContextInformation(viewer, offset); | |
1891 fLastErrorMessage= p.getErrorMessage(); | |
1892 } | |
1893 | |
1894 return result; | |
1895 } | |
1896 | |
1897 /** | |
1898 * Returns an array of context information objects computed based on the specified document | |
1899 * position. The position is used to determine the appropriate content assist processor to | |
1900 * invoke. | |
1901 * | |
1902 * @param contentAssistSubjectControl the content assist subject control | |
1903 * @param offset a document offset | |
1904 * @return an array of context information objects | |
1905 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int) | |
1906 * @since 3.0 | |
1907 */ | |
1908 IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1909 fLastErrorMessage= null; | |
1910 | |
1911 IContextInformation[] result= null; | |
1912 | |
1913 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
138 | 1914 if ( cast(ISubjectControlContentAssistProcessor)p ) { |
134 | 1915 result= (cast(ISubjectControlContentAssistProcessor) p).computeContextInformation(contentAssistSubjectControl, offset); |
129 | 1916 fLastErrorMessage= p.getErrorMessage(); |
1917 } | |
1918 | |
1919 return result; | |
1920 } | |
1921 | |
1922 /** | |
1923 * Returns the context information validator that should be used to determine when the currently | |
1924 * displayed context information should be dismissed. The position is used to determine the | |
1925 * appropriate content assist processor to invoke. | |
1926 * | |
1927 * @param viewer the text viewer | |
1928 * @param offset a document offset | |
1929 * @return an validator | |
1930 * @see IContentAssistProcessor#getContextInformationValidator() | |
1931 * @since 3.0 | |
1932 */ | |
1933 IContextInformationValidator getContextInformationValidator(ITextViewer viewer, int offset) { | |
1934 IContentAssistProcessor p= getProcessor(viewer, offset); | |
1935 return p !is null ? p.getContextInformationValidator() : null; | |
1936 } | |
1937 | |
1938 /** | |
1939 * Returns the context information validator that should be used to determine when the currently | |
1940 * displayed context information should be dismissed. The position is used to determine the | |
1941 * appropriate content assist processor to invoke. | |
1942 * | |
1943 * @param contentAssistSubjectControl the content assist subject control | |
1944 * @param offset a document offset | |
1945 * @return an validator | |
1946 * @see IContentAssistProcessor#getContextInformationValidator() | |
1947 * @since 3.0 | |
1948 */ | |
1949 IContextInformationValidator getContextInformationValidator(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1950 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
1951 return p !is null ? p.getContextInformationValidator() : null; | |
1952 } | |
1953 | |
1954 /** | |
1955 * Returns the context information presenter that should be used to display context information. | |
1956 * The position is used to determine the appropriate content assist processor to invoke. | |
1957 * | |
1958 * @param viewer the text viewer | |
1959 * @param offset a document offset | |
1960 * @return a presenter | |
1961 * @since 2.0 | |
1962 */ | |
1963 IContextInformationPresenter getContextInformationPresenter(ITextViewer viewer, int offset) { | |
1964 IContextInformationValidator validator= getContextInformationValidator(viewer, offset); | |
138 | 1965 if ( cast(IContextInformationPresenter)validator ) |
134 | 1966 return cast(IContextInformationPresenter) validator; |
129 | 1967 return null; |
1968 } | |
1969 | |
1970 /** | |
1971 * Returns the context information presenter that should be used to display context information. | |
1972 * The position is used to determine the appropriate content assist processor to invoke. | |
1973 * | |
1974 * @param contentAssistSubjectControl the content assist subject control | |
1975 * @param offset a document offset | |
1976 * @return a presenter | |
1977 * @since 3.0 | |
1978 */ | |
1979 IContextInformationPresenter getContextInformationPresenter(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1980 IContextInformationValidator validator= getContextInformationValidator(contentAssistSubjectControl, offset); | |
138 | 1981 if ( cast(IContextInformationPresenter)validator ) |
134 | 1982 return cast(IContextInformationPresenter) validator; |
129 | 1983 return null; |
1984 } | |
1985 | |
1986 /** | |
1987 * Returns the characters which when typed by the user should automatically initiate proposing | |
1988 * completions. The position is used to determine the appropriate content assist processor to | |
1989 * invoke. | |
1990 * | |
1991 * @param contentAssistSubjectControl the content assist subject control | |
1992 * @param offset a document offset | |
1993 * @return the auto activation characters | |
1994 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() | |
1995 * @since 3.0 | |
1996 */ | |
1997 char[] getCompletionProposalAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
1998 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
1999 return p !is null ? p.getCompletionProposalAutoActivationCharacters() : null; | |
2000 } | |
2001 | |
2002 /** | |
2003 * Returns the characters which when typed by the user should automatically initiate proposing | |
2004 * completions. The position is used to determine the appropriate content assist processor to | |
2005 * invoke. | |
2006 * | |
2007 * @param viewer the text viewer | |
2008 * @param offset a document offset | |
2009 * @return the auto activation characters | |
2010 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() | |
2011 */ | |
2012 char[] getCompletionProposalAutoActivationCharacters(ITextViewer viewer, int offset) { | |
2013 IContentAssistProcessor p= getProcessor(viewer, offset); | |
2014 return p !is null ? p.getCompletionProposalAutoActivationCharacters() : null; | |
2015 } | |
2016 | |
2017 /** | |
2018 * Returns the characters which when typed by the user should automatically initiate the | |
2019 * presentation of context information. The position is used to determine the appropriate | |
2020 * content assist processor to invoke. | |
2021 * | |
2022 * @param viewer the text viewer | |
2023 * @param offset a document offset | |
2024 * @return the auto activation characters | |
2025 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() | |
2026 * @since 3.0 | |
2027 */ | |
2028 char[] getContextInformationAutoActivationCharacters(ITextViewer viewer, int offset) { | |
2029 IContentAssistProcessor p= getProcessor(viewer, offset); | |
2030 return p !is null ? p.getContextInformationAutoActivationCharacters() : null; | |
2031 } | |
2032 | |
2033 /** | |
2034 * Returns the characters which when typed by the user should automatically initiate the | |
2035 * presentation of context information. The position is used to determine the appropriate | |
2036 * content assist processor to invoke. | |
2037 * | |
2038 * @param contentAssistSubjectControl the content assist subject control | |
2039 * @param offset a document offset | |
2040 * @return the auto activation characters | |
2041 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters() | |
2042 * @since 3.0 | |
2043 */ | |
2044 char[] getContextInformationAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) { | |
2045 IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset); | |
2046 return p !is null ? p.getContextInformationAutoActivationCharacters() : null; | |
2047 } | |
2048 | |
2049 /* | |
2050 * @see dwtx.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner) | |
2051 * @since 2.0 | |
2052 */ | |
2053 public bool requestWidgetToken(IWidgetTokenOwner owner) { | |
2054 return false; | |
2055 } | |
2056 | |
2057 /* | |
2058 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(dwtx.jface.text.IWidgetTokenOwner, | |
2059 * int) | |
2060 * @since 3.0 | |
2061 */ | |
2062 public bool requestWidgetToken(IWidgetTokenOwner owner, int priority) { | |
2063 if (priority > WIDGET_PRIORITY) { | |
2064 hide(); | |
2065 return true; | |
2066 } | |
2067 return false; | |
2068 } | |
2069 | |
2070 /* | |
2071 * @see dwtx.jface.text.IWidgetTokenKeeperExtension#setFocus(dwtx.jface.text.IWidgetTokenOwner) | |
2072 * @since 3.0 | |
2073 */ | |
2074 public bool setFocus(IWidgetTokenOwner owner) { | |
2075 if (fProposalPopup !is null) { | |
2076 fProposalPopup.setFocus(); | |
2077 return fProposalPopup.hasFocus(); | |
2078 } | |
2079 return false; | |
2080 } | |
2081 | |
2082 /** | |
2083 * Hides any open pop-ups. | |
2084 * | |
2085 * @since 3.0 | |
2086 */ | |
2087 protected void hide() { | |
2088 if (fProposalPopup !is null) | |
2089 fProposalPopup.hide(); | |
2090 | |
2091 if (fContextInfoPopup !is null) | |
2092 fContextInfoPopup.hide(); | |
2093 } | |
2094 | |
2095 // ------ control's size handling dialog settings ------ | |
2096 | |
2097 /** | |
2098 * Tells this information control manager to open the information control with the values | |
2099 * contained in the given dialog settings and to store the control's last valid size in the | |
2100 * given dialog settings. | |
2101 * <p> | |
2102 * Note: This API is only valid if the information control implements | |
2103 * {@link dwtx.jface.text.IInformationControlExtension3}. Not following this restriction | |
2104 * will later result in an {@link UnsupportedOperationException}. | |
2105 * </p> | |
2106 * <p> | |
2107 * The constants used to store the values are: | |
2108 * <ul> | |
2109 * <li>{@link ContentAssistant#STORE_SIZE_X}</li> | |
2110 * <li>{@link ContentAssistant#STORE_SIZE_Y}</li> | |
2111 * </ul> | |
2112 * </p> | |
2113 * | |
2114 * @param dialogSettings | |
2115 * @since 3.0 | |
2116 */ | |
2117 public void setRestoreCompletionProposalSize(IDialogSettings dialogSettings) { | |
2118 Assert.isTrue(dialogSettings !is null); | |
2119 fDialogSettings= dialogSettings; | |
2120 } | |
2121 | |
2122 /** | |
2123 * Stores the content assist pop-up's size. | |
2124 */ | |
2125 protected void storeCompletionProposalPopupSize() { | |
2126 if (fDialogSettings is null || fProposalPopup is null) | |
2127 return; | |
2128 | |
2129 Point size= fProposalPopup.getSize(); | |
2130 if (size is null) | |
2131 return; | |
2132 | |
2133 fDialogSettings.put(STORE_SIZE_X, size.x); | |
2134 fDialogSettings.put(STORE_SIZE_Y, size.y); | |
2135 } | |
2136 | |
2137 /** | |
2138 * Restores the content assist pop-up's size. | |
2139 * | |
2140 * @return the stored size | |
2141 * @since 3.0 | |
2142 */ | |
2143 protected Point restoreCompletionProposalPopupSize() { | |
2144 if (fDialogSettings is null) | |
2145 return null; | |
2146 | |
2147 Point size= new Point(-1, -1); | |
2148 | |
2149 try { | |
2150 size.x= fDialogSettings.getInt(STORE_SIZE_X); | |
2151 size.y= fDialogSettings.getInt(STORE_SIZE_Y); | |
2152 } catch (NumberFormatException ex) { | |
2153 size.x= -1; | |
2154 size.y= -1; | |
2155 } | |
2156 | |
2157 // sanity check | |
2158 if (size.x is -1 && size.y is -1) | |
2159 return null; | |
2160 | |
2161 Rectangle maxBounds= null; | |
2162 if (fContentAssistSubjectControl !is null && Helper.okToUse(fContentAssistSubjectControl.getControl())) | |
2163 maxBounds= fContentAssistSubjectControl.getControl().getDisplay().getBounds(); | |
2164 else { | |
2165 // fallback | |
2166 Display display= Display.getCurrent(); | |
2167 if (display is null) | |
2168 display= Display.getDefault(); | |
2169 if (display !is null && !display.isDisposed()) | |
2170 maxBounds= display.getBounds(); | |
2171 } | |
2172 | |
2173 if (size.x > -1 && size.y > -1) { | |
2174 if (maxBounds !is null) { | |
2175 size.x= Math.min(size.x, maxBounds.width); | |
2176 size.y= Math.min(size.y, maxBounds.height); | |
2177 } | |
2178 | |
2179 // Enforce an absolute minimal size | |
2180 size.x= Math.max(size.x, 30); | |
2181 size.y= Math.max(size.y, 30); | |
2182 } | |
2183 | |
2184 return size; | |
2185 } | |
2186 | |
2187 /** | |
2188 * Sets the prefix completion property. If enabled, content assist delegates completion to | |
2189 * prefix completion. | |
2190 * | |
2191 * @param enabled <code>true</code> to enable prefix completion, <code>false</code> to | |
2192 * disable | |
2193 */ | |
2194 public void enablePrefixCompletion(bool enabled) { | |
2195 fIsPrefixCompletionEnabled= enabled; | |
2196 } | |
158 | 2197 |
129 | 2198 /** |
2199 * Returns the prefix completion state. | |
158 | 2200 * |
129 | 2201 * @return <code>true</code> if prefix completion is enabled, <code>false</code> otherwise |
2202 * @since 3.2 | |
2203 */ | |
2204 bool isPrefixCompletionEnabled() { | |
2205 return fIsPrefixCompletionEnabled; | |
2206 } | |
2207 | |
2208 /** | |
2209 * Returns whether the content assistant proposal popup has the focus. | |
2210 * | |
2211 * @return <code>true</code> if the proposal popup has the focus | |
2212 * @since 3.0 | |
2213 */ | |
2214 public bool hasProposalPopupFocus() { | |
2215 return fProposalPopup.hasFocus(); | |
2216 } | |
2217 | |
2218 /* | |
2219 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#addCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) | |
2220 * @since 3.2 | |
2221 */ | |
2222 public void addCompletionListener(ICompletionListener listener) { | |
2223 Assert.isLegal(listener !is null); | |
2224 fCompletionListeners.add(listener); | |
2225 } | |
2226 | |
2227 /* | |
2228 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#removeCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) | |
2229 * @since 3.2 | |
2230 */ | |
2231 public void removeCompletionListener(ICompletionListener listener) { | |
2232 fCompletionListeners.remove(listener); | |
2233 } | |
2234 | |
2235 /** | |
2236 * Fires a session begin event to all registered {@link ICompletionListener}s. | |
158 | 2237 * |
129 | 2238 * @param isAutoActivated <code>true</code> if this session was triggered by auto activation |
2239 * @since 3.2 | |
2240 */ | |
2241 void fireSessionBeginEvent(bool isAutoActivated) { | |
2242 if (fContentAssistSubjectControlAdapter !is null && !isProposalPopupActive()) { | |
2243 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2244 ContentAssistEvent event= new ContentAssistEvent(this, processor, isAutoActivated); | |
2245 Object[] listeners= fCompletionListeners.getListeners(); | |
2246 for (int i= 0; i < listeners.length; i++) { | |
134 | 2247 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2248 listener.assistSessionStarted(event); |
2249 } | |
2250 } | |
2251 } | |
158 | 2252 |
129 | 2253 /** |
2254 * Fires a session restart event to all registered {@link ICompletionListener}s. | |
2255 * | |
2256 * @since 3.4 | |
2257 */ | |
2258 void fireSessionRestartEvent() { | |
2259 if (fContentAssistSubjectControlAdapter !is null) { | |
2260 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2261 ContentAssistEvent event= new ContentAssistEvent(this, processor); | |
2262 Object[] listeners= fCompletionListeners.getListeners(); | |
2263 for (int i= 0; i < listeners.length; i++) { | |
134 | 2264 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
138 | 2265 if ( cast(ICompletionListenerExtension)listener ) |
134 | 2266 (cast(ICompletionListenerExtension)listener).assistSessionRestarted(event); |
129 | 2267 } |
2268 } | |
2269 } | |
2270 | |
2271 /** | |
2272 * Fires a session end event to all registered {@link ICompletionListener}s. | |
2273 * | |
2274 * @since 3.2 | |
2275 */ | |
2276 void fireSessionEndEvent() { | |
2277 if (fContentAssistSubjectControlAdapter !is null) { | |
2278 IContentAssistProcessor processor= getProcessor(fContentAssistSubjectControlAdapter, fContentAssistSubjectControlAdapter.getSelectedRange().x); | |
2279 ContentAssistEvent event= new ContentAssistEvent(this, processor); | |
2280 Object[] listeners= fCompletionListeners.getListeners(); | |
2281 for (int i= 0; i < listeners.length; i++) { | |
134 | 2282 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2283 listener.assistSessionEnded(event); |
2284 } | |
2285 } | |
2286 } | |
2287 | |
2288 /* | |
2289 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setRepeatedInvocationMode(bool) | |
2290 * @since 3.2 | |
2291 */ | |
2292 public void setRepeatedInvocationMode(bool cycling) { | |
2293 fIsRepetitionMode= cycling; | |
2294 } | |
2295 | |
2296 /** | |
2297 * Returns <code>true</code> if repeated invocation mode is enabled, <code>false</code> | |
2298 * otherwise. | |
2299 * | |
2300 * @return <code>true</code> if repeated invocation mode is enabled, <code>false</code> | |
2301 * otherwise | |
2302 * @since 3.2 | |
2303 */ | |
2304 bool isRepeatedInvocationMode() { | |
2305 return fIsRepetitionMode; | |
2306 } | |
2307 | |
2308 /* | |
2309 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setShowEmptyList(bool) | |
2310 * @since 3.2 | |
2311 */ | |
2312 public void setShowEmptyList(bool showEmpty) { | |
2313 fShowEmptyList= showEmpty; | |
2314 } | |
2315 | |
2316 /** | |
2317 * Returns <code>true</code> if empty lists should be displayed, <code>false</code> | |
2318 * otherwise. | |
2319 * | |
2320 * @return <code>true</code> if empty lists should be displayed, <code>false</code> | |
2321 * otherwise | |
2322 * @since 3.2 | |
2323 */ | |
2324 bool isShowEmptyList() { | |
2325 return fShowEmptyList; | |
2326 } | |
2327 | |
2328 /* | |
2329 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setStatusLineVisible(bool) | |
2330 * @since 3.2 | |
2331 */ | |
2332 public void setStatusLineVisible(bool show) { | |
2333 fIsStatusLineVisible= show; | |
2334 if (fProposalPopup !is null) | |
2335 fProposalPopup.setStatusLineVisible(show); | |
2336 } | |
2337 | |
2338 /** | |
2339 * Returns <code>true</code> if a message line should be displayed, <code>false</code> | |
2340 * otherwise. | |
2341 * | |
2342 * @return <code>true</code> if a message line should be displayed, <code>false</code> | |
2343 * otherwise | |
2344 * @since 3.2 | |
2345 */ | |
2346 bool isStatusLineVisible() { | |
2347 return fIsStatusLineVisible; | |
2348 } | |
2349 | |
2350 /* | |
2351 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setStatusMessage(java.lang.String) | |
2352 * @since 3.2 | |
2353 */ | |
2354 public void setStatusMessage(String message) { | |
2355 Assert.isLegal(message !is null); | |
2356 fMessage= message; | |
2357 if (fProposalPopup !is null) | |
2358 fProposalPopup.setMessage(message); | |
2359 } | |
2360 | |
2361 /** | |
2362 * Returns the affordance caption for the cycling affordance at the bottom of the pop-up. | |
2363 * | |
2364 * @return the affordance caption for the cycling affordance at the bottom of the pop-up | |
2365 * @since 3.2 | |
2366 */ | |
2367 String getStatusMessage() { | |
2368 return fMessage; | |
2369 } | |
2370 | |
2371 /* | |
2372 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#setEmptyMessage(java.lang.String) | |
2373 * @since 3.2 | |
2374 */ | |
2375 public void setEmptyMessage(String message) { | |
2376 Assert.isLegal(message !is null); | |
2377 if (fProposalPopup !is null) | |
2378 fProposalPopup.setEmptyMessage(message); | |
2379 } | |
2380 | |
2381 /** | |
2382 * Fires a selection event, see {@link ICompletionListener}. | |
2383 * | |
2384 * @param proposal the selected proposal, possibly <code>null</code> | |
2385 * @param smartToggle true if the smart toggle is on | |
2386 * @since 3.2 | |
2387 */ | |
2388 void fireSelectionEvent(ICompletionProposal proposal, bool smartToggle) { | |
2389 Object[] listeners= fCompletionListeners.getListeners(); | |
2390 for (int i= 0; i < listeners.length; i++) { | |
134 | 2391 ICompletionListener listener= cast(ICompletionListener)listeners[i]; |
129 | 2392 listener.selectionChanged(proposal, smartToggle); |
2393 } | |
2394 } | |
2395 | |
2396 /* | |
2397 * @see dwtx.jface.text.contentassist.IContentAssistantExtension3#setInvocationTrigger(dwtx.jface.bindings.keys.KeySequence) | |
2398 * @since 3.2 | |
2399 */ | |
2400 public void setRepeatedInvocationTrigger(KeySequence sequence) { | |
2401 fRepeatedInvocationKeySequence= sequence; | |
2402 } | |
2403 | |
2404 /** | |
2405 * Returns the repeated invocation key sequence. | |
158 | 2406 * |
129 | 2407 * @return the repeated invocation key sequence or <code>null</code>, if none |
2408 * @since 3.2 | |
2409 */ | |
2410 KeySequence getRepeatedInvocationKeySequence() { | |
2411 return fRepeatedInvocationKeySequence; | |
2412 } | |
158 | 2413 |
129 | 2414 /** |
2415 * Returns whether proposal popup is active. | |
158 | 2416 * |
129 | 2417 * @return <code>true</code> if the proposal popup is active, <code>false</code> otherwise |
2418 * @since 3.4 | |
2419 */ | |
2420 protected bool isProposalPopupActive(){ | |
2421 return fProposalPopup !is null && fProposalPopup.isActive(); | |
2422 } | |
2423 | |
2424 /** | |
2425 * Returns whether the context information popup is active. | |
158 | 2426 * |
129 | 2427 * @return <code>true</code> if the context information popup is active, <code>false</code> otherwise |
2428 * @since 3.4 | |
2429 */ | |
2430 protected bool isContextInfoPopupActive(){ | |
2431 return fContextInfoPopup !is null && fContextInfoPopup.isActive(); | |
2432 } | |
2433 | |
2434 /** | |
2435 * {@inheritDoc} | |
158 | 2436 * |
129 | 2437 * @since 3.4 |
2438 */ | |
2439 public final IHandler getHandler(String commandId) { | |
2440 if (fHandlers is null) | |
2441 throw new IllegalStateException(); | |
2442 | |
134 | 2443 IHandler handler= cast(IHandler)fHandlers.get(commandId); |
129 | 2444 if (handler !is null) |
2445 return handler; | |
158 | 2446 |
129 | 2447 Assert.isLegal(false); |
2448 return null; | |
2449 } | |
2450 | |
2451 /** | |
2452 * Registers the given handler under the given command identifier. | |
158 | 2453 * |
129 | 2454 * @param commandId the command identifier |
2455 * @param handler the handler | |
2456 * @since 3.4 | |
2457 */ | |
2458 protected final void registerHandler(String commandId, IHandler handler) { | |
2459 if (fHandlers is null) | |
2460 fHandlers= new HashMap(2); | |
2461 fHandlers.put(commandId, handler); | |
2462 } | |
2463 | |
2464 /** | |
2465 * Tells whether the support for colored labels is enabled. | |
158 | 2466 * |
129 | 2467 * @return <code>true</code> if the support for colored labels is enabled, <code>false</code> otherwise |
2468 * @since 3.4 | |
2469 */ | |
2470 bool isColoredLabelsSupportEnabled() { | |
2471 return fIsColoredLabelsSupportEnabled; | |
2472 } | |
2473 | |
2474 /** | |
2475 * Enables the support for colored labels in the proposal popup. | |
2476 * <p>Completion proposals can implement {@link ICompletionProposalExtension6} | |
2477 * to provide colored proposal labels.</p> | |
158 | 2478 * |
129 | 2479 * @param isEnabled if <code>true</code> the support for colored labels is enabled in the proposal popup |
2480 * @since 3.4 | |
2481 */ | |
2482 public void enableColoredLabels(bool isEnabled) { | |
2483 fIsColoredLabelsSupportEnabled= isEnabled; | |
2484 } | |
2485 | |
2486 } |