mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Fix enabled state of editor actions in case of non-TUs
This commit is contained in:
parent
403e59ebed
commit
6871fd9ab5
3 changed files with 26 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue