comparison dwtx/jface/text/contentassist/CompletionProposalPopup.d @ 162:1a5b8f8129df

...
author Frank Benoit <benoit@tionex.de>
date Mon, 08 Sep 2008 00:51:37 +0200
parents 7926b636c282
children c3583c6ec027
comparison
equal deleted inserted replaced
161:f8d52b926852 162:1a5b8f8129df
310 if (!Helper.okToUse(fProposalShell)) 310 if (!Helper.okToUse(fProposalShell))
311 return; 311 return;
312 312
313 int accelerator= SWTKeySupport.convertEventToUnmodifiedAccelerator(e); 313 int accelerator= SWTKeySupport.convertEventToUnmodifiedAccelerator(e);
314 KeySequence sequence= KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator)); 314 KeySequence sequence= KeySequence.getInstance(SWTKeySupport.convertAcceleratorToKeyStroke(accelerator));
315 if (sequence.equals(fCommandSequence)) 315 if (sequence==/++/fCommandSequence)
316 if (fContentAssistant.isPrefixCompletionEnabled()) 316 if (fContentAssistant.isPrefixCompletionEnabled())
317 incrementalComplete(); 317 incrementalComplete();
318 else 318 else
319 showProposals(false); 319 showProposals(false);
320 320
656 createMessageText(); 656 createMessageText();
657 } 657 }
658 658
659 GridData data= new GridData(GridData.FILL_BOTH); 659 GridData data= new GridData(GridData.FILL_BOTH);
660 660
661 Point size= fContentAssistant.restoreCompletionProposalPopupSize(); 661 Point size= fContentAssistant.restoreCompletionProposalPopupSize_package();
662 if (size !is null) { 662 if (size !is null) {
663 fProposalTable.setLayoutData(data); 663 fProposalTable.setLayoutData(data);
664 fProposalShell.setSize(size); 664 fProposalShell.setSize(size);
665 } else { 665 } else {
666 int height= fProposalTable.getItemHeight() * 10; 666 int height= fProposalTable.getItemHeight() * 10;
667 // use golden ratio as default aspect ratio 667 // use golden ratio as default aspect ratio
668 final double aspectRatio= (1 + Math.sqrt(5)) / 2; 668 double aspectRatio= (1 + Math.sqrt(5.0f)) / 2;
669 int width= cast(int) (height * aspectRatio); 669 int width= cast(int) (height * aspectRatio);
670 Rectangle trim= fProposalTable.computeTrim(0, 0, width, height); 670 Rectangle trim= fProposalTable.computeTrim(0, 0, width, height);
671 data.heightHint= trim.height; 671 data.heightHint= trim.height;
672 data.widthHint= trim.width; 672 data.widthHint= trim.width;
673 fProposalTable.setLayoutData(data); 673 fProposalTable.setLayoutData(data);
840 private void createMessageText() { 840 private void createMessageText() {
841 if (fMessageText is null) { 841 if (fMessageText is null) {
842 fMessageText= new Label(fProposalShell, DWT.RIGHT); 842 fMessageText= new Label(fProposalShell, DWT.RIGHT);
843 GridData textData= new GridData(DWT.FILL, DWT.BOTTOM, true, false); 843 GridData textData= new GridData(DWT.FILL, DWT.BOTTOM, true, false);
844 fMessageText.setLayoutData(textData); 844 fMessageText.setLayoutData(textData);
845 fMessageText.setText(fContentAssistant.getStatusMessage() + " "); //$NON-NLS-1$ 845 fMessageText.setText(fContentAssistant.getStatusMessage() ~ " "); //$NON-NLS-1$
846 if (fMessageTextFont is null) { 846 if (fMessageTextFont is null) {
847 Font font= fMessageText.getFont(); 847 Font font= fMessageText.getFont();
848 Display display= fProposalShell.getDisplay(); 848 Display display= fProposalShell.getDisplay();
849 FontData[] fontDatas= font.getFontData(); 849 FontData[] fontDatas= font.getFontData();
850 for (int i= 0; i < fontDatas.length; i++) 850 for (int i= 0; i < fontDatas.length; i++)
893 item.setText(displayString); 893 item.setText(displayString);
894 if (fIsColoredLabelsSupportEnabled) 894 if (fIsColoredLabelsSupportEnabled)
895 TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges); 895 TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
896 896
897 item.setImage(current.getImage()); 897 item.setImage(current.getImage());
898 item.setData(current); 898 item.setData(cast(Object)current);
899 } else { 899 } else {
900 // this should not happen, but does on win32 900 // this should not happen, but does on win32
901 } 901 }
902 } 902 }
903 903
1127 } 1127 }
1128 1128
1129 fFilteredProposals= null; 1129 fFilteredProposals= null;
1130 fComputedProposals= null; 1130 fComputedProposals= null;
1131 1131
1132 fContentAssistant.possibleCompletionsClosed(); 1132 fContentAssistant.possibleCompletionsClosed_package();
1133 } 1133 }
1134 1134
1135 /** 1135 /**
1136 *Returns whether this popup is active. It is active if the proposal selector is visible. 1136 *Returns whether this popup is active. It is active if the proposal selector is visible.
1137 * 1137 *
1176 for (int i= 0; i < items.length; i++) { 1176 for (int i= 0; i < items.length; i++) {
1177 TableItem item= items[i]; 1177 TableItem item= items[i];
1178 ICompletionProposal proposal= proposals[i]; 1178 ICompletionProposal proposal= proposals[i];
1179 item.setText(proposal.getDisplayString()); 1179 item.setText(proposal.getDisplayString());
1180 item.setImage(proposal.getImage()); 1180 item.setImage(proposal.getImage());
1181 item.setData(proposal); 1181 item.setData(cast(Object)proposal);
1182 } 1182 }
1183 fProposalTable.setRedraw(true); 1183 fProposalTable.setRedraw(true);
1184 } 1184 }
1185 1185
1186 Point currentLocation= fProposalShell.getLocation(); 1186 Point currentLocation= fProposalShell.getLocation();
1197 * 1197 *
1198 * @return the location of this popup 1198 * @return the location of this popup
1199 */ 1199 */
1200 private Point getLocation() { 1200 private Point getLocation() {
1201 int caret= fContentAssistSubjectControlAdapter.getCaretOffset(); 1201 int caret= fContentAssistSubjectControlAdapter.getCaretOffset();
1202 Rectangle location= fContentAssistant.getLayoutManager().computeBoundsBelowAbove(fProposalShell, fSize is null ? fProposalShell.getSize() : fSize, caret, this); 1202 Rectangle location= fContentAssistant.getLayoutManager().computeBoundsBelowAbove_package(fProposalShell, fSize is null ? fProposalShell.getSize() : fSize, caret, this);
1203 return Geometry.getLocation(location); 1203 return Geometry.getLocation(location);
1204 } 1204 }
1205 1205
1206 /** 1206 /**
1207 * Returns the size of this completion proposal popup. 1207 * Returns the size of this completion proposal popup.
1517 1517
1518 if (cast(ICompletionProposalExtension2)proposals[i] ) { 1518 if (cast(ICompletionProposalExtension2)proposals[i] ) {
1519 1519
1520 ICompletionProposalExtension2 p= cast(ICompletionProposalExtension2) proposals[i]; 1520 ICompletionProposalExtension2 p= cast(ICompletionProposalExtension2) proposals[i];
1521 if (p.validate(document, offset, event)) 1521 if (p.validate(document, offset, event))
1522 filtered.add(p); 1522 filtered.add(cast(Object)p);
1523 1523
1524 } else if (cast(ICompletionProposalExtension)proposals[i] ) { 1524 } else if (cast(ICompletionProposalExtension)proposals[i] ) {
1525 1525
1526 ICompletionProposalExtension p= cast(ICompletionProposalExtension) proposals[i]; 1526 ICompletionProposalExtension p= cast(ICompletionProposalExtension) proposals[i];
1527 if (p.isValidFor(document, offset)) 1527 if (p.isValidFor(document, offset))
1528 filtered.add(p); 1528 filtered.add(cast(Object)p);
1529 1529
1530 } else { 1530 } else {
1531 // restore original behavior 1531 // restore original behavior
1532 fIsFilteredSubset= false; 1532 fIsFilteredSubset= false;
1533 fInvocationOffset= offset; 1533 fInvocationOffset= offset;
1651 1651
1652 // 1: extract pre- and postfix from all remaining proposals 1652 // 1: extract pre- and postfix from all remaining proposals
1653 IDocument document= fContentAssistSubjectControlAdapter.getDocument(); 1653 IDocument document= fContentAssistSubjectControlAdapter.getDocument();
1654 1654
1655 // contains the common postfix in the case that there are any proposals matching our LHS 1655 // contains the common postfix in the case that there are any proposals matching our LHS
1656 StringBuffer rightCasePostfix= null; 1656 StringBuffer rightCasePostfix;
1657 List rightCase= new ArrayList(); 1657 List rightCase= new ArrayList();
1658 1658
1659 bool isWrongCaseMatch= false; 1659 bool isWrongCaseMatch= false;
1660 1660
1661 // the prefix of all case insensitive matches. This differs from the document 1661 // the prefix of all case insensitive matches. This differs from the document
1662 // contents and will be replaced. 1662 // contents and will be replaced.
1663 CharSequence wrongCasePrefix= null; 1663 CharSequence wrongCasePrefix= null;
1664 int wrongCasePrefixStart= 0; 1664 int wrongCasePrefixStart= 0;
1665 // contains the common postfix of all case-insensitive matches 1665 // contains the common postfix of all case-insensitive matches
1666 StringBuffer wrongCasePostfix= null; 1666 StringBuffer wrongCasePostfix;
1667 List wrongCase= new ArrayList(); 1667 List wrongCase= new ArrayList();
1668 1668
1669 for (int i= 0; i < fFilteredProposals.length; i++) { 1669 for (int i= 0; i < fFilteredProposals.length; i++) {
1670 ICompletionProposal proposal= fFilteredProposals[i]; 1670 ICompletionProposal proposal= fFilteredProposals[i];
1671 1671
1673 return false; 1673 return false;
1674 1674
1675 int start= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionStart(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset); 1675 int start= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionStart(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
1676 CharSequence insertion= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionText(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset); 1676 CharSequence insertion= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionText(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
1677 if (insertion is null) 1677 if (insertion is null)
1678 insertion= proposal.getDisplayString(); 1678 insertion= new StringCharSequence(proposal.getDisplayString());
1679 try { 1679 try {
1680 int prefixLength= fFilterOffset - start; 1680 int prefixLength= fFilterOffset - start;
1681 int relativeCompletionOffset= Math.min(insertion.length(), prefixLength); 1681 int relativeCompletionOffset= Math.min(insertion.length(), prefixLength);
1682 String prefix= document.get(start, prefixLength); 1682 String prefix= document.get(start, prefixLength);
1683 if (!isWrongCaseMatch && insertion.toString().startsWith(prefix)) { 1683 if (!isWrongCaseMatch && insertion.toString().startsWith(prefix)) {
1684 isWrongCaseMatch= false; 1684 isWrongCaseMatch= false;
1685 rightCase.add(proposal); 1685 rightCase.add(cast(Object)proposal);
1686 CharSequence newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length()); 1686 CharSequence newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length());
1687 if (rightCasePostfix is null) 1687 if (rightCasePostfix is null)
1688 rightCasePostfix= new StringBuffer(newPostfix.toString()); 1688 rightCasePostfix= new StringBuffer(newPostfix.toString());
1689 else 1689 else
1690 truncatePostfix(rightCasePostfix, newPostfix); 1690 truncatePostfix(rightCasePostfix, newPostfix);
1697 CharSequence newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length()); 1697 CharSequence newPostfix= insertion.subSequence(relativeCompletionOffset, insertion.length());
1698 if (wrongCasePostfix is null) 1698 if (wrongCasePostfix is null)
1699 wrongCasePostfix= new StringBuffer(newPostfix.toString()); 1699 wrongCasePostfix= new StringBuffer(newPostfix.toString());
1700 else 1700 else
1701 truncatePostfix(wrongCasePostfix, newPostfix); 1701 truncatePostfix(wrongCasePostfix, newPostfix);
1702 wrongCase.add(proposal); 1702 wrongCase.add(cast(Object)proposal);
1703 } else { 1703 } else {
1704 return false; 1704 return false;
1705 } 1705 }
1706 } else 1706 } else
1707 return false; 1707 return false;
1738 1738
1739 CharSequence prefix; 1739 CharSequence prefix;
1740 if (isWrongCaseMatch) 1740 if (isWrongCaseMatch)
1741 prefix= wrongCasePrefix; 1741 prefix= wrongCasePrefix;
1742 else 1742 else
1743 prefix= ""; //$NON-NLS-1$ 1743 prefix= new StringCharSequence(""); //$NON-NLS-1$
1744 1744
1745 CharSequence postfix; 1745 CharSequence postfix;
1746 if (isWrongCaseMatch) 1746 if (isWrongCaseMatch)
1747 postfix= wrongCasePostfix; 1747 postfix= new StringCharSequence(wrongCasePostfix.toString);
1748 else 1748 else
1749 postfix= rightCasePostfix; 1749 postfix= new StringCharSequence(rightCasePostfix.toString);
1750 1750
1751 if (prefix is null || postfix is null) 1751 if (prefix is null || postfix is null)
1752 return false; 1752 return false;
1753 1753
1754 try { 1754 try {
1756 int to= Math.min(document.getLength(), fFilterOffset + postfix.length()); 1756 int to= Math.min(document.getLength(), fFilterOffset + postfix.length());
1757 StringBuffer inDocument= new StringBuffer(document.get(fFilterOffset, to - fFilterOffset)); 1757 StringBuffer inDocument= new StringBuffer(document.get(fFilterOffset, to - fFilterOffset));
1758 truncatePostfix(inDocument, postfix); 1758 truncatePostfix(inDocument, postfix);
1759 1759
1760 // 5: replace and reveal 1760 // 5: replace and reveal
1761 document.replace(fFilterOffset - prefix.length(), prefix.length() + inDocument.length(), prefix.toString() + postfix.toString()); 1761 document.replace(fFilterOffset - prefix.length(), prefix.length() + inDocument.length(), prefix.toString() ~ postfix.toString());
1762 1762
1763 fContentAssistSubjectControlAdapter.setSelectedRange(fFilterOffset + postfix.length(), 0); 1763 fContentAssistSubjectControlAdapter.setSelectedRange(fFilterOffset + postfix.length(), 0);
1764 fContentAssistSubjectControlAdapter.revealRange(fFilterOffset + postfix.length(), 0); 1764 fContentAssistSubjectControlAdapter.revealRange(fFilterOffset + postfix.length(), 0);
1765 fFilterOffset+= postfix.length(); 1765 fFilterOffset+= postfix.length();
1766 fLastCompletionOffset= fFilterOffset; 1766 fLastCompletionOffset= fFilterOffset;
1781 1781
1782 int min= Math.min(oneOffset, twoOffset); 1782 int min= Math.min(oneOffset, twoOffset);
1783 int oneEnd= oneOffset + oneSequence.length(); 1783 int oneEnd= oneOffset + oneSequence.length();
1784 int twoEnd= twoOffset + twoSequence.length(); 1784 int twoEnd= twoOffset + twoSequence.length();
1785 1785
1786 String one= document.get(oneOffset, min - oneOffset) + oneSequence + document.get(oneEnd, Math.min(fFilterOffset, fFilterOffset - oneEnd)); 1786 String one= document.get(oneOffset, min - oneOffset) ~ oneSequence.toString ~ document.get(oneEnd, Math.min(fFilterOffset, fFilterOffset - oneEnd));
1787 String two= document.get(twoOffset, min - twoOffset) + twoSequence + document.get(twoEnd, Math.min(fFilterOffset, fFilterOffset - twoEnd)); 1787 String two= document.get(twoOffset, min - twoOffset) ~ twoSequence.toString ~ document.get(twoEnd, Math.min(fFilterOffset, fFilterOffset - twoEnd));
1788 1788
1789 return one.equals(two); 1789 return one.equals(two);
1790 } 1790 }
1791 1791
1792 /** 1792 /**
1798 */ 1798 */
1799 private void truncatePostfix(StringBuffer buffer, CharSequence sequence) { 1799 private void truncatePostfix(StringBuffer buffer, CharSequence sequence) {
1800 // find common prefix 1800 // find common prefix
1801 int min= Math.min(buffer.length(), sequence.length()); 1801 int min= Math.min(buffer.length(), sequence.length());
1802 for (int c= 0; c < min; c++) { 1802 for (int c= 0; c < min; c++) {
1803 if (sequence.charAt(c) !is buffer.charAt(c)) { 1803 if (sequence.charAt(c) !is buffer.slice()[c]) {
1804 buffer.delete_(c, buffer.length()); 1804 buffer.truncate(c);
1805 return; 1805 return;
1806 } 1806 }
1807 } 1807 }
1808 1808
1809 // all equal up to minimum 1809 // all equal up to minimum
1810 buffer.delete_(min, buffer.length()); 1810 buffer.truncate(min);
1811 } 1811 }
1812 1812
1813 /** 1813 /**
1814 * Sets the message for the repetition affordance text at the bottom of the proposal. Only has 1814 * Sets the message for the repetition affordance text at the bottom of the proposal. Only has
1815 * an effect if {@link ContentAssistant#isRepeatedInvocationMode()} returns <code>true</code>. 1815 * an effect if {@link ContentAssistant#isRepeatedInvocationMode()} returns <code>true</code>.
1818 * @since 3.2 1818 * @since 3.2
1819 */ 1819 */
1820 void setMessage(String message) { 1820 void setMessage(String message) {
1821 Assert.isNotNull(message); 1821 Assert.isNotNull(message);
1822 if (isActive() && fMessageText !is null) 1822 if (isActive() && fMessageText !is null)
1823 fMessageText.setText(message + " "); //$NON-NLS-1$ 1823 fMessageText.setText(message ~ " "); //$NON-NLS-1$
1824 } 1824 }
1825 1825
1826 /** 1826 /**
1827 * Sets the text to be displayed if no proposals are available. Only has an effect if 1827 * Sets the text to be displayed if no proposals are available. Only has an effect if
1828 * {@link ContentAssistant#isShowEmptyList()} returns <code>true</code>. 1828 * {@link ContentAssistant#isShowEmptyList()} returns <code>true</code>.