comparison dwtx/jface/text/contentassist/CompletionProposalPopup.d @ 158:25f1f92fa3df

...
author Frank Benoit <benoit@tionex.de>
date Tue, 26 Aug 2008 02:46:34 +0200
parents f70d9508c95c
children 7926b636c282
comparison
equal deleted inserted replaced
157:7f75eaa8103a 158:25f1f92fa3df
109 import dwtx.jface.text.IRegion; 109 import dwtx.jface.text.IRegion;
110 import dwtx.jface.text.IRewriteTarget; 110 import dwtx.jface.text.IRewriteTarget;
111 import dwtx.jface.text.ITextViewer; 111 import dwtx.jface.text.ITextViewer;
112 import dwtx.jface.text.ITextViewerExtension; 112 import dwtx.jface.text.ITextViewerExtension;
113 import dwtx.jface.text.TextUtilities; 113 import dwtx.jface.text.TextUtilities;
114 import dwtx.jface.text.AbstractInformationControlManager.Anchor; 114 import dwtx.jface.text.AbstractInformationControlManager;
115 import dwtx.jface.util.Geometry; 115 import dwtx.jface.util.Geometry;
116 import dwtx.jface.viewers.StyledString; 116 import dwtx.jface.viewers.StyledString;
117 117
118 118
119 /** 119 /**
496 * be made out of an auto activation context. 496 * be made out of an auto activation context.
497 * 497 *
498 * @param autoActivated <code>true</code> if auto activation context 498 * @param autoActivated <code>true</code> if auto activation context
499 * @return an error message or <code>null</code> in case of no error 499 * @return an error message or <code>null</code> in case of no error
500 */ 500 */
501 public String showProposals(final bool autoActivated) { 501 public String showProposals(bool autoActivated) {
502 502
503 if (fKeyListener is null) 503 if (fKeyListener is null)
504 fKeyListener= new ProposalSelectionListener(); 504 fKeyListener= new ProposalSelectionListener();
505 505
506 final Control control= fContentAssistSubjectControlAdapter.getControl(); 506 final Control control= fContentAssistSubjectControlAdapter.getControl();
508 if (!Helper.okToUse(fProposalShell) && control !is null && !control.isDisposed()) { 508 if (!Helper.okToUse(fProposalShell) && control !is null && !control.isDisposed()) {
509 // add the listener before computing the proposals so we don't move the caret 509 // add the listener before computing the proposals so we don't move the caret
510 // when the user types fast. 510 // when the user types fast.
511 fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener); 511 fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener);
512 512
513 BusyIndicator.showWhile(control.getDisplay(), new class() Runnable { 513 BusyIndicator.showWhile(control.getDisplay(), dgRunnable((bool autoActivated_) {
514 public void run() { 514
515 515 fInvocationOffset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
516 fInvocationOffset= fContentAssistSubjectControlAdapter.getSelectedRange().x; 516 fFilterOffset= fInvocationOffset;
517 fFilterOffset= fInvocationOffset; 517 fLastCompletionOffset= fFilterOffset;
518 fLastCompletionOffset= fFilterOffset; 518 fComputedProposals= computeProposals(fInvocationOffset);
519 fComputedProposals= computeProposals(fInvocationOffset); 519
520 520 int count= (fComputedProposals is null ? 0 : fComputedProposals.length);
521 int count= (fComputedProposals is null ? 0 : fComputedProposals.length); 521 if (count is 0 && hideWhenNoProposals(autoActivated_))
522 if (count is 0 && hideWhenNoProposals(autoActivated)) 522 return;
523 return; 523
524 524 if (count is 1 && !autoActivated_ && canAutoInsert(fComputedProposals[0])) {
525 if (count is 1 && !autoActivated && canAutoInsert(fComputedProposals[0])) { 525 insertProposal(fComputedProposals[0], cast(wchar) 0, 0, fInvocationOffset);
526 insertProposal(fComputedProposals[0], cast(wchar) 0, 0, fInvocationOffset); 526 hide();
527 hide(); 527 } else {
528 } else { 528 createProposalSelector();
529 createProposalSelector(); 529 setProposals(fComputedProposals, false);
530 setProposals(fComputedProposals, false); 530 displayProposals();
531 displayProposals();
532 }
533 } 531 }
534 }); 532 }, autoActivated ));
535 } else { 533 } else {
536 fLastCompletionOffset= fFilterOffset; 534 fLastCompletionOffset= fFilterOffset;
537 handleRepeatedInvocation(); 535 handleRepeatedInvocation();
538 } 536 }
539 537
723 * Adds command support to the given control. 721 * Adds command support to the given control.
724 * 722 *
725 * @param control the control to watch for focus 723 * @param control the control to watch for focus
726 * @since 3.2 724 * @since 3.2
727 */ 725 */
728 private void addCommandSupport(final Control control) { 726 private void addCommandSupport(Control control) {
729 final KeySequence commandSequence= fContentAssistant.getRepeatedInvocationKeySequence(); 727 final KeySequence commandSequence= fContentAssistant.getRepeatedInvocationKeySequence();
730 if (commandSequence !is null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) { 728 if (commandSequence !is null && !commandSequence.isEmpty() && fContentAssistant.isRepeatedInvocationMode()) {
731 control.addFocusListener(new class() FocusListener { 729 control.addFocusListener(new class(control,commandSequence) FocusListener {
730 Control control_;
731 KeySequence commandSequence_;
732 this(Control a, KeySequence b){
733 control_=a;
734 commandSequence_=b;
735 }
732 private CommandKeyListener fCommandKeyListener; 736 private CommandKeyListener fCommandKeyListener;
733 public void focusGained(FocusEvent e) { 737 public void focusGained(FocusEvent e) {
734 if (Helper.okToUse(control)) { 738 if (Helper.okToUse(control_)) {
735 if (fCommandKeyListener is null) { 739 if (fCommandKeyListener is null) {
736 fCommandKeyListener= new CommandKeyListener(commandSequence); 740 fCommandKeyListener= new CommandKeyListener(commandSequence_);
737 fProposalTable.addKeyListener(fCommandKeyListener); 741 fProposalTable.addKeyListener(fCommandKeyListener);
738 } 742 }
739 } 743 }
740 } 744 }
741 public void focusLost(FocusEvent e) { 745 public void focusLost(FocusEvent e) {
742 if (fCommandKeyListener !is null) { 746 if (fCommandKeyListener !is null) {
743 control.removeKeyListener(fCommandKeyListener); 747 control_.removeKeyListener(fCommandKeyListener);
744 fCommandKeyListener= null; 748 fCommandKeyListener= null;
745 } 749 }
746 } 750 }
747 }); 751 });
748 } 752 }
749 control.addFocusListener(new class() FocusListener { 753 control.addFocusListener(new class(control) FocusListener {
754 Control control_;
750 private TraverseListener fTraverseListener; 755 private TraverseListener fTraverseListener;
756 this(Control a){
757 control_=a;
758 }
751 public void focusGained(FocusEvent e) { 759 public void focusGained(FocusEvent e) {
752 if (Helper.okToUse(control)) { 760 if (Helper.okToUse(control_)) {
753 if (fTraverseListener is null) { 761 if (fTraverseListener is null) {
754 fTraverseListener= new class() TraverseListener { 762 fTraverseListener= new class() TraverseListener {
755 public void keyTraversed(TraverseEvent event) { 763 public void keyTraversed(TraverseEvent event) {
756 if (event.detail is DWT.TRAVERSE_TAB_NEXT) { 764 if (event.detail is DWT.TRAVERSE_TAB_NEXT) {
757 IInformationControl iControl= fAdditionalInfoController.getCurrentInformationControl2(); 765 IInformationControl iControl= fAdditionalInfoController.getCurrentInformationControl2();
766 } 774 }
767 } 775 }
768 } 776 }
769 public void focusLost(FocusEvent e) { 777 public void focusLost(FocusEvent e) {
770 if (fTraverseListener !is null) { 778 if (fTraverseListener !is null) {
771 control.removeTraverseListener(fTraverseListener); 779 control_.removeTraverseListener(fTraverseListener);
772 fTraverseListener= null; 780 fTraverseListener= null;
773 } 781 }
774 } 782 }
775 }); 783 });
776 } 784 }
916 * @param trigger the trigger character 924 * @param trigger the trigger character
917 * @param stateMask the state mask 925 * @param stateMask the state mask
918 * @param offset the offset 926 * @param offset the offset
919 * @since 2.1 927 * @since 2.1
920 */ 928 */
921 private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) { 929 private void insertProposal(ICompletionProposal p, char trigger, int stateMask, int offset) {
922 930
923 fInserting= true; 931 fInserting= true;
924 IRewriteTarget target= null; 932 IRewriteTarget target= null;
925 IEditingSupport helper= new class() IEditingSupport { 933 IEditingSupport helper= new class(offset) IEditingSupport {
926 934 int offset_;
935 this(int a){
936 offset_=a;
937 }
927 public bool isOriginator(DocumentEvent event, IRegion focus) { 938 public bool isOriginator(DocumentEvent event, IRegion focus) {
928 return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset; 939 return focus.getOffset() <= offset_ && focus.getOffset() + focus.getLength() >= offset_;
929 } 940 }
930 941
931 public bool ownsFocusShell() { 942 public bool ownsFocusShell() {
932 return false; 943 return false;
933 } 944 }
1503 fComputedProposals= computeProposals(fInvocationOffset); 1514 fComputedProposals= computeProposals(fInvocationOffset);
1504 return fComputedProposals; 1515 return fComputedProposals;
1505 } 1516 }
1506 } 1517 }
1507 1518
1508 return (ICompletionProposal[]) filtered.toArray(new ICompletionProposal[filtered.size()]); 1519 return arraycast!(ICompletionProposal)( filtered.toArray());
1509 } 1520 }
1510 1521
1511 /** 1522 /**
1512 * Requests the proposal shell to take focus. 1523 * Requests the proposal shell to take focus.
1513 * 1524 *