mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 14:15:23 +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
|
||||
*/
|
||||
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;
|
||||
|
||||
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.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.cdt.ui.actions.CustomFiltersActionGroup;
|
||||
import org.eclipse.cdt.ui.actions.MemberFilterActionGroup;
|
||||
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 {
|
||||
|
||||
private Composite fParent;
|
||||
private StackLayout fStackLayout;
|
||||
private Composite fOutlinePage;
|
||||
private Control fStatusPage;
|
||||
private boolean fScalabilityMode;
|
||||
|
||||
public CContentOutlinePage(CEditor editor) {
|
||||
super("#TranslationUnitOutlinerContext", editor); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -40,6 +54,60 @@ public class CContentOutlinePage extends AbstractCModelOutlinePage {
|
|||
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
|
||||
protected SelectionSearchGroup createSearchActionGroup() {
|
||||
return new SelectionSearchGroup(this);
|
||||
|
|
|
@ -107,6 +107,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.search.ui.actions.TextSearchGroup;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.BusyIndicator;
|
||||
import org.eclipse.swt.custom.ST;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.custom.VerifyKeyListener;
|
||||
|
@ -1290,20 +1291,27 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
if (!(sourceViewer instanceof ISourceViewerExtension2)) {
|
||||
setPreferenceStore(createCombinedPreferenceStore(input));
|
||||
internalDoSetInput(input);
|
||||
updateScalabilityMode(input);
|
||||
return;
|
||||
}
|
||||
|
||||
// uninstall & unregister preference store listener
|
||||
getSourceViewerDecorationSupport(sourceViewer).uninstall();
|
||||
((ISourceViewerExtension2)sourceViewer).unconfigure();
|
||||
getDocumentProvider().connect(input);
|
||||
try {
|
||||
// uninstall & unregister preference store listener
|
||||
getSourceViewerDecorationSupport(sourceViewer).uninstall();
|
||||
((ISourceViewerExtension2)sourceViewer).unconfigure();
|
||||
|
||||
setPreferenceStore(createCombinedPreferenceStore(input));
|
||||
setPreferenceStore(createCombinedPreferenceStore(input));
|
||||
updateScalabilityMode(input);
|
||||
|
||||
// install & register preference store listener
|
||||
sourceViewer.configure(getSourceViewerConfiguration());
|
||||
getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
|
||||
// install & register preference store listener
|
||||
sourceViewer.configure(getSourceViewerConfiguration());
|
||||
getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
|
||||
|
||||
internalDoSetInput(input);
|
||||
internalDoSetInput(input);
|
||||
} finally {
|
||||
getDocumentProvider().disconnect(input);
|
||||
}
|
||||
}
|
||||
|
||||
private void internalDoSetInput(IEditorInput input) throws CoreException {
|
||||
|
@ -1333,12 +1341,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
} else {
|
||||
fBracketMatcher.configure(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void updateScalabilityMode(IEditorInput input) {
|
||||
int lines = getDocumentProvider().getDocument(input).getNumberOfLines();
|
||||
if (lines > getPreferenceStore().getInt(PreferenceConstants.SCALABILITY_NUMBER_OF_LINES)) {
|
||||
//Detecting if scalability mode should be turned on
|
||||
fEnableScalablilityMode = true;
|
||||
|
||||
boolean wasEnabled = fEnableScalablilityMode;
|
||||
fEnableScalablilityMode = lines > getPreferenceStore().getInt(PreferenceConstants.SCALABILITY_NUMBER_OF_LINES);
|
||||
if (fEnableScalablilityMode && !wasEnabled) {
|
||||
//Alert users that scalability mode should be turned on
|
||||
if (getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_ALERT)) {
|
||||
MessageDialogWithToggle dialog = new MessageDialogWithToggle(
|
||||
|
@ -1412,8 +1421,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
* @return Outline page.
|
||||
*/
|
||||
public CContentOutlinePage getOutlinePage() {
|
||||
if (isEnableScalablilityMode() && getPreferenceStore().getBoolean(PreferenceConstants.SCALABILITY_RECONCILER))
|
||||
return null;
|
||||
if (fOutlinePage == null) {
|
||||
fOutlinePage = new CContentOutlinePage(this);
|
||||
fOutlinePage.addSelectionChangedListener(this);
|
||||
|
@ -1494,7 +1501,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
}
|
||||
|
||||
try {
|
||||
AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
||||
final AdaptedSourceViewer asv = (AdaptedSourceViewer) getSourceViewer();
|
||||
|
||||
if (asv != null) {
|
||||
|
||||
|
@ -1529,12 +1536,14 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
} else {
|
||||
removeActionActivationCode("IndentOnTab"); //$NON-NLS-1$
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (TODO_TASK_TAGS.equals(event.getProperty())) {
|
||||
ISourceViewer sourceViewer = getSourceViewer();
|
||||
if (sourceViewer != null && affectsTextPresentation(event))
|
||||
sourceViewer.invalidateTextPresentation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (PreferenceConstants.EDITOR_FOLDING_PROVIDER.equals(property)) {
|
||||
|
@ -1595,8 +1604,13 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
if (isEnableScalablilityMode()) {
|
||||
if (PreferenceConstants.SCALABILITY_RECONCILER.equals(property) ||
|
||||
PreferenceConstants.SCALABILITY_SYNTAX_COLOR.equals(property)) {
|
||||
asv.unconfigure();
|
||||
asv.configure(getSourceViewerConfiguration());
|
||||
BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
|
||||
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.info=Editor Scalability
|
||||
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.label=Show in C/C++ Projects
|
||||
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.IRule;
|
||||
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.WordRule;
|
||||
|
||||
|
@ -27,8 +26,8 @@ import org.eclipse.cdt.core.model.IAsmLanguage;
|
|||
import org.eclipse.cdt.ui.text.ITokenStoreFactory;
|
||||
|
||||
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.util.CWhitespaceDetector;
|
||||
|
||||
|
||||
/*
|
||||
|
@ -66,11 +65,11 @@ public final class AsmCodeScanner extends AbstractCScanner {
|
|||
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);
|
||||
|
||||
// Add generic whitespace rule.
|
||||
rules.add(new CWhitespaceRule(other));
|
||||
|
||||
// Add rule for labels
|
||||
token= getToken(ICColorConstants.ASM_LABEL);
|
||||
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.IRule;
|
||||
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.ui.text.ITokenStoreFactory;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.AbstractCScanner;
|
||||
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.PreprocessorRule;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CWhitespaceDetector;
|
||||
import org.eclipse.cdt.internal.ui.text.util.CWordDetector;
|
||||
|
||||
/**
|
||||
|
@ -69,7 +67,7 @@ public class AsmPreprocessorScanner extends AbstractCScanner {
|
|||
IToken token;
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
rules.add(new CWhitespaceRule(defaultToken));
|
||||
|
||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||
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.IToken;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||
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;
|
||||
|
||||
|
||||
|
@ -63,11 +61,12 @@ public final class CCodeScanner extends AbstractCScanner {
|
|||
List<IRule> rules= new ArrayList<IRule>();
|
||||
IToken token;
|
||||
|
||||
token= getToken(ICColorConstants.C_DEFAULT);
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
rules.add(new CWhitespaceRule(token));
|
||||
|
||||
// Add word rule for keywords, types, and constants.
|
||||
token= getToken(ICColorConstants.C_DEFAULT);
|
||||
WordRule wordRule= new WordRule(new CWordDetector(), token);
|
||||
|
||||
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.IToken;
|
||||
import org.eclipse.jface.text.rules.PatternRule;
|
||||
import org.eclipse.jface.text.rules.WhitespaceRule;
|
||||
import org.eclipse.jface.text.rules.WordRule;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICLanguageKeywords;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -64,7 +62,7 @@ public class CPreprocessorScanner extends AbstractCScanner {
|
|||
IToken token;
|
||||
|
||||
// Add generic white space rule.
|
||||
rules.add(new WhitespaceRule(new CWhitespaceDetector()));
|
||||
rules.add(new CWhitespaceRule(defaultToken));
|
||||
|
||||
token= getToken(ICColorConstants.PP_DIRECTIVE);
|
||||
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.IMacroBinding;
|
||||
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.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
|
@ -251,7 +252,11 @@ public class CMacroExpansionInput {
|
|||
IEditorInput editorInput= editor.getEditorInput();
|
||||
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||
IWorkingCopy tu = manager.getWorkingCopy(editorInput);
|
||||
if (tu == null) {
|
||||
try {
|
||||
if (tu == null || !tu.isConsistent()) {
|
||||
return null;
|
||||
}
|
||||
} catch (CModelException exc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -606,7 +606,11 @@ public class CSourceHover extends AbstractCEditorTextHover {
|
|||
IEditorInput input= editor.getEditorInput();
|
||||
IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||
IWorkingCopy copy = manager.getWorkingCopy(input);
|
||||
if (copy == null) {
|
||||
try {
|
||||
if (copy == null || !copy.isConsistent()) {
|
||||
return null;
|
||||
}
|
||||
} catch (CModelException exc) {
|
||||
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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -31,7 +31,7 @@ public class CWhitespaceDetector implements IWhitespaceDetector {
|
|||
case '\n':
|
||||
return true;
|
||||
default:
|
||||
return Character.isWhitespace(c);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue