Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 109468 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (-101 / +104 lines)
Lines 112-296 Link Here
112
		<extension-point id="dragSourceTransfers" name="Drag Source Transfers"/>
112
		<extension-point id="dragSourceTransfers" name="Drag Source Transfers"/>
113
	-->
113
	-->
114
	<extension point="org.eclipse.ui.commands">
114
	<extension point="org.eclipse.ui.commands">
115
		<scope
116
			name="%scope.structuredTextEditor.name"
117
			parent="org.eclipse.ui.textEditorScope"
118
			description="%scope.structuredTextEditor.description"
119
			id="org.eclipse.wst.sse.ui.structuredTextEditorScope">
120
		</scope>
121
		<!--    dmw 6/6 (and 11/10 :) removed from 'scope'  parentId="org.eclipse.ui.textEditorScope" -->
122
		<!-- afw 11/11 added scope back in because these are keybindings for structuredtexteditors only -->
123
124
		<!-- Edit commands -->
115
		<!-- Edit commands -->
125
		<command
116
		<command
126
			name="%ActionDefinition.selectEnclosing.name"
117
			name="%ActionDefinition.selectEnclosing.name"
127
			description="%ActionDefinition.selectEnclosing.description"
118
			description="%ActionDefinition.selectEnclosing.description"
128
			category="org.eclipse.ui.category.edit"
119
			categoryId="org.eclipse.ui.category.edit"
129
			id="org.eclipse.wst.sse.ui.structure.select.enclosing">
120
			id="org.eclipse.wst.sse.ui.structure.select.enclosing">
130
		</command>
121
		</command>
131
		<command
122
		<command
132
			name="%ActionDefinition.selectNext.name"
123
			name="%ActionDefinition.selectNext.name"
133
			description="%ActionDefinition.selectNext.description"
124
			description="%ActionDefinition.selectNext.description"
134
			category="org.eclipse.ui.category.edit"
125
			categoryId="org.eclipse.ui.category.edit"
135
			id="org.eclipse.wst.sse.ui.structure.select.next">
126
			id="org.eclipse.wst.sse.ui.structure.select.next">
136
		</command>
127
		</command>
137
		<command
128
		<command
138
			name="%ActionDefinition.selectPrevious.name"
129
			name="%ActionDefinition.selectPrevious.name"
139
			description="%ActionDefinition.selectPrevious.description"
130
			description="%ActionDefinition.selectPrevious.description"
140
			category="org.eclipse.ui.category.edit"
131
			categoryId="org.eclipse.ui.category.edit"
141
			id="org.eclipse.wst.sse.ui.structure.select.previous">
132
			id="org.eclipse.wst.sse.ui.structure.select.previous">
142
		</command>
133
		</command>
143
		<command
134
		<command
144
			name="%ActionDefinition.selectLast.name"
135
			name="%ActionDefinition.selectLast.name"
145
			description="%ActionDefinition.selectLast.description"
136
			description="%ActionDefinition.selectLast.description"
146
			category="org.eclipse.ui.category.edit"
137
			categoryId="org.eclipse.ui.category.edit"
147
			id="org.eclipse.wst.sse.ui.structure.select.last">
138
			id="org.eclipse.wst.sse.ui.structure.select.last">
148
		</command>
139
		</command>
149
		<command
140
		<command
150
			name="%ActionDefinition.showJavadoc.name"
141
			name="%ActionDefinition.showJavadoc.name"
151
			description="%ActionDefinition.showJavadoc.description"
142
			description="%ActionDefinition.showJavadoc.description"
152
			category="org.eclipse.ui.category.edit"
143
			categoryId="org.eclipse.ui.category.edit"
153
			id="org.eclipse.wst.sse.ui.show.javadoc">
144
			id="org.eclipse.wst.sse.ui.show.javadoc">
154
		</command>
145
		</command>
155
		<command
146
		<command
156
			name="%ActionDefinition.quickFix.name"
147
			name="%ActionDefinition.quickFix.name"
157
			description="%ActionDefinition.quickFix.description"
148
			description="%ActionDefinition.quickFix.description"
158
			category="org.eclipse.ui.category.edit"
149
			categoryId="org.eclipse.ui.category.edit"
159
			id="org.eclipse.wst.sse.ui.edit.text.java.correction.assist.proposals">
150
			id="org.eclipse.wst.sse.ui.edit.text.java.correction.assist.proposals">
160
		</command>
151
		</command>
161
		<!-- Source commands -->
152
		<!-- Source commands -->
162
		<command
153
		<command
163
			name="%command.toggle.comment.name"
154
			name="%command.toggle.comment.name"
164
			description="%command.toggle.comment.description"
155
			description="%command.toggle.comment.description"
165
			category="org.eclipse.ui.category.edit"
156
			categoryId="org.eclipse.ui.category.edit"
166
			id="org.eclipse.wst.sse.ui.toggle.comment">
157
			id="org.eclipse.wst.sse.ui.toggle.comment">
167
		</command>
158
		</command>
168
		<command
159
		<command
169
			name="%command.add.block.comment.name"
160
			name="%command.add.block.comment.name"
170
			description="%command.add.block.comment.description"
161
			description="%command.add.block.comment.description"
171
			category="org.eclipse.ui.category.edit"
162
			categoryId="org.eclipse.ui.category.edit"
172
			id="org.eclipse.wst.sse.ui.add.block.comment">
163
			id="org.eclipse.wst.sse.ui.add.block.comment">
173
		</command>
164
		</command>
174
		<command
165
		<command
175
			name="%command.remove.block.comment.name"
166
			name="%command.remove.block.comment.name"
176
			description="%command.remove.block.comment.description"
167
			description="%command.remove.block.comment.description"
177
			category="org.eclipse.ui.category.edit"
168
			categoryId="org.eclipse.ui.category.edit"
178
			id="org.eclipse.wst.sse.ui.remove.block.comment">
169
			id="org.eclipse.wst.sse.ui.remove.block.comment">
179
		</command>
170
		</command>
180
		<command
171
		<command
181
			name="%command.cleanup.document.name"
172
			name="%command.cleanup.document.name"
182
			description="%command.cleanup.document.description"
173
			description="%command.cleanup.document.description"
183
			category="org.eclipse.ui.category.edit"
174
			categoryId="org.eclipse.ui.category.edit"
184
			id="org.eclipse.wst.sse.ui.cleanup.document">
175
			id="org.eclipse.wst.sse.ui.cleanup.document">
185
		</command>
176
		</command>
186
		<command
177
		<command
187
			name="%command.format.document.name"
178
			name="%command.format.document.name"
188
			description="%command.format.document.description"
179
			description="%command.format.document.description"
189
			category="org.eclipse.ui.category.edit"
180
			categoryId="org.eclipse.ui.category.edit"
190
			id="org.eclipse.wst.sse.ui.format.document">
181
			id="org.eclipse.wst.sse.ui.format.document">
191
		</command>
182
		</command>
192
		<command
183
		<command
193
			name="%command.format.active.elements.name"
184
			name="%command.format.active.elements.name"
194
			description="%command.format.active.elements.description"
185
			description="%command.format.active.elements.description"
195
			category="org.eclipse.ui.category.edit"
186
			categoryId="org.eclipse.ui.category.edit"
196
			id="org.eclipse.wst.sse.ui.format.active.elements">
187
			id="org.eclipse.wst.sse.ui.format.active.elements">
197
		</command>
188
		</command>
198
		<!-- Navigate commands -->
189
		<!-- Navigate commands -->
199
		<command
190
		<command
200
			name="%command.open.file.from.source.name"
191
			name="%command.open.file.from.source.name"
201
			description="%command.open.file.from.source.description"
192
			description="%command.open.file.from.source.description"
202
			category="org.eclipse.ui.category.edit"
193
			categoryId="org.eclipse.ui.category.edit"
203
			id="org.eclipse.wst.sse.ui.open.file.from.source">
194
			id="org.eclipse.wst.sse.ui.open.file.from.source">
204
		</command>
195
		</command>
205
		<!-- Find Occurrences -->
196
		<!-- Find Occurrences -->
206
		<command
197
		<command
207
			name="%command.search.find.occurrences.name"
198
			name="%command.search.find.occurrences.name"
208
			description="%command.search.find.occurrences.description"
199
			description="%command.search.find.occurrences.description"
209
			category="org.eclipse.ui.category.edit"
200
			categoryId="org.eclipse.ui.category.edit"
210
			id="org.eclipse.wst.sse.ui.search.find.occurrences">
201
			id="org.eclipse.wst.sse.ui.search.find.occurrences">
211
		</command>
202
		</command>
203
	</extension>
204
	<!-- Keybinding scope for source editor -->
205
	<extension point="org.eclipse.ui.contexts">
206
		<context
207
			name="%scope.structuredTextEditor.name"
208
			parentId="org.eclipse.ui.textEditorScope"
209
			description="%scope.structuredTextEditor.description"
210
			id="org.eclipse.wst.sse.ui.structuredTextEditorScope">
211
		</context>
212
	</extension>
213
	<!-- Keybindings for source editor -->
214
	<extension point="org.eclipse.ui.bindings">
212
		<!-- Edit commands -->
215
		<!-- Edit commands -->
213
		<keyBinding
216
		<key
214
			string="Alt+Shift+ARROW_UP"
217
			sequence="Alt+Shift+ARROW_UP"
215
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
218
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
216
			command="org.eclipse.wst.sse.ui.structure.select.enclosing"
219
			commandId="org.eclipse.wst.sse.ui.structure.select.enclosing"
217
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
220
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
218
		</keyBinding>
221
		</key>
219
		<keyBinding
222
		<key
220
			string="Alt+Shift+ARROW_RIGHT"
223
			sequence="Alt+Shift+ARROW_RIGHT"
221
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
224
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
222
			command="org.eclipse.wst.sse.ui.structure.select.next"
225
			commandId="org.eclipse.wst.sse.ui.structure.select.next"
223
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
226
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
224
		</keyBinding>
227
		</key>
225
		<keyBinding
228
		<key
226
			string="Alt+Shift+ARROW_LEFT"
229
			sequence="Alt+Shift+ARROW_LEFT"
227
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
230
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
228
			command="org.eclipse.wst.sse.ui.structure.select.previous"
231
			commandId="org.eclipse.wst.sse.ui.structure.select.previous"
229
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
232
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
230
		</keyBinding>
233
		</key>
231
		<keyBinding
234
		<key
232
			string="Alt+Shift+ARROW_DOWN"
235
			sequence="Alt+Shift+ARROW_DOWN"
233
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
236
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
234
			command="org.eclipse.wst.sse.ui.structure.select.last"
237
			commandId="org.eclipse.wst.sse.ui.structure.select.last"
235
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
238
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
236
		</keyBinding>
239
		</key>
237
		<keyBinding
240
		<key
238
			string="F2"
241
			sequence="F2"
239
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
242
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
240
			command="org.eclipse.wst.sse.ui.show.javadoc"
243
			commandId="org.eclipse.wst.sse.ui.show.javadoc"
241
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
244
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
242
		</keyBinding>
245
		</key>
243
		<keyBinding
246
		<key
244
			string="Ctrl+1"
247
			sequence="Ctrl+1"
245
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
248
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
246
			command="org.eclipse.wst.sse.ui.edit.text.java.correction.assist.proposals"
249
			commandId="org.eclipse.wst.sse.ui.edit.text.java.correction.assist.proposals"
247
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
250
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
248
		</keyBinding>
251
		</key>
249
		<!-- Source commands -->
252
		<!-- Source commands -->
250
		<keyBinding
253
		<key
251
			string="Ctrl+Shift+C"
254
			sequence="Ctrl+Shift+C"
252
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
255
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
253
			command="org.eclipse.wst.sse.ui.toggle.comment"
256
			commandId="org.eclipse.wst.sse.ui.toggle.comment"
254
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
257
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
255
		</keyBinding>
258
		</key>
256
		<keyBinding
259
		<key
257
			string="Ctrl+Shift+/"
260
			sequence="Ctrl+Shift+/"
258
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
261
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
259
			command="org.eclipse.wst.sse.ui.add.block.comment"
262
			commandId="org.eclipse.wst.sse.ui.add.block.comment"
260
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
263
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
261
		</keyBinding>
264
		</key>
262
		<keyBinding
265
		<key
263
			string="Ctrl+Shift+\"
266
			sequence="Ctrl+Shift+\"
264
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
267
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
265
			command="org.eclipse.wst.sse.ui.remove.block.comment"
268
			commandId="org.eclipse.wst.sse.ui.remove.block.comment"
266
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
269
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
267
		</keyBinding>
270
		</key>
268
		<keyBinding
271
		<key
269
			string="Ctrl+Shift+F"
272
			sequence="Ctrl+Shift+F"
270
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
273
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
271
			command="org.eclipse.wst.sse.ui.format.document"
274
			commandId="org.eclipse.wst.sse.ui.format.document"
272
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
275
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
273
		</keyBinding>
276
		</key>
274
		<keyBinding
277
		<key
275
			string="Ctrl+I"
278
			sequence="Ctrl+I"
276
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
279
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
277
			command="org.eclipse.wst.sse.ui.format.active.elements"
280
			commandId="org.eclipse.wst.sse.ui.format.active.elements"
278
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
281
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
279
		</keyBinding>
282
		</key>
280
		<!-- Navigate commands -->
283
		<!-- Navigate commands -->
281
		<keyBinding
284
		<key
282
			string="F3"
285
			sequence="F3"
283
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
286
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
284
			command="org.eclipse.wst.sse.ui.open.file.from.source"
287
			commandId="org.eclipse.wst.sse.ui.open.file.from.source"
285
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
288
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
286
		</keyBinding>
289
		</key>
287
		<!-- Find Occurrences -->
290
		<!-- Find Occurrences -->
288
		<keyBinding
291
		<key
289
			string="Ctrl+Shift+A"
292
			sequence="Ctrl+Shift+A"
290
			scope="org.eclipse.wst.sse.ui.structuredTextEditorScope"
293
			contextId="org.eclipse.wst.sse.ui.structuredTextEditorScope"
291
			command="org.eclipse.wst.sse.ui.search.find.occurrences"
294
			commandId="org.eclipse.wst.sse.ui.search.find.occurrences"
292
			configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
295
			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
293
		</keyBinding>
296
		</key>
294
	</extension>
297
	</extension>
295
	<!-- Font and colors contributions -->
298
	<!-- Font and colors contributions -->
296
	<extension point="org.eclipse.ui.themes">
299
	<extension point="org.eclipse.ui.themes">
(-)src/org/eclipse/wst/sse/ui/internal/StructuredTextEditor.java (-22 / +13 lines)
Lines 171-180 Link Here
171
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.PropertySheetConfiguration;
171
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.PropertySheetConfiguration;
172
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.StructuredPropertySheetConfiguration;
172
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.StructuredPropertySheetConfiguration;
173
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
173
import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory;
174
import org.eclipse.wst.sse.ui.internal.selection.StructureSelectEnclosingAction;
175
import org.eclipse.wst.sse.ui.internal.selection.StructureSelectHistoryAction;
176
import org.eclipse.wst.sse.ui.internal.selection.StructureSelectNextAction;
177
import org.eclipse.wst.sse.ui.internal.selection.StructureSelectPreviousAction;
178
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
174
import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher;
179
import org.eclipse.wst.sse.ui.internal.util.Assert;
175
import org.eclipse.wst.sse.ui.internal.util.Assert;
180
176
Lines 815-820 Link Here
815
	/** The text context menu manager to be disposed. */
811
	/** The text context menu manager to be disposed. */
816
	private MenuManager fTextContextMenuManager;
812
	private MenuManager fTextContextMenuManager;
817
	private String fViewerConfigurationTargetId;
813
	private String fViewerConfigurationTargetId;
814
	/** The selection history of the editor */
815
	private SelectionHistory fSelectionHistory;
818
816
819
	private boolean fUpdateMenuTextPending;
817
	private boolean fUpdateMenuTextPending;
820
	int hoverX = -1;
818
	int hoverX = -1;
Lines 1155-1178 Link Here
1155
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE, action);
1153
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_OPEN_FILE, action);
1156
1154
1157
		fShowPropertiesAction = new ShowPropertiesAction();
1155
		fShowPropertiesAction = new ShowPropertiesAction();
1158
1159
		SelectionHistory selectionHistory = new SelectionHistory(this);
1160
		action = new StructureSelectEnclosingAction(this, selectionHistory);
1161
		action.setActionDefinitionId(ActionDefinitionIds.STRUCTURE_SELECT_ENCLOSING);
1162
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_ENCLOSING, action);
1163
1164
		action = new StructureSelectNextAction(this, selectionHistory);
1165
		action.setActionDefinitionId(ActionDefinitionIds.STRUCTURE_SELECT_NEXT);
1166
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_NEXT, action);
1167
1168
		action = new StructureSelectPreviousAction(this, selectionHistory);
1169
		action.setActionDefinitionId(ActionDefinitionIds.STRUCTURE_SELECT_PREVIOUS);
1170
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_PREVIOUS, action);
1171
1172
		action = new StructureSelectHistoryAction(this, selectionHistory);
1173
		action.setActionDefinitionId(ActionDefinitionIds.STRUCTURE_SELECT_HISTORY);
1174
		setAction(StructuredTextEditorActionConstants.ACTION_NAME_STRUCTURE_SELECT_HISTORY, action);
1175
		selectionHistory.setHistoryAction((StructureSelectHistoryAction) action);
1176
	}
1156
	}
1177
1157
1178
	protected LineChangeHover createChangeHover() {
1158
	protected LineChangeHover createChangeHover() {
Lines 1385-1390 Link Here
1385
			System.out.println("Total time in getAdapter: " + adapterTime); //$NON-NLS-1$
1365
			System.out.println("Total time in getAdapter: " + adapterTime); //$NON-NLS-1$
1386
			System.out.println("Average time per call: " + (adapterTime / adapterRequests)); //$NON-NLS-1$
1366
			System.out.println("Average time per call: " + (adapterTime / adapterRequests)); //$NON-NLS-1$
1387
		}
1367
		}
1368
		
1369
		// dispose of selection history
1370
		if (fSelectionHistory != null) {
1371
			fSelectionHistory.dispose();
1372
			fSelectionHistory = null;
1373
		}
1388
1374
1389
		// dispose of document folding support
1375
		// dispose of document folding support
1390
		if (fProjectionModelUpdater != null) {
1376
		if (fProjectionModelUpdater != null) {
Lines 1733-1738 Link Here
1733
		else if (IShowInTargetList.class.equals(required)) {
1719
		else if (IShowInTargetList.class.equals(required)) {
1734
			return new ShowInTargetListAdapter();
1720
			return new ShowInTargetListAdapter();
1735
		}
1721
		}
1722
		else if (SelectionHistory.class.equals(required)) {
1723
			if (fSelectionHistory == null)
1724
				fSelectionHistory = new SelectionHistory(this);
1725
			return fSelectionHistory;
1726
		}
1736
		else {
1727
		else {
1737
			if (result == null && getInternalModel() != null) {
1728
			if (result == null && getInternalModel() != null) {
1738
				result = getInternalModel().getAdapter(required);
1729
				result = getInternalModel().getAdapter(required);
(-)src/org/eclipse/wst/sse/ui/internal/search/BasicFindOccurrencesAction.java (-1 / +1 lines)
Lines 42-48 Link Here
42
 * Java elements, etc...)
42
 * Java elements, etc...)
43
 * </p>
43
 * </p>
44
 * 
44
 * 
45
 * @author pavery
45
 * @deprecated use FindOccurrencesProcessor instead
46
 */
46
 */
47
public class BasicFindOccurrencesAction extends TextEditorAction {
47
public class BasicFindOccurrencesAction extends TextEditorAction {
48
	private IStructuredDocument fDocument = null;
48
	private IStructuredDocument fDocument = null;
(-)src/org/eclipse/wst/sse/ui/internal/search/FindOccurrencesActionProvider.java (-1 / +1 lines)
Lines 33-39 Link Here
33
 * Clients can add actions for different partitions via
33
 * Clients can add actions for different partitions via
34
 * <code>addAction(BasicFindOccurrencesAction action)</code>
34
 * <code>addAction(BasicFindOccurrencesAction action)</code>
35
 * 
35
 * 
36
 * @author pavery
36
 * @deprecated use FindOccurrencesActionDelegate instead
37
 */
37
 */
38
public class FindOccurrencesActionProvider extends TextEditorAction {
38
public class FindOccurrencesActionProvider extends TextEditorAction {
39
39
(-)src/org/eclipse/wst/sse/ui/internal/selection/SelectionHistory.java (-7 / +38 lines)
Lines 13-20 Link Here
13
package org.eclipse.wst.sse.ui.internal.selection;
13
package org.eclipse.wst.sse.ui.internal.selection;
14
14
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Iterator;
16
import java.util.List;
17
import java.util.List;
17
18
19
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.text.IRegion;
20
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.util.Assert;
21
import org.eclipse.jface.util.Assert;
20
import org.eclipse.jface.viewers.ISelectionChangedListener;
22
import org.eclipse.jface.viewers.ISelectionChangedListener;
Lines 23-31 Link Here
23
25
24
public class SelectionHistory {
26
public class SelectionHistory {
25
	private ITextEditor fEditor;
27
	private ITextEditor fEditor;
26
27
	private List fHistory;
28
	private List fHistory;
28
	private StructureSelectHistoryAction fHistoryAction;
29
	private List fHistoryActions;
29
	private int fSelectionChangeListenerCounter;
30
	private int fSelectionChangeListenerCounter;
30
	private ISelectionChangedListener fSelectionListener;
31
	private ISelectionChangedListener fSelectionListener;
31
32
Lines 44-56 Link Here
44
45
45
	public void dispose() {
46
	public void dispose() {
46
		fEditor.getSelectionProvider().removeSelectionChangedListener(fSelectionListener);
47
		fEditor.getSelectionProvider().removeSelectionChangedListener(fSelectionListener);
48
		fEditor = null;
49
		if (fHistory != null && !fHistory.isEmpty()) {
50
			fHistory.clear();
51
		}
52
		if (fHistoryActions != null && !fHistoryActions.isEmpty()) {
53
			fHistoryActions.clear();
54
		}
47
	}
55
	}
48
56
49
	public void flush() {
57
	public void flush() {
50
		if (fHistory.isEmpty())
58
		if (fHistory.isEmpty())
51
			return;
59
			return;
52
		fHistory.clear();
60
		fHistory.clear();
53
		fHistoryAction.update();
61
		updateHistoryAction();
54
	}
62
	}
55
63
56
	public IRegion getLast() {
64
	public IRegion getLast() {
Lines 58-64 Link Here
58
			return null;
66
			return null;
59
		int size = fHistory.size();
67
		int size = fHistory.size();
60
		IRegion result = (IRegion) fHistory.remove(size - 1);
68
		IRegion result = (IRegion) fHistory.remove(size - 1);
61
		fHistoryAction.update();
69
		updateHistoryAction();
62
		return result;
70
		return result;
63
	}
71
	}
64
72
Lines 76-86 Link Here
76
84
77
	public void remember(IRegion region) {
85
	public void remember(IRegion region) {
78
		fHistory.add(region);
86
		fHistory.add(region);
79
		fHistoryAction.update();
87
		updateHistoryAction();
80
	}
88
	}
81
89
82
	public void setHistoryAction(StructureSelectHistoryAction action) {
90
	public void setHistoryAction(IAction action) {
83
		Assert.isNotNull(action);
91
		Assert.isNotNull(action);
84
		fHistoryAction = action;
92
		
93
		if (fHistoryActions == null)
94
			fHistoryActions = new ArrayList();
95
		if (!fHistoryActions.contains(action))
96
			fHistoryActions.add(action);
97
		
98
		// update action
99
		if (fHistory != null && !fHistory.isEmpty())
100
			action.setEnabled(true);
101
		else
102
			action.setEnabled(false);
103
	}
104
105
	private void updateHistoryAction() {
106
		if (fHistoryActions != null && !fHistoryActions.isEmpty()) {
107
			boolean enabled = false;
108
			if (fHistory != null && !fHistory.isEmpty())
109
				enabled = true;
110
111
			Iterator iter = fHistoryActions.iterator();
112
			while (iter.hasNext()) {
113
				((IAction)iter.next()).setEnabled(enabled);
114
			}
115
		}
85
	}
116
	}
86
}
117
}
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructureSelectAction.java (-12 / +22 lines)
Lines 13-44 Link Here
13
package org.eclipse.wst.sse.ui.internal.selection;
13
package org.eclipse.wst.sse.ui.internal.selection;
14
14
15
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.text.IDocument;
16
import org.eclipse.jface.text.Region;
17
import org.eclipse.jface.text.Region;
17
import org.eclipse.jface.util.Assert;
18
import org.eclipse.jface.util.Assert;
18
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
19
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
19
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
20
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
21
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
20
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
22
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
21
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
23
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
22
import org.w3c.dom.Node;
24
import org.w3c.dom.Node;
23
25
24
26
/**
27
 * @deprecated use StructuredSelectActionDelegate instead
28
 */
25
public abstract class StructureSelectAction extends Action {
29
public abstract class StructureSelectAction extends Action {
26
	protected StructuredTextEditor fEditor = null;
30
	protected StructuredTextEditor fEditor = null;
27
	protected SelectionHistory fHistory;
31
	protected SelectionHistory fHistory;
28
	protected IStructuredModel fModel = null;
29
	protected StructuredTextViewer fViewer = null;
32
	protected StructuredTextViewer fViewer = null;
30
33
31
	public StructureSelectAction(StructuredTextEditor editor, SelectionHistory history) {
34
	public StructureSelectAction(StructuredTextEditor editor) {
32
		super();
35
		super();
33
36
34
		Assert.isNotNull(editor);
37
		Assert.isNotNull(editor);
35
		Assert.isNotNull(history);
36
		fEditor = editor;
38
		fEditor = editor;
37
		fHistory = history;
39
		fHistory = (SelectionHistory) editor.getAdapter(SelectionHistory.class);
38
		fViewer = editor.getTextViewer();
40
		fViewer = editor.getTextViewer();
39
		fModel = editor.getModel();
40
		Assert.isNotNull(fViewer);
41
		Assert.isNotNull(fViewer);
41
		//Assert.isNotNull(fModel);
42
	}
42
	}
43
43
44
	abstract protected IndexedRegion getCursorIndexedRegion();
44
	abstract protected IndexedRegion getCursorIndexedRegion();
Lines 47-56 Link Here
47
		IndexedRegion indexedRegion = null;
47
		IndexedRegion indexedRegion = null;
48
48
49
		int lastOffset = offset;
49
		int lastOffset = offset;
50
		indexedRegion = fModel.getIndexedRegion(lastOffset);
50
		IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
51
		while (indexedRegion == null && lastOffset >= 0) {
51
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
52
			lastOffset--;
52
		if (model != null) {
53
			indexedRegion = fModel.getIndexedRegion(lastOffset);
53
			try {
54
				indexedRegion = model.getIndexedRegion(lastOffset);
55
				while (indexedRegion == null && lastOffset >= 0) {
56
					lastOffset--;
57
					indexedRegion = model.getIndexedRegion(lastOffset);
58
				}
59
			}
60
			finally {
61
				model.releaseFromRead();
62
			}
54
		}
63
		}
55
64
56
		return indexedRegion;
65
		return indexedRegion;
Lines 88-94 Link Here
88
				try {
97
				try {
89
					fHistory.ignoreSelectionChanges();
98
					fHistory.ignoreSelectionChanges();
90
					fEditor.selectAndReveal(newRegion.getOffset(), newRegion.getLength());
99
					fEditor.selectAndReveal(newRegion.getOffset(), newRegion.getLength());
91
				} finally {
100
				}
101
				finally {
92
					fHistory.listenToSelectionChanges();
102
					fHistory.listenToSelectionChanges();
93
				}
103
				}
94
			}
104
			}
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructureSelectEnclosingAction.java (-2 / +7 lines)
Lines 18-26 Link Here
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
19
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
20
20
21
/**
22
 * @deprecated use
23
 *             org.eclipse.wst.xml.ui.internal.selection.StructuredSelectEnclosingXMLActionDelegate
24
 *             instead
25
 */
21
public class StructureSelectEnclosingAction extends StructureSelectAction {
26
public class StructureSelectEnclosingAction extends StructureSelectAction {
22
	public StructureSelectEnclosingAction(StructuredTextEditor editor, SelectionHistory history) {
27
	public StructureSelectEnclosingAction(StructuredTextEditor editor) {
23
		super(editor, history);
28
		super(editor);
24
		setText(SSEUIMessages.StructureSelectEnclosing_label); //$NON-NLS-1$
29
		setText(SSEUIMessages.StructureSelectEnclosing_label); //$NON-NLS-1$
25
		setToolTipText(SSEUIMessages.StructureSelectEnclosing_tooltip); //$NON-NLS-1$
30
		setToolTipText(SSEUIMessages.StructureSelectEnclosing_tooltip); //$NON-NLS-1$
26
		setDescription(SSEUIMessages.StructureSelectEnclosing_description); //$NON-NLS-1$
31
		setDescription(SSEUIMessages.StructureSelectEnclosing_description); //$NON-NLS-1$
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructureSelectHistoryAction.java (-2 / +6 lines)
Lines 20-32 Link Here
20
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
20
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
21
import org.w3c.dom.Node;
21
import org.w3c.dom.Node;
22
22
23
/**
24
 * @deprecated use StructuredSelectHistoryActionDelegate instead
25
 */
23
public class StructureSelectHistoryAction extends StructureSelectAction implements IUpdate {
26
public class StructureSelectHistoryAction extends StructureSelectAction implements IUpdate {
24
	public StructureSelectHistoryAction(StructuredTextEditor editor, SelectionHistory history) {
27
	public StructureSelectHistoryAction(StructuredTextEditor editor) {
25
		super(editor, history);
28
		super(editor);
26
		setText(SSEUIMessages.StructureSelectHistory_label); //$NON-NLS-1$
29
		setText(SSEUIMessages.StructureSelectHistory_label); //$NON-NLS-1$
27
		setToolTipText(SSEUIMessages.StructureSelectHistory_tooltip); //$NON-NLS-1$
30
		setToolTipText(SSEUIMessages.StructureSelectHistory_tooltip); //$NON-NLS-1$
28
		setDescription(SSEUIMessages.StructureSelectHistory_description); //$NON-NLS-1$
31
		setDescription(SSEUIMessages.StructureSelectHistory_description); //$NON-NLS-1$
29
32
33
		fHistory.setHistoryAction(this);
30
		update();
34
		update();
31
	}
35
	}
32
36
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructureSelectNextAction.java (-2 / +7 lines)
Lines 18-26 Link Here
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
19
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
20
20
21
/**
22
 * @deprecated use
23
 *             org.eclipse.wst.xml.ui.internal.selection.StructuredSelectNextXMLActionDelegate
24
 *             instead
25
 */
21
public class StructureSelectNextAction extends StructureSelectAction {
26
public class StructureSelectNextAction extends StructureSelectAction {
22
	public StructureSelectNextAction(StructuredTextEditor editor, SelectionHistory history) {
27
	public StructureSelectNextAction(StructuredTextEditor editor) {
23
		super(editor, history);
28
		super(editor);
24
		setText(SSEUIMessages.StructureSelectNext_label); //$NON-NLS-1$
29
		setText(SSEUIMessages.StructureSelectNext_label); //$NON-NLS-1$
25
		setToolTipText(SSEUIMessages.StructureSelectNext_tooltip); //$NON-NLS-1$
30
		setToolTipText(SSEUIMessages.StructureSelectNext_tooltip); //$NON-NLS-1$
26
		setDescription(SSEUIMessages.StructureSelectNext_description); //$NON-NLS-1$
31
		setDescription(SSEUIMessages.StructureSelectNext_description); //$NON-NLS-1$
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructureSelectPreviousAction.java (-2 / +7 lines)
Lines 18-26 Link Here
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
18
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
19
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
20
20
21
/**
22
 * @deprecated use
23
 *             org.eclipse.wst.xml.ui.internal.selection.StructuredSelectPreviousXMLActionDelegate
24
 *             instead
25
 */
21
public class StructureSelectPreviousAction extends StructureSelectAction {
26
public class StructureSelectPreviousAction extends StructureSelectAction {
22
	public StructureSelectPreviousAction(StructuredTextEditor editor, SelectionHistory history) {
27
	public StructureSelectPreviousAction(StructuredTextEditor editor) {
23
		super(editor, history);
28
		super(editor);
24
		setText(SSEUIMessages.StructureSelectPrevious_label); //$NON-NLS-1$
29
		setText(SSEUIMessages.StructureSelectPrevious_label); //$NON-NLS-1$
25
		setToolTipText(SSEUIMessages.StructureSelectPrevious_tooltip); //$NON-NLS-1$
30
		setToolTipText(SSEUIMessages.StructureSelectPrevious_tooltip); //$NON-NLS-1$
26
		setDescription(SSEUIMessages.StructureSelectPrevious_description); //$NON-NLS-1$
31
		setDescription(SSEUIMessages.StructureSelectPrevious_description); //$NON-NLS-1$
(-)src/org/eclipse/wst/sse/ui/internal/search/FindOccurrencesActionDelegate.java (+147 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 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
 *     
11
 *******************************************************************************/
12
13
package org.eclipse.wst.sse.ui.internal.search;
14
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.text.BadLocationException;
21
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.ITextSelection;
23
import org.eclipse.jface.text.ITypedRegion;
24
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.swt.widgets.Event;
26
import org.eclipse.ui.IActionDelegate2;
27
import org.eclipse.ui.IEditorActionDelegate;
28
import org.eclipse.ui.IEditorPart;
29
import org.eclipse.ui.IFileEditorInput;
30
import org.eclipse.ui.IViewActionDelegate;
31
import org.eclipse.ui.IViewPart;
32
import org.eclipse.ui.texteditor.ITextEditor;
33
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
34
import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil;
35
36
/**
37
 * Performs the appropriate FindOccurrencesProcessor action call based on
38
 * selection. Clients can add processors for different partitions via
39
 * <code>getProcessors</code>
40
 * 
41
 */
42
abstract public class FindOccurrencesActionDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
43
	private IEditorPart fEditor;
44
45
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
46
		fEditor = targetEditor;
47
	}
48
49
	public void dispose() {
50
		// nulling out just in case
51
		fEditor = null;
52
	}
53
54
	public void init(IAction action) {
55
		if (action != null) {
56
			action.setText(SSEUIMessages.FindOccurrences_label);
57
		}
58
	}
59
60
	public void runWithEvent(IAction action, Event event) {
61
		run(action);
62
	}
63
64
	public void run(IAction action) {
65
		boolean okay = false;
66
		if (fEditor instanceof ITextEditor) {
67
			ITextEditor textEditor = (ITextEditor) fEditor;
68
			IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
69
			if (document != null) {
70
				ITextSelection textSelection = getTextSelection(textEditor);
71
				FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection);
72
				if (findOccurrenceProcessor != null) {
73
					if (textEditor.getEditorInput() instanceof IFileEditorInput) {
74
						IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
75
						okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file);
76
					}
77
				}
78
			}
79
		}
80
		if (okay) {
81
			// clear status message
82
			PlatformStatusLineUtil.clearStatusLine();
83
		}
84
		else {
85
			String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0; //$NON-NLS-1$
86
			PlatformStatusLineUtil.displayErrorMessage(errorMessage);
87
			PlatformStatusLineUtil.addOneTimeClearListener();
88
		}
89
	}
90
91
	public void init(IViewPart view) {
92
		// do nothing
93
	}
94
95
	public void selectionChanged(IAction action, ISelection selection) {
96
		// clear status message
97
		PlatformStatusLineUtil.clearStatusLine();
98
	}
99
100
	/**
101
	 * Get the appropriate find occurrences processor
102
	 * 
103
	 * @param document -
104
	 *            assumes not null
105
	 * @param textSelection
106
	 * @return
107
	 */
108
	private FindOccurrencesProcessor getProcessorForCurrentSelection(IDocument document, ITextSelection textSelection) {
109
		// check if we have an action that's enabled on the current partition
110
		ITypedRegion tr = getPartition(document, textSelection);
111
		String partition = tr != null ? tr.getType() : ""; //$NON-NLS-1$
112
113
		Iterator it = getProcessors().iterator();
114
		FindOccurrencesProcessor action = null;
115
		while (it.hasNext()) {
116
			action = (FindOccurrencesProcessor) it.next();
117
			// we just choose the first action that can handle the partition
118
			if (action.enabledForParitition(partition))
119
				return action;
120
		}
121
		return null;
122
	}
123
124
	private ITypedRegion getPartition(IDocument document, ITextSelection textSelection) {
125
		ITypedRegion region = null;
126
		if (textSelection != null) {
127
			try {
128
				region = document.getPartition(textSelection.getOffset());
129
			}
130
			catch (BadLocationException e) {
131
				region = null;
132
			}
133
		}
134
		return region;
135
	}
136
137
	private ITextSelection getTextSelection(ITextEditor textEditor) {
138
		ITextSelection textSelection = null;
139
		ISelection selection = textEditor.getSelectionProvider().getSelection();
140
		if (selection instanceof ITextSelection && !selection.isEmpty()) {
141
			textSelection = (ITextSelection) selection;
142
		}
143
		return textSelection;
144
	}
145
146
	abstract protected List getProcessors();
147
}
(-)src/org/eclipse/wst/sse/ui/internal/search/FindOccurrencesProcessor.java (+121 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 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
 *     
11
 *******************************************************************************/
12
13
package org.eclipse.wst.sse.ui.internal.search;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.ITextSelection;
18
import org.eclipse.search.ui.ISearchQuery;
19
import org.eclipse.search.ui.NewSearchUI;
20
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
21
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
22
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
23
24
/**
25
 * <p>
26
 * Finds occurrences of a specified region type w/ region text in an
27
 * IStructuredDocument. Clients must implement getPartitionTypes() and
28
 * getRegionTypes() to indicate which partition types and region types it can
29
 * operate on.
30
 * </p>
31
 * 
32
 * <p>
33
 * Clients should override <code>getSearchQuery()</code> in order to provide
34
 * their own type of "search" (eg. searching for XML start tags, searching for
35
 * Java elements, etc...)
36
 * </p>
37
 * 
38
 */
39
abstract public class FindOccurrencesProcessor {
40
	public boolean findOccurrences(IDocument document, ITextSelection textSelection, IFile file) {
41
		boolean findOccurrences = false;
42
43
		// determine if action should be enabled or not
44
		if (document instanceof IStructuredDocument) {
45
			IStructuredDocument structuredDocument = (IStructuredDocument) document;
46
			IStructuredDocumentRegion sdRegion = structuredDocument.getRegionAtCharacterOffset(textSelection.getOffset());
47
			if (sdRegion != null) {
48
				ITextRegion r = sdRegion.getRegionAtCharacterOffset(textSelection.getOffset());
49
				if (r != null) {
50
					String type = r.getType();
51
					if (enabledForRegionType(type)) {
52
						String matchText = sdRegion.getText(r);
53
54
						// first of all activate the view
55
						NewSearchUI.activateSearchResultView();
56
57
						if (matchText != null && type != null) {
58
							ISearchQuery searchQuery = getSearchQuery(file, structuredDocument, matchText, type, textSelection);
59
							if (searchQuery != null) {
60
								if (searchQuery.canRunInBackground())
61
									NewSearchUI.runQueryInBackground(searchQuery);
62
								else
63
									NewSearchUI.runQueryInForeground(null, searchQuery);
64
							}
65
							findOccurrences = true;
66
						}
67
					}
68
				}
69
			}
70
		}
71
		return findOccurrences;
72
	}
73
74
	/**
75
	 * @param regionType
76
	 * @return <code>true</code> if this action can operate on this region
77
	 *         type (ITextRegion), otherwise false.
78
	 */
79
	private boolean enabledForRegionType(String regionType) {
80
81
		String[] accept = getRegionTypes();
82
		for (int i = 0; i < accept.length; i++) {
83
			if (regionType.equals(accept[i]))
84
				return true;
85
		}
86
		return false;
87
	}
88
89
	/**
90
	 * Clients should override this to enable find occurrences on certain
91
	 * partition(s).
92
	 */
93
	abstract protected String[] getPartitionTypes();
94
95
	/**
96
	 * Clients should override this to enable find occurrences on different
97
	 * region type(s).
98
	 */
99
	abstract protected String[] getRegionTypes();
100
101
	/**
102
	 * Clients should override to provide their own search for the file.
103
	 */
104
	protected ISearchQuery getSearchQuery(IFile file, IStructuredDocument document, String regionText, String regionType, ITextSelection textSelection) {
105
		return new OccurrencesSearchQuery(file, document, regionText, regionType);
106
	}
107
108
	/**
109
	 * @param partitionType
110
	 * @return <code>true</code> if this action can operate on this type of
111
	 *         partition, otherwise <code>false</code>.
112
	 */
113
	public boolean enabledForParitition(String partitionType) {
114
		String[] accept = getPartitionTypes();
115
		for (int i = 0; i < accept.length; i++) {
116
			if (partitionType.equals(accept[i]))
117
				return true;
118
		}
119
		return false;
120
	}
121
}
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructuredSelectActionDelegate.java (+124 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 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
 *     
11
 *******************************************************************************/
12
13
package org.eclipse.wst.sse.ui.internal.selection;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.IDocument;
17
import org.eclipse.jface.text.ITextSelection;
18
import org.eclipse.jface.text.Region;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.swt.widgets.Event;
21
import org.eclipse.ui.IActionDelegate2;
22
import org.eclipse.ui.IEditorActionDelegate;
23
import org.eclipse.ui.IEditorPart;
24
import org.eclipse.ui.IViewActionDelegate;
25
import org.eclipse.ui.IViewPart;
26
import org.eclipse.ui.texteditor.ITextEditor;
27
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
28
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
29
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
30
31
abstract public class StructuredSelectActionDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
32
	private IEditorPart fEditor;
33
	private SelectionHistory fHistory;
34
35
	public void dispose() {
36
		fEditor = null;
37
		fHistory = null;
38
	}
39
40
	public void init(IViewPart view) {
41
		// do nothing
42
	}
43
44
	public void runWithEvent(IAction action, Event event) {
45
		run(action);
46
	}
47
48
	public void run(IAction action) {
49
		if (fEditor instanceof ITextEditor) {
50
			ITextEditor textEditor = (ITextEditor) fEditor;
51
52
			ISelection selection = textEditor.getSelectionProvider().getSelection();
53
			IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
54
			// determine current text selection
55
			if (selection instanceof ITextSelection && document != null) {
56
				ITextSelection textSelection = (ITextSelection) selection;
57
58
				if (textSelection.getLength() < document.getLength()) {
59
					// get current indexed region
60
					IndexedRegion cursorIndexedRegion = getCursorIndexedRegion(document, textSelection);
61
62
					// determine new selection based on current indexed region
63
					Region newSelectionRegion = getNewSelectionRegion(cursorIndexedRegion, textSelection);
64
65
					// select new selection
66
					if (newSelectionRegion != null) {
67
						fHistory.remember(new Region(textSelection.getOffset(), textSelection.getLength()));
68
						try {
69
							fHistory.ignoreSelectionChanges();
70
							textEditor.selectAndReveal(newSelectionRegion.getOffset(), newSelectionRegion.getLength());
71
						}
72
						finally {
73
							fHistory.listenToSelectionChanges();
74
						}
75
					}
76
				}
77
			}
78
		}
79
	}
80
81
	public void selectionChanged(IAction action, ISelection selection) {
82
		// do nothing
83
	}
84
85
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
86
		fEditor = targetEditor;
87
		if (fEditor != null)
88
			fHistory = (SelectionHistory) fEditor.getAdapter(SelectionHistory.class);
89
		else
90
			fHistory = null;
91
	}
92
	
93
	abstract protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection);
94
	
95
	abstract protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection);
96
	
97
	/**
98
	 * This method will probably be removed and replaced by using new selection provider
99
	 * @param document
100
	 * @param offset
101
	 * @return
102
	 */
103
	protected IndexedRegion getIndexedRegion(IDocument document, int offset) {
104
		IndexedRegion indexedRegion = null;
105
106
		int lastOffset = offset;
107
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
108
		if (model != null) {
109
			try {
110
				indexedRegion = model.getIndexedRegion(lastOffset);
111
				while (indexedRegion == null && lastOffset >= 0) {
112
					lastOffset--;
113
					indexedRegion = model.getIndexedRegion(lastOffset);
114
				}
115
			}
116
			finally {
117
				model.releaseFromRead();
118
			}
119
		}
120
121
		return indexedRegion;
122
	}
123
124
}
(-)src/org/eclipse/wst/sse/ui/internal/selection/StructuredSelectHistoryActionDelegate.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 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
 *     
11
 *******************************************************************************/
12
13
package org.eclipse.wst.sse.ui.internal.selection;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.IRegion;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.swt.widgets.Event;
19
import org.eclipse.ui.IActionDelegate2;
20
import org.eclipse.ui.IEditorActionDelegate;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IViewActionDelegate;
23
import org.eclipse.ui.IViewPart;
24
import org.eclipse.ui.texteditor.ITextEditor;
25
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
26
27
/**
28
 * Selection history action delegate. Keeps track of selection within editor.
29
 */
30
public class StructuredSelectHistoryActionDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
31
	private IEditorPart fEditor;
32
	private SelectionHistory fHistory;
33
34
	public void dispose() {
35
		fEditor = null;
36
		fHistory = null;
37
	}
38
39
	public void init(IAction action) {
40
		if (action != null) {
41
			action.setText(SSEUIMessages.StructureSelectHistory_label);
42
			action.setToolTipText(SSEUIMessages.StructureSelectHistory_tooltip);
43
			action.setDescription(SSEUIMessages.StructureSelectHistory_description);
44
		}
45
	}
46
47
	public void init(IViewPart view) {
48
		// do nothing
49
	}
50
51
	public void run(IAction action) {
52
		IRegion old = fHistory.getLast();
53
		if (old != null) {
54
			try {
55
				fHistory.ignoreSelectionChanges();
56
				if (fEditor instanceof ITextEditor)
57
					((ITextEditor) fEditor).selectAndReveal(old.getOffset(), old.getLength());
58
			}
59
			finally {
60
				fHistory.listenToSelectionChanges();
61
			}
62
		}
63
	}
64
65
	public void runWithEvent(IAction action, Event event) {
66
		run(action);
67
	}
68
69
	public void selectionChanged(IAction action, ISelection selection) {
70
		// do nothing
71
	}
72
73
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
74
		fEditor = targetEditor;
75
		if (fEditor != null)
76
			fHistory = (SelectionHistory) fEditor.getAdapter(SelectionHistory.class);
77
		else
78
			fHistory = null;
79
		if (fHistory != null) {
80
			fHistory.setHistoryAction(action);
81
		}
82
	}
83
}

Return to bug 109468