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.properties (-1 / +19 lines)
Lines 49-52 Link Here
49
###############################################################################
49
###############################################################################
50
_UI_XML_VALIDATOR                   = XML Validator
50
_UI_XML_VALIDATOR                   = XML Validator
51
_UI_REF_FILE_SHOW_DETAILS           = Show Details...
51
_UI_REF_FILE_SHOW_DETAILS           = Show Details...
52
_UI_MENU_VALIDATE_XML               = Validate XML File 
52
_UI_MENU_VALIDATE_XML               = Validate XML File
53
##
54
CleanupDocument_label=Cleanup Document...
55
CleanupDocument_tooltip=Cleanup Document
56
ToggleComment_label=Toggle Comment
57
ToggleComment_tooltip=Toggle Comment
58
AddBlockComment_label=Add Block Comment
59
AddBlockComment_tooltip=Add Block Comment
60
RemoveBlockComment_label=Remove Block Comment
61
RemoveBlockComment_tooltip=Remove Block Comment
62
FindOccurrences_label=Occurrences in File
63
StructureSelectEnclosing_label=Enclosing Element
64
StructureSelectEnclosing_tooltip=Expand selection to include enclosing element
65
StructureSelectNext_label=Next Element
66
StructureSelectNext_tooltip=Expand selection to include next sibling
67
StructureSelectPrevious_label=Previous Element
68
StructureSelectPrevious_tooltip=Expand selection to include previous sibling
69
StructureSelectHistory_label=Restore Last Selection
70
StructureSelectHistory_tooltip=Restore last selection
(-)plugin.xml (-1 / +77 lines)
Lines 477-481 Link Here
477
		</validator>
477
		</validator>
478
	</extension>
478
	</extension>
479
479
480
480
	<extension point="org.eclipse.ui.editorActions">
481
		<editorContribution
482
			id="org.eclipse.core.runtime.xml.source.editorActions"
483
			targetID="org.eclipse.core.runtime.xml.source">
484
			<action
485
				id="CleanupDocument"
486
				label="%CleanupDocument_label"
487
				definitionId="org.eclipse.wst.sse.ui.cleanup.document"
488
				tooltip="%CleanupDocument_tooltip"
489
				class="org.eclipse.wst.xml.ui.internal.actions.CleanupActionXMLDelegate"
490
				actionID="CleanupDocument">
491
			</action>
492
			<action
493
				id="ToggleComment"
494
				label="%ToggleComment_label"
495
				definitionId="org.eclipse.wst.sse.ui.toggle.comment"
496
				tooltip="%ToggleComment_tooltip"
497
				class="org.eclipse.wst.xml.ui.internal.actions.ToggleCommentActionXMLDelegate"
498
				actionID="ToggleComment">
499
			</action>
500
			<action
501
				id="AddBlockComment"
502
				label="%AddBlockComment_label"
503
				definitionId="org.eclipse.wst.sse.ui.add.block.comment"
504
				tooltip="%AddBlockComment_tooltip"
505
				class="org.eclipse.wst.xml.ui.internal.actions.AddBlockCommentActionXMLDelegate"
506
				actionID="AddBlockComment">
507
			</action>
508
			<action
509
				id="RemoveBlockComment"
510
				label="%RemoveBlockComment_label"
511
				definitionId="org.eclipse.wst.sse.ui.remove.block.comment"
512
				tooltip="%RemoveBlockComment_tooltip"
513
				class="org.eclipse.wst.xml.ui.internal.actions.RemoveBlockCommentActionXMLDelegate"
514
				actionID="RemoveBlockComment">
515
			</action>
516
			<action
517
				id="FindOccurrences"
518
				label="%FindOccurrences_label"
519
				definitionId="org.eclipse.wst.sse.ui.search.find.occurrences"
520
				class="org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesActionDelegate"
521
				actionID="FindOccurrences">
522
			</action>
523
			<action
524
				id="StructureSelectEnclosing"
525
				label="%StructureSelectEnclosing_label"
526
				definitionId="org.eclipse.wst.sse.ui.structure.select.enclosing"
527
				tooltip="%StructureSelectEnclosing_tooltip"
528
				class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectEnclosingXMLActionDelegate"
529
				actionID="StructureSelectEnclosing">
530
			</action>
531
			<action
532
				id="StructureSelectNext"
533
				label="%StructureSelectNext_label"
534
				definitionId="org.eclipse.wst.sse.ui.structure.select.next"
535
				tooltip="%StructureSelectNext_tooltip"
536
				class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectNextXMLActionDelegate"
537
				actionID="StructureSelectNext">
538
			</action>
539
			<action
540
				id="StructureSelectPrevious"
541
				label="%StructureSelectPrevious_label"
542
				definitionId="org.eclipse.wst.sse.ui.structure.select.previous"
543
				tooltip="%StructureSelectPrevious_tooltip"
544
				class="org.eclipse.wst.xml.ui.internal.selection.StructuredSelectPreviousXMLActionDelegate"
545
				actionID="StructureSelectPrevious">
546
			</action>
547
			<action
548
				id="StructureSelectHistory"
