mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 09:15:38 +02:00
patch from Thomas Fletcher
This commit is contained in:
parent
1e011191d0
commit
56971cf3df
7 changed files with 218 additions and 168 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2003-0213 Thomas Fletcher
|
||||||
|
* src/org/eclipse/cdt/internal/ui/cview/CView.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/cview/FilterSelectionAction.java
|
||||||
|
Cleaned up some text strings.
|
||||||
|
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/ContextTypeRegistry.java
|
||||||
|
* src/org/eclipse/cdt/internal/corext/template/default-templates.xml
|
||||||
|
* src/org/eclipse/cdt/internal/ui/preferences/TemplatePreferencePage.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CCompletionProcessor.java
|
||||||
|
Adds a C++ context and moves those templates which are C++ specific to that context
|
||||||
|
Allows you to use the C++ and C contexts when you are working in C++ code,
|
||||||
|
but only giving you the C contexts when you are working in C code.
|
||||||
|
|
||||||
2003-02-06 David Inglis
|
2003-02-06 David Inglis
|
||||||
* src/org/eclipse/cdt/internal/core/DocumentInputStream.java (Removed)
|
* src/org/eclipse/cdt/internal/core/DocumentInputStream.java (Removed)
|
||||||
* src/org/eclipse/cdt/internal/ui/DocumentInputStream.java (Added)
|
* src/org/eclipse/cdt/internal/ui/DocumentInputStream.java (Added)
|
||||||
|
|
|
@ -5,11 +5,13 @@ package org.eclipse.cdt.internal.corext.template;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.corext.template.c.CContextType;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.corext.template.c.CContextType;
|
||||||
|
import org.eclipse.cdt.internal.corext.template.c.CppContextType;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton to keep track of all known context types.
|
* A singleton to keep track of all known context types.
|
||||||
|
@ -63,7 +65,7 @@ public class ContextTypeRegistry {
|
||||||
// XXX bootstrap with C and C++ types
|
// XXX bootstrap with C and C++ types
|
||||||
private ContextTypeRegistry() {
|
private ContextTypeRegistry() {
|
||||||
add(new CContextType());
|
add(new CContextType());
|
||||||
//add(new CppContextType());
|
add(new CppContextType());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,89 +7,99 @@ All Rights Reserved.
|
||||||
|
|
||||||
<templates>
|
<templates>
|
||||||
|
|
||||||
<!-- C++ -->
|
<!-- C++ -->
|
||||||
|
|
||||||
<template description="for loop" name="for" context="C"
|
<template description="for loop" name="for" context="C">
|
||||||
>for (${var} = 0; ${var} < ${max}; ${var}++) {
|
for (${var} = 0; ${var} < ${max}; ${var}++) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="for loop with temporary variable" name="for" context="C"
|
<template description="for loop with temporary variable" name="for" context="C">
|
||||||
>for (int ${var} = 0; ${var} < ${max}; ${var}++) {
|
for (int ${var} = 0; ${var} < ${max}; ${var}++) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="do while statement" name="do" context="C"
|
<template description="do while statement" name="do" context="C">
|
||||||
>do {
|
do {
|
||||||
${cursor}
|
${cursor}
|
||||||
} while (${condition});</template>
|
} while (${condition});
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="switch case statement" name="switch" context="C"
|
<template description="switch case statement" name="switch" context="C">
|
||||||
>switch (${key}) {
|
switch (${key}) {
|
||||||
case ${value}:
|
case ${value}:
|
||||||
${cursor}
|
${cursor}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="if statement" name="if" context="C"
|
<template description="if statement" name="if" context="C">
|
||||||
>if (${condition}) {
|
if (${condition}) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="if else statement" name="ifelse" context="C"
|
<template description="if else statement" name="ifelse" context="C">
|
||||||
>if (${condition}) {
|
if (${condition}) {
|
||||||
${cursor}
|
${cursor}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="else if block" name="elseif" context="C"
|
<template description="else if block" name="elseif" context="C">
|
||||||
>else if (${condition}) {
|
else if (${condition}) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="else block" name="else" context="C"
|
<template description="else block" name="else" context="C">
|
||||||
>else {
|
else {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="try catch block" name="try" context="C"
|
<template description="try catch block" name="try" context="C++">
|
||||||
>try {
|
try {
|
||||||
${cursor}
|
${cursor}
|
||||||
} catch (${Exception} e) {
|
} catch (${Exception} e) {
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="catch block" name="catch" context="C"
|
<template description="catch block" name="catch" context="C++">
|
||||||
>catch (${Exception} e) {
|
catch (${Exception} e) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template description="main method" name="main" context="C"
|
<template description="main method" name="main" context="C">
|
||||||
>
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}
|
||||||
|
|
||||||
<template description="class declaration" name="class" context="C"
|
|
||||||
>class ${name} {
|
|
||||||
${cursor}
|
|
||||||
private:
|
|
||||||
};</template>
|
|
||||||
|
|
||||||
<template description="using a namespace" name="using" context="C"
|
|
||||||
>using namespace ${namespace};
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template description="namespace declaration" name="namespace" context="C"
|
<template description="class declaration" name="class" context="C++">
|
||||||
|
class ${name} {
|
||||||
|
${cursor}
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template description="using a namespace" name="using" context="C++">
|
||||||
|
using namespace ${namespace};
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template description="namespace declaration" name="namespace" context="C++"
|
||||||
>namespace ${namespace} {
|
>namespace ${namespace} {
|
||||||
${cursor}
|
${cursor}
|
||||||
}</template>
|
}</template>
|
||||||
|
|
||||||
<template description="create new object" name="new" context="C"
|
<template description="create new object" name="new" context="C++"
|
||||||
>${type} ${name} = new ${type}(${arguments});
|
>${type} ${name} = new ${type}(${arguments});
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -519,8 +519,7 @@ public class CView extends ViewPart implements IMenuListener, ISetSelectionTarge
|
||||||
|
|
||||||
//sortByNameAction = new SortViewAction(this, false);
|
//sortByNameAction = new SortViewAction(this, false);
|
||||||
//sortByTypeAction = new SortViewAction(this, true);
|
//sortByTypeAction = new SortViewAction(this, true);
|
||||||
|
patternFilterAction = new FilterSelectionAction(shell, this, "Filters...");
|
||||||
patternFilterAction = new FilterSelectionAction(shell, this, "Filters..");
|
|
||||||
clibFilterAction = new ShowLibrariesAction(shell, this, "Show Referenced Libs");
|
clibFilterAction = new ShowLibrariesAction(shell, this, "Show Referenced Libs");
|
||||||
|
|
||||||
goIntoAction = new GoIntoAction(frameList);
|
goIntoAction = new GoIntoAction(frameList);
|
||||||
|
|
|
@ -53,9 +53,10 @@ class FilterSelectionAction extends SelectionProviderAction {
|
||||||
cview.getViewer(),
|
cview.getViewer(),
|
||||||
contentProvider,
|
contentProvider,
|
||||||
new LabelProvider(),
|
new LabelProvider(),
|
||||||
"Select Filter"); //$NON-NLS-1$
|
"Select the filters to apply (matching files will be hidden):");
|
||||||
|
|
||||||
dialog.setInitialSelections(contentProvider.getInitialSelections());
|
dialog.setInitialSelections(contentProvider.getInitialSelections());
|
||||||
|
dialog.setTitle("C/C++ File Filters");
|
||||||
dialog.open();
|
dialog.open();
|
||||||
if (dialog.getReturnCode() == Window.OK) {
|
if (dialog.getReturnCode() == Window.OK) {
|
||||||
Object[] results= dialog.getResult();
|
Object[] results= dialog.getResult();
|
||||||
|
|
|
@ -357,7 +357,7 @@ public class TemplatePreferencePage extends PreferencePage implements IWorkbench
|
||||||
Template template= new Template();
|
Template template= new Template();
|
||||||
|
|
||||||
ContextTypeRegistry registry=ContextTypeRegistry.getInstance();
|
ContextTypeRegistry registry=ContextTypeRegistry.getInstance();
|
||||||
ContextType type= registry.getContextType("java");
|
ContextType type= registry.getContextType("C");
|
||||||
|
|
||||||
String contextTypeName;
|
String contextTypeName;
|
||||||
if (type != null)
|
if (type != null)
|
||||||
|
|
|
@ -5,24 +5,23 @@ package org.eclipse.cdt.internal.ui.text;
|
||||||
* All Rights Reserved.
|
* All Rights Reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.cdt.core.index.ITagEntry;
|
|
||||||
import org.eclipse.cdt.core.index.IndexModel;
|
|
||||||
import org.eclipse.cdt.core.index.TagFlags;
|
|
||||||
import org.eclipse.cdt.internal.corext.template.ContextType;
|
|
||||||
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
|
|
||||||
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
|
||||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
|
||||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
|
||||||
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.cdt.ui.IFunctionSummary;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.cdt.core.index.ITagEntry;
|
||||||
import org.eclipse.swt.graphics.Point;
|
import org.eclipse.cdt.core.index.IndexModel;
|
||||||
|
import org.eclipse.cdt.core.index.TagFlags;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
import org.eclipse.cdt.internal.corext.template.ContextType;
|
||||||
|
import org.eclipse.cdt.internal.corext.template.ContextTypeRegistry;
|
||||||
|
import org.eclipse.cdt.internal.ui.CCompletionContributorManager;
|
||||||
|
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.template.TemplateEngine;
|
||||||
|
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.IFunctionSummary;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
@ -33,7 +32,8 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||||
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
||||||
import org.eclipse.jface.text.contentassist.IContextInformation;
|
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||||
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.IFileEditorInput;
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
|
@ -46,7 +46,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
private CEditor fEditor;
|
private CEditor fEditor;
|
||||||
private char[] fProposalAutoActivationSet;
|
private char[] fProposalAutoActivationSet;
|
||||||
private CCompletionProposalComparator fComparator;
|
private CCompletionProposalComparator fComparator;
|
||||||
private TemplateEngine fTemplateEngine;
|
private TemplateEngine[] fTemplateEngine;
|
||||||
|
|
||||||
private boolean fRestrictToMatchingCase;
|
private boolean fRestrictToMatchingCase;
|
||||||
private boolean fAllowAddIncludes;
|
private boolean fAllowAddIncludes;
|
||||||
|
@ -54,16 +54,50 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
private CElementLabelProvider fElementLabelProvider;
|
private CElementLabelProvider fElementLabelProvider;
|
||||||
//private ImageRegistry fImageRegistry;
|
//private ImageRegistry fImageRegistry;
|
||||||
|
|
||||||
|
|
||||||
public CCompletionProcessor(IEditorPart editor) {
|
public CCompletionProcessor(IEditorPart editor) {
|
||||||
fEditor= (CEditor)editor;
|
fEditor = (CEditor) editor;
|
||||||
ContextType contextType= ContextTypeRegistry.getInstance().getContextType("C"); //$NON-NLS-1$
|
|
||||||
if (contextType != null)
|
|
||||||
fTemplateEngine= new TemplateEngine(contextType);
|
|
||||||
fRestrictToMatchingCase= false;
|
|
||||||
fAllowAddIncludes= true;
|
|
||||||
|
|
||||||
fComparator= new CCompletionProposalComparator();
|
//Determine if this is a C or a C++ file for the context completion + //This is _totally_ ugly and likely belongs in the main editor class.
|
||||||
|
String contextNames[] = new String[2];
|
||||||
|
ArrayList templateList = new ArrayList(2);
|
||||||
|
String filename = null;
|
||||||
|
if (fEditor != null && fEditor.getEditorInput() != null) {
|
||||||
|
filename = fEditor.getEditorInput().getName();
|
||||||
|
}
|
||||||
|
if (filename == null) {
|
||||||
|
contextNames[0] = "C"; //$NON-NLS-1$
|
||||||
|
contextNames[1] = "C++"; //$NON-NLS-1$
|
||||||
|
} else if (filename.endsWith(".c")) { //Straight C files are always C
|
||||||
|
contextNames[0] = "C"; //$NON-NLS-1$
|
||||||
|
} else if (
|
||||||
|
filename.endsWith(".cpp")
|
||||||
|
|| filename.endsWith(".cc")
|
||||||
|
|| filename.endsWith(".cxx")
|
||||||
|
|| filename.endsWith(".C")
|
||||||
|
|| filename.endsWith(".hxx")) {
|
||||||
|
contextNames[0] = "C++"; //$NON-NLS-1$
|
||||||
|
contextNames[1] = "C"; //$NON-NLS-1$
|
||||||
|
} else { //Defer to the nature of the project
|
||||||
|
IFile file = fEditor.getInputFile();
|
||||||
|
if (file != null && CoreModel.getDefault().hasCCNature(file.getProject())) {
|
||||||
|
contextNames[0] = "C++"; //$NON-NLS-1$
|
||||||
|
contextNames[1] = "C"; //$NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
contextNames[0] = "C"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContextType contextType;
|
||||||
|
for (int i = 0; i < contextNames.length; i++) {
|
||||||
|
contextType = ContextTypeRegistry.getInstance().getContextType(contextNames[i]);
|
||||||
|
if (contextType != null) {
|
||||||
|
templateList.add(new TemplateEngine(contextType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fTemplateEngine = (TemplateEngine[]) templateList.toArray(new TemplateEngine[templateList.size()]);
|
||||||
|
fRestrictToMatchingCase = false;
|
||||||
|
fAllowAddIncludes = true;
|
||||||
|
|
||||||
|
fComparator = new CCompletionProposalComparator();
|
||||||
|
|
||||||
fElementLabelProvider = new CElementLabelProvider();
|
fElementLabelProvider = new CElementLabelProvider();
|
||||||
//fImageRegistry= CUIPlugin.getDefault().getImageRegistry();
|
//fImageRegistry= CUIPlugin.getDefault().getImageRegistry();
|
||||||
|
@ -113,7 +147,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
* @param activationSet the activation set
|
* @param activationSet the activation set
|
||||||
*/
|
*/
|
||||||
public void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
|
public void setCompletionProposalAutoActivationCharacters(char[] activationSet) {
|
||||||
fProposalAutoActivationSet= activationSet;
|
fProposalAutoActivationSet = activationSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,7 +174,7 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
* @param restrict <code>true</code> if import can be added
|
* @param restrict <code>true</code> if import can be added
|
||||||
*/
|
*/
|
||||||
public void allowAddingIncludes(boolean allowAddingIncludes) {
|
public void allowAddingIncludes(boolean allowAddingIncludes) {
|
||||||
fAllowAddIncludes= allowAddingIncludes;
|
fAllowAddIncludes = allowAddingIncludes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,51 +182,54 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
*/
|
*/
|
||||||
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
|
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
|
||||||
//IDocument unit= fManager.getWorkingCopy(fEditor.getEditorInput());
|
//IDocument unit= fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||||
IDocument document= viewer.getDocument();
|
IDocument document = viewer.getDocument();
|
||||||
|
|
||||||
ICCompletionProposal[] results = null;
|
ICCompletionProposal[] results = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
|
|
||||||
int offset= documentOffset;
|
int offset = documentOffset;
|
||||||
int length= 0;
|
int length = 0;
|
||||||
|
|
||||||
Point selection= viewer.getSelectedRange();
|
Point selection = viewer.getSelectedRange();
|
||||||
if (selection.y > 0) {
|
if (selection.y > 0) {
|
||||||
offset= selection.x;
|
offset = selection.x;
|
||||||
length= selection.y;
|
length = selection.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
//CCompletionEvaluator evaluator= new CCompletionEvaluator(document, offset, length);
|
//CCompletionEvaluator evaluator= new CCompletionEvaluator(document, offset, length);
|
||||||
//evaluator.restrictProposalsToMatchingCases(fRestrictToMatchingCase);
|
//evaluator.restrictProposalsToMatchingCases(fRestrictToMatchingCase);
|
||||||
results= evalProposals(document, offset, length);
|
results = evalProposals(document, offset, length);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.getDefault().log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(results == null)
|
if (results == null)
|
||||||
results = new ICCompletionProposal[0];
|
results = new ICCompletionProposal[0];
|
||||||
|
|
||||||
if (fTemplateEngine != null) {
|
for (int i = 0; i < fTemplateEngine.length; i++) {
|
||||||
|
if (fTemplateEngine[i] == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
fTemplateEngine.reset();
|
fTemplateEngine[i].reset();
|
||||||
fTemplateEngine.complete(viewer, documentOffset, null);
|
fTemplateEngine[i].complete(viewer, documentOffset, null);
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
System.out.println("Template Exception");
|
System.out.println("Template Exception");
|
||||||
CUIPlugin.getDefault().log(x);
|
CUIPlugin.getDefault().log(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
ICCompletionProposal[] templateResults= fTemplateEngine.getResults();
|
ICCompletionProposal[] templateResults = fTemplateEngine[i].getResults();
|
||||||
if (results.length == 0) {
|
if (results.length == 0) {
|
||||||
results= templateResults;
|
results = templateResults;
|
||||||
} else {
|
} else {
|
||||||
// concatenate arrays
|
// concatenate arrays
|
||||||
ICCompletionProposal[] total= new ICCompletionProposal[results.length + templateResults.length];
|
ICCompletionProposal[] total = new ICCompletionProposal[results.length + templateResults.length];
|
||||||
System.arraycopy(templateResults, 0, total, 0, templateResults.length);
|
System.arraycopy(templateResults, 0, total, 0, templateResults.length);
|
||||||
System.arraycopy(results, 0, total, templateResults.length, results.length);
|
System.arraycopy(results, 0, total, templateResults.length, results.length);
|
||||||
results= total;
|
results = total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +238,8 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
* applies to all proposals and not just those of the compilation unit.
|
* applies to all proposals and not just those of the compilation unit.
|
||||||
*/
|
*/
|
||||||
order(results);
|
order(results);
|
||||||
if((results.length == 1) && (CUIPlugin.getDefault().getPreferenceStore().getBoolean(ContentAssistPreference.AUTOINSERT))) {
|
if ((results.length == 1)
|
||||||
|
&& (CUIPlugin.getDefault().getPreferenceStore().getBoolean(ContentAssistPreference.AUTOINSERT))) {
|
||||||
results[0].apply(document);
|
results[0].apply(document);
|
||||||
// Trick the content assistant into thinking we have no proposals
|
// Trick the content assistant into thinking we have no proposals
|
||||||
return new ICCompletionProposal[0];
|
return new ICCompletionProposal[0];
|
||||||
|
@ -221,29 +259,24 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
private void addProjectCompletions(IProject project, IRegion region, String frag, ArrayList completions) {
|
private void addProjectCompletions(IProject project, IRegion region, String frag, ArrayList completions) {
|
||||||
IndexModel model = IndexModel.getDefault();
|
IndexModel model = IndexModel.getDefault();
|
||||||
|
|
||||||
ITagEntry[] tags= model.query(project, frag+"*", false, false);
|
ITagEntry[] tags = model.query(project, frag + "*", false, false);
|
||||||
if(tags != null && tags.length > 0) {
|
if (tags != null && tags.length > 0) {
|
||||||
// We have some matches!
|
// We have some matches!
|
||||||
for(int i = 0; i < tags.length; i++) {
|
for (int i = 0; i < tags.length; i++) {
|
||||||
|
|
||||||
String fname = tags[i].getTagName();
|
String fname = tags[i].getTagName();
|
||||||
|
|
||||||
int kind = tags[i].getKind();
|
int kind = tags[i].getKind();
|
||||||
|
|
||||||
if(kind == TagFlags.T_FUNCTION || kind == TagFlags.T_PROTOTYPE) {
|
if (kind == TagFlags.T_FUNCTION || kind == TagFlags.T_PROTOTYPE) {
|
||||||
fname = fname + "()";
|
fname = fname + "()";
|
||||||
}
|
}
|
||||||
String proto = fname + " - " + tags[i].getPattern();
|
String proto = fname + " - " + tags[i].getPattern();
|
||||||
//System.out.println("tagmatch " + fname + " proto " + proto + " type" + tags[i].getKind());
|
//System.out.println("tagmatch " + fname + " proto " + proto + " type" + tags[i].getKind());
|
||||||
if(tags[i].getKind() != TagFlags.T_MEMBER) {
|
if (tags[i].getKind() != TagFlags.T_MEMBER) {
|
||||||
completions.add(
|
completions.add(new CCompletionProposal(fname, region.getOffset(), region.getLength(),
|
||||||
new CCompletionProposal(
|
|
||||||
fname,
|
|
||||||
region.getOffset(),
|
|
||||||
region.getLength(),
|
|
||||||
//fname.length() + 1,
|
//fname.length() + 1,
|
||||||
getTagImage(kind),
|
getTagImage(kind), proto.equals("") ? (fname + "()") : proto,
|
||||||
proto.equals("") ? (fname + "()") : proto,
|
|
||||||
//null,
|
//null,
|
||||||
//null));
|
//null));
|
||||||
3));
|
3));
|
||||||
|
@ -311,27 +344,26 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
// Based on the frag name, build a list of completion proposals
|
// Based on the frag name, build a list of completion proposals
|
||||||
// We look in two places: the content outline and the libs
|
// We look in two places: the content outline and the libs
|
||||||
|
|
||||||
|
|
||||||
ArrayList completions = new ArrayList();
|
ArrayList completions = new ArrayList();
|
||||||
|
|
||||||
// Look in index manager
|
// Look in index manager
|
||||||
IProject project = null;
|
IProject project = null;
|
||||||
IEditorInput input = fEditor.getEditorInput();
|
IEditorInput input = fEditor.getEditorInput();
|
||||||
if(input instanceof IFileEditorInput) {
|
if (input instanceof IFileEditorInput) {
|
||||||
project = ((IFileEditorInput)input).getFile().getProject();
|
project = ((IFileEditorInput) input).getFile().getProject();
|
||||||
|
|
||||||
// Bail out quickly, if the project was deleted.
|
// Bail out quickly, if the project was deleted.
|
||||||
if (!project.exists()) {
|
if (!project.exists()) {
|
||||||
project = null;
|
project = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(project != null) {
|
if (project != null) {
|
||||||
addProjectCompletions(project, region, frag, completions);
|
addProjectCompletions(project, region, frag, completions);
|
||||||
// Now query referenced projects
|
// Now query referenced projects
|
||||||
IProject referenced[];
|
IProject referenced[];
|
||||||
try {
|
try {
|
||||||
referenced = project.getReferencedProjects();
|
referenced = project.getReferencedProjects();
|
||||||
if(referenced.length > 0) {
|
if (referenced.length > 0) {
|
||||||
for (int i = 0; i < referenced.length; i++) {
|
for (int i = 0; i < referenced.length; i++) {
|
||||||
addProjectCompletions(referenced[i], region, frag, completions);
|
addProjectCompletions(referenced[i], region, frag, completions);
|
||||||
}
|
}
|
||||||
|
@ -341,23 +373,17 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IFunctionSummary[] summary;
|
IFunctionSummary[] summary;
|
||||||
|
|
||||||
//UserHelpFunctionInfo inf = plugin.getFunctionInfo();
|
//UserHelpFunctionInfo inf = plugin.getFunctionInfo();
|
||||||
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(frag);
|
summary = CCompletionContributorManager.getDefault().getMatchingFunctions(frag);
|
||||||
if(summary != null) {
|
if (summary != null) {
|
||||||
for(int i = 0; i < summary.length; i++) {
|
for (int i = 0; i < summary.length; i++) {
|
||||||
String fname = summary[i].getName();
|
String fname = summary[i].getName();
|
||||||
String proto = summary[i].getPrototype();
|
String proto = summary[i].getPrototype();
|
||||||
completions.add(
|
completions.add(new CCompletionProposal(fname + "()", region.getOffset(), region.getLength(),
|
||||||
new CCompletionProposal(
|
|
||||||
fname + "()",
|
|
||||||
region.getOffset(),
|
|
||||||
region.getLength(),
|
|
||||||
//fname.length() + 1,
|
//fname.length() + 1,
|
||||||
CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION),
|
CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION), proto.equals("") ? (fname + "()") : proto,
|
||||||
proto.equals("") ? (fname + "()") : proto,
|
|
||||||
//null,
|
//null,
|
||||||
//null));
|
//null));
|
||||||
2));
|
2));
|
||||||
|
@ -368,25 +394,24 @@ public class CCompletionProcessor implements IContentAssistProcessor {
|
||||||
|
|
||||||
private Image getTagImage(int kind) {
|
private Image getTagImage(int kind) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
case TagFlags.T_PROTOTYPE:
|
case TagFlags.T_PROTOTYPE :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_DECLARATION);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_DECLARATION);
|
||||||
case TagFlags.T_CLASS:
|
case TagFlags.T_CLASS :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_CLASS);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_CLASS);
|
||||||
case TagFlags.T_ENUM:
|
case TagFlags.T_ENUM :
|
||||||
case TagFlags.T_VARIABLE:
|
case TagFlags.T_VARIABLE :
|
||||||
case TagFlags.T_MEMBER:
|
case TagFlags.T_MEMBER :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_FIELD);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_FIELD);
|
||||||
case TagFlags.T_FUNCTION:
|
case TagFlags.T_FUNCTION :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
|
||||||
case TagFlags.T_STRUCT:
|
case TagFlags.T_STRUCT :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_STRUCT);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_STRUCT);
|
||||||
case TagFlags.T_UNION:
|
case TagFlags.T_UNION :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_UNION);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_UNION);
|
||||||
case TagFlags.T_MACRO:
|
case TagFlags.T_MACRO :
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_MACRO);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_MACRO);
|
||||||
}
|
}
|
||||||
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
|
return CPluginImages.get(CPluginImages.IMG_OBJS_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue