mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 321881 - CDT editor should have selection expansion - contribution from Tomasz Wesolowski
This commit is contained in:
parent
67f3e3b559
commit
d535cea64c
14 changed files with 685 additions and 5 deletions
|
@ -12,6 +12,7 @@
|
|||
# Sergey Prigogin (Google)
|
||||
# QNX Software Systems - [272416] Rework the working set configurations
|
||||
# Axel Mueller - [289339] Surround with
|
||||
# Tomasz Wesolowski
|
||||
###############################################################################
|
||||
pluginName=C/C++ Development Tools UI
|
||||
providerName=Eclipse CDT
|
||||
|
@ -577,4 +578,12 @@ excluded-file.name = C/C++ Files Excluded from Build
|
|||
templatesViewName= Templates
|
||||
|
||||
deleteConfigsCommand.name = Reset to Default
|
||||
excludeCommand.name = Exclude from Build
|
||||
excludeCommand.name = Exclude from Build
|
||||
ActionDefinition.selectEnclosing.description = Expand the selection to enclosing C/C++ element
|
||||
ActionDefinition.selectEnclosing.name = Select Enclosing C/C++ Element
|
||||
ActionDefinition.selectNext.description = Expand the selection to next C/C++ element
|
||||
ActionDefinition.selectNext.name = Select Next C/C++ Element
|
||||
ActionDefinition.selectPrevious.description = Expand the selection to enclosing C/C++ element
|
||||
ActionDefinition.selectPrevious.name = Select Previous C/C++ Element
|
||||
ActionDefinition.selectLast.description = Restore last selection in C/C++ editor
|
||||
ActionDefinition.selectLast.name = Restore Last C/C++ Selection
|
|
@ -1628,6 +1628,79 @@
|
|||
|
||||
<!-- win32: M1=CTRL, M2=SHIFT, M3=ALT, M4=-
|
||||
carbon: M1=COMMAND, M2=SHIFT, M3=ALT, M4=CTRL -->
|
||||
|
||||
<!-- edit -->
|
||||
<key
|
||||
sequence="M2+M3+ARROW_UP"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.enclosing"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
sequence="M2+M3+ARROW_RIGHT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.next"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
sequence="M2+M3+ARROW_LEFT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.previous"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
sequence="M2+M3+ARROW_DOWN"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.last"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="M2+M3+ARROW_UP"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId=""
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="M2+M3+ARROW_RIGHT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId=""
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="M2+M3+ARROW_LEFT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId=""
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="M2+M3+ARROW_DOWN"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId=""
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="CTRL+SHIFT+ARROW_UP"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.enclosing"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="CTRL+SHIFT+ARROW_RIGHT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.next"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="CTRL+SHIFT+ARROW_LEFT"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.previous"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
<key
|
||||
platform="carbon"
|
||||
sequence="CTRL+SHIFT+ARROW_DOWN"
|
||||
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.select.last"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||
|
||||
|
||||
|
||||
<key
|
||||
sequence="M2+M3+S"
|
||||
commandId="org.eclipse.cdt.ui.edit.text.c.source.quickMenu"
|
||||
|
@ -2385,6 +2458,30 @@
|
|||
categoryId="org.eclipse.cdt.ui.category.source"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.surround.with.quickMenu">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.selectEnclosing.name"
|
||||
description="%ActionDefinition.selectEnclosing.description"
|
||||
categoryId="org.eclipse.ui.category.edit"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.select.enclosing">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.selectNext.name"
|
||||
description="%ActionDefinition.selectNext.description"
|
||||
categoryId="org.eclipse.ui.category.edit"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.select.next">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.selectPrevious.name"
|
||||
description="%ActionDefinition.selectPrevious.description"
|
||||
categoryId="org.eclipse.ui.category.edit"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.select.previous">
|
||||
</command>
|
||||
<command
|
||||
name="%ActionDefinition.selectLast.name"
|
||||
description="%ActionDefinition.selectLast.description"
|
||||
categoryId="org.eclipse.ui.category.edit"
|
||||
id="org.eclipse.cdt.ui.edit.text.c.select.last">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
id="pdomSearchPage"
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski 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:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.SelectionHistory;
|
||||
|
||||
public class StructureSelectEnclosingAction extends StructureSelectionAction {
|
||||
|
||||
public static final String PREFIX = "StructureSelectEnclosing."; //$NON-NLS-1$
|
||||
|
||||
public StructureSelectEnclosingAction(ResourceBundle bundle, ITextEditor editor, SelectionHistory history) {
|
||||
super(bundle, PREFIX, editor, history);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceRange doExpand(IASTTranslationUnit ast, SourceRange current) {
|
||||
|
||||
ISourceRange newSourceRange = expandToEnclosing(ast, current);
|
||||
if (newSourceRange != null) {
|
||||
history.remember(current);
|
||||
}
|
||||
return newSourceRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Made public to serve as fallback for other expansions
|
||||
*/
|
||||
public static ISourceRange expandToEnclosing(IASTTranslationUnit ast, SourceRange current) {
|
||||
IASTNode enclosingNode = ast.getNodeSelector(null).findEnclosingNode(current.getStartPos(),
|
||||
current.getLength());
|
||||
|
||||
int newOffset = enclosingNode.getFileLocation().getNodeOffset();
|
||||
int newLength = enclosingNode.getFileLocation().getNodeLength();
|
||||
|
||||
// we can have some nested nodes with same position, so traverse until we have a new position.
|
||||
while (newOffset == current.getStartPos() && newLength == current.getLength()) {
|
||||
IASTNode toBeSelected = enclosingNode.getParent();
|
||||
// if we can't traverse further, give up
|
||||
if (toBeSelected == null
|
||||
|| toBeSelected.getFileLocation().getFileName() != enclosingNode.getFileLocation()
|
||||
.getFileName()) {
|
||||
return null;
|
||||
}
|
||||
newOffset = toBeSelected.getFileLocation().getNodeOffset();
|
||||
newLength = toBeSelected.getFileLocation().getNodeLength();
|
||||
|
||||
enclosingNode = toBeSelected;
|
||||
}
|
||||
|
||||
return new SourceRange(newOffset, newLength);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* 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:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.SelectionHistory;
|
||||
|
||||
public class StructureSelectHistoryAction extends StructureSelectionAction {
|
||||
|
||||
public static final String PREFIX = "StructureSelectHistory."; //$NON-NLS-1$
|
||||
|
||||
public StructureSelectHistoryAction(ResourceBundle bundle, ITextEditor editor,
|
||||
SelectionHistory history) {
|
||||
super(bundle, PREFIX, editor, history);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ISourceRange doExpand(IASTTranslationUnit ast, SourceRange currentSourceRange) {
|
||||
if (!history.isEmpty()) {
|
||||
return history.getLast();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski 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:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.SelectionHistory;
|
||||
|
||||
public class StructureSelectNextAction extends StructureSelectionAction {
|
||||
|
||||
public static final String PREFIX = "StructureSelectNext."; //$NON-NLS-1$
|
||||
|
||||
public StructureSelectNextAction(ResourceBundle bundle, ITextEditor editor,
|
||||
SelectionHistory history) {
|
||||
super(bundle, PREFIX, editor, history);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceRange doExpand(IASTTranslationUnit ast, SourceRange current) {
|
||||
|
||||
ISourceRange newSourceRange = expandToNext(ast, current);
|
||||
if (newSourceRange == null) {
|
||||
newSourceRange = StructureSelectEnclosingAction.expandToEnclosing(ast, current);
|
||||
}
|
||||
if (newSourceRange != null) {
|
||||
history.remember(current);
|
||||
}
|
||||
return newSourceRange;
|
||||
}
|
||||
|
||||
private ISourceRange expandToNext(IASTTranslationUnit ast, SourceRange current) {
|
||||
|
||||
IASTNode enclosingNode = ast.getNodeSelector(null).findEnclosingNode(current.getStartPos(),
|
||||
current.getLength());
|
||||
if (samePosition(enclosingNode, current)) {
|
||||
enclosingNode = enclosingNode.getParent();
|
||||
}
|
||||
if (enclosingNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// find the last child of enclosingNode containing selection end
|
||||
|
||||
int selectionEnd = current.getStartPos()+current.getLength();
|
||||
|
||||
int lastSelectedChildIndex = -1;
|
||||
IASTNode[] children = enclosingNode.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
IASTNode node = children[i];
|
||||
if (nodeContains(node, selectionEnd)) {
|
||||
lastSelectedChildIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastSelectedChildIndex != -1 && lastSelectedChildIndex+1 < children.length) {
|
||||
IASTNode nextNode = children[lastSelectedChildIndex+1];
|
||||
int endingOffset = nextNode.getFileLocation().getNodeOffset()+nextNode.getFileLocation().getNodeLength();
|
||||
return new SourceRange(current.getStartPos(),endingOffset-current.getStartPos());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski 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:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.SelectionHistory;
|
||||
|
||||
public class StructureSelectPreviousAction extends StructureSelectionAction {
|
||||
|
||||
public static final String PREFIX = "StructureSelectPrevious."; //$NON-NLS-1$
|
||||
|
||||
public StructureSelectPreviousAction(ResourceBundle bundle, ITextEditor editor,
|
||||
SelectionHistory history) {
|
||||
super(bundle, PREFIX, editor, history);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISourceRange doExpand(IASTTranslationUnit ast, SourceRange current) {
|
||||
|
||||
ISourceRange newSourceRange = expandToPrevious(ast, current);
|
||||
if (newSourceRange == null) {
|
||||
newSourceRange = StructureSelectEnclosingAction.expandToEnclosing(ast, current);
|
||||
}
|
||||
if (newSourceRange != null) {
|
||||
history.remember(current);
|
||||
}
|
||||
return newSourceRange;
|
||||
}
|
||||
|
||||
private ISourceRange expandToPrevious(IASTTranslationUnit ast, SourceRange current) {
|
||||
|
||||
IASTNode enclosingNode = ast.getNodeSelector(null).findEnclosingNode(current.getStartPos(),
|
||||
current.getLength());
|
||||
if (samePosition(enclosingNode, current)) {
|
||||
enclosingNode = enclosingNode.getParent();
|
||||
}
|
||||
if (enclosingNode == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// find the first child of enclosingNode containing selection end
|
||||
|
||||
int selectionStart = current.getStartPos();
|
||||
|
||||
int firstSelectedChildIndex = -1;
|
||||
IASTNode[] children = enclosingNode.getChildren();
|
||||
for (int i = 0; i < children.length; i++) {
|
||||
IASTNode node = children[i];
|
||||
if (nodeContains(node, selectionStart)) {
|
||||
firstSelectedChildIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstSelectedChildIndex != -1 && firstSelectedChildIndex-1 >= 0) {
|
||||
IASTNode prevNode = children[firstSelectedChildIndex-1];
|
||||
int endingOffset = current.getStartPos() + current.getLength();
|
||||
return new SourceRange(prevNode.getFileLocation().getNodeOffset(), endingOffset - prevNode.getFileLocation().getNodeOffset());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski 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:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.TextEditorAction;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ILanguage;
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.CDTUITools;
|
||||
import org.eclipse.cdt.ui.text.SharedASTJob;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.ext.SourceRange;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.editor.SelectionHistory;
|
||||
|
||||
public abstract class StructureSelectionAction extends TextEditorAction {
|
||||
|
||||
protected final SelectionHistory history;
|
||||
|
||||
protected StructureSelectionAction(ResourceBundle bundle, String prefix, ITextEditor editor, SelectionHistory history) {
|
||||
super(bundle, prefix, editor);
|
||||
this.history = history;
|
||||
}
|
||||
|
||||
private final class ExpandSelectionJob extends SharedASTJob {
|
||||
|
||||
public ISourceRange newSourceRange;
|
||||
private SourceRange currentSourceRange;
|
||||
|
||||
private ExpandSelectionJob(String name, ITranslationUnit tUnit, CEditor cEditor, SourceRange range) {
|
||||
super(name, tUnit);
|
||||
currentSourceRange = range;
|
||||
newSourceRange = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) throws CoreException {
|
||||
newSourceRange = doExpand(ast,currentSourceRange);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String ENCLOSING = "StructureSelectEnclosing"; //$NON-NLS-1$
|
||||
public static final String NEXT = "StructureSelectNext"; //$NON-NLS-1$
|
||||
public static final String PREVIOUS = "StructureSelectPrevious"; //$NON-NLS-1$
|
||||
public static final String HISTORY = "StructureSelectHistory"; //$NON-NLS-1$
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
if (!(editorPart instanceof CEditor)) {
|
||||
return;
|
||||
}
|
||||
final CEditor cEditor = (CEditor) editorPart;
|
||||
|
||||
ITranslationUnit tu = (ITranslationUnit) CDTUITools.getEditorInputCElement(cEditor.getEditorInput());
|
||||
|
||||
ITextSelection selection;
|
||||
try {
|
||||
selection = (ITextSelection) cEditor.getSelectionProvider().getSelection();
|
||||
} catch (ClassCastException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int offset = selection.getOffset();
|
||||
final int length = selection.getLength();
|
||||
|
||||
ExpandSelectionJob expandSelectionJob = new ExpandSelectionJob("expand selection", tu, cEditor, new SourceRange(offset, length)); //$NON-NLS-1$
|
||||
|
||||
expandSelectionJob.schedule();
|
||||
try {
|
||||
expandSelectionJob.join();
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (expandSelectionJob.newSourceRange != null) {
|
||||
history.ignoreSelectionChanges();
|
||||
cEditor.setSelection(expandSelectionJob.newSourceRange, true);
|
||||
history.listenToSelectionChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract ISourceRange doExpand(IASTTranslationUnit ast, SourceRange currentSourceRange);
|
||||
|
||||
protected boolean nodeContains(IASTNode node, int position) {
|
||||
IASTFileLocation fl = node.getFileLocation();
|
||||
return (position >= fl.getNodeOffset() && position <= fl.getNodeOffset() + fl.getNodeLength());
|
||||
}
|
||||
|
||||
protected boolean samePosition(IASTNode node, SourceRange current) {
|
||||
IASTFileLocation fl = node.getFileLocation();
|
||||
return (fl.getNodeOffset() == current.getStartPos() && fl.getNodeLength() == current.getLength());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -87,10 +87,10 @@ import org.eclipse.jface.text.formatter.IFormattingContext;
|
|||
import org.eclipse.jface.text.link.ILinkedModeListener;
|
||||
import org.eclipse.jface.text.link.LinkedModeModel;
|
||||
import org.eclipse.jface.text.link.LinkedModeUI;
|
||||
import org.eclipse.jface.text.link.LinkedPosition;
|
||||
import org.eclipse.jface.text.link.LinkedPositionGroup;
|
||||
import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags;
|
||||
import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy;
|
||||
import org.eclipse.jface.text.link.LinkedPosition;
|
||||
import org.eclipse.jface.text.link.LinkedPositionGroup;
|
||||
import org.eclipse.jface.text.source.Annotation;
|
||||
import org.eclipse.jface.text.source.IAnnotationModel;
|
||||
import org.eclipse.jface.text.source.IAnnotationModelExtension;
|
||||
|
@ -198,15 +198,20 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
|
|||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.actions.AddBlockCommentAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectHistoryAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectEnclosingAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectNextAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectPreviousAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.FoldingActionGroup;
|
||||
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.IndentAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.RemoveBlockCommentAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectionAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.SurroundWithActionGroup;
|
||||
import org.eclipse.cdt.internal.ui.search.OccurrencesFinder;
|
||||
import org.eclipse.cdt.internal.ui.search.IOccurrencesFinder.OccurrenceLocation;
|
||||
import org.eclipse.cdt.internal.ui.search.OccurrencesFinder;
|
||||
import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||
import org.eclipse.cdt.internal.ui.text.CHeuristicScanner;
|
||||
import org.eclipse.cdt.internal.ui.text.CPairMatcher;
|
||||
|
@ -1304,6 +1309,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
|
||||
private CTemplatesPage fTemplatesPage;
|
||||
|
||||
private SelectionHistory fSelectionHistory;
|
||||
|
||||
private static final Set<String> angularIntroducers = new HashSet<String>();
|
||||
static {
|
||||
angularIntroducers.add("template"); //$NON-NLS-1$
|
||||
|
@ -2093,6 +2100,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
fEditorSelectionChangedListener.uninstall(getSelectionProvider());
|
||||
fEditorSelectionChangedListener = null;
|
||||
}
|
||||
|
||||
if (fSelectionHistory != null) {
|
||||
fSelectionHistory.dispose();
|
||||
fSelectionHistory = null;
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
@ -2238,6 +2250,25 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_QUICK_MACRO_EXPLORER);
|
||||
setAction("OpenMacroExplorer", action); //$NON-NLS-1$*/
|
||||
|
||||
fSelectionHistory = new SelectionHistory(this);
|
||||
|
||||
action = new StructureSelectEnclosingAction(bundle, this, fSelectionHistory);
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_ENCLOSING);
|
||||
setAction(StructureSelectionAction.ENCLOSING, action);
|
||||
|
||||
action = new StructureSelectNextAction(bundle, this, fSelectionHistory);
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_NEXT);
|
||||
setAction(StructureSelectionAction.NEXT, action);
|
||||
|
||||
action = new StructureSelectPreviousAction(bundle, this, fSelectionHistory);
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_PREVIOUS);
|
||||
setAction(StructureSelectionAction.PREVIOUS, action);
|
||||
|
||||
action = new StructureSelectHistoryAction(bundle, this, fSelectionHistory);
|
||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_LAST);
|
||||
setAction(StructureSelectionAction.HISTORY, action);
|
||||
|
||||
|
||||
// Assorted action groupings
|
||||
fSelectionSearchGroup = createSelectionSearchGroup();
|
||||
fTextSearchGroup= new TextSearchGroup(this);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
* QNX Software System
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Tomasz Wesolowski
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
|
@ -17,6 +18,7 @@ import java.util.ResourceBundle;
|
|||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
@ -31,6 +33,11 @@ import org.eclipse.ui.texteditor.RetargetTextEditorAction;
|
|||
import org.eclipse.cdt.ui.actions.CdtActionConstants;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectHistoryAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectNextAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectPreviousAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectionAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.StructureSelectEnclosingAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.FindWordAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.GoToNextPreviousMemberAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.GotoNextBookmarkAction;
|
||||
|
@ -51,6 +58,10 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
private RetargetTextEditorAction fToggleSourceHeader;
|
||||
private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction;
|
||||
private RetargetTextEditorAction fFindWord;
|
||||
private RetargetTextEditorAction fExpandSelectionToEnclosing;
|
||||
private RetargetTextEditorAction fExpandSelectionToNext;
|
||||
private RetargetTextEditorAction fExpandSelectionToPrevious;
|
||||
private RetargetTextEditorAction fExpandSelectionToHistory;
|
||||
|
||||
public CEditorActionContributor() {
|
||||
super();
|
||||
|
@ -93,6 +104,15 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
|
||||
fFindWord = new RetargetTextEditorAction(bundle, "FindWord."); //$NON-NLS-1$
|
||||
fFindWord.setActionDefinitionId(ICEditorActionDefinitionIds.FIND_WORD);
|
||||
|
||||
fExpandSelectionToEnclosing = new RetargetTextEditorAction(bundle, StructureSelectEnclosingAction.PREFIX);
|
||||
fExpandSelectionToEnclosing.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_ENCLOSING);
|
||||
fExpandSelectionToNext= new RetargetTextEditorAction(bundle, StructureSelectNextAction.PREFIX);
|
||||
fExpandSelectionToNext.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_NEXT);
|
||||
fExpandSelectionToPrevious= new RetargetTextEditorAction(bundle, StructureSelectPreviousAction.PREFIX);
|
||||
fExpandSelectionToPrevious.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_PREVIOUS);
|
||||
fExpandSelectionToHistory= new RetargetTextEditorAction(bundle, StructureSelectHistoryAction.PREFIX);
|
||||
fExpandSelectionToHistory.setActionDefinitionId(ICEditorActionDefinitionIds.SELECT_LAST);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -118,6 +138,15 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
// editMenu.appendToGroup(ITextEditorActionConstants.GROUP_GENERATE, new Separator());
|
||||
|
||||
editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction);
|
||||
|
||||
{
|
||||
MenuManager structureSelection = new MenuManager(CEditorMessages.CEditorActionContributor_ExpandSelectionMenu_label,"expandSelection"); //$NON-NLS-1$
|
||||
editMenu.insertAfter(ITextEditorActionConstants.SELECT_ALL, structureSelection);
|
||||
structureSelection.add(fExpandSelectionToEnclosing);
|
||||
structureSelection.add(fExpandSelectionToNext);
|
||||
structureSelection.add(fExpandSelectionToPrevious);
|
||||
structureSelection.add(fExpandSelectionToHistory);
|
||||
}
|
||||
}
|
||||
|
||||
IMenuManager navigateMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_NAVIGATE);
|
||||
|
@ -135,7 +164,6 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
gotoMenu.appendToGroup("additions2", fGotoNextBookmark); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,6 +211,11 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
fToggleSourceHeader.setAction(getAction(textEditor, "ToggleSourceHeader")); //$NON-NLS-1$
|
||||
fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE));
|
||||
fFindWord.setAction(getAction(textEditor, FindWordAction.FIND_WORD));
|
||||
|
||||
fExpandSelectionToEnclosing.setAction(getAction(textEditor, StructureSelectionAction.ENCLOSING));
|
||||
fExpandSelectionToNext.setAction(getAction(textEditor, StructureSelectionAction.NEXT));
|
||||
fExpandSelectionToPrevious.setAction(getAction(textEditor, StructureSelectionAction.PREVIOUS));
|
||||
fExpandSelectionToHistory.setAction(getAction(textEditor, StructureSelectionAction.HISTORY));
|
||||
|
||||
// Source menu.
|
||||
IActionBars bars= getActionBars();
|
||||
|
|
|
@ -95,6 +95,7 @@ public final class CEditorMessages extends NLS {
|
|||
public static String SemanticHighlighting_problem;
|
||||
public static String SemanticHighlighting_externalSDK;
|
||||
public static String CEditor_markOccurrences_job_name;
|
||||
public static String CEditorActionContributor_ExpandSelectionMenu_label;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(CEditorMessages.class.getName(), CEditorMessages.class);
|
||||
|
|
|
@ -92,3 +92,4 @@ SemanticHighlighting_problem= Problems
|
|||
SemanticHighlighting_externalSDK= External SDK calls
|
||||
|
||||
CEditor_markOccurrences_job_name= Occurrences Marker
|
||||
CEditorActionContributor_ExpandSelectionMenu_label=E&xpand Selection To
|
||||
|
|
|
@ -133,6 +133,22 @@ CSelectAnnotationRulerAction.GotoAnnotation.tooltip= Go to Annotation
|
|||
CSelectAnnotationRulerAction.GotoAnnotation.description= Selects the annotation in the editor
|
||||
CSelectAnnotationRulerAction.GotoAnnotation.image=
|
||||
|
||||
StructureSelectNext.label=&Next Element
|
||||
StructureSelectNext.tooltip=Expand Selection to Include Next Sibling
|
||||
StructureSelectNext.description=Expand selection to include next sibling
|
||||
|
||||
StructureSelectPrevious.label=&Previous Element
|
||||
StructureSelectPrevious.tooltip=Expand Selection to Include Previous Sibling
|
||||
StructureSelectPrevious.description=Expand selection to include previous sibling
|
||||
|
||||
StructureSelectEnclosing.label=&Enclosing Element
|
||||
StructureSelectEnclosing.tooltip=Expand Selection to Include Enclosing Element
|
||||
StructureSelectEnclosing.description=Expand selection to include enclosing element
|
||||
|
||||
StructureSelectHistory.label=&Restore Last Selection
|
||||
StructureSelectHistory.tooltip=Restore Last Selection
|
||||
StructureSelectHistory.description=Restore last selection
|
||||
|
||||
CSelectAnnotationRulerAction.OpenSuperImplementation.label= &Open Super Implementation
|
||||
CSelectAnnotationRulerAction.OpenSuperImplementation.tooltip= Open Super Implementation
|
||||
CSelectAnnotationRulerAction.OpenSuperImplementation.description= Opens the super implementation
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* Markus Schorn (Wind River Systems)
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Sergey Prigogin (Google)
|
||||
* Tomasz Wesolowski
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
@ -247,4 +248,28 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
* @since 5.2
|
||||
*/
|
||||
public static final String SORT_LINES = "org.eclipse.cdt.ui.edit.text.c.sort.lines"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the edit -> select enclosing action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.select.enclosing"</code>).
|
||||
*/
|
||||
public static final String SELECT_ENCLOSING = "org.eclipse.cdt.ui.edit.text.c.select.enclosing"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the edit -> select next action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.select.next"</code>).
|
||||
*/
|
||||
public static final String SELECT_NEXT = "org.eclipse.cdt.ui.edit.text.c.select.next"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the edit -> select previous action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.select.previous"</code>).
|
||||
*/
|
||||
public static final String SELECT_PREVIOUS = "org.eclipse.cdt.ui.edit.text.c.select.previous"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the edit -> select restore last action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.select.last"</code>).
|
||||
*/
|
||||
public static final String SELECT_LAST = "org.eclipse.cdt.ui.edit.text.c.select.last"; //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 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 (JDT)
|
||||
* Tomasz Wesolowski - port from JDT
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
|
||||
import org.eclipse.cdt.core.model.ISourceRange;
|
||||
|
||||
public class SelectionHistory {
|
||||
|
||||
private Stack<ISourceRange> fHistory;
|
||||
private CEditor fEditor;
|
||||
private ISelectionChangedListener fSelectionListener;
|
||||
private int fSelectionChangeListenerCounter;
|
||||
|
||||
public SelectionHistory(CEditor editor) {
|
||||
Assert.isNotNull(editor);
|
||||
fEditor= editor;
|
||||
fHistory= new Stack<ISourceRange>();
|
||||
fSelectionListener= new ISelectionChangedListener() {
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
if (fSelectionChangeListenerCounter == 0)
|
||||
flush();
|
||||
}
|
||||
};
|
||||
fEditor.getSelectionProvider().addSelectionChangedListener(fSelectionListener);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return fHistory.isEmpty();
|
||||
}
|
||||
|
||||
public void remember(ISourceRange range) {
|
||||
fHistory.push(range);
|
||||
}
|
||||
|
||||
public ISourceRange getLast() {
|
||||
if (isEmpty())
|
||||
return null;
|
||||
ISourceRange result= fHistory.pop();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
if (fHistory.isEmpty())
|
||||
return;
|
||||
fHistory.clear();
|
||||
}
|
||||
|
||||
public void ignoreSelectionChanges() {
|
||||
fSelectionChangeListenerCounter++;
|
||||
}
|
||||
|
||||
public void listenToSelectionChanges() {
|
||||
fSelectionChangeListenerCounter--;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
fEditor.getSelectionProvider().removeSelectionChangedListener(fSelectionListener);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue