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
|
||||
|
||||
Deal with WorkingCopy vs TranslationUnit in the hashCode.
|
||||
|
|
|
@ -134,6 +134,10 @@ OpenTypeAction.tooltip= Open Type
|
|||
ActionDefinition.openType.name= Open Type
|
||||
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++
|
||||
|
||||
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"
|
||||
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||
</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
|
||||
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.actions.WorkbenchRunnableAdapter;
|
||||
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.ui.CSearchResultLabelProvider;
|
||||
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.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.window.Window;
|
||||
|
@ -137,20 +139,6 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
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
|
||||
*/
|
||||
|
@ -185,11 +173,11 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate {
|
|||
|
||||
ITextSelection selection= (ITextSelection) s;
|
||||
try {
|
||||
int selStart= selection.getOffset();
|
||||
int nameStart= getNameStart(doc, selStart);
|
||||
int len= selStart - nameStart + selection.getLength();
|
||||
|
||||
String name = doc.get(nameStart, len).trim();
|
||||
IRegion region = CWordFinder.findWord(doc, selection.getOffset());
|
||||
if (region == null || region.getLength() == 0) {
|
||||
return;
|
||||
}
|
||||
String name = doc.get(region.getOffset(), region.getLength());
|
||||
if (name.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -622,7 +622,9 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
|||
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||
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.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_DECL);
|
||||
|
|
|
@ -10,7 +10,7 @@ AddIncludeOnSelection.error.message1=Adding include statements failed
|
|||
AddIncludeOnSelection.error.message2=Error
|
||||
AddIncludeOnSelection.error.message3=Error
|
||||
AddIncludeOnSelection.error.message4=BadLocationException:
|
||||
AddIncludeOnSelection.label=Add I&nclude@Ctrl+Shift+N
|
||||
AddIncludeOnSelection.label=Add I&nclude
|
||||
AddIncludeOnSelection.tooltip=Add Include Statement on Selection
|
||||
|
||||
ShowInCView.description=Show the current resource in the C/C++ Projects view
|
||||
|
|
|
@ -10,49 +10,44 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text;
|
||||
|
||||
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.text.Region;
|
||||
|
||||
/**
|
||||
* This is a helper class for the text editor to be able to determine,
|
||||
* given a particular offset in a document, various candidates segments
|
||||
* for things like context help, proposals and hovering.
|
||||
* This is a helper class for the text editor to be able to determine, given a
|
||||
* particular offset in a document, various candidates segments for things like
|
||||
* context help, proposals and hovering.
|
||||
*/
|
||||
public class CWordFinder
|
||||
{
|
||||
public class CWordFinder {
|
||||
/**
|
||||
* This method determines for a given offset into a given document
|
||||
* what the region is which defines the current word. A word is
|
||||
* defined as the set of non "C" identifiers. So assuming that !
|
||||
* indicated the current cursor postion:
|
||||
* !afunction(int a, int b) --> word = length 0
|
||||
* afunc!tion(int a, int b) --> word = afunction
|
||||
* afunction!(int a, int b) --> word = afunction
|
||||
* afunction(!int a, int b) --> word = length 0
|
||||
* afunction(int a,! int b) --> word = length 0
|
||||
* afunction(!) --> word = length 0
|
||||
* @param document The document to be examined
|
||||
* @param offset The offset into the document where a word should
|
||||
* be idendified.
|
||||
* @return The region defining the current word, which may be a
|
||||
* region of length 0 if the offset is not in a word, or null if
|
||||
* there is an error accessing the docment data.
|
||||
* This method determines for a given offset into a given document what the
|
||||
* region is which defines the current word. A word is defined as the set of
|
||||
* non "C" identifiers. So assuming that ! indicated the current cursor
|
||||
* postion: !afunction(int a, int b) --> word = length 0 afunc!tion(int a,
|
||||
* int b) --> word = afunction afunction!(int a, int b) --> word = afunction
|
||||
* afunction(!int a, int b) --> word = length 0 afunction(int a,! int b) -->
|
||||
* word = length 0 afunction(!) --> word = length 0
|
||||
*
|
||||
* @param document
|
||||
* The document to be examined
|
||||
* @param offset
|
||||
* The offset into the document where a word should be
|
||||
* idendified.
|
||||
* @return The region defining the current word, which may be a region of
|
||||
* length 0 if the offset is not in a word, or null if there is an
|
||||
* 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 end = -1;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
int pos = offset;
|
||||
char c;
|
||||
|
||||
while( pos >= 0 )
|
||||
{
|
||||
while (pos >= 0) {
|
||||
c = document.getChar(pos);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
|
@ -64,8 +59,7 @@ public class CWordFinder
|
|||
pos = offset;
|
||||
int length = document.getLength();
|
||||
|
||||
while( pos < length )
|
||||
{
|
||||
while (pos < length) {
|
||||
c = document.getChar(pos);
|
||||
if (!Character.isJavaIdentifierPart(c))
|
||||
break;
|
||||
|
@ -74,13 +68,10 @@ public class CWordFinder
|
|||
|
||||
end = pos;
|
||||
|
||||
}
|
||||
catch( BadLocationException x )
|
||||
{
|
||||
} catch (BadLocationException x) {
|
||||
}
|
||||
|
||||
if ( start > -1 && end > -1 )
|
||||
{
|
||||
if (start > -1 && end > -1) {
|
||||
if (start == offset && end == offset)
|
||||
return new Region(offset, 0);
|
||||
else if (start == offset)
|
||||
|
@ -93,17 +84,19 @@ public class CWordFinder
|
|||
}
|
||||
|
||||
/**
|
||||
* This method will determine the region for the name of the function
|
||||
* within which the current offset is contained.
|
||||
* @param document The document to be examined
|
||||
* @param offset The offset into the document where a word should
|
||||
* be 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.
|
||||
* This method will determine the region for the name of the function within
|
||||
* which the current offset is contained.
|
||||
*
|
||||
* @param document
|
||||
* The document to be examined
|
||||
* @param offset
|
||||
* The offset into the document where a word should be
|
||||
* 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 leftbracketcount = 0;
|
||||
int rightbracket = -1;
|
||||
|
@ -111,9 +104,7 @@ public class CWordFinder
|
|||
int functionstart = -1;
|
||||
int functionend = -1;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
int length = document.getLength();
|
||||
int pos;
|
||||
char c;
|
||||
|
@ -209,4 +200,3 @@ public class CWordFinder
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ public abstract class SelectionDispatchAction extends Action implements ISelecti
|
|||
public ISelection getSelection() {
|
||||
if (getSelectionProvider() != null)
|
||||
return getSelectionProvider().getSelection();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue