Mercurial > projects > dwt-addons
comparison dwtx/jface/internal/text/link/contentassist/ContentAssistant2.d @ 168:cef27f663573
jface.text ...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 09 Sep 2008 17:44:11 +0200 |
parents | 862b05e0334a |
children | c3583c6ec027 |
comparison
equal
deleted
inserted
replaced
167:862b05e0334a | 168:cef27f663573 |
---|---|
23 import dwtx.jface.internal.text.link.contentassist.AdditionalInfoController2; // packageimport | 23 import dwtx.jface.internal.text.link.contentassist.AdditionalInfoController2; // packageimport |
24 | 24 |
25 import dwt.dwthelper.utils; | 25 import dwt.dwthelper.utils; |
26 import dwtx.dwtxhelper.Collection; | 26 import dwtx.dwtxhelper.Collection; |
27 import dwtx.dwtxhelper.JThread; | 27 import dwtx.dwtxhelper.JThread; |
28 import tango.core.sync.Mutex; | |
29 import tango.core.sync.Condition; | |
28 | 30 |
29 import dwt.DWT; | 31 import dwt.DWT; |
30 import dwt.DWTError; | 32 import dwt.DWTError; |
31 import dwt.custom.StyledText; | 33 import dwt.custom.StyledText; |
32 import dwt.custom.VerifyKeyListener; | 34 import dwt.custom.VerifyKeyListener; |
230 */ | 232 */ |
231 class AutoAssistListener : VerifyKeyListener, Runnable { | 233 class AutoAssistListener : VerifyKeyListener, Runnable { |
232 | 234 |
233 private JThread fThread; | 235 private JThread fThread; |
234 private bool fIsReset= false; | 236 private bool fIsReset= false; |
235 private Object fMutex= new Object(); | 237 private Mutex fMutex; |
238 private Condition fMutex_cond; | |
236 private int fShowStyle; | 239 private int fShowStyle; |
237 | 240 |
238 private const static int SHOW_PROPOSALS= 1; | 241 private const static int SHOW_PROPOSALS= 1; |
239 private const static int SHOW_CONTEXT_INFO= 2; | 242 private const static int SHOW_CONTEXT_INFO= 2; |
240 | 243 |
241 protected this() { | 244 protected this() { |
245 fMutex = new Mutex(); | |
246 fMutex_cond = new Condition(fMutex); | |
242 } | 247 } |
243 | 248 |
244 protected void start(int showStyle) { | 249 protected void start(int showStyle) { |
245 fShowStyle= showStyle; | 250 fShowStyle= showStyle; |
246 fThread= new Thread(&run); | 251 fThread= new JThread(this); |
247 fThread.name = ContentAssistMessages.getString("ContentAssistant.assist_delay_timer_name"); //$NON-NLS-1$ | 252 fThread.setName( ContentAssistMessages.getString("ContentAssistant.assist_delay_timer_name")); //$NON-NLS-1$ |
248 fThread.start(); | 253 fThread.start(); |
249 } | 254 } |
250 | 255 |
251 public void run() { | 256 public override void run() { |
252 try { | 257 try { |
253 while (true) { | 258 while (true) { |
254 synchronized (fMutex) { | 259 synchronized (fMutex) { |
255 if (fAutoActivationDelay !is 0) | 260 if (fAutoActivationDelay !is 0) |
256 fMutex.wait(fAutoActivationDelay); | 261 fMutex_cond.wait(fAutoActivationDelay); |
257 if (fIsReset) { | 262 if (fIsReset) { |
258 fIsReset= false; | 263 fIsReset= false; |
259 continue; | 264 continue; |
260 } | 265 } |
261 } | 266 } |
269 | 274 |
270 protected void reset(int showStyle) { | 275 protected void reset(int showStyle) { |
271 synchronized (fMutex) { | 276 synchronized (fMutex) { |
272 fShowStyle= showStyle; | 277 fShowStyle= showStyle; |
273 fIsReset= true; | 278 fIsReset= true; |
274 fMutex.notifyAll(); | 279 fMutex_cond.notifyAll(); |
275 } | 280 } |
276 } | 281 } |
277 | 282 |
278 protected void stop() { | 283 protected void stop() { |
279 Thread threadToStop= fThread; | 284 JThread threadToStop= fThread; |
280 if (threadToStop !is null) | 285 if (threadToStop !is null) |
281 threadToStop.interrupt(); | 286 threadToStop.interrupt(); |
282 } | 287 } |
283 | 288 |
284 private bool contains(char[] characters, char character) { | 289 private bool contains(char[] characters, char character) { |
355 public const static int LAYOUT_CONTEXT_SELECTOR= 1; | 360 public const static int LAYOUT_CONTEXT_SELECTOR= 1; |
356 /** context info */ | 361 /** context info */ |
357 public const static int LAYOUT_CONTEXT_INFO_POPUP= 2; | 362 public const static int LAYOUT_CONTEXT_INFO_POPUP= 2; |
358 | 363 |
359 int fContextType= LAYOUT_CONTEXT_SELECTOR; | 364 int fContextType= LAYOUT_CONTEXT_SELECTOR; |
360 Shell[] fShells= new Shell[3]; | 365 Shell[] fShells; |
361 Object[] fPopups= new Object[3]; | 366 Object[] fPopups; |
367 | |
368 this(){ | |
369 fShells= new Shell[3]; | |
370 fPopups= new Object[3]; | |
371 } | |
362 | 372 |
363 protected void add(Object popup, Shell shell, int type, int offset) { | 373 protected void add(Object popup, Shell shell, int type, int offset) { |
364 Assert.isNotNull(popup); | 374 Assert.isNotNull(popup); |
365 Assert.isTrue(shell !is null && !shell.isDisposed()); | 375 Assert.isTrue(shell !is null && !shell.isDisposed()); |
366 checkType(type); | 376 checkType(type); |
630 * | 640 * |
631 * @param e the verify event | 641 * @param e the verify event |
632 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) | 642 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) |
633 */ | 643 */ |
634 public void verifyKey(VerifyEvent e) { | 644 public void verifyKey(VerifyEvent e) { |
635 IContentAssistListener2[] listeners= arraycast!(IContentAssistListener2)( fListeners.clone()); | 645 IContentAssistListener2[] listeners= arraycast!(IContentAssistListener2)( fListeners.dup ); |
636 for (int i= 0; i < listeners.length; i++) { | 646 for (int i= 0; i < listeners.length; i++) { |
637 if (listeners[i] !is null) { | 647 if (listeners[i] !is null) { |
638 if (!listeners[i].verifyKey(e) || !e.doit) | 648 if (!listeners[i].verifyKey(e) || !e.doit) |
639 return; | 649 return; |
640 } | 650 } |
646 */ | 656 */ |
647 public void processEvent(VerifyEvent event) { | 657 public void processEvent(VerifyEvent event) { |
648 | 658 |
649 installKeyListener(); | 659 installKeyListener(); |
650 | 660 |
651 IContentAssistListener2[] listeners= arraycast!(IContentAssistListener2)(fListeners.clone()); | 661 IContentAssistListener2[] listeners= arraycast!(IContentAssistListener2)( fListeners.dup ); |
652 for (int i= 0; i < listeners.length; i++) { | 662 for (int i= 0; i < listeners.length; i++) { |
653 if (listeners[i] !is null) { | 663 if (listeners[i] !is null) { |
654 listeners[i].processEvent(event); | 664 listeners[i].processEvent(event); |
655 if (!event.doit) | 665 if (!event.doit) |
656 return; | 666 return; |
659 } | 669 } |
660 } | 670 } |
661 | 671 |
662 | 672 |
663 // Content-Assist Listener types | 673 // Content-Assist Listener types |
664 final static int CONTEXT_SELECTOR= 0; | 674 const static int CONTEXT_SELECTOR= 0; |
665 final static int PROPOSAL_SELECTOR= 1; | 675 const static int PROPOSAL_SELECTOR= 1; |
666 final static int CONTEXT_INFO_POPUP= 2; | 676 const static int CONTEXT_INFO_POPUP= 2; |
667 | 677 |
668 /** | 678 /** |
669 * The popup priority: > info pop-ups, < standard content assist. | 679 * The popup priority: > info pop-ups, < standard content assist. |
670 * Default value: <code>10</code>. | 680 * Default value: <code>10</code>. |
671 * | 681 * |
699 private InternalListener fInternalListener; | 709 private InternalListener fInternalListener; |
700 private CompletionProposalPopup2 fProposalPopup; | 710 private CompletionProposalPopup2 fProposalPopup; |
701 private ContextInformationPopup2 fContextInfoPopup; | 711 private ContextInformationPopup2 fContextInfoPopup; |
702 | 712 |
703 private bool fKeyListenerHooked= false; | 713 private bool fKeyListenerHooked= false; |
704 private IContentAssistListener2[] fListeners= new IContentAssistListener2[4]; | 714 private IContentAssistListener2[] fListeners; |
705 private int fCompletionPosition; | 715 private int fCompletionPosition; |
706 private String[] fProposalStrings; | 716 private String[] fProposalStrings; |
707 private ICompletionProposal[] fProposals; | 717 private ICompletionProposal[] fProposals; |
708 private const List fProposalListeners= new ArrayList(); | 718 private const List fProposalListeners; |
709 | 719 |
710 /** | 720 /** |
711 * Tells whether colored label support is enabled. | 721 * Tells whether colored label support is enabled. |
712 * @since 3.4 | 722 * @since 3.4 |
713 */ | 723 */ |
720 * shows the context information above the location at which it was activated. If auto | 730 * shows the context information above the location at which it was activated. If auto |
721 * activation will be enabled, without further configuration steps, this content assistant | 731 * activation will be enabled, without further configuration steps, this content assistant |
722 * is activated after a 500 ms delay. It uses the default partitioning. | 732 * is activated after a 500 ms delay. It uses the default partitioning. |
723 */ | 733 */ |
724 public this() { | 734 public this() { |
735 fListeners= new IContentAssistListener2[4]; | |
736 fProposalListeners= new ArrayList(); | |
737 | |
725 setContextInformationPopupOrientation(CONTEXT_INFO_ABOVE); | 738 setContextInformationPopupOrientation(CONTEXT_INFO_ABOVE); |
726 setInformationControlCreator(getInformationControlCreator()); | 739 setInformationControlCreator(getInformationControlCreator()); |
727 | 740 |
728 // JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); | 741 // JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); |
729 // IColorManager manager= textTools.getColorManager(); | 742 // IColorManager manager= textTools.getColorManager(); |
784 fProcessors= new HashMap(); | 797 fProcessors= new HashMap(); |
785 | 798 |
786 if (processor is null) | 799 if (processor is null) |
787 fProcessors.remove(contentType); | 800 fProcessors.remove(contentType); |
788 else | 801 else |
789 fProcessors.put(contentType, processor); | 802 fProcessors.put(contentType, cast(Object)processor); |
790 } | 803 } |
791 | 804 |
792 /* | 805 /* |
793 * @see IContentAssistant#getContentAssistProcessor | 806 * @see IContentAssistant#getContentAssistProcessor |
794 */ | 807 */ |
1012 | 1025 |
1013 /* | 1026 /* |
1014 * @see IContentAssist#install | 1027 * @see IContentAssist#install |
1015 */ | 1028 */ |
1016 public void install(ITextViewer textViewer) { | 1029 public void install(ITextViewer textViewer) { |
1017 Assert.isNotNull(textViewer); | 1030 Assert.isNotNull(cast(Object)textViewer); |
1018 | 1031 |
1019 fViewer= textViewer; | 1032 fViewer= textViewer; |
1020 | 1033 |
1021 fLayoutManager= new LayoutManager(); | 1034 fLayoutManager= new LayoutManager(); |
1022 fInternalListener= new InternalListener(); | 1035 fInternalListener= new InternalListener(); |
1024 AdditionalInfoController2 controller= null; | 1037 AdditionalInfoController2 controller= null; |
1025 if (fInformationControlCreator !is null) { | 1038 if (fInformationControlCreator !is null) { |
1026 int delay= fAutoActivationDelay; | 1039 int delay= fAutoActivationDelay; |
1027 if (delay is 0) | 1040 if (delay is 0) |
1028 delay= DEFAULT_AUTO_ACTIVATION_DELAY; | 1041 delay= DEFAULT_AUTO_ACTIVATION_DELAY; |
1029 delay= Math.round(delay * 1.5f); | 1042 delay= cast(int)Math.round(delay * 1.5f); |
1030 controller= new AdditionalInfoController2(fInformationControlCreator, delay); | 1043 controller= new AdditionalInfoController2(fInformationControlCreator, delay); |
1031 } | 1044 } |
1032 fContextInfoPopup= new ContextInformationPopup2(this, fViewer); | 1045 fContextInfoPopup= new ContextInformationPopup2(this, fViewer); |
1033 fProposalPopup= new CompletionProposalPopup2(this, fViewer, controller); | 1046 fProposalPopup= new CompletionProposalPopup2(this, fViewer, controller); |
1034 | 1047 |
1566 | 1579 |
1567 /** | 1580 /** |
1568 * @param listener | 1581 * @param listener |
1569 */ | 1582 */ |
1570 public void removeProposalListener(IProposalListener listener) { | 1583 public void removeProposalListener(IProposalListener listener) { |
1571 fProposalListeners.remove(listener); | 1584 fProposalListeners.remove(cast(Object)listener); |
1572 } | 1585 } |
1573 | 1586 |
1574 /** | 1587 /** |
1575 * @param listener | 1588 * @param listener |
1576 */ | 1589 */ |
1577 public void addProposalListener(IProposalListener listener) { | 1590 public void addProposalListener(IProposalListener listener) { |
1578 fProposalListeners.add(listener); | 1591 fProposalListeners.add(cast(Object)listener); |
1579 } | 1592 } |
1580 | 1593 |
1581 /** | 1594 /** |
1582 * Tells whether the support for colored labels is enabled. | 1595 * Tells whether the support for colored labels is enabled. |
1583 * | 1596 * |