mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
Bug 228653 - Minor editor scalability improvements
This commit is contained in:
parent
cca64fca6c
commit
4796a78346
12 changed files with 163 additions and 39 deletions
|
@ -269,7 +269,7 @@ public final class ASTProvider {
|
||||||
* @return <code>true</code> if the given translation unit is the active one
|
* @return <code>true</code> if the given translation unit is the active one
|
||||||
*/
|
*/
|
||||||
public boolean isActive(ITranslationUnit tu) {
|
public boolean isActive(ITranslationUnit tu) {
|
||||||
return fCache.isActiveElement(tu);
|
return fCache.isActiveElement(tu) && tu.isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,8 +13,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.custom.StackLayout;
|
||||||
|
import org.eclipse.swt.layout.FillLayout;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.ui.actions.ActionGroup;
|
import org.eclipse.ui.actions.ActionGroup;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||||
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
|
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
|
||||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||||
|
@ -28,6 +36,12 @@ import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup;
|
||||||
*/
|
*/
|
||||||
public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
||||||
|
|
||||||
|
private Composite fParent;
|
||||||
|
private StackLayout fStackLayout;
|
||||||
|
private Composite fOutlinePage;
|
||||||
|
private Control fStatusPage;
|
||||||
|
private boolean fScalabilityMode;
|
||||||
|
|
||||||
public CContentOutlinePage(CEditor editor) {
|
public CContentOutlinePage(CEditor editor) {
|
||||||
super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
|
super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
@ -40,6 +54,60 @@ public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
||||||
return (CEditor)fEditor;
|
return (CEditor)fEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createControl(Composite parent) {
|
||||||
|
fParent = new Composite(parent, SWT.NONE);
|
||||||
|
fStackLayout = new StackLayout();
|
||||||
|
fParent.setLayout(fStackLayout);
|
||||||
|
fOutlinePage = new Composite(fParent, SWT.NONE);
|
||||||
|
fOutlinePage.setLayout(new FillLayout());
|
||||||
|
super.createControl(fOutlinePage);
|
||||||
|
fStatusPage = createStatusPage(fParent);
|
||||||
|
updateVisiblePage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Control getControl() {
|
||||||
|
return fParent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Control createStatusPage(Composite parent) {
|
||||||
|
Label label = new Label(parent, SWT.NONE);
|
||||||
|
label.setText(CEditorMessages.getString("Scalability.outlineDisabled")); //$NON-NLS-1$
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInput(ITranslationUnit unit) {
|
||||||
|
final CEditor editor= getEditor();
|
||||||
|
if (editor.isEnableScalablilityMode()
|
||||||
|
&& PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_RECONCILER)) {
|
||||||
|
fScalabilityMode = true;
|
||||||
|
super.setInput(null);
|
||||||
|
} else {
|
||||||
|
fScalabilityMode = false;
|
||||||
|
super.setInput(unit);
|
||||||
|
}
|
||||||
|
updateVisiblePage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVisiblePage() {
|
||||||
|
if (fStackLayout == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (fScalabilityMode) {
|
||||||
|
if (fStackLayout.topControl != fStatusPage) {
|
||||||
|
fStackLayout.topControl = fStatusPage;
|
||||||
|
fParent.layout();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fStackLayout.topControl != fOutlinePage) {
|
||||||
|
fStackLayout.topControl = fOutlinePage;
|
||||||
|
fParent.layout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SelectionSearchGroup createSearchActionGroup() {
|
protected SelectionSearchGroup createSearchActionGroup() {
|
||||||
return new SelectionSearchGroup(this);
|
return new SelectionSearchGroup(this);
|
||||||
|
|
|
@ -107,6 +107,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||||
import org.eclipse.jface.viewers.StructuredSelection;
|
import org.eclipse.jface.viewers.StructuredSelection;
|
||||||
import org.eclipse.search.ui.actions.TextSearchGroup;
|
import org.eclipse.search.ui.actions.TextSearchGroup;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.custom.BusyIndicator;
|
||||||
import org.eclipse.swt.custom.ST;
|
import org.eclipse.swt.custom.ST;
|
||||||
import org.eclipse.swt.custom.StyledText;
|
import org.eclipse.swt.custom.StyledText;
|
||||||
import org.eclipse.swt.custom.VerifyKeyListener;
|
import org.eclipse.swt.custom.VerifyKeyListener;
|
||||||
|
@ -1290,20 +1291,27 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
if (!(sourceViewer instanceof ISourceViewerExtension2)) {
|
if (!(sourceViewer instanceof ISourceViewerExtension2)) {
|
||||||
setPreferenceStore(createCombinedPreferenceStore(input));
|
setPreferenceStore(createCombinedPreferenceStore(input));
|
||||||
internalDoSetInput(input);
|
internalDoSetInput(input);
|
||||||
|
updateScalabilityMode(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// uninstall & unregister preference store listener
|
getDocumentProvider().connect(input);
|
||||||
getSourceViewerDecorationSupport(sourceViewer).uninstall();
|
try {
|
||||||
((ISourceViewerExtension2)sourceViewer).unconfigure();
|
// uninstall & unregister preference store listener
|
||||||
|
getSourceViewerDecorationSupport(sourceViewer).uninstall();
|
||||||
|
((ISourceViewerExtension2)sourceViewer).unconfigure();
|
||||||
|
|
||||||
setPreferenceStore(createCombinedPreferenceStore(input));
|
setPreferenceStore(createCombinedPreferenceStore(input));
|
||||||
|
updateScalabilityMode(input);
|
||||||
|
|
||||||
// install & register preference store listener
|
// install & register preference store listener
|
||||||
sourceViewer.configure(getSourceViewerConfiguration());
|
sourceViewer.configure(getSourceViewerConfiguration());
|
||||||
getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
|
getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
|
||||||
|
|
||||||
internalDoSetInput(input);
|
internalDoSetInput(input);
|
||||||
|
} finally {
|
||||||
|
getDocumentProvider().disconnect(input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void internalDoSetInput(IEditorInput input) throws CoreException {
|
private void internalDoSetInput(IEditorInput input) throws CoreException {
|
||||||
|
@ -1333,12 +1341,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
} else {
|
} else {
|
||||||
fBracketMatcher.configure(null);
|
fBracketMatcher.configure(null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateScalabilityMode(IEditorInput input) {
|
||||||
int lines = getDocumentProvider().getDocument(input).getNumberOfLines();
|
int lines = getDocumentProvider().getDocument(input).getNumberOfLines();
|
||||||
if (lines > getPreferenceStore().getInt(PreferenceConstants.SCALABILITY_NUMBER_OF_LINES)) {
|
boolean wasEnabled = fEnableScalablilityMode;
|
||||||
//Detecting if scalability mode should be turned on
|
fEnableScalablilityMode = lines > getPreferenceStore().getInt(PreferenceConstants.SCALABILITY_NUMBER_OF_LINES);
|
||||||
fEnableScalablilityMode = true;
|
if (fEnableScalablilityMode && !wasEnabled) {
|
||||||
|
|
||||||
//Alert users that scalability mode should be turned on
|
//Alert users that scalability mode should be turned on
|
||||||
if (getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_ALERT)) {
|
if (getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_ALERT)) {
|
||||||
MessageDialogWithToggle dialog = new MessageDialogWithToggle(
|
MessageDialogWithToggle dialog = new MessageDialogWithToggle(
|
||||||
|
@ -1412,8 +1421,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
* @return Outline page.
|
* @return Outline page.
|
||||||
*/
|
*/
|
||||||
public CContentOutlinePage getOutlinePage() {
|
public CContentOutlinePage getOutlinePage() {
|
||||||
if (isEnableScalablilityMode() && getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_RECONCILER))
|
|
||||||
return null;
|
|
||||||
if (fOutlinePage == null) {
|
if (fOutlinePage == null) {
|
||||||
fOutlinePage = new CContentOutlinePage(this);
|
fOutlinePage = new CContentOutlinePage(this);
|
||||||
fOutlinePage.addSelectionChangedListener(this);
|
fOutlinePage.addSelectionChangedListener(this);
|
||||||
|
@ -1494,7 +1501,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
final AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
||||||
|
|
||||||
if (asv != null) {
|
if (asv != null) {
|
||||||
|
|
||||||
|
@ -1529,12 +1536,14 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
} else {
|
} else {
|
||||||
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$
|
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TODO_TASK_TAGS.equals(event.getProperty())) {
|
if (TODO_TASK_TAGS.equals(event.getProperty())) {
|
||||||
ISourceViewer sourceViewer = getSourceViewer();
|
ISourceViewer sourceViewer = getSourceViewer();
|
||||||
if (sourceViewer != null && affectsTextPresentation(event))
|
if (sourceViewer != null && affectsTextPresentation(event))
|
||||||
sourceViewer.invalidateTextPresentation();
|
sourceViewer.invalidateTextPresentation();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
|
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
|
||||||
|
@ -1595,8 +1604,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
||||||
if (isEnableScalablilityMode()) {
|
if (isEnableScalablilityMode()) {
|
||||||
if (PreferenceConstants.SCALABILITY_RECONCILER.equals(property) ||
|
if (PreferenceConstants.SCALABILITY_RECONCILER.equals(property) ||
|
||||||
PreferenceConstants.SCALABILITY_SYNTAX_COLOR.equals(property)) {
|
PreferenceConstants.SCALABILITY_SYNTAX_COLOR.equals(property)) {
|
||||||
asv.unconfigure();
|
BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
|
||||||
asv.configure(getSourceViewerConfiguration());
|
public void run() {
|
||||||
|
setOutlinePageInput(fOutlinePage, getEditorInput());
|
||||||
|
asv.unconfigure();
|
||||||
|
asv.configure(getSourceViewerConfiguration());
|
||||||
|
}});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ AddIncludesOperation.description=Adding include statement
|
||||||
Scalability.message=You are opening a large file. Turning on scalability mode might help improve editor's performance. Please see the Scalability preference page under Preferences > C/C++ > Editor.
|
Scalability.message=You are opening a large file. Turning on scalability mode might help improve editor's performance. Please see the Scalability preference page under Preferences > C/C++ > Editor.
|
||||||
Scalability.info=Editor Scalability
|
Scalability.info=Editor Scalability
|
||||||
Scalability.reappear=Do not show this message again.
|
Scalability.reappear=Do not show this message again.
|
||||||
|
Scalability.outlineDisabled=Outline is disabled due to scalability mode.
|
||||||
|
|
||||||
ShowInCView.description=Show the current resource in the C/C++ Projects view
|
ShowInCView.description=Show the current resource in the C/C++ Projects view
|
||||||
ShowInCView.label=Show in C/C++ Projects
|
ShowInCView.label=Show in C/C++ Projects
|
||||||
ShowInCView.tooltip=Show current resource in C/C++ Projects view
|
ShowInCView.tooltip=Show current resource in C/C++ Projects view
|
||||||
|
|
|
@ -19,7 +19,6 @@ import java.util.List;
|
||||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||||
import org.eclipse.jface.text.rules.IRule;
|
import org.eclipse.jface.text.rules.IRule;
|
||||||
import org.eclipse.jface.text.rules.IToken;
|
import org.eclipse.jface.text.rules.IToken;
|
||||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
|
||||||
import org.eclipse.jface.text.rules.WordPatternRule;
|
import org.eclipse.jface.text.rules.WordPatternRule;
|
||||||
import org.eclipse.jface.text.rules.WordRule;
|
import org.eclipse.jface.text.rules.WordRule;
|
||||||
|
|
||||||
|
@ -27,8 +26,8 @@ import org.eclipse.cdt.core.model.IAsmLanguage;
|
||||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CWhitespaceRule;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -66,11 +65,11 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
||||||
rules.add(new EndOfLineRule(new String(new char [] {lineCommentChars[i]}), token));
|
rules.add(new EndOfLineRule(new String(new char [] {lineCommentChars[i]}), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add generic whitespace rule.
|
|
||||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
|
||||||
|
|
||||||
final IToken other= getToken(ICColorConstants.C_DEFAULT);
|
final IToken other= getToken(ICColorConstants.C_DEFAULT);
|
||||||
|
|
||||||
|
// Add generic whitespace rule.
|
||||||
|
rules.add(new CWhitespaceRule(other));
|
||||||
|
|
||||||
// Add rule for labels
|
// Add rule for labels
|
||||||
token= getToken(ICColorConstants.ASM_LABEL);
|
token= getToken(ICColorConstants.ASM_LABEL);
|
||||||
IRule labelRule= new AsmLabelRule(new AsmWordDetector(false), token, other);
|
IRule labelRule= new AsmLabelRule(new AsmWordDetector(false), token, other);
|
||||||
|
|
|
@ -18,16 +18,14 @@ import org.eclipse.core.runtime.Assert;
|
||||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||||
import org.eclipse.jface.text.rules.IRule;
|
import org.eclipse.jface.text.rules.IRule;
|
||||||
import org.eclipse.jface.text.rules.IToken;
|
import org.eclipse.jface.text.rules.IToken;
|
||||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.IAsmLanguage;
|
import org.eclipse.cdt.core.model.IAsmLanguage;
|
||||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||||
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
|
import org.eclipse.cdt.internal.ui.text.CHeaderRule;
|
||||||
|
import org.eclipse.cdt.internal.ui.text.CWhitespaceRule;
|
||||||
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
import org.eclipse.cdt.internal.ui.text.ICColorConstants;
|
||||||
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
|
import org.eclipse.cdt.internal.ui.text.PreprocessorRule;
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +67,7 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
|
||||||
IToken token;
|
IToken token;
|
||||||
|
|
||||||
// Add generic white space rule.
|
// Add generic white space rule.
|
||||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
rules.add(new CWhitespaceRule(defaultToken));
|
||||||
|
|
||||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||||
PreprocessorRule preprocessorRule= new PreprocessorRule(new CWordDetector(), defaultToken, getToken(ICColorConstants.C_SINGLE_LINE_COMMENT));
|
PreprocessorRule preprocessorRule= new PreprocessorRule(new CWordDetector(), defaultToken, getToken(ICColorConstants.C_SINGLE_LINE_COMMENT));
|
||||||
|
|
|
@ -18,13 +18,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jface.text.rules.IRule;
|
import org.eclipse.jface.text.rules.IRule;
|
||||||
import org.eclipse.jface.text.rules.IToken;
|
import org.eclipse.jface.text.rules.IToken;
|
||||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
|
||||||
import org.eclipse.jface.text.rules.WordRule;
|
import org.eclipse.jface.text.rules.WordRule;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,11 +61,12 @@ public final class CCodeScanner extends AbstractCScanner {
|
||||||
List<IRule> rules= new ArrayList<IRule>();
|
List<IRule> rules= new ArrayList<IRule>();
|
||||||
IToken token;
|
IToken token;
|
||||||
|
|
||||||
|
token= getToken(ICColorConstants.C_DEFAULT);
|
||||||
|
|
||||||
// Add generic white space rule.
|
// Add generic white space rule.
|
||||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
rules.add(new CWhitespaceRule(token));
|
||||||
|
|
||||||
// Add word rule for keywords, types, and constants.
|
// Add word rule for keywords, types, and constants.
|
||||||
token= getToken(ICColorConstants.C_DEFAULT);
|
|
||||||
WordRule wordRule= new WordRule(new CWordDetector(), token);
|
WordRule wordRule= new WordRule(new CWordDetector(), token);
|
||||||
|
|
||||||
token= getToken(ICColorConstants.C_KEYWORD);
|
token= getToken(ICColorConstants.C_KEYWORD);
|
||||||
|
|
|
@ -17,13 +17,11 @@ import java.util.List;
|
||||||
import org.eclipse.jface.text.rules.IRule;
|
import org.eclipse.jface.text.rules.IRule;
|
||||||
import org.eclipse.jface.text.rules.IToken;
|
import org.eclipse.jface.text.rules.IToken;
|
||||||
import org.eclipse.jface.text.rules.PatternRule;
|
import org.eclipse.jface.text.rules.PatternRule;
|
||||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
|
||||||
import org.eclipse.jface.text.rules.WordRule;
|
import org.eclipse.jface.text.rules.WordRule;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
|
||||||
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +62,7 @@ public class CPreprocessorScanner extends AbstractCScanner {
|
||||||
IToken token;
|
IToken token;
|
||||||
|
|
||||||
// Add generic white space rule.
|
// Add generic white space rule.
|
||||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
rules.add(new CWhitespaceRule(defaultToken));
|
||||||
|
|
||||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||||
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), defaultToken);
|
PreprocessorRule preprocessorRule = new PreprocessorRule(new CWordDetector(), defaultToken);
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 Wind River Systems, Inc. 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:
|
||||||
|
* Wind River Systems - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.ui.text;
|
||||||
|
|
||||||
|
import org.eclipse.jface.text.rules.IToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple whitespace rule with configurable token.
|
||||||
|
*/
|
||||||
|
public class CWhitespaceRule extends SingleCharRule {
|
||||||
|
|
||||||
|
public CWhitespaceRule(IToken token) {
|
||||||
|
super(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isRuleChar(int ch) {
|
||||||
|
switch (ch) {
|
||||||
|
case ' ':
|
||||||
|
case '\t':
|
||||||
|
case '\r':
|
||||||
|
case '\n':
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
import org.eclipse.cdt.core.dom.ast.IMacroBinding;
|
||||||
import org.eclipse.cdt.core.dom.rewrite.MacroExpansionExplorer;
|
import org.eclipse.cdt.core.dom.rewrite.MacroExpansionExplorer;
|
||||||
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
@ -251,7 +252,11 @@ public class CMacroExpansionInput {
|
||||||
IEditorInput editorInput= editor.getEditorInput();
|
IEditorInput editorInput= editor.getEditorInput();
|
||||||
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||||
IWorkingCopy tu = manager.getWorkingCopy(editorInput);
|
IWorkingCopy tu = manager.getWorkingCopy(editorInput);
|
||||||
if (tu == null) {
|
try {
|
||||||
|
if (tu == null || !tu.isConsistent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (CModelException exc) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -606,7 +606,11 @@ public class CSourceHover extends AbstractCEditorTextHover {
|
||||||
IEditorInput input= editor.getEditorInput();
|
IEditorInput input= editor.getEditorInput();
|
||||||
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||||
IWorkingCopy copy = manager.getWorkingCopy(input);
|
IWorkingCopy copy = manager.getWorkingCopy(input);
|
||||||
if (copy == null) {
|
try {
|
||||||
|
if (copy == null || !copy.isConsistent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (CModelException exc) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
* Copyright (c) 2000, 2008 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -31,7 +31,7 @@ public class CWhitespaceDetector implements IWhitespaceDetector {
|
||||||
case '\n':
|
case '\n':
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return Character.isWhitespace(c);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue