1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Reorganize the actions of the cview into groups.

This commit is contained in:
Alain Magloire 2004-02-16 01:36:28 +00:00
parent 39a6ce2544
commit 47f1f6f040
11 changed files with 1291 additions and 691 deletions

View file

@ -1,3 +1,15 @@
2004-02-15 Alain Magloire
Reorganize the action of the CView and distribute them
in different action group.
New files:
* src/org/eclipse/cdt/internal/ui/cview/Buildgroup.java
* src/org/eclipse/cdt/internal/ui/cview/OpenFileGroup.java
* src/org/eclipse/cdt/internal/ui/cview/OpenProjectGroup.java
* src/org/eclipse/cdt/internal/ui/cview/SelectionConverter.java
* src/org/eclipse/cdt/internal/ui/cview/GotoActionGroup.java
2004-02-12 John Camelon 2004-02-12 John Camelon
Updated Content Assist feature to not use IASTCompletionKind.SCOPED_REFERENCE Updated Content Assist feature to not use IASTCompletionKind.SCOPED_REFERENCE

View file

@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials!
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import java.util.Iterator;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.BuildAction;
import org.eclipse.ui.ide.IDEActionFactory;
/**
* This is the action group for workspace actions such as Build
*/
public class BuildGroup extends CViewActionGroup {
private BuildAction buildAction;
private BuildAction rebuildAction;
// Menu tags for the build
final String BUILD_GROUP_MARKER = "buildGroup";
final String BUILD_GROUP_MARKER_END = "end-buildGroup";
public BuildGroup(CView cview) {
super(cview);
}
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(IDEActionFactory.BUILD.getId(), buildAction);
actionBars.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), rebuildAction);
}
/**
* Adds the build actions to the context menu.
* <p>
* The following conditions apply: build-only projects selected, auto build
* disabled, at least one * builder present
* </p>
* <p>
* No disabled action should be on the context menu.
* </p>
*
* @param menu
* context menu to add actions to
*/
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
boolean isProjectSelection = true;
boolean hasOpenProjects = false;
boolean hasClosedProjects = false;
boolean hasBuilder = true; // false if any project is closed or does
// not have builder
menu.add(new GroupMarker(BUILD_GROUP_MARKER));
Iterator resources = selection.iterator();
while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || hasBuilder || isProjectSelection)) {
Object next = resources.next();
IProject project = null;
if (next instanceof IProject) {
project = (IProject) next;
} else if (next instanceof IAdaptable) {
project = (IProject) ((IAdaptable) next).getAdapter(IProject.class);
}
if (project == null) {
isProjectSelection = false;
continue;
}
if (project.isOpen()) {
hasOpenProjects = true;
if (hasBuilder && !hasBuilder(project)) {
hasBuilder = false;
}
} else {
hasClosedProjects = true;
hasBuilder = false;
}
}
// Allow manual incremental build only if auto build is off.
//if (!selection.isEmpty() && isProjectSelection
// && !ResourcesPlugin.getWorkspace().isAutoBuilding()
// && hasBuilder) {
if (!selection.isEmpty() && isProjectSelection && hasBuilder) {
buildAction.selectionChanged(selection);
menu.add(buildAction);
rebuildAction.selectionChanged(selection);
menu.add(rebuildAction);
}
menu.add(new GroupMarker(BUILD_GROUP_MARKER_END));
}
/**
* Handles a key pressed event by invoking the appropriate action.
*/
public void handleKeyPressed(KeyEvent event) {
}
/**
* Returns whether there are builders configured on the given project.
*
* @return <code>true</code> if it has builders, <code>false</code> if
* not, or if this could not be determined
*/
boolean hasBuilder(IProject project) {
try {
ICommand[] commands = project.getDescription().getBuildSpec();
if (commands.length > 0) return true;
} catch (CoreException e) {
// Cannot determine if project has builders. Project is closed
// or does not exist. Fall through to return false.
}
return false;
}
protected void makeActions() {
Shell shell = getCView().getSite().getShell();
buildAction = new BuildAction(shell, IncrementalProjectBuilder.INCREMENTAL_BUILD);
rebuildAction = new BuildAction(shell, IncrementalProjectBuilder.FULL_BUILD);
}
public void updateActionBars() {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
buildAction.selectionChanged(selection);
rebuildAction.selectionChanged(selection);
}
}

View file

@ -1,13 +1,10 @@
package org.eclipse.cdt.internal.ui.cview; package org.eclipse.cdt.internal.ui.cview;
/* /*
* (c) Copyright QNX Software Systems Ltd. 2002. * (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved.
* All Rights Reserved.
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
@ -40,7 +37,6 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
@ -52,11 +48,13 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelDecorator; import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeViewerListener; import org.eclipse.jface.viewers.ITreeViewerListener;
import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeExpansionEvent;
@ -69,6 +67,8 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Tree;
@ -85,7 +85,6 @@ import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ResourceWorkingSetFilter; import org.eclipse.ui.ResourceWorkingSetFilter;
import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
import org.eclipse.ui.part.ISetSelectionTarget; import org.eclipse.ui.part.ISetSelectionTarget;
import org.eclipse.ui.part.IShowInTarget; import org.eclipse.ui.part.IShowInTarget;
import org.eclipse.ui.part.PluginTransfer; import org.eclipse.ui.part.PluginTransfer;
@ -100,25 +99,22 @@ import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
* CView * CView
* *
*/ */
public class CView extends ViewPart implements ISetSelectionTarget, public class CView extends ViewPart implements ISetSelectionTarget, IPropertyChangeListener, IShowInTarget {
IPropertyChangeListener, IShowInTarget {
ProblemTreeViewer viewer; ProblemTreeViewer viewer;
IMemento memento; IMemento memento;
CViewActionGroup actionGroup; CViewActionGroup actionGroup;
WorkingSetFilterActionGroup wsFilterActionGroup;
FrameList frameList; FrameList frameList;
CViewFrameSource frameSource; CViewFrameSource frameSource;
CLibFilter clibFilter = new CLibFilter(); CLibFilter clibFilter = new CLibFilter();
CPatternFilter patternFilter = new CPatternFilter(); CPatternFilter patternFilter = new CPatternFilter();
ResourceWorkingSetFilter workingSetFilter = new ResourceWorkingSetFilter(); ResourceWorkingSetFilter workingSetFilter = new ResourceWorkingSetFilter();
ActionContributionItem adjustWorkingSetContributions [] = new ActionContributionItem[5]; private boolean dragDetected;
private Listener dragDetectListener;
// Persistance tags. // Persistance tags.
static final String TAG_SELECTION = "selection"; //$NON-NLS-1$ static final String TAG_SELECTION = "selection"; //$NON-NLS-1$
@ -138,45 +134,43 @@ public class CView extends ViewPart implements ISetSelectionTarget,
final String WORKING_GROUP_MARKER_END = "end-workingSetGroup"; final String WORKING_GROUP_MARKER_END = "end-workingSetGroup";
private IPartListener partListener = new IPartListener() { private IPartListener partListener = new IPartListener() {
public void partActivated(IWorkbenchPart part) { public void partActivated(IWorkbenchPart part) {
if (part instanceof IEditorPart) { if (part instanceof IEditorPart) {
editorActivated((IEditorPart) part); editorActivated((IEditorPart) part);
} }
} }
public void partBroughtToTop(IWorkbenchPart part) {}
public void partClosed(IWorkbenchPart part) {} public void partBroughtToTop(IWorkbenchPart part) {
public void partDeactivated(IWorkbenchPart part) {} }
public void partOpened(IWorkbenchPart part) {}
public void partClosed(IWorkbenchPart part) {
}
public void partDeactivated(IWorkbenchPart part) {
}
public void partOpened(IWorkbenchPart part) {
}
}; };
private IPropertyChangeListener workingSetListener = new IPropertyChangeListener() { private IPropertyChangeListener workingSetListener = new IPropertyChangeListener() {
private void doViewerUpdate() {
viewer.getControl().setRedraw(false);
viewer.refresh();
viewer.getControl().setRedraw(true);
}
public void propertyChange(PropertyChangeEvent ev) { public void propertyChange(PropertyChangeEvent ev) {
String prop = ev.getProperty(); String property = ev.getProperty();
if(prop == null) { Object newValue = ev.getNewValue();
Object oldValue = ev.getOldValue();
IWorkingSet filterWorkingSet = workingSetFilter.getWorkingSet();
if (property == null) {
return; return;
} }
if(prop.equals(WorkingSetFilterActionGroup.CHANGE_WORKING_SET)) { if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(property) && oldValue == filterWorkingSet) {
workingSetFilter.setWorkingSet((IWorkingSet)ev.getNewValue()); setWorkingSet(null);
doViewerUpdate(); } else if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property) && newValue == filterWorkingSet) {
} else if(prop.equals(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE)){ updateTitle();
if(ev.getOldValue() instanceof IWorkingSet && workingSetFilter.getWorkingSet() != null) { } else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property) && newValue == filterWorkingSet) {
if(workingSetFilter.getWorkingSet().equals(ev.getOldValue())) { getViewer().refresh();
doViewerUpdate();
}
}
} else if(prop.equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE)) {
if(ev.getOldValue() instanceof IWorkingSet && workingSetFilter.getWorkingSet() != null) {
if(workingSetFilter.getWorkingSet().equals(ev.getOldValue())) {
workingSetFilter.setWorkingSet(null);
doViewerUpdate();
}
}
} }
} }
}; };
@ -194,17 +188,20 @@ public class CView extends ViewPart implements ISetSelectionTarget,
} }
/** /**
* Reveal and select the passed element selection in self's visual component * Reveal and select the passed element selection in self's visual
* component
*
* @see ISetSelectionTarget#selectReveal() * @see ISetSelectionTarget#selectReveal()
*/ */
public void selectReveal(ISelection selection) { public void selectReveal(ISelection selection) {
IStructuredSelection ssel = convertSelectionToCElement(selection); IStructuredSelection ssel = SelectionConverter.convertSelectionToCElements(selection);
if (!ssel.isEmpty()) { if (!ssel.isEmpty()) {
getViewer().setSelection(ssel, true); getViewer().setSelection(ssel, true);
} }
} }
private ITreeViewerListener expansionListener = new ITreeViewerListener() { private ITreeViewerListener expansionListener = new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) { public void treeCollapsed(TreeExpansionEvent event) {
} }
@ -215,6 +212,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
Control ctrl = viewer.getControl(); Control ctrl = viewer.getControl();
if (ctrl != null && !ctrl.isDisposed()) { if (ctrl != null && !ctrl.isDisposed()) {
ctrl.getDisplay().asyncExec(new Runnable() { ctrl.getDisplay().asyncExec(new Runnable() {
public void run() { public void run() {
Control ctrl = viewer.getControl(); Control ctrl = viewer.getControl();
if (ctrl != null && !ctrl.isDisposed()) { if (ctrl != null && !ctrl.isDisposed()) {
@ -228,13 +226,25 @@ public class CView extends ViewPart implements ISetSelectionTarget,
}; };
/** /**
* Handles double clicks in viewer. * Handles an open event from the viewer.
* Opens editor if file double-clicked. * Opens an editor on the selected file.
*
* @param event the open event
*/
protected void handleOpen(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
getActionGroup().runDefaultAction(selection);
}
/**
* Handles double clicks in viewer. Opens editor if file double-clicked.
*/ */
protected void handleDoubleClick(DoubleClickEvent event) { protected void handleDoubleClick(DoubleClickEvent event) {
IStructuredSelection s = (IStructuredSelection) event.getSelection(); IStructuredSelection s = (IStructuredSelection) event.getSelection();
IAdaptable element = (IAdaptable)s.getFirstElement();
IEditorPart part = null; IEditorPart part = null;
Object o = s.getFirstElement();
if (o instanceof IAdaptable) {
IAdaptable element = (IAdaptable) o;
//System.out.println ("Double click on " + element); //System.out.println ("Double click on " + element);
try { try {
@ -248,8 +258,9 @@ public class CView extends ViewPart implements ISetSelectionTarget,
} }
} catch (Exception e) { } catch (Exception e) {
} }
if (part == null && viewer.isExpandable(element)) { }
viewer.setExpandedState(element, !viewer.getExpandedState(element)); if (part == null && viewer.isExpandable(o)) {
viewer.setExpandedState(o, !viewer.getExpandedState(o));
} }
} }
@ -267,20 +278,33 @@ public class CView extends ViewPart implements ISetSelectionTarget,
* *
*/ */
protected void handleKeyReleased(KeyEvent event) { protected void handleKeyReleased(KeyEvent event) {
if (getActionGroup() != null) {
getActionGroup().handleKeyReleased(event);
}
} }
/** /**
* Handles selection changed in viewer. * Handles selection changed in viewer. Updates global actions. Links to
* Updates global actions. * editor (if option enabled)
* Links to editor (if option enabled)
*/ */
void handleSelectionChanged(SelectionChangedEvent event) { void handleSelectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection(); final IStructuredSelection selection = (IStructuredSelection) event.getSelection();
updateStatusLine(sel); updateStatusLine(selection);
if (getActionGroup() != null) { updateActionBars(selection);
getActionGroup().runDefaultAction(sel); dragDetected = false;
if (isLinkingEnabled()) {
getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
if (dragDetected == false) {
// only synchronize with editor when the selection is
// not the result
// of a drag. Fixes bug 22274.
linkToEditor(selection);
}
}
});
} }
linkToEditor(sel);
} }
/** /**
@ -295,7 +319,8 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Sets the action group. * Sets the action group.
* *
* @param actionGroup the action group * @param actionGroup
* the action group
*/ */
protected void setActionGroup(CViewActionGroup actionGroup) { protected void setActionGroup(CViewActionGroup actionGroup) {
this.actionGroup = actionGroup; this.actionGroup = actionGroup;
@ -305,13 +330,12 @@ public class CView extends ViewPart implements ISetSelectionTarget,
* Answer the property defined by key. * Answer the property defined by key.
*/ */
public Object getAdapter(Class key) { public Object getAdapter(Class key) {
if (key.equals(ISelectionProvider.class)) if (key.equals(ISelectionProvider.class)) return viewer;
return viewer;
return super.getAdapter(key); return super.getAdapter(key);
} }
/* (non-Javadoc) /*
* Method declared on IViewPart. * (non-Javadoc) Method declared on IViewPart.
*/ */
public void init(IViewSite site, IMemento memento) throws PartInitException { public void init(IViewSite site, IMemento memento) throws PartInitException {
super.init(site, memento); super.init(site, memento);
@ -337,7 +361,8 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Adds the filters to the viewer. * Adds the filters to the viewer.
* *
* @param viewer the viewer * @param viewer
* the viewer
*/ */
void initFilters(TreeViewer viewer) { void initFilters(TreeViewer viewer) {
viewer.addFilter(patternFilter); viewer.addFilter(patternFilter);
@ -351,29 +376,25 @@ public class CView extends ViewPart implements ISetSelectionTarget,
void initDragAndDrop() { void initDragAndDrop() {
int ops = DND.DROP_COPY | DND.DROP_MOVE; int ops = DND.DROP_COPY | DND.DROP_MOVE;
Transfer[] dragTransfers = Transfer[] dragTransfers = new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(),
new Transfer[] { CLocalSelectionTransfer.getInstance(), PluginTransfer.getInstance()};
ResourceTransfer.getInstance(),
FileTransfer.getInstance(),
CLocalSelectionTransfer.getInstance(),
PluginTransfer.getInstance()};
TransferDragSourceListener[] dragListeners = TransferDragSourceListener[] dragListeners = new TransferDragSourceListener[] { new ResourceTransferDragAdapter(viewer),
new TransferDragSourceListener[] { new LocalSelectionTransferDragAdapter(viewer), new FileTransferDragAdapter(viewer)};
new ResourceTransferDragAdapter(viewer),
new LocalSelectionTransferDragAdapter(viewer),
new FileTransferDragAdapter(viewer)};
viewer.addDragSupport(ops, dragTransfers, new DelegatingDragAdapter(viewer, dragListeners)); viewer.addDragSupport(ops, dragTransfers, new DelegatingDragAdapter(viewer, dragListeners));
Transfer[] dropTransfers = Transfer[] dropTransfers = new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(),
new Transfer[] { LocalSelectionTransfer.getInstance(), PluginTransfer.getInstance()};
ResourceTransfer.getInstance(),
FileTransfer.getInstance(),
LocalSelectionTransfer.getInstance(),
PluginTransfer.getInstance()};
viewer.addDropSupport(ops, dropTransfers, new CViewDropAdapter(viewer)); viewer.addDropSupport(ops, dropTransfers, new CViewDropAdapter(viewer));
dragDetectListener = new Listener() {
public void handleEvent(Event event) {
dragDetected = true;
}
};
viewer.getControl().addListener(SWT.DragDetect, dragDetectListener);
} }
@ -410,8 +431,6 @@ public class CView extends ViewPart implements ISetSelectionTarget,
viewer.setLabelProvider(new DecoratingLabelProvider(cProvider, decorator)); viewer.setLabelProvider(new DecoratingLabelProvider(cProvider, decorator));
} }
/** /**
* Initializes and registers the context menu. * Initializes and registers the context menu.
*/ */
@ -419,6 +438,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true); menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() { menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) { public void menuAboutToShow(IMenuManager manager) {
CView.this.fillContextMenu(manager); CView.this.fillContextMenu(manager);
} }
@ -429,26 +449,60 @@ public class CView extends ViewPart implements ISetSelectionTarget,
getSite().registerContextMenu(menuMgr, viewer); getSite().registerContextMenu(menuMgr, viewer);
} }
/**
* Restores the working set filter from the persistence store.
*/
void initWorkingSetFilter() {
// FIXME: the memento does not work if we close the view
// and reopen we should save this somewhere else.
// but it goes to pretty much all the settings 8-(
if (memento == null) {
return;
}
String wsname = memento.getString(TAG_WORKINGSET);
if (wsname != null && wsname.equals("") == false) { //$NON-NLS-1$
IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager();
IWorkingSet workingSet = wsmanager.getWorkingSet(wsname);
if (workingSet != null) {
// Only initialize filter. Don't set working set into viewer.
// Working set is set via WorkingSetFilterActionGroup
// during action creation.
workingSetFilter.setWorkingSet(workingSet);
}
}
}
/** /**
* Add listeners to the viewer. * Add listeners to the viewer.
*/ */
protected void initListeners(TreeViewer viewer) { protected void initListeners(TreeViewer viewer) {
viewer.addDoubleClickListener(new IDoubleClickListener() { viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) { public void doubleClick(DoubleClickEvent event) {
handleDoubleClick(event); handleDoubleClick(event);
} }
}); });
viewer.addSelectionChangedListener(new ISelectionChangedListener() { viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) { public void selectionChanged(SelectionChangedEvent event) {
handleSelectionChanged(event); handleSelectionChanged(event);
} }
}); });
viewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
handleOpen(event);
}
});
viewer.getControl().addKeyListener(new KeyAdapter() { viewer.getControl().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
handleKeyPressed(e); handleKeyPressed(e);
} }
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
handleKeyReleased(e); handleKeyReleased(e);
} }
@ -467,19 +521,20 @@ public class CView extends ViewPart implements ISetSelectionTarget,
CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer); CUIPlugin.getDefault().getProblemMarkerManager().addListener(viewer);
CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
initFilters(viewer);
initListeners(viewer);
initCElementSorter();
initFrameList();
initDragAndDrop();
updateTitle();
if (memento != null) { if (memento != null) {
restoreFilters(); restoreFilters();
} else { } else {
initFilterFromPreferences(); initFilterFromPreferences();
} }
initFilters(viewer);
initWorkingSetFilter();
initListeners(viewer);
initCElementSorter();
initFrameList();
initDragAndDrop();
updateTitle();
viewer.setInput(CoreModel.getDefault().getCModel()); viewer.setInput(CoreModel.getDefault().getCModel());
initContextMenu(); initContextMenu();
@ -487,7 +542,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
// Make the Actions for the Context Menu // Make the Actions for the Context Menu
makeActions(); makeActions();
getActionGroup().fillActionBars(getViewSite().getActionBars()); getActionGroup().fillActionBars(getViewSite().getActionBars());
updateActionBars((IStructuredSelection) viewer.getSelection());
//Add the property changes after all of the UI work has been done. //Add the property changes after all of the UI work has been done.
IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager(); IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager();
@ -498,8 +553,9 @@ public class CView extends ViewPart implements ISetSelectionTarget,
getSite().setSelectionProvider(viewer); getSite().setSelectionProvider(viewer);
getSite().getPage().addPartListener(partListener); getSite().getPage().addPartListener(partListener);
if (memento != null) if (memento != null) {
restoreState(memento); restoreState(memento);
}
memento = null; memento = null;
} }
@ -517,8 +573,8 @@ public class CView extends ViewPart implements ISetSelectionTarget,
return new StandardCElementLabelProvider(); return new StandardCElementLabelProvider();
} }
/* (non-Javadoc) /*
* Method declared on IWorkbenchPart. * (non-Javadoc) Method declared on IWorkbenchPart.
*/ */
public void dispose() { public void dispose() {
getSite().getPage().removePartListener(partListener); getSite().getPage().removePartListener(partListener);
@ -533,12 +589,17 @@ public class CView extends ViewPart implements ISetSelectionTarget,
IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager(); IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager();
wsmanager.removePropertyChangeListener(workingSetListener); wsmanager.removePropertyChangeListener(workingSetListener);
Control control = viewer.getControl();
if (dragDetectListener != null && control != null && control.isDisposed() == false) {
control.removeListener(SWT.DragDetect, dragDetectListener);
}
super.dispose(); super.dispose();
} }
/** /**
* An editor has been activated. Set the selection in this navigator * An editor has been activated. Set the selection in this navigator to be
* to be the editor's input, if linking is enabled. * the editor's input, if linking is enabled.
*/ */
void editorActivated(IEditorPart editor) { void editorActivated(IEditorPart editor) {
if (!CPluginPreferencePage.isLinkToEditor()) { if (!CPluginPreferencePage.isLinkToEditor()) {
@ -566,6 +627,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Returns the pattern filter for this view. * Returns the pattern filter for this view.
*
* @return the pattern filter * @return the pattern filter
*/ */
CPatternFilter getPatternFilter() { CPatternFilter getPatternFilter() {
@ -574,6 +636,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Returns the working set filter for this view. * Returns the working set filter for this view.
*
* @return the working set * @return the working set
*/ */
public IWorkingSet getWorkingSet() { public IWorkingSet getWorkingSet() {
@ -604,36 +667,23 @@ public class CView extends ViewPart implements ISetSelectionTarget,
* Create self's action objects * Create self's action objects
*/ */
void makeActions() { void makeActions() {
wsFilterActionGroup = new WorkingSetFilterActionGroup(getViewSite().getShell(), workingSetListener);
setActionGroup(new MainActionGroup(this)); setActionGroup(new MainActionGroup(this));
} }
/** /**
* Called when the context menu is about to open. * Called when the context menu is about to open. Delegates to the action
* Delegates to the action group using the viewer's selection as the action context. * group using the viewer's selection as the action context.
*
* @since 2.0 * @since 2.0
*/ */
protected void fillContextMenu(IMenuManager menu) { protected void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
(IStructuredSelection) getViewer().getSelection(); CViewActionGroup actionGroup = getActionGroup();
getActionGroup().setContext(new ActionContext(selection)); if (actionGroup != null) {
getActionGroup().fillContextMenu(menu); actionGroup.setContext(new ActionContext(selection));
actionGroup.fillContextMenu(menu);
actionGroup.setContext(null);
} }
IStructuredSelection convertSelectionToCElement(ISelection s) {
List converted = new ArrayList();
if (s instanceof StructuredSelection) {
Object[] elements= ((StructuredSelection)s).toArray();
for (int i= 0; i < elements.length; i++) {
Object e = elements[i];
if (e instanceof IAdaptable) {
ICElement c = (ICElement)((IAdaptable)e).getAdapter(ICElement.class);
if (c != null)
converted.add(c);
}
}
}
return new StructuredSelection(converted.toArray());
} }
/** /**
@ -655,7 +705,8 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Returns the message to show in the status line. * Returns the message to show in the status line.
* *
* @param selection the current selection * @param selection
* the current selection
* @return the status line message * @return the status line message
*/ */
String getStatusLineMessage(IStructuredSelection selection) { String getStatusLineMessage(IStructuredSelection selection) {
@ -697,6 +748,20 @@ public class CView extends ViewPart implements ISetSelectionTarget,
return "";//$NON-NLS-1$ return "";//$NON-NLS-1$
} }
/**
* Updates the action bar actions.
*
* @param selection
* the current selection
*/
protected void updateActionBars(IStructuredSelection selection) {
CViewActionGroup group = getActionGroup();
if (group != null) {
group.setContext(new ActionContext(selection));
group.updateActionBars();
}
}
void updateTitle() { void updateTitle() {
Object input = getViewer().getInput(); Object input = getViewer().getInput();
String viewName = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$ String viewName = getConfigurationElement().getAttribute("name"); //$NON-NLS-1$
@ -714,17 +779,41 @@ public class CView extends ViewPart implements ISetSelectionTarget,
/** /**
* Updates the message shown in the status line. * Updates the message shown in the status line.
* *
* @param selection the current selection * @param selection
* the current selection
*/ */
void updateStatusLine(IStructuredSelection selection) { void updateStatusLine(IStructuredSelection selection) {
String msg = getStatusLineMessage(selection); String msg = getStatusLineMessage(selection);
getViewSite().getActionBars().getStatusLineManager().setMessage(msg); getViewSite().getActionBars().getStatusLineManager().setMessage(msg);
} }
/*
*/
public void setWorkingSet(IWorkingSet workingSet) {
TreeViewer treeViewer = getViewer();
Object[] expanded = treeViewer.getExpandedElements();
ISelection selection = treeViewer.getSelection();
workingSetFilter.setWorkingSet(workingSet);
/*
* if (workingSet != null) { settings.put(STORE_WORKING_SET,
* workingSet.getName()); } else { settings.put(STORE_WORKING_SET, "");
* //$NON-NLS-1$ }
*/
updateTitle();
treeViewer.refresh();
treeViewer.setExpandedElements(expanded);
if (selection.isEmpty() == false && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
treeViewer.reveal(structuredSelection.getFirstElement());
}
}
/** /**
* Sets the decorator for the package explorer. * Sets the decorator for the package explorer.
* *
* @param decorator a label decorator or <code>null</code> for no decorations. * @param decorator
* a label decorator or <code>null</code> for no decorations.
*/ */
public void setLabelDecorator(ILabelDecorator decorator) { public void setLabelDecorator(ILabelDecorator decorator) {
ILabelProvider cProvider = createLabelProvider(); ILabelProvider cProvider = createLabelProvider();
@ -732,8 +821,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
} }
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if (viewer == null) if (viewer == null) return;
return;
boolean refreshViewer = false; boolean refreshViewer = false;
@ -743,24 +831,32 @@ public class CView extends ViewPart implements ISetSelectionTarget,
refreshViewer = true; refreshViewer = true;
} }
if (refreshViewer) if (refreshViewer) viewer.refresh();
viewer.refresh(); }
/**
* Returns whether the navigator selection automatically tracks the active
* editor.
*
* @return <code>true</code> if linking is enabled, <code>false</code>
* if not
*/
public boolean isLinkingEnabled() {
return CPluginPreferencePage.isLinkToEditor();
} }
/** /**
* Links to editor (if option enabled) * Links to editor (if option enabled)
*/ */
void linkToEditor(IStructuredSelection selection) { void linkToEditor(IStructuredSelection selection) {
if (!CPluginPreferencePage.isLinkToEditor()) { // ignore selection changes if the package explorer is not the active
// part.
// In this case the selection change isn't triggered by a user.
if (!isActivePart()) {
return; return;
} }
// ignore selection changes if the package explorer is not the active part.
// In this case the selection change isn't triggered by a user.
if (!isActivePart())
return;
Object obj= selection.getFirstElement();
if (selection.size() == 1) { if (selection.size() == 1) {
Object obj = selection.getFirstElement();
if (obj instanceof ISourceReference) { if (obj instanceof ISourceReference) {
ITranslationUnit tu = ((ISourceReference) obj).getTranslationUnit(); ITranslationUnit tu = ((ISourceReference) obj).getTranslationUnit();
if (tu != null) { if (tu != null) {
@ -775,14 +871,15 @@ public class CView extends ViewPart implements ISetSelectionTarget,
} }
} }
} }
} }
private boolean isActivePart() { private boolean isActivePart() {
return this == getSite().getPage().getActivePart(); return this == getSite().getPage().getActivePart();
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see IViewPartInputProvider#getViewPartInput() * @see IViewPartInputProvider#getViewPartInput()
*/ */
public Object getViewPartInput() { public Object getViewPartInput() {
@ -816,22 +913,12 @@ public class CView extends ViewPart implements ISetSelectionTarget,
String show = memento.getString(TAG_SHOWLIBRARIES); String show = memento.getString(TAG_SHOWLIBRARIES);
if (show != null) { if (show != null) {
getLibraryFilter().setShowLibraries(show.equals("true")); //$NON-NLS-1$ getLibraryFilter().setShowLibraries(show.equals("true")); //$NON-NLS-1$
} } else {
else
initFilterFromPreferences(); initFilterFromPreferences();
} }
}
void restoreState(IMemento memento) { void restoreState(IMemento memento) {
//Restore the working set before we re-build the tree
String wsname = memento.getString(TAG_WORKINGSET);
if(wsname != null) {
IWorkingSetManager wsmanager = getViewSite().getWorkbenchWindow().getWorkbench().getWorkingSetManager();
IWorkingSet set = wsmanager.getWorkingSet(wsname);
wsFilterActionGroup.setWorkingSet(set);
} else {
wsFilterActionGroup.setWorkingSet(null);
}
//ICelement container = CElementFactory.getDefault().getRoot(); //ICelement container = CElementFactory.getDefault().getRoot();
CoreModel factory = CoreModel.getDefault(); CoreModel factory = CoreModel.getDefault();
IMemento childMem = memento.getChild(TAG_EXPANDED); IMemento childMem = memento.getChild(TAG_EXPANDED);
@ -910,8 +997,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
Object o = expandedElements[i]; Object o = expandedElements[i];
// Do not save expanded binary files are libraries. // Do not save expanded binary files are libraries.
if (o instanceof IParent if (o instanceof IParent
&& ! (o instanceof IArchiveContainer || o instanceof IBinaryContainer && !(o instanceof IArchiveContainer || o instanceof IBinaryContainer || o instanceof IBinary || o instanceof IArchive)) {
|| o instanceof IBinary || o instanceof IArchive)) {
IMemento elementMem = expandedMem.createChild(TAG_ELEMENT); IMemento elementMem = expandedMem.createChild(TAG_ELEMENT);
ICElement e = (ICElement) o; ICElement e = (ICElement) o;
IResource res = e.getResource(); IResource res = e.getResource();
@ -960,8 +1046,7 @@ public class CView extends ViewPart implements ISetSelectionTarget,
//save library filter //save library filter
boolean showLibraries = getLibraryFilter().getShowLibraries(); boolean showLibraries = getLibraryFilter().getShowLibraries();
String show = "true"; //$NON-NLS-1$ String show = "true"; //$NON-NLS-1$
if (!showLibraries) if (!showLibraries) show = "false"; //$NON-NLS-1$
show= "false"; //$NON-NLS-1$
memento.putString(TAG_SHOWLIBRARIES, show); memento.putString(TAG_SHOWLIBRARIES, show);
//Save the working set away //Save the working set away
@ -973,7 +1058,9 @@ public class CView extends ViewPart implements ISetSelectionTarget,
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext) * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
*/ */
public boolean show(ShowInContext context) { public boolean show(ShowInContext context) {

View file

@ -14,24 +14,25 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin;
/** /**
* This is the action group for all the resource navigator actions. * This is the action group for all the view actions.
* It delegates to several subgroups for most of the actions. * It delegates to several subgroups for most of the actions.
* *
* @see GotoActionGroup * @see GotoActionGroup
* @see OpenActionGroup * @see OpenFileGroup
* @see RefactorActionGroup * @see RefactorActionGroup
* @see SortAndFilterActionGroup * @see SortAndFilterActionGroup
* @see WorkspaceActionGroup * @see WorkspaceActionGroup
* *
* @since 2.0
*/ */
public abstract class CViewActionGroup extends ActionGroup { public abstract class CViewActionGroup extends ActionGroup {
@ -80,11 +81,31 @@ public abstract class CViewActionGroup extends ActionGroup {
public void handleKeyPressed(KeyEvent event) { public void handleKeyPressed(KeyEvent event) {
} }
/**
* Handles a key released event by invoking the appropriate action.
* Does nothing by default.
*/
public void handleKeyReleased(KeyEvent event) {
}
/** /**
* Makes the actions contained in this action group. * Makes the actions contained in this action group.
*/ */
protected abstract void makeActions(); protected abstract void makeActions();
/**
* Called when the context menu is about to open.
* Override to add your own context dependent menu contributions.
*/
public abstract void fillContextMenu(IMenuManager menu);
/* (non-Javadoc)
* @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
*/
public abstract void fillActionBars(IActionBars actionBars);
public abstract void updateActionBars();
/** /**
* Runs the default action in the group. * Runs the default action in the group.
* Does nothing by default. * Does nothing by default.

View file

@ -10,6 +10,11 @@
############################################################################### ###############################################################################
OpenWithMenu.label=Open Wit&h
BuildAction.label=&Build Project
RebuildAction.label=Rebuild Pro&ject
CollapseAllAction.label=Collapse All CollapseAllAction.label=Collapse All
CollapseAllAction.tooltip=Collapse All CollapseAllAction.tooltip=Collapse All
CollapseAllAction.description=Collapse All CollapseAllAction.description=Collapse All
@ -20,3 +25,26 @@ CopyAction.toolTip = Copy
PasteAction.title=&Paste PasteAction.title=&Paste
PasteAction.toolTip = Paste PasteAction.toolTip = Paste
NewWizardsActionGroup.new=Ne&w
OpenProjectAction.dialog.title=Open Project
OpenProjectAction.dialog.message=Select project(s) to be opened
OpenProjectAction.error.message=Problems while opening projects
RefreshAction.label= Re&fresh
RefreshAction.toolTip= Refresh
RefreshAction.progressMessage= Refreshing...
RefreshAction.error.title= Refresh Problems
RefreshAction.error.message= Problems occurred refreshing the selected resources.
RefreshAction.locationDeleted.title= Project location has been deleted
RefreshAction.locationDeleted.message= The location for project {0} ({1}) has been deleted.\n Delete {0} from the workspace?
ToggleLinkingAction.label=Lin&k With Editor
ToggleLinkingAction.tooltip=Link with Editor
ToggleLinkingAction.description=Link with active editor
SearchAction.label=Search
FileSearchAction.label=Search
FilterSelectionAction.label= Filters ...
ShowLibrariesAction.label = Show Reference Libs

View file

@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
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);
}
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);
}
}
}
}
}
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);
}
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)
*/
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 = (IResource)((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
}
}

View file

@ -10,9 +10,6 @@
************************************************************************/ ************************************************************************/
package org.eclipse.cdt.internal.ui.cview; package org.eclipse.cdt.internal.ui.cview;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.IContextMenuConstants;
@ -21,88 +18,57 @@ import org.eclipse.cdt.internal.ui.editor.FileSearchActionInWorkingSet;
import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction; import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction;
import org.eclipse.cdt.internal.ui.editor.SearchDialogAction; import org.eclipse.cdt.internal.ui.editor.SearchDialogAction;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.Separator;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars; import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.AddBookmarkAction; import org.eclipse.ui.actions.AddBookmarkAction;
import org.eclipse.ui.actions.BuildAction; import org.eclipse.ui.actions.AddTaskAction;
import org.eclipse.ui.actions.CloseResourceAction;
import org.eclipse.ui.actions.ExportResourcesAction; import org.eclipse.ui.actions.ExportResourcesAction;
import org.eclipse.ui.actions.ImportResourcesAction; import org.eclipse.ui.actions.ImportResourcesAction;
import org.eclipse.ui.actions.NewWizardMenu; import org.eclipse.ui.actions.NewWizardMenu;
import org.eclipse.ui.actions.OpenFileAction;
import org.eclipse.ui.actions.OpenInNewWindowAction;
import org.eclipse.ui.actions.OpenResourceAction;
import org.eclipse.ui.actions.OpenSystemEditorAction;
import org.eclipse.ui.actions.OpenWithMenu;
import org.eclipse.ui.actions.RefreshAction;
import org.eclipse.ui.actions.WorkingSetFilterActionGroup; import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
import org.eclipse.ui.dialogs.PropertyDialogAction; import org.eclipse.ui.dialogs.PropertyDialogAction;
import org.eclipse.ui.ide.IDEActionFactory; import org.eclipse.ui.ide.IDEActionFactory;
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;
/** /**
* The main action group for the cview. * The main action group for the cview. This contains a few actions and several
* This contains a few actions and several subgroups. * subgroups.
*/ */
public class MainActionGroup extends CViewActionGroup { public class MainActionGroup extends CViewActionGroup {
// Actions for Menu context. // Actions for Menu context.
AddBookmarkAction addBookmarkAction; AddBookmarkAction addBookmarkAction;
OpenFileAction openFileAction; AddTaskAction addTaskAction;
OpenSystemEditorAction openSystemEditorAction;
PropertyDialogAction propertyDialogAction; PropertyDialogAction propertyDialogAction;
ImportResourcesAction importAction; ImportResourcesAction importAction;
ExportResourcesAction exportAction; ExportResourcesAction exportAction;
RefreshAction refreshAction;
CloseResourceAction closeProjectAction;
OpenResourceAction openProjectAction;
RefactorActionGroup refactorGroup;
BuildAction buildAction;
BuildAction rebuildAction;
// CElement action // CElement action
OpenIncludeAction openIncludeAction; OpenIncludeAction openIncludeAction;
BackAction backAction;
ForwardAction forwardAction;
GoIntoAction goIntoAction;
UpAction upAction;
// Collapsing // Collapsing
CollapseAllAction collapseAllAction; CollapseAllAction collapseAllAction;
WorkingSetFilterActionGroup wsFilterActionGroup; //ToggleLinkingAction toggleLinkingAction;
ShowLibrariesAction clibFilterAction; ShowLibrariesAction clibFilterAction;
@ -110,12 +76,14 @@ public class MainActionGroup extends CViewActionGroup {
FileSearchAction fFileSearchAction; FileSearchAction fFileSearchAction;
FileSearchActionInWorkingSet fFileSearchActionInWorkingSet; FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
SearchDialogAction fSearchDialogAction; SearchDialogAction fSearchDialogAction;
FilterSelectionAction patternFilterAction; FilterSelectionAction patternFilterAction;
// Menu tags for the build BuildGroup buildGroup;
final String BUILD_GROUP_MARKER = "buildGroup"; OpenFileGroup openFileGroup;
final String BUILD_GROUP_MARKER_END = "end-buildGroup"; GotoActionGroup gotoGroup;
RefactorActionGroup refactorGroup;
OpenProjectGroup openProjectGroup;
WorkingSetFilterActionGroup workingSetGroup;
public MainActionGroup(CView cview) { public MainActionGroup(CView cview) {
super(cview); super(cview);
@ -126,85 +94,80 @@ public class MainActionGroup extends CViewActionGroup {
*/ */
public void handleKeyPressed(KeyEvent event) { public void handleKeyPressed(KeyEvent event) {
refactorGroup.handleKeyPressed(event); refactorGroup.handleKeyPressed(event);
openFileGroup.handleKeyPressed(event);
openProjectGroup.handleKeyPressed(event);
gotoGroup.handleKeyPressed(event);
buildGroup.handleKeyPressed(event);
} }
/** /**
* Create the KeyListener for doing the refresh on the viewer. * Handles key events in viewer.
*/ */
void initRefreshKey() { public void handleKeyReleased(KeyEvent event) {
final Viewer viewer = getCView().getViewer(); refactorGroup.handleKeyReleased(event);
viewer.getControl().addKeyListener(new KeyAdapter() { openFileGroup.handleKeyReleased(event);
public void keyReleased(KeyEvent event) { openProjectGroup.handleKeyReleased(event);
if (event.keyCode == SWT.F5) { gotoGroup.handleKeyReleased(event);
refreshAction.selectionChanged( buildGroup.handleKeyReleased(event);
(IStructuredSelection)viewer.getSelection());
if (refreshAction.isEnabled())
refreshAction.run();
}
}
});
} }
protected void makeActions() { protected void makeActions() {
final Viewer viewer = getCView().getViewer(); final Viewer viewer = getCView().getViewer();
FrameList framelist = getCView().getFrameList();
Shell shell = getCView().getViewSite().getShell(); Shell shell = getCView().getViewSite().getShell();
openIncludeAction = new OpenIncludeAction (viewer);
openFileAction = new OpenFileAction(getCView().getSite().getPage());
openSystemEditorAction = new OpenSystemEditorAction(getCView().getSite().getPage());
refreshAction = new RefreshAction(shell); openFileGroup = new OpenFileGroup(getCView());
initRefreshKey(); openProjectGroup = new OpenProjectGroup(getCView());
gotoGroup = new GotoActionGroup(getCView());
buildAction = new BuildAction(shell, IncrementalProjectBuilder.INCREMENTAL_BUILD); buildGroup = new BuildGroup(getCView());
rebuildAction = new BuildAction(shell, IncrementalProjectBuilder.FULL_BUILD);
refactorGroup = new RefactorActionGroup(getCView()); refactorGroup = new RefactorActionGroup(getCView());
IWorkspace workspace = CUIPlugin.getWorkspace(); openIncludeAction = new OpenIncludeAction(viewer);
openProjectAction = new OpenResourceAction(shell);
workspace.addResourceChangeListener(openProjectAction, IResourceChangeEvent.POST_CHANGE);
closeProjectAction = new CloseResourceAction(shell);
workspace.addResourceChangeListener(closeProjectAction, IResourceChangeEvent.POST_CHANGE);
//sortByNameAction = new SortViewAction(this, false); //sortByNameAction = new SortViewAction(this, false);
//sortByTypeAction = new SortViewAction(this, true); //sortByTypeAction = new SortViewAction(this, true);
patternFilterAction = new FilterSelectionAction(shell, getCView(), "Filters..."); patternFilterAction = new FilterSelectionAction(shell, getCView(), CViewMessages.getString("FilterSelectionAction.label")); //$NON-NLS-1$
clibFilterAction = new ShowLibrariesAction(shell, getCView(), "Show Referenced Libs"); clibFilterAction = new ShowLibrariesAction(shell, getCView(), CViewMessages.getString("ShowLibrariesAction.label")); //$NON-NLS-1$
//wsFilterActionGroup = new WorkingSetFilterActionGroup(getCView().getViewSite().getShell(), workingSetListener); IPropertyChangeListener workingSetUpdater = new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
goIntoAction = new GoIntoAction(framelist); if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(property)) {
backAction = new BackAction(framelist); Object newValue = event.getNewValue();
forwardAction = new ForwardAction(framelist);
upAction = new UpAction(framelist); if (newValue instanceof IWorkingSet) {
getCView().setWorkingSet((IWorkingSet) newValue);
} else if (newValue == null) {
getCView().setWorkingSet(null);
}
}
}
};
workingSetGroup = new WorkingSetFilterActionGroup(shell, workingSetUpdater);
workingSetGroup.setWorkingSet(getCView().getWorkingSet());
addBookmarkAction = new AddBookmarkAction(shell); addBookmarkAction = new AddBookmarkAction(shell);
//propertyDialogAction = new PropertyDialogAction(shell, viewer); addTaskAction = new AddTaskAction(shell);
propertyDialogAction = new PropertyDialogAction(shell, propertyDialogAction = new PropertyDialogAction(shell, new ISelectionProvider() {
new ISelectionProvider () {
public void addSelectionChangedListener(ISelectionChangedListener listener) { public void addSelectionChangedListener(ISelectionChangedListener listener) {
viewer.addSelectionChangedListener(listener); viewer.addSelectionChangedListener(listener);
} }
public ISelection getSelection() { public ISelection getSelection() {
return convertSelection (viewer.getSelection ()); return SelectionConverter.convertSelectionToResources(viewer.getSelection());
} }
public void removeSelectionChangedListener(ISelectionChangedListener listener) { public void removeSelectionChangedListener(ISelectionChangedListener listener) {
viewer.removeSelectionChangedListener(listener); viewer.removeSelectionChangedListener(listener);
} }
public void setSelection(ISelection selection) { public void setSelection(ISelection selection) {
viewer.setSelection(selection); viewer.setSelection(selection);
} }
}); });
IActionBars actionBars = getCView().getViewSite().getActionBars(); // Importing/exporting.
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
actionBars.setGlobalActionHandler(IDEActionFactory.BUILD_PROJECT.getId(), buildAction);
actionBars.setGlobalActionHandler(IDEActionFactory.REBUILD_PROJECT.getId(), rebuildAction);
actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), openProjectAction);
actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), closeProjectAction);
importAction = new ImportResourcesAction(getCView().getSite().getWorkbenchWindow()); importAction = new ImportResourcesAction(getCView().getSite().getWorkbenchWindow());
exportAction = new ExportResourcesAction(getCView().getSite().getWorkbenchWindow()); exportAction = new ExportResourcesAction(getCView().getSite().getWorkbenchWindow());
@ -215,227 +178,101 @@ public class MainActionGroup extends CViewActionGroup {
fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow()); fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow());
} }
/** /**
* Called when the context menu is about to open. * Called when the context menu is about to open. Override to add your own
* Override to add your own context dependent menu contributions. * context dependent menu contributions.
*/ */
public void fillContextMenu(IMenuManager menu) { public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection= (IStructuredSelection) getCView().getViewer().getSelection(); IStructuredSelection celements = (IStructuredSelection) getCView().getViewer().getSelection();
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(celements);
if (selection.isEmpty()) { if (resources.isEmpty()) {
new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false); new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false);
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
return; return;
} }
updateActions (convertSelection(selection)); //updateActions(resources);
//updateActions (selection); addNewMenu(menu, resources);
addNewMenu(menu, selection);
menu.add(new Separator()); menu.add(new Separator());
addOpenMenu(menu, selection); gotoGroup.fillContextMenu(menu);
menu.add(new Separator()); menu.add(new Separator());
addBuildMenu(menu, selection); openFileGroup.fillContextMenu(menu);
menu.add(new Separator());
buildGroup.fillContextMenu(menu);
menu.add(new Separator()); menu.add(new Separator());
refactorGroup.fillContextMenu(menu); refactorGroup.fillContextMenu(menu);
menu.add(new Separator()); menu.add(new Separator());
importAction.selectionChanged(selection); importAction.selectionChanged(resources);
exportAction.selectionChanged(selection);
menu.add(importAction); menu.add(importAction);
exportAction.selectionChanged(resources);
menu.add(exportAction); menu.add(exportAction);
menu.add(new Separator()); menu.add(new Separator());
addRefreshMenu (menu, selection); openProjectGroup.fillContextMenu(menu);
addBookMarkMenu(menu, resources);
menu.add(new Separator()); menu.add(new Separator());
addCloseMenu(menu, selection); addSearchMenu(menu, resources);
menu.add(new Separator());
addBookMarkMenu (menu, selection);
menu.add(new Separator());
addSearchMenu(menu, selection);
//menu.add(new Separator());
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
addPropertyMenu(menu, selection); addPropertyMenu(menu, resources);
} }
/** /**
* Extends the superclass implementation to set the context in the subgroups. * Extends the superclass implementation to set the context in the
* subgroups.
*/ */
public void setContext(ActionContext context) { public void setContext(ActionContext context) {
super.setContext(context); super.setContext(context);
//gotoGroup.setContext(context); gotoGroup.setContext(context);
//openGroup.setContext(context); openFileGroup.setContext(context);
openProjectGroup.setContext(context);
refactorGroup.setContext(context); refactorGroup.setContext(context);
buildGroup.setContext(context);
//sortAndFilterGroup.setContext(context); //sortAndFilterGroup.setContext(context);
//workspaceGroup.setContext(context); //workspaceGroup.setContext(context);
} }
void addNewMenu(IMenuManager menu, IStructuredSelection selection) { void addNewMenu(IMenuManager menu, IStructuredSelection selection) {
MenuManager newMenu = new MenuManager(CViewMessages.getString("NewWizardsActionGroup.new")); //$NON-NLS-1$
MenuManager newMenu = new MenuManager("New");
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
newMenu.add(goIntoAction);
new NewWizardMenu(newMenu, getCView().getSite().getWorkbenchWindow(), false); new NewWizardMenu(newMenu, getCView().getSite().getWorkbenchWindow(), false);
menu.add(newMenu); menu.add(newMenu);
if (resource == null)
return;
menu.add (new Separator ());
if (selection.size() == 1 && resource instanceof IContainer) {
menu.add(goIntoAction);
}
MenuManager gotoMenu = new MenuManager("GoTo");
menu.add(gotoMenu);
if (getCView().getViewer().isExpandable(element)) {
gotoMenu.add(backAction);
gotoMenu.add(forwardAction);
gotoMenu.add(upAction);
}
}
void addOpenMenu(IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null)
return;
// Create a menu flyout.
//MenuManager submenu= new MenuManager("Open With"); //$NON-NLS-1$
//submenu.add(new OpenWithMenu(getSite().getPage(), (IFile) resource));
//menu.add(submenu);
if (resource instanceof IFile)
menu.add(openFileAction);
fillOpenWithMenu(menu, selection);
fillOpenToMenu(menu, selection);
}
void addBuildMenu(IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null) {
return;
}
menu.add(new GroupMarker(BUILD_GROUP_MARKER));
if (resource instanceof IProject && hasBuilder((IProject) resource)) {
buildAction.selectionChanged(selection);
menu.add(buildAction);
rebuildAction.selectionChanged(selection);
menu.add(rebuildAction);
}
menu.add(new GroupMarker(BUILD_GROUP_MARKER_END));
}
void addRefreshMenu (IMenuManager menu, IStructuredSelection selection) {
menu.add(refreshAction);
}
void addCloseMenu (IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null)
return;
if (resource instanceof IProject) {
menu.add(closeProjectAction);
}
} }
void addBookMarkMenu(IMenuManager menu, IStructuredSelection selection) { void addBookMarkMenu(IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable)selection.getFirstElement(); Object obj = selection.getFirstElement();
if (obj instanceof IAdaptable) {
IAdaptable element = (IAdaptable) obj;
IResource resource = (IResource) element.getAdapter(IResource.class); IResource resource = (IResource) element.getAdapter(IResource.class);
if (resource == null)
return;
if (resource instanceof IFile) { if (resource instanceof IFile) {
addBookmarkAction.selectionChanged(selection);
menu.add(addBookmarkAction); menu.add(addBookmarkAction);
} }
} }
}
void addPropertyMenu(IMenuManager menu, IStructuredSelection selection) { void addPropertyMenu(IMenuManager menu, IStructuredSelection selection) {
propertyDialogAction.selectionChanged(convertSelection(selection)); propertyDialogAction.selectionChanged(selection);
if (propertyDialogAction.isApplicableForSelection()) { if (propertyDialogAction.isApplicableForSelection()) {
menu.add(propertyDialogAction); menu.add(propertyDialogAction);
} }
} }
/**
* Add "open with" actions to the context sensitive menu.
* @param menu the context sensitive menu
* @param selection the current selection in the project explorer
*/
void fillOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null)
return;
// If one file is selected get it.
// Otherwise, do not show the "open with" menu.
if (selection.size() != 1)
return;
if (!(resource instanceof IFile))
return;
// Create a menu flyout.
MenuManager submenu = new MenuManager("Open With"); //$NON-NLS-1$
submenu.add(new OpenWithMenu(getCView().getSite().getPage(), (IFile) resource));
// Add the submenu.
menu.add(submenu);
}
/**
* Add "open to" actions to the context sensitive menu.
* @param menu the context sensitive menu
* @param selection the current selection in the project explorer
*/
void fillOpenToMenu(IMenuManager menu, IStructuredSelection selection)
{
IAdaptable element = (IAdaptable)selection.getFirstElement();
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null)
return;
// If one file is selected get it.
// Otherwise, do not show the "open with" menu.
if (selection.size() != 1)
return;
if (!(resource instanceof IContainer))
return;
menu.add(new OpenInNewWindowAction(getCView().getSite().getWorkbenchWindow(), resource));
}
void addSearchMenu(IMenuManager menu, IStructuredSelection selection) { void addSearchMenu(IMenuManager menu, IStructuredSelection selection) {
IAdaptable element = (IAdaptable) selection.getFirstElement(); IAdaptable element = (IAdaptable) selection.getFirstElement();
if (element instanceof ITranslationUnit || if (element instanceof ITranslationUnit || element instanceof ICProject) {
element instanceof ICProject)
return; return;
}
MenuManager search = new MenuManager("Search", IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$ MenuManager search = new MenuManager(CViewMessages.getString("SearchAction.label"), IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
if (SearchDialogAction.canActionBeAdded(selection)) { if (SearchDialogAction.canActionBeAdded(selection)) {
search.add(fSearchDialogAction); search.add(fSearchDialogAction);
} }
if (FileSearchAction.canActionBeAdded(selection)) { if (FileSearchAction.canActionBeAdded(selection)) {
MenuManager fileSearch = new MenuManager("File Search"); MenuManager fileSearch = new MenuManager(CViewMessages.getString("FileSearchAction.label"));//$NON-NLS-1$
fileSearch.add(fFileSearchAction); fileSearch.add(fFileSearchAction);
fileSearch.add(fFileSearchActionInWorkingSet); fileSearch.add(fFileSearchActionInWorkingSet);
search.add(fileSearch); search.add(fileSearch);
@ -444,102 +281,70 @@ public class MainActionGroup extends CViewActionGroup {
menu.add(search); menu.add(search);
} }
boolean hasBuilder(IProject project) {
try {
ICommand[] commands = project.getDescription().getBuildSpec();
if (commands.length > 0)
return true;
}
catch (CoreException e) {
// Cannot determine if project has builders. Project is closed
// or does not exist. Fall through to return false.
}
return false;
}
public void runDefaultAction(IStructuredSelection selection) { public void runDefaultAction(IStructuredSelection selection) {
updateActions(convertSelection(selection)); openFileGroup.runDefaultAction(selection);
updateGlobalActions(convertSelection(selection)); openProjectGroup.runDefaultAction(selection);
gotoGroup.runDefaultAction(selection);
buildGroup.runDefaultAction(selection);
refactorGroup.runDefaultAction(selection);
//workingSetGroup.runDefaultAction(selection);
} }
/** /**
* Updates all actions with the given selection. * Updates all actions with the given selection. Necessary when popping up
* Necessary when popping up a menu, because some of the enablement criteria * a menu, because some of the enablement criteria may have changed, even
* may have changed, even if the selection in the viewer hasn't. * if the selection in the viewer hasn't. E.g. A project was opened or
* E.g. A project was opened or closed. * closed.
*/ */
void updateActions(IStructuredSelection selection) { public void updateActionBars() {
goIntoAction.update(); IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
refreshAction.selectionChanged(selection);
openFileAction.selectionChanged(selection); propertyDialogAction.setEnabled(selection.size() == 1);
openSystemEditorAction.selectionChanged(selection);
propertyDialogAction.selectionChanged(selection);
importAction.selectionChanged(selection);
exportAction.selectionChanged(selection);
refactorGroup.updateActions(selection);
//sortByTypeAction.selectionChanged(selection); //sortByTypeAction.selectionChanged(selection);
//sortByNameAction.selectionChanged(selection); //sortByNameAction.selectionChanged(selection);
}
/**
* Updates the global actions with the given selection.
* Be sure to invoke after actions objects have updated, since can* methods delegate to action objects.
*/
void updateGlobalActions(IStructuredSelection selection) {
addBookmarkAction.selectionChanged(selection); addBookmarkAction.selectionChanged(selection);
addTaskAction.selectionChanged(selection);
// Ensure Copy global action targets correct action, openFileGroup.updateActionBars();
// either copyProjectAction or copyResourceAction, openProjectGroup.updateActionBars();
// depending on selection. gotoGroup.updateActionBars();
IActionBars actionBars = getCView().getViewSite().getActionBars(); buildGroup.updateActionBars();
actionBars.updateActionBars(); refactorGroup.updateActionBars();
workingSetGroup.updateActionBars();
refreshAction.selectionChanged(selection);
buildAction.selectionChanged(selection);
rebuildAction.selectionChanged(selection);
openProjectAction.selectionChanged(selection);
closeProjectAction.selectionChanged(selection);
} }
public void fillActionBars(IActionBars actionBars) { public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), addTaskAction);
workingSetGroup.fillActionBars(actionBars);
gotoGroup.fillActionBars(actionBars);
refactorGroup.fillActionBars(actionBars);
openFileGroup.fillActionBars(actionBars);
openProjectGroup.fillActionBars(actionBars);
buildGroup.fillActionBars(actionBars);
IToolBarManager toolBar = actionBars.getToolBarManager(); IToolBarManager toolBar = actionBars.getToolBarManager();
toolBar.add(backAction);
toolBar.add(forwardAction);
toolBar.add(upAction);
toolBar.add(new Separator()); toolBar.add(new Separator());
toolBar.add(collapseAllAction); toolBar.add(collapseAllAction);
actionBars.updateActionBars(); //toolBar.add(toggleLinkingAction);
//actionBars.updateActionBars();
//wsFilterActionGroup.fillActionBars(actionBars);
IMenuManager menu = actionBars.getMenuManager(); IMenuManager menu = actionBars.getMenuManager();
//menu.add(toggleLinkingAction);
//menu.add (clibFilterAction); //menu.add (clibFilterAction);
menu.add(patternFilterAction); menu.add(patternFilterAction);
refactorGroup.fillActionBars(actionBars);
} }
public void dispose() { public void dispose() {
IWorkspace workspace = CUIPlugin.getWorkspace(); IWorkspace workspace = CUIPlugin.getWorkspace();
workspace.removeResourceChangeListener(closeProjectAction);
workspace.removeResourceChangeListener(openProjectAction);
refactorGroup.dispose(); refactorGroup.dispose();
openFileGroup.dispose();
openProjectGroup.dispose();
gotoGroup.dispose();
buildGroup.dispose();
super.dispose();
} }
static IStructuredSelection convertSelection(ISelection s) {
List converted = new ArrayList();
if (s instanceof StructuredSelection) {
Object[] elements= ((StructuredSelection)s).toArray();
for (int i= 0; i < elements.length; i++) {
Object e = elements[i];
if (e instanceof IAdaptable) {
IResource r = (IResource)((IAdaptable)e).getAdapter(IResource.class);
if (r != null)
converted.add(r);
}
}
}
return new StructuredSelection(converted.toArray());
}
} }

View file

@ -0,0 +1,132 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
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.MenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.OpenFileAction;
import org.eclipse.ui.actions.OpenInNewWindowAction;
import org.eclipse.ui.actions.OpenWithMenu;
/**
* This is the action group for the open actions.
*/
public class OpenFileGroup extends CViewActionGroup {
private OpenFileAction openFileAction;
public OpenFileGroup(CView cview) {
super(cview);
}
protected void makeActions() {
openFileAction = new OpenFileAction(getCView().getSite().getPage());
}
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection celements = (IStructuredSelection) getContext().getSelection();
IStructuredSelection selection = SelectionConverter.convertSelectionToResources(celements);
boolean anyResourceSelected = !selection.isEmpty()
&& SelectionConverter.allResourcesAreOfType(selection, IResource.PROJECT | IResource.FOLDER | IResource.FILE);
boolean onlyFilesSelected = !selection.isEmpty() && SelectionConverter.allResourcesAreOfType(selection, IResource.FILE);
if (onlyFilesSelected) {
openFileAction.selectionChanged(selection);
menu.add(openFileAction);
fillOpenWithMenu(menu, selection);
}
if (anyResourceSelected) {
addNewWindowAction(menu, selection);
}
}
/**
* Adds the OpenWith submenu to the context menu.
*
* @param menu
* the context menu
* @param selection
* the current selection
*/
private void fillOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
// Only supported if exactly one file is selected.
if (selection.size() != 1) {
return;
}
Object element = selection.getFirstElement();
if (!(element instanceof IFile)) {
return;
}
MenuManager submenu = new MenuManager(CViewMessages.getString("OpenWithMenu.label")); //$NON-NLS-1$
submenu.add(new OpenWithMenu(getCView().getSite().getPage(), (IFile) element));
menu.add(submenu);
}
/**
* Adds the Open in New Window action to the context menu.
*
* @param menu
* the context menu
* @param selection
* the current selection
*/
private void addNewWindowAction(IMenuManager menu, IStructuredSelection selection) {
// Only supported if exactly one container (i.e open project or folder) is selected.
if (selection.size() != 1) {
return;
}
Object element = selection.getFirstElement();
if (!(element instanceof IContainer)) {
return;
}
if (element instanceof IProject && !(((IProject) element).isOpen())) {
return;
}
menu.add(new OpenInNewWindowAction(getCView().getSite().getWorkbenchWindow(), (IContainer) element));
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
*/
public void fillActionBars(IActionBars actionBars) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
*/
public void updateActionBars() {
}
/**
* Runs the default action (open file).
*/
public void runDefaultAction(IStructuredSelection selection) {
Object obj = selection.getFirstElement();
if (obj instanceof IAdaptable) {
IResource element = (IResource)((IAdaptable)obj).getAdapter(IResource.class);
if (element instanceof IFile) {
openFileAction.selectionChanged(selection);
openFileAction.run();
}
}
}
}

View file

@ -0,0 +1,154 @@
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials!
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
************************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import java.util.Iterator;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.CloseResourceAction;
import org.eclipse.ui.actions.OpenResourceAction;
import org.eclipse.ui.actions.RefreshAction;
import org.eclipse.ui.ide.IDEActionFactory;
/**
* This is the action group for actions such as Refresh Local, and Open/Close
* Project.
*/
public class OpenProjectGroup extends CViewActionGroup {
private OpenResourceAction openProjectAction;
private CloseResourceAction closeProjectAction;
private RefreshAction refreshAction;
public OpenProjectGroup(CView cview) {
super(cview);
}
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
actionBars.setGlobalActionHandler(IDEActionFactory.OPEN_PROJECT.getId(), openProjectAction);
actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT.getId(), closeProjectAction);
}
/**
* Adds the open project, close project and refresh resource actions to the
* context menu.
* <p>
* refresh-no closed project selected
* </p>
* <p>
* Both the open project and close project action may be on the menu at the
* same time.
* </p>
* <p>
* No disabled action should be on the context menu.
* </p>
*
* @param menu
* context menu to add actions to
*/
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
boolean isProjectSelection = true;
boolean hasOpenProjects = false;
boolean hasClosedProjects = false;
Iterator resources = selection.iterator();
while (resources.hasNext() && (!hasOpenProjects || !hasClosedProjects || isProjectSelection)) {
Object next = resources.next();
IProject project = null;
if (next instanceof IProject) {
project = (IProject) next;
} else if (next instanceof IAdaptable) {
IResource res = (IResource) ((IAdaptable) next).getAdapter(IResource.class);
if (res instanceof IProject) {
project = (IProject)res;
}
}
if (project == null) {
isProjectSelection = false;
continue;
}
if (project.isOpen()) {
hasOpenProjects = true;
} else {
hasClosedProjects = true;
}
}
if (!hasClosedProjects) {
refreshAction.selectionChanged(selection);
menu.add(refreshAction);
}
if (isProjectSelection) {
if (hasClosedProjects) {
openProjectAction.selectionChanged(selection);
menu.add(openProjectAction);
}
if (hasOpenProjects) {
closeProjectAction.selectionChanged(selection);
menu.add(closeProjectAction);
}
}
}
/**
* Handles a key pressed event by invoking the appropriate action.
*/
public void handleKeyPressed(KeyEvent event) {
if (event.keyCode == SWT.F5 && event.stateMask == 0) {
if (refreshAction.isEnabled()) {
refreshAction.refreshAll();
}
}
}
protected void makeActions() {
Shell shell = getCView().getSite().getShell();
IWorkspace workspace = CUIPlugin.getWorkspace();
openProjectAction = new OpenResourceAction(shell);
workspace.addResourceChangeListener(openProjectAction, IResourceChangeEvent.POST_CHANGE);
closeProjectAction = new CloseResourceAction(shell);
workspace.addResourceChangeListener(closeProjectAction, IResourceChangeEvent.POST_CHANGE);
refreshAction = new RefreshAction(shell);
refreshAction.setDisabledImageDescriptor(getImageDescriptor("dlcl16/refresh_nav.gif"));//$NON-NLS-1$
refreshAction.setImageDescriptor(getImageDescriptor("elcl16/refresh_nav.gif"));//$NON-NLS-1$
refreshAction.setHoverImageDescriptor(getImageDescriptor("clcl16/refresh_nav.gif"));//$NON-NLS-1$
}
public void updateActionBars() {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
refreshAction.selectionChanged(selection);
openProjectAction.selectionChanged(selection);
closeProjectAction.selectionChanged(selection);
}
public void dispose() {
IWorkspace workspace = CUIPlugin.getWorkspace();
workspace.removeResourceChangeListener(closeProjectAction);
workspace.removeResourceChangeListener(openProjectAction);
}
}

