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:
parent
39a6ce2544
commit
47f1f6f040
11 changed files with 1291 additions and 691 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load diff
|
@ -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.
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,14 +76,16 @@ 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,420 +94,257 @@ 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);
|
|
||||||
initRefreshKey();
|
|
||||||
|
|
||||||
buildAction = new BuildAction(shell, IncrementalProjectBuilder.INCREMENTAL_BUILD);
|
openFileGroup = new OpenFileGroup(getCView());
|
||||||
rebuildAction = new BuildAction(shell, IncrementalProjectBuilder.FULL_BUILD);
|
openProjectGroup = new OpenProjectGroup(getCView());
|
||||||
|
gotoGroup = new GotoActionGroup(getCView());
|
||||||
|
buildGroup = new BuildGroup(getCView());
|
||||||
refactorGroup = new RefactorActionGroup(getCView());
|
refactorGroup = new RefactorActionGroup(getCView());
|
||||||
|
|
||||||
IWorkspace workspace = CUIPlugin.getWorkspace();
|
|
||||||
|
|
||||||
openProjectAction = new OpenResourceAction(shell);
|
openIncludeAction = new OpenIncludeAction(viewer);
|
||||||
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) {
|
||||||
goIntoAction = new GoIntoAction(framelist);
|
String property = event.getProperty();
|
||||||
backAction = new BackAction(framelist);
|
|
||||||
forwardAction = new ForwardAction(framelist);
|
if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(property)) {
|
||||||
upAction = new UpAction(framelist);
|
Object newValue = event.getNewValue();
|
||||||
|
|
||||||
|
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() {
|
|
||||||
return convertSelection (viewer.getSelection ());
|
public ISelection 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) {
|
|
||||||
viewer.setSelection (selection);
|
public void setSelection(ISelection 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());
|
||||||
|
|
||||||
collapseAllAction = new CollapseAllAction(getCView());
|
collapseAllAction = new CollapseAllAction(getCView());
|
||||||
|
|
||||||
fFileSearchAction = new FileSearchAction(viewer);
|
fFileSearchAction = new FileSearchAction(viewer);
|
||||||
fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(viewer);
|
fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(viewer);
|
||||||
fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow());
|
fSearchDialogAction = new SearchDialogAction(viewer, getCView().getViewSite().getWorkbenchWindow());
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the context menu is about to open.
|
|
||||||
* Override to add your own context dependent menu contributions.
|
|
||||||
*/
|
|
||||||
public void fillContextMenu(IMenuManager menu) {
|
|
||||||
IStructuredSelection selection= (IStructuredSelection) getCView().getViewer().getSelection();
|
|
||||||
|
|
||||||
if (selection.isEmpty()) {
|
|
||||||
new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false);
|
|
||||||
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
|
||||||
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS+"-end"));//$NON-NLS-1$
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateActions (convertSelection(selection));
|
|
||||||
//updateActions (selection);
|
|
||||||
addNewMenu(menu, selection);
|
|
||||||
menu.add(new Separator());
|
|
||||||
addOpenMenu(menu, selection);
|
|
||||||
menu.add(new Separator());
|
|
||||||
addBuildMenu(menu, selection);
|
|
||||||
menu.add(new Separator ());
|
|
||||||
refactorGroup.fillContextMenu(menu);
|
|
||||||
menu.add(new Separator());
|
|
||||||
importAction.selectionChanged(selection);
|
|
||||||
exportAction.selectionChanged(selection);
|
|
||||||
menu.add(importAction);
|
|
||||||
menu.add(exportAction);
|
|
||||||
menu.add(new Separator());
|
|
||||||
addRefreshMenu (menu, selection);
|
|
||||||
menu.add(new Separator());
|
|
||||||
addCloseMenu(menu, selection);
|
|
||||||
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+"-end"));//$NON-NLS-1$
|
|
||||||
addPropertyMenu(menu, selection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends the superclass implementation to set the context in the subgroups.
|
* Called when the context menu is about to open. Override to add your own
|
||||||
|
* context dependent menu contributions.
|
||||||
|
*/
|
||||||
|
public void fillContextMenu(IMenuManager menu) {
|
||||||
|
IStructuredSelection celements = (IStructuredSelection) getCView().getViewer().getSelection();
|
||||||
|
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(celements);
|
||||||
|
|
||||||
|
if (resources.isEmpty()) {
|
||||||
|
new NewWizardMenu(menu, getCView().getSite().getWorkbenchWindow(), false);
|
||||||
|
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||||
|
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//updateActions(resources);
|
||||||
|
addNewMenu(menu, resources);
|
||||||
|
menu.add(new Separator());
|
||||||
|
gotoGroup.fillContextMenu(menu);
|
||||||
|
menu.add(new Separator());
|
||||||
|
openFileGroup.fillContextMenu(menu);
|
||||||
|
menu.add(new Separator());
|
||||||
|
buildGroup.fillContextMenu(menu);
|
||||||
|
menu.add(new Separator());
|
||||||
|
refactorGroup.fillContextMenu(menu);
|
||||||
|
menu.add(new Separator());
|
||||||
|
importAction.selectionChanged(resources);
|
||||||
|
menu.add(importAction);
|
||||||
|
exportAction.selectionChanged(resources);
|
||||||
|
menu.add(exportAction);
|
||||||
|
menu.add(new Separator());
|
||||||
|
openProjectGroup.fillContextMenu(menu);
|
||||||
|
addBookMarkMenu(menu, resources);
|
||||||
|
menu.add(new Separator());
|
||||||
|
addSearchMenu(menu, resources);
|
||||||
|
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||||
|
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$
|
||||||
|
addPropertyMenu(menu, resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
void addBookMarkMenu(IMenuManager menu, IStructuredSelection selection) {
|
||||||
IAdaptable element = (IAdaptable)selection.getFirstElement();
|
Object obj = selection.getFirstElement();
|
||||||
IResource resource = (IResource)element.getAdapter(IResource.class);
|
if (obj instanceof IAdaptable) {
|
||||||
if (resource == null)
|
IAdaptable element = (IAdaptable) obj;
|
||||||
return;
|
IResource resource = (IResource) element.getAdapter(IResource.class);
|
||||||
|
if (resource instanceof IFile) {
|
||||||
// Create a menu flyout.
|
addBookmarkAction.selectionChanged(selection);
|
||||||
//MenuManager submenu= new MenuManager("Open With"); //$NON-NLS-1$
|
menu.add(addBookmarkAction);
|
||||||
//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) {
|
|
||||||
IAdaptable element = (IAdaptable)selection.getFirstElement();
|
|
||||||
IResource resource = (IResource)element.getAdapter(IResource.class);
|
|
||||||
if (resource == null)
|
|
||||||
return;
|
|
||||||
if (resource instanceof IFile) {
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addSearchMenu(IMenuManager menu, IStructuredSelection selection) {
|
||||||
|
IAdaptable element = (IAdaptable) selection.getFirstElement();
|
||||||
|
|
||||||
/**
|
if (element instanceof ITranslationUnit || element instanceof ICProject) {
|
||||||
* 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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If one file is selected get it.
|
MenuManager search = new MenuManager(CViewMessages.getString("SearchAction.label"), IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
|
||||||
// Otherwise, do not show the "open with" menu.
|
|
||||||
if (selection.size() != 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(resource instanceof IFile))
|
if (SearchDialogAction.canActionBeAdded(selection)) {
|
||||||
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) {
|
|
||||||
IAdaptable element = (IAdaptable)selection.getFirstElement();
|
|
||||||
|
|
||||||
if (element instanceof ITranslationUnit ||
|
|
||||||
element instanceof ICProject)
|
|
||||||
return;
|
|
||||||
|
|
||||||
MenuManager search = new MenuManager("Search", IContextMenuConstants.GROUP_SEARCH); //$NON-NLS-1$
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
|
||||||
IWorkspace workspace = CUIPlugin.getWorkspace();
|
|
||||||
workspace.removeResourceChangeListener(closeProjectAction);
|
|
||||||
workspace.removeResourceChangeListener(openProjectAction);
|
|
||||||
refactorGroup.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static IStructuredSelection convertSelection(ISelection s) {
|
public void dispose() {
|
||||||
List converted = new ArrayList();
|
IWorkspace workspace = CUIPlugin.getWorkspace();
|
||||||
if (s instanceof StructuredSelection) {
|
refactorGroup.dispose();
|
||||||
Object[] elements= ((StructuredSelection)s).toArray();
|
openFileGroup.dispose();
|
||||||
for (int i= 0; i < elements.length; i++) {
|
openProjectGroup.dispose();
|
||||||
Object e = elements[i];
|
gotoGroup.dispose();
|
||||||
if (e instanceof IAdaptable) {
|
buildGroup.dispose();
|
||||||
IResource r = (IResource)((IAdaptable)e).getAdapter(IResource.class);
|
super.dispose();
|
||||||
if (r != null)
|
|
||||||
converted.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new StructuredSelection(converted.toArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
@ -116,7 +111,7 @@ public class RefactorActionGroup extends CViewActionGroup {
|
||||||
pasteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
|
pasteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
|
||||||
pasteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
|
pasteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
|
||||||
pasteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_HOVER));
|
pasteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_HOVER));
|
||||||
|
|
||||||
copyAction = new CopyAction(shell, clipboard, pasteAction);
|
copyAction = new CopyAction(shell, clipboard, pasteAction);
|
||||||
copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
|
copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
|
||||||
copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue