Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/link/contentassist/ContextInformationPopup2.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | f70d9508c95c |
children | 1a5b8f8129df |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 | |
131 | 14 |
151 | 15 module dwtx.jface.internal.text.link.contentassist.ContextInformationPopup2; |
16 | |
131 | 17 import dwtx.jface.internal.text.link.contentassist.IProposalListener; // packageimport |
18 import dwtx.jface.internal.text.link.contentassist.LineBreakingReader; // packageimport | |
19 import dwtx.jface.internal.text.link.contentassist.CompletionProposalPopup2; // packageimport | |
20 import dwtx.jface.internal.text.link.contentassist.ContentAssistMessages; // packageimport | |
21 import dwtx.jface.internal.text.link.contentassist.Helper2; // packageimport | |
22 import dwtx.jface.internal.text.link.contentassist.PopupCloser2; // packageimport | |
23 import dwtx.jface.internal.text.link.contentassist.IContentAssistListener2; // packageimport | |
24 import dwtx.jface.internal.text.link.contentassist.ContentAssistant2; // packageimport | |
25 import dwtx.jface.internal.text.link.contentassist.AdditionalInfoController2; // packageimport | |
26 | |
129 | 27 import dwt.dwthelper.utils; |
28 | |
29 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
151
diff
changeset
|
30 import dwtx.dwtxhelper.Collection; |
129 | 31 |
32 import dwt.DWT; | |
33 import dwt.custom.BusyIndicator; | |
34 import dwt.custom.StyledText; | |
35 import dwt.events.KeyEvent; | |
36 import dwt.events.SelectionEvent; | |
37 import dwt.events.SelectionListener; | |
38 import dwt.events.VerifyEvent; | |
39 import dwt.graphics.Color; | |
40 import dwt.graphics.Point; | |
41 import dwt.layout.GridData; | |
42 import dwt.layout.GridLayout; | |
43 import dwt.widgets.Control; | |
44 import dwt.widgets.Display; | |
45 import dwt.widgets.Shell; | |
46 import dwt.widgets.Table; | |
47 import dwt.widgets.TableItem; | |
48 import dwtx.jface.text.ITextViewer; | |
49 import dwtx.jface.text.TextPresentation; | |
50 import dwtx.jface.text.contentassist.IContextInformation; | |
51 import dwtx.jface.text.contentassist.IContextInformationExtension; | |
52 import dwtx.jface.text.contentassist.IContextInformationPresenter; | |
53 import dwtx.jface.text.contentassist.IContextInformationValidator; | |
54 | |
55 | |
56 /** | |
57 * This class is used to present context information to the user. | |
58 * If multiple contexts are valid at the current cursor location, | |
59 * a list is presented from which the user may choose one context. | |
60 * Once the user makes their choice, or if there was only a single | |
61 * possible context, the context information is shown in a tooltip like popup. <p> | |
62 * If the tooltip is visible and the user wants to see context information of | |
63 * a context embedded into the one for which context information is displayed, | |
64 * context information for the embedded context is shown. As soon as the | |
65 * cursor leaves the embedded context area, the context information for | |
66 * the embedding context is shown again. | |
67 * | |
68 * @see IContextInformation | |
69 * @see IContextInformationValidator | |
70 */ | |
71 class ContextInformationPopup2 : IContentAssistListener2 { | |
72 | |
73 | |
74 | |
75 /** | |
76 * Represents the state necessary for embedding contexts. | |
77 * @since 2.0 | |
78 */ | |
79 static class ContextFrame { | |
80 public int fBeginOffset; | |
81 public int fOffset; | |
82 public int fVisibleOffset; | |
83 public IContextInformation fInformation; | |
84 public IContextInformationValidator fValidator; | |
85 public IContextInformationPresenter fPresenter; | |
86 } | |
87 | |
88 private ITextViewer fViewer; | |
89 private ContentAssistant2 fContentAssistant; | |
90 | |
91 private PopupCloser2 fPopupCloser= new PopupCloser2(); | |
92 private Shell fContextSelectorShell; | |
93 private Table fContextSelectorTable; | |
94 private IContextInformation[] fContextSelectorInput; | |
95 private String fLineDelimiter= null; | |
96 | |
97 private Shell fContextInfoPopup; | |
98 private StyledText fContextInfoText; | |
99 private TextPresentation fTextPresentation; | |
100 | |
101 private Stack fContextFrameStack= new Stack(); | |
102 | |
103 | |
104 /** | |
105 * Creates a new context information popup. | |
106 * | |
107 * @param contentAssistant the content assist for computing the context information | |
108 * @param viewer the viewer on top of which the context information is shown | |
109 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
110 public this(ContentAssistant2 contentAssistant, ITextViewer viewer) { |
129 | 111 fContentAssistant= contentAssistant; |
112 fViewer= viewer; | |
113 } | |
114 | |
115 /** | |
116 * Shows all possible contexts for the given cursor position of the viewer. | |
117 * | |
118 * @param autoActivated <code>true</code> if auto activated | |
119 * @return a potential error message or <code>null</code> in case of no error | |
120 */ | |
158 | 121 public String showContextProposals(bool autoActivated) { |
129 | 122 final StyledText styledText= fViewer.getTextWidget(); |
158 | 123 BusyIndicator.showWhile(styledText.getDisplay(), dgRunnable( (bool autoActivated_, StyledText styledText_ ) { |
124 int position= fViewer.getSelectedRange().x; | |
129 | 125 |
158 | 126 IContextInformation[] contexts= computeContextInformation(position); |
127 int count = (contexts is null ? 0 : contexts.length); | |
128 if (count is 1) { | |
129 | 129 |
158 | 130 // Show context information directly |
131 internalShowContextInfo(contexts[0], position); | |
129 | 132 |
158 | 133 } else if (count > 0) { |
134 // Precise context must be selected | |
129 | 135 |
158 | 136 if (fLineDelimiter is null) |
137 fLineDelimiter= styledText_.getLineDelimiter(); | |
129 | 138 |
158 | 139 createContextSelector(); |
140 setContexts(contexts); | |
141 displayContextSelector(); | |
142 hideContextInfoPopup(); | |
129 | 143 |
158 | 144 } else if (!autoActivated_) { |
145 styledText_.getDisplay().beep(); | |
129 | 146 } |
158 | 147 }, autoActivated, styledText )); |
129 | 148 |
149 return getErrorMessage(); | |
150 } | |
151 | |
152 /** | |
153 * Displays the given context information for the given offset. | |
154 * | |
155 * @param info the context information | |
156 * @param position the offset | |
157 * @since 2.0 | |
158 */ | |
158 | 159 public void showContextInformation(IContextInformation info, int position) { |
129 | 160 Control control= fViewer.getTextWidget(); |
158 | 161 BusyIndicator.showWhile(control.getDisplay(), dgRunnable( (IContextInformation info_, int position_) { |
162 internalShowContextInfo(info_, position_); | |
163 hideContextSelector(); | |
164 }, info, position)); | |
129 | 165 } |
166 | |
167 /** | |
168 * Displays the given context information for the given offset. | |
169 * | |
170 * @param information the context information | |
171 * @param offset the offset | |
172 * @since 2.0 | |
173 */ | |
174 | |
175 private void internalShowContextInfo(IContextInformation information, int offset) { | |
176 | |
177 IContextInformationValidator validator= fContentAssistant.getContextInformationValidator(fViewer, offset); | |
178 | |
179 if (validator !is null) { | |
180 ContextFrame current= new ContextFrame(); | |
181 current.fInformation= information; | |
138 | 182 current.fBeginOffset= ( cast(IContextInformationExtension)information ) ? (cast(IContextInformationExtension) information).getContextInformationPosition() : offset; |
129 | 183 if (current.fBeginOffset is -1) current.fBeginOffset= offset; |
184 current.fOffset= offset; | |
185 current.fVisibleOffset= fViewer.getTextWidget().getSelectionRange().x - (offset - current.fBeginOffset); | |
186 current.fValidator= validator; | |
187 current.fPresenter= fContentAssistant.getContextInformationPresenter(fViewer, offset); | |
188 | |
189 fContextFrameStack.push(current); | |
190 | |
191 internalShowContextFrame(current, fContextFrameStack.size() is 1); | |
192 } | |
193 } | |
194 | |
195 /** | |
196 * Shows the given context frame. | |
197 * | |
198 * @param frame the frane to display | |
199 * @param initial <code>true</code> if this is the first frame to be displayed | |
200 * @since 2.0 | |
201 */ | |
202 private void internalShowContextFrame(ContextFrame frame, bool initial) { | |
203 | |
204 frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset); | |
205 | |
206 if (frame.fPresenter !is null) { | |
207 if (fTextPresentation is null) | |
208 fTextPresentation= new TextPresentation(); | |
209 frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset); | |
210 frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation); | |
211 } | |
212 | |
213 createContextInfoPopup(); | |
214 | |
215 fContextInfoText.setText(frame.fInformation.getInformationDisplayString()); | |
216 if (fTextPresentation !is null) | |
217 TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); | |
218 resize(); | |
219 | |
220 if (initial) { | |
221 if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_INFO_POPUP)) { | |
222 fContentAssistant.addToLayout(this, fContextInfoPopup, ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset); | |
223 fContextInfoPopup.setVisible(true); | |
224 } | |
225 } else { | |
226 fContentAssistant.layout(ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset); | |
227 } | |
228 } | |
229 | |
230 /** | |
231 * Computes all possible context information for the given offset. | |
232 * | |
233 * @param position the offset | |
234 * @return all possible context information for the given offset | |
235 * @since 2.0 | |
236 */ | |
237 private IContextInformation[] computeContextInformation(int position) { | |
238 return fContentAssistant.computeContextInformation(fViewer, position); | |
239 } | |
240 | |
241 /** | |
242 *Returns the error message generated while computing context information. | |
243 * | |
244 * @return the error message | |
245 */ | |
246 private String getErrorMessage() { | |
247 return fContentAssistant.getErrorMessage(); | |
248 } | |
249 | |
250 /** | |
251 * Creates the context information popup. This is the tooltip like overlay window. | |
252 */ | |
253 private void createContextInfoPopup() { | |
254 if (Helper2.okToUse(fContextInfoPopup)) | |
255 return; | |
256 | |
257 Control control= fViewer.getTextWidget(); | |
258 Display display= control.getDisplay(); | |
259 | |
260 fContextInfoPopup= new Shell(control.getShell(), DWT.NO_TRIM | DWT.ON_TOP); | |
261 fContextInfoPopup.setBackground(display.getSystemColor(DWT.COLOR_BLACK)); | |
262 | |
263 fContextInfoText= new StyledText(fContextInfoPopup, DWT.MULTI | DWT.READ_ONLY); | |
264 | |
265 Color c= fContentAssistant.getContextInformationPopupBackground(); | |
266 if (c is null) | |
267 c= display.getSystemColor(DWT.COLOR_INFO_BACKGROUND); | |
268 fContextInfoText.setBackground(c); | |
269 | |
270 c= fContentAssistant.getContextInformationPopupForeground(); | |
271 if (c is null) | |
272 c= display.getSystemColor(DWT.COLOR_INFO_FOREGROUND); | |
273 fContextInfoText.setForeground(c); | |
274 } | |
275 | |
276 /** | |
277 * Resizes the context information popup. | |
278 * @since 2.0 | |
279 */ | |
280 private void resize() { | |
281 Point size= fContextInfoText.computeSize(DWT.DEFAULT, DWT.DEFAULT, true); | |
282 size.x += 3; | |
283 fContextInfoText.setSize(size); | |
284 fContextInfoText.setLocation(1,1); | |
285 size.x += 2; | |
286 size.y += 2; | |
287 fContextInfoPopup.setSize(size); | |
288 } | |
289 | |
290 /** | |
291 *Hides the context information popup. | |
292 */ | |
293 private void hideContextInfoPopup() { | |
294 | |
295 if (Helper2.okToUse(fContextInfoPopup)) { | |
296 | |
297 int size= fContextFrameStack.size(); | |
298 if (size > 0) { | |
299 fContextFrameStack.pop(); | |
300 -- size; | |
301 } | |
302 | |
303 if (size > 0) { | |
134 | 304 ContextFrame current= cast(ContextFrame) fContextFrameStack.peek(); |
129 | 305 internalShowContextFrame(current, false); |
306 } else { | |
307 | |
308 fContentAssistant.removeContentAssistListener(this, ContentAssistant2.CONTEXT_INFO_POPUP); | |
309 | |
310 fContextInfoPopup.setVisible(false); | |
311 fContextInfoPopup.dispose(); | |
312 fContextInfoPopup= null; | |
313 | |
314 if (fTextPresentation !is null) { | |
315 fTextPresentation.clear(); | |
316 fTextPresentation= null; | |
317 } | |
318 } | |
319 } | |
320 | |
321 if (fContextInfoPopup is null) | |
322 fContentAssistant.contextInformationClosed(); | |
323 } | |
324 | |
325 /** | |
326 * Creates the context selector in case the user has the choice between multiple valid contexts | |
327 * at a given offset. | |
328 */ | |
329 private void createContextSelector() { | |
330 if (Helper2.okToUse(fContextSelectorShell)) | |
331 return; | |
332 | |
333 Control control= fViewer.getTextWidget(); | |
334 fContextSelectorShell= new Shell(control.getShell(), DWT.NO_TRIM | DWT.ON_TOP); | |
335 GridLayout layout= new GridLayout(); | |
336 layout.marginWidth= 0; | |
337 layout.marginHeight= 0; | |
338 fContextSelectorShell.setLayout(layout); | |
339 fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(DWT.COLOR_BLACK)); | |
340 | |
341 | |
342 fContextSelectorTable= new Table(fContextSelectorShell, DWT.H_SCROLL | DWT.V_SCROLL); | |
343 fContextSelectorTable.setLocation(1, 1); | |
344 GridData gd= new GridData(GridData.FILL_BOTH); | |
345 gd.heightHint= fContextSelectorTable.getItemHeight() * 10; | |
346 gd.widthHint= 300; | |
347 fContextSelectorTable.setLayoutData(gd); | |
348 | |
349 fContextSelectorShell.pack(true); | |
350 | |
351 Color c= fContentAssistant.getContextSelectorBackground(); | |
352 if (c is null) | |
353 c= control.getDisplay().getSystemColor(DWT.COLOR_INFO_BACKGROUND); | |
354 fContextSelectorTable.setBackground(c); | |
355 | |
356 c= fContentAssistant.getContextSelectorForeground(); | |
357 if (c is null) | |
358 c= control.getDisplay().getSystemColor(DWT.COLOR_INFO_FOREGROUND); | |
359 fContextSelectorTable.setForeground(c); | |
360 | |
135 | 361 fContextSelectorTable.addSelectionListener(new class() SelectionListener { |
129 | 362 public void widgetSelected(SelectionEvent e) { |
363 } | |
364 | |
365 public void widgetDefaultSelected(SelectionEvent e) { | |
366 insertSelectedContext(); | |
367 hideContextSelector(); | |
368 } | |
369 }); | |
370 | |
371 fPopupCloser.install(fContentAssistant, fContextSelectorTable); | |
372 | |
373 fContextSelectorTable.setHeaderVisible(false); | |
374 fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset()); | |
375 } | |
376 | |
377 /** | |
378 * Causes the context information of the context selected in the context selector | |
379 * to be displayed in the context information popup. | |
380 */ | |
381 private void insertSelectedContext() { | |
382 int i= fContextSelectorTable.getSelectionIndex(); | |
383 | |
384 if (i < 0 || i >= fContextSelectorInput.length) | |
385 return; | |
386 | |
387 int position= fViewer.getSelectedRange().x; | |
388 internalShowContextInfo(fContextSelectorInput[i], position); | |
389 } | |
390 | |
391 /** | |
392 * Sets the contexts in the context selector to the given set. | |
393 * | |
394 * @param contexts the possible contexts | |
395 */ | |
396 private void setContexts(IContextInformation[] contexts) { | |
397 if (Helper2.okToUse(fContextSelectorTable)) { | |
398 | |
399 fContextSelectorInput= contexts; | |
400 | |
401 fContextSelectorTable.setRedraw(false); | |
402 fContextSelectorTable.removeAll(); | |
403 | |
404 TableItem item; | |
405 IContextInformation t; | |
406 for (int i= 0; i < contexts.length; i++) { | |
407 t= contexts[i]; | |
408 item= new TableItem(fContextSelectorTable, DWT.NULL); | |
409 if (t.getImage() !is null) | |
410 item.setImage(t.getImage()); | |
411 item.setText(t.getContextDisplayString()); | |
412 } | |
413 | |
414 fContextSelectorTable.select(0); | |
415 fContextSelectorTable.setRedraw(true); | |
416 } | |
417 } | |
418 | |
419 /** | |
420 * Displays the context selector. | |
421 */ | |
422 private void displayContextSelector() { | |
423 if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR)) | |
424 fContextSelectorShell.setVisible(true); | |
425 } | |
426 | |
427 /** | |
428 * Hodes the context selector. | |
429 */ | |
430 private void hideContextSelector() { | |
431 if (Helper2.okToUse(fContextSelectorShell)) { | |
432 fContentAssistant.removeContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR); | |
433 | |
434 fPopupCloser.uninstall(); | |
435 fContextSelectorShell.setVisible(false); | |
436 fContextSelectorShell.dispose(); | |
437 fContextSelectorShell= null; | |
438 } | |
439 | |
440 if (!Helper2.okToUse(fContextInfoPopup)) | |
441 fContentAssistant.contextInformationClosed(); | |
442 } | |
443 | |
444 /** | |
445 *Returns whether the context selector has the focus. | |
446 * | |
447 * @return <code>true</code> if teh context selector has the focus | |
448 */ | |
449 public bool hasFocus() { | |
450 if (Helper2.okToUse(fContextSelectorShell)) | |
451 return (fContextSelectorShell.isFocusControl() || fContextSelectorTable.isFocusControl()); | |
452 | |
453 return false; | |
454 } | |
455 | |
456 /** | |
457 * Hides context selector and context information popup. | |
458 */ | |
459 public void hide() { | |
460 hideContextSelector(); | |
461 hideContextInfoPopup(); | |
462 } | |
463 | |
464 /** | |
465 * Returns whether this context information popup is active. I.e., either | |
466 * a context selector or context information is displayed. | |
467 * | |
468 * @return <code>true</code> if the context selector is active | |
469 */ | |
470 public bool isActive() { | |
471 return (Helper2.okToUse(fContextInfoPopup) || Helper2.okToUse(fContextSelectorShell)); | |
472 } | |
473 | |
474 /* | |
475 * @see IContentAssistListener#verifyKey(VerifyEvent) | |
476 */ | |
477 public bool verifyKey(VerifyEvent e) { | |
478 if (Helper2.okToUse(fContextSelectorShell)) | |
479 return contextSelectorKeyPressed(e); | |
480 if (Helper2.okToUse(fContextInfoPopup)) | |
481 return contextInfoPopupKeyPressed(e); | |
482 return true; | |
483 } | |
484 | |
485 /** | |
486 * Processes a key stroke in the context selector. | |
487 * | |
488 * @param e the verify event describing the key stroke | |
489 * @return <code>true</code> if processing can be stopped | |
490 */ | |
491 private bool contextSelectorKeyPressed(VerifyEvent e) { | |
492 | |
493 char key= e.character; | |
494 if (key is 0) { | |
495 | |
496 int change; | |
497 int visibleRows= (fContextSelectorTable.getSize().y / fContextSelectorTable.getItemHeight()) - 1; | |
498 int selection= fContextSelectorTable.getSelectionIndex(); | |
499 | |
500 switch (e.keyCode) { | |
501 | |
502 case DWT.ARROW_UP: | |
503 change= (fContextSelectorTable.getSelectionIndex() > 0 ? -1 : 0); | |
504 break; | |
505 | |
506 case DWT.ARROW_DOWN: | |
507 change= (fContextSelectorTable.getSelectionIndex() < fContextSelectorTable.getItemCount() - 1 ? 1 : 0); | |
508 break; | |
509 | |
510 case DWT.PAGE_DOWN : | |
511 change= visibleRows; | |
512 if (selection + change >= fContextSelectorTable.getItemCount()) | |
513 change= fContextSelectorTable.getItemCount() - selection; | |
514 break; | |
515 | |
516 case DWT.PAGE_UP : | |
517 change= -visibleRows; | |
518 if (selection + change < 0) | |
519 change= -selection; | |
520 break; | |
521 | |
522 case DWT.HOME : | |
523 change= -selection; | |
524 break; | |
525 | |
526 case DWT.END : | |
527 change= fContextSelectorTable.getItemCount() - selection; | |
528 break; | |
529 | |
530 default: | |
531 if (e.keyCode !is DWT.MOD1 && e.keyCode !is DWT.MOD2 && e.keyCode !is DWT.MOD3 && e.keyCode !is DWT.MOD4) | |
532 hideContextSelector(); | |
533 return true; | |
534 } | |
535 | |
536 fContextSelectorTable.setSelection(selection + change); | |
537 fContextSelectorTable.showSelection(); | |
538 e.doit= false; | |
539 return false; | |
540 | |
541 } else if ('\t' is key) { | |
542 // switch focus to selector shell | |
543 e.doit= false; | |
544 fContextSelectorShell.setFocus(); | |
545 return false; | |
546 } else if (key is DWT.ESC) { | |
547 e.doit= false; | |
548 hideContextSelector(); | |
549 } | |
550 | |
551 return true; | |
552 } | |
553 | |
554 /** | |
555 * Processes a key stroke while the info popup is up. | |
556 * | |
557 * @param e the verify event describing the key stroke | |
558 * @return <code>true</code> if processing can be stopped | |
559 */ | |
560 private bool contextInfoPopupKeyPressed(KeyEvent e) { | |
561 | |
562 char key= e.character; | |
563 if (key is 0) { | |
564 | |
565 switch (e.keyCode) { | |
566 case DWT.ARROW_LEFT: | |
567 case DWT.ARROW_RIGHT: | |
568 validateContextInformation(); | |
569 break; | |
570 default: | |
571 if (e.keyCode !is DWT.MOD1 && e.keyCode !is DWT.MOD2 && e.keyCode !is DWT.MOD3 && e.keyCode !is DWT.MOD4) | |
572 hideContextInfoPopup(); | |
573 break; | |
574 } | |
575 | |
576 } else if (key is DWT.ESC) { | |
577 e.doit= false; | |
578 hideContextInfoPopup(); | |
579 } else { | |
580 validateContextInformation(); | |
581 } | |
582 return true; | |
583 } | |
584 | |
585 /* | |
586 * @see IEventConsumer#processEvent(VerifyEvent) | |
587 */ | |
588 public void processEvent(VerifyEvent event) { | |
589 if (Helper2.okToUse(fContextSelectorShell)) | |
590 contextSelectorProcessEvent(event); | |
591 if (Helper2.okToUse(fContextInfoPopup)) | |
592 contextInfoPopupProcessEvent(event); | |
593 } | |
594 | |
595 /** | |
596 * Processes a key stroke in the context selector. | |
597 * | |
598 * @param e the verify event describing the key stroke | |
599 */ | |
600 private void contextSelectorProcessEvent(VerifyEvent e) { | |
601 | |
602 if (e.start is e.end && e.text !is null && e.text.equals(fLineDelimiter)) { | |
603 e.doit= false; | |
604 insertSelectedContext(); | |
605 } | |
606 | |
607 hideContextSelector(); | |
608 } | |
609 | |
610 /** | |
611 * Processes a key stroke while the info popup is up. | |
612 * | |
613 * @param e the verify event describing the key stroke | |
614 */ | |
615 private void contextInfoPopupProcessEvent(VerifyEvent e) { | |
616 if (e.start !is e.end && (e.text is null || e.text.length() is 0)) | |
617 validateContextInformation(); | |
618 } | |
619 | |
620 /** | |
621 * Validates the context information for the viewer's actual cursor position. | |
622 */ | |
623 private void validateContextInformation() { | |
624 /* | |
625 * Post the code in the event queue in order to ensure that the | |
626 * action described by this verify key event has already beed executed. | |
627 * Otherwise, we'd validate the context information based on the | |
628 * pre-key-stroke state. | |
629 */ | |
135 | 630 fContextInfoPopup.getDisplay().asyncExec(new class() Runnable { |
129 | 631 |
134 | 632 private ContextFrame fFrame= cast(ContextFrame) fContextFrameStack.peek(); |
129 | 633 |
634 public void run() { | |
635 if (Helper2.okToUse(fContextInfoPopup) && fFrame is fContextFrameStack.peek()) { | |
636 int offset= fViewer.getSelectedRange().x; | |
637 if (fFrame.fValidator is null || !fFrame.fValidator.isContextInformationValid(offset)) { | |
638 hideContextInfoPopup(); | |
639 } else if (fFrame.fPresenter !is null && fFrame.fPresenter.updatePresentation(offset, fTextPresentation)) { | |
640 TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText); | |
641 resize(); | |
642 } | |
643 } | |
644 } | |
645 }); | |
646 } | |
647 } |