diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java index f39048871d6..d92521dbe49 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java @@ -145,6 +145,9 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate { public void run() { ITranslationUnit tu= getTranslationUnit(); + if (tu == null) { + return; + } IIndex index; try { index = CCorePlugin.getIndexManager().getIndex(tu.getCProject(), IIndexManager.ADD_DEPENDENCIES); @@ -377,7 +380,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate { } public void update() { - setEnabled(true); + setEnabled(getTranslationUnit() != null); } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java index 67349fca3b3..059aef9d873 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/ToggleSourceAndHeaderAction.java @@ -195,14 +195,10 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction { * @see org.eclipse.jface.action.Action#run() */ public void run() { - IEditorPart editor = getTextEditor(); - if (editor == null) { + IWorkingCopy currentUnit= getWorkingCopy(); + if (currentUnit == null) { return; } - IEditorInput input= editor.getEditorInput(); - IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager(); - IWorkingCopy currentUnit= manager.getWorkingCopy(input); - ITranslationUnit partnerUnit= computePartnerFile(currentUnit); if (partnerUnit != null) { fgLastSourceUnit= currentUnit.getOriginalElement(); @@ -217,6 +213,23 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction { } } + private IWorkingCopy getWorkingCopy() { + IEditorPart editor = getTextEditor(); + if (editor == null) { + return null; + } + IEditorInput input= editor.getEditorInput(); + IWorkingCopyManager manager= CUIPlugin.getDefault().getWorkingCopyManager(); + return manager.getWorkingCopy(input); + } + + /* + * @see org.eclipse.ui.texteditor.TextEditorAction#update() + */ + public void update() { + setEnabled(getWorkingCopy() != null); + } + /** * Compute the corresponding translation unit for the given unit. * diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/GenerateActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/GenerateActionGroup.java index 0241a93d74b..980a60a01e1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/GenerateActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/GenerateActionGroup.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 @@ -469,6 +469,8 @@ public class GenerateActionGroup extends ActionGroup { } private int addAction(IMenuManager menu, IAction action) { + if (action instanceof IUpdate) + ((IUpdate)action).update(); if (action != null && action.isEnabled()) { menu.add(action); return 1;