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

Reogornize the CView Action menus

This commit is contained in:
Alain Magloire 2004-02-11 05:20:09 +00:00
parent 409b1021af
commit 84cfa94f9b
12 changed files with 1650 additions and 629 deletions

View file

@ -1,3 +1,15 @@
2004-02-11 Alain Magloire
Reorganize the CView to better deal with the menu actions.
* src/org/eclipse/cdt/internal/ui/cview/CopyAction.java
* src/org/eclipse/cdt/internal/ui/cview/PasteAction.java
* src/org/eclipse/cdt/internal/ui/cview/CViewActionGroup.java
* src/org/eclipse/cdt/internal/ui/cview/CViewMoveAction.java
* src/org/eclipse/cdt/internal/ui/cview/CViewRenameAction.java
* src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java
* src/org/eclipse/cdt/internal/ui/cview/RefactorActionGroup.java
2004-02-10 Hoda Amer 2004-02-10 Hoda Amer
Content Assist Preference : Reduced search options to two choices: Content Assist Preference : Reduced search options to two choices:
Current file (plus its included files) + Current project (plus its included paths) Current file (plus its included files) + Current project (plus its included paths)

View file

@ -3,59 +3,65 @@ package org.eclipse.cdt.internal.ui;
import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.cdt.ui.CUIPlugin;
/* /*
* (c) Copyright IBM Corp. 2000, 2001. * (c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
* All Rights Reserved.
*/ */
/** /**
* Help context ids for the c ui. * Help context ids for the c ui.
* <p> * <p>
* This interface contains constants only; it is not intended to be implemented * This interface contains constants only; it is not intended to be implemented or extended.
* or extended.
* </p> * </p>
* *
*/ */
public interface ICHelpContextIds { public interface ICHelpContextIds {
public static final String PREFIX= CUIPlugin.PLUGIN_ID + "."; public static final String PREFIX = CUIPlugin.PLUGIN_ID + ".";
// Wizard pages // Wizard pages
public static final String NEW_CPROJECT_WIZARD_PAGE= PREFIX + "new_cproject_wizard_page_context"; public static final String NEW_CPROJECT_WIZARD_PAGE = PREFIX + "new_cproject_wizard_page_context";
public static final String NEW_LAUNCH_WIZARD_PAGE= PREFIX + "new_launch_wizard_page_context"; public static final String NEW_LAUNCH_WIZARD_PAGE = PREFIX + "new_launch_wizard_page_context";
public static final String NEW_CLASS_WIZARD_PAGE= PREFIX + "new_class_wizard_page_context"; public static final String NEW_CLASS_WIZARD_PAGE = PREFIX + "new_class_wizard_page_context";
public static final String OPEN_CLASS_WIZARD_ACTION= PREFIX + "open_class_wizard_action"; public static final String OPEN_CLASS_WIZARD_ACTION = PREFIX + "open_class_wizard_action";
// Actions // Actions
public static final String FILTER_PUBLIC_ACTION= PREFIX + "filter_public_action"; public static final String FILTER_PUBLIC_ACTION = PREFIX + "filter_public_action";
public static final String FILTER_FIELDS_ACTION= PREFIX + "filter_fields_action"; public static final String FILTER_FIELDS_ACTION = PREFIX + "filter_fields_action";
public static final String FILTER_STATIC_ACTION= PREFIX + "filter_static_action"; public static final String FILTER_STATIC_ACTION = PREFIX + "filter_static_action";
// Preference/property pages // Preference/property pages
public static final String C_PREF_PAGE= PREFIX + "new_c_pref_page_context"; public static final String C_PREF_PAGE = PREFIX + "new_c_pref_page_context";
public static final String C_EDITOR_PREF_PAGE= PREFIX + "new_c_editor_pref_page_context"; public static final String C_EDITOR_PREF_PAGE = PREFIX + "new_c_editor_pref_page_context";
public static final String C_EDITOR_ANNOTATIONS_PREF_PAGE= PREFIX + "new_c_editor_annotations_pref_page_context"; public static final String C_EDITOR_ANNOTATIONS_PREF_PAGE = PREFIX + "new_c_editor_annotations_pref_page_context";
public static final String C_EDITOR_COLORS_PREF_PAGE= PREFIX + "new_c_editor_colors_pref_page_context"; public static final String C_EDITOR_COLORS_PREF_PAGE = PREFIX + "new_c_editor_colors_pref_page_context";
public static final String C_EDITOR_CONTENT_ASSIST_PREF_PAGE= PREFIX + "new_c_editor_content_assist_pref_page_context"; public static final String C_EDITOR_CONTENT_ASSIST_PREF_PAGE = PREFIX + "new_c_editor_content_assist_pref_page_context";
public static final String TEMPLATE_PREFERENCE_PAGE= PREFIX + "new_c_templates_pref_page_context"; public static final String TEMPLATE_PREFERENCE_PAGE = PREFIX + "new_c_templates_pref_page_context";
public static final String LAUNCH_PROPERTY_PAGE= PREFIX + "new_launch_property_page_context"; public static final String LAUNCH_PROPERTY_PAGE = PREFIX + "new_launch_property_page_context";
public static final String PROJECT_PROPERTY_PAGE= PREFIX + "new_project_property_page_context"; public static final String PROJECT_PROPERTY_PAGE = PREFIX + "new_project_property_page_context";
public static final String PROJ_CONF_BLOCK= PREFIX + "new_proj_conf_block_context"; public static final String PROJ_CONF_BLOCK = PREFIX + "new_proj_conf_block_context";
public static final String TODO_TASK_INPUT_DIALOG= PREFIX + "todo_task_input_dialog_context"; //$NON-NLS-1$ public static final String TODO_TASK_INPUT_DIALOG = PREFIX + "todo_task_input_dialog_context"; //$NON-NLS-1$
public static final String TODO_TASK_PROPERTY_PAGE= PREFIX + "tasktags_property_page_context"; //$NON-NLS-1$ public static final String TODO_TASK_PROPERTY_PAGE = PREFIX + "tasktags_property_page_context"; //$NON-NLS-1$
public static final String TODO_TASK_PREFERENCE_PAGE= PREFIX + "tasktags_preference_page_context"; //$NON-NLS-1$ public static final String TODO_TASK_PREFERENCE_PAGE = PREFIX + "tasktags_preference_page_context"; //$NON-NLS-1$
public static final String BINARY_PARSER_PAGE= PREFIX + "cdt_binary_parser_page"; //$NON-NLS-1$ public static final String BINARY_PARSER_PAGE = PREFIX + "cdt_binary_parser_page"; //$NON-NLS-1$
public static final String ERROR_PARSERS_PAGE= PREFIX + "cdt_error_parsers_page"; //$NON-NLS-1$ public static final String ERROR_PARSERS_PAGE = PREFIX + "cdt_error_parsers_page"; //$NON-NLS-1$
// Console view // Console view
public static final String CLEAR_CONSOLE_ACTION= PREFIX + "clear_console_action_context"; public static final String CLEAR_CONSOLE_ACTION = PREFIX + "clear_console_action_context";
public static final String CLEAR_CONSOLE_VIEW= PREFIX + "clear_console_view_context"; public static final String CLEAR_CONSOLE_VIEW = PREFIX + "clear_console_view_context";
public static final String TOGGLE_PRESENTATION_ACTION= PREFIX + "toggle_presentation_action_context"; //$NON-NLS-1$ public static final String TOGGLE_PRESENTATION_ACTION = PREFIX + "toggle_presentation_action_context"; //$NON-NLS-1$
public static final String TOGGLE_TEXTHOVER_ACTION= PREFIX + "toggle_texthover_action_context"; //$NON-NLS-1$ public static final String TOGGLE_TEXTHOVER_ACTION = PREFIX + "toggle_texthover_action_context"; //$NON-NLS-1$
public static final String COLLAPSE_ALL_ACTION= PREFIX + "collapse_all_action"; //$NON-NLS-1$ public static final String COLLAPSE_ALL_ACTION = PREFIX + "collapse_all_action"; //$NON-NLS-1$
public static final String C_SEARCH_PAGE = PREFIX + "c_search_page"; //$NON-NLS-1$
public static final String COPY_ACTION = PREFIX + "copy_action_context"; //$NON-NLS-1$
public static final String PASTE_ACTION = PREFIX + "paste_action_context"; //$NON_NLS-1$
public static final String MOVE_ACTION = PREFIX + "move_action_context"; //$NON-NLS-1$
public static final String RENAME_ACTION = PREFIX + "rename_action_context"; //$NON-NLS-1$
public static final String C_SEARCH_PAGE= PREFIX + "c_search_page"; //$NON-NLS-1$
} }

View file

@ -0,0 +1,97 @@
/*******************************************************************************
* 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.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
* This is the action group for all the resource navigator actions.
* It delegates to several subgroups for most of the actions.
*
* @see GotoActionGroup
* @see OpenActionGroup
* @see RefactorActionGroup
* @see SortAndFilterActionGroup
* @see WorkspaceActionGroup
*
* @since 2.0
*/
public abstract class CViewActionGroup extends ActionGroup {
/**
* The resource navigator.
*/
protected CView cview;
/**
* Constructs a new navigator action group and creates its actions.
*
* @param navigator the resource navigator
*/
public CViewActionGroup(CView cview) {
this.cview = cview;
makeActions();
}
/**
* Returns the image descriptor with the given relative path.
*/
protected ImageDescriptor getImageDescriptor(String relativePath) {
String iconPath = "icons/full/"; //$NON-NLS-1$
try {
AbstractUIPlugin plugin = (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
URL installURL = plugin.getDescriptor().getInstallURL();
URL url = new URL(installURL, iconPath + relativePath);
return ImageDescriptor.createFromURL(url);
} catch (MalformedURLException e) {
// should not happen
return ImageDescriptor.getMissingImageDescriptor();
}
}
/**
* Returns the resource navigator.
*/
public CView getCView() {
return cview;
}
/**
* Handles a key pressed event by invoking the appropriate action.
* Does nothing by default.
*/
public void handleKeyPressed(KeyEvent event) {
}
/**
* Makes the actions contained in this action group.
*/
protected abstract void makeActions();
/**
* Runs the default action in the group.
* Does nothing by default.
*
* @param selection the current selection
*/
public void runDefaultAction(IStructuredSelection selection) {
}
}

View file

@ -24,7 +24,7 @@ public class CViewFrameSource extends TreeViewerFrameSource {
cview.updateTitle(); cview.updateTitle();
} }
public CViewFrameSource(CView cview) { public CViewFrameSource(CView cview) {
super(cview.getResourceViewer()); super(cview.getViewer());
this.cview = cview; this.cview = cview;
} }
} }

View file

@ -14,3 +14,9 @@ CollapseAllAction.label=Collapse All
CollapseAllAction.tooltip=Collapse All CollapseAllAction.tooltip=Collapse All
CollapseAllAction.description=Collapse All CollapseAllAction.description=Collapse All
CopyAction.title = &Copy
CopyAction.toolTip = Copy
PasteAction.title=&Paste
PasteAction.toolTip = Paste

View file

@ -0,0 +1,84 @@
/*******************************************************************************
* 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.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.MoveProjectAction;
import org.eclipse.ui.actions.MoveResourceAction;
import org.eclipse.ui.help.WorkbenchHelp;
/**
* The ResourceNavigatorMoveAction is a resource move that aso updates the navigator
* to show the result of the move.
* It also delegates to MoveProjectAction as needed.
*
* @since 2.0
*/
public class CViewMoveAction extends MoveResourceAction {
private StructuredViewer viewer;
private MoveProjectAction moveProjectAction;
/**
* Create a ResourceNavigatorMoveAction and use the supplied viewer to update the UI.
* @param shell Shell
* @param structureViewer StructuredViewer
*/
public CViewMoveAction(Shell shell, StructuredViewer structureViewer) {
super(shell);
WorkbenchHelp.setHelp(this, ICHelpContextIds.MOVE_ACTION);
this.viewer = structureViewer;
this.moveProjectAction = new MoveProjectAction(shell);
}
/* (non-Javadoc)
* Method declared on IAction.
*/
public void run() {
if (moveProjectAction.isEnabled()) {
moveProjectAction.run();
return;
}
super.run();
List destinations = getDestinations();
if (destinations != null && destinations.isEmpty() == false) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
List resources = new ArrayList();
Iterator iterator = destinations.iterator();
while (iterator.hasNext()) {
IResource newResource = root.findMember((IPath) iterator.next());
if (newResource != null)
resources.add(newResource);
}
this.viewer.setSelection(new StructuredSelection(resources), true);
}
}
protected boolean updateSelection(IStructuredSelection selection) {
moveProjectAction.selectionChanged(selection);
return super.updateSelection(selection) || moveProjectAction.isEnabled();
}
}

View file

@ -0,0 +1,66 @@
/*******************************************************************************
* 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.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.actions.RenameResourceAction;
import org.eclipse.ui.help.WorkbenchHelp;
/**
* The ResourceNavigatorRenameAction is the rename action used by the
* ResourceNavigator that also allows updating after rename.
* @since 2.0
*/
public class CViewRenameAction extends RenameResourceAction {
private TreeViewer viewer;
/**
* Create a ResourceNavigatorRenameAction and use the tree of the supplied viewer
* for editing.
* @param shell Shell
* @param treeViewer TreeViewer
*/
public CViewRenameAction(Shell shell, TreeViewer treeViewer) {
super(shell, treeViewer.getTree());
WorkbenchHelp.setHelp(
this,
ICHelpContextIds.RENAME_ACTION);
this.viewer = treeViewer;
}
/* (non-Javadoc)
* Run the action to completion using the supplied path.
*/
protected void runWithNewPath(IPath path, IResource resource) {
IWorkspaceRoot root = resource.getProject().getWorkspace().getRoot();
super.runWithNewPath(path, resource);
if (this.viewer != null) {
IResource newResource = root.findMember(path);
if (newResource != null)
this.viewer.setSelection(new StructuredSelection(newResource), true);
}
}
/**
* Handle the key release
*/
public void handleKeyReleased(KeyEvent event) {
if (event.keyCode == SWT.F2 && event.stateMask == 0 && isEnabled()) {
run();
}
}
}

View file

@ -0,0 +1,201 @@
/*******************************************************************************
* 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 java.util.List;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.Assert;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.SelectionListenerAction;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.internal.WorkbenchMessages;
import org.eclipse.ui.part.ResourceTransfer;
/**
* Standard action for copying the currently selected resources to the clipboard.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
public class CopyAction extends SelectionListenerAction {
/**
* The id of this action.
*/
public static final String ID = PlatformUI.PLUGIN_ID + ".CopyAction"; //$NON-NLS-1$
/**
* The shell in which to show any dialogs.
*/
private Shell shell;
/**
* System clipboard
*/
private Clipboard clipboard;
/**
* Associated paste action. May be <code>null</code>
*/
private PasteAction pasteAction;
/**
* Creates a new action.
*
* @param shell the shell for any dialogs
* @param clipboard a platform clipboard
*/
public CopyAction(Shell shell, Clipboard clipboard) {
super(CViewMessages.getString("CopyAction.title")); //$NON-NLS-1$
Assert.isNotNull(shell);
Assert.isNotNull(clipboard);
this.shell = shell;
this.clipboard = clipboard;
setToolTipText(CViewMessages.getString("CopyAction.toolTip")); //$NON-NLS-1$
setId(CopyAction.ID);
WorkbenchHelp.setHelp(this, ICHelpContextIds.COPY_ACTION);
}
/**
* Creates a new action.
*
* @param shell the shell for any dialogs
* @param clipboard a platform clipboard
* @param pasteAction a paste action
*
* @since 2.0
*/
public CopyAction(Shell shell, Clipboard clipboard, PasteAction pasteAction) {
this(shell, clipboard);
this.pasteAction = pasteAction;
}
/**
* The <code>CopyAction</code> implementation of this method defined
* on <code>IAction</code> copies the selected resources to the
* clipboard.
*/
public void run() {
List selectedResources = getSelectedResources();
IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]);
// Get the file names and a string representation
final int length = resources.length;
int actualLength = 0;
String[] fileNames = new String[length];
StringBuffer buf = new StringBuffer();
for (int i = 0; i < length; i++) {
IPath location = resources[i].getLocation();
// location may be null. See bug 29491.
if (location != null)
fileNames[actualLength++] = location.toOSString();
if (i > 0)
buf.append("\n"); //$NON-NLS-1$
buf.append(resources[i].getName());
}
// was one or more of the locations null?
if (actualLength < length) {
String[] tempFileNames = fileNames;
fileNames = new String[actualLength];
for (int i = 0; i < actualLength; i++)
fileNames[i] = tempFileNames[i];
}
setClipboard(resources, fileNames, buf.toString());
// update the enablement of the paste action
// workaround since the clipboard does not suppot callbacks
if (pasteAction != null && pasteAction.getStructuredSelection() != null)
pasteAction.selectionChanged(pasteAction.getStructuredSelection());
}
/**
* Set the clipboard contents. Prompt to retry if clipboard is busy.
*
* @param resources the resources to copy to the clipboard
* @param fileNames file names of the resources to copy to the clipboard
* @param names string representation of all names
*/
private void setClipboard(IResource[] resources, String[] fileNames, String names) {
try {
// set the clipboard contents
if (fileNames.length > 0) {
clipboard.setContents(
new Object[] { resources, fileNames, names },
new Transfer[] { ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance()});
} else {
clipboard.setContents(
new Object[] { resources, names },
new Transfer[] { ResourceTransfer.getInstance(), TextTransfer.getInstance()});
}
} catch (SWTError e) {
if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
throw e;
if (MessageDialog.openQuestion(shell, WorkbenchMessages.getString("CopyToClipboardProblemDialog.title"), WorkbenchMessages.getString("CopyToClipboardProblemDialog.message"))) //$NON-NLS-1$ //$NON-NLS-2$
setClipboard(resources, fileNames, names);
}
}
/**
* The <code>CopyAction</code> implementation of this
* <code>SelectionListenerAction</code> method enables this action if
* one or more resources of compatible types are selected.
*/
protected boolean updateSelection(IStructuredSelection selection) {
if (!super.updateSelection(selection))
return false;
if (getSelectedNonResources().size() > 0)
return false;
List selectedResources = getSelectedResources();
if (selectedResources.size() == 0)
return false;
boolean projSelected = selectionIsOfType(IResource.PROJECT);
boolean fileFoldersSelected = selectionIsOfType(IResource.FILE | IResource.FOLDER);
if (!projSelected && !fileFoldersSelected)
return false;
// selection must be homogeneous
if (projSelected && fileFoldersSelected)
return false;
// must have a common parent
IContainer firstParent = ((IResource) selectedResources.get(0)).getParent();
if (firstParent == null)
return false;
Iterator resourcesEnum = selectedResources.iterator();
while (resourcesEnum.hasNext()) {
IResource currentResource = (IResource) resourcesEnum.next();
if (!currentResource.getParent().equals(firstParent))
return false;
// resource location must exist
if (currentResource.getLocation() == null)
return false;
}
return true;
}
}