549
				label="%StructureSelectHistory_label"
550
				definitionId="org.eclipse.wst.sse.ui.structure.select.last"
551
				tooltip="%StructureSelectHistory_tooltip"
552
				class="org.eclipse.wst.sse.ui.internal.selection.StructuredSelectHistoryActionDelegate"
553
				actionID="StructureSelectHistory">
554
			</action>
555
		</editorContribution>
556
	</extension>
481
</plugin>
557
</plugin>
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 27-32 Link Here
27
 org.eclipse.wst.xml.ui.internal.provisional,
27
 org.eclipse.wst.xml.ui.internal.provisional,
28
 org.eclipse.wst.xml.ui.internal.registry,
28
 org.eclipse.wst.xml.ui.internal.registry,
29
 org.eclipse.wst.xml.ui.internal.search,
29
 org.eclipse.wst.xml.ui.internal.search,
30
  org.eclipse.wst.xml.ui.internal.selection,
30
 org.eclipse.wst.xml.ui.internal.style,
31
 org.eclipse.wst.xml.ui.internal.style,
31
 org.eclipse.wst.xml.ui.internal.tabletree,
32
 org.eclipse.wst.xml.ui.internal.tabletree,
32
 org.eclipse.wst.xml.ui.internal.taginfo,
33
 org.eclipse.wst.xml.ui.internal.taginfo,
(-)src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java (+9 lines)
Lines 271-276 Link Here
271
	public static String OpenFileFromSource_tooltip; // Resource bundle
271
	public static String OpenFileFromSource_tooltip; // Resource bundle
272
	public static String OpenFileFromSource_description; // Resource bundle
272
	public static String OpenFileFromSource_description; // Resource bundle
273
	public static String XMLContentOutlineConfiguration_0;
273
	public static String XMLContentOutlineConfiguration_0;
274
	public static String StructureSelectEnclosing_label;
275
	public static String StructureSelectEnclosing_tooltip;
276
	public static String StructureSelectEnclosing_description;
277
	public static String StructureSelectNext_label;
278
	public static String StructureSelectNext_tooltip;
279
	public static String StructureSelectNext_description;
280
	public static String StructureSelectPrevious_label;
281
	public static String StructureSelectPrevious_tooltip;
282
	public static String StructureSelectPrevious_description;
274
283
275
	static {
284
	static {
276
		// load message values from bundle file
285
		// load message values from bundle file
(-)src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties (-5 / +14 lines)
Lines 269-287 Link Here
269
Uncomment_label=&Uncomment
269
Uncomment_label=&Uncomment
270
Uncomment_tooltip=Uncomment
270
Uncomment_tooltip=Uncomment
271
Uncomment_description=Uncomment
271
Uncomment_description=Uncomment
272
ToggleComment_label=Togg&le Comment
272
ToggleComment_label=Toggle Comment
273
ToggleComment_tooltip=Toggle Comment
273
ToggleComment_tooltip=Toggle Comment
274
ToggleComment_description=Toggle Comment
274
ToggleComment_description=Toggle Comment
275
AddBlockComment_label=Add &Block Comment
275
AddBlockComment_label=Add Block Comment
276
AddBlockComment_tooltip=Add Block Comment
276
AddBlockComment_tooltip=Add Block Comment
277
AddBlockComment_description=Add Block Comment
277
AddBlockComment_description=Add Block Comment
278
RemoveBlockComment_label=Remove Bloc&k Comment
278
RemoveBlockComment_label=Remove Block Comment
279
RemoveBlockComment_tooltip=Remove Block Comment
279
RemoveBlockComment_tooltip=Remove Block Comment
280
RemoveBlockComment_description=Remove Block Comment
280
RemoveBlockComment_description=Remove Block Comment
281
CleanupDocument_label=C&leanup Document...
281
CleanupDocument_label=Cleanup Document...
282
CleanupDocument_tooltip=Cleanup Document
282
CleanupDocument_tooltip=Cleanup Document
283
CleanupDocument_description=Cleanup Document
283
CleanupDocument_description=Cleanup Document
284
FindOccurrences_label=O&ccurrences in File
284
FindOccurrences_label=Occurrences in File
285
ShowTooltipDesc_label=Show &Tooltip Description
285
ShowTooltipDesc_label=Show &Tooltip Description
286
ShowTooltipDesc_tooltip=Displays the hover help for the selected element
286
ShowTooltipDesc_tooltip=Displays the hover help for the selected element
287
ShowTooltipDesc_description=Displays the hover help for the selected element
287
ShowTooltipDesc_description=Displays the hover help for the selected element
Lines 301-303 Link Here
301
OpenFileFromSource_tooltip=Open an editor on the selected link
301
OpenFileFromSource_tooltip=Open an editor on the selected link
302
OpenFileFromSource_description=Open an editor on the selected link
302
OpenFileFromSource_description=Open an editor on the selected link
303
XMLContentOutlineConfiguration_0=Show Attributes
303
XMLContentOutlineConfiguration_0=Show Attributes
304
StructureSelectEnclosing_label=Enclosing Element
305
StructureSelectEnclosing_tooltip=Expand selection to include enclosing element
306
StructureSelectEnclosing_description=Expand selection to include enclosing element
307
StructureSelectNext_label=Next Element
308
StructureSelectNext_tooltip=Expand selection to include next sibling
309
StructureSelectNext_description=Expand selection to include next sibling
310
StructureSelectPrevious_label=Previous Element
311
StructureSelectPrevious_tooltip=Expand selection to include previous sibling
312
StructureSelectPrevious_description=Expand selection to include previous sibling
(-)src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXML.java (+3 lines)
Lines 21-26 Link Here
21
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
21
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
22
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
22
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
23
23
24
/**
25
 * @deprecated use AddBlockCommentActionXMLDelegate instead
26
 */
24
public class AddBlockCommentActionXML extends CommentActionXML {
27
public class AddBlockCommentActionXML extends CommentActionXML {
25
	protected int fCloseCommentOffset;
28
	protected int fCloseCommentOffset;
26
	protected int fOpenCommentOffset;
29
	protected int fOpenCommentOffset;
(-)src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXML.java (-1 / +3 lines)
Lines 21-27 Link Here
21
import org.eclipse.wst.sse.ui.internal.actions.CleanupAction;
21
import org.eclipse.wst.sse.ui.internal.actions.CleanupAction;
22
import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML;
22
import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML;
23
23
24
24
/**
25
 * @deprecated Use CleanupActionXMLDelegate instead.
26
 */
25
public class CleanupActionXML extends CleanupAction {
27
public class CleanupActionXML extends CleanupAction {
26
	protected IStructuredCleanupProcessor fCleanupProcessor;
28
	protected IStructuredCleanupProcessor fCleanupProcessor;
27
29
(-)src/org/eclipse/wst/xml/ui/internal/actions/CommentActionXML.java (+4 lines)
Lines 32-37 Link Here
32
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
32
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
33
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
33
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
34
34
35
/**
36
 * @deprecated use AbstractCommentActionXMLDelegate or
37
 *             ToggleCommentActionXMLDelegate instead
38
 */
35
public class CommentActionXML extends TextEditorAction {
39
public class CommentActionXML extends TextEditorAction {
36
	protected static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$
40
	protected static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$
37
	protected static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$
41
	protected static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$
(-)src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXML.java (+3 lines)
Lines 20-25 Link Here
20
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
20
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
22
22
23
/**
24
 * @deprecated use RemoveBlockCommentActionXMLDelegate instead
25
 */
23
public class RemoveBlockCommentActionXML extends AddBlockCommentActionXML {
26
public class RemoveBlockCommentActionXML extends AddBlockCommentActionXML {
24
	public RemoveBlockCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
27
	public RemoveBlockCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
25
		super(bundle, prefix, editor);
28
		super(bundle, prefix, editor);
(-)src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXML.java (+3 lines)
Lines 20-25 Link Here
20
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
20
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
22
22
23
/**
24
 * @deprecated use ToggleCommentActionXMLDelegate instead
25
 */
23
public class ToggleCommentActionXML extends UncommentActionXML {
26
public class ToggleCommentActionXML extends UncommentActionXML {
24
	public ToggleCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
27
	public ToggleCommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
25
		super(bundle, prefix, editor);
28
		super(bundle, prefix, editor);
(-)src/org/eclipse/wst/xml/ui/internal/actions/UncommentActionXML.java (+3 lines)
Lines 20-25 Link Here
20
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
20
import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
22
22
23
/**
24
 * @deprecated use ToggleCommentActionXMLDelegate instead
25
 */
23
public class UncommentActionXML extends CommentActionXML {
26
public class UncommentActionXML extends CommentActionXML {
24
	public UncommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
27
	public UncommentActionXML(ResourceBundle bundle, String prefix, ITextEditor editor) {
25
		super(bundle, prefix, editor);
28
		super(bundle, prefix, editor);
(-)src/org/eclipse/wst/xml/ui/internal/provisional/StructuredTextEditorXML.java (+4 lines)
Lines 27-32 Link Here
27
import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds;
27
import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds;
28
import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesAction;
28
import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesAction;
29
29
30
/**
31
 * @deprecated XML editor is created from StructuredTextEditor with
32
 *             XML configurations
33
 */
30
public class StructuredTextEditorXML extends StructuredTextEditor {
34
public class StructuredTextEditorXML extends StructuredTextEditor {
31
	private final static String UNDERSCORE = "_"; //$NON-NLS-1$
35
	private final static String UNDERSCORE = "_"; //$NON-NLS-1$
32
	
36
	
(-)src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesAction.java (-1 / +1 lines)
Lines 30-36 Link Here
30
 * Uses default <code>getSearchQuery()</code>.
30
 * Uses default <code>getSearchQuery()</code>.
31
 * </p>
31
 * </p>
32
 * 
32
 * 
33
 * @author pavery
33
 * @deprecated use XMLFindOccurrencesProcessor instead
34
 */
34
 */
35
public class XMLFindOccurrencesAction extends BasicFindOccurrencesAction {
35
public class XMLFindOccurrencesAction extends BasicFindOccurrencesAction {
36
36
(-)src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java (-2 / +8 lines)
Lines 42-50 Link Here
42
import org.eclipse.wst.common.ui.provisional.editors.PostSelectionMultiPageEditorPart;
42
import org.eclipse.wst.common.ui.provisional.editors.PostSelectionMultiPageEditorPart;
43
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
43
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
44
import org.eclipse.wst.xml.core.internal.provisional.IXMLPreferenceNames;
44
import org.eclipse.wst.xml.core.internal.provisional.IXMLPreferenceNames;
45
import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML;
45
import org.eclipse.wst.xml.ui.internal.Logger;
46
import org.eclipse.wst.xml.ui.internal.Logger;
46
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
47
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
47
import org.eclipse.wst.xml.ui.internal.provisional.StructuredTextEditorXML;
48
48
49
public class XMLMultiPageEditorPart extends PostSelectionMultiPageEditorPart {
49
public class XMLMultiPageEditorPart extends PostSelectionMultiPageEditorPart {
50
50
Lines 467-472 Link Here
467
					}
467
					}
468
					return contributor;
468
					return contributor;
469
				}
469
				}
470
471
				public String getId() {
472
					// sets this id so nested editor is considered xml source
473
					// page
474
					return ContentTypeIdForXML.ContentTypeID_XML + ".source"; //$NON-NLS-1$;
475
				}
470
			};
476
			};
471
		}
477
		}
472
		else {
478
		else {
Lines 494-500 Link Here
494
	 * @return StructuredTextEditor
500
	 * @return StructuredTextEditor
495
	 */
501
	 */
496
	private StructuredTextEditor createTextEditor() {
502
	private StructuredTextEditor createTextEditor() {
497
		return new StructuredTextEditorXML();
503
		return new StructuredTextEditor();
498
	}
504
	}
499
505
500
	private void disconnectDesignPage() {
506
	private void disconnectDesignPage() {
(-)src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java (+115 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.xml.ui.internal.actions;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.ITextSelection;
19
import org.eclipse.jface.text.TextSelection;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.ISelectionProvider;
22
import org.eclipse.swt.widgets.Event;
23
import org.eclipse.ui.IActionDelegate2;
24
import org.eclipse.ui.IEditorActionDelegate;
25
import org.eclipse.ui.IEditorPart;
26
import org.eclipse.ui.IViewActionDelegate;
27
import org.eclipse.ui.IViewPart;
28
import org.eclipse.ui.texteditor.ITextEditor;
29
import org.eclipse.wst.xml.ui.internal.Logger;
30
31
/**
32
 * Abstract comment action delegate for XML editors
33
 */
34
abstract public class AbstractCommentActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
35
	static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$
36
	static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$
37
38
	IEditorPart fEditor;
39
40
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
41
		fEditor = targetEditor;
42
	}
43
44
	public void dispose() {
45
		// nulling out just in case
46
		fEditor = null;
47
	}
48
49
	public void runWithEvent(IAction action, Event event) {
50
		run(action);
51
	}
52
53
	public void run(IAction action) {
54
		if (fEditor instanceof ITextEditor) {
55
			ITextEditor textEditor = (ITextEditor) fEditor;
56
			IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
57
			if (document != null) {
58
				// get current text selection
59
				ITextSelection textSelection = getCurrentSelection();
60
				if (textSelection.isEmpty())
61
					return;
62
63
				processAction(document, textSelection);
64
			}
65
		}
66
	}
67
68
	public void init(IViewPart view) {
69
		// do nothing
70
	}
71
72
	public void selectionChanged(IAction action, ISelection selection) {
73
		// do nothing
74
	}
75
76
	private ITextSelection getCurrentSelection() {
77
		if (fEditor instanceof ITextEditor) {
78
			ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider();
79
			if (provider != null) {
80
				ISelection selection = provider.getSelection();
81
				if (selection instanceof ITextSelection)
82
					return (ITextSelection) selection;
83
			}
84
		}
85
		return TextSelection.emptySelection();
86
	}
87
88
	abstract void processAction(IDocument document, ITextSelection textSelection);
89
90
	void removeOpenCloseComments(IDocument document, int offset, int length) {
91
		try {
92
			int adjusted_length = length;
93
94
			// remove open comments
95
			String string = document.get(offset, length);
96
			int index = string.lastIndexOf(OPEN_COMMENT);
97
			while (index != -1) {
98
				document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
99
				index = string.lastIndexOf(OPEN_COMMENT, index - 1);
100
				adjusted_length -= OPEN_COMMENT.length();
101
			}
102
103
			// remove close comments
104
			string = document.get(offset, adjusted_length);
105
			index = string.lastIndexOf(CLOSE_COMMENT);
106
			while (index != -1) {
107
				document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
108
				index = string.lastIndexOf(CLOSE_COMMENT, index - 1);
109
			}
110
		}
111
		catch (BadLocationException e) {
112
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
113
		}
114
	}
115
}
(-)src/org/eclipse/wst/xml/ui/internal/actions/AddBlockCommentActionXMLDelegate.java (+82 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.xml.ui.internal.actions;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.ITextSelection;
19
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
20
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
21
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
22
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
23
import org.eclipse.wst.xml.ui.internal.Logger;
24
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
25
26
/**
27
 * Add block comment action delegate for XML editor
28
 */
29
public class AddBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
30
31
	public void init(IAction action) {
32
		if (action != null) {
33
			action.setText(XMLUIMessages.AddBlockComment_label);
34
			action.setToolTipText(XMLUIMessages.AddBlockComment_tooltip);
35
			action.setDescription(XMLUIMessages.AddBlockComment_description);
36
		}
37
	}
38
39
	void processAction(IDocument document, ITextSelection textSelection) {
40
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
41
		if (model != null) {
42
			try {
43
				IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
44
				IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
45
46
				if (selectionStartIndexedRegion == null)
47
					return;
48
				if (selectionEndIndexedRegion == null && textSelection.getLength() > 0) {
49
					selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1);
50
				}
51
				if (selectionEndIndexedRegion == null)
52
					return;
53
54
				int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
55
				int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length();
56
57
58
				if (textSelection.getLength() == 0 && selectionStartIndexedRegion instanceof CommentImpl)
59
					return;
60
61
				model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip);
62
				model.aboutToChangeModel();
63
64
				try {
65
					document.replace(openCommentOffset, 0, OPEN_COMMENT);
66
					document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
67
					removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
68
				}
69
				catch (BadLocationException e) {
70
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
71
				}
72
				finally {
73
					model.changedModel();
74
					model.endRecording(this);
75
				}
76
			}
77
			finally {
78
				model.releaseFromEdit();
79
			}
80
		}
81
	}
82
}
(-)src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java (+136 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.xml.ui.internal.actions;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.text.ITextSelection;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.window.Window;
20
import org.eclipse.swt.custom.BusyIndicator;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.ui.IActionDelegate2;
23
import org.eclipse.ui.IEditorActionDelegate;
24
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IViewActionDelegate;
26
import org.eclipse.ui.IViewPart;
27
import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor;
28
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
29
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
30
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
31
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
32
import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML;
33
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
34
35
/**
36
 * Cleanup action delegate for CSS editor
37
 */
38
public class CleanupActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
39
	private IEditorPart fEditor;
40
	private IStructuredCleanupProcessor fCleanupProcessor;
41
42
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
43
		fEditor = targetEditor;
44
	}
45
46
	public void dispose() {
47
		// nulling out just in case
48
		fEditor = null;
49
		fCleanupProcessor = null;
50
	}
51
52
	public void init(IAction action) {
53
		if (action != null) {
54
			action.setText(XMLUIMessages.CleanupDocument_label);
55
			action.setToolTipText(XMLUIMessages.CleanupDocument_tooltip);
56
			action.setDescription(XMLUIMessages.CleanupDocument_description);
57
		}
58
	}
59
60
	public void runWithEvent(IAction action, Event event) {
61
		run(action);
62
	}
63
64
	public void init(IViewPart view) {
65
		// do nothing
66
	}
67
68
	public void run(IAction action) {
69
		if (fEditor instanceof StructuredTextEditor) {
70
			final StructuredTextEditor editor = (StructuredTextEditor) fEditor;
71
			Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
72
			if (cleanupDialog.open() == Window.OK) {
73
				// setup runnable
74
				Runnable runnable = new Runnable() {
75
					public void run() {
76
						IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
77
						if (cleanupProcessor != null) {
78
							IStructuredModel model = null;
79
							try {
80
								model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
81
								if (model != null)
82
									cleanupProcessor.cleanupModel(model);
83
							}
84
							finally {
85
								if (model != null)
86
									model.releaseFromEdit();
87
							}
88
						}
89
					}
90
				};
91
92
				// TODO: make independent of 'model'.
93
				IStructuredModel model = null;
94
				try {
95
					model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
96
					if (model != null) {
97
						// begin recording
98
						ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
99
						model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
100
101
						// tell the model that we are about to make a big
102
						// model change
103
						model.aboutToChangeModel();
104
105
						// run
106
						BusyIndicator.showWhile(editor.getTextViewer().getControl().getDisplay(), runnable);
107
					}
108
				}
109
				finally {
110
					if (model != null) {
111
						// tell the model that we are done with the big
112
						// model
113
						// change
114
						model.changedModel();
115
116
						// end recording
117
						ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
118
						model.endRecording(this, selection.getOffset(), selection.getLength());
119
						model.releaseFromEdit();
120
					}
121
				}
122
			}
123
		}
124
	}
125
126
	public void selectionChanged(IAction action, ISelection selection) {
127
		// do nothing
128
	}
129
130
	IStructuredCleanupProcessor getCleanupProcessor() {
131
		if (fCleanupProcessor == null)
132
			fCleanupProcessor = new CleanupProcessorXML();
133
134
		return fCleanupProcessor;
135
	}
136
}
(-)src/org/eclipse/wst/xml/ui/internal/actions/RemoveBlockCommentActionXMLDelegate.java (+86 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.xml.ui.internal.actions;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.ITextSelection;
19
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
20
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
21
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
22
import org.eclipse.wst.xml.core.internal.document.CommentImpl;
23
import org.eclipse.wst.xml.ui.internal.Logger;
24
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
25
26
/**
27
 * Remove block comment action delegate for XML editor
28
 */
29
public class RemoveBlockCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
30
31
	void processAction(IDocument document, ITextSelection textSelection) {
32
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
33
		if (model != null) {
34
			try {
35
				IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset());
36
				IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength());
37
38
				if (selectionStartIndexedRegion == null || selectionEndIndexedRegion == null)
39
					return;
40
41
				int openCommentOffset = selectionStartIndexedRegion.getStartOffset();
42
				int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length();
43
44
				model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip);
45
				model.aboutToChangeModel();
46
47
				try {
48
					if (textSelection.getLength() == 0) {
49
						if (selectionStartIndexedRegion instanceof CommentImpl) {
50
							document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
51
							document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
52
						}
53
					}
54
					else {
55
						if (selectionStartIndexedRegion instanceof CommentImpl) {
56
							document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
57
						}
58
59
						if (selectionEndIndexedRegion instanceof CommentImpl) {
60
							document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
61
						}
62
					}
63
					removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
64
				}
65
				catch (BadLocationException e) {
66
					Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
67
				}
68
				finally {
69
					model.changedModel();
70
					model.endRecording(this);
71
				}
72
			}
73
			finally {
74
				model.releaseFromEdit();
75
			}
76
		}
77
	}
78
79
	public void init(IAction action) {
80
		if (action != null) {
81
			action.setText(XMLUIMessages.RemoveBlockComment_label);
82
			action.setToolTipText(XMLUIMessages.RemoveBlockComment_tooltip);
83
			action.setDescription(XMLUIMessages.RemoveBlockComment_description);
84
		}
85
	}
86
}
(-)src/org/eclipse/wst/xml/ui/internal/actions/ToggleCommentActionXMLDelegate.java (+170 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.xml.ui.internal.actions;
14
15
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.ITextSelection;
20
import org.eclipse.jface.text.Position;
21
import org.eclipse.jface.text.TextSelection;
22
import org.eclipse.jface.viewers.ISelectionProvider;
23
import org.eclipse.ui.texteditor.ITextEditor;
24
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
25
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
26
import org.eclipse.wst.xml.ui.internal.Logger;
27
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
28
29
/**
30
 * Toggle comment action delegate for XML editor
31
 */
32
public class ToggleCommentActionXMLDelegate extends AbstractCommentActionXMLDelegate {
33
	public void init(IAction action) {
34
		if (action != null) {
35
			action.setText(XMLUIMessages.ToggleComment_label);
36
			action.setToolTipText(XMLUIMessages.ToggleComment_tooltip);
37
			action.setDescription(XMLUIMessages.ToggleComment_description);
38
		}
39
	}
40
41
	void processAction(IDocument document, ITextSelection textSelection) {
42
		// get text selection lines info
43
		int selectionStartLine = textSelection.getStartLine();
44
		int selectionEndLine = textSelection.getEndLine();
45
		try {
46
			int selectionEndLineOffset = document.getLineOffset(selectionEndLine);
47
			int selectionEndOffset = textSelection.getOffset() + textSelection.getLength();
48
49
			// adjust selection end line
50
			if (selectionEndLine > selectionStartLine && selectionEndLineOffset == selectionEndOffset)
51
				selectionEndLine--;
52
53
		}
54
		catch (BadLocationException e) {
55
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
56
		}
57
58
		// save the selection position since it will be changing
59
		Position selectionPosition = null;
60
		boolean updateStartOffset = false;
61
		try {
62
			selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength());
63
			document.addPosition(selectionPosition);
64
65
			// extra check if commenting from beginning of line
66
			int selectionStartLineOffset = document.getLineOffset(selectionStartLine);
67
			if (textSelection.getLength() > 0 && selectionStartLineOffset == textSelection.getOffset() && !isCommentLine(document, selectionStartLine))
68
				updateStartOffset = true;
69
		}
70
		catch (BadLocationException e) {
71
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
72
		}
73
74
		processAction(document, selectionStartLine, selectionEndLine);
75
76
		updateCurrentSelection(selectionPosition, document, updateStartOffset);
77
	}
78
79
	private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) {
80
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
81
		if (model != null) {
82
			try {
83
				model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip);
84
				model.aboutToChangeModel();
85
86
				for (int i = selectionStartLine; i <= selectionEndLine; i++) {
87
					try {
88
						if (document.getLineLength(i) > 0) {
89
							if (isCommentLine(document, i)) {
90
								int lineOffset = document.getLineOffset(i);
91
								IRegion region = document.getLineInformation(i);
92
								String string = document.get(region.getOffset(), region.getLength());
93
								int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT);
94
								int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length();
95
								uncomment(document, openCommentOffset, closeCommentOffset);
96
							}
97
							else {
98
								int openCommentOffset = document.getLineOffset(i);
99
								int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length();
100
								int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length();
101
								comment(document, openCommentOffset, closeCommentOffset);
102
							}
103
						}
104
					}
105
					catch (BadLocationException e) {
106
						Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
107
					}
108
				}
109
			}
110
			finally {
111
				model.changedModel();
112
				model.endRecording(this);
113
				model.releaseFromEdit();
114
			}
115
		}
116
	}
117
118
	private boolean isCommentLine(IDocument document, int line) {
119
		boolean isComment = false;
120
121
		try {
122
			IRegion region = document.getLineInformation(line);
123
			String string = document.get(region.getOffset(), region.getLength()).trim();
124
			isComment = string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length() && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT);
125
		}
126
		catch (BadLocationException e) {
127
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
128
		}
129
		return isComment;
130
	}
131
132
	private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) {
133
		try {
134
			document.replace(openCommentOffset, 0, OPEN_COMMENT);
135
			document.replace(closeCommentOffset, 0, CLOSE_COMMENT);
136
			removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length());
137
		}
138
		catch (BadLocationException e) {
139
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
140
		}
141
	}
142
143
	private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) {
144
		try {
145
			document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$
146
			document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$
147
		}
148
		catch (BadLocationException e) {
149
			Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
150
		}
151
	}
152
153
	private void updateCurrentSelection(Position selectionPosition, IDocument document, boolean updateStartOffset) {
154
		if (fEditor instanceof ITextEditor) {
155
			// update the selection if text selection changed
156
			if (selectionPosition != null) {
157
				ITextSelection selection = null;
158
				if (updateStartOffset)
159
					selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length());
160
				else
161
					selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength());
162
				ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider();
163
				if (provider != null) {
164
					provider.setSelection(selection);
165
				}
166
				document.removePosition(selectionPosition);
167
			}
168
		}
169
	}
170
}
(-)src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesActionDelegate.java (+34 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.xml.ui.internal.search;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesActionDelegate;
19
20
/**
21
 * Sets up FindOccurrencesActionDelegate for xml find occurrences processors
22
 */
23
public class XMLFindOccurrencesActionDelegate extends FindOccurrencesActionDelegate {
24
	private List fProcessors;
25
26
	protected List getProcessors() {
27
		if (fProcessors == null) {
28
			fProcessors = new ArrayList();
29
			XMLFindOccurrencesProcessor htmlProcessor = new XMLFindOccurrencesProcessor();
30
			fProcessors.add(htmlProcessor);
31
		}
32
		return fProcessors;
33
	}
34
}
(-)src/org/eclipse/wst/xml/ui/internal/search/XMLFindOccurrencesProcessor.java (+31 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.xml.ui.internal.search;
14
15
import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor;
16
import org.eclipse.wst.xml.core.internal.provisional.text.IXMLPartitions;
17
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
18
19
/**
20
 * Configures a FindOccurrencesProcessor with XML partitions and regions
21
 */
22
public class XMLFindOccurrencesProcessor extends FindOccurrencesProcessor {
23
24
	protected String[] getPartitionTypes() {
25
		return new String[]{IXMLPartitions.XML_DEFAULT};
26
	}
27
28
	protected String[] getRegionTypes() {
29
		return new String[]{DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE};
30
	}
31
}
(-)src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectEnclosingXMLActionDelegate.java (+70 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.xml.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.wst.sse.core.internal.provisional.IndexedRegion;
20
import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate;
21
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
22
import org.w3c.dom.Node;
23
24
public class StructuredSelectEnclosingXMLActionDelegate extends StructuredSelectActionDelegate {
25
26
	protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
27
		IndexedRegion indexedRegion = null;
28
		
29
		indexedRegion = getIndexedRegion(document, textSelection.getOffset());
30
31
		return indexedRegion;
32
	}
33
34
	protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
35
		Region newRegion = null;
36
		if (indexedRegion instanceof Node) {
37
			Node cursorNode = (Node) indexedRegion;
38
39
			// use parent node for empty text node
40
			if (cursorNode.getNodeType() == Node.TEXT_NODE && cursorNode.getNodeValue().trim().length() == 0) {
41
				cursorNode = cursorNode.getParentNode();
42
43
				if (cursorNode instanceof IndexedRegion)
44
					indexedRegion = (IndexedRegion) cursorNode;
45
			}
46
47
			Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
48
49
			if (cursorNodeRegion.getOffset() >= textSelection.getOffset() && cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength()) {
50
				Node newNode = cursorNode.getParentNode();
51
52
				if (newNode instanceof IndexedRegion) {
53
					IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
54
					newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
55
				}
56
			}
57
			else
58
				newRegion = cursorNodeRegion;
59
		}
60
		return newRegion;
61
	}
62
63
	public void init(IAction action) {
64
		if (action != null) {
65
			action.setText(XMLUIMessages.StructureSelectEnclosing_label);
66
			action.setToolTipText(XMLUIMessages.StructureSelectEnclosing_tooltip);
67
			action.setDescription(XMLUIMessages.StructureSelectEnclosing_description);
68
		}
69
	}
70
}
(-)src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectNextXMLActionDelegate.java (+88 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.xml.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.text.TextSelection;
20
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
21
import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate;
22
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
23
import org.w3c.dom.Node;
24
25
public class StructuredSelectNextXMLActionDelegate extends StructuredSelectActionDelegate {
26
27
	protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
28
		int offset = textSelection.getOffset() + textSelection.getLength();
29
		if (offset < 0)
30
			offset = 0;
31
32
		IndexedRegion indexedRegion = null;
33
34
		indexedRegion = getIndexedRegion(document, offset);
35
36
		return indexedRegion;
37
	}
38
39
	protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
40
		Region newRegion = null;
41
		if (indexedRegion instanceof Node) {
42
			Node cursorNode = (Node) indexedRegion;
43
44
			// use parent node for empty text node
45
			if (cursorNode.getNodeType() == Node.TEXT_NODE && cursorNode.getNodeValue().trim().length() == 0) {
46
				cursorNode = cursorNode.getParentNode();
47
48
				if (cursorNode instanceof IndexedRegion)
49
					indexedRegion = (IndexedRegion) cursorNode;
50
			}
51
52
			Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
53
54
			if (cursorNodeRegion.getOffset() >= textSelection.getOffset() && cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength()) {
55
				Node newNode = cursorNode.getNextSibling();
56
				if (newNode == null) {
57
					newNode = cursorNode.getParentNode();
58
59
					if (newNode instanceof IndexedRegion) {
60
						IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
61
						newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
62
					}
63
				}
64
				else {
65
					if (newNode instanceof IndexedRegion) {
66
						IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
67
						newRegion = new Region(textSelection.getOffset(), newIndexedRegion.getEndOffset() - textSelection.getOffset());
68
69
						if (newNode.getNodeType() == Node.TEXT_NODE)
70
							newRegion = getNewSelectionRegion(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
71
					}
72
				}
73
			}
74
			else
75
				newRegion = cursorNodeRegion;
76
		}
77
		return newRegion;
78
	}
79
80
	public void init(IAction action) {
81
		if (action != null) {
82
			action.setText(XMLUIMessages.StructureSelectNext_label);
83
			action.setToolTipText(XMLUIMessages.StructureSelectNext_tooltip);
84
			action.setDescription(XMLUIMessages.StructureSelectNext_description);
85
		}
86
	}
87
88
}
(-)src/org/eclipse/wst/xml/ui/internal/selection/StructuredSelectPreviousXMLActionDelegate.java (+85 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.xml.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.text.TextSelection;
20
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
21
import org.eclipse.wst.sse.ui.internal.selection.StructuredSelectActionDelegate;
22
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
23
import org.w3c.dom.Node;
24
25
public class StructuredSelectPreviousXMLActionDelegate extends StructuredSelectActionDelegate {
26
27
	protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
28
		IndexedRegion indexedRegion = null;
29
30
		indexedRegion = getIndexedRegion(document, textSelection.getOffset());
31
32
		return indexedRegion;
33
	}
34
35
	protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
36
		Region newRegion = null;
37
		if (indexedRegion instanceof Node) {
38
			Node cursorNode = (Node) indexedRegion;
39
40
			// use parent node for empty text node
41
			if (cursorNode.getNodeType() == Node.TEXT_NODE && cursorNode.getNodeValue().trim().length() == 0) {
42
				cursorNode = cursorNode.getParentNode();
43
44
				if (cursorNode instanceof IndexedRegion)
45
					indexedRegion = (IndexedRegion) cursorNode;
46
			}
47
48
			Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
49
50
			if (cursorNodeRegion.getOffset() >= textSelection.getOffset() && cursorNodeRegion.getOffset() <= textSelection.getOffset() + textSelection.getLength() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= textSelection.getOffset() && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= textSelection.getOffset() + textSelection.getLength()) {
51
				Node newNode = cursorNode.getPreviousSibling();
52
				if (newNode == null) {
53
					newNode = cursorNode.getParentNode();
54
55
					if (newNode instanceof IndexedRegion) {
56
						IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
57
						newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
58
					}
59
				}
60
				else {
61
					if (newNode instanceof IndexedRegion) {
62
						IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
63
						newRegion = new Region(newIndexedRegion.getStartOffset(), textSelection.getOffset() + textSelection.getLength() - newIndexedRegion.getStartOffset());
64
65
						if (newNode.getNodeType() == Node.TEXT_NODE)
66
							newRegion = getNewSelectionRegion(newIndexedRegion, new TextSelection(newRegion.getOffset(), newRegion.getLength()));
67
					}
68
				}
69
70
			}
71
			else
72
				newRegion = cursorNodeRegion;
73
		}
74
		return newRegion;
75
	}
76
77
	public void init(IAction action) {
78
		if (action != null) {
79
			action.setText(XMLUIMessages.StructureSelectPrevious_label);
80
			action.setToolTipText(XMLUIMessages.StructureSelectPrevious_tooltip);
81
			action.setDescription(XMLUIMessages.StructureSelectPrevious_description);
82
		}
83
	}
84
85
}

Return to bug 109468