Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 160677 Details for
Bug 86520
[editor] toggle comment always uses <!-- -->
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch - Update 7
86520_final.txt (text/plain), 158.11 KB, created by
Ian Tewksbury
on 2010-03-02 15:05:50 EST
(
hide
)
Description:
Patch - Update 7
Filename:
MIME Type:
Creator:
Ian Tewksbury
Created:
2010-03-02 15:05:50 EST
Size:
158.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.css.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.css.ui/plugin.xml,v >retrieving revision 1.51 >diff -u -r1.51 plugin.xml >--- plugin.xml 26 Feb 2010 20:59:15 -0000 1.51 >+++ plugin.xml 2 Mar 2010 20:05:30 -0000 >@@ -48,7 +48,7 @@ > <provisionalDefinition > type="activecontexts" > value="org.eclipse.wst.css.core.csssource" >- target="org.eclipse.wst.css.core.csssource" /> >+ target="org.eclipse.wst.css.core.csssource, org.eclipse.wst.css.comments" /> > </extension> > > <extension point="org.eclipse.ui.contexts"> >@@ -58,6 +58,12 @@ > description="%scope.structured.text.editor.css.description" > id="org.eclipse.wst.css.core.csssource"> > </context> >+ <context >+ name="%scope.structured.text.editor.css.comments.name" >+ parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" >+ description="%scope.structured.text.editor.css.comments.description" >+ id="org.eclipse.wst.css.comments"> >+ </context> > </extension> > > <extension >@@ -255,7 +261,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.css.ui.internal.handlers.ToggleCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.ToggleLineCommentHandler" > commandId="org.eclipse.wst.sse.ui.toggle.comment"> > <activeWhen> > <reference >@@ -269,7 +275,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.css.ui.internal.handlers.AddBlockCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.AddBlockCommentHandler" > commandId="org.eclipse.wst.sse.ui.add.block.comment"> > <activeWhen> > <reference >@@ -283,7 +289,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.css.ui.internal.handlers.RemoveBlockCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.RemoveBlockCommentHandler" > commandId="org.eclipse.wst.sse.ui.remove.block.comment"> > <activeWhen> > <reference >@@ -339,53 +345,6 @@ > </handler> > </extension> > >- <extension point="org.eclipse.ui.menus"> >- <menuContribution >- locationURI="popup:sourcePopupMenuId?before=sourceBegin"> >- <command commandId="org.eclipse.wst.sse.ui.toggle.comment" id="ToggleComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition"/> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.add.block.comment" id="AddBlockComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition" /> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" id="RemoveBlockComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition" /> >- </visibleWhen> >- </command> >- </menuContribution> >- >- <menuContribution locationURI="menu:sourceMenuId?before=sourceBegin"> >- <command commandId="org.eclipse.wst.sse.ui.toggle.comment" >- id="ToggleComment" >- mnemonic="%command.toggle.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition"/> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.add.block.comment" >- id="AddBlockComment" >- mnemonic="%command.add.block.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition"/> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" >- id="RemoveBlockComment" >- mnemonic="%command.remove.block.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.css.ui.cssSourceContributions.definition"/> >- </visibleWhen> >- </command> >- </menuContribution> >- </extension> > <!-- CSS editor actions --> > <extension point="org.eclipse.ui.editorActions"> > <!--<editorContribution >@@ -459,6 +418,16 @@ > </definition> > </extension> > >+ <extension point="org.eclipse.core.expressions.definitions"> >+ <definition id="org.eclipse.wst.css.ui.comments"> >+ <with variable="activeContexts"> >+ <iterate operator="or"> >+ <equals value="org.eclipse.wst.css.comments"/> >+ </iterate> >+ </with> >+ </definition> >+ </extension> >+ > <!-- Define theme --> > <extension > point="org.eclipse.ui.themes"> >@@ -599,6 +568,44 @@ > </inserter> > </extension> > <extension >+ point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="/*" >+ suffix="*/"> >+ <contentType >+ id="org.eclipse.wst.html.core.htmlsource"> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ <requiredPartitionTypes >+ requireAll="true"> >+ <partitionType >+ id="org.eclipse.wst.css.STYLE"> >+ </partitionType> >+ </requiredPartitionTypes> >+ </contentType> >+ <contentType >+ associatedCommentPartitionTypeID="org.eclipse.wst.css.COMMENT" >+ id="org.eclipse.wst.css.core.csssource"> >+ <allowablePartitionTypes >+ anyPartitionType="true"> >+ </allowablePartitionTypes> >+ </contentType> >+ <contentType >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ <requiredPartitionTypes >+ requireAll="true"> >+ <partitionType >+ id="org.eclipse.wst.css.STYLE"> >+ </partitionType> >+ </requiredPartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ </extension> >+ <extension > point="org.eclipse.wst.sse.ui.completionProposal"> > <proposalCategory > icon="icons/full/obj16/tag_selector.gif" >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.css.ui/plugin.properties,v >retrieving revision 1.25 >diff -u -r1.25 plugin.properties >--- plugin.properties 26 Feb 2010 20:59:15 -0000 1.25 >+++ plugin.properties 2 Mar 2010 20:05:29 -0000 >@@ -56,10 +56,8 @@ > > scope.structured.text.editor.css.name=Editing CSS Source > scope.structured.text.editor.css.description=Editing CSS Source >- >-command.toggle.comment.mnemonic=T >-command.remove.block.comment.mnemonic=R >-command.add.block.comment.mnemonic=A >+scope.structured.text.editor.css.comments.name=CSS Source Comments >+scope.structured.text.editor.css.comments.description=CSS Source Comments > > Colors.atmarkRule=At Mark Rule > Colors.selector=Selector >Index: src/org/eclipse/wst/css/ui/internal/handlers/ToggleCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/css/ui/internal/handlers/ToggleCommentHandler.java >diff -N src/org/eclipse/wst/css/ui/internal/handlers/ToggleCommentHandler.java >--- src/org/eclipse/wst/css/ui/internal/handlers/ToggleCommentHandler.java 30 Nov 2009 20:33:18 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,159 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.css.ui.internal.handlers; >- >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.IRegion; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.jface.text.Position; >-import org.eclipse.jface.text.TextSelection; >-import org.eclipse.jface.viewers.ISelectionProvider; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.css.ui.internal.Logger; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.css.ui.internal.CSSUIMessages; >- >-public class ToggleCommentHandler extends AbstractCommentHandler { >- >- protected void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- // get text selection lines info >- int selectionStartLine = textSelection.getStartLine(); >- int selectionEndLine = textSelection.getEndLine(); >- try { >- int selectionEndLineOffset = document.getLineOffset(selectionEndLine); >- int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); >- >- // adjust selection end line >- if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { >- selectionEndLine--; >- } >- >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- >- // save the selection position since it will be changing >- Position selectionPosition = null; >- boolean updateStartOffset = false; >- try { >- selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); >- document.addPosition(selectionPosition); >- >- // extra check if commenting from beginning of line >- int selectionStartLineOffset = document.getLineOffset(selectionStartLine); >- if ((textSelection.getLength() > 0) && (selectionStartLineOffset == textSelection.getOffset()) && !isCommentLine(document, selectionStartLine)) { >- updateStartOffset = true; >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- >- processAction(document, selectionStartLine, selectionEndLine); >- >- updateCurrentSelection(textEditor, selectionPosition, document, updateStartOffset); >- } >- >- private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null) { >- try { >- model.beginRecording(this, CSSUIMessages.ToggleComment_tooltip); >- model.aboutToChangeModel(); >- >- for (int i = selectionStartLine; i <= selectionEndLine; i++) { >- try { >- if (document.getLineLength(i) > 0) { >- if (isCommentLine(document, i)) { >- int lineOffset = document.getLineOffset(i); >- IRegion region = document.getLineInformation(i); >- String string = document.get(region.getOffset(), region.getLength()); >- int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); >- int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); >- uncomment(document, openCommentOffset, closeCommentOffset); >- } >- else { >- int openCommentOffset = document.getLineOffset(i); >- int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length(); >- int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); >- comment(document, openCommentOffset, closeCommentOffset); >- } >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- model.releaseFromEdit(); >- } >- } >- } >- >- private void updateCurrentSelection(ITextEditor textEditor, Position selectionPosition, IDocument document, boolean updateStartOffset) { >- // update the selection if text selection changed >- if (selectionPosition != null) { >- ITextSelection selection = null; >- if (updateStartOffset) { >- selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length()); >- } >- else { >- selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength()); >- } >- ISelectionProvider provider = textEditor.getSelectionProvider(); >- if (provider != null) { >- provider.setSelection(selection); >- } >- document.removePosition(selectionPosition); >- } >- } >- >- private boolean isCommentLine(IDocument document, int line) { >- boolean isComment = false; >- >- try { >- IRegion region = document.getLineInformation(line); >- String string = document.get(region.getOffset(), region.getLength()).trim(); >- isComment = (string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length()) && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- return isComment; >- } >- >- private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) { >- try { >- document.replace(openCommentOffset, 0, OPEN_COMMENT); >- document.replace(closeCommentOffset, 0, CLOSE_COMMENT); >- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >- >- private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) { >- try { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >-} >Index: src/org/eclipse/wst/css/ui/internal/handlers/AbstractCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/css/ui/internal/handlers/AbstractCommentHandler.java >diff -N src/org/eclipse/wst/css/ui/internal/handlers/AbstractCommentHandler.java >--- src/org/eclipse/wst/css/ui/internal/handlers/AbstractCommentHandler.java 30 Nov 2009 20:33:18 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,102 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.css.ui.internal.handlers; >- >-import org.eclipse.core.commands.AbstractHandler; >-import org.eclipse.core.commands.ExecutionEvent; >-import org.eclipse.core.commands.ExecutionException; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.jface.text.TextSelection; >-import org.eclipse.jface.viewers.ISelection; >-import org.eclipse.jface.viewers.ISelectionProvider; >-import org.eclipse.ui.IEditorPart; >-import org.eclipse.ui.handlers.HandlerUtil; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.css.ui.internal.Logger; >- >-public class AbstractCommentHandler extends AbstractHandler { >- >- static final String OPEN_COMMENT = "/*"; //$NON-NLS-1$ >- static final String CLOSE_COMMENT = "*/"; //$NON-NLS-1$ >- >- public Object execute(ExecutionEvent event) throws ExecutionException { >- ITextEditor textEditor = getTextEditor(event); >- if (textEditor != null) { >- IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); >- if (document != null) { >- // get current text selection >- ITextSelection textSelection = getCurrentSelection(textEditor); >- if (textSelection.isEmpty()) { >- return null; >- } >- >- processAction(textEditor, document, textSelection); >- } >- } >- >- return null; >- } >- >- protected void processAction(ITextEditor editor, IDocument document, ITextSelection textSelection) { >- } >- >- protected ITextEditor getTextEditor(ExecutionEvent event) { >- IEditorPart editor = HandlerUtil.getActiveEditor(event); >- ITextEditor textEditor = null; >- if (editor instanceof ITextEditor) >- textEditor = (ITextEditor) editor; >- else { >- Object o = editor.getAdapter(ITextEditor.class); >- if (o != null) >- textEditor = (ITextEditor) o; >- } >- return textEditor; >- } >- >- protected ITextSelection getCurrentSelection(ITextEditor textEditor) { >- ISelectionProvider provider = textEditor.getSelectionProvider(); >- if (provider != null) { >- ISelection selection = provider.getSelection(); >- if (selection instanceof ITextSelection) { >- return (ITextSelection) selection; >- } >- } >- return TextSelection.emptySelection(); >- } >- >- protected void removeOpenCloseComments(IDocument document, int offset, int length) { >- try { >- int adjusted_length = length; >- >- // remove open comments >- String string = document.get(offset, length); >- int index = string.lastIndexOf(OPEN_COMMENT); >- while (index != -1) { >- document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- index = string.lastIndexOf(OPEN_COMMENT, index - 1); >- adjusted_length -= OPEN_COMMENT.length(); >- } >- >- // remove close comments >- string = document.get(offset, adjusted_length); >- index = string.lastIndexOf(CLOSE_COMMENT); >- while (index != -1) { >- document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- index = string.lastIndexOf(CLOSE_COMMENT, index - 1); >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >-} >Index: src/org/eclipse/wst/css/ui/internal/handlers/AddBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/css/ui/internal/handlers/AddBlockCommentHandler.java >diff -N src/org/eclipse/wst/css/ui/internal/handlers/AddBlockCommentHandler.java >--- src/org/eclipse/wst/css/ui/internal/handlers/AddBlockCommentHandler.java 30 Nov 2009 20:33:18 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,74 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.css.ui.internal.handlers; >- >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts; >-import org.eclipse.wst.css.ui.internal.Logger; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >-import org.eclipse.wst.css.ui.internal.CSSUIMessages; >- >-public class AddBlockCommentHandler extends AbstractCommentHandler { >- >- protected void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null && document instanceof IStructuredDocument) { >- try { >- IStructuredDocument doc = (IStructuredDocument) document; >- IStructuredDocumentRegion startRegion = doc.getRegionAtCharacterOffset(textSelection.getOffset()); >- IStructuredDocumentRegion endRegion = doc.getRegionAtCharacterOffset(textSelection.getOffset() + textSelection.getLength()); >- >- if (startRegion == null) { >- return; >- } >- if ((endRegion == null) && (textSelection.getLength() > 0)) { >- endRegion = doc.getRegionAtCharacterOffset(textSelection.getOffset() + textSelection.getLength() - 1); >- } >- if (endRegion == null) { >- return; >- } >- >- int openCommentOffset = startRegion.getStartOffset(); >- int closeCommentOffset = endRegion.getEndOffset() + CLOSE_COMMENT.length(); >- >- if ((textSelection.getLength() == 0) && (startRegion.getType() == CSSRegionContexts.CSS_COMMENT)) { >- return; >- } >- >- model.beginRecording(this, CSSUIMessages.AddBlockComment_tooltip); >- model.aboutToChangeModel(); >- >- try { >- document.replace(openCommentOffset, 0, OPEN_COMMENT); >- document.replace(closeCommentOffset, 0, CLOSE_COMMENT); >- super.removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- } >- } >- finally { >- model.releaseFromEdit(); >- } >- } >- } >- >-} >Index: src/org/eclipse/wst/css/ui/internal/handlers/RemoveBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/css/ui/internal/handlers/RemoveBlockCommentHandler.java >diff -N src/org/eclipse/wst/css/ui/internal/handlers/RemoveBlockCommentHandler.java >--- src/org/eclipse/wst/css/ui/internal/handlers/RemoveBlockCommentHandler.java 30 Nov 2009 20:33:18 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,77 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2009 IBM Corporation and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * IBM Corporation - initial API and implementation >- *******************************************************************************/ >-package org.eclipse.wst.css.ui.internal.handlers; >- >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.css.core.internal.parserz.CSSRegionContexts; >-import org.eclipse.wst.css.ui.internal.Logger; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >-import org.eclipse.wst.css.ui.internal.CSSUIMessages; >- >-public class RemoveBlockCommentHandler extends AbstractCommentHandler { >- >- protected void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null && document instanceof IStructuredDocument) { >- try { >- IStructuredDocument doc = (IStructuredDocument) document; >- IStructuredDocumentRegion startRegion = doc.getRegionAtCharacterOffset(textSelection.getOffset()); >- IStructuredDocumentRegion endRegion = doc.getRegionAtCharacterOffset(textSelection.getOffset() + textSelection.getLength()); >- >- if ((startRegion == null) || (endRegion == null)) { >- return; >- } >- >- int openCommentOffset = startRegion.getStartOffset(); >- int closeCommentOffset = endRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); >- >- model.beginRecording(this, CSSUIMessages.RemoveBlockComment_tooltip); >- model.aboutToChangeModel(); >- >- try { >- if (textSelection.getLength() == 0) { >- if (startRegion.getType() == CSSRegionContexts.CSS_COMMENT) { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- } >- else { >- if (startRegion.getType() == CSSRegionContexts.CSS_COMMENT) { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- >- if (endRegion.getType() == CSSRegionContexts.CSS_COMMENT) { >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- } >- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- } >- } >- finally { >- model.releaseFromEdit(); >- } >- } >- } >- >-} >#P org.eclipse.wst.sse.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/plugin.xml,v >retrieving revision 1.68 >diff -u -r1.68 plugin.xml >--- plugin.xml 26 Feb 2010 20:59:20 -0000 1.68 >+++ plugin.xml 2 Mar 2010 20:05:30 -0000 >@@ -519,6 +519,7 @@ > id="quickFixProcessor" > name="%quickFixProcessor" > schema="schema/quickFixProcessor.exsd"/> >+ <extension-point id="commentingStrategy" name="%Commenting_Strategy_Extension.name" schema="schema/commentingStrategy.exsd"/> > <extension-point id="completionProposal" name="%Completion_Proposal.name" schema="schema/completionProposal.exsd"/> > <extension-point id="completionProposalCategoriesConfiguration" name="%Completion_Proposal_Categories_Configuration.name" schema="schema/completionProposalCategoriesConfiguration.exsd"/> > >@@ -649,8 +650,27 @@ > </command> > </menuContribution> > >- <menuContribution >+ <menuContribution > locationURI="popup:sourcePopupMenuId?after=sourceBegin"> >+ <command >+ commandId="org.eclipse.wst.sse.ui.toggle.comment" >+ id="ToggleComment" >+ style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"></reference> >+ </visibleWhen> >+ </command> >+ <command commandId="org.eclipse.wst.sse.ui.add.block.comment" id="AddBlockComment" style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"></reference> >+ </visibleWhen> >+ </command> >+ <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" id="RemoveBlockComment" style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"></reference> >+ </visibleWhen> >+ </command> >+ <separator name="format" visible="true"></separator> > <command > commandId="org.eclipse.wst.sse.ui.cleanup.document" > id="CleanupDocument" >@@ -679,6 +699,34 @@ > </command> > > </menuContribution> >+ <menuContribution locationURI="menu:sourceMenuId?after=sourceBegin"> >+ <command commandId="org.eclipse.wst.sse.ui.toggle.comment" >+ id="ToggleComment" >+ mnemonic="%command.toggle.comment.mnemonic" >+ style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> >+ </visibleWhen> >+ </command> >+ <command commandId="org.eclipse.wst.sse.ui.add.block.comment" >+ id="AddBlockComment" >+ mnemonic="%command.add.block.comment.mnemonic" >+ style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> >+ </visibleWhen> >+ </command> >+ <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" >+ id="RemoveBlockComment" >+ mnemonic="%command.remove.block.comment.mnemonic" >+ style="push"> >+ <visibleWhen checkEnabled="false"> >+ <reference definitionId="org.eclipse.wst.sse.ui.sseActiveContext.definition"/> >+ </visibleWhen> >+ </command> >+ </menuContribution> >+ >+ > </extension> > <extension > point="org.eclipse.ui.commands"> >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/plugin.properties,v >retrieving revision 1.30 >diff -u -r1.30 plugin.properties >--- plugin.properties 26 Feb 2010 20:59:20 -0000 1.30 >+++ plugin.properties 2 Mar 2010 20:05:30 -0000 >@@ -30,11 +30,14 @@ > Character_Pairing.name=Character Pairing Extension > Completion_Proposal.name=Completion Proposal > Completion_Proposal_Categories_Configuration.name=Completion Proposal Categories Configuration >+Commenting_Strategy_Extension.name=Commenting Strategy Extension > ########################################################################## > # These strings are used in Workbench Keys Preferences > ########################################################################## > scope.structuredTextEditor.name=Editing in Structured Text Editors > scope.structuredTextEditor.description=Editing in Structured Text Editors >+scope.structuredTextEditor.comments.description=Source Comments in Structured Text Editors >+scope.structuredTextEditor.comments.name=Source Comments in Structured Text Editors > command.toggle.comment.name=Toggle Comment > command.toggle.comment.description=Toggle Comment > command.add.block.comment.name=Add Block Comment >@@ -107,3 +110,8 @@ > Colors.content_assist_proposals_foreground=Content Assist Proposals Foreground > Colors.content_assist_parameters_background=Content Assist Parameters Background > Colors.content_assist_parameters_foreground=Content Assist Parameters Foreground >+ >+# Menu contributions >+command.toggle.comment.mnemonic=T >+command.add.block.comment.mnemonic=A >+command.remove.block.comment.mnemonic=Rs >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.43 >diff -u -r1.43 MANIFEST.MF >--- META-INF/MANIFEST.MF 26 Feb 2010 20:59:20 -0000 1.43 >+++ META-INF/MANIFEST.MF 2 Mar 2010 20:05:30 -0000 >@@ -7,6 +7,7 @@ > Bundle-Vendor: %providerName > Bundle-Localization: plugin > Export-Package: org.eclipse.wst.sse.ui, >+ org.eclipse.wst.sse.ui.handlers, > org.eclipse.wst.sse.ui.contentassist, > org.eclipse.wst.sse.ui.internal;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", > org.eclipse.wst.sse.ui.internal.actions;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", >Index: src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java,v >retrieving revision 1.26 >diff -u -r1.26 SSEUIMessages.java >--- src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java 26 Feb 2010 20:59:19 -0000 1.26 >+++ src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java 2 Mar 2010 20:05:30 -0000 >@@ -90,6 +90,7 @@ > public static String ToggleComment_tooltip; > public static String ToggleComment_image; > public static String ToggleComment_description; >+ public static String ToggleComment_progress; > public static String AddBlockComment_label; > public static String AddBlockComment_tooltip; > public static String AddBlockComment_image; >Index: src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties,v >retrieving revision 1.31 >diff -u -r1.31 SSEUIPluginResources.properties >--- src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties 26 Feb 2010 20:59:19 -0000 1.31 >+++ src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties 2 Mar 2010 20:05:30 -0000 >@@ -62,6 +62,7 @@ > ToggleComment_tooltip=Toggle Comment > ToggleComment_image= > ToggleComment_description=Toggle Comment >+ToggleComment_progress=Toggling line comments... > AddBlockComment_label=Add &Block Comment > AddBlockComment_tooltip=Add Block Comment > AddBlockComment_image= >Index: src/org/eclipse/wst/sse/ui/internal/handlers/AbstractCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/handlers/AbstractCommentHandler.java >diff -N src/org/eclipse/wst/sse/ui/internal/handlers/AbstractCommentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/handlers/AbstractCommentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,96 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.handlers; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.TextSelection; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.ISelectionProvider; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.handlers.HandlerUtil; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+ >+/** >+ * This class contains all of the shared functionality for comment handlers >+ */ >+public abstract class AbstractCommentHandler extends AbstractHandler { >+ >+ /** >+ * <p>Default constructor must exist because sub classes are created by java reflection</p> >+ */ >+ public AbstractCommentHandler() { >+ super(); >+ } >+ >+ /** >+ * <p>Gets the important information out of the event and passes it onto >+ * the internal method {@link #processAction}</p> >+ * >+ * @see org.eclipse.wst.xml.ui.internal.handlers.CommentHandler#execute(org.eclipse.core.commands.ExecutionEvent) >+ */ >+ public final Object execute(ExecutionEvent event) throws ExecutionException { >+ IEditorPart editor = HandlerUtil.getActiveEditor(event); >+ ITextEditor textEditor = null; >+ if (editor instanceof ITextEditor) >+ textEditor = (ITextEditor) editor; >+ else { >+ Object o = editor.getAdapter(ITextEditor.class); >+ if (o != null) >+ textEditor = (ITextEditor) o; >+ } >+ if (textEditor != null) { >+ IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); >+ if (document != null && document instanceof IStructuredDocument) { >+ // get current text selection >+ ITextSelection textSelection = getCurrentSelection(textEditor); >+ if (!textSelection.isEmpty()) { >+ //call the implementers code to deal with the event >+ processAction(textEditor, (IStructuredDocument)document, textSelection); >+ } >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * <p>This method is called by the public {@link #execute} method whenever >+ * the comment handler is invoked. This method should be used for the >+ * logic of handling the structured comment event.</p> >+ * >+ * @param textEditor the text editor the initiating event was caused in >+ * @param document the document the text editor is editing >+ * @param textSelection the user selection when the event was caused >+ */ >+ protected abstract void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection); >+ >+ /** >+ * <p>Gets the current user selection in the given {@link ITextEditor}</p> >+ * >+ * @param textEditor get the user selection from here >+ * @return the current user selection in <code>textEdtior</code> >+ */ >+ private static ITextSelection getCurrentSelection(ITextEditor textEditor) { >+ ISelectionProvider provider = textEditor.getSelectionProvider(); >+ if (provider != null) { >+ ISelection selection = provider.getSelection(); >+ if (selection instanceof ITextSelection) { >+ return (ITextSelection) selection; >+ } >+ } >+ return TextSelection.emptySelection(); >+ } >+} >Index: src/org/eclipse/wst/sse/ui/internal/comment/LineCommentingStrategy.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/comment/LineCommentingStrategy.java >diff -N src/org/eclipse/wst/sse/ui/internal/comment/LineCommentingStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/comment/LineCommentingStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,86 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.comment; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+ >+/** >+ * <p>Represents a Line Comment commenting strategy</p> >+ */ >+public class LineCommentingStrategy extends CommentingStrategy { >+ /** the prefix of the line comment associated with this strategy */ >+ private String fPrefix; >+ >+ /** >+ * @param prefix the prefix of the line comment associated with this strategy >+ */ >+ public LineCommentingStrategy(String prefix) { >+ super(); >+ this.fPrefix = prefix; >+ } >+ >+ /** >+ * <p>Assumes that the given offset is at the begining of a line and adds the line >+ * comment prefix there</p> >+ * >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#apply( >+ * org.eclipse.wst.sse.core.internal.provisional.IStructuredModel, int, int) >+ */ >+ public void apply(IStructuredModel model, int offset, int length) >+ throws BadLocationException { >+ >+ IDocument document = model.getStructuredDocument(); >+ document.replace(offset, 0, this.fPrefix + " "); >+ } >+ >+ /** >+ * <p>Assumes that the given offset is at the beginning of a line that is commented and removes >+ * the comment prefix from the beginning of the line, leading whitespace on the line will not >+ * prevent this method from finishing correctly</p> >+ * >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#remove( >+ * org.eclipse.wst.sse.core.internal.provisional.IStructuredModel, int, int, boolean) >+ */ >+ public void remove(IStructuredModel model, int offset, int length, boolean removeEnclosing) throws BadLocationException{ >+ IDocument document = model.getStructuredDocument(); >+ String content = document.get(offset, length); >+ int innerOffset = content.indexOf(this.fPrefix); >+ if(innerOffset > 0) { >+ offset += innerOffset; >+ } >+ >+ uncomment(model.getStructuredDocument(), offset, this.fPrefix, -1, null); >+ } >+ >+ /** >+ * <p>A region is already commented if it begins with the the associated prefix ignoring any >+ * leading whitespace</p> >+ * >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#alreadyCommenting( >+ * org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion) >+ */ >+ public boolean alreadyCommenting(IDocument document, IRegion region) >+ throws BadLocationException { >+ >+ String regionContent = document.get(region.getOffset(), region.getLength()).trim(); >+ return regionContent.startsWith(this.fPrefix); >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#clone() >+ */ >+ public Object clone() { >+ return new LineCommentingStrategy(this.fPrefix); >+ } >+} >Index: src/org/eclipse/wst/sse/ui/handlers/AddBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/handlers/AddBlockCommentHandler.java >diff -N src/org/eclipse/wst/sse/ui/handlers/AddBlockCommentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/handlers/AddBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,81 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.handlers; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.DocumentRewriteSession; >+import org.eclipse.jface.text.DocumentRewriteSessionType; >+import org.eclipse.jface.text.IDocumentExtension4; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.Logger; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+import org.eclipse.wst.sse.ui.internal.SSEUIMessages; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategyRegistry; >+import org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler; >+ >+/** >+ * <p>A comment handler to add block comments</p> >+ */ >+public final class AddBlockCommentHandler extends >+ AbstractCommentHandler { >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction( >+ * org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection) >+ */ >+ protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) { >+ IStructuredModel model = null; >+ boolean changed = false; >+ DocumentRewriteSession session = null; >+ >+ try { >+ model = StructuredModelManager.getModelManager().getModelForEdit(document); >+ if(model != null) { >+ //makes it so one undo will undo all the edits to the document >+ model.beginRecording(this, SSEUIMessages.AddBlockComment_label, SSEUIMessages.AddBlockComment_description); >+ >+ //keeps listeners from doing anything until updates are all done >+ model.aboutToChangeModel(); >+ if(document instanceof IDocumentExtension4) { >+ session = ((IDocumentExtension4)document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); >+ } >+ changed = true; >+ >+ ITypedRegion[] typedRegions = document.computePartitioning(textSelection.getOffset(), textSelection.getLength()); >+ CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy(model.getContentTypeIdentifier(), typedRegions); >+ >+ if(commentType != null) { >+ commentType.apply(model, textSelection.getOffset(), textSelection.getLength()); >+ } >+ } >+ } catch (BadLocationException e) { >+ Logger.logException("The given selection " + textSelection + " must be invalid", e); //$NON-NLS-1$ //$NON-NLS-2$ >+ } finally { >+ //clean everything up >+ if(session != null && document instanceof IDocumentExtension4) { >+ ((IDocumentExtension4)document).stopRewriteSession(session); >+ } >+ >+ if(model != null) { >+ model.endRecording(this); >+ if(changed) { >+ model.changedModel(); >+ } >+ model.releaseFromEdit(); >+ } >+ } >+ } >+} >Index: src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategy.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategy.java >diff -N src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,380 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.comment; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.jface.text.Region; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.ui.internal.Logger; >+ >+/** >+ * <p>Defines a commenting strategy defined by the <code>org.eclipse.wst.sse.ui.commentinStrategy</code> >+ * extension point and tracked by the {@link CommentingStrategyRegistry}. Though it is important to >+ * note it is note a one to one relationship of {@link CommentingStrategy}s to extensions, there is actually >+ * one {@link CommentingStrategy} for each content type defined for each >+ * <code>org.eclipse.wst.sse.ui.commentinStrategy</code> extension.<p> >+ * >+ * <p>The expected use case is that a {@link CommentingStrategy} is created off the basic configuration >+ * of the extension point and then cloned for each associated content type and then each clone has >+ * its partition information set using {@link #setPartitionInformation}. >+ * Then the {@link CommentingStrategyRegistry} can be used to retrieve applicable {@link CommentingStrategy}s >+ * and apply them to documents.</p> >+ * >+ * <p>It is important to note that any instance of a {@link CommentingStrategy} is only valid for a specific >+ * content type ID but this relationship is tracked by the {@link CommentingStrategyRegistry} and not by >+ * the strategy itself. Thus any reference to the strategy being valid for specific or general partition >+ * types is implying it is already only valid for a specific content type</p> >+ */ >+public abstract class CommentingStrategy { >+ /** <code>true</code> if this strategy has any required partition types, <code>false</code> otherwise */ >+ private boolean fHasRequiredPartitionTypes; >+ >+ /** >+ * <p><code>true</code> if for this strategy to be valid all of the required partition types must be seen, >+ * <code>false</code> if only at least one of the required partition types must be seen for this >+ * strategy to be valid.</p> >+ * >+ * @see #fRequriedPartitionTypeIDs >+ */ >+ private boolean fRequireAllRequiredPartitionTypes; >+ >+ /** >+ * <p>required partition type IDs that must be seen for this strategy to be valid, the number of them >+ * that must be seen for the strategy to be valid is determined by {@link #fRequireAllRequiredPartitionTypes} >+ * this requirement is waved if the optional {@link #fAssociatedCommentPartitionTypeID} is specified and >+ * present because this strategy must be valid if its {@link #fAssociatedCommentPartitionTypeID} is present</p> >+ * >+ * @see #fRequireAllRequiredPartitionTypes >+ * @see #fAssociatedCommentPartitionTypeID >+ */ >+ private List fRequriedPartitionTypeIDs; >+ >+ /** >+ * <p>if <code>true</code> then {@link #fAllowablePartitionTypeIDs} is ignored because >+ * this strategy is valid for any partition type, if <code>false</code> then this >+ * strategy is only valid for those partition types listed in {@link #fAllowablePartitionTypeIDs}</p> >+ * >+ * @see #fAllowablePartitionTypeIDs >+ */ >+ private boolean fAllPartitionTypesAllowable; >+ >+ /** >+ * <p>the partition types that this strategy is valid for, it is also automatically valid for >+ * any partition types listed in {@link #fRequriedPartitionTypeIDs} and the optionally >+ * specified {@link #fAssociatedCommentPartitionTypeID}</p> >+ * >+ * @see #fAllPartitionTypesAllowable >+ * @see #fRequriedPartitionTypeIDs >+ * @see #fAssociatedCommentPartitionTypeID >+ */ >+ private List fAllowablePartitionTypeIDs; >+ >+ /** >+ * an optional associated comment partition type ID, if this partition type is seen then the >+ * the {@link #fRequriedPartitionTypeIDs} requirement is waved as to weather this strategy is >+ * valid or not >+ * >+ * @see #fRequriedPartitionTypeIDs >+ */ >+ private String fAssociatedCommentPartitionTypeID; >+ >+ /** >+ * <p>Default constructor, the specific initialization is done by >+ * {@link #setPartitionInformation}</p> >+ */ >+ public CommentingStrategy() { >+ this.fAssociatedCommentPartitionTypeID = null; >+ this.fRequriedPartitionTypeIDs = Collections.EMPTY_LIST; >+ this.fAllowablePartitionTypeIDs = Collections.EMPTY_LIST; >+ this.fHasRequiredPartitionTypes = false; >+ this.fRequireAllRequiredPartitionTypes = false; >+ this.fAllPartitionTypesAllowable = false; >+ } >+ >+ /** >+ * <p>Used to set up the partition information for this strategy</p> >+ * <p>This information is used to determine if a strategy is valid for a set of >+ * {@link ITypedRegion}s.</p> >+ * >+ * @param allowablePartitionTypeIDs the partition types this strategy is valid for, the strategy will also >+ * be considered valid for any of the required partition types >+ * @param allPartitionTypesAllowable if <code>true</code> then this strategy is valid for any partition types >+ * thus ignoring the <code>allowablePartitionTypeIDs</code>, <code>false</code> otherwise >+ * @param requiredPartitionTypeIDs partition type IDs that must be seen for this strategy to be valid, there >+ * are exceptions to this rule, see {@link #isApplicableFor(ITypedRegion[])} >+ * @param requireAllRequiredPartitionTypes <code>true</code> if all of the <code>requiredPartitionTypeIDs must >+ * be seen for this strategy to be valid, <code>false</code> otherwise, there are exceptions to these rules, see >+ * {@link #isApplicableFor(ITypedRegion[])} >+ * @param associatedCommentPartitionTypeID optional comment partition type associated with this strategy, >+ * maybe <code>null</code> >+ * >+ * @see #isApplicableFor(ITypedRegion[]) >+ */ >+ protected final void setPartitionInformation(List allowablePartitionTypeIDs, boolean allPartitionTypesAllowable, >+ List requiredPartitionTypeIDs, boolean requireAllRequiredPartitionTypes, String associatedCommentPartitionTypeID) { >+ >+ this.fAllPartitionTypesAllowable = allPartitionTypesAllowable; >+ this.fRequireAllRequiredPartitionTypes = requireAllRequiredPartitionTypes; >+ >+ this.fRequriedPartitionTypeIDs = requiredPartitionTypeIDs; >+ if(this.fRequriedPartitionTypeIDs == null) { >+ this.fRequriedPartitionTypeIDs = Collections.EMPTY_LIST; >+ } >+ >+ this.fHasRequiredPartitionTypes = this.fRequriedPartitionTypeIDs.size() != 0; >+ >+ this.fAllowablePartitionTypeIDs = allowablePartitionTypeIDs; >+ if(this.fAllowablePartitionTypeIDs == null) { >+ this.fAllowablePartitionTypeIDs = Collections.EMPTY_LIST; >+ } >+ >+ this.fAssociatedCommentPartitionTypeID = associatedCommentPartitionTypeID; >+ } >+ >+ /** >+ * <p>Applies this strategy to the given model starting at the given offset for the given length</p> >+ * >+ * @param model {@link IStructuredModel} to apply this strategy too >+ * @param offset the offset to start this comment at >+ * @param length the length of the region to apply this comment too >+ * >+ * @throws BadLocationException it is not the fault of the strategy if callers passes a bad >+ * <code>offset</code> and/or <code>length</code> for the given <code>model</code> >+ */ >+ public abstract void apply(IStructuredModel model, int offset, int length) throws BadLocationException; >+ >+ /** >+ * <p>Remove any comments associated with this strategy from the given model for the given offset to >+ * the given length. Weather a comment surrounding the given range should be removed can also be >+ * specified</p> >+ * >+ * @param model {@link IStructuredModel} to remove comments associated with this strategy from >+ * @param offset the location to start removing comments associated with this strategy from >+ * @param length the length of the region to remove associated comments from >+ * @param removeEnclosing weather a comment should be removed if it incloses the region specified >+ * by the given <code>offset</code> and <code>length</code> >+ * >+ * @throws BadLocationException it is not the fault of the strategy if callers passes a bad >+ * <code>offset</code> and/or <code>length</code> for the given <code>model</code> >+ */ >+ public abstract void remove(IStructuredModel model, int offset, int length, boolean removeEnclosing) throws BadLocationException; >+ >+ /** >+ * <p>Determines if the given region is a comment region commented by this strategy.</p> >+ * >+ * @param document {@link IDocument} containing the given <code>region</code> >+ * @param region determine if this region is a comment region commented by this strategy >+ * @return <code>true</code> if the given <code>region</code> has already been >+ * commented by this strategy, <code>false</code> otherwise >+ * >+ * @throws BadLocationException it is not the fault of the strategy if callers passes a bad >+ * <code>offset</code> and/or <code>length</code> for the given <code>model</code> >+ */ >+ public abstract boolean alreadyCommenting(IDocument document, IRegion region) throws BadLocationException; >+ >+ /** >+ * <p>Implementers should return a copy of themselves</p> >+ * <p>Allows the {@link CommentingStrategyRegistry} to create a {@link CommentingStrategy} for >+ * each of its associated content types.</p> >+ * >+ * @return implementers should return an object of type {@link CommentingStrategy} >+ * >+ * @see java.lang.Object#clone() >+ */ >+ public abstract Object clone(); >+ >+ /** >+ * <p>Determines if this strategy is applicable for the given regions for either commenting or un-commenting. >+ * For this strategy to be applicable the given regions must contain at least one or all of the >+ * {@link #fRequriedPartitionTypeIDs} (depending on the value of {@link #fRequireAllRequiredPartitionTypes}) >+ * or contain at least one region of type {@link #fAssociatedCommentPartitionTypeID}. Also if the value of >+ * {@link #fAllPartitionTypesAllowable} is <code>false</code> the given regions must all be of type >+ * {@link #fAllowablePartitionTypeIDs} and/or {@link #fRequriedPartitionTypeIDs} and/or >+ * {@link #fAssociatedCommentPartitionTypeID} otherwise the regions can be of any type except for they still >+ * must beet the required partition type requirements</p> >+ * >+ * @param regions determine if this strategy is applicable for these regions >+ * @return <code>true</code> if this strategy is applicable for the given <code>regions</code> >+ * <code>false</code> otherwise. >+ */ >+ public final boolean isApplicableFor(ITypedRegion[] regions) { >+ List partitionTypeIDs = getPartitionTypeIDs(regions); >+ >+ boolean foundAssociatedCommentPartitions = false; >+ if(this.fAssociatedCommentPartitionTypeID != null) { >+ foundAssociatedCommentPartitions = partitionTypeIDs.contains(this.fAssociatedCommentPartitionTypeID); >+ if(foundAssociatedCommentPartitions) { >+ //remove all instances of the comment partition type >+ boolean removed; >+ do { >+ removed = partitionTypeIDs.remove(this.fAssociatedCommentPartitionTypeID); >+ } while(removed); >+ } >+ } >+ >+ //determine if required partitions requirements are met >+ boolean requiredPartitionsRequirementsMet = false; >+ if(this.fHasRequiredPartitionTypes) { >+ /* either all specified required partitions must be found, >+ * or just at least one of them must be found >+ */ >+ if(this.fRequireAllRequiredPartitionTypes) { >+ requiredPartitionsRequirementsMet = >+ partitionTypeIDs.containsAll(this.fRequriedPartitionTypeIDs); >+ partitionTypeIDs.removeAll(this.fRequriedPartitionTypeIDs); >+ } else { >+ requiredPartitionsRequirementsMet = >+ partitionTypeIDs.removeAll(this.fRequriedPartitionTypeIDs); >+ } >+ } else { >+ requiredPartitionsRequirementsMet = true; >+ } >+ >+ //determine if allowable partitions requirements are met >+ boolean allowablePartitionsRequirementsMet = false; >+ if(this.fAllPartitionTypesAllowable) { >+ allowablePartitionsRequirementsMet = true; >+ } else { >+ partitionTypeIDs.removeAll(this.fAllowablePartitionTypeIDs); >+ >+ //at this point all required partitions and allowable partitions have been removed >+ allowablePartitionsRequirementsMet = partitionTypeIDs.size() == 0; >+ } >+ >+ return (requiredPartitionsRequirementsMet || foundAssociatedCommentPartitions) && allowablePartitionsRequirementsMet; >+ } >+ >+ /** >+ * <p>Convenience method to take a list of regions and create one encompassing region to pass to >+ * {@link #alreadyCommenting(IDocument, IRegion)}</p> >+ * >+ * @param document {@link IDocument} that contains the given <code>regions</code> >+ * @param regions {@link IRegion}s to combine into one region and pass onto >+ * {@link #alreadyCommenting(IDocument, IRegion)} >+ * >+ * @return the result of a call to {@link #alreadyCommenting(IDocument, IRegion)} combining >+ * all of the given <code>regions</code> into one region >+ * >+ * @throws BadLocationException it is not the fault of the strategy if callers passes a bad >+ * <code>offset</code> and/or <code>length</code> for the given <code>model</code> >+ */ >+ public final boolean alreadyCommenting(IDocument document, IRegion[] regions) throws BadLocationException { >+ boolean alreadyCommenting = false; >+ if(regions != null && regions.length > 0) { >+ //create one region spanning all the given regions >+ int offset = regions[0].getOffset(); >+ int length = regions[regions.length-1].getOffset() + >+ regions[regions.length-1].getLength() - offset; >+ >+ IRegion region = new Region(offset, length); >+ alreadyCommenting = this.alreadyCommenting(document, region); >+ } >+ >+ return alreadyCommenting; >+ } >+ /** >+ * <p>Given a list of {@link ITypedRegion}s returns the sub set of that list that >+ * are of the comment region type associated with this strategy</p> >+ * >+ * @param typedRegions {@link ITypedRegion}s to filter down to only the comment regions >+ * associated with this strategy >+ * >+ * @return {@link List} of {@link ITypedRegion}s from the given <code>typedRegions</code> >+ * that are of the comment partition type associated with this strategy >+ */ >+ protected List getAssociatedCommentedRegions(ITypedRegion[] typedRegions) { >+ List commentedRegions = new ArrayList(); >+ >+ for(int i = 0; i < typedRegions.length; ++i) { >+ if(typedRegions[i].getType().equals(this.fAssociatedCommentPartitionTypeID)) { >+ commentedRegions.add(typedRegions[i]); >+ } >+ } >+ >+ return commentedRegions; >+ } >+ >+ /** >+ * <p>Given a list of {@link ITypedRegion}s returns a list of the partition >+ * type IDs taken from the given regions.</p> >+ * >+ * @param regions {@link ITypedRegion}s to get the partition type IDs from >+ * @return {@link List} of the partition type IDs taken from the given <code>regions</code> >+ */ >+ private static List getPartitionTypeIDs(ITypedRegion[] regions) { >+ List partitionTypes = new ArrayList(regions.length); >+ for(int i = 0; i < regions.length; ++i) { >+ partitionTypes.add(regions[i].getType()); >+ } >+ >+ return partitionTypes; >+ } >+ >+ /** >+ * <p>This method modifies the given document to remove the given comment >+ * prefix at the given comment prefix offset and the given comment >+ * suffix at the given comment suffix offset. In the case of removing >+ * a line comment that does not have a suffix, pass <code>null</code> >+ * for the comment suffix and it and its associated offset will >+ * be ignored.</p> >+ * >+ * <p><b>NOTE:</b> it is a good idea if a model is at hand when calling this to >+ * warn the model of an impending update</p> >+ * >+ * @param document the document to remove the comment from >+ * @param commentPrefixOffset the offset of the comment prefix >+ * @param commentSuffixOffset the offset of the comment suffix >+ * (ignored if <code>commentSuffix</code> is <code>null</code>) >+ * @param commentPrefix the prefix of the comment to remove from its associated given offset >+ * @param commentSuffix the suffix of the comment to remove from its associated given offset, >+ * or null if there is not suffix to remove for this comment >+ */ >+ protected static void uncomment(IDocument document, int commentPrefixOffset, String commentPrefix, >+ int commentSuffixOffset, String commentSuffix) { >+ >+ try { >+ //determine if there is a space after the comment prefix that should also be removed >+ int commentPrefixLength = commentPrefix.length(); >+ String postCommentPrefixChar = document.get(commentPrefixOffset + commentPrefix.length(), 1); >+ if(postCommentPrefixChar.equals(" ")) { >+ commentPrefixLength++; >+ } >+ >+ //remove the comment prefix >+ document.replace(commentPrefixOffset, commentPrefixLength, ""); //$NON-NLS-1$ >+ >+ if(commentSuffix != null) { >+ commentSuffixOffset -= commentPrefixLength; >+ >+ //determine if there is a space before the comment suffix that should also be removed >+ int commentSuffixLength = commentSuffix.length(); >+ String preCommentSuffixChar = document.get(commentSuffixOffset-1, 1); >+ if(preCommentSuffixChar.equals(" ")) { >+ commentSuffixLength++; >+ commentSuffixOffset--; >+ } >+ >+ //remove the comment suffix >+ document.replace(commentSuffixOffset, commentSuffixLength, ""); //$NON-NLS-1$ >+ } >+ } >+ catch (BadLocationException e) { >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } >+ } >+} >Index: src/org/eclipse/wst/sse/ui/handlers/ToggleLineCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/handlers/ToggleLineCommentHandler.java >diff -N src/org/eclipse/wst/sse/ui/handlers/ToggleLineCommentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/handlers/ToggleLineCommentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,282 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.handlers; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.jface.dialogs.ProgressMonitorDialog; >+import org.eclipse.jface.operation.IRunnableWithProgress; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.DocumentRewriteSession; >+import org.eclipse.jface.text.DocumentRewriteSessionType; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IDocumentExtension4; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.jface.text.Position; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+import org.eclipse.wst.sse.ui.internal.Logger; >+import org.eclipse.wst.sse.ui.internal.SSEUIMessages; >+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; >+import org.eclipse.wst.sse.ui.internal.comment.BlockCommentingStrategy; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategyRegistry; >+import org.eclipse.wst.sse.ui.internal.comment.LineCommentingStrategy; >+import org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler; >+ >+/** >+ * <p>A comment handler to toggle line comments, this means that if a >+ * comment already exists on a line then toggling it will remove the comment, >+ * if the line in question is not already commented then it will not be commented. >+ * If multiple lines are selected each will be commented separately. The handler >+ * first attempts to find a {@link LineCommentingStrategy} for a line, if it can >+ * not find one then it will try and find a {@link BlockCommentingStrategy} to >+ * wrap just that line in.</p> >+ * >+ * <p>If a great number of lines are being toggled then a progress dialog will be >+ * displayed because this can be a timely process</p> >+ */ >+public final class ToggleLineCommentHandler extends AbstractCommentHandler { >+ /** if toggling more then this many lines then use a busy indicator */ >+ private static final int TOGGLE_LINES_MAX_NO_BUSY_INDICATOR = 10; >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction( >+ * org.eclipse.ui.texteditor.ITextEditor, org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument, >+ * org.eclipse.jface.text.ITextSelection) >+ */ >+ protected void processAction(ITextEditor textEditor, >+ final IStructuredDocument document, ITextSelection textSelection) { >+ >+ IStructuredModel model = null; >+ DocumentRewriteSession session = null; >+ boolean changed = false; >+ >+ try { >+ // get text selection lines info >+ int selectionStartLine = textSelection.getStartLine(); >+ int selectionEndLine = textSelection.getEndLine(); >+ >+ int selectionEndLineOffset = document.getLineOffset(selectionEndLine); >+ int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); >+ >+ // adjust selection end line >+ if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { >+ selectionEndLine--; >+ } >+ >+ // save the selection position since it will be changing >+ Position selectionPosition = null; >+ selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); >+ document.addPosition(selectionPosition); >+ >+ >+ model = StructuredModelManager.getModelManager().getModelForEdit(document); >+ if (model != null) { >+ //makes it so one undo will undo all the edits to the document >+ model.beginRecording(this, SSEUIMessages.ToggleComment_label, SSEUIMessages.ToggleComment_description); >+ >+ //keeps listeners from doing anything until updates are all done >+ model.aboutToChangeModel(); >+ if(document instanceof IDocumentExtension4) { >+ session = ((IDocumentExtension4)document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); >+ } >+ changed = true; >+ >+ //get the display for the editor if we can >+ Display display = null; >+ if(textEditor instanceof StructuredTextEditor) { >+ StructuredTextViewer viewer = ((StructuredTextEditor)textEditor).getTextViewer(); >+ if(viewer != null) { >+ display = viewer.getControl().getDisplay(); >+ } >+ } >+ >+ //create the toggling operation >+ IRunnableWithProgress toggleCommentsRunnable = >+ new ToggleLinesRunnable(model, document, selectionStartLine, selectionEndLine, display); >+ >+ //if toggling lots of lines then use progress monitor else just run the operation >+ if((selectionEndLine - selectionStartLine) > TOGGLE_LINES_MAX_NO_BUSY_INDICATOR && display != null) { >+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell()); >+ dialog.run(false, true, toggleCommentsRunnable); >+ } else { >+ toggleCommentsRunnable.run(new NullProgressMonitor()); >+ } >+ } >+ } catch (InvocationTargetException e) { >+ Logger.logException("Problem running toggle comment progess dialog.", e); //$NON-NLS-1$ >+ } catch (InterruptedException e) { >+ Logger.logException("Problem running toggle comment progess dialog.", e); //$NON-NLS-1$ >+ } catch (BadLocationException e) { >+ Logger.logException("The given selection " + textSelection + " must be invalid", e); //$NON-NLS-1$ //$NON-NLS-2$ >+ } finally { >+ //clean everything up >+ if(session != null && document instanceof IDocumentExtension4) { >+ ((IDocumentExtension4)document).stopRewriteSession(session); >+ } >+ >+ if(model != null) { >+ model.endRecording(this); >+ if(changed) { >+ model.changedModel(); >+ } >+ model.releaseFromEdit(); >+ } >+ } >+ } >+ >+ /** >+ * <p>The actual line toggling takes place in a runnable so it can be >+ * run as part of a progress dialog if there are many lines to toggle >+ * and thus the operation will take a noticeable amount of time the user >+ * should be aware of, this also allows for the operation to be canceled >+ * by the user</p> >+ * >+ */ >+ private static class ToggleLinesRunnable implements IRunnableWithProgress { >+ /** the model that the lines will be toggled on */ >+ private IStructuredModel fModel; >+ >+ /** the document that the lines will be toggled on */ >+ private IDocument fDocument; >+ >+ /** the first line in the document to toggle */ >+ private int fSelectionStartLine; >+ >+ /** the last line in the document to toggle */ >+ private int fSelectionEndLine; >+ >+ /** the display, so that it can be updated during a long operation */ >+ private Display fDisplay; >+ >+ /** >+ * @param model {@link IStructuredModel} that the lines will be toggled on >+ * @param document {@link IDocument} that the lines will be toggled on >+ * @param selectionStartLine first line in the document to toggle >+ * @param selectionEndLine last line in the document to toggle >+ * @param display {@link Display}, so that it can be updated during a long operation >+ */ >+ protected ToggleLinesRunnable(IStructuredModel model, IDocument document, >+ int selectionStartLine, int selectionEndLine, Display display) { >+ >+ this.fModel = model; >+ this.fDocument = document; >+ this.fSelectionStartLine = selectionStartLine; >+ this.fSelectionEndLine = selectionEndLine; >+ this.fDisplay = display; >+ } >+ >+ /** >+ * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ public void run(IProgressMonitor monitor) { >+ //start work >+ monitor.beginTask(SSEUIMessages.ToggleComment_progress, >+ this.fSelectionEndLine-this.fSelectionStartLine); >+ try { >+ //toggle each line so long as task not canceled >+ for (int line = this.fSelectionStartLine; >+ line <= this.fSelectionEndLine && !monitor.isCanceled(); ++line) { >+ >+ //allows the user to be able to click the cancel button >+ readAndDispatch(this.fDisplay); >+ >+ //get the line region >+ IRegion lineRegion = this.fDocument.getLineInformation(line); >+ >+ //don't toggle empty lines >+ String content = this.fDocument.get(lineRegion.getOffset(), lineRegion.getLength()); >+ if (content.trim().length() > 0) { >+ //try to get a line comment type >+ ITypedRegion[] lineTypedRegions = >+ this.fDocument.computePartitioning(lineRegion.getOffset(), lineRegion.getLength()); >+ CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getLineCommentingStrategy( >+ this.fModel.getContentTypeIdentifier(), lineTypedRegions); >+ >+ //could not find line comment type so find block comment type to use on line >+ if(commentType == null) { >+ commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy( >+ this.fModel.getContentTypeIdentifier(), lineTypedRegions); >+ } >+ >+ //toggle the comment on the line >+ if(commentType != null) { >+ if(commentType.alreadyCommenting(this.fDocument, lineTypedRegions)) { >+ commentType.remove(this.fModel, lineRegion.getOffset(), lineRegion.getLength(), true); >+ } else { >+ commentType.apply(this.fModel, lineRegion.getOffset(), lineRegion.getLength()); >+ } >+ } >+ } >+ monitor.worked(1); >+ } >+ } catch(BadLocationException e) { >+ Logger.logException("Bad location while toggling comments.", e); //$NON-NLS-1$ >+ } >+ //done work >+ monitor.done(); >+ } >+ >+ /** >+ * <p>When calling {@link Display#readAndDispatch()} the game is off as to whose code you maybe >+ * calling into because of event handling/listeners/etc. The only important thing is that >+ * the UI has been given a chance to react to user clicks. Thus the logging of most {@link Exception}s >+ * and {@link Error}s as caused by {@link Display#readAndDispatch()} because they are not caused >+ * by this code and do not effect it.</p> >+ * >+ * @param display the {@link Display} to call <code>readAndDispatch</code> >+ * on with exception/error handling. >+ */ >+ private void readAndDispatch(Display display) { >+ try { >+ display.readAndDispatch(); >+ } >+ catch (Exception e) { >+ Logger.log(Logger.WARNING, >+ "Exception caused by readAndDispatch, not caused by or fatal to caller", e); >+ } >+ catch (LinkageError e) { >+ Logger.log(Logger.WARNING, >+ "LinkageError caused by readAndDispatch, not caused by or fatal to caller", e); >+ } >+ catch (VirtualMachineError e) { >+ // re-throw these >+ throw e; >+ } >+ catch (ThreadDeath e) { >+ // re-throw these >+ throw e; >+ } >+ catch (Error e) { >+ // catch every error, except for a few that we don't want to handle >+ Logger.log(Logger.WARNING, >+ "Error caused by readAndDispatch, not caused by or fatal to caller", e); >+ } >+ } >+ } >+ >+ /** >+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled() >+ */ >+ public boolean isEnabled() { >+ // TODO: IAN: fill this in >+ return super.isEnabled(); >+ } >+} >Index: schema/commentingStrategy.exsd >=================================================================== >RCS file: schema/commentingStrategy.exsd >diff -N schema/commentingStrategy.exsd >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ schema/commentingStrategy.exsd 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,261 @@ >+<?xml version='1.0' encoding='UTF-8'?> >+<!-- Schema file written by PDE --> >+<schema targetNamespace="org.eclipse.wst.sse.ui" xmlns="http://www.w3.org/2001/XMLSchema"> >+<annotation> >+ <appInfo> >+ <meta.schema plugin="org.eclipse.wst.sse.ui" id="commentingStrategy" name="Commenting Strategy"/> >+ </appInfo> >+ <documentation> >+ This extension point allows the contribution of commenting strategy's to participate in the commenting actions, such as adding and removing commenting blocks and toggling line comments. >+ </documentation> >+ </annotation> >+ >+ <element name="extension"> >+ <annotation> >+ <appInfo> >+ <meta.element /> >+ </appInfo> >+ </annotation> >+ <complexType> >+ <sequence> >+ <choice minOccurs="1" maxOccurs="unbounded"> >+ <element ref="blockCommentingStrategy" minOccurs="0" maxOccurs="unbounded"/> >+ <element ref="lineCommentingStrategy" minOccurs="0" maxOccurs="unbounded"/> >+ </choice> >+ </sequence> >+ <attribute name="point" type="string" use="required"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="id" type="string"> >+ <annotation> >+ <documentation> >+ an optional identifier of the extension instance >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="name" type="string"> >+ <annotation> >+ <documentation> >+ >+ </documentation> >+ <appInfo> >+ <meta.attribute translatable="true"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="blockCommentingStrategy"> >+ <annotation> >+ <documentation> >+ Defines a block commenting strategy >+ </documentation> >+ </annotation> >+ <complexType> >+ <sequence minOccurs="1" maxOccurs="unbounded"> >+ <element ref="contentType"/> >+ </sequence> >+ <attribute name="prefix" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The prefix of the block comment this strategy impliments >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="suffix" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The suffix of the block comment this strategy impliments >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="lineCommentingStrategy"> >+ <annotation> >+ <documentation> >+ Deefines a line commenting strategy >+ </documentation> >+ </annotation> >+ <complexType> >+ <sequence minOccurs="1" maxOccurs="unbounded"> >+ <element ref="contentType"/> >+ </sequence> >+ <attribute name="prefix" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The prefix of the block comment this strategy impliments >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="contentType"> >+ <annotation> >+ <documentation> >+ A content type that the strategy is applicable for >+ </documentation> >+ </annotation> >+ <complexType> >+ <sequence> >+ <element ref="allowablePartitionTypes"/> >+ <element ref="requiredPartitionTypes" minOccurs="0" maxOccurs="1"/> >+ </sequence> >+ <attribute name="id" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The ID of the content type >+ </documentation> >+ <appInfo> >+ <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/> >+ </appInfo> >+ </annotation> >+ </attribute> >+ <attribute name="associatedCommentPartitionTypeID" type="string"> >+ <annotation> >+ <documentation> >+ The partition type ID of the comment partition that is associated with the strategy in this content type >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="requiredPartitionTypes"> >+ <annotation> >+ <documentation> >+ List of partition types in the associated content type that are requried for the strategy to be applicable. Depending on the value of the <code>requireAll</code> attribute either all or only at least one of these partition types must be present in a selection for the strategy to be applicable. >+ </documentation> >+ </annotation> >+ <complexType> >+ <sequence minOccurs="1" maxOccurs="unbounded"> >+ <element ref="partitionType"/> >+ </sequence> >+ <attribute name="requireAll" type="boolean" use="default" value="false"> >+ <annotation> >+ <documentation> >+ If <code>true</code> then all of the required partition types must be present in a user selection for the strategy to be valid, if <code>false</code> only at least one of the required partition types must be present in the a user selection for the strategy to be valid. These conditions are shortucted if the <code>associatedCommentPartitiontTypeID</code> for the <code>contentType</code> that thes required partition types are associated with is present in the user selection >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="allowablePartitionTypes"> >+ <annotation> >+ <documentation> >+ The partition types that are allowed in a user selection for the strategy to be valid. It is assumed that any partition types listed in the <code>requiredPartitionTypes</code> are also allowable. This list is ignored if the value of <code>anyPartitionType</code> is <code>true</code> >+ </documentation> >+ </annotation> >+ <complexType> >+ <sequence minOccurs="0" maxOccurs="unbounded"> >+ <element ref="partitionType"/> >+ </sequence> >+ <attribute name="anyPartitionType" type="boolean" use="default" value="false"> >+ <annotation> >+ <documentation> >+ If <code>true</code> then the strategy is valid for any partition type in the associated <code>contentType</code>, this means that any <code>partionType</code>s listed here would be ignored. If <code>false</code> then only the <code>partitionType</code>s listed here are allowed in a user selection (allong with any specified requried partition types) for the strategy to be valid. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ <element name="partitionType"> >+ <annotation> >+ <documentation> >+ A partition type associated with the parenting content type >+ </documentation> >+ </annotation> >+ <complexType> >+ <attribute name="id" type="string" use="required"> >+ <annotation> >+ <documentation> >+ The ID of the partition type. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="examples"/> >+ </appInfo> >+ <documentation> >+ <p><b>Example 1:</b> A simple example for block comments on XML documents</p><pre><extension point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="&lt;!--" >+ suffix="--&gt;"> >+ <contentType >+ id="org.eclipse.core.runtime.xml" >+ associatedCommentPartitionTypeID="org.eclipse.wst.xml.XML_COMMENT"> >+ <allowablePartitionTypes >+ anyPartitionType="true"> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+</extension></pre> >+ >+<p><b>Example 2:</b> A more complex example for adding CSS comenting to both CSS and HTML documents</p><pre><extension point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="/*" >+ suffix="*/"> >+ <contentType >+ associatedCommentPartitionTypeID="org.eclipse.wst.css.COMMENT" >+ id="org.eclipse.wst.css.core.csssource"> >+ <allowablePartitionTypes >+ anyPartitionType="true"> >+ </allowablePartitionTypes> >+ </contentType> >+ <contentType >+ id="org.eclipse.wst.html.core.htmlsource"> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ <requiredPartitionTypes >+ requireAll="true"> >+ <partitionType >+ id="org.eclipse.wst.css.STYLE"> >+ </partitionType> >+ </requiredPartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+</extension></pre> >+ </documentation> >+ </annotation> >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="apiinfo"/> >+ </appInfo> >+ <documentation> >+ The user of this extension point does not need to impliment any classes themselves but for their contributions to work in any given content type then the following handlers must be registered for the content type in question by using the <code>org.eclipse.ui.handlers</code> extension point. >+<ul> >+<li><code>org.eclipse.wst.sse.ui.handlers.AddBlockCommentHandler</code></li> >+<li><code>org.eclipse.wst.sse.ui.handlers.RemoveBlockCommentHandler</code></li> >+<li><code>org.eclipse.wst.sse.ui.handlers.ToggleLineCommentHandler</code></li> >+</ul> >+ </documentation> >+ </annotation> >+ >+ >+ <annotation> >+ <appInfo> >+ <meta.section type="copyright"/> >+ </appInfo> >+ <documentation> >+ Copyright (c) 2010 IBM Corporation and others. >+All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> >+ </documentation> >+ </annotation> >+ >+</schema> >Index: src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategyRegistry.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategyRegistry.java >diff -N src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategyRegistry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/comment/CommentingStrategyRegistry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,352 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.comment; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtensionRegistry; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.InvalidRegistryObjectException; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.wst.sse.ui.internal.Logger; >+import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; >+ >+/** >+ * <p>The registry of {@link CommentingStrategy}s defined by the <code>org.eclipse.wst.sse.ui.commentinStrategy</code> >+ * extension point.</p> >+ */ >+public class CommentingStrategyRegistry { >+ /** The extension schema name of the extension point */ >+ private static final String EXTENSION_POINT = "commentingStrategy"; //$NON-NLS-1$ >+ >+ /** The extension schema name of proposal block comment child elements. */ >+ private static final String ELEM_PROPOSAL_BLOCK_COMMENTING_STRATEGY = "blockCommentingStrategy"; //$NON-NLS-1$ >+ >+ /** The extension schema name of proposal line comment child elements. */ >+ private static final String ELEM_PROPOSAL_LINE_COMMENTING_STRATEGY = "lineCommentingStrategy"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the content type child elements. */ >+ private static final String ELEM_CONTENT_TYPE = "contentType"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the required partition types child elements */ >+ private static final String ELEM_REQUIRED_PARTITION_TYPES= "requiredPartitionTypes"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the allowable partition types child elements */ >+ private static final String ELEM_ALLOWABLE_PARTITION_TYPES= "allowablePartitionTypes"; //$NON-NLS-1$ >+ >+ /** The extension schema name of partition type child elements */ >+ private static final String ELEM_PARTITION_TYPE= "partitionType"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the prefix attribute */ >+ private static final String ATTR_PREFIX = "prefix"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the suffix attribute */ >+ private static final String ATTR_SUFFIX = "suffix"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the associatedCommentPartitionTypeID attribute */ >+ private static final String ATTR_ASSOCIATED_COMMENT_PARTITION_TPYPE_ID = "associatedCommentPartitionTypeID"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the anyPartitionType attribute */ >+ private static final String ATTR_ANY_PARTITION_TYPE = "anyPartitionType"; //$NON-NLS-1$ >+ >+ /** The extension schema name of the requireAll attribute */ >+ private static final String ATTR_REQUIRE_ALL = "requireAll"; //$NON-NLS-1$ >+ >+ /** The extension schema name for ID attribute */ >+ private static final String ATTR_ID= "id"; //$NON-NLS-1$ >+ >+ /** the singleton instance of the registry */ >+ private static CommentingStrategyRegistry fSingleton = null; >+ >+ /** <code>true</code> if this registry has been loaded. */ >+ private boolean fLoaded; >+ >+ /** >+ * <p>Registry of content type IDs to {@link BlockCommentingStrategy}s</p> >+ * >+ * <code>{@link Map}<{@link String}, {@link List}<{@link BlockContentType}>></code> >+ * <ul> >+ * <li><b>key:</b> content type ID</li> >+ * <li><b>value:</b> List of associated {@link BlockContentType}s</li> >+ * <ul> >+ */ >+ private Map fBlockCommentTypes; >+ >+ /** >+ * <p>Registry of content type IDs to {@link LineCommentingStrategy}s</p> >+ * >+ * <code>{@link Map}<{@link String}, {@link List}<{@link LineContentType}>></code> >+ * <ul> >+ * <li><b>key:</b> content type ID</li> >+ * <li><b>value:</b> List of associated {@link LineContentType}s</li> >+ * <ul> >+ */ >+ private Map fLineCommentTypes; >+ >+ /** >+ * @return the single instance of the {@link CommentingStrategyRegistry} >+ */ >+ public static synchronized CommentingStrategyRegistry getDefault() { >+ if(fSingleton == null) { >+ fSingleton = new CommentingStrategyRegistry(); >+ } >+ >+ return fSingleton; >+ } >+ >+ /** >+ * Singleton constructor for the registry >+ */ >+ private CommentingStrategyRegistry() { >+ this.fLoaded = false; >+ this.fBlockCommentTypes = new HashMap(); >+ this.fLineCommentTypes = new HashMap(); >+ } >+ >+ /** >+ * @param contentTypeID get only {@link BlockCommentingStrategy}s associated with this content type >+ * @param regions get only {@link BlockCommentingStrategy}s associated with these types of regions >+ * @return all the {@link BlockCommentingStrategy}s associated with the given content type and regions >+ */ >+ public CommentingStrategy getBlockCommentingStrategy(String contentTypeID, ITypedRegion[] regions) { >+ return getCommentingStrategy(contentTypeID, regions, this.fBlockCommentTypes); >+ } >+ >+ /** >+ * @param contentTypeID get only {@link LineCommentingStrategy}s associated with this content type >+ * @param regions get only {@link LineCommentingStrategy}s associated with these types of regions >+ * @return all the {@link LineCommentingStrategy}s associated with the given content type and regions >+ */ >+ public CommentingStrategy getLineCommentingStrategy(String contentTypeID, ITypedRegion[] regions) { >+ return getCommentingStrategy(contentTypeID, regions, this.fLineCommentTypes); >+ } >+ >+ /** >+ * <p>get all the {@link CommentingStrategy}s associated with the given content type and regions >+ * from the given registry</p> >+ * >+ * @param contentTypeID get only {@link CommentingStrategy}s associated with this content type >+ * @param regions get only {@link CommentingStrategy}s associated with these types of regions >+ * @param registry get the {@link CommentingStrategy}s from this registry >+ * @return all the {@link CommentingStrategy}s associated with the given content type and regions >+ * from the given registry >+ */ >+ private CommentingStrategy getCommentingStrategy(String contentTypeID, ITypedRegion[] regions, Map registry) { >+ ensureExtensionPointRead(); >+ >+ CommentingStrategy match = null; >+ List commentingStrategys = (List)registry.get(contentTypeID); >+ if(commentingStrategys != null) { >+ for(int i = 0; i < commentingStrategys.size() && match == null; ++i) { >+ CommentingStrategy commentType = (CommentingStrategy)commentingStrategys.get(i); >+ if(commentType.isApplicableFor(regions)) { >+ match = commentType; >+ } >+ } >+ } >+ >+ return match; >+ } >+ >+ /** >+ * <p>Ensures that the extensions are read and this registry is built</p> >+ */ >+ private void ensureExtensionPointRead() { >+ if(!fLoaded) { >+ load(); >+ fLoaded = true; >+ } >+ } >+ >+ /** >+ * <p>Load the extension points into the registry</p> >+ */ >+ private void load() { >+ IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); >+ List extensionElements = new ArrayList(Arrays.asList(extensionRegistry.getConfigurationElementsFor(SSEUIPlugin.ID, EXTENSION_POINT))); >+ >+ //for each extension >+ for (Iterator iter= extensionElements.iterator(); iter.hasNext();) { >+ IConfigurationElement element = (IConfigurationElement) iter.next(); >+ try { >+ CommentingStrategy newCommentingStrategy = null; >+ Map commentingStrategyRegistry = null; >+ //either a block or line commenting strategy >+ if(element.getName().equals(ELEM_PROPOSAL_BLOCK_COMMENTING_STRATEGY)) { >+ String prefix = element.getAttribute(ATTR_PREFIX); >+ checkExtensionAttributeNotNull(prefix, ATTR_PREFIX, element); >+ >+ String suffix = element.getAttribute(ATTR_SUFFIX); >+ checkExtensionAttributeNotNull(suffix, ATTR_SUFFIX, element); >+ >+ if(prefix != null && suffix != null) { >+ newCommentingStrategy = new BlockCommentingStrategy(prefix, suffix); >+ commentingStrategyRegistry = this.fBlockCommentTypes; >+ } >+ } else if(element.getName().equals(ELEM_PROPOSAL_LINE_COMMENTING_STRATEGY)) { >+ String prefix = element.getAttribute(ATTR_PREFIX); >+ checkExtensionAttributeNotNull(prefix, ATTR_PREFIX, element); >+ >+ if(prefix != null) { >+ newCommentingStrategy = new LineCommentingStrategy(prefix); >+ commentingStrategyRegistry = this.fLineCommentTypes; >+ } >+ } >+ >+ //add the new strategy to the registry >+ if(commentingStrategyRegistry != null && newCommentingStrategy != null) { >+ addCommentingStrategyToRegistry(element, commentingStrategyRegistry, newCommentingStrategy); >+ } else { >+ Logger.log(Logger.WARNING, "Invalid CommentingStrategy extension: " + element); //$NON-NLS-1$ >+ } >+ } catch (CoreException e) { >+ Logger.logException(e); >+ } catch (InvalidRegistryObjectException x) { >+ /* Element is not valid any longer as the contributing plug-in was unloaded or for >+ * some other reason. Do not include the extension in the list and log it >+ */ >+ String message = "The extension ''" + element.toString() + "'' is invalid."; //$NON-NLS-1$ //$NON-NLS-2$ >+ IStatus status= new Status(IStatus.WARNING, SSEUIPlugin.ID, IStatus.WARNING, message, x); >+ Logger.log(status); >+ } >+ } >+ } >+ >+ /** >+ * <p>Checks that the given attribute value is not <code>null</code>.</p> >+ * >+ * @param value the object to check if not null >+ * @param attribute the attribute >+ * >+ * @throws InvalidRegistryObjectException if the registry element is no longer valid >+ * @throws CoreException if <code>value</code> is <code>null</code> >+ */ >+ private static void checkExtensionAttributeNotNull(Object value, String attribute, >+ IConfigurationElement element) throws InvalidRegistryObjectException, CoreException { >+ >+ if (value == null) { >+ String message = "The extension \"" + element.getDeclaringExtension().getUniqueIdentifier() + //$NON-NLS-1$ >+ "\" from plug-in \"" + element.getContributor().getName() + //$NON-NLS-1$ >+ "\" did not specify a value for the required \"" + attribute + //$NON-NLS-1$ >+ "\" attribute for the element \"" + element.getName() + "\". Disabling the extension."; //$NON-NLS-1$ //$NON-NLS-2$ >+ IStatus status= new Status(IStatus.WARNING, SSEUIPlugin.ID, IStatus.OK, message, null); >+ throw new CoreException(status); >+ } >+ } >+ >+ /** >+ * <p>Using the content type element children of the given element add a copy of the given >+ * base commenting strategy to the given registry</p> >+ * >+ * @param element a {@link IConfigurationElement} with contentType element children >+ * @param commentingStrategyRegistry {@link Map} of content type ids to {@link CommentingStrategy}s to register >+ * the given {@link CommentingStrategy} with based on the <code>element</code> >+ * @param baseCommentingStrategy {@link CommentingStrategy} that will be cloned and configured for each >+ * content type in the given <code>element</code> >+ */ >+ private static void addCommentingStrategyToRegistry(IConfigurationElement element, >+ Map commentingStrategyRegistry, CommentingStrategy baseCommentingStrategy) { >+ >+ //get all the content type elements >+ IConfigurationElement[] contentTypeElements = element.getChildren(ELEM_CONTENT_TYPE); >+ if(contentTypeElements.length > 0) { >+ for(int contentTypeIndex = 0; contentTypeIndex < contentTypeElements.length; ++contentTypeIndex) { >+ try { >+ String contentTypeID = contentTypeElements[contentTypeIndex].getAttribute(ATTR_ID); >+ checkExtensionAttributeNotNull(contentTypeID, ATTR_ID, contentTypeElements[contentTypeIndex]); >+ >+ List commentTypes = (List)commentingStrategyRegistry.get(contentTypeID); >+ if(commentTypes == null) { >+ commentTypes = new ArrayList(); >+ commentingStrategyRegistry.put(contentTypeID, commentTypes); >+ } >+ >+ //this element is required >+ List allowablePartitionTypeIDs = new ArrayList(); >+ IConfigurationElement[] allowablePartitionTypes = >+ contentTypeElements[contentTypeIndex].getChildren(ELEM_ALLOWABLE_PARTITION_TYPES); >+ boolean anyPartitionType = false; >+ if(allowablePartitionTypes.length > 0) { >+ //determine anyPartitionType attribute value >+ String anyPartitionTypeValue = allowablePartitionTypes[0].getAttribute(ATTR_ANY_PARTITION_TYPE); >+ if(anyPartitionTypeValue != null) { >+ anyPartitionType = Boolean.valueOf(anyPartitionTypeValue).booleanValue(); >+ } >+ >+ //get the optional partition types >+ allowablePartitionTypes = allowablePartitionTypes[0].getChildren(ELEM_PARTITION_TYPE); >+ if(allowablePartitionTypes.length > 0) { >+ for (int partitionTypeIndex = 0; partitionTypeIndex < allowablePartitionTypes.length; ++partitionTypeIndex) { >+ String partitionTypeID = allowablePartitionTypes[partitionTypeIndex].getAttribute(ATTR_ID); >+ checkExtensionAttributeNotNull(partitionTypeID, ATTR_ID, allowablePartitionTypes[partitionTypeIndex]); >+ >+ allowablePartitionTypeIDs.add(partitionTypeID); >+ } >+ } >+ >+ //this element is optional >+ List requiredPartitionTypeIDs = new ArrayList(); >+ IConfigurationElement[] requiredPartitionTypes = >+ contentTypeElements[contentTypeIndex].getChildren(ELEM_REQUIRED_PARTITION_TYPES); >+ boolean requireAll = false; >+ if(requiredPartitionTypes.length > 0) { >+ //determine requireAll attribute value >+ String requireAllValue = requiredPartitionTypes[0].getAttribute(ATTR_REQUIRE_ALL); >+ if(requireAllValue != null) { >+ requireAll = Boolean.valueOf(requireAllValue).booleanValue(); >+ } >+ >+ //get the required partition types >+ requiredPartitionTypes = requiredPartitionTypes[0].getChildren(ELEM_PARTITION_TYPE); >+ if(requiredPartitionTypes.length > 0) { >+ for (int partitionTypeIndex = 0; partitionTypeIndex < requiredPartitionTypes.length; ++partitionTypeIndex) { >+ String partitionTypeID = requiredPartitionTypes[partitionTypeIndex].getAttribute(ATTR_ID); >+ checkExtensionAttributeNotNull(partitionTypeID, ATTR_ID, requiredPartitionTypes[partitionTypeIndex]); >+ >+ requiredPartitionTypeIDs.add(partitionTypeID); >+ } >+ } >+ } >+ >+ //get the optional associated comment partition type ID >+ String associatedCommentPartitionTypeID = >+ contentTypeElements[contentTypeIndex].getAttribute(ATTR_ASSOCIATED_COMMENT_PARTITION_TPYPE_ID); >+ >+ //register the strategy >+ CommentingStrategy newCommentingStrategy = (CommentingStrategy)baseCommentingStrategy.clone(); >+ newCommentingStrategy.setPartitionInformation(allowablePartitionTypeIDs, anyPartitionType, >+ requiredPartitionTypeIDs, requireAll, associatedCommentPartitionTypeID); >+ commentTypes.add(newCommentingStrategy); >+ >+ } else { >+ Logger.log(Logger.WARNING, "The " + ELEM_ALLOWABLE_PARTITION_TYPES + >+ " element was not specified for one of the " + ELEM_CONTENT_TYPE +"s in " + //$NON-NLS-1$ //$NON-NLS-2$ >+ element + " affected extension will not be loaded" ); //$NON-NLS-1$ >+ } >+ } catch(CoreException e) { >+ Logger.logException(e); >+ } >+ } >+ } else { >+ Logger.log(Logger.WARNING, "The commmentying strategy element: " + element +//$NON-NLS-1$ >+ " does not contain any requried " + ELEM_CONTENT_TYPE + "s"); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } >+} >Index: src/org/eclipse/wst/sse/ui/internal/comment/BlockCommentingStrategy.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/comment/BlockCommentingStrategy.java >diff -N src/org/eclipse/wst/sse/ui/internal/comment/BlockCommentingStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/comment/BlockCommentingStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,142 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.comment; >+ >+import java.util.List; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.jface.text.Region; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; >+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; >+import org.eclipse.wst.sse.ui.internal.Logger; >+ >+/** >+ * <p>Represents a Block Comment commenting strategy</p> >+ */ >+public class BlockCommentingStrategy extends CommentingStrategy { >+ /** the prefix of the block comment associated with this strategy */ >+ private String fPrefix; >+ >+ /** the suffix of the block comment associated with this strategy */ >+ private String fSuffix; >+ >+ /** >+ * @param prefix the prefix of the block comment associated with this strategy >+ * @param suffix the suffix of the block comment associated with this strategy >+ */ >+ public BlockCommentingStrategy(String prefix, String suffix) { >+ super(); >+ this.fPrefix = prefix; >+ this.fSuffix = suffix; >+ } >+ >+ /** >+ * <p>When applying a block comment it also removes any block comments associated >+ * with this strategy that would now be enclosed by the new block comment</p> >+ * >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#apply( >+ * org.eclipse.wst.sse.core.internal.provisional.IStructuredModel, int, int) >+ */ >+ public void apply(IStructuredModel model, int offset, int length) throws BadLocationException { >+ IDocument document = model.getStructuredDocument(); >+ int commentPrefixOffset = offset; >+ int commentSuffixOffset = commentPrefixOffset + length; >+ >+ try { >+ document.replace(commentSuffixOffset, 0, " " + this.fSuffix); //$NON-NLS-1$ >+ this.remove(model, commentPrefixOffset + this.fPrefix.length(), length, false); >+ document.replace(commentPrefixOffset, 0, this.fPrefix + " "); //$NON-NLS-1$ >+ } >+ catch (BadLocationException e) { >+ Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >+ } >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#remove( >+ * org.eclipse.jface.text.IDocument, int, int) >+ */ >+ public void remove(IStructuredModel model, int offset, int length, boolean removeEnclosing) throws BadLocationException { >+ IDocument document = model.getStructuredDocument(); >+ >+ IRegion region = new Region(offset, length); >+ ITypedRegion[] typedRegions = document.computePartitioning(region.getOffset(), region.getLength()); >+ List commentRegions = this.getAssociatedCommentedRegions(typedRegions); >+ >+ //remove in reverse order as to not effect offset of other regions >+ for(int i = commentRegions.size()-1; i >= 0; --i) { >+ try { >+ //get the comment region >+ ITypedRegion typedRegion = (ITypedRegion)commentRegions.get(i); >+ IRegion commentRegion = new Region(typedRegion.getOffset(), typedRegion.getLength()); >+ >+ /* because of the nature of structured regions the comment region could actually be a >+ * sub region that needs to be drilled down too >+ */ >+ if(!this.alreadyCommenting(document, commentRegion)) { >+ IStructuredDocumentRegion structuredRegion = >+ model.getStructuredDocument().getRegionAtCharacterOffset(commentRegion.getOffset()); >+ >+ commentRegion = new Region(structuredRegion.getStartOffset(), structuredRegion.getLength()); >+ >+ if(!this.alreadyCommenting(document, commentRegion)) { >+ ITextRegion enclosedRegion = structuredRegion.getRegionAtCharacterOffset(typedRegion.getOffset()); >+ int enclosedOffset = structuredRegion.getStartOffset(enclosedRegion); >+ commentRegion = new Region(enclosedOffset, structuredRegion.getTextEndOffset(enclosedRegion)-enclosedOffset); >+ } >+ } >+ >+ //at this point should have found the comment region, if not there is an issue >+ if(this.alreadyCommenting(document, commentRegion)) { >+ String regionContent = document.get(commentRegion.getOffset(), commentRegion.getLength()); >+ >+ //if found the comment prefix and suffix then uncomment, otherwise log error >+ int commentPrefixOffset = commentRegion.getOffset() + regionContent.indexOf(this.fPrefix); >+ int commentSuffixOffset = commentRegion.getOffset(); >+ commentSuffixOffset += regionContent.lastIndexOf(this.fSuffix); >+ >+ //remove comment block depending on if its an enclosing comment block and weather that is allowed >+ if(removeEnclosing || (commentPrefixOffset >= offset && commentSuffixOffset <= offset+length)) { >+ uncomment(document, commentPrefixOffset, this.fPrefix, commentSuffixOffset, this.fSuffix); >+ } >+ } else { >+ Logger.log(Logger.ERROR, >+ "BlockCommentingStrategy#remove could not find the commenting region to remove"); //$NON-NLS-1$ >+ } >+ } catch(BadLocationException e) { >+ Logger.logException("This shoudl only ever happen if somethign has gone wrong with the partitioning", e); //$NON-NLS-1$ >+ } >+ } >+ } >+ >+ /** >+ * <p>A region is already commented by this strategy if it starts with the strategy's associated >+ * prefix and ends with its associated suffix, ignoring any trailing or leading whitespace</p> >+ * >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#alreadyCommenting( >+ * org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion) >+ */ >+ public boolean alreadyCommenting(IDocument document, IRegion region) throws BadLocationException { >+ String regionContent = document.get(region.getOffset(), region.getLength()).trim(); >+ return regionContent.startsWith(this.fPrefix) && regionContent.endsWith(this.fSuffix); >+ } >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy#clone() >+ */ >+ public Object clone() { >+ return new BlockCommentingStrategy(this.fPrefix, this.fSuffix); >+ } >+} >Index: src/org/eclipse/wst/sse/ui/handlers/RemoveBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/handlers/RemoveBlockCommentHandler.java >diff -N src/org/eclipse/wst/sse/ui/handlers/RemoveBlockCommentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/handlers/RemoveBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.handlers; >+ >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.DocumentRewriteSession; >+import org.eclipse.jface.text.DocumentRewriteSessionType; >+import org.eclipse.jface.text.IDocumentExtension4; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.ITypedRegion; >+import org.eclipse.ui.texteditor.ITextEditor; >+import org.eclipse.wst.sse.core.StructuredModelManager; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; >+import org.eclipse.wst.sse.ui.internal.Logger; >+import org.eclipse.wst.sse.ui.internal.SSEUIMessages; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategy; >+import org.eclipse.wst.sse.ui.internal.comment.CommentingStrategyRegistry; >+import org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler; >+ >+/** >+ * <p>A comment handler to remove block comments</p> >+ */ >+public final class RemoveBlockCommentHandler extends >+ AbstractCommentHandler { >+ >+ /** >+ * @see org.eclipse.wst.sse.ui.internal.handlers.AbstractCommentHandler#processAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.IDocument, org.eclipse.jface.text.ITextSelection) >+ */ >+ protected void processAction(ITextEditor textEditor, IStructuredDocument document, ITextSelection textSelection) { >+ >+ IStructuredModel model = null; >+ boolean changed = false; >+ DocumentRewriteSession session = null; >+ try { >+ model = StructuredModelManager.getModelManager().getModelForEdit(document); >+ >+ if(model != null) { >+ //makes it so one undo will undo all the edits to the document >+ model.beginRecording(this, SSEUIMessages.RemoveBlockComment_label, >+ SSEUIMessages.RemoveBlockComment_label); >+ >+ //keeps listeners from doing anything until updates are all done >+ model.aboutToChangeModel(); >+ if(document instanceof IDocumentExtension4) { >+ session = ((IDocumentExtension4)document).startRewriteSession( >+ DocumentRewriteSessionType.UNRESTRICTED); >+ } >+ changed = true; >+ >+ ITypedRegion[] typedRegions = document.computePartitioning( >+ textSelection.getOffset(), textSelection.getLength()); >+ CommentingStrategy commentType = CommentingStrategyRegistry.getDefault().getBlockCommentingStrategy( >+ model.getContentTypeIdentifier(), typedRegions); >+ >+ if(commentType != null) { >+ commentType.remove(model, textSelection.getOffset(), textSelection.getLength(), true); >+ } >+ } >+ } catch (BadLocationException e) { >+ Logger.logException("The given selection " + textSelection + " must be invalid", e); //$NON-NLS-1$ //$NON-NLS-2$ >+ } finally { >+ //clean everything up >+ if(session != null && document instanceof IDocumentExtension4) { >+ ((IDocumentExtension4)document).stopRewriteSession(session); >+ } >+ >+ if(model != null) { >+ model.endRecording(this); >+ if(changed) { >+ model.changedModel(); >+ } >+ model.releaseFromEdit(); >+ } >+ } >+ } >+} >#P org.eclipse.wst.xml.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.xml,v >retrieving revision 1.111 >diff -u -r1.111 plugin.xml >--- plugin.xml 26 Feb 2010 20:59:34 -0000 1.111 >+++ plugin.xml 2 Mar 2010 20:05:31 -0000 >@@ -1012,53 +1012,6 @@ > </command> > </toolbar> > </menuContribution> >- >- <menuContribution locationURI="menu:sourceMenuId?after=sourceBegin"> >- <command commandId="org.eclipse.wst.sse.ui.toggle.comment" >- id="ToggleComment" >- mnemonic="%command.toggle.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.add.block.comment" >- id="AddBlockComment" >- mnemonic="%command.add.block.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" >- id="RemoveBlockComment" >- mnemonic="%command.remove.block.comment.mnemonic" >- style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >- </visibleWhen> >- </command> >- </menuContribution> >- >- <menuContribution >- locationURI="popup:sourcePopupMenuId?after=sourceBegin"> >- <command commandId="org.eclipse.wst.sse.ui.toggle.comment" id="ToggleComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.add.block.comment" id="AddBlockComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> >- </visibleWhen> >- </command> >- <command commandId="org.eclipse.wst.sse.ui.remove.block.comment" id="RemoveBlockComment" style="push"> >- <visibleWhen checkEnabled="false"> >- <reference definitionId="org.eclipse.wst.xml.ui.comments"></reference> >- </visibleWhen> >- </command> >- <separator name="format" visible="true"></separator> >- </menuContribution> > </extension> > > <extension point="org.eclipse.core.expressions.definitions"> >@@ -1189,7 +1142,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.xml.ui.internal.handlers.ToggleCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.ToggleLineCommentHandler" > commandId="org.eclipse.wst.sse.ui.toggle.comment"> > <activeWhen> > <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >@@ -1199,7 +1152,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.xml.ui.internal.handlers.AddBlockCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.AddBlockCommentHandler" > commandId="org.eclipse.wst.sse.ui.add.block.comment"> > <activeWhen> > <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >@@ -1209,7 +1162,7 @@ > </enabledWhen> > </handler> > <handler >- class="org.eclipse.wst.xml.ui.internal.handlers.RemoveBlockCommentHandler" >+ class="org.eclipse.wst.sse.ui.handlers.RemoveBlockCommentHandler" > commandId="org.eclipse.wst.sse.ui.remove.block.comment"> > <activeWhen> > <reference definitionId="org.eclipse.wst.xml.ui.comments"/> >@@ -1672,6 +1625,20 @@ > </inserter> > </extension> > <extension >+ point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="<!--" >+ suffix="-->"> >+ <contentType >+ id="org.eclipse.core.runtime.xml" >+ associatedCommentPartitionTypeID="org.eclipse.wst.xml.XML_COMMENT"> >+ <allowablePartitionTypes >+ anyPartitionType="true"> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ </extension> >+ <extension > point="org.eclipse.wst.sse.ui.completionProposal"> > <proposalCategory > icon="icons/full/obj16/tag-generic.gif" >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.properties,v >retrieving revision 1.45 >diff -u -r1.45 plugin.properties >--- plugin.properties 26 Feb 2010 20:59:34 -0000 1.45 >+++ plugin.properties 2 Mar 2010 20:05:31 -0000 >@@ -135,12 +135,6 @@ > Colors.cdataBorder=CDATA Border > Colors.cdataText=CDATA Text > Colors.entityReference=Entity Reference >- >-# Menu contributions >-command.toggle.comment.mnemonic=T >-command.add.block.comment.mnemonic=A >-command.remove.block.comment.mnemonic=R >- > # content assist > proposalCategory.xmlTags=XML Tag Proposals > proposalCategory.xmlTemplates=XML Template Proposals >\ No newline at end of file >Index: src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java >diff -N src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java >--- src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java 27 Mar 2008 02:58:48 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,103 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * David Carver - initial API and implementation, bug 212330 >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.ui.internal.handlers; >- >-import org.eclipse.core.commands.AbstractHandler; >-import org.eclipse.core.commands.ExecutionEvent; >-import org.eclipse.core.commands.ExecutionException; >-import org.eclipse.core.commands.IHandler; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.jface.text.TextSelection; >-import org.eclipse.jface.viewers.ISelection; >-import org.eclipse.jface.viewers.ISelectionProvider; >-import org.eclipse.ui.IEditorPart; >-import org.eclipse.ui.handlers.HandlerUtil; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.xml.ui.internal.Logger; >- >-public class CommentHandler extends AbstractHandler implements IHandler { >- static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ >- static final String OPEN_COMMENT = "<!--"; //$NON-NLS-1$ >- >- public CommentHandler() { >- super(); >- } >- >- public Object execute(ExecutionEvent event) throws ExecutionException { >- IEditorPart editor = HandlerUtil.getActiveEditor(event); >- ITextEditor textEditor = null; >- if (editor instanceof ITextEditor) >- textEditor = (ITextEditor) editor; >- else { >- Object o = editor.getAdapter(ITextEditor.class); >- if (o != null) >- textEditor = (ITextEditor) o; >- } >- if (textEditor != null) { >- IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); >- if (document != null) { >- // get current text selection >- ITextSelection textSelection = getCurrentSelection(textEditor); >- if (textSelection.isEmpty()) { >- return null; >- } >- >- processAction(textEditor, document, textSelection); >- } >- } >- >- return null; >- } >- >- protected ITextSelection getCurrentSelection(ITextEditor textEditor) { >- ISelectionProvider provider = textEditor.getSelectionProvider(); >- if (provider != null) { >- ISelection selection = provider.getSelection(); >- if (selection instanceof ITextSelection) { >- return (ITextSelection) selection; >- } >- } >- return TextSelection.emptySelection(); >- } >- >- void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- // Implementations to over ride. >- } >- >- protected void removeOpenCloseComments(IDocument document, int offset, int length) { >- try { >- int adjusted_length = length; >- >- // remove open comments >- String string = document.get(offset, length); >- int index = string.lastIndexOf(OPEN_COMMENT); >- while (index != -1) { >- document.replace(offset + index, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- index = string.lastIndexOf(OPEN_COMMENT, index - 1); >- adjusted_length -= OPEN_COMMENT.length(); >- } >- >- // remove close comments >- string = document.get(offset, adjusted_length); >- index = string.lastIndexOf(CLOSE_COMMENT); >- while (index != -1) { >- document.replace(offset + index, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- index = string.lastIndexOf(CLOSE_COMMENT, index - 1); >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >-} >Index: src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java >diff -N src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java >--- src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java 27 Mar 2008 02:58:48 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,84 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * David Carver - initial API and implementation, bug 212330 >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.ui.internal.handlers; >- >-import org.eclipse.core.commands.IHandler; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; >-import org.eclipse.wst.xml.core.internal.document.CommentImpl; >-import org.eclipse.wst.xml.ui.internal.Logger; >-import org.eclipse.wst.xml.ui.internal.XMLUIMessages; >- >-/** >- * @author dcarver >- * >- */ >-public class RemoveBlockCommentHandler extends CommentHandler implements IHandler { >- >- public RemoveBlockCommentHandler() { >- super(); >- } >- >- void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null) { >- try { >- IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); >- IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); >- >- if ((selectionStartIndexedRegion == null) || (selectionEndIndexedRegion == null)) { >- return; >- } >- >- int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); >- int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() - OPEN_COMMENT.length() - CLOSE_COMMENT.length(); >- >- model.beginRecording(this, XMLUIMessages.RemoveBlockComment_tooltip); >- model.aboutToChangeModel(); >- >- try { >- if (textSelection.getLength() == 0) { >- if (selectionStartIndexedRegion instanceof CommentImpl) { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- } >- else { >- if (selectionStartIndexedRegion instanceof CommentImpl) { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- >- if (selectionEndIndexedRegion instanceof CommentImpl) { >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- } >- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- } >- } >- finally { >- model.releaseFromEdit(); >- } >- } >- } >-} >Index: src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java >diff -N src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java >--- src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java 27 Mar 2008 02:58:48 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,77 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * David Carver - initial API and implementation, bug 212330 >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.ui.internal.handlers; >- >-import org.eclipse.core.commands.IHandler; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; >-import org.eclipse.wst.xml.core.internal.document.CommentImpl; >-import org.eclipse.wst.xml.ui.internal.Logger; >-import org.eclipse.wst.xml.ui.internal.XMLUIMessages; >- >-public class AddBlockCommentHandler extends CommentHandler implements IHandler { >- >- public AddBlockCommentHandler() { >- super(); >- } >- >- void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null) { >- try { >- IndexedRegion selectionStartIndexedRegion = model.getIndexedRegion(textSelection.getOffset()); >- IndexedRegion selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength()); >- >- if (selectionStartIndexedRegion == null) { >- return; >- } >- if ((selectionEndIndexedRegion == null) && (textSelection.getLength() > 0)) { >- selectionEndIndexedRegion = model.getIndexedRegion(textSelection.getOffset() + textSelection.getLength() - 1); >- } >- if (selectionEndIndexedRegion == null) { >- return; >- } >- >- int openCommentOffset = selectionStartIndexedRegion.getStartOffset(); >- int closeCommentOffset = selectionEndIndexedRegion.getEndOffset() + OPEN_COMMENT.length(); >- >- if ((textSelection.getLength() == 0) && (selectionStartIndexedRegion instanceof CommentImpl)) { >- return; >- } >- >- model.beginRecording(this, XMLUIMessages.AddBlockComment_tooltip); >- model.aboutToChangeModel(); >- >- try { >- document.replace(openCommentOffset, 0, OPEN_COMMENT); >- document.replace(closeCommentOffset, 0, CLOSE_COMMENT); >- super.removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- } >- } >- finally { >- model.releaseFromEdit(); >- } >- } >- } >-} >Index: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java >diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java >--- src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java 27 Mar 2008 02:58:48 -0000 1.2 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,193 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * David Carver - initial API and implementation, bug 212330 >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.ui.internal.handlers; >- >-import org.eclipse.core.commands.ExecutionEvent; >-import org.eclipse.core.commands.ExecutionException; >-import org.eclipse.core.commands.IHandler; >-import org.eclipse.jface.text.BadLocationException; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.IRegion; >-import org.eclipse.jface.text.ITextSelection; >-import org.eclipse.jface.text.Position; >-import org.eclipse.jface.text.TextSelection; >-import org.eclipse.jface.viewers.ISelectionProvider; >-import org.eclipse.ui.IEditorPart; >-import org.eclipse.ui.handlers.HandlerUtil; >-import org.eclipse.ui.texteditor.ITextEditor; >-import org.eclipse.wst.sse.core.StructuredModelManager; >-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >-import org.eclipse.wst.xml.ui.internal.Logger; >-import org.eclipse.wst.xml.ui.internal.XMLUIMessages; >- >-public class ToggleCommentHandler extends CommentHandler implements IHandler { >- public ToggleCommentHandler() { >- super(); >- } >- >- public Object execute(ExecutionEvent event) throws ExecutionException { >- IEditorPart editor = HandlerUtil.getActiveEditor(event); >- ITextEditor textEditor = null; >- if (editor instanceof ITextEditor) >- textEditor = (ITextEditor) editor; >- else { >- Object o = editor.getAdapter(ITextEditor.class); >- if (o != null) >- textEditor = (ITextEditor) o; >- } >- if (textEditor != null) { >- IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); >- if (document != null) { >- // get current text selection >- ITextSelection textSelection = getCurrentSelection(textEditor); >- if (textSelection.isEmpty()) { >- return null; >- } >- >- processAction(textEditor, document, textSelection); >- } >- } >- return null; >- } >- >- void processAction(ITextEditor textEditor, IDocument document, ITextSelection textSelection) { >- // get text selection lines info >- int selectionStartLine = textSelection.getStartLine(); >- int selectionEndLine = textSelection.getEndLine(); >- try { >- int selectionEndLineOffset = document.getLineOffset(selectionEndLine); >- int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); >- >- // adjust selection end line >- if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { >- selectionEndLine--; >- } >- >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- >- // save the selection position since it will be changing >- Position selectionPosition = null; >- boolean updateStartOffset = false; >- try { >- selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); >- document.addPosition(selectionPosition); >- >- // extra check if commenting from beginning of line >- int selectionStartLineOffset = document.getLineOffset(selectionStartLine); >- if ((textSelection.getLength() > 0) && (selectionStartLineOffset == textSelection.getOffset()) && !isCommentLine(document, selectionStartLine)) { >- updateStartOffset = true; >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- >- processAction(document, selectionStartLine, selectionEndLine); >- >- updateCurrentSelection(textEditor, selectionPosition, document, updateStartOffset); >- } >- >- private void processAction(IDocument document, int selectionStartLine, int selectionEndLine) { >- IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForEdit(document); >- if (model != null) { >- try { >- model.beginRecording(this, XMLUIMessages.ToggleComment_tooltip); >- model.aboutToChangeModel(); >- >- for (int i = selectionStartLine; i <= selectionEndLine; i++) { >- try { >- if (document.getLineLength(i) > 0) { >- if (isCommentLine(document, i)) { >- int lineOffset = document.getLineOffset(i); >- IRegion region = document.getLineInformation(i); >- String string = document.get(region.getOffset(), region.getLength()); >- int openCommentOffset = lineOffset + string.indexOf(OPEN_COMMENT); >- int closeCommentOffset = lineOffset + string.indexOf(CLOSE_COMMENT) - OPEN_COMMENT.length(); >- uncomment(document, openCommentOffset, closeCommentOffset); >- } >- else { >- int openCommentOffset = document.getLineOffset(i); >- int lineDelimiterLength = document.getLineDelimiter(i) == null ? 0 : document.getLineDelimiter(i).length(); >- int closeCommentOffset = openCommentOffset + document.getLineLength(i) - lineDelimiterLength + OPEN_COMMENT.length(); >- comment(document, openCommentOffset, closeCommentOffset); >- } >- } >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >- } >- finally { >- model.changedModel(); >- model.endRecording(this); >- model.releaseFromEdit(); >- } >- } >- } >- >- private boolean isCommentLine(IDocument document, int line) { >- boolean isComment = false; >- >- try { >- IRegion region = document.getLineInformation(line); >- String string = document.get(region.getOffset(), region.getLength()).trim(); >- isComment = (string.length() >= OPEN_COMMENT.length() + CLOSE_COMMENT.length()) && string.startsWith(OPEN_COMMENT) && string.endsWith(CLOSE_COMMENT); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- return isComment; >- } >- >- private void comment(IDocument document, int openCommentOffset, int closeCommentOffset) { >- try { >- document.replace(openCommentOffset, 0, OPEN_COMMENT); >- document.replace(closeCommentOffset, 0, CLOSE_COMMENT); >- removeOpenCloseComments(document, openCommentOffset + OPEN_COMMENT.length(), closeCommentOffset - openCommentOffset - CLOSE_COMMENT.length()); >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >- >- private void uncomment(IDocument document, int openCommentOffset, int closeCommentOffset) { >- try { >- document.replace(openCommentOffset, OPEN_COMMENT.length(), ""); //$NON-NLS-1$ >- document.replace(closeCommentOffset, CLOSE_COMMENT.length(), ""); //$NON-NLS-1$ >- } >- catch (BadLocationException e) { >- Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); >- } >- } >- >- private void updateCurrentSelection(ITextEditor textEditor, Position selectionPosition, IDocument document, boolean updateStartOffset) { >- // update the selection if text selection changed >- if (selectionPosition != null) { >- ITextSelection selection = null; >- if (updateStartOffset) { >- selection = new TextSelection(document, selectionPosition.getOffset() - OPEN_COMMENT.length(), selectionPosition.getLength() + OPEN_COMMENT.length()); >- } >- else { >- selection = new TextSelection(document, selectionPosition.getOffset(), selectionPosition.getLength()); >- } >- ISelectionProvider provider = textEditor.getSelectionProvider(); >- if (provider != null) { >- provider.setSelection(selection); >- } >- document.removePosition(selectionPosition); >- } >- } >-} >#P org.eclipse.wst.jsdt.web.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.jsdt.web.ui/plugin.xml,v >retrieving revision 1.34 >diff -u -r1.34 plugin.xml >--- plugin.xml 23 Feb 2010 03:19:15 -0000 1.34 >+++ plugin.xml 2 Mar 2010 20:05:32 -0000 >@@ -670,6 +670,70 @@ > </objectContribution> > </extension> > --> >+ <extension >+ point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="/*" >+ suffix="*/"> >+ <contentType >+ id="org.eclipse.wst.html.core.htmlsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ <contentType >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JAVASCRIPT"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ <lineCommentingStrategy >+ prefix="//"> >+ <contentType >+ id="org.eclipse.wst.html.core.htmlsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ <contentType >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JAVASCRIPT"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ </lineCommentingStrategy> >+ </extension> > > <!-- Uncomment for Standalone + HTML as seperate options --> > <!-- >#P org.eclipse.jst.jsp.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.ui/plugin.xml,v >retrieving revision 1.95 >diff -u -r1.95 plugin.xml >--- plugin.xml 2 Mar 2010 16:56:30 -0000 1.95 >+++ plugin.xml 2 Mar 2010 20:05:32 -0000 >@@ -72,7 +72,7 @@ > target="org.eclipse.jst.jsp.core.jspsource" /> > <provisionalDefinition > type="activecontexts" >- value="org.eclipse.jst.jsp.core.jspsource, org.eclipse.jst.jsp.ui.structured.text.editor.jsp.scope, org.eclipse.wst.html.core.htmlsource, org.eclipse.core.runtime.xml, org.eclipse.wst.xml.navigation, org.eclipse.wst.xml.comments, org.eclipse.wst.xml.selection" >+ value="org.eclipse.jst.jsp.core.jspsource, org.eclipse.jst.jsp.ui.structured.text.editor.jsp.scope, org.eclipse.wst.html.core.htmlsource, org.eclipse.core.runtime.xml, org.eclipse.wst.xml.navigation, org.eclipse.jst.jsp.comments, org.eclipse.wst.xml.selection" > target="org.eclipse.jst.jsp.core.jspsource" /> > > <contentOutlineConfiguration >@@ -497,6 +497,12 @@ > description="%scope.jsp.core.jspsource.description" > id="org.eclipse.jst.jsp.core.jspsource"> > </context> >+ <context >+ name="%scope.structured.text.editor.jsp.comments.name" >+ parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" >+ description="%scope.structured.text.editor.jsp.comments.description" >+ id="org.eclipse.jst.jsp.comments"> >+ </context> > </extension> > > <!-- Keybindings for jsp source editor --> >@@ -1033,8 +1039,8 @@ > </menuContribution> > </extension> > >- <!-- Enable the FormatHandler for JSP Content Type --> > <extension point="org.eclipse.ui.handlers"> >+ <!-- Enable the FormatHandler for JSP Content Type --> > <handler > class="org.eclipse.wst.sse.ui.internal.handlers.FormatHandler" > commandId="org.eclipse.wst.sse.ui.format"> >@@ -1045,6 +1051,36 @@ > <reference definitionId="org.eclipse.wst.jsp.ui.jspContentType.definition"></reference> > </enabledWhen> > </handler> >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.ToggleLineCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.toggle.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </enabledWhen> >+ </handler> >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.AddBlockCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.add.block.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </enabledWhen> >+ </handler> >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.RemoveBlockCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.remove.block.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.jst.jsp.ui.comments"/> >+ </enabledWhen> >+ </handler> > </extension> > > <!-- Set up a definition for JSP Content Types --> >@@ -1059,6 +1095,16 @@ > </iterate> > </definition> > </extension> >+ <!-- Set up a definition for JSP Comments handler --> >+ <extension point="org.eclipse.core.expressions.definitions"> >+ <definition id="org.eclipse.jst.jsp.ui.comments"> >+ <with variable="activeContexts"> >+ <iterate operator="or"> >+ <equals value="org.eclipse.jst.jsp.comments"/> >+ </iterate> >+ </with> >+ </definition> >+ </extension> > <extension point="org.eclipse.wst.sse.ui.characterPairing"> > <inserter class="org.eclipse.wst.html.ui.internal.text.CharacterPairInserter" id="org.eclipse.wst.jsp.ui.inserter"> > <contentTypeIdentifier >@@ -1084,6 +1130,95 @@ > </inserter> > </extension> > <extension >+ point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="<!--" >+ suffix="-->"> >+ <contentType >+ associatedCommentPartitionTypeID="org.eclipse.wst.html.HTML_COMMENT" >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ <partitionType >+ id="org.eclipse.wst.css.STYLE"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT.EVENTHANDLER"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.HTML_DEFAULT"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.HTML_DECLARATION"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.xml.XML_PI"> >+ </partitionType> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ <blockCommentingStrategy >+ prefix="<%--" >+ suffix="--%>"> >+ <contentType >+ associatedCommentPartitionTypeID="org.eclipse.jst.jsp.JSP_COMMENT" >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.jst.jsp.JSP_DIRECTIVE"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.DEFAULT_JSP"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.DELIMITER"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JSP_EL"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JSP_EL2"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="true"> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ <blockCommentingStrategy >+ prefix="/*" >+ suffix="*/"> >+ <contentType >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JAVA"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ <lineCommentingStrategy >+ prefix="//"> >+ <contentType >+ id="org.eclipse.jst.jsp.core.jspsource"> >+ <requiredPartitionTypes >+ requireAll="false"> >+ <partitionType >+ id="org.eclipse.jst.jsp.SCRIPT.JAVA"> >+ </partitionType> >+ </requiredPartitionTypes> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ </allowablePartitionTypes> >+ </contentType> >+ </lineCommentingStrategy> >+ </extension> >+ <extension > point="org.eclipse.wst.sse.ui.completionProposal"> > <proposalCategory > icon="icons/full/obj16/tag-template.gif" >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.jst.jsp.ui/plugin.properties,v >retrieving revision 1.27 >diff -u -r1.27 plugin.properties >--- plugin.properties 26 Feb 2010 20:59:29 -0000 1.27 >+++ plugin.properties 2 Mar 2010 20:05:32 -0000 >@@ -51,6 +51,8 @@ > scope.structured.text.editor.jsp.description=Editing JSP Source > scope.jsp.core.jspsource.name=JSP Source > scope.jsp.core.jspsource.description=JSP Source >+scope.structured.text.editor.jsp.comments.name=JSP Source Comments >+scope.structured.text.editor.jsp.comments.description=JSP Source Comments > JSP_Type_Rename_Participant_Extension_Element.name=JSP Type Rename Participant > JSP_Method_Rename_Participant_Extension_Element.name=JSP Method Rename Participant > JSP_Package_Rename_Participant_Extension_Element.name=JSP Package Rename Participant >#P org.eclipse.wst.html.core >Index: src/org/eclipse/wst/html/core/text/IHTMLPartitions.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/text/IHTMLPartitions.java,v >retrieving revision 1.5 >diff -u -r1.5 IHTMLPartitions.java >--- src/org/eclipse/wst/html/core/text/IHTMLPartitions.java 24 Oct 2007 09:45:10 -0000 1.5 >+++ src/org/eclipse/wst/html/core/text/IHTMLPartitions.java 2 Mar 2010 20:05:32 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation and others. >+ * Copyright (c) 2005, 2010 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -26,6 +26,10 @@ > > String SCRIPT = "org.eclipse.wst.html.SCRIPT"; //$NON-NLS-1$ > String SCRIPT_EVENTHANDLER = SCRIPT + ".EVENTHANDLER"; //$NON-NLS-1$ >+ >+ /** >+ * @deprecated this partition type is not used locally any longer >+ */ > String STYLE = "org.eclipse.wst.html.STYLE"; //$NON-NLS-1$ > > // ISSUE: I think meta tag areas are here too? >#P org.eclipse.wst.html.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/plugin.xml,v >retrieving revision 1.92 >diff -u -r1.92 plugin.xml >--- plugin.xml 26 Feb 2010 20:59:37 -0000 1.92 >+++ plugin.xml 2 Mar 2010 20:05:33 -0000 >@@ -60,7 +60,7 @@ > target="org.eclipse.wst.html.core.htmlsource" /> > <provisionalDefinition > type="activecontexts" >- value="org.eclipse.wst.html.core.htmlsource, org.eclipse.wst.html.occurrences, org.eclipse.core.runtime.xml, org.eclipse.wst.xml.navigation, org.eclipse.wst.xml.comments, org.eclipse.wst.xml.selection" >+ value="org.eclipse.wst.html.core.htmlsource, org.eclipse.wst.html.occurrences, org.eclipse.core.runtime.xml, org.eclipse.wst.xml.navigation, org.eclipse.wst.html.comments, org.eclipse.wst.xml.selection" > target="org.eclipse.wst.html.core.htmlsource" /> > </extension> > <extension >@@ -287,6 +287,12 @@ > description="%scope.structured.text.editor.html.occurrences.description" > id="org.eclipse.wst.html.occurrences"> > </context> >+ <context >+ name="%scope.structured.text.editor.html.comments.name" >+ parentId="org.eclipse.wst.sse.ui.structuredTextEditorScope" >+ description="%scope.structured.text.editor.html.comments.description" >+ id="org.eclipse.wst.html.comments"> >+ </context> > </extension> > > <!-- initialize html ui preferences --> >@@ -548,7 +554,36 @@ > </reference> > </enabledWhen> > </handler> >- >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.ToggleLineCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.toggle.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </enabledWhen> >+ </handler> >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.AddBlockCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.add.block.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </enabledWhen> >+ </handler> >+ <handler >+ class="org.eclipse.wst.sse.ui.handlers.RemoveBlockCommentHandler" >+ commandId="org.eclipse.wst.sse.ui.remove.block.comment"> >+ <activeWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </activeWhen> >+ <enabledWhen> >+ <reference definitionId="org.eclipse.wst.html.ui.comments"/> >+ </enabledWhen> >+ </handler> > </extension> > > <extension >@@ -594,7 +629,17 @@ > </with> > </definition> > </extension> >- >+ <!-- Set up a definition for HTML Comments handler --> >+ <extension point="org.eclipse.core.expressions.definitions"> >+ <definition id="org.eclipse.wst.html.ui.comments"> >+ <with variable="activeContexts"> >+ <iterate operator="or"> >+ <equals value="org.eclipse.wst.html.comments"/> >+ </iterate> >+ </with> >+ </definition> >+ </extension> >+ > <!-- Define theme - Many of the color overrides and definitions come from > the XML plugin --> > <extension >@@ -627,7 +672,36 @@ > </enabledWhen> > </handler> > </extension> >- >+ >+ <extension >+ point="org.eclipse.wst.sse.ui.commentingStrategy"> >+ <blockCommentingStrategy >+ prefix="<!--" >+ suffix="-->"> >+ <contentType >+ id="org.eclipse.wst.html.core.htmlsource" >+ associatedCommentPartitionTypeID="org.eclipse.wst.html.HTML_COMMENT"> >+ <allowablePartitionTypes >+ anyPartitionType="false"> >+ <partitionType >+ id="org.eclipse.wst.css.STYLE"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.SCRIPT.EVENTHANDLER"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.HTML_DEFAULT"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.html.HTML_DECLARATION"> >+ </partitionType> >+ <partitionType >+ id="org.eclipse.wst.xml.XML_PI"> >+ </partitionType> >+ </allowablePartitionTypes> >+ </contentType> >+ </blockCommentingStrategy> >+ </extension> > <!-- Set up a definition for HTML Content Types --> > <extension point="org.eclipse.core.expressions.definitions"> > <definition id="org.eclipse.wst.html.ui.htmlContentType.definition"> >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.html.ui/plugin.properties,v >retrieving revision 1.31 >diff -u -r1.31 plugin.properties >--- plugin.properties 26 Feb 2010 20:59:37 -0000 1.31 >+++ plugin.properties 2 Mar 2010 20:05:33 -0000 >@@ -72,6 +72,8 @@ > scope.structured.text.editor.html.description=Editing HTML Source > scope.structured.text.editor.html.occurrences.name=HTML Source Occurrences > scope.structured.text.editor.html.occurrences.description=HTML Source Occurrences >+scope.structured.text.editor.html.comments.name=HTML Source Comments >+scope.structured.text.editor.html.comments.description=HTML Source Comments > > Colors.scriptAreaBorder=Script Area Border > hyperlinkDetector.anchor.name=Anchors
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 86520
:
140629
|
140906
|
146755
|
147138
|
159026
|
159376
|
160677
|
160843
|
160936
|
160938
|
166769
|
178931