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