### Eclipse Workspace Patch 1.0 #P org.eclipse.wst.sse.ui Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF,v retrieving revision 1.29 diff -u -r1.29 MANIFEST.MF --- META-INF/MANIFEST.MF 30 Oct 2007 22:40:59 -0000 1.29 +++ META-INF/MANIFEST.MF 19 Dec 2007 02:18:26 -0000 @@ -55,6 +55,7 @@ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.wst.validation;bundle-version="[1.1.0,1.2.0)", org.eclipse.emf.common;bundle-version="[2.2.0,3.0.0)", - com.ibm.icu;bundle-version="[3.4.4,4.0.0)" + com.ibm.icu;bundle-version="[3.4.4,4.0.0)", + org.eclipse.core.expressions;bundle-version="3.3.100" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/plugin.xml,v retrieving revision 1.44 diff -u -r1.44 plugin.xml --- plugin.xml 15 Oct 2007 17:39:51 -0000 1.44 +++ plugin.xml 19 Dec 2007 02:18:25 -0000 @@ -2,68 +2,42 @@ - - - - + + + + - + - - + + - - - + + - - - + + - - + + - + - - - - + + + + - - - + + - - + + - - - - - - + + + + - + @@ -119,269 +82,154 @@ --> - - - + + - - - + + - - - - - - - - + - - + - + - - + - - - - - - - - - - - + - - %sourceEditorFontDefintion.description - + %sourceEditorFontDefintion.description - - + + - - + - - - - - + - + - + - - + + + + - - + - + - + + + + + + + + + + + + + + + + Index: src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java,v retrieving revision 1.5 diff -u -r1.5 ActionContributor.java --- src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java 8 Nov 2006 21:02:43 -0000 1.5 +++ src/org/eclipse/wst/sse/ui/internal/actions/ActionContributor.java 19 Dec 2007 02:18:28 -0000 @@ -12,11 +12,11 @@ *******************************************************************************/ package org.eclipse.wst.sse.ui.internal.actions; -import java.util.ResourceBundle; +//import java.util.ResourceBundle; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IAction; +//import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.action.IToolBarManager; @@ -24,21 +24,21 @@ import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; +//import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.actions.ActionFactory; +//import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.editors.text.TextEditorActionContributor; -import org.eclipse.ui.ide.IDEActionFactory; +//import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; -import org.eclipse.ui.texteditor.ITextEditorExtension; +//import org.eclipse.ui.texteditor.ITextEditorActionConstants; +//import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +//import org.eclipse.ui.texteditor.ITextEditorExtension; import org.eclipse.ui.texteditor.RetargetTextEditorAction; -import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder; +//import org.eclipse.wst.sse.ui.internal.ExtendedEditorActionBuilder; import org.eclipse.wst.sse.ui.internal.GotoAnnotationAction; import org.eclipse.wst.sse.ui.internal.IExtendedContributor; import org.eclipse.wst.sse.ui.internal.ISourceViewerActionBarContributor; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +//import org.eclipse.wst.sse.ui.internal.SSEUIMessages; import org.eclipse.wst.sse.ui.internal.ui.OffsetStatusLineContributionItem; /** @@ -85,7 +85,7 @@ public ActionContributor() { super(); - ResourceBundle resourceBundle = SSEUIMessages.getResourceBundle(); +/* ResourceBundle resourceBundle = SSEUIMessages.getResourceBundle(); fCommandsSeparator = new Separator(); @@ -146,11 +146,11 @@ if (_showDebugStatus) { fDebugStatusOffset = new OffsetStatusLineContributionItem(StructuredTextEditorActionConstants.STATUS_CATEGORY_OFFSET, true, 20); } - } +*/ } protected void addToMenu(IMenuManager menu) { // edit commands - IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); +/* IMenuManager editMenu = menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); if (editMenu != null) { editMenu.add(fCommandsSeparator); editMenu.add(fToggleInsertModeAction); @@ -159,7 +159,7 @@ editMenu.add(fCommandsSeparator); editMenu.add(fMenuAdditionsGroupMarker); } - + // source commands String sourceMenuLabel = SSEUIMessages.SourceMenu_label; //$NON-NLS-1$ String sourceMenuId = "sourceMenuId"; // This is just a menu id. No //$NON-NLS-1$ @@ -175,7 +175,7 @@ sourceMenu.add(fShiftRight); sourceMenu.add(fShiftLeft); } - } +*/ } protected void addToPopupMenu(IMenuManager menu) { // add nothing @@ -188,22 +188,22 @@ } protected void addToToolBar(IToolBarManager toolBarManager) { - toolBarManager.add(fToolbarSeparator); +/* toolBarManager.add(fToolbarSeparator); toolBarManager.add(fToolbarAdditionsGroupMarker); - } +*/ } /** * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToMenu(IMenuManager) */ public void contributeToMenu(IMenuManager menu) { super.contributeToMenu(menu); - +/* addToMenu(menu); if (extendedContributor != null) { extendedContributor.contributeToMenu(menu); } - } +*/ } /* * (non-Javadoc) @@ -212,12 +212,12 @@ */ public void contributeToPopupMenu(IMenuManager menu) { - addToPopupMenu(menu); +/* addToPopupMenu(menu); if (extendedContributor != null) { extendedContributor.contributeToPopupMenu(menu); } - } +*/ } /* * (non-Javadoc) @@ -240,12 +240,12 @@ public void contributeToToolBar(IToolBarManager toolBarManager) { super.contributeToToolBar(toolBarManager); - addToToolBar(toolBarManager); +/* addToToolBar(toolBarManager); if (extendedContributor != null) { extendedContributor.contributeToToolBar(toolBarManager); } - } +*/ } /** * @see org.eclipse.ui.part.EditorActionBarContributor#dispose() @@ -300,9 +300,9 @@ return; super.setActiveEditor(activeEditor); - ITextEditor textEditor = getTextEditor(activeEditor); +// ITextEditor textEditor = getTextEditor(activeEditor); - IActionBars actionBars = getActionBars(); +/* IActionBars actionBars = getActionBars(); if (actionBars != null) { actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, fNextAnnotation); actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, fPreviousAnnotation); @@ -342,7 +342,7 @@ ((ITextEditorExtension) textEditor).setStatusField(fDebugStatusOffset, StructuredTextEditorActionConstants.STATUS_CATEGORY_OFFSET); fDebugStatusOffset.setActiveEditor(textEditor); } - } +*/ } /* * (non-Javadoc) @@ -350,19 +350,19 @@ * @see org.eclipse.wst.sse.ui.ISourceViewerActionBarContributor#setViewerSpecificContributionsEnabled(boolean) */ public void setViewerSpecificContributionsEnabled(boolean enabled) { - fShiftRight.setEnabled(enabled); +/* fShiftRight.setEnabled(enabled); fShiftLeft.setEnabled(enabled); fNextAnnotation.setEnabled(enabled); fPreviousAnnotation.setEnabled(enabled); - /* + * fComment.setEnabled(enabled); fUncomment.setEnabled(enabled); - */ + fToggleComment.setEnabled(enabled); fAddBlockComment.setEnabled(enabled); fRemoveBlockComment.setEnabled(enabled); // convert line delimiters are not source viewer-specific - } +*/ } /* * (non-Javadoc) @@ -370,8 +370,8 @@ * @see org.eclipse.wst.sse.ui.extension.IExtendedContributor#updateToolbarActions() */ public void updateToolbarActions() { - if (extendedContributor != null) { +/* if (extendedContributor != null) { extendedContributor.updateToolbarActions(); } - } +*/ } } Index: src/org/eclipse/wst/sse/ui/StructuredTextEditor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java,v retrieving revision 1.85 diff -u -r1.85 StructuredTextEditor.java --- src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 3 Dec 2007 18:45:58 -0000 1.85 +++ src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 19 Dec 2007 02:18:28 -0000 @@ -105,6 +105,8 @@ import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +//import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.editors.text.EditorsUI; import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; import org.eclipse.ui.editors.text.TextEditor; @@ -1509,6 +1511,10 @@ * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { + + IContextService contextService = (IContextService) getSite().getService(IContextService.class); + contextService.activateContext("org.eclipse.wst.sse.ui.structuredTextEditorScope"); + if (getSourceViewerConfiguration() == null) { ConfigurationAndTarget cat = createSourceViewerConfiguration(); fViewerConfigurationTargetId = cat.getTargetId(); #P org.eclipse.wst.xml.ui Index: src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java,v retrieving revision 1.3 diff -u -r1.3 AbstractCommentActionXMLDelegate.java --- src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java 10 Apr 2007 20:04:55 -0000 1.3 +++ src/org/eclipse/wst/xml/ui/internal/actions/AbstractCommentActionXMLDelegate.java 19 Dec 2007 02:18:30 -0000 @@ -74,7 +74,7 @@ // do nothing } - private ITextSelection getCurrentSelection() { + ITextSelection getCurrentSelection() { if (fEditor instanceof ITextEditor) { ISelectionProvider provider = ((ITextEditor) fEditor).getSelectionProvider(); if (provider != null) { Index: src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java,v retrieving revision 1.5 diff -u -r1.5 CleanupActionXMLDelegate.java --- src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java 10 Apr 2007 20:04:55 -0000 1.5 +++ src/org/eclipse/wst/xml/ui/internal/actions/CleanupActionXMLDelegate.java 19 Dec 2007 02:18:30 -0000 @@ -34,6 +34,7 @@ /** * Cleanup action delegate for CSS editor + * @deprecated */ public class CleanupActionXMLDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate { private IEditorPart fEditor; Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/META-INF/MANIFEST.MF,v retrieving revision 1.27 diff -u -r1.27 MANIFEST.MF --- META-INF/MANIFEST.MF 30 Oct 2007 22:42:35 -0000 1.27 +++ META-INF/MANIFEST.MF 19 Dec 2007 02:18:30 -0000 @@ -21,6 +21,7 @@ org.eclipse.wst.xml.ui.internal.dnd;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", org.eclipse.wst.xml.ui.internal.doubleclick;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", org.eclipse.wst.xml.ui.internal.editor;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", + org.eclipse.wst.xml.ui.internal.handlers;x-internal:=true, org.eclipse.wst.xml.ui.internal.hyperlink;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", org.eclipse.wst.xml.ui.internal.nsedit;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", org.eclipse.wst.xml.ui.internal.preferences;x-friends:="org.eclipse.wst.xsd.ui,org.eclipse.wst.dtd.ui", @@ -54,6 +55,7 @@ org.eclipse.wst.xml.core;bundle-version="[1.1.0,1.2.0)", org.eclipse.wst.common.ui;bundle-version="[1.1.0,1.2.0)", org.eclipse.wst.validation;bundle-version="[1.1.0,1.2.0)", - com.ibm.icu;bundle-version="[3.4.4,4.0.0)" + com.ibm.icu;bundle-version="[3.4.4,4.0.0)", + org.eclipse.core.expressions;bundle-version="3.3.100" Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.4 Index: src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java,v retrieving revision 1.16 diff -u -r1.16 XMLTableTreeActionBarContributor.java --- src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java 10 Apr 2007 20:04:57 -0000 1.16 +++ src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeActionBarContributor.java 19 Dec 2007 02:18:30 -0000 @@ -14,14 +14,14 @@ import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IContributionManager; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; +//import org.eclipse.jface.action.IToolBarManager; +//import org.eclipse.jface.action.MenuManager; +//import org.eclipse.jface.action.Separator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.IWorkbenchActionConstants; +//import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.texteditor.ITextEditor; @@ -62,7 +62,7 @@ } protected void removeContributions(IContributionManager manager) { - try { +/* try { doRemove(manager, DESIGN_VIEWER_SEPARATOR_1_ID); doRemove(manager, DESIGN_VIEWER_SEPARATOR_2_ID); doRemove(manager, VALIDATE_XML_ID); @@ -73,16 +73,16 @@ } catch (Exception e) { } - } +*/ } protected void doRemove(IContributionManager manager, String id) { - try { - if (manager.find(id) != null) { - manager.remove(id); - } - } - catch (Exception e) { - } +// try { +// if (manager.find(id) != null) { +// manager.remove(id); +// } +// } +// catch (Exception e) { +// } } public void init(IActionBars bars, IWorkbenchPage page) { @@ -90,9 +90,9 @@ } public void init(IActionBars bars) { - IToolBarManager tbm = bars.getToolBarManager(); +// IToolBarManager tbm = bars.getToolBarManager(); - IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ +/* IMenuManager xmlMenu = bars.getMenuManager().findMenuUsingPath("org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ if (xmlMenu == null) { xmlMenu = new MenuManager(XMLEditorMessages.XMLTableTreeActionBarContributor_0, "org.eclipse.core.runtime.xml.design.xmlmenu"); //$NON-NLS-1$ @@ -103,7 +103,7 @@ } tbm.add(new Separator("DESIGN_VIEWER_SEPARATOR_1_ID")); //$NON-NLS-1$ - +*/ // ValidateXMLAction // // ugly hack ... we don't contribute the generic XML validator if we @@ -119,23 +119,23 @@ // ToggleEditModeAction // - toggleAction = new ToggleEditModeAction(); +/* toggleAction = new ToggleEditModeAction(); toggleAction.setId(TOGGLE_EDIT_MODE_ID); xmlMenu.add(toggleAction); tbm.add(toggleAction); - +*/ // ReloadGrammarAction // - reloadGrammarAction = new ReloadGrammarAction(); +/* reloadGrammarAction = new ReloadGrammarAction(); reloadGrammarAction.setId(RELOAD_GRAMMAR_ID); tbm.add(reloadGrammarAction); xmlMenu.add(reloadGrammarAction); xmlMenu.add(new Separator()); - +*/ // ExpandCollapseAction // - xmlMenuExpandAction = new ViewerExpandCollapseAction(true); +/* xmlMenuExpandAction = new ViewerExpandCollapseAction(true); xmlMenuExpandAction.setId(EXPAND_ALL_ID); xmlMenuExpandAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_1); xmlMenu.add(xmlMenuExpandAction); @@ -145,7 +145,7 @@ xmlMenuCollapseAction.setId(EXPAND_ALL_ID); xmlMenuCollapseAction.setText(XMLEditorMessages.XMLTableTreeActionBarContributor_2); xmlMenu.add(xmlMenuCollapseAction); - } +*/ } protected void addActionWithId(IMenuManager menuManager, Action action, String id) { action.setId(id); @@ -153,7 +153,7 @@ } public void initViewerSpecificContributions(IActionBars bars) { - IToolBarManager tbm = bars.getToolBarManager(); +/* IToolBarManager tbm = bars.getToolBarManager(); tbm.add(new Separator(DESIGN_VIEWER_SEPARATOR_2_ID)); expandAction = new ViewerExpandCollapseAction(true); @@ -163,10 +163,10 @@ collapseAction = new ViewerExpandCollapseAction(false); collapseAction.setId(COLLAPSE_ALL_ID); tbm.add(collapseAction); - } +*/ } public void setViewerSpecificContributionsEnabled(boolean enabled) { - if (expandAction != null) { +/* if (expandAction != null) { expandAction.setEnabled(enabled); xmlMenuExpandAction.setEnabled(enabled); } @@ -175,16 +175,16 @@ collapseAction.setEnabled(enabled); xmlMenuCollapseAction.setEnabled(enabled); } - } +*/ } public void setActiveEditor(IEditorPart targetEditor) { editorPart = targetEditor; - IStructuredModel model = getModelForEditorPart(targetEditor); - reloadGrammarAction.setModel(model); +// IStructuredModel model = getModelForEditorPart(targetEditor); +/* reloadGrammarAction.setModel(model); toggleAction.setModelQuery(ModelQueryUtil.getModelQuery(model)); - - XMLTableTreeViewer tableTreeViewer = getTableTreeViewerForEditorPart(editorPart); +*/ +/* XMLTableTreeViewer tableTreeViewer = getTableTreeViewerForEditorPart(editorPart); if (tableTreeViewer != null) { expandAction.setViewer(tableTreeViewer); collapseAction.setViewer(tableTreeViewer); @@ -192,7 +192,7 @@ xmlMenuExpandAction.setViewer(tableTreeViewer); xmlMenuCollapseAction.setViewer(tableTreeViewer); } - +*/ if (editorPart instanceof XMLMultiPageEditorPart) { IWorkbenchPartSite site = editorPart.getSite(); if (site instanceof IEditorSite) { Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.xml,v retrieving revision 1.74 diff -u -r1.74 plugin.xml --- plugin.xml 18 Dec 2007 03:51:15 -0000 1.74 +++ plugin.xml 19 Dec 2007 02:18:29 -0000 @@ -1,589 +1,606 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %_UI_CREATE_NEW_XML_FILE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %XMLExampleProjectCreationWizard.description - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - %_UI_IMPORT_XML_CATALOG_FILE - - - - - - - - - %_UI_EXPORT_XML_CATALOG_FILE - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %_UI_CREATE_NEW_XML_FILE + + + + + + + + + + + + + + + + + + + + + + + %XMLExampleProjectCreationWizard.description + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ReloadDependenciesHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,66 @@ +/** + * + */ +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.ui.IEditorPart; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; +import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader; +import org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader; +import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; +import org.w3c.dom.Document; + +/** + * @author dcarver + * + */ +public class ReloadDependenciesHandler extends AbstractHandler implements + IHandler { + protected IStructuredModel model; + + /** + * + */ + public ReloadDependenciesHandler() { + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IEditorPart fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + StructuredTextEditor textEditor = (StructuredTextEditor) fEditor.getAdapter(ITextEditor.class); + model = (textEditor != null) ? textEditor.getModel() : null; + } + + if (model != null) { + ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model); + Document document = ((IDOMModel) model).getDocument(); + if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) { + modelQuery.getCMDocumentManager().getCMDocumentCache().clear(); + // TODO... need to figure out how to access the + // DOMObserver via ModelQuery + // ...why? + CMDocumentLoader loader = new InferredGrammarBuildingCMDocumentLoader(document, modelQuery); + loader.loadCMDocuments(); + } + } + return null; + } + + + +} 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/RemoveBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,75 @@ +/** + * + */ +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.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(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/CleanupdocumentHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/CleanupdocumentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2007 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 - + * Based off CleanupActionXMLDelegate + *******************************************************************************/ + +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.dialogs.Dialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.custom.BusyIndicator; +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.cleanup.IStructuredCleanupProcessor; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +import org.eclipse.wst.xml.core.internal.cleanup.CleanupProcessorXML; +import org.eclipse.wst.xml.ui.internal.actions.CleanupDialogXML; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class CleanupdocumentHandler extends AbstractHandler implements IHandler { + + private IEditorPart fEditor; + private IStructuredCleanupProcessor fCleanupProcessor; + + public void dispose() { + // nulling out just in case + fEditor = null; + fCleanupProcessor = null; + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor editor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell()); + if (cleanupDialog.open() == Window.OK) { + // setup runnable + Runnable runnable = new Runnable() { + public void run() { + IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor(); + if (cleanupProcessor != null) { + IStructuredModel model = null; + try { + model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); + if (model != null) { + cleanupProcessor.cleanupModel(model); + } + } + finally { + if (model != null) { + model.releaseFromEdit(); + } + } + } + } + }; + + // TODO: make independent of 'model'. + IStructuredModel model = null; + try { + model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput())); + if (model != null) { + // begin recording + ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); + model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); + + // tell the model that we are about to make a big + // model change + model.aboutToChangeModel(); + + // run + BusyIndicator.showWhile(fEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable); + } + } + finally { + if (model != null) { + // tell the model that we are done with the big + // model + // change + model.changedModel(); + + // end recording + ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); + model.endRecording(this, selection.getOffset(), selection.getLength()); + model.releaseFromEdit(); + } + } + } + } + + return null; + } + + IStructuredCleanupProcessor getCleanupProcessor() { + if (fCleanupProcessor == null) { + fCleanupProcessor = new CleanupProcessorXML(); + } + + return fCleanupProcessor; + } +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ToggleEditModeHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,30 @@ +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.resource.ImageDescriptor; +//import org.eclipse.ui.commands.ICommand; +import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery; +//import org.eclipse.wst.xml.ui.internal.tabletree.XMLEditorMessages; +import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper; + +public class ToggleEditModeHandler extends AbstractHandler implements IHandler { + protected ImageDescriptor onImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINON); + protected ImageDescriptor offImage = SharedXMLEditorPluginImageHelper.getImageDescriptor(SharedXMLEditorPluginImageHelper.IMG_ETOOL_CONSTRAINOFF); + protected ModelQuery modelQuery; + + public ToggleEditModeHandler() { + super(); + } + + public Object execute(ExecutionEvent arg0) throws ExecutionException { + // TODO Auto-generated method stub + return null; + } + + // TODO Add in ability to change command enablement and icons for this handler. + + +} Index: src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java =================================================================== RCS file: src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java diff -N src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/XMLFindOccurencesHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2007 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 - + * Based off CleanupActionXMLDelegate + *******************************************************************************/ + +package org.eclipse.wst.xml.ui.internal.handlers; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +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.core.resources.IFile; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITypedRegion; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.wst.sse.ui.internal.SSEUIMessages; +import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor; +import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil; +import org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class XMLFindOccurencesHandler extends AbstractHandler implements IHandler { + + private IEditorPart fEditor; + private List fProcessors; + + public void dispose() { + // nulling out just in case + fEditor = null; + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + fEditor = HandlerUtil.getActiveEditor(event); + boolean okay = false; + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor textEditor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); + if (document != null) { + ITextSelection textSelection = getTextSelection(textEditor); + FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection); + if (findOccurrenceProcessor != null) { + if (textEditor.getEditorInput() instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile(); + okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file); + } + } + } + } + if (okay) { + // clear status message + PlatformStatusLineUtil.clearStatusLine(); + } + else { + String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0; //$NON-NLS-1$ + PlatformStatusLineUtil.displayErrorMessage(errorMessage); + PlatformStatusLineUtil.addOneTimeClearListener(); + } + + return null; + } + + /** + * Get the appropriate find occurrences processor + * + * @param document - + * assumes not null + * @param textSelection + * @return + */ + private FindOccurrencesProcessor getProcessorForCurrentSelection(IDocument document, ITextSelection textSelection) { + // check if we have an action that's enabled on the current partition + ITypedRegion tr = getPartition(document, textSelection); + String partition = tr != null ? tr.getType() : ""; //$NON-NLS-1$ + + Iterator it = getProcessors().iterator(); + FindOccurrencesProcessor action = null; + while (it.hasNext()) { + action = (FindOccurrencesProcessor) it.next(); + // we just choose the first action that can handle the partition + if (action.enabledForParitition(partition)) + return action; + } + return null; + } + + private ITypedRegion getPartition(IDocument document, ITextSelection textSelection) { + ITypedRegion region = null; + if (textSelection != null) { + try { + region = document.getPartition(textSelection.getOffset()); + } + catch (BadLocationException e) { + region = null; + } + } + return region; + } + + private ITextSelection getTextSelection(ITextEditor textEditor) { + ITextSelection textSelection = null; + ISelection selection = textEditor.getSelectionProvider().getSelection(); + if (selection instanceof ITextSelection && !selection.isEmpty()) { + textSelection = (ITextSelection) selection; + } + return textSelection; + } + + protected List getProcessors() { + if (fProcessors == null) { + fProcessors = new ArrayList(); + XMLFindOccurrencesProcessor htmlProcessor = new XMLFindOccurrencesProcessor(); + fProcessors.add(htmlProcessor); + } + return fProcessors; + } + + +} 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/AddBlockCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,76 @@ +/** + * + */ +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.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 AddBlockCommentHandler extends CommentHandler implements IHandler { + + public AddBlockCommentHandler() { + super(); + } + + void processAction(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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/ToggleCommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,182 @@ +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.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; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class ToggleCommentHandler extends CommentHandler implements IHandler { + + public ToggleCommentHandler() { + // TODO Auto-generated constructor stub + super(); + } + + public Object execute(ExecutionEvent event) throws ExecutionException { + + fEditor = HandlerUtil.getActiveEditor(event); + + if (fEditor instanceof XMLMultiPageEditorPart) { + final ITextEditor textEditor = (ITextEditor) fEditor.getAdapter(ITextEditor.class); + fEditor = textEditor; + IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); + if (document != null) { + // get current text selection + ITextSelection textSelection = getCurrentSelection(); + if (textSelection.isEmpty()) { + return null; + } + + processAction(document, textSelection); + } + } + return null; + } + + void processAction(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(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(Position selectionPosition, IDocument document, boolean updateStartOffset) { + if (fEditor instanceof ITextEditor) { + // 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 = ((ITextEditor) fEditor).getSelectionProvider(); + if (provider != null) { + provider.setSelection(selection); + } + document.removePosition(selectionPosition); + } + } + } +} 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/wst/xml/ui/internal/handlers/CommentHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,97 @@ +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; +import org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart; + +public class CommentHandler extends AbstractHandler implements IHandler { + + + static final String CLOSE_COMMENT = "-->"; //$NON-NLS-1$ + static final String OPEN_COMMENT = "