comparison dwtx/jface/internal/text/link/contentassist/CompletionProposalPopup2.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 7926b636c282
children
comparison
equal deleted inserted replaced
161:f8d52b926852 162:1a5b8f8129df
88 /** The associated content assistant */ 88 /** The associated content assistant */
89 private ContentAssistant2 fContentAssistant; 89 private ContentAssistant2 fContentAssistant;
90 /** The used additional info controller */ 90 /** The used additional info controller */
91 private AdditionalInfoController2 fAdditionalInfoController; 91 private AdditionalInfoController2 fAdditionalInfoController;
92 /** The closing strategy for this completion proposal popup */ 92 /** The closing strategy for this completion proposal popup */
93 private PopupCloser2 fPopupCloser= new PopupCloser2(); 93 private PopupCloser2 fPopupCloser;
94 /** The popup shell */ 94 /** The popup shell */
95 private Shell fProposalShell; 95 private Shell fProposalShell;
96 /** The proposal table */ 96 /** The proposal table */
97 private Table fProposalTable; 97 private Table fProposalTable;
98 /** Indicates whether a completion proposal is being inserted */ 98 /** Indicates whether a completion proposal is being inserted */
99 private bool fInserting= false; 99 private bool fInserting= false;
100 /** The key listener to control navigation */ 100 /** The key listener to control navigation */
101 private KeyListener fKeyListener; 101 private KeyListener fKeyListener;
102 /** List of document events used for filtering proposals */ 102 /** List of document events used for filtering proposals */
103 private List fDocumentEvents= new ArrayList(); 103 private List fDocumentEvents;
104 /** Listener filling the document event queue */ 104 /** Listener filling the document event queue */
105 private IDocumentListener fDocumentListener; 105 private IDocumentListener fDocumentListener;
106 /** Reentrance count for <code>filterProposals</code> */ 106 /** Reentrance count for <code>filterProposals</code> */
107 private long fInvocationCounter= 0; 107 private long fInvocationCounter= 0;
108 /** The filter list of proposals */ 108 /** The filter list of proposals */
166 * @param viewer the viewer on top of which this popup appears 166 * @param viewer the viewer on top of which this popup appears
167 * @param infoController the info control collaborating with this popup 167 * @param infoController the info control collaborating with this popup
168 * @since 2.0 168 * @since 2.0
169 */ 169 */
170 public this(ContentAssistant2 contentAssistant, ITextViewer viewer, AdditionalInfoController2 infoController) { 170 public this(ContentAssistant2 contentAssistant, ITextViewer viewer, AdditionalInfoController2 infoController) {
171 fPopupCloser= new PopupCloser2();
172 fDocumentEvents= new ArrayList();
171 173
172 fModificationEditingSupport_init(); 174 fModificationEditingSupport_init();
173 fFocusEditingSupport_init(); 175 fFocusEditingSupport_init();
174 176
175 fContentAssistant= contentAssistant; 177 fContentAssistant= contentAssistant;
519 fLastProposal= null; 521 fLastProposal= null;
520 } 522 }
521 523
522 fFilteredProposals= null; 524 fFilteredProposals= null;
523 525
524 fContentAssistant.possibleCompletionsClosed(); 526 fContentAssistant.possibleCompletionsClosed_package();
525 } 527 }
526 528
527 /** 529 /**
528 *Returns whether this popup is active. It is active if the propsal selector is visible. 530 *Returns whether this popup is active. It is active if the propsal selector is visible.
529 * 531 *
577 579
578 item.setText(displayString); 580 item.setText(displayString);
579 if (fIsColoredLabelsSupportEnabled) 581 if (fIsColoredLabelsSupportEnabled)
580 TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges); 582 TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
581 583
582 item.setData(p); 584 item.setData(cast(Object)p);
583 585
584 if (validate && validateProposal(document, p, endOffset, null)) { 586 if (validate && validateProposal(document, p, endOffset, null)) {
585 selectionIndex= i; 587 selectionIndex= i;
586 validate= false; 588 validate= false;
587 } 589 }
621 * @param table the table to compute the height for 623 * @param table the table to compute the height for
622 * @param rows the number of rows to compute the height for 624 * @param rows the number of rows to compute the height for
623 * @return the height hint for <code>table</code> 625 * @return the height hint for <code>table</code>
624 */ 626 */
625 private int getTableHeightHint(Table table, int rows) { 627 private int getTableHeightHint(Table table, int rows) {
626 if (table.getFont().equals(JFaceResources.getDefaultFont())) 628 if (table.getFont().opEquals(JFaceResources.getDefaultFont()))
627 table.setFont(JFaceResources.getDialogFont()); 629 table.setFont(JFaceResources.getDialogFont());
628 int result= table.getItemHeight() * rows; 630 int result= table.getItemHeight() * rows;
629 if (table.getLinesVisible()) 631 if (table.getLinesVisible())
630 result+= table.getGridLineWidth() * (rows - 1); 632 result+= table.getGridLineWidth() * (rows - 1);
631 633
874 * offset of the original invocation of the content assistant. 876 * offset of the original invocation of the content assistant.
875 */ 877 */
876 private void filterProposals() { 878 private void filterProposals() {
877 ++ fInvocationCounter; 879 ++ fInvocationCounter;
878 Control control= fViewer.getTextWidget(); 880 Control control= fViewer.getTextWidget();
879 control.getDisplay().asyncExec(new class() Runnable { 881 control.getDisplay().asyncExec(dgRunnable( (long fInvocationCounter_) {
880 long fCounter= fInvocationCounter; 882 long fCounter= fInvocationCounter_;
881 public void run() { 883
882 884 if (fCounter !is fInvocationCounter) return;
883 if (fCounter !is fInvocationCounter) return; 885
884 886 int offset= fViewer.getSelectedRange().x;
885 int offset= fViewer.getSelectedRange().x; 887 ICompletionProposal[] proposals= null;
886 ICompletionProposal[] proposals= null; 888 try {
887 try { 889 if (offset > -1) {
888 if (offset > -1) { 890 DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents);
889 DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents); 891 proposals= computeFilteredProposals(offset, event);
890 proposals= computeFilteredProposals(offset, event);
891 }
892 } catch (BadLocationException x) {
893 } finally {
894 fDocumentEvents.clear();
895 } 892 }
896 fFilterOffset= offset; 893 } catch (BadLocationException x) {
897 894 } finally {
898 if (proposals !is null && proposals.length > 0) 895 fDocumentEvents.clear();
899 setProposals(proposals); 896 }
900 else 897 fFilterOffset= offset;
901 hide(); 898
902 } 899 if (proposals !is null && proposals.length > 0)
903 }); 900 setProposals(proposals);
901 else
902 hide();
903 }, fInvocationCounter));
904 } 904 }
905 905
906 /** 906 /**
907 * Computes the subset of already computed propsals that are still valid for 907 * Computes the subset of already computed propsals that are still valid for
908 * the given offset. 908 * the given offset.
935 935
936 if (cast(ICompletionProposalExtension2)proposals[i] ) { 936 if (cast(ICompletionProposalExtension2)proposals[i] ) {
937 937
938 ICompletionProposalExtension2 p= cast(ICompletionProposalExtension2) proposals[i]; 938 ICompletionProposalExtension2 p= cast(ICompletionProposalExtension2) proposals[i];
939 if (p.validate(document, offset, event)) 939 if (p.validate(document, offset, event))
940 filtered.add(p); 940 filtered.add(cast(Object)p);
941 941
942 } else if (cast(ICompletionProposalExtension)proposals[i] ) { 942 } else if (cast(ICompletionProposalExtension)proposals[i] ) {
943 943
944 ICompletionProposalExtension p= cast(ICompletionProposalExtension) proposals[i]; 944 ICompletionProposalExtension p= cast(ICompletionProposalExtension) proposals[i];
945 if (p.isValidFor(document, offset)) 945 if (p.isValidFor(document, offset))
946 filtered.add(p); 946 filtered.add(cast(Object)p);
947 947
948 } else { 948 } else {
949 // restore original behavior 949 // restore original behavior
950 fInvocationOffset= offset; 950 fInvocationOffset= offset;
951 fComputedProposals= computeProposals(fInvocationOffset); 951 fComputedProposals= computeProposals(fInvocationOffset);
952 return fComputedProposals; 952 return fComputedProposals;
953 } 953 }
954 } 954 }
955 955
956 ICompletionProposal[] p= new ICompletionProposal[filtered.size()]; 956 return arraycast!(ICompletionProposal)(filtered.toArray());
957 filtered.toArray(p);
958 return p;
959 } 957 }
960 958
961 /** 959 /**
962 * Requests the proposal shell to take focus. 960 * Requests the proposal shell to take focus.
963 * 961 *