mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
2004-09-03 Alain Magloire
Provide key binding for AddInclude action * src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java * src/org/eclipse/cdt/internal/ui/editor/CEditor.java * src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties * plugin.xml * plugin.properties
This commit is contained in:
parent
dee933ea8c
commit
6fc219f9cc
8 changed files with 129 additions and 125 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2004-09-03 Alain Magloire
|
||||||
|
|
||||||
|
Provide key binding for AddInclude action
|
||||||
|
* src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/editor/CEditor.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/editor/CEditorMessages.properties
|
||||||
|
* plugin.xml
|
||||||
|
* plugin.properties
|
||||||
|
|
||||||
2004-09-02 Alain Magloire
|
2004-09-02 Alain Magloire
|
||||||
|
|
||||||
Deal with WorkingCopy vs TranslationUnit in the hashCode.
|
Deal with WorkingCopy vs TranslationUnit in the hashCode.
|
||||||
|
|
|
@ -134,6 +134,10 @@ OpenTypeAction.tooltip= Open Type
|
||||||
ActionDefinition.openType.name= Open Type
|
ActionDefinition.openType.name= Open Type
|
||||||
ActionDefinition.openType.description= Open a type in a C editor
|
ActionDefinition.openType.description= Open a type in a C editor
|
||||||
|
|
||||||
|
#Add include
|
||||||
|
ActionDefinition.addInclude.name= Add Include
|
||||||
|
ActionDefinition.addInclude.description= Create include statement on selection
|
||||||
|
|
||||||
CElementWorkingSetPage.name = C/C++
|
CElementWorkingSetPage.name = C/C++
|
||||||
|
|
||||||
CEditorFontDefinition.description = The C/C++ editor text font is used by C/C++ editors.
|
CEditorFontDefinition.description = The C/C++ editor text font is used by C/C++ editors.
|
||||||
|
|
|
@ -698,6 +698,18 @@
|
||||||
command="org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"
|
command="org.eclipse.cdt.ui.edit.text.c.open.type.hierarchy"
|
||||||
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||||
</keyBinding>
|
</keyBinding>
|
||||||
|
<command
|
||||||
|
name="%ActionDefinition.addInclude.name"
|
||||||
|
description="%ActionDefinition.addInclude.description"
|
||||||
|
category="org.eclipse.cdt.ui.category.source"
|
||||||
|
id="org.eclipse.cdt.ui.edit.text.c.add.include">
|
||||||
|
</command>
|
||||||
|
<keyBinding
|
||||||
|
string="Ctrl+Shift+N"
|
||||||
|
scope="org.eclipse.cdt.ui.cEditorScope"
|
||||||
|
command="org.eclipse.cdt.ui.edit.text.c.add.include"
|
||||||
|
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||||
|
</keyBinding>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
id="org.eclipse.cdt.ui.CSearchPage"
|
id="org.eclipse.cdt.ui.CSearchPage"
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
|
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
|
||||||
import org.eclipse.cdt.internal.ui.codemanipulation.AddIncludesOperation;
|
import org.eclipse.cdt.internal.ui.codemanipulation.AddIncludesOperation;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CWordFinder;
|
||||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||||
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
import org.eclipse.cdt.ui.CSearchResultLabelProvider;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
@ -53,6 +54,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.window.Window;
|
import org.eclipse.jface.window.Window;
|
||||||
|
@ -136,20 +138,6 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
private Shell getShell() {
|
private Shell getShell() {
|
||||||
return fEditor.getSite().getShell();
|
return fEditor.getSite().getShell();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNameStart(IDocument doc, int pos) throws BadLocationException {
|
|
||||||
if (pos > 0 && doc.getChar(pos - 1) == '.') {
|
|
||||||
pos--;
|
|
||||||
while (pos > 0) {
|
|
||||||
char ch= doc.getChar(pos - 1);
|
|
||||||
if (!Character.isJavaIdentifierPart(ch) && ch != '.') {
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
pos--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see IAction#actionPerformed
|
* @see IAction#actionPerformed
|
||||||
|
@ -185,11 +173,11 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
||||||
|
|
||||||
ITextSelection selection= (ITextSelection) s;
|
ITextSelection selection= (ITextSelection) s;
|
||||||
try {
|
try {
|
||||||
int selStart= selection.getOffset();
|
IRegion region = CWordFinder.findWord(doc, selection.getOffset());
|
||||||
int nameStart= getNameStart(doc, selStart);
|
if (region == null || region.getLength() == 0) {
|
||||||
int len= selStart - nameStart + selection.getLength();
|
return;
|
||||||
|
}
|
||||||
String name = doc.get(nameStart, len).trim();
|
String name = doc.get(region.getOffset(), region.getLength());
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -622,7 +622,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||||
setAction("ContentAssistTip", action); //$NON-NLS-1$
|
setAction("ContentAssistTip", action); //$NON-NLS-1$
|
||||||
|
|
||||||
setAction("AddIncludeOnSelection", new AddIncludeOnSelectionAction(this)); //$NON-NLS-1$
|
action = new AddIncludeOnSelectionAction(this);
|
||||||
|
action.setActionDefinitionId(ICEditorActionDefinitionIds.ADD_INCLUDE);
|
||||||
|
setAction("AddIncludeOnSelection", action); //$NON-NLS-1$
|
||||||
|
|
||||||
action = new OpenDeclarationsAction(this);
|
action = new OpenDeclarationsAction(this);
|
||||||
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
||||||
|
|
|
@ -10,7 +10,7 @@ AddIncludeOnSelection.error.message1=Adding include statements failed
|
||||||
AddIncludeOnSelection.error.message2=Error
|
AddIncludeOnSelection.error.message2=Error
|
||||||
AddIncludeOnSelection.error.message3=Error
|
AddIncludeOnSelection.error.message3=Error
|
||||||
AddIncludeOnSelection.error.message4=BadLocationException:
|
AddIncludeOnSelection.error.message4=BadLocationException:
|
||||||
AddIncludeOnSelection.label=Add I&nclude@Ctrl+Shift+N
|
AddIncludeOnSelection.label=Add I&nclude
|
||||||
AddIncludeOnSelection.tooltip=Add Include Statement on Selection
|
AddIncludeOnSelection.tooltip=Add Include Statement on Selection
|
||||||
|
|
||||||
ShowInCView.description=Show the current resource in the C/C++ Projects view
|
ShowInCView.description=Show the current resource in the C/C++ Projects view
|
||||||
|
|
|
@ -10,110 +10,101 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text;
|
package org.eclipse.cdt.internal.ui.text;
|
||||||
|
|
||||||
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.Region;
|
import org.eclipse.jface.text.Region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class for the text editor to be able to determine,
|
* This is a helper class for the text editor to be able to determine, given a
|
||||||
* given a particular offset in a document, various candidates segments
|
* particular offset in a document, various candidates segments for things like
|
||||||
* for things like context help, proposals and hovering.
|
* context help, proposals and hovering.
|
||||||
*/
|
*/
|
||||||
public class CWordFinder
|
public class CWordFinder {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* This method determines for a given offset into a given document
|
* This method determines for a given offset into a given document what the
|
||||||
* what the region is which defines the current word. A word is
|
* region is which defines the current word. A word is defined as the set of
|
||||||
* defined as the set of non "C" identifiers. So assuming that !
|
* non "C" identifiers. So assuming that ! indicated the current cursor
|
||||||
* indicated the current cursor postion:
|
* postion: !afunction(int a, int b) --> word = length 0 afunc!tion(int a,
|
||||||
* !afunction(int a, int b) --> word = length 0
|
* int b) --> word = afunction afunction!(int a, int b) --> word = afunction
|
||||||
* afunc!tion(int a, int b) --> word = afunction
|
* afunction(!int a, int b) --> word = length 0 afunction(int a,! int b) -->
|
||||||
* afunction!(int a, int b) --> word = afunction
|
* word = length 0 afunction(!) --> word = length 0
|
||||||
* afunction(!int a, int b) --> word = length 0
|
*
|
||||||
* afunction(int a,! int b) --> word = length 0
|
* @param document
|
||||||
* afunction(!) --> word = length 0
|
* The document to be examined
|
||||||
* @param document The document to be examined
|
* @param offset
|
||||||
* @param offset The offset into the document where a word should
|
* The offset into the document where a word should be
|
||||||
* be idendified.
|
* idendified.
|
||||||
* @return The region defining the current word, which may be a
|
* @return The region defining the current word, which may be a region of
|
||||||
* region of length 0 if the offset is not in a word, or null if
|
* length 0 if the offset is not in a word, or null if there is an
|
||||||
* there is an error accessing the docment data.
|
* error accessing the docment data.
|
||||||
*/
|
*/
|
||||||
public static IRegion findWord( IDocument document, int offset )
|
public static IRegion findWord(IDocument document, int offset) {
|
||||||
{
|
|
||||||
int start = -1;
|
int start = -1;
|
||||||
int end = -1;
|
int end = -1;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
int pos = offset;
|
int pos = offset;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
while( pos >= 0 )
|
while (pos >= 0) {
|
||||||
{
|
c = document.getChar(pos);
|
||||||
c = document.getChar( pos );
|
if (!Character.isJavaIdentifierPart(c))
|
||||||
if ( !Character.isJavaIdentifierPart( c ) )
|
|
||||||
break;
|
break;
|
||||||
--pos;
|
--pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = pos;
|
start = pos;
|
||||||
|
|
||||||
pos = offset;
|
pos = offset;
|
||||||
int length = document.getLength();
|
int length = document.getLength();
|
||||||
|
|
||||||
while( pos < length )
|
while (pos < length) {
|
||||||
{
|
c = document.getChar(pos);
|
||||||
c = document.getChar( pos );
|
if (!Character.isJavaIdentifierPart(c))
|
||||||
if ( !Character.isJavaIdentifierPart( c ) )
|
|
||||||
break;
|
break;
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
end = pos;
|
end = pos;
|
||||||
|
|
||||||
}
|
} catch (BadLocationException x) {
|
||||||
catch( BadLocationException x )
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( start > -1 && end > -1 )
|
if (start > -1 && end > -1) {
|
||||||
{
|
if (start == offset && end == offset)
|
||||||
if ( start == offset && end == offset )
|
return new Region(offset, 0);
|
||||||
return new Region( offset, 0 );
|
else if (start == offset)
|
||||||
else if ( start == offset )
|
return new Region(start, end - start);
|
||||||
return new Region( start, end - start );
|
|
||||||
else
|
else
|
||||||
return new Region( start + 1, end - start - 1 );
|
return new Region(start + 1, end - start - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will determine the region for the name of the function
|
* This method will determine the region for the name of the function within
|
||||||
* within which the current offset is contained.
|
* which the current offset is contained.
|
||||||
* @param document The document to be examined
|
*
|
||||||
* @param offset The offset into the document where a word should
|
* @param document
|
||||||
* be idendified.
|
* The document to be examined
|
||||||
* @return The region defining the current word, which may be a
|
* @param offset
|
||||||
* region of length 0 if the offset is not in a function, or null if
|
* The offset into the document where a word should be
|
||||||
* there is an error accessing the docment data.
|
* idendified.
|
||||||
|
* @return The region defining the current word, which may be a region of
|
||||||
|
* length 0 if the offset is not in a function, or null if there is
|
||||||
|
* an error accessing the docment data.
|
||||||
*/
|
*/
|
||||||
public static IRegion findFunction( IDocument document, int offset )
|
public static IRegion findFunction(IDocument document, int offset) {
|
||||||
{
|
|
||||||
int leftbracket = -1;
|
int leftbracket = -1;
|
||||||
int leftbracketcount = 0;
|
int leftbracketcount = 0;
|
||||||
int rightbracket = -1;
|
int rightbracket = -1;
|
||||||
int rightbracketcount = 0;
|
int rightbracketcount = 0;
|
||||||
int functionstart = -1;
|
int functionstart = -1;
|
||||||
int functionend = -1;
|
int functionend = -1;
|
||||||
|
|
||||||
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
int length = document.getLength();
|
int length = document.getLength();
|
||||||
int pos;
|
int pos;
|
||||||
char c;
|
char c;
|
||||||
|
@ -121,92 +112,91 @@ public class CWordFinder
|
||||||
//Find most relevant right bracket from our position
|
//Find most relevant right bracket from our position
|
||||||
pos = offset;
|
pos = offset;
|
||||||
rightbracketcount = leftbracketcount = 0;
|
rightbracketcount = leftbracketcount = 0;
|
||||||
while(pos < length) {
|
while (pos < length) {
|
||||||
c = document.getChar( pos );
|
c = document.getChar(pos);
|
||||||
|
|
||||||
if( c == ')') {
|
if (c == ')') {
|
||||||
rightbracketcount++;
|
rightbracketcount++;
|
||||||
if(rightbracketcount >= leftbracketcount) {
|
if (rightbracketcount >= leftbracketcount) {
|
||||||
rightbracket = pos;
|
rightbracket = pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == '(') {
|
if (c == '(') {
|
||||||
leftbracketcount++;
|
leftbracketcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == ';') {
|
if (c == ';') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( rightbracket == -1 ) {
|
if (rightbracket == -1) {
|
||||||
return new Region(offset, 0);
|
return new Region(offset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now backtrack our way from the rightbracket to the left
|
//Now backtrack our way from the rightbracket to the left
|
||||||
pos = rightbracket;
|
pos = rightbracket;
|
||||||
rightbracketcount = leftbracketcount = 0;
|
rightbracketcount = leftbracketcount = 0;
|
||||||
while(pos >= 0) {
|
while (pos >= 0) {
|
||||||
c = document.getChar( pos );
|
c = document.getChar(pos);
|
||||||
|
|
||||||
if( c == ')') {
|
if (c == ')') {
|
||||||
rightbracketcount++;
|
rightbracketcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == '(') {
|
if (c == '(') {
|
||||||
leftbracketcount++;
|
leftbracketcount++;
|
||||||
if(leftbracketcount >= rightbracketcount) {
|
if (leftbracketcount >= rightbracketcount) {
|
||||||
leftbracket = pos;
|
leftbracket = pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(c == ';') {
|
if (c == ';') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( leftbracket == -1 ) {
|
if (leftbracket == -1) {
|
||||||
return new Region(offset, 0);
|
return new Region(offset, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Now work our way to the function name
|
//Now work our way to the function name
|
||||||
pos = leftbracket - 1;
|
pos = leftbracket - 1;
|
||||||
while(pos >= 0) {
|
while (pos >= 0) {
|
||||||
c = document.getChar( pos );
|
c = document.getChar(pos);
|
||||||
if(functionend == -1 && c == ' ' ) {
|
if (functionend == -1 && c == ' ') {
|
||||||
pos--;
|
pos--;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Character.isJavaIdentifierPart(c)) {
|
if (!Character.isJavaIdentifierPart(c)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
functionstart = pos;
|
functionstart = pos;
|
||||||
if(functionend == -1) {
|
if (functionend == -1) {
|
||||||
functionend = pos;
|
functionend = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos--;
|
pos--;
|
||||||
}
|
}
|
||||||
} catch( BadLocationException x ) {
|
} catch (BadLocationException x) {
|
||||||
/* Ignore */
|
/* Ignore */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (functionstart > -1 && functionend > -1) {
|
if (functionstart > -1 && functionend > -1) {
|
||||||
return new Region(functionstart, functionend - functionstart + 1);
|
return new Region(functionstart, functionend - functionstart + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,7 @@ public abstract class SelectionDispatchAction extends Action implements ISelecti
|
||||||
public ISelection getSelection() {
|
public ISelection getSelection() {
|
||||||
if (getSelectionProvider() != null)
|
if (getSelectionProvider() != null)
|
||||||
return getSelectionProvider().getSelection();
|
return getSelectionProvider().getSelection();
|
||||||
else
|
return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue