[140632] Formatting of selection
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/ActionContributorCSS.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/ActionContributorCSS.java
index d758cf6..682d92c 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/ActionContributorCSS.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/ActionContributorCSS.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2007 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
@@ -41,7 +41,6 @@
protected RetargetTextEditorAction fContentAssist = null;
protected RetargetTextEditorAction fCleanupDocument = null;
- protected MenuManager fFormatMenu = null;
protected RetargetTextEditorAction fFormatDocument = null;
protected RetargetTextEditorAction fFormatActiveElements = null;
@@ -63,10 +62,6 @@
fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
fFormatActiveElements.setActionDefinitionId(ActionDefinitionIds.FORMAT_ACTIVE_ELEMENTS);
-
- fFormatMenu = new MenuManager(CSSUIMessages.FormatMenu_label);
- fFormatMenu.add(fFormatDocument);
- fFormatMenu.add(fFormatActiveElements);
}
protected String[] getExtensionIDs() {
@@ -96,7 +91,8 @@
sourceMenu.add(fShiftRight);
sourceMenu.add(fShiftLeft);
sourceMenu.add(fCleanupDocument);
- sourceMenu.add(fFormatMenu);
+ sourceMenu.add(fFormatDocument);
+ sourceMenu.add(fFormatActiveElements);
sourceMenu.add(fCommandsSeparator);
}
}
diff --git a/bundles/org.eclipse.wst.sse.ui/plugin.properties b/bundles/org.eclipse.wst.sse.ui/plugin.properties
index ce1d043..182cc1e 100644
--- a/bundles/org.eclipse.wst.sse.ui/plugin.properties
+++ b/bundles/org.eclipse.wst.sse.ui/plugin.properties
@@ -39,8 +39,8 @@
command.remove.block.comment.description=Remove Block Comment
command.cleanup.document.name=Cleanup Document
command.cleanup.document.description=Cleanup document
-command.format.document.name=Format Document
-command.format.document.description=Format document
+command.format.document.name=Format
+command.format.document.description=Format selection
command.format.active.elements.name=Format Active Elements
command.format.active.elements.description=Format active elements
command.open.file.from.source.name=Open Selection
@@ -68,7 +68,7 @@
# These strings are used in file and container resource popup menu
##########################################################################
Source=&Source
-FormatDocument=&Format document
+FormatDocument=&Format
##
Breakpoint_Extension_Point.name=Breakpoint Extension Point
Source_Validation_Extension_Point.name=Reconcile Validator Extension Point
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java
index 6762a8e..ed3eaf8 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java
@@ -1269,14 +1269,6 @@
* Not API. May be removed in the future.
*/
public static final String GROUP_NAME_ADDITIONS = "additions"; //$NON-NLS-1$
- /**
- * Not API. May be removed in the future.
- */
- public static final String GROUP_NAME_FORMAT = "Format"; //$NON-NLS-1$
- /**
- * Not API. May be removed in the future.
- */
- public static final String GROUP_NAME_FORMAT_EXT = "Format.ext"; //$NON-NLS-1$
private static final String REDO_ACTION_DESC = SSEUIMessages.Redo___0___UI_; //$NON-NLS-1$ = "Redo: {0}."
private static final String REDO_ACTION_DESC_DEFAULT = SSEUIMessages.Redo_Text_Change__UI_; //$NON-NLS-1$ = "Redo Text Change."
@@ -1402,14 +1394,9 @@
boolean enableFormatMenu = (formatAll != null && formatAll.isEnabled()) || (formatSelection != null && formatSelection.isEnabled()) || (cleanupAll != null && cleanupAll.isEnabled());
if (getSourceViewer().isEditable() && enableFormatMenu) {
- String label = SSEUIMessages.FormatMenu_label; //$NON-NLS-1$ = "Format"
- MenuManager subMenu = new MenuManager(label, GROUP_NAME_FORMAT);
- subMenu.add(new GroupMarker(GROUP_NAME_FORMAT_EXT));
- addAction(subMenu, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT);
- addAction(subMenu, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS);
- subMenu.add(new GroupMarker(GROUP_NAME_ADDITIONS));
+ addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_DOCUMENT);
+ addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_FORMAT_ACTIVE_ELEMENTS);
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT);
- menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, subMenu);
}
// Some Design editors (DTD) rely on this view for their own uses
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java
index 5c3923d..87b555d 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIMessages.java
@@ -55,7 +55,6 @@
public static String Redo_Text_Change__UI_;
public static String _Redo__0___Ctrl_Y_UI_;
public static String Redo___0___UI_;
- public static String FormatMenu_label;
public static String Format_Document_UI_;
public static String Format_Active_Elements_UI_;
public static String Text_Cut_UI_;
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties
index 3bf5742..8b86a6b 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/SSEUIPluginResources.properties
@@ -22,8 +22,7 @@
Redo_Text_Change__UI_=Redo Text Change.
_Redo__0___Ctrl_Y_UI_=&Redo {0} @Ctrl+Y
Redo___0___UI_=Redo: {0}.
-FormatMenu_label=F&ormat
-Format_Document_UI_=Format Document
+Format_Document_UI_=Format
Format_Active_Elements_UI_=Format Active Elements
Text_Cut_UI_=Text Cut
Text_Paste_UI_=Text Paste
@@ -75,11 +74,11 @@
CleanupDocument_tooltip=Cleanup Document
CleanupDocument_image=
CleanupDocument_description=Cleanup Document
-FormatDocument_label=&Document
-FormatDocument_tooltip=Format Document
+FormatDocument_label=&Format
+FormatDocument_tooltip=Format
FormatDocument_image=
-FormatDocument_description=Format Document
-FormatActiveElements_label=Act&ive Elements
+FormatDocument_description=Format
+FormatActiveElements_label=Format Act&ive Elements
FormatActiveElements_tooltip=Format Active Elements
FormatActiveElements_image=
FormatActiveElements_description=Format Active Elements
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
index 3cf26ea..a90ded3 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
@@ -420,15 +420,28 @@
break;
case FORMAT_DOCUMENT :
try {
+ /*
+ * This command will actually format selection if text is
+ * selected, otherwise format entire document
+ */
// begin recording
beginRecording(FORMAT_DOCUMENT_TEXT, FORMAT_DOCUMENT_TEXT, cursorPosition, selectionLength);
-
- // format
- IRegion region = getModelCoverage();
+ boolean formatDocument = false;
+ IRegion region = null;
+ Point s = getSelectedRange();
+ if (s.y > 0) {
+ // only format currently selected text
+ region = new Region(s.x, s.y);
+ }
+ else {
+ // no selection, so format entire document
+ region = getModelCoverage();
+ formatDocument = true;
+ }
if (fContentFormatter instanceof IContentFormatterExtension) {
IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
IFormattingContext context = new FormattingContext();
- context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
+ context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.valueOf(formatDocument));
context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
extension.format(getDocument(), context);
}
@@ -446,13 +459,28 @@
break;
case FORMAT_ACTIVE_ELEMENTS :
try {
+ /*
+ * This command will format the node at cursor position
+ * (and all its children)
+ */
// begin recording
beginRecording(FORMAT_ACTIVE_ELEMENTS_TEXT, FORMAT_ACTIVE_ELEMENTS_TEXT, cursorPosition, selectionLength);
-
- // format
+ IRegion region = null;
Point s = getSelectedRange();
- IRegion region = new Region(s.x, s.y);
- fContentFormatter.format(getDocument(), region);
+ if (s.y > -1) {
+ // only format node at cursor position
+ region = new Region(s.x, s.y);
+ }
+ if (fContentFormatter instanceof IContentFormatterExtension) {
+ IContentFormatterExtension extension = (IContentFormatterExtension) fContentFormatter;
+ IFormattingContext context = new FormattingContext();
+ context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
+ context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
+ extension.format(getDocument(), context);
+ }
+ else {
+ fContentFormatter.format(getDocument(), region);
+ }
}
finally {
// end recording
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
index 517c392..21c3f2c 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIMessages.java
@@ -238,7 +238,6 @@
public static String Attribute____3;
public static String Data_Type____4;
public static String Enumerated_Values____5;
- public static String FormatMenu_label;
public static String SourceMenu_label;
public static String Comment_label; // Resource bundle
public static String Comment_tooltip; // Resource bundle
@@ -259,21 +258,6 @@
public static String CleanupDocument_tooltip; // Resource bundle
public static String CleanupDocument_description; // Resource bundle
public static String FindOccurrences_label; // Resource bundle
- public static String ShowTooltipDesc_label; // Resource bundle
- public static String ShowTooltipDesc_tooltip; // Resource bundle
- public static String ShowTooltipDesc_description; // Resource bundle
- public static String ContentAssistProposals_label; // Resource bundle
- public static String ContentAssistProposals_tooltip; // Resource bundle
- public static String ContentAssistProposals_description; // Resourcebundle
- public static String QuickFix_label; // Resource bundle
- public static String QuickFix_tooltip; // Resource bundle
- public static String QuickFix_description; // Resource bundle
- public static String FormatDocument_label; // Resource bundle
- public static String FormatDocument_tooltip; // Resource bundle
- public static String FormatDocument_description; // Resource bundle
- public static String FormatActiveElements_label; // Resource bundle
- public static String FormatActiveElements_tooltip; // Resource bundle
- public static String FormatActiveElements_description; // Resource bundle
public static String OpenFileFromSource_label; // Resource bundle
public static String OpenFileFromSource_tooltip; // Resource bundle
public static String OpenFileFromSource_description; // Resource bundle
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
index 73146e8..146eff3 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/XMLUIPluginResources.properties
@@ -270,7 +270,6 @@
Data_Type____4=Data Type :
Enumerated_Values____5=Enumerated Values :
## copied from sse.ui
-FormatMenu_label=F&ormat
SourceMenu_label=&Source
Comment_label=Co&mment
Comment_tooltip=Comment
@@ -291,21 +290,6 @@
CleanupDocument_tooltip=Cleanup Document
CleanupDocument_description=Cleanup Document
FindOccurrences_label=Occurrences in File
-ShowTooltipDesc_label=Show &Tooltip Description
-ShowTooltipDesc_tooltip=Displays the hover help for the selected element
-ShowTooltipDesc_description=Displays the hover help for the selected element
-ContentAssistProposals_label=Con&tent Assist
-ContentAssistProposals_tooltip=Content Assist
-ContentAssistProposals_description=Content Assist
-QuickFix_label=&Quick Fix
-QuickFix_tooltip=Quick Fix
-QuickFix_description=Quick Fix
-FormatDocument_label=&Document
-FormatDocument_tooltip=Format Document
-FormatDocument_description=Format Document
-FormatActiveElements_label=Act&ive Elements
-FormatActiveElements_tooltip=Format Active Elements
-FormatActiveElements_description=Format Active Elements
OpenFileFromSource_label=Op&en Selection
OpenFileFromSource_tooltip=Open an editor on the selected link
OpenFileFromSource_description=Open an editor on the selected link
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java
index 6590c05..08b1507 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/actions/ActionContributorXML.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * Copyright (c) 2001, 2007 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
@@ -52,7 +52,6 @@
protected RetargetTextEditorAction fFindOccurrences = null;
protected RetargetTextEditorAction fFormatActiveElements = null;
protected RetargetTextEditorAction fFormatDocument = null;
- protected MenuManager fFormatMenu = null;
protected RetargetTextEditorAction fOpenFileAction = null; // open file
protected RetargetTextEditorAction fQuickFix = null;
@@ -84,10 +83,6 @@
fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
fFormatActiveElements.setActionDefinitionId(ActionDefinitionIds.FORMAT_ACTIVE_ELEMENTS);
- fFormatMenu = new MenuManager(XMLUIMessages.FormatMenu_label);
- fFormatMenu.add(fFormatDocument);
- fFormatMenu.add(fFormatActiveElements);
-
// navigate commands
fOpenFileAction = new RetargetTextEditorAction(resourceBundle, ""); //$NON-NLS-1$
fOpenFileAction.setActionDefinitionId(ActionDefinitionIds.OPEN_FILE);
@@ -124,7 +119,8 @@
sourceMenu.add(fShiftRight);
sourceMenu.add(fShiftLeft);
sourceMenu.add(fCleanupDocument);
- sourceMenu.add(fFormatMenu);
+ sourceMenu.add(fFormatDocument);
+ sourceMenu.add(fFormatActiveElements);
sourceMenu.add(fCommandsSeparator);
sourceMenu.add(fFindOccurrences);
}