diff options
author | Anton Leherbauer | 2006-07-03 09:11:48 +0000 |
---|---|---|
committer | Anton Leherbauer | 2006-07-03 09:11:48 +0000 |
commit | 36c5a333f11f15e78b6495251140c516e892de12 (patch) | |
tree | b4ab1288d6b30c380b5d5316ad34c8af30223f69 | |
parent | 7f90464021151bfab78b5310f935079271cd2704 (diff) | |
download | org.eclipse.cdt-36c5a333f11f15e78b6495251140c516e892de12.tar.gz org.eclipse.cdt-36c5a333f11f15e78b6495251140c516e892de12.tar.xz org.eclipse.cdt-36c5a333f11f15e78b6495251140c516e892de12.zip |
Common Navigator extensions - bug 140337
23 files changed, 1995 insertions, 14 deletions
diff --git a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF index 9938b15a71d..5f6e1fd8b31 100644 --- a/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.make.ui/META-INF/MANIFEST.MF @@ -31,5 +31,6 @@ Require-Bundle: org.eclipse.ui.ide, org.eclipse.cdt.ui, org.eclipse.cdt.make.core, org.eclipse.core.runtime, - org.eclipse.debug.ui + org.eclipse.debug.ui, + org.eclipse.ui.navigator Eclipse-LazyStart: true diff --git a/build/org.eclipse.cdt.make.ui/plugin.xml b/build/org.eclipse.cdt.make.ui/plugin.xml index 7ee36209505..8446bae1f7c 100644 --- a/build/org.eclipse.cdt.make.ui/plugin.xml +++ b/build/org.eclipse.cdt.make.ui/plugin.xml @@ -423,4 +423,38 @@ class="org.eclipse.cdt.make.ui.dialogs.GCCPerFileSCDProfilePage" name="%GCCPerFileProfile.name" profileId="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile"/> + </extension> + <extension + point="org.eclipse.ui.navigator.navigatorContent"> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui.newCWizards" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.NewMakeCProjectWizard"> + <enablement/> + </commonWizard> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui.newCWizards" + type="new" + wizardId="org.eclipse.cdt.make.ui.wizards.NewMakeCCProjectWizard"> + <enablement/> + </commonWizard> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui.newCWizards" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.ConvertToMakeWizard"> + <enablement> + <instanceof value="org.eclipse.core.resources.IProject"/> + </enablement> + </commonWizard> + </extension> + <extension + point="org.eclipse.ui.navigator.viewer"> + <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer"> + <includes> + <contentExtension pattern="org.eclipse.cdt.make.ui.wizards.*"/> + </includes> + </viewerContentBinding> </extension></plugin> diff --git a/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF index 43034926383..2b8c23f1ef2 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF +++ b/build/org.eclipse.cdt.managedbuilder.ui/META-INF/MANIFEST.MF @@ -17,5 +17,6 @@ Require-Bundle: org.eclipse.ui.ide, org.eclipse.cdt.ui, org.eclipse.cdt.managedbuilder.core, org.eclipse.core.runtime, - org.eclipse.core.variables + org.eclipse.core.variables, + org.eclipse.ui.navigator Eclipse-LazyStart: true diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 190affe4e7d..40bec947889 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -226,5 +226,26 @@ <actionSet id="org.eclipse.cdt.managedbuilder.ui.buildConfigActionSet"/> <actionSet id="org.eclipse.cdt.managedbuilder.ui.buildSelectedFilesActionSet"/> </perspectiveExtension> + </extension> + <extension + point="org.eclipse.ui.navigator.navigatorContent"> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui.newCWizards" + type="new" + wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCCWizard"/> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui.newCWizards" + type="new" + wizardId="org.eclipse.cdt.managedbuilder.ui.wizards.StdCWizard"/> + </extension> + <extension + point="org.eclipse.ui.navigator.viewer"> + <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer"> + <includes> + <contentExtension pattern="org.eclipse.cdt.managedbuilder.ui.wizards.*"/> + </includes> + </viewerContentBinding> </extension> </plugin> diff --git a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF index 574c27fb688..4cc7601442b 100644 --- a/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui/META-INF/MANIFEST.MF @@ -66,6 +66,9 @@ Require-Bundle: org.eclipse.ui.ide, org.eclipse.ui.console, org.eclipse.core.filebuffers, org.eclipse.core.runtime, - org.eclipse.help + org.eclipse.help, + org.eclipse.ui.navigator, + org.eclipse.core.expressions, + org.eclipse.ui.navigator.resources Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.3 diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 1ed07eb4c75..af650c06a56 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -137,6 +137,12 @@ CFolderActionSet.description=C Folder Action Set DeleteTaskAction.label=Delete C/C++ Markers DeleteIProblemMarkerAction.label=Delete IProblem Markers +# Common Editor ruler actions +AddTask.label=Add &Task... +AddTask.tooltip=Add Task... +AddBookmark.label=Add Boo&kmark... +AddBookmark.tooltip=Add Bookmark... + # C/C++ Search CSearchPage.label= C/C++ Search openCSearchPageAction.label= &C/C++... @@ -333,4 +339,10 @@ RebuildIndex.name=Rebuild Index indexerPage.name = Indexer Page proposalFilter.name = Code Completion Proposal Filter includeBrowser.name = Include Browser -cSearchPage.name = CSearchPage
\ No newline at end of file +cSearchPage.name = CSearchPage + +# dummy label (not displayed) +Dummy.label = dummy + +# Common Navigator +navigatorContent.name = CDT Elements diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 88ec71ab2f0..cc63dde747e 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -1366,4 +1366,217 @@ </objectContribution> </extension> +<!--- Common Navigator extensions --> + <extension + point="org.eclipse.ui.navigator.navigatorContent"> + <navigatorContent + activeByDefault="true" + contentProvider="org.eclipse.cdt.internal.ui.navigator.CNavigatorContentProvider" + icon="icons/view16/cview.gif" + id="org.eclipse.cdt.ui.navigator.content" + labelProvider="org.eclipse.cdt.internal.ui.navigator.CNavigatorLabelProvider" + name="%navigatorContent.name" + priority="normal"> + <triggerPoints> + <or> + <adapt type="org.eclipse.core.resources.IProject"> + <or> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.cnature"/> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.ccnature"/> + </or> + </adapt> + <instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/> + <instanceof value="org.eclipse.core.resources.IFolder" /> + <instanceof value="org.eclipse.core.resources.IFile" /> + <instanceof value="org.eclipse.core.resources.IStorage" /> + <instanceof value="org.eclipse.cdt.core.model.ICProject"/> + <instanceof value="org.eclipse.cdt.core.model.ICContainer"/> + <instanceof value="org.eclipse.cdt.core.model.ICElement"/> + <instanceof value="org.eclipse.cdt.ui.CElementGrouping"/> + </or> + </triggerPoints> + <possibleChildren> + <or> + <instanceof value="org.eclipse.core.resources.IWorkspaceRoot"/> + <instanceof value="org.eclipse.core.resources.IFolder" /> + <instanceof value="org.eclipse.core.resources.IFile" /> + <instanceof value="org.eclipse.core.resources.IStorage" /> + <instanceof value="org.eclipse.cdt.core.model.ICProject"/> + <instanceof value="org.eclipse.cdt.core.model.ICContainer"/> + <instanceof value="org.eclipse.cdt.core.model.ICElement"/> + <instanceof value="org.eclipse.cdt.ui.CElementGrouping"/> + </or> + </possibleChildren> + <override + policy="InvokeAlwaysRegardlessOfSuppressedExt" + suppressedExtensionId="org.eclipse.ui.navigator.resourceContent"/> + <commonSorter + class="org.eclipse.cdt.ui.CElementSorter" + id="org.eclipse.cdt.ui.commonSorter"/> + <actionProvider + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorOpenActionProvider" + id="org.eclipse.cdt.ui.navigator.actions.open" + overrides="org.eclipse.ui.navigator.resources.OpenActions"> + <enablement> + <instanceof value="org.eclipse.cdt.core.model.ICElement"/> + </enablement> + </actionProvider> + <actionProvider + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorBuildActionProvider" + id="org.eclipse.cdt.ui.navigator.actions.build"> + <enablement> + <instanceof value="org.eclipse.cdt.core.model.ICElement"/> + </enablement> + </actionProvider> + <actionProvider + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorWorkingSetActionProvider" + id="org.eclipse.cdt.ui.navigator.actions.workingSet"> + </actionProvider> + <actionProvider + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorSearchActionProvider" + id="org.eclipse.cdt.ui.navigator.actions.search"> + <enablement> + <instanceof value="org.eclipse.cdt.core.model.ICElement"/> + </enablement> + </actionProvider> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.NewSourceFileCreationWizard"> + <enablement> + <or> + <instanceof value="org.eclipse.cdt.core.model.ICElement" /> + <adapt type="org.eclipse.core.resources.IProject"> + <or> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.cnature"/> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.ccnature"/> + </or> + </adapt> + </or> + </enablement> + </commonWizard> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.NewHeaderFileCreationWizard"> + <enablement> + <or> + <instanceof value="org.eclipse.cdt.core.model.ICElement" /> + <adapt type="org.eclipse.core.resources.IProject"> + <or> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.cnature"/> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.ccnature"/> + </or> + </adapt> + </or> + </enablement> + </commonWizard> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.NewSourceFolderCreationWizard"> + <enablement> + <or> + <instanceof value="org.eclipse.cdt.core.model.ICElement" /> + <adapt type="org.eclipse.core.resources.IProject"> + <or> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.cnature"/> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.ccnature"/> + </or> + </adapt> + </or> + </enablement> + </commonWizard> + <commonWizard + associatedExtensionId="org.eclipse.cdt.ui.navigator.content" + menuGroupId="org.eclipse.cdt.ui" + type="new" + wizardId="org.eclipse.cdt.ui.wizards.NewClassCreationWizard"> + <enablement> + <or> + <instanceof value="org.eclipse.cdt.core.model.ICElement" /> + <adapt type="org.eclipse.core.resources.IProject"> + <or> + <test + property="org.eclipse.core.resources.projectNature" + value="org.eclipse.cdt.core.ccnature"/> + </or> + </adapt> + </or> + </enablement> + </commonWizard> + <dropAssistant + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDropAdapterAssistant" + id="org.eclipse.cdt.ui.navigator.dropAssistant"> + <possibleDropTargets> + <or> + <instanceof value="org.eclipse.cdt.core.model.ISourceReference"/> + </or> + </possibleDropTargets> + </dropAssistant> + </navigatorContent> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.ExecutableFilter" + description="%HideExecutableFiles.description" + id="org.eclipse.cdt.ui.navigator.filters.ExecutableFilter" + name="%HideExecutableFiles.label"/> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.SharedFilter" + description="%HideSharedFiles.description" + id="org.eclipse.cdt.ui.navigator.filters.SharedFilter" + name="%HideSharedFiles.label"/> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.ObjectFilter" + description="%HideObjectFiles.description" + id="org.eclipse.cdt.ui.navigator.filters.ObjectFilter" + name="%HideObjectFiles.label"/> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.ArchiveFilter" + description="%HideArchiveFiles.description" + id="org.eclipse.cdt.ui.navigator.filters.ArchiveFilter" + name="%HideArchiveFiles.label"/> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.NonCProjectsFilter" + description="%HideNonCProjects.description" + id="org.eclipse.cdt.ui.navigator.filters.NonCProjectsFilter" + name="%HideNonCProjects.label"/> + <commonFilter + class="org.eclipse.cdt.internal.ui.filters.NonCElementFilter" + description="%HideNonCElements.description" + id="org.eclipse.cdt.ui.navigator.filters.NonCElementFilter" + name="%HideNonCElements.label"/> + </extension> + <extension + point="org.eclipse.ui.navigator.viewer"> + <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer"> + <includes> + <contentExtension pattern="org.eclipse.cdt.ui.navigator.content"/> + <contentExtension pattern="org.eclipse.cdt.ui.navigator.filters.*"/> + <contentExtension pattern="org.eclipse.cdt.ui.wizards.*"/> + </includes> + </viewerContentBinding> + <dragAssistant + class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDragAdapterAssistant" + viewerId="org.eclipse.ui.navigator.ProjectExplorer"/> + </extension> + </plugin> diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java index e4a7c3034ea..969fb67a2f3 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/cview/MainActionGroup.java @@ -180,7 +180,7 @@ public class MainActionGroup extends CViewActionGroup { //Can be added once support for manually adding external files to index is established /*menu.add(new Separator()); menu.add(addToIndexAction);*/ - menu.add(new Separator()); + menu.add(new Separator(org.eclipse.search.ui.IContextMenuConstants.GROUP_SEARCH)); addSearchMenu(menu, celements); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/AbstractCNavigatorActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/AbstractCNavigatorActionGroup.java new file mode 100644 index 00000000000..430e85208ac --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/AbstractCNavigatorActionGroup.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import java.net.URL; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.Assert; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionGroup; + +/** + * A basic abstract action group implementation similar to + * {@link org.eclipse.cdt.internal.ui.cview.CViewActionGroup}, avoiding + * the explicit dependency on {@link org.eclipse.cdt.internal.ui.cview.CView} to + * allow reuse in the Common Navigator. + * + * @see org.eclipse.cdt.internal.ui.cview.CViewActionGroup + */ +public abstract class AbstractCNavigatorActionGroup extends ActionGroup { + + /** + * The view part this action group is associated with. + */ + private final IViewPart fViewPart; + + /** + * Create a new action group associated with given view part. + * + * @param viewPart + * the view part this action group is associated with, may not be + * <code>null</code>. + */ + public AbstractCNavigatorActionGroup(IViewPart viewPart) { + Assert.isNotNull(viewPart); + fViewPart = viewPart; + makeActions(); + } + + /** + * Provide access to the view part this action group has been registered with. + * + * @return the view part + */ + protected IViewPart getViewPart() { + return fViewPart; + } + + /** + * Returns the image descriptor with the given relative path. + */ + protected ImageDescriptor getImageDescriptor(String relativePath) { + String iconPath = "/icons/" + relativePath; //$NON-NLS-1$ + URL iconURL = FileLocator.find(CUIPlugin.getDefault().getBundle(), new Path(iconPath), null); + // it's safe to pass null + return ImageDescriptor.createFromURL(iconURL); + } + + /** + * Makes the actions contained in this action group. + */ + protected abstract void makeActions(); + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public abstract void fillContextMenu(IMenuManager menu); + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public abstract void fillActionBars(IActionBars actionBars); + + /* + * @see org.eclipse.ui.actions.ActionGroup#updateActionBars() + */ + public abstract void updateActionBars(); + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionGroup.java new file mode 100644 index 00000000000..4f2585d8400 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionGroup.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import java.util.Iterator; + +import org.eclipse.cdt.internal.ui.cview.CViewMessages; +import org.eclipse.core.resources.ICommand; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +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.widgets.Shell; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.BuildAction; +import org.eclipse.ui.navigator.ICommonMenuConstants; + +/** + * Common Navigator compatible clone of {@link org.eclipse.cdt.internal.ui.cview.BuildGroup}. + * <p> + * Adds action "Clean Project" and group marker "buildGroup" to the context menu. + * </p> + * @see org.eclipse.cdt.internal.ui.cview.BuildGroup + * @see org.eclipse.ui.actions.BuildAction + */ +public class CNavigatorBuildActionGroup extends AbstractCNavigatorActionGroup { + + private BuildAction fCleanAction; + + // Menu tags for the build + final String BUILD_GROUP_MARKER= "buildGroup"; //$NON-NLS-1$ + final String BUILD_GROUP_MARKER_END= "end-buildGroup"; //$NON-NLS-1$ + + /** + * Create action group associated with given view part. + * @param viewPart + */ + public CNavigatorBuildActionGroup(IViewPart viewPart) { + super(viewPart); + } + + public void fillActionBars(IActionBars actionBars) { + } + + /** + * 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 + + 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) { + 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; + if (hasBuilder && !hasBuilder(project)) { + hasBuilder= false; + } + } else { + hasClosedProjects= true; + hasBuilder= false; + } + } + + menu.insertAfter(ICommonMenuConstants.GROUP_BUILD, new GroupMarker(BUILD_GROUP_MARKER)); + + if (!selection.isEmpty() && isProjectSelection && hasBuilder) { + fCleanAction.selectionChanged(selection); + if (fCleanAction.isEnabled()) { + menu.appendToGroup(BUILD_GROUP_MARKER, fCleanAction); + } + } + menu.appendToGroup(BUILD_GROUP_MARKER, new GroupMarker(BUILD_GROUP_MARKER_END)); + } + + /** + * 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= getViewPart().getSite().getShell(); + + fCleanAction= new BuildAction(shell, IncrementalProjectBuilder.CLEAN_BUILD); + fCleanAction.setText(CViewMessages.getString("CleanAction.label")); //$NON-NLS-1$ + + } + + public void updateActionBars() { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionProvider.java new file mode 100644 index 00000000000..630d9efeb7b --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorBuildActionProvider.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; + +/** + * A Common Navigator action provider providing the contributions + * from the build action group. + * + * @see CNavigatorBuildActionGroup + */ +public class CNavigatorBuildActionProvider extends CommonActionProvider { + + private CNavigatorBuildActionGroup fBuildGroup; + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) + */ + public void init(ICommonActionExtensionSite site) { + ICommonViewerWorkbenchSite workbenchSite= null; + if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { + workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); + } + if (workbenchSite != null) { + if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { + IViewPart viewPart= (IViewPart) workbenchSite.getPart(); + + fBuildGroup= new CNavigatorBuildActionGroup(viewPart); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + public void dispose() { + if (fBuildGroup != null) { + fBuildGroup.dispose(); + fBuildGroup = null; + } + super.dispose(); + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + if (fBuildGroup != null) { + fBuildGroup.fillActionBars(actionBars); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (fBuildGroup != null) { + fBuildGroup.fillContextMenu(menu); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext) + */ + public void setContext(ActionContext context) { + super.setContext(context); + if (fBuildGroup != null) { + fBuildGroup.setContext(context); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorContentProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorContentProvider.java new file mode 100644 index 00000000000..9b624c6bcc2 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorContentProvider.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICModel; +import org.eclipse.cdt.internal.ui.cview.CViewContentProvider; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.ui.PreferenceConstants; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; +import org.eclipse.ui.navigator.IPipelinedTreeContentProvider; +import org.eclipse.ui.navigator.PipelinedShapeModification; +import org.eclipse.ui.navigator.PipelinedViewerUpdate; + +/** + * A content provider populating a Common Navigator view with CDT model content. + */ +public class CNavigatorContentProvider extends CViewContentProvider implements IPipelinedTreeContentProvider { + + /** The input object as supplied in the call to {@link #inputChanged()} */ + private Object fRealInput; + private IPropertyChangeListener fPropertyChangeListener; + + /* + * @see org.eclipse.ui.navigator.ICommonContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) + */ + public void init(ICommonContentExtensionSite commonContentExtensionSite) { + IMemento memento= commonContentExtensionSite.getMemento(); + restoreState(memento); + + fPropertyChangeListener= new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + boolean refreshViewer= false; + String property= event.getProperty(); + Object newValue= event.getNewValue(); + + if (property.equals(PreferenceConstants.PREF_SHOW_CU_CHILDREN)) { + boolean showCUChildren= newValue instanceof Boolean ? ((Boolean)newValue).booleanValue() : false; + setProvideMembers(showCUChildren); + refreshViewer= true; + } else if (property.equals(PreferenceConstants.CVIEW_GROUP_INCLUDES)) { + boolean groupIncludes= newValue instanceof Boolean ? ((Boolean)newValue).booleanValue() : false; + setIncludesGrouping(groupIncludes); + refreshViewer= true; + } + + if (refreshViewer && getViewer() != null) { + getViewer().refresh(); + } + } + }; + CUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyChangeListener); + // TLETODO [CN] use extension state model for view options persistence +// fStateModel.addPropertyChangeListener(listener); + } + + /* + * @see org.eclipse.cdt.ui.CElementContentProvider#dispose() + */ + public void dispose() { + CUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyChangeListener); + // TLETODO [CN] use extension state model for view options persistence +// fStateModel.removePropertyChangeListener(fPropertyChangeListener); + super.dispose(); + } + + /* + * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) + */ + public void restoreState(IMemento memento) { + IPreferenceStore store= PreferenceConstants.getPreferenceStore(); + boolean showCUChildren= store.getBoolean(PreferenceConstants.PREF_SHOW_CU_CHILDREN); + boolean groupIncludes= store.getBoolean(PreferenceConstants.CVIEW_GROUP_INCLUDES); + if (memento != null) { + String mementoValue= memento.getString(PreferenceConstants.PREF_SHOW_CU_CHILDREN); + if (mementoValue != null) { + showCUChildren= Boolean.parseBoolean(mementoValue); + } + mementoValue= memento.getString(PreferenceConstants.CVIEW_GROUP_INCLUDES); + if (mementoValue != null) { + groupIncludes= Boolean.parseBoolean(mementoValue); + } + } + setProvideMembers(showCUChildren); + setIncludesGrouping(groupIncludes); + setProvideWorkingCopy(true); + } + + /* + * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) + */ + public void saveState(IMemento memento) { + if (memento != null) { + memento.putString(PreferenceConstants.PREF_SHOW_CU_CHILDREN, String.valueOf(getProvideMembers())); + memento.putString(PreferenceConstants.CVIEW_GROUP_INCLUDES, String.valueOf(areIncludesGroup())); + } + } + + /* + * @see org.eclipse.cdt.ui.CElementContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + fRealInput= newInput; + super.inputChanged(viewer, oldInput, findInputElement(newInput)); + } + + private Object findInputElement(Object newInput) { + if (newInput instanceof IWorkspaceRoot) { + return CoreModel.create((IWorkspaceRoot) newInput); + } + return newInput; + } + + /* + * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + Object parent= super.getParent(element); + if (parent instanceof ICModel) { + return getViewerInput() != null ? fRealInput : parent; + } + return parent; + } + + /** + * Access the viewer input. + * @return the viewer input + */ + protected Object getViewerInput() { + return fInput; + } + + /** + * Access the viewer. + * @return the viewer + */ + protected Viewer getViewer() { + return fViewer; + } + + /* + * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object parent) { + if (parent instanceof IWorkspaceRoot) { + return super.getElements(CoreModel.create((IWorkspaceRoot)parent)); + } + return super.getElements(parent); + } + + /* + * @see org.eclipse.cdt.internal.ui.cview.CViewContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object element) { + Object children[]; + if (element instanceof IWorkspaceRoot) { + children = super.getChildren(CoreModel.create((IWorkspaceRoot)element)); + } else { + children = super.getChildren(element); + } + return children; + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set) + */ + public void getPipelinedChildren(Object parent, Set currentChildren) { + Object[] children= getChildren(parent); + for (Iterator iter= currentChildren.iterator(); iter.hasNext();) { + if (iter.next() instanceof IResource) { + iter.remove(); + } + } + currentChildren.addAll(Arrays.asList(children)); + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedElements(java.lang.Object, java.util.Set) + */ + public void getPipelinedElements(Object input, Set currentElements) { + // only replace plain resource elements with custom elements + // and avoid duplicating elements already customized + // by upstream content providers + Object[] elements= getElements(input); + List elementList= Arrays.asList(elements); + for (Iterator iter= currentElements.iterator(); iter.hasNext();) { + Object element= iter.next(); + IResource resource= null; + if (element instanceof IResource) { + resource= (IResource)element; + } else if (element instanceof IAdaptable) { + resource= (IResource)((IAdaptable)element).getAdapter(IResource.class); + } + if (resource != null) { + int i= elementList.indexOf(resource); + if (i >= 0) { + elements[i]= null; + } + } + } + for (int i= 0; i < elements.length; i++) { + Object element= elements[i]; + if (element instanceof ICElement) { + ICElement cElement= (ICElement)element; + IResource resource= cElement.getResource(); + if (resource != null) { + currentElements.remove(resource); + } + currentElements.add(element); + } else if (element != null) { + currentElements.add(element); + } + } + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedParent(java.lang.Object, java.lang.Object) + */ + public Object getPipelinedParent(Object object, Object suggestedParent) { + return getParent(object); + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification) + */ + public PipelinedShapeModification interceptAdd(PipelinedShapeModification addModification) { + convertToCElements(addModification); + return addModification; + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRefresh(org.eclipse.ui.navigator.PipelinedViewerUpdate) + */ + public boolean interceptRefresh(PipelinedViewerUpdate refreshSynchronization) { + return convertToCElements(refreshSynchronization.getRefreshTargets()); + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRemove(org.eclipse.ui.navigator.PipelinedShapeModification) + */ + public PipelinedShapeModification interceptRemove(PipelinedShapeModification removeModification) { + convertToCElements(removeModification.getChildren()); + return removeModification; + } + + /* + * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptUpdate(org.eclipse.ui.navigator.PipelinedViewerUpdate) + */ + public boolean interceptUpdate(PipelinedViewerUpdate updateSynchronization) { + return convertToCElements(updateSynchronization.getRefreshTargets()); + } + + /** + * Converts the shape modification to use ICElements. + * + * @param modification + * the shape modification to convert + * @return <code>true</code> if the shape modification set was modified + */ + private boolean convertToCElements( + PipelinedShapeModification modification) { + Object parent= modification.getParent(); + if (parent instanceof IContainer) { + ICElement element= CoreModel.getDefault().create((IContainer) parent); + if (element != null && element.exists()) { + // don't convert the root + if( !(element instanceof ICModel)) { + modification.setParent(element); + } + return convertToCElements(modification.getChildren()); + + } + } + return false; + } + + /** + * Converts the given set to ICElements. + * + * @param currentChildren + * The set of current children that would be contributed or + * refreshed in the viewer. + * @return <code>true</code> if the input set was modified + */ + private boolean convertToCElements(Set currentChildren) { + LinkedHashSet convertedChildren= new LinkedHashSet(); + ICElement newChild; + for (Iterator iter= currentChildren.iterator(); iter.hasNext();) { + Object child= iter.next(); + if (child instanceof IResource) { + if ((newChild= CoreModel.getDefault().create((IResource) child)) != null + && newChild.exists()) { + iter.remove(); + convertedChildren.add(newChild); + } + } + } + if (!convertedChildren.isEmpty()) { + currentChildren.addAll(convertedChildren); + return true; + } + return false; + + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java new file mode 100644 index 00000000000..8d59412e752 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDragAdapterAssistant.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import java.util.Iterator; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.ui.navigator.CommonDragAdapterAssistant; +import org.eclipse.ui.views.navigator.LocalSelectionTransfer; + + +/** + * A Common Navigator drag assistant for <code>ICElement</code>s being also + * <code>ISourceReference</code>s. + * + * @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDragAdapter + * @see org.eclipse.cdt.internal.ui.cview.CView#initDrag() + */ +public class CNavigatorDragAdapterAssistant extends CommonDragAdapterAssistant { + + /* + * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#getSupportedTransferTypes() + */ + public Transfer[] getSupportedTransferTypes() { + Transfer[] transfers= new Transfer[] { + LocalSelectionTransfer.getInstance() + }; + return transfers; + } + + /* + * @see org.eclipse.ui.navigator.CommonDragAdapterAssistant#setDragData(org.eclipse.swt.dnd.DragSourceEvent, org.eclipse.jface.viewers.IStructuredSelection) + */ + public boolean setDragData(DragSourceEvent event, + IStructuredSelection selection) { + if (selection instanceof IStructuredSelection) { + for (Iterator iter= ((IStructuredSelection)selection).iterator(); iter.hasNext();) { + Object element= iter.next(); + if (element instanceof ICElement) { + if (!(element instanceof ISourceReference)) { + return false; + } + } + } + event.data = selection; + return true; + } + return false; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java new file mode 100644 index 00000000000..5f1f45be50e --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorDropAdapterAssistant.java @@ -0,0 +1,258 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.internal.ui.cview.CViewMessages; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.TransferData; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonDropAdapterAssistant; + +/** + * A Common Navigator drop adapter assistant handling dropping of <code>ICElement</code>s. + * + * @see org.eclipse.cdt.internal.ui.cview.SelectionTransferDropAdapter + * @see org.eclipse.cdt.internal.ui.cview.CView#initDrop() + */ +public class CNavigatorDropAdapterAssistant extends CommonDropAdapterAssistant { + + /* + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) + */ + public IStatus handleDrop(CommonDropAdapter dropAdapter, + DropTargetEvent event, Object target) { + try { + switch(event.detail) { + case DND.DROP_MOVE: + return handleDropMove(target, event); + case DND.DROP_COPY: + return handleDropCopy(target, event); + } + } catch (CModelException e){ + ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$ + return e.getStatus(); + } catch(InvocationTargetException e) { + ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.exception")); //$NON-NLS-1$ //$NON-NLS-2$ + return Status.CANCEL_STATUS; + } catch (InterruptedException e) { + //ok + } finally { + // The drag source listener must not perform any operation + // since this drop adapter did the remove of the source even + // if we moved something. + event.detail= DND.DROP_NONE; + } + return Status.CANCEL_STATUS; + } + + /* + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) + */ + public IStatus validateDrop(Object target, int operation, + TransferData transferType) { + try { + switch(operation) { + case DND.DROP_DEFAULT: + return handleValidateMove(target); + case DND.DROP_COPY: + return handleValidateCopy(target); + case DND.DROP_MOVE: + return handleValidateMove(target); + } + } catch (CModelException e){ + ExceptionHandler.handle(e, CViewMessages.getString("SelectionTransferDropAdapter.error.title"), CViewMessages.getString("SelectionTransferDropAdapter.error.message")); //$NON-NLS-1$ //$NON-NLS-2$ + } + return Status.CANCEL_STATUS; + } + + private IStatus handleValidateCopy(Object target) throws CModelException{ + if (target != null) { + + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + ICElement[] cElements= getCElements(selection); + + if (!canCopyElements(cElements)) + return Status.CANCEL_STATUS; + + if (target instanceof ISourceReference) { + return Status.OK_STATUS; + } + + } + return Status.CANCEL_STATUS; + } + + private IStatus handleValidateMove(Object target) throws CModelException { + if (target != null) { + + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + ICElement[] cElements= getCElements(selection); + + if (!canMoveElements(cElements)) + return Status.CANCEL_STATUS; + + if (target instanceof ISourceReference) { + return Status.OK_STATUS; + } + + } + return Status.CANCEL_STATUS; + } + + private IStatus handleDropCopy(final Object target, DropTargetEvent event) throws CModelException, InvocationTargetException, InterruptedException{ + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + final ICElement[] cElements= getCElements(selection); + + if (target instanceof ICElement) { + ICElement cTarget = (ICElement)target; + ICElement parent = cTarget; + boolean isTargetTranslationUnit = cTarget instanceof ITranslationUnit; + if (!isTargetTranslationUnit) { + parent = cTarget.getParent(); + } + final ICElement[] containers = new ICElement[cElements.length]; + for (int i = 0; i < containers.length; ++i) { + containers[i] = parent; + } + ICElement[] neighbours = null; + if (!isTargetTranslationUnit) { + neighbours = new ICElement[cElements.length]; + for (int i = 0; i < neighbours.length; ++i) { + neighbours[i] = cTarget; + } + } + final ICElement[] siblings = neighbours; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + CoreModel.getDefault().getCModel().copy(cElements, containers, siblings, null, false, monitor); + } catch (CModelException e) { + throw new InvocationTargetException(e); + } + } + }; + run(runnable); + return Status.OK_STATUS; + } + return Status.CANCEL_STATUS; + } + + private IStatus handleDropMove(final Object target, DropTargetEvent event) throws CModelException, InvocationTargetException, InterruptedException{ + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + final ICElement[] cElements= getCElements(selection); + + if (target instanceof ICElement) { + ICElement cTarget = (ICElement)target; + ICElement parent = cTarget; + boolean isTargetTranslationUnit = cTarget instanceof ITranslationUnit; + if (!isTargetTranslationUnit) { + parent = cTarget.getParent(); + } + final ICElement[] containers = new ICElement[cElements.length]; + for (int i = 0; i < containers.length; ++i) { + containers[i] = parent; + } + ICElement[] neighbours = null; + if (!isTargetTranslationUnit) { + neighbours = new ICElement[cElements.length]; + for (int i = 0; i < neighbours.length; ++i) { + neighbours[i] = cTarget; + } + } + final ICElement[] siblings = neighbours; + IRunnableWithProgress runnable = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + CoreModel.getDefault().getCModel().move(cElements, containers, siblings, null, false, monitor); + } catch (CModelException e) { + throw new InvocationTargetException(e); + } + } + }; + run(runnable); + return Status.OK_STATUS; + } + return Status.CANCEL_STATUS; + } + + public void run(IRunnableWithProgress runnable) throws InterruptedException, InvocationTargetException { + IRunnableContext context= new ProgressMonitorDialog(getShell()); + context.run(true, true, runnable); + } + + public static ICElement[] getCElements(ISelection selection) { + if (!(selection instanceof IStructuredSelection)) { + return null; + } + List elements = ((IStructuredSelection)selection).toList(); + List resources= new ArrayList(elements.size()); + for (Iterator iter= elements.iterator(); iter.hasNext();) { + Object element= iter.next(); + if (element instanceof ITranslationUnit) { + continue; + } + if (element instanceof ICElement) + resources.add(element); + } + return (ICElement[]) resources.toArray(new ICElement[resources.size()]); + } + + private static boolean canCopyElements(ICElement[] cElements) { + if (cElements != null) { + return hasCommonParent(cElements); + } + return false; + } + + private static boolean canMoveElements(ICElement[] cElements) { + if (cElements != null) { + return hasCommonParent(cElements); + } + return false; + } + + private static boolean hasCommonParent(ICElement[] elements) { + if (elements.length > 1) { + ICElement parent = elements[0]; + for (int i = 0; i < elements.length; ++i) { + ICElement p = elements[i].getParent(); + if (parent == null && p!= null) { + return false; + } else if (!parent.equals(p)){ + return false; + } + } + } + return true; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorLabelProvider.java new file mode 100644 index 00000000000..3ef26de5c2a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorLabelProvider.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.cdt.core.model.IArchiveContainer; +import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.IBinaryContainer; +import org.eclipse.cdt.core.model.IBinaryModule; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider; +import org.eclipse.cdt.internal.ui.cview.CViewMessages; +import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; +import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; +import org.eclipse.core.resources.IResource; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.navigator.ICommonContentExtensionSite; +import org.eclipse.ui.navigator.ICommonLabelProvider; + +/** + * A label provider suitable for the Common Navigator providing also + * status message text for the current selected item. + * + * @see org.eclipse.cdt.internal.ui.cview.CView#getStatusLineMessage() + */ +public class CNavigatorLabelProvider extends CViewLabelProvider implements ICommonLabelProvider { + + /** + * Create a default label provider. + * + * @see org.eclipse.cdt.internal.ui.cview.CView#createLabelProvider() + */ + public CNavigatorLabelProvider() { + super(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS, + AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS + | CElementImageProvider.SMALL_ICONS); + } + + /* + * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) + */ + public void init(ICommonContentExtensionSite extensionSite) { + // no-op + } + + /* + * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) + */ + public void restoreState(IMemento memento) { + // no-op + } + + /* + * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) + */ + public void saveState(IMemento memento) { + // no-op + } + + /* + * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) + */ + public String getDescription(Object element) { + if (element instanceof IResource) { + return ((IResource) element).getFullPath().makeRelative().toString(); + } else if (element instanceof ICElement) { + ICElement celement = (ICElement) element; + IResource res = (IResource) celement.getAdapter(IResource.class); + if (res != null) { + return res.getFullPath().toString(); + } else if (celement.getElementType() == ICElement.C_VCONTAINER) { + if (celement instanceof IBinaryContainer) { + ICProject cproj = celement.getCProject(); + if (cproj != null) { + return cproj.getPath() + CViewMessages.getString("CView.binaries"); //$NON-NLS-1$ + } + } else if (celement instanceof IArchiveContainer) { + ICProject cproj = celement.getCProject(); + if (cproj != null) { + return cproj.getPath() + CViewMessages.getString("CView.archives"); //$NON-NLS-1$ + } + } else if (celement instanceof IBinaryModule) { + IBinary bin = ((IBinaryModule) celement).getBinary(); + return bin.getPath() + ":" + celement.getElementName(); //$NON-NLS-1$ + } + } else if (celement.getElementType() > ICElement.C_UNIT) { + return celement.getPath().toString() + " - [" + celement.getElementName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + return celement.getElementName(); + } else if (element instanceof IWorkbenchAdapter) { + IWorkbenchAdapter wAdapter = (IWorkbenchAdapter)element; + return wAdapter.getLabel(element); + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenActionProvider.java new file mode 100644 index 00000000000..9e5f0e3a3e3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenActionProvider.java @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.ICommonActionConstants; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; + +/** + * A Common Navigator action provider providing the contributions + * from the open editor action group. + * + * @see CNavigatorOpenEditorActionGroup + */ +public class CNavigatorOpenActionProvider extends CommonActionProvider { + + private CNavigatorOpenEditorActionGroup fOpenGroup; + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) + */ + public void init(ICommonActionExtensionSite site) { + ICommonViewerWorkbenchSite workbenchSite = null; + if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { + workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite(); + } + if (workbenchSite != null) { + if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { + IViewPart viewPart = (IViewPart) workbenchSite.getPart(); + + fOpenGroup = new CNavigatorOpenEditorActionGroup(viewPart); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + public void dispose() { + if (fOpenGroup != null) { + fOpenGroup.dispose(); + fOpenGroup = null; + } + super.dispose(); + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + if (fOpenGroup != null) { + fOpenGroup.updateActionBars(); + if (fOpenGroup.getOpenAction().isEnabled()) { + actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, fOpenGroup.getOpenAction()); + } + } + + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (fOpenGroup != null) { + if (fOpenGroup.getOpenAction().isEnabled()) { + fOpenGroup.fillContextMenu(menu); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext) + */ + public void setContext(ActionContext context) { + super.setContext(context); + if (fOpenGroup != null) { + fOpenGroup.setContext(context); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenEditorActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenEditorActionGroup.java new file mode 100644 index 00000000000..ffffc8ac152 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorOpenEditorActionGroup.java @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Anton Leherbauer (Wind River Systems) - adaptations for Common Navigator + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.cdt.internal.ui.actions.SelectionConverter; +import org.eclipse.cdt.internal.ui.cview.CViewMessages; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.action.IAction; +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.IViewPart; +import org.eclipse.ui.actions.OpenFileAction; +import org.eclipse.ui.actions.OpenInNewWindowAction; +import org.eclipse.ui.actions.OpenWithMenu; +import org.eclipse.ui.navigator.ICommonMenuConstants; + + +/** + * This is basically a clone of {@link org.eclipse.cdt.internal.ui.OpenFileGroup}, + * but without explicit dependency on CView. This opens it up for use in the + * Common Navigator framework. + * <p> + * Contributes an "Open" action for the default editor, an "Open With" sub-menu + * for all applicable editors if one or more files are selected. + * For all container selections, an "Open In New Window" action is contributed. + * </p> + * + * @see org.eclipse.cdt.internal.ui.cview.OpenFileGroup + * @see org.eclipse.ui.actions.OpenFileAction + * @see org.eclipse.ui.actions.OpenWithMenu + * @see org.eclipse.ui.actions.OpenInNewWindowAction + */ +public class CNavigatorOpenEditorActionGroup extends AbstractCNavigatorActionGroup { + + /** The open file action. */ + private OpenFileAction fOpenFileAction; + + /** + * Create an action group for the given view part. + * + * @param viewPart + */ + public CNavigatorOpenEditorActionGroup(IViewPart viewPart) { + super(viewPart); + } + + protected void makeActions() { + fOpenFileAction= new OpenCElementAction(getViewPart().getSite().getPage()); + } + + public void fillContextMenu(IMenuManager menu) { + IStructuredSelection celements= (IStructuredSelection) getContext().getSelection(); + IStructuredSelection selection= SelectionConverter.convertSelectionToResources(celements); + + fOpenFileAction.selectionChanged(celements); + if (fOpenFileAction.isEnabled()) { + menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, fOpenFileAction); + fillOpenWithMenu(menu, selection); + } + + 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"), ICommonMenuConstants.GROUP_OPEN_WITH); //$NON-NLS-1$ + submenu.add(new OpenWithMenu(getViewPart().getSite().getPage(), (IFile) element)); + menu.insertAfter(ICommonMenuConstants.GROUP_OPEN_WITH, 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.appendToGroup(ICommonMenuConstants.GROUP_OPEN, new OpenInNewWindowAction(getViewPart().getSite().getWorkbenchWindow(), (IContainer) element)); + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#updateActionBars() + */ + public void updateActionBars() { + IStructuredSelection celements= (IStructuredSelection) getContext().getSelection(); + fOpenFileAction.selectionChanged(celements); + } + + /** + * Returns the open action managed by this action group. + * + * @return the open action + */ + IAction getOpenAction() { + return fOpenFileAction; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorSearchActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorSearchActionProvider.java new file mode 100644 index 00000000000..929b9cb4b25 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorSearchActionProvider.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; + +/** + * Common Navigator action provider for the C-search sub menus. + * + * @see org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup + */ +public class CNavigatorSearchActionProvider extends CommonActionProvider { + + private SelectionSearchGroup fSearchGroup; + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) + */ + public void init(ICommonActionExtensionSite site) { + ICommonViewerWorkbenchSite workbenchSite= null; + if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { + workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); + } + if (workbenchSite != null) { + if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { + fSearchGroup= new SelectionSearchGroup(workbenchSite.getSite()); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + public void dispose() { + if (fSearchGroup != null) { + fSearchGroup.dispose(); + fSearchGroup = null; + } + super.dispose(); + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + if (fSearchGroup != null) { + fSearchGroup.fillActionBars(actionBars); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (fSearchGroup != null) { + ISelection selection = getContext().getSelection(); + if (SelectionSearchGroup.canActionBeAdded(selection)){ + fSearchGroup.fillContextMenu(menu); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext) + */ + public void setContext(ActionContext context) { + super.setContext(context); + if (fSearchGroup != null) { + fSearchGroup.setContext(context); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#updateActionBars() + */ + public void updateActionBars() { + if (fSearchGroup != null) { + fSearchGroup.updateActionBars(); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionGroup.java new file mode 100644 index 00000000000..d36d5431b37 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionGroup.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.WorkingSetFilterActionGroup; + +/** + * A Common Navigator adapted <code>WorkingSetFilterActionGroup</code> adding persistency. + * + * @see org.eclipse.ui.actions.WorkingSetFilterActionGroup + */ +public class CNavigatorWorkingSetActionGroup extends WorkingSetFilterActionGroup { + + private static final String TAG_WORKING_SET_NAME= "workingSetName"; //$NON-NLS-1$ + + /** + * Create a new working set filter action group. + * @param shell + * @param workingSetUpdater + */ + public CNavigatorWorkingSetActionGroup(Shell shell, IPropertyChangeListener workingSetUpdater) { + super(shell, workingSetUpdater); + } + + /** + * Saves the state of the filter actions in a memento. + * + * @param memento the memento + */ + public void saveState(IMemento memento) { + String workingSetName= ""; //$NON-NLS-1$ + IWorkingSet workingSet= getWorkingSet(); + if (workingSet != null) { + workingSetName= workingSet.getName(); + } + memento.putString(TAG_WORKING_SET_NAME, workingSetName); + } + + /** + * Restores the state of the filter actions from a memento. + * <p> + * Note: This method does not refresh the viewer. + * </p> + * @param memento + */ + public void restoreState(IMemento memento) { + String workingSetName= memento.getString(TAG_WORKING_SET_NAME); + IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName); + setWorkingSet(workingSet); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionProvider.java new file mode 100644 index 00000000000..0db7211edbc --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/CNavigatorWorkingSetActionProvider.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.ResourceWorkingSetFilter; +import org.eclipse.ui.actions.ActionContext; +import org.eclipse.ui.actions.WorkingSetFilterActionGroup; +import org.eclipse.ui.navigator.CommonActionProvider; +import org.eclipse.ui.navigator.ICommonActionExtensionSite; +import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite; + +/** + * A Common Navigator action provider adding standard working set filter support. + * + * @see CNavigatorWorkingSetActionGroup + * @see org.eclipse.cdt.internal.ui.workingsets.WorkingSetFilter + */ +public class CNavigatorWorkingSetActionProvider extends CommonActionProvider { + + private CNavigatorWorkingSetActionGroup fWorkingSetGroup; + private ResourceWorkingSetFilter fWorkingSetFilter; + private boolean fContributed; + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + if(fWorkingSetGroup != null && !fContributed) { + // contribute only once to action bars + fContributed= true; + // add an extra separator before the working set filter actions + // TLETODO [CN] add working set filter actions on top of the menu + actionBars.getMenuManager().add(new Separator()); + fWorkingSetGroup.fillActionBars(actionBars); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (fWorkingSetGroup != null) { + fWorkingSetGroup.fillContextMenu(menu); + } + } + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#init(org.eclipse.ui.navigator.ICommonActionExtensionSite) + */ + public void init(ICommonActionExtensionSite site) { + super.init(site); + ICommonViewerWorkbenchSite workbenchSite= null; + if (site.getViewSite() instanceof ICommonViewerWorkbenchSite) { + workbenchSite= (ICommonViewerWorkbenchSite) site.getViewSite(); + } + if (workbenchSite != null) { + if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) { + final StructuredViewer viewer= site.getStructuredViewer(); + fWorkingSetFilter= new ResourceWorkingSetFilter(); + viewer.addFilter(fWorkingSetFilter); + IPropertyChangeListener workingSetUpdater= new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + String property= event.getProperty(); + if (WorkingSetFilterActionGroup.CHANGE_WORKING_SET.equals(property)) { + Object newValue= event.getNewValue(); + if (newValue instanceof IWorkingSet) { + fWorkingSetFilter.setWorkingSet((IWorkingSet) newValue); + viewer.refresh(); + } else if (newValue == null) { + fWorkingSetFilter.setWorkingSet(null); + viewer.refresh(); + } + } + }}; + fWorkingSetGroup= new CNavigatorWorkingSetActionGroup(workbenchSite.getShell(), workingSetUpdater); + } + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#setContext(org.eclipse.ui.actions.ActionContext) + */ + public void setContext(ActionContext context) { + super.setContext(context); + if (fWorkingSetGroup != null) { + fWorkingSetGroup.setContext(context); + } + } + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#restoreState(org.eclipse.ui.IMemento) + */ + public void restoreState(IMemento memento) { + super.restoreState(memento); + if (fWorkingSetGroup != null && memento != null) { + fWorkingSetGroup.restoreState(memento); + } + } + + /* + * @see org.eclipse.ui.navigator.CommonActionProvider#saveState(org.eclipse.ui.IMemento) + */ + public void saveState(IMemento memento) { + super.saveState(memento); + if (fWorkingSetGroup != null && memento != null) { + fWorkingSetGroup.saveState(memento); + } + } + + /* + * @see org.eclipse.ui.actions.ActionGroup#dispose() + */ + public void dispose() { + if (fWorkingSetGroup != null) { + fWorkingSetGroup.dispose(); + fWorkingSetGroup= null; + } + super.dispose(); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java new file mode 100644 index 00000000000..e423e0c6ab5 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/navigator/OpenCElementAction.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.navigator; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ISourceReference; +import org.eclipse.cdt.internal.ui.util.EditorUtility; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.actions.OpenFileAction; + +/** + * Open an editor and navigate to the source location of + * the currently selected <code>ICElement</code>. + * In case of multiple selections, opening is delegated to + * the base class {@link OpenFileAction}. + */ +public class OpenCElementAction extends OpenFileAction { + + private ICElement fOpenElement; + /** + * @param page + */ + public OpenCElementAction(IWorkbenchPage page) { + super(page); + } + + /* + * @see org.eclipse.ui.actions.OpenSystemEditorAction#run() + */ + public void run() { + if (fOpenElement != null) { + IEditorPart part; + try { + part= EditorUtility.openInEditor(fOpenElement); + if (fOpenElement instanceof ISourceReference) { + EditorUtility.revealInEditor(part, (ICElement)fOpenElement); + } + } catch (CoreException exc) { + CUIPlugin.getDefault().log(exc.getStatus()); + } + } else { + super.run(); + } + } + + /* + * @see org.eclipse.ui.actions.OpenSystemEditorAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + protected boolean updateSelection(IStructuredSelection selection) { + fOpenElement = null; + if (selection.size() == 1) { + Object element = selection.getFirstElement(); + if (element instanceof ICElement && element instanceof ISourceReference) { + fOpenElement = (ICElement)element; + } + } + return fOpenElement != null || super.updateSelection(selection); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java index d3c78761b1b..1b2bd69453c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/DeclarationsSearchGroup.java @@ -42,8 +42,6 @@ public class DeclarationsSearchGroup extends ActionGroup { private FindDeclarationsProjectAction fFindDeclarationsProjectAction; private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction; - private ArrayList actions; - public DeclarationsSearchGroup(IWorkbenchSite site) { fFindDeclarationsAction= new FindDeclarationsAction(site); fFindDeclarationsProjectAction = new FindDeclarationsProjectAction(site); @@ -81,9 +79,9 @@ public class DeclarationsSearchGroup extends ActionGroup { if (fEditor != null){ menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, declarationsMenu); + } else { + incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, declarationsMenu); } - - incomingMenu.add(declarationsMenu); incomingMenu = declarationsMenu; FindAction[] actions = getWorkingSetActions(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java index 7ecb069cc65..2286e0af45d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/ReferencesSearchGroup.java @@ -73,13 +73,10 @@ public class ReferencesSearchGroup extends ActionGroup { if (fEditor != null){ menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, refsMenu); + } else { + incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, refsMenu); } - -// /setReferenceMenuEnabled(); - - - incomingMenu.add(refsMenu); incomingMenu = refsMenu; FindAction[] actions = getWorkingSetActions(); |