View file

@ -0,0 +1,545 @@
/*******************************************************************************
* 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.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
import org.eclipse.cdt.internal.ui.editor.FileSearchAction;
import org.eclipse.cdt.internal.ui.editor.FileSearchActionInWorkingSet;
import org.eclipse.cdt.internal.ui.editor.OpenIncludeAction;
import org.eclipse.cdt.internal.ui.editor.SearchDialogAction;
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.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
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.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
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.widgets.Shell;
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.actions.AddBookmarkAction;
import org.eclipse.ui.actions.BuildAction;
import org.eclipse.ui.actions.CloseResourceAction;
import org.eclipse.ui.actions.ExportResourcesAction;
import org.eclipse.ui.actions.ImportResourcesAction;
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.dialogs.PropertyDialogAction;
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.
* This contains a few actions and several subgroups.
*/
public class MainActionGroup extends CViewActionGroup {
// Actions for Menu context.
AddBookmarkAction addBookmarkAction;
OpenFileAction openFileAction;
OpenSystemEditorAction openSystemEditorAction;
PropertyDialogAction propertyDialogAction;
ImportResourcesAction importAction;
ExportResourcesAction exportAction;
RefreshAction refreshAction;
CloseResourceAction closeProjectAction;
OpenResourceAction openProjectAction;
RefactorActionGroup refactorGroup;
BuildAction buildAction;
BuildAction rebuildAction;
// CElement action
OpenIncludeAction openIncludeAction;
BackAction backAction;
ForwardAction forwardAction;
GoIntoAction goIntoAction;
UpAction upAction;
// Collapsing
CollapseAllAction collapseAllAction;
WorkingSetFilterActionGroup wsFilterActionGroup;
ShowLibrariesAction clibFilterAction;
//Search
FileSearchAction fFileSearchAction;
FileSearchActionInWorkingSet fFileSearchActionInWorkingSet;
SearchDialogAction fSearchDialogAction;
FilterSelectionAction patternFilterAction;
// Menu tags for the build
final String BUILD_GROUP_MARKER = "buildGroup";
final String BUILD_GROUP_MARKER_END = "end-buildGroup";
public MainActionGroup (CView cview) {
super(cview);
}
/**
* Handles key events in viewer.
*/
public void handleKeyPressed(KeyEvent event) {
refactorGroup.handleKeyPressed(event);
}
/**
* Create the KeyListener for doing the refresh on the viewer.
*/
void initRefreshKey() {
final Viewer viewer = getCView().getViewer();
viewer.getControl().addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent event) {
if (event.keyCode == SWT.F5) {
refreshAction.selectionChanged(
(IStructuredSelection)viewer.getSelection());
if (refreshAction.isEnabled())
refreshAction.run();
}
}
});
}
protected void makeActions() {
final Viewer viewer = getCView().getViewer();
FrameList framelist = getCView().getFrameList();
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);
rebuildAction = new BuildAction(shell, IncrementalProjectBuilder.FULL_BUILD);
refactorGroup = new RefactorActionGroup(getCView());
IWorkspace workspace = CUIPlugin.getWorkspace();
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);
//sortByTypeAction = new SortViewAction(this, true);
patternFilterAction = new FilterSelectionAction(shell, getCView(), "Filters...");
clibFilterAction = new ShowLibrariesAction(shell, getCView(), "Show Referenced Libs");
//wsFilterActionGroup = new WorkingSetFilterActionGroup(getCView().getViewSite().getShell(), workingSetListener);
goIntoAction = new GoIntoAction(framelist);
backAction = new BackAction(framelist);
forwardAction = new ForwardAction(framelist);
upAction = new UpAction(framelist);
addBookmarkAction = new AddBookmarkAction(shell);
//propertyDialogAction = new PropertyDialogAction(shell, viewer);
propertyDialogAction = new PropertyDialogAction(shell,
new ISelectionProvider () {
public void addSelectionChangedListener(ISelectionChangedListener listener) {
viewer.addSelectionChangedListener (listener);
}
public ISelection getSelection() {
return convertSelection (viewer.getSelection ());
}
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
viewer.removeSelectionChangedListener (listener);
}
public void setSelection(ISelection selection) {
viewer.setSelection (selection);
}
});
IActionBars actionBars = getCView().getViewSite().getActionBars();
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());
exportAction = new ExportResourcesAction(getCView().getSite().getWorkbenchWindow());
collapseAllAction = new CollapseAllAction(getCView());
fFileSearchAction = new FileSearchAction(viewer);
fFileSearchActionInWorkingSet = new FileSearchActionInWorkingSet(viewer);
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.
*/
public void setContext(ActionContext context) {
super.setContext(context);
//gotoGroup.setContext(context);
//openGroup.setContext(context);
refactorGroup.setContext(context);
//sortAndFilterGroup.setContext(context);
//workspaceGroup.setContext(context);
}
void addNewMenu (IMenuManager menu, IStructuredSelection selection) {
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);
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) {
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) {
propertyDialogAction.selectionChanged(convertSelection(selection));
if (propertyDialogAction.isApplicableForSelection()) {
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) {
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);
}
if (FileSearchAction.canActionBeAdded(selection)) {
MenuManager fileSearch = new MenuManager("File Search");
fileSearch.add(fFileSearchAction);
fileSearch.add(fFileSearchActionInWorkingSet);
search.add(fileSearch);
}
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) {
updateActions(convertSelection(selection));
updateGlobalActions(convertSelection(selection));
}
/**
* Updates all actions with the given selection.
* Necessary when popping up a menu, because some of the enablement criteria
* may have changed, even if the selection in the viewer hasn't.
* E.g. A project was opened or closed.
*/
void updateActions(IStructuredSelection selection) {
goIntoAction.update();
refreshAction.selectionChanged(selection);
openFileAction.selectionChanged(selection);
openSystemEditorAction.selectionChanged(selection);
propertyDialogAction.selectionChanged(selection);
importAction.selectionChanged(selection);
exportAction.selectionChanged(selection);
refactorGroup.updateActions(selection);
//sortByTypeAction.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);
// Ensure Copy global action targets correct action,
// either copyProjectAction or copyResourceAction,
// depending on selection.
IActionBars actionBars = getCView().getViewSite().getActionBars();
actionBars.updateActionBars();
refreshAction.selectionChanged(selection);
buildAction.selectionChanged(selection);
rebuildAction.selectionChanged(selection);
openProjectAction.selectionChanged(selection);
closeProjectAction.selectionChanged(selection);
}
public void fillActionBars(IActionBars actionBars) {
IToolBarManager toolBar = actionBars.getToolBarManager();
toolBar.add(backAction);
toolBar.add(forwardAction);
toolBar.add(upAction);
toolBar.add(new Separator());
toolBar.add(collapseAllAction);
actionBars.updateActionBars();
//wsFilterActionGroup.fillActionBars(actionBars);
IMenuManager menu = actionBars.getMenuManager();
//menu.add (clibFilterAction);
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) {
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,224 @@
/*******************************************************************************
* 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.List;
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
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.jface.util.Assert;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
import org.eclipse.ui.actions.CopyProjectOperation;
import org.eclipse.ui.actions.SelectionListenerAction;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.part.ResourceTransfer;
/**
* Standard action for pasting resources on the clipboard to the selected resource's location.
* <p>
* This class may be instantiated; it is not intended to be subclassed.
* </p>
*
* @since 2.0
*/
/*package*/
public class PasteAction extends SelectionListenerAction {
/**
* The id of this action.
*/
public static final String ID = PlatformUI.PLUGIN_ID + ".PasteAction"; //$NON-NLS-1$
/**
* The shell in which to show any dialogs.
*/
private Shell shell;
/**
* System clipboard
*/
private Clipboard clipboard;
/**
* Creates a new action.
*
* @param shell the shell for any dialogs
*/
public PasteAction(Shell shell, Clipboard clipboard) {
super(CViewMessages.getString("PasteAction.title")); //$NON-NLS-1$
Assert.isNotNull(shell);
Assert.isNotNull(clipboard);
this.shell = shell;
this.clipboard = clipboard;
setToolTipText(CViewMessages.getString("PasteAction.toolTip")); //$NON-NLS-1$
setId(PasteAction.ID);
WorkbenchHelp.setHelp(this, ICHelpContextIds.PASTE_ACTION);
}
/**
* Returns the actual target of the paste action. Returns null
* if no valid target is selected.
*
* @return the actual target of the paste action
*/
private IResource getTarget() {
List selectedResources = getSelectedResources();
for (int i = 0; i < selectedResources.size(); i++) {
IResource resource = (IResource) selectedResources.get(i);
if (resource instanceof IProject && !((IProject) resource).isOpen())
return null;
if (resource.getType() == IResource.FILE)
resource = resource.getParent();
if (resource != null)
return resource;
}
return null;
}
/**
* Returns whether any of the given resources are linked resources.
*
* @param resources resource to check for linked type. may be null
* @return true=one or more resources are linked. false=none of the
* resources are linked
*/
private boolean isLinked(IResource[] resources) {
if (resources != null) {
for (int i = 0; i < resources.length; i++) {
if (resources[i].isLinked()) {
return true;
}
}
}
return false;
}
/**
* Implementation of method defined on <code>IAction</code>.
*/
public void run() {
// try a resource transfer
ResourceTransfer resTransfer = ResourceTransfer.getInstance();
IResource[] resourceData = (IResource[]) clipboard.getContents(resTransfer);
if (resourceData != null && resourceData.length > 0) {
if (resourceData[0].getType() == IResource.PROJECT) {
// enablement checks for all projects
for (int i = 0; i < resourceData.length; i++) {
CopyProjectOperation operation = new CopyProjectOperation(this.shell);
operation.copyProject((IProject) resourceData[i]);
}
} else {
// enablement should ensure that we always have access to a container
IContainer container = getContainer();
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell);
operation.copyResources(resourceData, container);
}
return;
}
// try a file transfer
FileTransfer fileTransfer = FileTransfer.getInstance();
String[] fileData = (String[]) clipboard.getContents(fileTransfer);
if (fileData != null) {
// enablement should ensure that we always have access to a container
IContainer container = getContainer();
CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(this.shell);
operation.copyFiles(fileData, container);
}
}
/**
* Returns the container to hold the pasted resources.
*/
private IContainer getContainer() {
List selection = getSelectedResources();
if (selection.get(0) instanceof IFile)
return ((IFile) selection.get(0)).getParent();
else
return (IContainer) selection.get(0);
}
/**
* The <code>PasteAction</code> implementation of this
* <code>SelectionListenerAction</code> method enables this action if
* a resource compatible with what is on the clipboard is selected.
*/
protected boolean updateSelection(IStructuredSelection selection) {
if (!super.updateSelection(selection))
return false;
// clipboard must have resources or files
ResourceTransfer resTransfer = ResourceTransfer.getInstance();
IResource[] resourceData = (IResource[]) clipboard.getContents(resTransfer);
FileTransfer fileTransfer = FileTransfer.getInstance();
String[] fileData = (String[]) clipboard.getContents(fileTransfer);
if (resourceData == null && fileData == null)
return false;
// can paste open projects regardless of selection
boolean isProjectRes = resourceData != null && resourceData.length > 0 && resourceData[0].getType() == IResource.PROJECT;
if (isProjectRes) {
for (int i = 0; i < resourceData.length; i++) {
// make sure all resource data are open projects
if (resourceData[i].getType() != IResource.PROJECT || ((IProject) resourceData[i]).isOpen() == false)
return false;
}
return true;
}
// can paste files and folders to a single selection (project must be open)
// or multiple file selection with the same parent
if (getSelectedNonResources().size() > 0)
return false;
List selectedResources = getSelectedResources();
IResource targetResource = getTarget();
// targetResource is null if no valid target is selected or
// selection is empty
if (targetResource == null)
return false;
// linked resources can only be pasted into projects
if (isLinked(resourceData) && targetResource.getType() != IResource.PROJECT)
return false;
if (selectedResources.size() > 1) {
// if more than one resource is selected the selection has
// to be all files with the same parent
for (int i = 0; i < selectedResources.size(); i++) {
IResource resource = (IResource) selectedResources.get(i);
if (resource.getType() != IResource.FILE)
return false;
if (!targetResource.equals(resource.getParent()))
return false;
}
}
if (targetResource.getType() == IResource.FOLDER && resourceData != null) {
// don't try to copy folder to self
for (int i = 0; i < resourceData.length; i++) {
if (targetResource.equals(resourceData[i]))
return false;
}
}
return true;
}
}