View file

@ -10,10 +10,7 @@
************************************************************************/ ************************************************************************/
package org.eclipse.cdt.internal.ui.cview; package org.eclipse.cdt.internal.ui.cview;
import java.util.Iterator;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
@ -57,13 +54,11 @@ public class RefactorActionGroup extends CViewActionGroup {
} }
public void fillContextMenu(IMenuManager menu) { public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = MainActionGroup.convertSelection(getCView().getViewer().getSelection()); IStructuredSelection celements = (IStructuredSelection) getContext().getSelection();
//(IStructuredSelection) getContext().getSelection(); IStructuredSelection selection = SelectionConverter.convertSelectionToResources(celements);
boolean anyResourceSelected = boolean anyResourceSelected = !selection.isEmpty()
!selection.isEmpty() && SelectionConverter.allResourcesAreOfType(selection, IResource.PROJECT | IResource.FOLDER | IResource.FILE);
&& allResourcesAreOfType(selection,
IResource.PROJECT | IResource.FOLDER | IResource.FILE);
copyAction.selectionChanged(selection); copyAction.selectionChanged(selection);
menu.add(copyAction); menu.add(copyAction);
@ -131,8 +126,9 @@ public class RefactorActionGroup extends CViewActionGroup {
deleteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_HOVER)); deleteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_HOVER));
} }
public void updateActions(IStructuredSelection selection) { public void updateActionBars() {
//IStructuredSelection selection = (IStructuredSelection) getContext().getSelection(); IStructuredSelection celements = (IStructuredSelection) getContext().getSelection();
IStructuredSelection selection = SelectionConverter.convertSelectionToResources(celements);
copyAction.selectionChanged(selection); copyAction.selectionChanged(selection);
pasteAction.selectionChanged(selection); pasteAction.selectionChanged(selection);
@ -140,20 +136,4 @@ public class RefactorActionGroup extends CViewActionGroup {
moveAction.selectionChanged(selection); moveAction.selectionChanged(selection);
renameAction.selectionChanged(selection); renameAction.selectionChanged(selection);
} }
public static boolean allResourcesAreOfType(IStructuredSelection selection, int resourceMask) {
Iterator resources = selection.iterator();
while (resources.hasNext()) {
Object next = resources.next();
IAdaptable element = (IAdaptable)next;
IResource resource = (IResource)element.getAdapter(IResource.class);
if (resource == null)
return false;
if ((resource.getType() & resourceMask) == 0)
return false;
}
return true;
}
} }

