comparison dwtx/jface/text/contentassist/CompletionProposalPopup.d @ 134:51e6e63f930e

Regex fix for casts
author Frank Benoit <benoit@tionex.de>
date Sun, 24 Aug 2008 01:46:20 +0200
parents 7d818bd32d63
children 65801ad2b265
comparison
equal deleted inserted replaced
133:7d818bd32d63 134:51e6e63f930e
521 int count= (fComputedProposals is null ? 0 : fComputedProposals.length); 521 int count= (fComputedProposals is null ? 0 : fComputedProposals.length);
522 if (count is 0 && hideWhenNoProposals(autoActivated)) 522 if (count is 0 && hideWhenNoProposals(autoActivated))
523 return; 523 return;
524 524
525 if (count is 1 && !autoActivated && canAutoInsert(fComputedProposals[0])) { 525 if (count is 1 && !autoActivated && canAutoInsert(fComputedProposals[0])) {
526 insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset); 526 insertProposal(fComputedProposals[0], cast(wchar) 0, 0, fInvocationOffset);
527 hide(); 527 hide();
528 } else { 528 } else {
529 createProposalSelector(); 529 createProposalSelector();
530 setProposals(fComputedProposals, false); 530 setProposals(fComputedProposals, false);
531 displayProposals(); 531 displayProposals();
604 return; 604 return;
605 605
606 Control control= fContentAssistSubjectControlAdapter.getControl(); 606 Control control= fContentAssistSubjectControlAdapter.getControl();
607 fProposalShell= new Shell(control.getShell(), DWT.ON_TOP | DWT.RESIZE ); 607 fProposalShell= new Shell(control.getShell(), DWT.ON_TOP | DWT.RESIZE );
608 fProposalShell.setFont(JFaceResources.getDefaultFont()); 608 fProposalShell.setFont(JFaceResources.getDefaultFont());
609 if (USE_VIRTUAL) { 609 if cast(USE_VIRTUAL) {
610 fProposalTable= new Table(fProposalShell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.VIRTUAL); 610 fProposalTable= new Table(fProposalShell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.VIRTUAL);
611 611
612 Listener listener= new Listener() { 612 Listener listener= new Listener() {
613 public void handleEvent(Event event) { 613 public void handleEvent(Event event) {
614 handleSetData(event); 614 handleSetData(event);
645 fProposalShell.setSize(size); 645 fProposalShell.setSize(size);
646 } else { 646 } else {
647 int height= fProposalTable.getItemHeight() * 10; 647 int height= fProposalTable.getItemHeight() * 10;
648 // use golden ratio as default aspect ratio 648 // use golden ratio as default aspect ratio
649 final double aspectRatio= (1 + Math.sqrt(5)) / 2; 649 final double aspectRatio= (1 + Math.sqrt(5)) / 2;
650 int width= (int) (height * aspectRatio); 650 int width= cast(int) (height * aspectRatio);
651 Rectangle trim= fProposalTable.computeTrim(0, 0, width, height); 651 Rectangle trim= fProposalTable.computeTrim(0, 0, width, height);
652 data.heightHint= trim.height; 652 data.heightHint= trim.height;
653 data.widthHint= trim.width; 653 data.widthHint= trim.width;
654 fProposalTable.setLayoutData(data); 654 fProposalTable.setLayoutData(data);
655 fProposalShell.pack(); 655 fProposalShell.pack();
844 844
845 /* 845 /*
846 * @since 3.1 846 * @since 3.1
847 */ 847 */
848 private void handleSetData(Event event) { 848 private void handleSetData(Event event) {
849 TableItem item= (TableItem) event.item; 849 TableItem item= cast(TableItem) event.item;
850 int index= fProposalTable.indexOf(item); 850 int index= fProposalTable.indexOf(item);
851 851
852 if (0 <= index && index < fFilteredProposals.length) { 852 if (0 <= index && index < fFilteredProposals.length) {
853 ICompletionProposal current= fFilteredProposals[index]; 853 ICompletionProposal current= fFilteredProposals[index];
854 854
855 String displayString; 855 String displayString;
856 StyleRange[] styleRanges= null; 856 StyleRange[] styleRanges= null;
857 if (fIsColoredLabelsSupportEnabled && current instanceof ICompletionProposalExtension6) { 857 if (fIsColoredLabelsSupportEnabled && current instanceof ICompletionProposalExtension6) {
858 StyledString styledString= ((ICompletionProposalExtension6)current).getStyledDisplayString(); 858 StyledString styledString= (cast(ICompletionProposalExtension6)current).getStyledDisplayString();
859 displayString= styledString.getString(); 859 displayString= styledString.getString();
860 styleRanges= styledString.getStyleRanges(); 860 styleRanges= styledString.getStyleRanges();
861 } else 861 } else
862 displayString= current.getDisplayString(); 862 displayString= current.getDisplayString();
863 863
903 */ 903 */
904 private void insertSelectedProposalWithMask(int stateMask) { 904 private void insertSelectedProposalWithMask(int stateMask) {
905 ICompletionProposal p= getSelectedProposal(); 905 ICompletionProposal p= getSelectedProposal();
906 hide(); 906 hide();
907 if (p !is null) 907 if (p !is null)
908 insertProposal(p, (char) 0, stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x); 908 insertProposal(p, cast(wchar) 0, stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x);
909 } 909 }
910 910
911 /** 911 /**
912 * Applies the given proposal at the given offset. The given character is the 912 * Applies the given proposal at the given offset. The given character is the
913 * one that triggered the insertion of this proposal. 913 * one that triggered the insertion of this proposal.
937 try { 937 try {
938 938
939 IDocument document= fContentAssistSubjectControlAdapter.getDocument(); 939 IDocument document= fContentAssistSubjectControlAdapter.getDocument();
940 940
941 if (fViewer instanceof ITextViewerExtension) { 941 if (fViewer instanceof ITextViewerExtension) {
942 ITextViewerExtension extension= (ITextViewerExtension) fViewer; 942 ITextViewerExtension extension= cast(ITextViewerExtension) fViewer;
943 target= extension.getRewriteTarget(); 943 target= extension.getRewriteTarget();
944 } 944 }
945 945
946 if (target !is null) 946 if (target !is null)
947 target.beginCompoundChange(); 947 target.beginCompoundChange();
948 948
949 if (fViewer instanceof IEditingSupportRegistry) { 949 if (fViewer instanceof IEditingSupportRegistry) {
950 IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer; 950 IEditingSupportRegistry registry= cast(IEditingSupportRegistry) fViewer;
951 registry.register(helper); 951 registry.register(helper);
952 } 952 }
953 953
954 954
955 if (p instanceof ICompletionProposalExtension2 && fViewer !is null) { 955 if (p instanceof ICompletionProposalExtension2 && fViewer !is null) {
956 ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p; 956 ICompletionProposalExtension2 e= cast(ICompletionProposalExtension2) p;
957 e.apply(fViewer, trigger, stateMask, offset); 957 e.apply(fViewer, trigger, stateMask, offset);
958 } else if (p instanceof ICompletionProposalExtension) { 958 } else if (p instanceof ICompletionProposalExtension) {
959 ICompletionProposalExtension e= (ICompletionProposalExtension) p; 959 ICompletionProposalExtension e= cast(ICompletionProposalExtension) p;
960 e.apply(document, trigger, offset); 960 e.apply(document, trigger, offset);
961 } else { 961 } else {
962 p.apply(document); 962 p.apply(document);
963 } 963 }
964 964
971 IContextInformation info= p.getContextInformation(); 971 IContextInformation info= p.getContextInformation();
972 if (info !is null) { 972 if (info !is null) {
973 973
974 int contextInformationOffset; 974 int contextInformationOffset;
975 if (p instanceof ICompletionProposalExtension) { 975 if (p instanceof ICompletionProposalExtension) {
976 ICompletionProposalExtension e= (ICompletionProposalExtension) p; 976 ICompletionProposalExtension e= cast(ICompletionProposalExtension) p;
977 contextInformationOffset= e.getContextInformationPosition(); 977 contextInformationOffset= e.getContextInformationPosition();
978 } else { 978 } else {
979 if (selection is null) 979 if (selection is null)
980 selection= fContentAssistSubjectControlAdapter.getSelectedRange(); 980 selection= fContentAssistSubjectControlAdapter.getSelectedRange();
981 contextInformationOffset= selection.x + selection.y; 981 contextInformationOffset= selection.x + selection.y;
989 } finally { 989 } finally {
990 if (target !is null) 990 if (target !is null)
991 target.endCompoundChange(); 991 target.endCompoundChange();
992 992
993 if (fViewer instanceof IEditingSupportRegistry) { 993 if (fViewer instanceof IEditingSupportRegistry) {
994 IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer; 994 IEditingSupportRegistry registry= cast(IEditingSupportRegistry) fViewer;
995 registry.unregister(helper); 995 registry.unregister(helper);
996 } 996 }
997 fInserting= false; 997 fInserting= false;
998 } 998 }
999 } 999 }
1035 public void hide() { 1035 public void hide() {
1036 1036
1037 unregister(); 1037 unregister();
1038 1038
1039 if (fViewer instanceof IEditingSupportRegistry) { 1039 if (fViewer instanceof IEditingSupportRegistry) {
1040 IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer; 1040 IEditingSupportRegistry registry= cast(IEditingSupportRegistry) fViewer;
1041 registry.unregister(fFocusHelper); 1041 registry.unregister(fFocusHelper);
1042 } 1042 }
1043 1043
1044 if (Helper.okToUse(fProposalShell)) { 1044 if (Helper.okToUse(fProposalShell)) {
1045 1045
1086 fKeyListener= null; 1086 fKeyListener= null;
1087 } 1087 }
1088 1088
1089 if (fLastProposal !is null) { 1089 if (fLastProposal !is null) {
1090 if (fLastProposal instanceof ICompletionProposalExtension2 && fViewer !is null) { 1090 if (fLastProposal instanceof ICompletionProposalExtension2 && fViewer !is null) {
1091 ICompletionProposalExtension2 extension= (ICompletionProposalExtension2) fLastProposal; 1091 ICompletionProposalExtension2 extension= cast(ICompletionProposalExtension2) fLastProposal;
1092 extension.unselected(fViewer); 1092 extension.unselected(fViewer);
1093 } 1093 }
1094 fLastProposal= null; 1094 fLastProposal= null;
1095 } 1095 }
1096 1096
1122 if (oldProposals !is fFilteredProposals) // reentrant call was first - abort 1122 if (oldProposals !is fFilteredProposals) // reentrant call was first - abort
1123 return; 1123 return;
1124 1124
1125 if (Helper.okToUse(fProposalTable)) { 1125 if (Helper.okToUse(fProposalTable)) {
1126 if (oldProposal instanceof ICompletionProposalExtension2 && fViewer !is null) 1126 if (oldProposal instanceof ICompletionProposalExtension2 && fViewer !is null)
1127 ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); 1127 (cast(ICompletionProposalExtension2) oldProposal).unselected(fViewer);
1128 1128
1129 if (proposals is null || proposals.length is 0) { 1129 if (proposals is null || proposals.length is 0) {
1130 fEmptyProposal.fOffset= fFilterOffset; 1130 fEmptyProposal.fOffset= fFilterOffset;
1131 fEmptyProposal.fDisplayString= fEmptyMessage !is null ? fEmptyMessage : JFaceTextMessages.getString("CompletionProposalPopup.no_proposals"); //$NON-NLS-1$ 1131 fEmptyProposal.fDisplayString= fEmptyMessage !is null ? fEmptyMessage : JFaceTextMessages.getString("CompletionProposalPopup.no_proposals"); //$NON-NLS-1$
1132 proposals= new ICompletionProposal[] { fEmptyProposal }; 1132 proposals= new ICompletionProposal[] { fEmptyProposal };
1133 } 1133 }
1134 1134
1135 fFilteredProposals= proposals; 1135 fFilteredProposals= proposals;
1136 final int newLen= proposals.length; 1136 final int newLen= proposals.length;
1137 if (USE_VIRTUAL) { 1137 if cast(USE_VIRTUAL) {
1138 fProposalTable.setItemCount(newLen); 1138 fProposalTable.setItemCount(newLen);
1139 fProposalTable.clearAll(); 1139 fProposalTable.clearAll();
1140 } else { 1140 } else {
1141 fProposalTable.setRedraw(false); 1141 fProposalTable.setRedraw(false);
1142 fProposalTable.setItemCount(newLen); 1142 fProposalTable.setItemCount(newLen);
1206 } 1206 }
1207 1207
1208 }; 1208 };
1209 } 1209 }
1210 if (fViewer instanceof IEditingSupportRegistry) { 1210 if (fViewer instanceof IEditingSupportRegistry) {
1211 IEditingSupportRegistry registry= (IEditingSupportRegistry) fViewer; 1211 IEditingSupportRegistry registry= cast(IEditingSupportRegistry) fViewer;
1212 registry.register(fFocusHelper); 1212 registry.register(fFocusHelper);
1213 } 1213 }
1214 1214
1215 1215
1216 /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=52646 1216 /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=52646
1341 return false; 1341 return false;
1342 1342
1343 default: 1343 default:
1344 ICompletionProposal p= getSelectedProposal(); 1344 ICompletionProposal p= getSelectedProposal();
1345 if (p instanceof ICompletionProposalExtension) { 1345 if (p instanceof ICompletionProposalExtension) {
1346 ICompletionProposalExtension t= (ICompletionProposalExtension) p; 1346 ICompletionProposalExtension t= cast(ICompletionProposalExtension) p;
1347 char[] triggers= t.getTriggerCharacters(); 1347 char[] triggers= t.getTriggerCharacters();
1348 if (contains(triggers, key)) { 1348 if (contains(triggers, key)) {
1349 e.doit= false; 1349 e.doit= false;
1350 hide(); 1350 hide();
1351 insertProposal(p, key, e.stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x); 1351 insertProposal(p, key, e.stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x);
1366 */ 1366 */
1367 private void selectProposal(int index, bool smartToggle) { 1367 private void selectProposal(int index, bool smartToggle) {
1368 1368
1369 ICompletionProposal oldProposal= getSelectedProposal(); 1369 ICompletionProposal oldProposal= getSelectedProposal();
1370 if (oldProposal instanceof ICompletionProposalExtension2 && fViewer !is null) 1370 if (oldProposal instanceof ICompletionProposalExtension2 && fViewer !is null)
1371 ((ICompletionProposalExtension2) oldProposal).unselected(fViewer); 1371 (cast(ICompletionProposalExtension2) oldProposal).unselected(fViewer);
1372 1372
1373 if (fFilteredProposals is null) { 1373 if (fFilteredProposals is null) {
1374 fireSelectionEvent(null, smartToggle); 1374 fireSelectionEvent(null, smartToggle);
1375 return; 1375 return;
1376 } 1376 }
1377 1377
1378 ICompletionProposal proposal= fFilteredProposals[index]; 1378 ICompletionProposal proposal= fFilteredProposals[index];
1379 if (proposal instanceof ICompletionProposalExtension2 && fViewer !is null) 1379 if (proposal instanceof ICompletionProposalExtension2 && fViewer !is null)
1380 ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle); 1380 (cast(ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
1381 1381
1382 fireSelectionEvent(proposal, smartToggle); 1382 fireSelectionEvent(proposal, smartToggle);
1383 1383
1384 fLastProposal= proposal; 1384 fLastProposal= proposal;
1385 1385
1483 List filtered= new ArrayList(length); 1483 List filtered= new ArrayList(length);
1484 for (int i= 0; i < length; i++) { 1484 for (int i= 0; i < length; i++) {
1485 1485
1486 if (proposals[i] instanceof ICompletionProposalExtension2) { 1486 if (proposals[i] instanceof ICompletionProposalExtension2) {
1487 1487
1488 ICompletionProposalExtension2 p= (ICompletionProposalExtension2) proposals[i]; 1488 ICompletionProposalExtension2 p= cast(ICompletionProposalExtension2) proposals[i];
1489 if (p.validate(document, offset, event)) 1489 if (p.validate(document, offset, event))
1490 filtered.add(p); 1490 filtered.add(p);
1491 1491
1492 } else if (proposals[i] instanceof ICompletionProposalExtension) { 1492 } else if (proposals[i] instanceof ICompletionProposalExtension) {
1493 1493
1494 ICompletionProposalExtension p= (ICompletionProposalExtension) proposals[i]; 1494 ICompletionProposalExtension p= cast(ICompletionProposalExtension) proposals[i];
1495 if (p.isValidFor(document, offset)) 1495 if (p.isValidFor(document, offset))
1496 filtered.add(p); 1496 filtered.add(p);
1497 1497
1498 } else { 1498 } else {
1499 // restore original behavior 1499 // restore original behavior
1529 * @since 3.1 1529 * @since 3.1
1530 */ 1530 */
1531 private bool canAutoInsert(ICompletionProposal proposal) { 1531 private bool canAutoInsert(ICompletionProposal proposal) {
1532 if (fContentAssistant.isAutoInserting()) { 1532 if (fContentAssistant.isAutoInserting()) {
1533 if (proposal instanceof ICompletionProposalExtension4) { 1533 if (proposal instanceof ICompletionProposalExtension4) {
1534 ICompletionProposalExtension4 ext= (ICompletionProposalExtension4) proposal; 1534 ICompletionProposalExtension4 ext= cast(ICompletionProposalExtension4) proposal;
1535 return ext.isAutoInsertable(); 1535 return ext.isAutoInsertable();
1536 } 1536 }
1537 return true; // default behavior before ICompletionProposalExtension4 was introduced 1537 return true; // default behavior before ICompletionProposalExtension4 was introduced
1538 } 1538 }
1539 return false; 1539 return false;
1574 int count= (fFilteredProposals is null ? 0 : fFilteredProposals.length); 1574 int count= (fFilteredProposals is null ? 0 : fFilteredProposals.length);
1575 if (count is 0 && hideWhenNoProposals(false)) 1575 if (count is 0 && hideWhenNoProposals(false))
1576 return; 1576 return;
1577 1577
1578 if (count is 1 && canAutoInsert(fFilteredProposals[0])) { 1578 if (count is 1 && canAutoInsert(fFilteredProposals[0])) {
1579 insertProposal(fFilteredProposals[0], (char) 0, 0, fInvocationOffset); 1579 insertProposal(fFilteredProposals[0], cast(wchar) 0, 0, fInvocationOffset);
1580 hide(); 1580 hide();
1581 } else { 1581 } else {
1582 ensureDocumentListenerInstalled(); 1582 ensureDocumentListenerInstalled();
1583 if (count > 0 && completeCommonPrefix()) 1583 if (count > 0 && completeCommonPrefix())
1584 hide(); 1584 hide();
1608 private bool completeCommonPrefix() { 1608 private bool completeCommonPrefix() {
1609 1609
1610 // 0: insert single proposals 1610 // 0: insert single proposals
1611 if (fFilteredProposals.length is 1) { 1611 if (fFilteredProposals.length is 1) {
1612 if (canAutoInsert(fFilteredProposals[0])) { 1612 if (canAutoInsert(fFilteredProposals[0])) {
1613 insertProposal(fFilteredProposals[0], (char) 0, 0, fFilterOffset); 1613 insertProposal(fFilteredProposals[0], cast(wchar) 0, 0, fFilterOffset);
1614 hide(); 1614 hide();
1615 return true; 1615 return true;
1616 } 1616 }
1617 return false; 1617 return false;
1618 } 1618 }
1638 ICompletionProposal proposal= fFilteredProposals[i]; 1638 ICompletionProposal proposal= fFilteredProposals[i];
1639 1639
1640 if (!(proposal instanceof ICompletionProposalExtension3)) 1640 if (!(proposal instanceof ICompletionProposalExtension3))
1641 return false; 1641 return false;
1642 1642
1643 int start= ((ICompletionProposalExtension3)proposal).getPrefixCompletionStart(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset); 1643 int start= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionStart(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
1644 CharSequence insertion= ((ICompletionProposalExtension3)proposal).getPrefixCompletionText(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset); 1644 CharSequence insertion= (cast(ICompletionProposalExtension3)proposal).getPrefixCompletionText(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
1645 if (insertion is null) 1645 if (insertion is null)
1646 insertion= proposal.getDisplayString(); 1646 insertion= proposal.getDisplayString();
1647 try { 1647 try {
1648 int prefixLength= fFilterOffset - start; 1648 int prefixLength= fFilterOffset - start;
1649 int relativeCompletionOffset= Math.min(insertion.length(), prefixLength); 1649 int relativeCompletionOffset= Math.min(insertion.length(), prefixLength);
1683 } 1683 }
1684 1684
1685 // 2: replace single proposals 1685 // 2: replace single proposals
1686 1686
1687 if (rightCase.size() is 1) { 1687 if (rightCase.size() is 1) {
1688 ICompletionProposal proposal= (ICompletionProposal) rightCase.get(0); 1688 ICompletionProposal proposal= cast(ICompletionProposal) rightCase.get(0);
1689 if (canAutoInsert(proposal) && rightCasePostfix.length() > 0) { 1689 if (canAutoInsert(proposal) && rightCasePostfix.length() > 0) {
1690 insertProposal(proposal, (char) 0, 0, fInvocationOffset); 1690 insertProposal(proposal, cast(wchar) 0, 0, fInvocationOffset);
1691 hide(); 1691 hide();
1692 return true; 1692 return true;
1693 } 1693 }
1694 return false; 1694 return false;
1695 } else if (isWrongCaseMatch && wrongCase.size() is 1) { 1695 } else if (isWrongCaseMatch && wrongCase.size() is 1) {
1696 ICompletionProposal proposal= (ICompletionProposal) wrongCase.get(0); 1696 ICompletionProposal proposal= cast(ICompletionProposal) wrongCase.get(0);
1697 if (canAutoInsert(proposal)) { 1697 if (canAutoInsert(proposal)) {
1698 insertProposal(proposal, (char) 0, 0, fInvocationOffset); 1698 insertProposal(proposal, cast(wchar) 0, 0, fInvocationOffset);
1699 hide(); 1699 hide();
1700 return true; 1700 return true;
1701 } 1701 }
1702 return false; 1702 return false;
1703 } 1703 }