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