Mercurial > projects > dwt2
comparison org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 org.eclipse.jface.text.contentassist.CompletionProposal; | |
14 | |
15 import org.eclipse.jface.text.contentassist.ContentAssistEvent; // packageimport | |
16 import org.eclipse.jface.text.contentassist.Helper; // packageimport | |
17 import org.eclipse.jface.text.contentassist.PopupCloser; // packageimport | |
18 import org.eclipse.jface.text.contentassist.IContentAssistant; // packageimport | |
19 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5; // packageimport | |
20 import org.eclipse.jface.text.contentassist.IContextInformationValidator; // packageimport | |
21 import org.eclipse.jface.text.contentassist.IContentAssistListener; // packageimport | |
22 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6; // packageimport | |
23 import org.eclipse.jface.text.contentassist.ICompletionListener; // packageimport | |
24 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; // packageimport | |
25 import org.eclipse.jface.text.contentassist.IContentAssistantExtension4; // packageimport | |
26 import org.eclipse.jface.text.contentassist.ContextInformation; // packageimport | |
27 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3; // packageimport | |
28 import org.eclipse.jface.text.contentassist.ContextInformationValidator; // packageimport | |
29 import org.eclipse.jface.text.contentassist.ICompletionProposal; // packageimport | |
30 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; // packageimport | |
31 import org.eclipse.jface.text.contentassist.AdditionalInfoController; // packageimport | |
32 import org.eclipse.jface.text.contentassist.IContextInformationPresenter; // packageimport | |
33 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4; // packageimport | |
34 import org.eclipse.jface.text.contentassist.ICompletionListenerExtension; // packageimport | |
35 import org.eclipse.jface.text.contentassist.ContextInformationPopup; // packageimport | |
36 import org.eclipse.jface.text.contentassist.IContextInformationExtension; // packageimport | |
37 import org.eclipse.jface.text.contentassist.IContentAssistantExtension2; // packageimport | |
38 import org.eclipse.jface.text.contentassist.ContentAssistSubjectControlAdapter; // packageimport | |
39 import org.eclipse.jface.text.contentassist.CompletionProposalPopup; // packageimport | |
40 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension; // packageimport | |
41 import org.eclipse.jface.text.contentassist.IContextInformation; // packageimport | |
42 import org.eclipse.jface.text.contentassist.IContentAssistantExtension3; // packageimport | |
43 import org.eclipse.jface.text.contentassist.ContentAssistant; // packageimport | |
44 import org.eclipse.jface.text.contentassist.IContentAssistantExtension; // packageimport | |
45 import org.eclipse.jface.text.contentassist.JFaceTextMessages; // packageimport | |
46 | |
47 | |
48 import java.lang.all; | |
49 import java.util.Set; | |
50 | |
51 | |
52 | |
53 | |
54 import org.eclipse.swt.graphics.Image; | |
55 import org.eclipse.swt.graphics.Point; | |
56 import org.eclipse.core.runtime.Assert; | |
57 import org.eclipse.jface.text.BadLocationException; | |
58 import org.eclipse.jface.text.IDocument; | |
59 | |
60 | |
61 /** | |
62 * The standard implementation of the <code>ICompletionProposal</code> interface. | |
63 */ | |
64 public final class CompletionProposal : ICompletionProposal { | |
65 | |
66 /** The string to be displayed in the completion proposal popup. */ | |
67 private String fDisplayString; | |
68 /** The replacement string. */ | |
69 private String fReplacementString; | |
70 /** The replacement offset. */ | |
71 private int fReplacementOffset; | |
72 /** The replacement length. */ | |
73 private int fReplacementLength; | |
74 /** The cursor position after this proposal has been applied. */ | |
75 private int fCursorPosition; | |
76 /** The image to be displayed in the completion proposal popup. */ | |
77 private Image fImage; | |
78 /** The context information of this proposal. */ | |
79 private IContextInformation fContextInformation; | |
80 /** The additional info of this proposal. */ | |
81 private String fAdditionalProposalInfo; | |
82 | |
83 /** | |
84 * Creates a new completion proposal based on the provided information. The replacement string is | |
85 * considered being the display string too. All remaining fields are set to <code>null</code>. | |
86 * | |
87 * @param replacementString the actual string to be inserted into the document | |
88 * @param replacementOffset the offset of the text to be replaced | |
89 * @param replacementLength the length of the text to be replaced | |
90 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset | |
91 */ | |
92 public this(String replacementString, int replacementOffset, int replacementLength, int cursorPosition) { | |
93 this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null); | |
94 } | |
95 | |
96 /** | |
97 * Creates a new completion proposal. All fields are initialized based on the provided information. | |
98 * | |
99 * @param replacementString the actual string to be inserted into the document | |
100 * @param replacementOffset the offset of the text to be replaced | |
101 * @param replacementLength the length of the text to be replaced | |
102 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset | |
103 * @param image the image to display for this proposal | |
104 * @param displayString the string to be displayed for the proposal | |
105 * @param contextInformation the context information associated with this proposal | |
106 * @param additionalProposalInfo the additional information associated with this proposal | |
107 */ | |
108 public this(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) { | |
109 Assert.isNotNull(replacementString); | |
110 Assert.isTrue(replacementOffset >= 0); | |
111 Assert.isTrue(replacementLength >= 0); | |
112 Assert.isTrue(cursorPosition >= 0); | |
113 | |
114 fReplacementString= replacementString; | |
115 fReplacementOffset= replacementOffset; | |
116 fReplacementLength= replacementLength; | |
117 fCursorPosition= cursorPosition; | |
118 fImage= image; | |
119 fDisplayString= displayString; | |
120 fContextInformation= contextInformation; | |
121 fAdditionalProposalInfo= additionalProposalInfo; | |
122 } | |
123 | |
124 /* | |
125 * @see ICompletionProposal#apply(IDocument) | |
126 */ | |
127 public void apply(IDocument document) { | |
128 try { | |
129 document.replace(fReplacementOffset, fReplacementLength, fReplacementString); | |
130 } catch (BadLocationException x) { | |
131 // ignore | |
132 } | |
133 } | |
134 | |
135 /* | |
136 * @see ICompletionProposal#getSelection(IDocument) | |
137 */ | |
138 public Point getSelection(IDocument document) { | |
139 return new Point(fReplacementOffset + fCursorPosition, 0); | |
140 } | |
141 | |
142 /* | |
143 * @see ICompletionProposal#getContextInformation() | |
144 */ | |
145 public IContextInformation getContextInformation() { | |
146 return fContextInformation; | |
147 } | |
148 | |
149 /* | |
150 * @see ICompletionProposal#getImage() | |
151 */ | |
152 public Image getImage() { | |
153 return fImage; | |
154 } | |
155 | |
156 /* | |
157 * @see ICompletionProposal#getDisplayString() | |
158 */ | |
159 public String getDisplayString() { | |
160 if (fDisplayString !is null) | |
161 return fDisplayString; | |
162 return fReplacementString; | |
163 } | |
164 | |
165 /* | |
166 * @see ICompletionProposal#getAdditionalProposalInfo() | |
167 */ | |
168 public String getAdditionalProposalInfo() { | |
169 return fAdditionalProposalInfo; | |
170 } | |
171 } |