View file

@ -0,0 +1,159 @@
/*******************************************************************************
* 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.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.DeleteResourceAction;
import org.eclipse.ui.actions.TextActionHandler;
/**
* This is the action group for refactor actions,
* including global action handlers for copy, paste and delete.
*
*/
public class RefactorActionGroup extends CViewActionGroup {
private Clipboard clipboard;
private CopyAction copyAction;
private DeleteResourceAction deleteAction;
private PasteAction pasteAction;
private CViewRenameAction renameAction;
private CViewMoveAction moveAction;
private TextActionHandler textActionHandler;
public RefactorActionGroup(CView cview) {
super(cview);
}
public void dispose() {
if (clipboard != null) {
clipboard.dispose();
clipboard = null;
}
super.dispose();
}
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = MainActionGroup.convertSelection(getCView().getViewer().getSelection());
//(IStructuredSelection) getContext().getSelection();
boolean anyResourceSelected =
!selection.isEmpty()
&& allResourcesAreOfType(selection,
IResource.PROJECT | IResource.FOLDER | IResource.FILE);
copyAction.selectionChanged(selection);
menu.add(copyAction);
pasteAction.selectionChanged(selection);
menu.add(pasteAction);
if (anyResourceSelected) {
deleteAction.selectionChanged(selection);
menu.add(deleteAction);
moveAction.selectionChanged(selection);
menu.add(moveAction);
renameAction.selectionChanged(selection);
menu.add(renameAction);
}
}
public void fillActionBars(IActionBars actionBars) {
textActionHandler = new TextActionHandler(actionBars); // hooks handlers
textActionHandler.setCopyAction(copyAction);
textActionHandler.setPasteAction(pasteAction);
textActionHandler.setDeleteAction(deleteAction);
renameAction.setTextActionHandler(textActionHandler);
actionBars.setGlobalActionHandler(ActionFactory.MOVE.getId(), moveAction);
actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
}
/**
* Handles a key pressed event by invoking the appropriate action.
*/
public void handleKeyPressed(KeyEvent event) {
if (event.character == SWT.DEL && event.stateMask == 0) {
if (deleteAction.isEnabled()) {
deleteAction.run();
}
} else if (event.keyCode == SWT.F2 && event.stateMask == 0) {
if (renameAction.isEnabled()) {
renameAction.run();
}
}
}
protected void makeActions() {
TreeViewer treeViewer = (TreeViewer) getCView().getViewer();
Shell shell = getCView().getSite().getShell();
clipboard = new Clipboard(shell.getDisplay());
pasteAction = new PasteAction(shell, clipboard);
ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
pasteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
pasteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
pasteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_HOVER));
copyAction = new CopyAction(shell, clipboard, pasteAction);
copyAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
copyAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_HOVER));
moveAction = new CViewMoveAction(shell, treeViewer);
renameAction = new CViewRenameAction(shell, treeViewer);
deleteAction = new DeleteResourceAction(shell);
deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
deleteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_HOVER));
}
public void updateActions(IStructuredSelection selection) {
//IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
copyAction.selectionChanged(selection);
pasteAction.selectionChanged(selection);
deleteAction.selectionChanged(selection);
moveAction.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;
}
}