Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2004-12-03 21:13:52 +0000
committerAlain Magloire2004-12-03 21:13:52 +0000
commita71c47c4e85a1823e39fd7745a00dc56e818d08c (patch)
treed86f5644c7a502a7068b90dac33769e153024f48 /core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java
parent74269187424750d88469931377f5cad33c308199 (diff)
downloadorg.eclipse.cdt-a71c47c4e85a1823e39fd7745a00dc56e818d08c.tar.gz
org.eclipse.cdt-a71c47c4e85a1823e39fd7745a00dc56e818d08c.tar.xz
org.eclipse.cdt-a71c47c4e85a1823e39fd7745a00dc56e818d08c.zip
2004-12-03 Alain Magloire
Implement comment blocks(Code take from JDT Editor) * src/org/eclipse/cdt/internal/ui/action/AddBlockCommentAction.java * src/org/eclipse/cdt/internal/ui/action/BlockCommentAction.java * src/org/eclipse/cdt/internal/ui/action/RemoveBlockCommentAction.java * src/org/eclipse/cdt/internal/ui/editor/CEditor.java * src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties * src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java * src/org/eclipse/cdt/internal/ui/text/ CPartitionScanner.java * src/org/eclipse/cdt/internal/ui/text/CTextTools.java * src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java * src/org/eclipse/cdt/internal/ui/text/ICPartitions.java * plugin.xml
Diffstat (limited to 'core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java')
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java
new file mode 100644
index 00000000000..5733327285e
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RemoveBlockCommentAction.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.cdt.internal.ui.actions;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import org.eclipse.cdt.internal.ui.text.ICPartitions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPartitioningException;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Action that removes the enclosing comment marks from a Java block comment.
+ *
+ * @since 3.0
+ */
+public class RemoveBlockCommentAction extends BlockCommentAction {
+
+ /**
+ * Creates a new instance.
+ *
+ * @param bundle the resource bundle
+ * @param prefix a prefix to be prepended to the various resource keys
+ * (described in <code>ResourceAction</code> constructor), or
+ * <code>null</code> if none
+ * @param editor the text editor
+ */
+ public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
+ super(bundle, prefix, editor);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory)
+ */
+ protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
+ List edits= new LinkedList();
+ int tokenLength= getCommentStart().length();
+
+ int offset= selection.getOffset();
+ int endOffset= offset + selection.getLength();
+
+ ITypedRegion partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
+ int partOffset= partition.getOffset();
+ int partEndOffset= partOffset + partition.getLength();
+
+ while (partEndOffset < endOffset) {
+
+ if (partition.getType() == ICPartitions.C_MULTILINE_COMMENT) {
+ edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
+ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
+ }
+
+ partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, partEndOffset, false);
+ partOffset= partition.getOffset();
+ partEndOffset= partOffset + partition.getLength();
+ }
+
+ if (partition.getType() == ICPartitions.C_MULTILINE_COMMENT) {
+ edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
+ edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
+ }
+
+ executeEdits(edits);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
+ */
+ protected boolean isValidSelection(ITextSelection selection) {
+ return selection != null && !selection.isEmpty();
+ }
+
+
+}

Back to the top