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