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