mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 186729: Folding enablement does not always work reliable in CDT RC1
This commit is contained in:
parent
4cee9ce5a3
commit
d660f20353
4 changed files with 51 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2007 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
|
||||
|
@ -141,7 +141,7 @@ public class FoldingTest extends TestCase {
|
|||
return (Position[]) positions.toArray(new Position[positions.size()]);
|
||||
}
|
||||
|
||||
public void testFoldingPositions() throws BadLocationException {
|
||||
public void testInitialFolding() throws BadLocationException {
|
||||
Position[] actual= getFoldingPositions();
|
||||
Position[] expected= new Position[] {
|
||||
createPosition(0, 2),
|
||||
|
@ -170,4 +170,26 @@ public class FoldingTest extends TestCase {
|
|||
assertEqualPositions(expected, actual);
|
||||
}
|
||||
|
||||
public void testToggleFolding_Bug186729() throws BadLocationException {
|
||||
fEditor.getAction("FoldingToggle").run();
|
||||
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
|
||||
store.setValue(PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED, false);
|
||||
fEditor.getAction("FoldingToggle").run();
|
||||
|
||||
Position[] actual= getFoldingPositions();
|
||||
Position[] expected= new Position[] {
|
||||
createPosition(0, 2),
|
||||
createPosition(4, 7),
|
||||
createPosition(29, 31),
|
||||
createPosition(35, 40),
|
||||
createPosition(42, 46),
|
||||
createPosition(48, 55),
|
||||
createPosition(51, 53),
|
||||
createPosition(57, 59),
|
||||
createPosition(61, 63),
|
||||
createPosition(65, 67),
|
||||
};
|
||||
if (false) System.out.println(toString(actual));
|
||||
assertEqualPositions(expected, actual);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2000, 2007 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
|
||||
|
@ -38,6 +38,7 @@ public class FoldingActionGroup extends ActionGroup {
|
|||
private static abstract class PreferenceAction extends ResourceAction implements IUpdate {
|
||||
PreferenceAction(ResourceBundle bundle, String prefix, int style) {
|
||||
super(bundle, prefix, style);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1097,6 +1097,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
*/
|
||||
private ListenerList fReconcilingListeners= new ListenerList(ListenerList.IDENTITY);
|
||||
|
||||
/**
|
||||
* Flag indicating whether the reconciler is currently running.
|
||||
* @since 4.0
|
||||
*/
|
||||
private volatile boolean fIsReconciling;
|
||||
|
||||
/**
|
||||
* Semantic highlighting manager
|
||||
* @since 4.0
|
||||
|
@ -1526,7 +1532,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
* @since 4.0
|
||||
*/
|
||||
protected void synchronizeOutlinePage() {
|
||||
if(fOutlinePage != null && fOutlinePage.isLinkingEnabled()) {
|
||||
if(fOutlinePage != null && fOutlinePage.isLinkingEnabled() && !fIsReconciling) {
|
||||
fOutlinePage.removeSelectionChangedListener(this);
|
||||
fOutlinePage.synchronizeSelectionWithEditor();
|
||||
fOutlinePage.addSelectionChangedListener(this);
|
||||
|
@ -2510,7 +2516,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
* @since 4.0
|
||||
*/
|
||||
public void aboutToBeReconciled() {
|
||||
|
||||
fIsReconciling= true;
|
||||
|
||||
// Notify AST provider
|
||||
CUIPlugin.getDefault().getASTProvider().aboutToBeReconciled(getInputCElement());
|
||||
|
||||
|
@ -2526,7 +2533,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IC
|
|||
* @since 4.0
|
||||
*/
|
||||
public void reconciled(IASTTranslationUnit ast, IPositionConverter positionTracker, IProgressMonitor progressMonitor) {
|
||||
|
||||
fIsReconciling= false;
|
||||
|
||||
CUIPlugin cuiPlugin= CUIPlugin.getDefault();
|
||||
if (cuiPlugin == null)
|
||||
return;
|
||||
|
|
|
@ -112,10 +112,8 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
try {
|
||||
FoldingStructureComputationContext ctx= createContext(fInitialReconcilePending);
|
||||
fInitialReconcilePending= false;
|
||||
if (fPreprocessorBranchFoldingEnabled) {
|
||||
ctx.fAST= ast;
|
||||
ctx.fASTPositionConverter= positionTracker;
|
||||
}
|
||||
ctx.fAST= ast;
|
||||
ctx.fASTPositionConverter= positionTracker;
|
||||
update(ctx);
|
||||
} finally {
|
||||
fReconciling= false;
|
||||
|
@ -1067,7 +1065,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
computeFoldingStructure(ast, ctx);
|
||||
}
|
||||
}
|
||||
if (!fInitialReconcilePending) {
|
||||
if (!fInitialReconcilePending || isConsistent(fInput)) {
|
||||
IParent parent= (IParent) fInput;
|
||||
try {
|
||||
computeFoldingStructure(parent.getChildren(), ctx);
|
||||
|
@ -1075,7 +1073,17 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static boolean isConsistent(ICElement element) {
|
||||
if (element instanceof ITranslationUnit) {
|
||||
try {
|
||||
return ((ITranslationUnit)element).isConsistent();
|
||||
} catch (CModelException exc) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute folding structure of the preprocessor branches for the given AST.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue