diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java index cee355b87f1..73154175c44 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java @@ -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); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FoldingActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FoldingActionGroup.java index 019644b0ec7..adb31073c9c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FoldingActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FoldingActionGroup.java @@ -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(); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index cac83bbfcb2..037ffceb2db 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -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; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java index ff5f03877ec..ee8cdf33230 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java @@ -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. *