129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.contentassist.CompletionProposal;
|
|
14
|
131
|
15 import dwtx.jface.text.contentassist.ContentAssistEvent; // packageimport
|
|
16 import dwtx.jface.text.contentassist.Helper; // packageimport
|
|
17 import dwtx.jface.text.contentassist.PopupCloser; // packageimport
|
|
18 import dwtx.jface.text.contentassist.IContentAssistant; // packageimport
|
|
19 import dwtx.jface.text.contentassist.ICompletionProposalExtension5; // packageimport
|
|
20 import dwtx.jface.text.contentassist.IContextInformationValidator; // packageimport
|
|
21 import dwtx.jface.text.contentassist.IContentAssistListener; // packageimport
|
|
22 import dwtx.jface.text.contentassist.ICompletionProposalExtension6; // packageimport
|
|
23 import dwtx.jface.text.contentassist.ICompletionListener; // packageimport
|
|
24 import dwtx.jface.text.contentassist.ICompletionProposalExtension2; // packageimport
|
|
25 import dwtx.jface.text.contentassist.IContentAssistantExtension4; // packageimport
|
|
26 import dwtx.jface.text.contentassist.ContextInformation; // packageimport
|
|
27 import dwtx.jface.text.contentassist.ICompletionProposalExtension3; // packageimport
|
|
28 import dwtx.jface.text.contentassist.ContextInformationValidator; // packageimport
|
|
29 import dwtx.jface.text.contentassist.ICompletionProposal; // packageimport
|
|
30 import dwtx.jface.text.contentassist.IContentAssistProcessor; // packageimport
|
|
31 import dwtx.jface.text.contentassist.AdditionalInfoController; // packageimport
|
|
32 import dwtx.jface.text.contentassist.IContextInformationPresenter; // packageimport
|
|
33 import dwtx.jface.text.contentassist.ICompletionProposalExtension4; // packageimport
|
|
34 import dwtx.jface.text.contentassist.ICompletionListenerExtension; // packageimport
|
|
35 import dwtx.jface.text.contentassist.ContextInformationPopup; // packageimport
|
|
36 import dwtx.jface.text.contentassist.IContextInformationExtension; // packageimport
|
|
37 import dwtx.jface.text.contentassist.IContentAssistantExtension2; // packageimport
|
|
38 import dwtx.jface.text.contentassist.ContentAssistSubjectControlAdapter; // packageimport
|
|
39 import dwtx.jface.text.contentassist.CompletionProposalPopup; // packageimport
|
|
40 import dwtx.jface.text.contentassist.ICompletionProposalExtension; // packageimport
|
|
41 import dwtx.jface.text.contentassist.IContextInformation; // packageimport
|
|
42 import dwtx.jface.text.contentassist.IContentAssistantExtension3; // packageimport
|
|
43 import dwtx.jface.text.contentassist.ContentAssistant; // packageimport
|
|
44 import dwtx.jface.text.contentassist.IContentAssistantExtension; // packageimport
|
|
45 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport
|
|
46
|
|
47
|
129
|
48 import dwt.dwthelper.utils;
|
|
49
|
|
50
|
|
51
|
|
52
|
|
53 import dwt.graphics.Image;
|
|
54 import dwt.graphics.Point;
|
|
55 import dwtx.core.runtime.Assert;
|
|
56 import dwtx.jface.text.BadLocationException;
|
|
57 import dwtx.jface.text.IDocument;
|
|
58
|
|
59
|
|
60 /**
|
|
61 * The standard implementation of the <code>ICompletionProposal</code> interface.
|
|
62 */
|
|
63 public final class CompletionProposal : ICompletionProposal {
|
|
64
|
|
65 /** The string to be displayed in the completion proposal popup. */
|
|
66 private String fDisplayString;
|
|
67 /** The replacement string. */
|
|
68 private String fReplacementString;
|
|
69 /** The replacement offset. */
|
|
70 private int fReplacementOffset;
|
|
71 /** The replacement length. */
|
|
72 private int fReplacementLength;
|
|
73 /** The cursor position after this proposal has been applied. */
|
|
74 private int fCursorPosition;
|
|
75 /** The image to be displayed in the completion proposal popup. */
|
|
76 private Image fImage;
|
|
77 /** The context information of this proposal. */
|
|
78 private IContextInformation fContextInformation;
|
|
79 /** The additional info of this proposal. */
|
|
80 private String fAdditionalProposalInfo;
|
|
81
|
|
82 /**
|
|
83 * Creates a new completion proposal based on the provided information. The replacement string is
|
|
84 * considered being the display string too. All remaining fields are set to <code>null</code>.
|
|
85 *
|
|
86 * @param replacementString the actual string to be inserted into the document
|
|
87 * @param replacementOffset the offset of the text to be replaced
|
|
88 * @param replacementLength the length of the text to be replaced
|
|
89 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
|
|
90 */
|
|
91 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition) {
|
|
92 this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null);
|
|
93 }
|
|
94
|
|
95 /**
|
|
96 * Creates a new completion proposal. All fields are initialized based on the provided information.
|
|
97 *
|
|
98 * @param replacementString the actual string to be inserted into the document
|
|
99 * @param replacementOffset the offset of the text to be replaced
|
|
100 * @param replacementLength the length of the text to be replaced
|
|
101 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
|
|
102 * @param image the image to display for this proposal
|
|
103 * @param displayString the string to be displayed for the proposal
|
|
104 * @param contextInformation the context information associated with this proposal
|
|
105 * @param additionalProposalInfo the additional information associated with this proposal
|
|
106 */
|
|
107 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
|
|
108 Assert.isNotNull(replacementString);
|
|
109 Assert.isTrue(replacementOffset >= 0);
|
|
110 Assert.isTrue(replacementLength >= 0);
|
|
111 Assert.isTrue(cursorPosition >= 0);
|
|
112
|
|
113 fReplacementString= replacementString;
|
|
114 fReplacementOffset= replacementOffset;
|
|
115 fReplacementLength= replacementLength;
|
|
116 fCursorPosition= cursorPosition;
|
|
117 fImage= image;
|
|
118 fDisplayString= displayString;
|
|
119 fContextInformation= contextInformation;
|
|
120 fAdditionalProposalInfo= additionalProposalInfo;
|
|
121 }
|
|
122
|
|
123 /*
|
|
124 * @see ICompletionProposal#apply(IDocument)
|
|
125 */
|
|
126 public void apply(IDocument document) {
|
|
127 try {
|
|
128 document.replace(fReplacementOffset, fReplacementLength, fReplacementString);
|
|
129 } catch (BadLocationException x) {
|
|
130 // ignore
|
|
131 }
|
|
132 }
|
|
133
|
|
134 /*
|
|
135 * @see ICompletionProposal#getSelection(IDocument)
|
|
136 */
|
|
137 public Point getSelection(IDocument document) {
|
|
138 return new Point(fReplacementOffset + fCursorPosition, 0);
|
|
139 }
|
|
140
|
|
141 /*
|
|
142 * @see ICompletionProposal#getContextInformation()
|
|
143 */
|
|
144 public IContextInformation getContextInformation() {
|
|
145 return fContextInformation;
|
|
146 }
|
|
147
|
|
148 /*
|
|
149 * @see ICompletionProposal#getImage()
|
|
150 */
|
|
151 public Image getImage() {
|
|
152 return fImage;
|
|
153 }
|
|
154
|
|
155 /*
|
|
156 * @see ICompletionProposal#getDisplayString()
|
|
157 */
|
|
158 public String getDisplayString() {
|
|
159 if (fDisplayString !is null)
|
|
160 return fDisplayString;
|
|
161 return fReplacementString;
|
|
162 }
|
|
163
|
|
164 /*
|
|
165 * @see ICompletionProposal#getAdditionalProposalInfo()
|
|
166 */
|
|
167 public String getAdditionalProposalInfo() {
|
|
168 return fAdditionalProposalInfo;
|
|
169 }
|
|
170 }
|