blob: 962fde48f7246dbfbc2c8572162c7e8768f4ccfc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* Copyright (c) 2000, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.views.framelist.BackAction;
import org.eclipse.ui.views.framelist.ForwardAction;
import org.eclipse.ui.views.framelist.FrameList;
import org.eclipse.ui.views.framelist.GoIntoAction;
import org.eclipse.ui.views.framelist.UpAction;
/**
* This is the action group for the goto actions.
*/
public class GotoActionGroup extends CViewActionGroup {
private BackAction backAction;
private ForwardAction forwardAction;
private GoIntoAction goIntoAction;
private UpAction upAction;
public GotoActionGroup(CView cview) {
super(cview);
}
@Override
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection celements = (IStructuredSelection) getContext().getSelection();
IStructuredSelection selection = SelectionConverter.convertSelectionToResources(celements);
if (selection.size() == 1) {
if (SelectionConverter.allResourcesAreOfType(selection, IResource.FOLDER)) {
menu.add(goIntoAction);
} else {
IStructuredSelection resourceSelection = SelectionConverter.allResources(selection, IResource.PROJECT);
if (resourceSelection != null && !resourceSelection.isEmpty()) {
IProject project = (IProject) resourceSelection.getFirstElement();
if (project.isOpen()) {
menu.add(goIntoAction);
}
}
}
}
}
@Override
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(IWorkbenchActionConstants.GO_INTO, goIntoAction);
actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), backAction);
actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), forwardAction);
actionBars.setGlobalActionHandler(IWorkbenchActionConstants.UP, upAction);
IToolBarManager toolBar = actionBars.getToolBarManager();
toolBar.add(backAction);
toolBar.add(forwardAction);
toolBar.add(upAction);
}
@Override
protected void makeActions() {
FrameList frameList = getCView().getFrameList();
goIntoAction = new GoIntoAction(frameList);
backAction = new BackAction(frameList);
forwardAction = new ForwardAction(frameList);
upAction = new UpAction(frameList);
}
/* (non-Javadoc)
*/
@Override
public void updateActionBars() {
ActionContext context = getContext();
boolean enable = false;
// Fix for bug 26126. Resource change listener could call
// updateActionBars without a context being set.
// This should never happen because resource navigator sets
// context immediately after this group is created.
if (context != null) {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
if (selection.size() == 1) {
Object object = selection.getFirstElement();
if (object instanceof IAdaptable) {
IResource resource = ((IAdaptable)object).getAdapter(IResource.class);
if (resource instanceof IProject) {
enable = ((IProject) resource).isOpen();
} else if (resource instanceof IFolder) {
enable = true;
}
}
}
}
goIntoAction.setEnabled(enable);
// the rest of the actions update by listening to frame list changes
}
}
|