comparison dwtx/jface/text/contentassist/ContentAssistant.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
47 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport 47 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport
48 48
49 import dwt.dwthelper.utils; 49 import dwt.dwthelper.utils;
50 import dwtx.dwtxhelper.Collection; 50 import dwtx.dwtxhelper.Collection;
51 import dwtx.dwtxhelper.JThread; 51 import dwtx.dwtxhelper.JThread;
52 import tango.core.sync.Mutex;
53 import tango.core.sync.Condition;
52 54
53 import dwt.DWT; 55 import dwt.DWT;
54 import dwt.DWTError; 56 import dwt.DWTError;
55 import dwt.custom.VerifyKeyListener; 57 import dwt.custom.VerifyKeyListener;
56 import dwt.events.ControlEvent; 58 import dwt.events.ControlEvent;
274 * 276 *
275 * @since 3.4 protected, was added in 2.1 as private class 277 * @since 3.4 protected, was added in 2.1 as private class
276 */ 278 */
277 protected class AutoAssistListener : KeyAdapter , KeyListener, Runnable, VerifyKeyListener { 279 protected class AutoAssistListener : KeyAdapter , KeyListener, Runnable, VerifyKeyListener {
278 280
281 // DWT intf impl
282 public void keyReleased(KeyEvent e) {
283 super.keyReleased(e);
284 }
285
279 private JThread fThread; 286 private JThread fThread;
280 private bool fIsReset= false; 287 private bool fIsReset= false;
281 private Object fMutex= new Object(); 288 private Mutex fMutex;
289 private Condition fMutex_cond;
282 private int fShowStyle; 290 private int fShowStyle;
283 291
284 private const static int SHOW_PROPOSALS= 1; 292 private const static int SHOW_PROPOSALS= 1;
285 private const static int SHOW_CONTEXT_INFO= 2; 293 private const static int SHOW_CONTEXT_INFO= 2;
286 294
287 protected this() { 295 protected this() {
296 fMutex = new Mutex();
297 fMutex_cond = new Condition(fMutex);
288 } 298 }
289 299
290 protected void start(int showStyle) { 300 protected void start(int showStyle) {
291 fShowStyle= showStyle; 301 fShowStyle= showStyle;
292 fThread= new Thread(&run); 302 fThread= new JThread(this);
293 fThread.name = JFaceTextMessages.getString("ContentAssistant.assist_delay_timer_name"); //$NON-NLS-1$ 303 fThread.setName( JFaceTextMessages.getString("ContentAssistant.assist_delay_timer_name")); //$NON-NLS-1$
294 fThread.start(); 304 fThread.start();
295 } 305 }
296 306
297 public void run() { 307 public override void run() {
298 try { 308 try {
299 while (true) { 309 while (true) {
300 synchronized (fMutex) { 310 synchronized (fMutex) {
301 if (fAutoActivationDelay !is 0) 311 if (fAutoActivationDelay !is 0)
302 fMutex.wait(fAutoActivationDelay); 312 fMutex_cond.wait(fAutoActivationDelay);
303 if (fIsReset) { 313 if (fIsReset) {
304 fIsReset= false; 314 fIsReset= false;
305 continue; 315 continue;
306 } 316 }
307 } 317 }
315 325
316 protected void reset(int showStyle) { 326 protected void reset(int showStyle) {
317 synchronized (fMutex) { 327 synchronized (fMutex) {
318 fShowStyle= showStyle; 328 fShowStyle= showStyle;
319 fIsReset= true; 329 fIsReset= true;
320 fMutex.notifyAll(); 330 fMutex_cond.notifyAll();
321 } 331 }
322 } 332 }
323 333
324 protected void stop() { 334 protected void stop() {
325 Thread threadToStop= fThread; 335 JThread threadToStop= fThread;
326 if (threadToStop !is null && threadToStop.isAlive()) 336 if (threadToStop !is null && threadToStop.isAlive())
327 threadToStop.interrupt(); 337 threadToStop.interrupt();
328 } 338 }
329 339
330 private bool contains(char[] characters, char character) { 340 private bool contains(char[] characters, char character) {
430 public const static int LAYOUT_CONTEXT_SELECTOR= 1; 440 public const static int LAYOUT_CONTEXT_SELECTOR= 1;
431 /** The presentation type for the context information hover . */ 441 /** The presentation type for the context information hover . */
432 public const static int LAYOUT_CONTEXT_INFO_POPUP= 2; 442 public const static int LAYOUT_CONTEXT_INFO_POPUP= 2;
433 443
434 int fContextType= LAYOUT_CONTEXT_SELECTOR; 444 int fContextType= LAYOUT_CONTEXT_SELECTOR;
435 Shell[] fShells= new Shell[3]; 445 Shell[] fShells;
436 Object[] fPopups= new Object[3]; 446 Object[] fPopups;
447
448 this(){
449 fShells= new Shell[3];
450 fPopups= new Object[3];
451 }
437 452
438 protected void add(Object popup, Shell shell, int type, int offset) { 453 protected void add(Object popup, Shell shell, int type, int offset) {
439 Assert.isNotNull(popup); 454 Assert.isNotNull(popup);
440 Assert.isTrue(shell !is null && !shell.isDisposed()); 455 Assert.isTrue(shell !is null && !shell.isDisposed());
441 checkType(type); 456 checkType(type);
666 */ 681 */
667 protected Rectangle computeBoundsAboveBelow(Shell shell, Point preferred, int offset) { 682 protected Rectangle computeBoundsAboveBelow(Shell shell, Point preferred, int offset) {
668 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); 683 Control subjectControl= fContentAssistSubjectControlAdapter.getControl();
669 Display display= subjectControl.getDisplay(); 684 Display display= subjectControl.getDisplay();
670 Rectangle caret= getCaretRectangle(offset); 685 Rectangle caret= getCaretRectangle(offset);
671 Monitor monitor= getClosestMonitor(display, caret); 686 dwt.widgets.Monitor.Monitor monitor= getClosestMonitor(display, caret);
672 Rectangle bounds= monitor.getClientArea(); 687 Rectangle bounds= monitor.getClientArea();
673 Geometry.moveInside(caret, bounds); 688 Geometry.moveInside(caret, bounds);
674 689
675 int spaceAbove= caret.y - bounds.y; 690 int spaceAbove= caret.y - bounds.y;
676 int caretLowerY= caret.y + caret.height; 691 int caretLowerY= caret.y + caret.height;
706 */ 721 */
707 protected Rectangle computeBoundsBelowAbove(Shell shell, Point preferred, int offset, CompletionProposalPopup popup) { 722 protected Rectangle computeBoundsBelowAbove(Shell shell, Point preferred, int offset, CompletionProposalPopup popup) {
708 Control subjectControl= fContentAssistSubjectControlAdapter.getControl(); 723 Control subjectControl= fContentAssistSubjectControlAdapter.getControl();
709 Display display= subjectControl.getDisplay(); 724 Display display= subjectControl.getDisplay();
710 Rectangle caret= getCaretRectangle(offset); 725 Rectangle caret= getCaretRectangle(offset);
711 Monitor monitor= getClosestMonitor(display, caret); 726 dwt.widgets.Monitor.Monitor monitor= getClosestMonitor(display, caret);
712 Rectangle bounds= monitor.getClientArea(); 727 Rectangle bounds= monitor.getClientArea();
713 Geometry.moveInside(caret, bounds); 728 Geometry.moveInside(caret, bounds);
714 729
715 int threshold= popup is null ? Integer.MAX_VALUE : popup.getMinimalHeight(); 730 int threshold= popup is null ? Integer.MAX_VALUE : popup.getMinimalHeight();
716 int spaceAbove= caret.y - bounds.y; 731 int spaceAbove= caret.y - bounds.y;
759 p.y += size.y; 774 p.y += size.y;
760 775
761 p= parent.toDisplay(p); 776 p= parent.toDisplay(p);
762 777
763 Point shellSize= shell.getSize(); 778 Point shellSize= shell.getSize();
764 Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0)); 779 dwt.widgets.Monitor.Monitor monitor= getClosestMonitor(parent.getDisplay(), new Rectangle(p.x, p.y, 0, 0));
765 Rectangle displayBounds= monitor.getClientArea(); 780 Rectangle displayBounds= monitor.getClientArea();
766 constrainLocation(p, shellSize, displayBounds); 781 constrainLocation(p, shellSize, displayBounds);
767 782
768 return p; 783 return p;
769 } 784 }
798 * @param rectangle 813 * @param rectangle
799 * rectangle to find (display coordinates) 814 * rectangle to find (display coordinates)
800 * @return the monitor closest to the given point 815 * @return the monitor closest to the given point
801 * @since 3.3 816 * @since 3.3
802 */ 817 */
803 private Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) { 818 private dwt.widgets.Monitor.Monitor getClosestMonitor(Display toSearch, Rectangle rectangle) {
804 int closest = Integer.MAX_VALUE; 819 int closest = Integer.MAX_VALUE;
805 820
806 Point toFind= Geometry.centerPoint(rectangle); 821 Point toFind= Geometry.centerPoint(rectangle);
807 Monitor[] monitors = toSearch.getMonitors(); 822 dwt.widgets.Monitor.Monitor[] monitors = toSearch.getMonitors();
808 Monitor result = monitors[0]; 823 dwt.widgets.Monitor.Monitor result = monitors[0];
809 824
810 for (int idx = 0; idx < monitors.length; idx++) { 825 for (int idx = 0; idx < monitors.length; idx++) {
811 Monitor current = monitors[idx]; 826 dwt.widgets.Monitor.Monitor current = monitors[idx];
812 827
813 Rectangle clientArea = current.getClientArea(); 828 Rectangle clientArea = current.getClientArea();
814 829
815 if (clientArea.contains(toFind)) { 830 if (clientArea.contains(toFind)) {
816 return current; 831 return current;
838 * 853 *
839 * @param e the verify event 854 * @param e the verify event
840 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent) 855 * @see VerifyKeyListener#verifyKey(dwt.events.VerifyEvent)
841 */ 856 */
842 public void verifyKey(VerifyEvent e) { 857 public void verifyKey(VerifyEvent e) {
843 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); 858 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.dup );
844 for (int i= 0; i < listeners.length; i++) { 859 for (int i= 0; i < listeners.length; i++) {
845 if (listeners[i] !is null) { 860 if (listeners[i] !is null) {
846 if (!listeners[i].verifyKey(e) || !e.doit) 861 if (!listeners[i].verifyKey(e) || !e.doit)
847 break; 862 break;
848 } 863 }
856 */ 871 */
857 public void processEvent(VerifyEvent event) { 872 public void processEvent(VerifyEvent event) {
858 873
859 installKeyListener(); 874 installKeyListener();
860 875
861 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.clone() ); 876 IContentAssistListener[] listeners= arraycast!(IContentAssistListener)( fListeners.dup );
862 for (int i= 0; i < listeners.length; i++) { 877 for (int i= 0; i < listeners.length; i++) {
863 if (listeners[i] !is null) { 878 if (listeners[i] !is null) {
864 listeners[i].processEvent(event); 879 listeners[i].processEvent(event);
865 if (!event.doit) 880 if (!event.doit)
866 return; 881 return;
876 */ 891 */
877 public static const String STORE_SIZE_X= "size.x"; //$NON-NLS-1$ 892 public static const String STORE_SIZE_X= "size.x"; //$NON-NLS-1$
878 public static const String STORE_SIZE_Y= "size.y"; //$NON-NLS-1$ 893 public static const String STORE_SIZE_Y= "size.y"; //$NON-NLS-1$
879 894
880 // Content-Assist Listener types 895 // Content-Assist Listener types
881 final static int CONTEXT_SELECTOR= 0; 896 const static int CONTEXT_SELECTOR= 0;
882 final static int PROPOSAL_SELECTOR= 1; 897 const static int PROPOSAL_SELECTOR= 1;
883 final static int CONTEXT_INFO_POPUP= 2; 898 const static int CONTEXT_INFO_POPUP= 2;
884 899
885 /** 900 /**
886 * The popup priority: &gt; linked position proposals and hover pop-ups. Default value: 901 * The popup priority: &gt; linked position proposals and hover pop-ups. Default value:
887 * <code>20</code>; 902 * <code>20</code>;
888 * 903 *
1073 fProcessors= new HashMap(); 1088 fProcessors= new HashMap();
1074 1089
1075 if (processor is null) 1090 if (processor is null)
1076 fProcessors.remove(contentType); 1091 fProcessors.remove(contentType);
1077 else 1092 else
1078 fProcessors.put(contentType, processor); 1093 fProcessors.put(contentType, cast(Object)processor);
1079 } 1094 }
1080 1095
1081 /* 1096 /*
1082 * @see IContentAssistant#getContentAssistProcessor 1097 * @see IContentAssistant#getContentAssistProcessor
1083 */ 1098 */
1099 return ""; //$NON-NLS-1$ 1114 return ""; //$NON-NLS-1$
1100 1115
1101 StringBuffer buf= new StringBuffer(5); 1116 StringBuffer buf= new StringBuffer(5);
1102 Iterator iter= fProcessors.entrySet().iterator(); 1117 Iterator iter= fProcessors.entrySet().iterator();
1103 while (iter.hasNext()) { 1118 while (iter.hasNext()) {
1104 Entry entry= cast(Entry) iter.next(); 1119 Map.Entry entry= cast(Map.Entry) iter.next();
1105 IContentAssistProcessor processor= cast(IContentAssistProcessor) entry.getValue(); 1120 IContentAssistProcessor processor= cast(IContentAssistProcessor) entry.getValue();
1106 char[] triggers= processor.getCompletionProposalAutoActivationCharacters(); 1121 char[] triggers= processor.getCompletionProposalAutoActivationCharacters();
1107 if (triggers !is null) 1122 if (triggers !is null)
1108 buf.append(triggers); 1123 buf.append(triggers);
1109 triggers= processor.getContextInformationAutoActivationCharacters(); 1124 triggers= processor.getContextInformationAutoActivationCharacters();
1412 AdditionalInfoController controller= null; 1427 AdditionalInfoController controller= null;
1413 if (fInformationControlCreator !is null) { 1428 if (fInformationControlCreator !is null) {
1414 int delay= fAutoActivationDelay; 1429 int delay= fAutoActivationDelay;
1415 if (delay is 0) 1430 if (delay is 0)
1416 delay= DEFAULT_AUTO_ACTIVATION_DELAY; 1431 delay= DEFAULT_AUTO_ACTIVATION_DELAY;
1417 delay= Math.round(delay * 1.5f); 1432 delay= cast(int)Math.round(delay * 1.5f);
1418 controller= new AdditionalInfoController(fInformationControlCreator, delay); 1433 controller= new AdditionalInfoController(fInformationControlCreator, delay);
1419 } 1434 }
1420 1435
1421 fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this); 1436 fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
1422 fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller); 1437 fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
2239 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#addCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) 2254 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#addCompletionListener(dwtx.jface.text.contentassist.ICompletionListener)
2240 * @since 3.2 2255 * @since 3.2
2241 */ 2256 */
2242 public void addCompletionListener(ICompletionListener listener) { 2257 public void addCompletionListener(ICompletionListener listener) {
2243 Assert.isLegal(listener !is null); 2258 Assert.isLegal(listener !is null);
2244 fCompletionListeners.add(listener); 2259 fCompletionListeners.add(cast(Object)listener);
2245 } 2260 }
2246 2261
2247 /* 2262 /*
2248 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#removeCompletionListener(dwtx.jface.text.contentassist.ICompletionListener) 2263 * @see dwtx.jface.text.contentassist.IContentAssistantExtension2#removeCompletionListener(dwtx.jface.text.contentassist.ICompletionListener)
2249 * @since 3.2 2264 * @since 3.2
2250 */ 2265 */
2251 public void removeCompletionListener(ICompletionListener listener) { 2266 public void removeCompletionListener(ICompletionListener listener) {
2252 fCompletionListeners.remove(listener); 2267 fCompletionListeners.remove(cast(Object)listener);
2253 } 2268 }
2254 2269
2255 /** 2270 /**
2256 * Fires a session begin event to all registered {@link ICompletionListener}s. 2271 * Fires a session begin event to all registered {@link ICompletionListener}s.
2257 * 2272 *
2476 * @since 3.4 2491 * @since 3.4
2477 */ 2492 */
2478 protected final void registerHandler(String commandId, IHandler handler) { 2493 protected final void registerHandler(String commandId, IHandler handler) {
2479 if (fHandlers is null) 2494 if (fHandlers is null)
2480 fHandlers= new HashMap(2); 2495 fHandlers= new HashMap(2);
2481 fHandlers.put(commandId, handler); 2496 fHandlers.put(commandId, cast(Object)handler);
2482 } 2497 }
2483 2498
2484 /** 2499 /**
2485 * Tells whether the support for colored labels is enabled. 2500 * Tells whether the support for colored labels is enabled.
2486 * 2501 *