View file

@ -0,0 +1,127 @@
/**********************************************************************
* Created on 25-Mar-2003
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.internal.ui.cview;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
public class SelectionConverter {
public static IStructuredSelection convertSelectionToCElements(ISelection s) {
List converted = new ArrayList();
if (s instanceof StructuredSelection) {
Object[] elements = ((StructuredSelection) s).toArray();
for (int i = 0; i < elements.length; i++) {
Object e = elements[i];
if (e instanceof IAdaptable) {
ICElement c = (ICElement) ((IAdaptable) e).getAdapter(ICElement.class);
if (c != null) {
converted.add(c);
}
}
}
}
return new StructuredSelection(converted.toArray());
}
public static IStructuredSelection convertSelectionToResources(ISelection s) {
List converted = new ArrayList();
if (s instanceof StructuredSelection) {
Object[] elements = ((StructuredSelection) s).toArray();
for (int i = 0; i < elements.length; i++) {
Object e = elements[i];
if (e instanceof IAdaptable) {
IResource r = (IResource) ((IAdaptable) e).getAdapter(IResource.class);
if (r != null) {
converted.add(r);
}
}
}
}
return new StructuredSelection(converted.toArray());
}
public static boolean allResourcesAreOfType(IStructuredSelection selection, int resourceMask) {
Iterator resources = selection.iterator();
while (resources.hasNext()) {
Object next = resources.next();
if (next instanceof IAdaptable) {
IAdaptable element = (IAdaptable) next;
IResource resource = (IResource) element.getAdapter(IResource.class);
if (resource == null) {
return false;
}
if (!resourceIsType(resource, resourceMask)) {
return false;
}
}
}
return true;
}
/**
* Returns the selection adapted to IResource. Returns null if any of the entries are not adaptable.
*
* @param selection
* the selection
* @param resourceMask
* resource mask formed by bitwise OR of resource type constants (defined on <code>IResource</code>)
* @return IStructuredSelection or null if any of the entries are not adaptable.
* @see IResource#getType()
*/
public static IStructuredSelection allResources(IStructuredSelection selection, int resourceMask) {
Iterator adaptables = selection.iterator();
List result = new ArrayList();
while (adaptables.hasNext()) {
Object next = adaptables.next();
if (next instanceof IAdaptable) {
IResource resource = (IResource)((IAdaptable) next).getAdapter(IResource.class);
if (resource == null) {
return null;
} else if (resourceIsType(resource, resourceMask)) {
result.add(resource);
}
} else {
return null;
}
}
return new StructuredSelection(result);
}
/**
* Returns whether the type of the given resource is among the specified
* resource types.
*
* @param resource the resource
* @param resourceMask resource mask formed by bitwise OR of resource type
* constants (defined on <code>IResource</code>)
* @return <code>true</code> if the resources has a matching type, and
* <code>false</code> otherwise
* @see IResource#getType()
*/
public static boolean resourceIsType(IResource resource, int resourceMask) {
return (resource.getType() & resourceMask) != 0;
}
}