|
Lines 480-501
Link Here
|
| 480 |
} |
480 |
} |
| 481 |
return null; |
481 |
return null; |
| 482 |
} |
482 |
} |
| 483 |
|
483 |
|
| 484 |
private void execute(IWorkbenchWindow activeWorkbenchWindow, |
484 |
/* (non-Javadoc) |
| 485 |
IWorkbenchPart part, ISelection selection) |
485 |
* @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object) |
| 486 |
throws InvocationTargetException, InterruptedException { |
486 |
*/ |
|
|
487 |
public void setEnabled(Object evaluationContext) { |
| 488 |
IWorkbenchWindow activeWorkbenchWindow = (IWorkbenchWindow) HandlerUtil |
| 489 |
.getVariable(evaluationContext, |
| 490 |
ISources.ACTIVE_WORKBENCH_WINDOW_NAME); |
| 491 |
if (activeWorkbenchWindow != null) { |
| 492 |
ISelection selection = (ISelection) HandlerUtil.getVariable( |
| 493 |
evaluationContext, ISources.ACTIVE_CURRENT_SELECTION_NAME); |
| 494 |
if (selection == null) { |
| 495 |
selection = StructuredSelection.EMPTY; |
| 496 |
} |
| 497 |
IWorkbenchPart part = (IWorkbenchPart) HandlerUtil.getVariable( |
| 498 |
evaluationContext, ISources.ACTIVE_PART_NAME); |
| 499 |
updateSelection(activeWorkbenchWindow, part, selection); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Allows subclasses to check for ResourceMappings or CVS related inputs. |
| 505 |
* |
| 506 |
* @param input the editor input to consider for selection. |
| 507 |
*/ |
| 508 |
protected void updateInput(IEditorInput input) { |
| 509 |
IFile file = ResourceUtil.getFile(input); |
| 510 |
if (file != null) { |
| 511 |
selectionChanged((IAction) null, new StructuredSelection(file)); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
private void updateSelection(IWorkbenchWindow activeWorkbenchWindow, |
| 516 |
IWorkbenchPart part, ISelection selection) { |
| 487 |
// If the action is run from within an editor, try and find the |
517 |
// If the action is run from within an editor, try and find the |
| 488 |
// file for the given editor. |
518 |
// file for the given editor. |
| 489 |
if (part != null && part instanceof IEditorPart) { |
519 |
if (part != null && part instanceof IEditorPart) { |
| 490 |
IEditorInput input = ((IEditorPart) part).getEditorInput(); |
520 |
IEditorInput input = ((IEditorPart) part).getEditorInput(); |
| 491 |
IFile file = ResourceUtil.getFile(input); |
521 |
updateInput(input); |
| 492 |
if (file != null) { |
|
|
| 493 |
selectionChanged((IAction) null, new StructuredSelection(file)); |
| 494 |
} |
| 495 |
} else { |
522 |
} else { |
| 496 |
// Fallback is to prime the action with the selection |
523 |
// Fallback is to prime the action with the selection |
| 497 |
selectionChanged((IAction) null, selection); |
524 |
selectionChanged((IAction) null, selection); |
| 498 |
} |
525 |
} |
|
|
526 |
} |
| 527 |
|
| 528 |
private void execute(IWorkbenchWindow activeWorkbenchWindow, |
| 529 |
IWorkbenchPart part, ISelection selection) |
| 530 |
throws InvocationTargetException, InterruptedException { |
| 531 |
updateSelection(activeWorkbenchWindow, part, selection); |
| 499 |
// Safe guard to ensure that the action is only run when enabled. |
532 |
// Safe guard to ensure that the action is only run when enabled. |
| 500 |
if (isEnabled()) { |
533 |
if (isEnabled()) { |
| 501 |
execute((IAction) null); |
534 |
execute((IAction) null); |