+ * The selection offset is model based. + *
+ * + * @param sourceViewer the source viewer + * @return a region denoting the current signed selection, for a resulting RtoL selections length is < 0 + */ + protected IRegion getSignedSelection(ISourceViewer sourceViewer) { + StyledText text= sourceViewer.getTextWidget(); + Point selection= text.getSelectionRange(); + + if (text.getCaretOffset() == selection.x) { + selection.x= selection.x + selection.y; + selection.y= -selection.y; + } + + selection.x= widgetOffset2ModelOffset(sourceViewer, selection.x); + + return new Region(selection.x, selection.y); + } + + private static boolean isBracket(char character) { + for (int i= 0; i != BRACKETS.length; ++i) + if (character == BRACKETS[i]) + return true; + return false; + } + + private static boolean isSurroundedByBrackets(IDocument document, int offset) { + if (offset == 0 || offset == document.getLength()) + return false; + + try { + return + isBracket(document.getChar(offset - 1)) && + isBracket(document.getChar(offset)); + + } catch (BadLocationException e) { + return false; + } + } + + /* (non-Javadoc) * @see org.eclipse.cdt.internal.ui.editor.IReconcilingParticipant#reconciled() */ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/GotoMatchingBracketAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/GotoMatchingBracketAction.java new file mode 100644 index 00000000000..a7380dedede --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/GotoMatchingBracketAction.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * 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.editor; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.text.Assert; + +import org.eclipse.ui.PlatformUI; + +import org.eclipse.cdt.internal.ui.ICHelpContextIds; + + +public class GotoMatchingBracketAction extends Action { + + public final static String GOTO_MATCHING_BRACKET= "GotoMatchingBracket"; //$NON-NLS-1$ + + private final CEditor fEditor; + + public GotoMatchingBracketAction(CEditor editor) { + super(CEditorMessages.getString("GotoMatchingBracket.label")); //$NON-NLS-1$ + Assert.isNotNull(editor); + fEditor= editor; + setEnabled(true); + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ICHelpContextIds.GOTO_MATCHING_BRACKET_ACTION); + } + + public void run() { + fEditor.gotoMatchingBracket(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java index 2fbbdedbae1..266e06fefed 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ICEditorActionDefinitionIds.java @@ -130,4 +130,13 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition * (value"org.eclipse.cdt.ui.edit.text.c.goto.prev.memeber"
)
*/
public static final String GOTO_PREVIOUS_MEMBER = "org.eclipse.cdt.ui.edit.text.c.goto.prev.member"; //$NON-NLS-1$
+
+ /**
+ * Action definition ID of the edit -> go to matching bracket action
+ * (value "org.eclipse.cdt.ui.edit.text.c.goto.matching.bracket"
).
+ *
+ * @since 3.0
+ */
+ public static final String GOTO_MATCHING_BRACKET= "org.eclipse.cdt.ui.edit.text.c.goto.matching.bracket"; //$NON-NLS-1$
+
}