diff options
author | Mickael Istria | 2021-10-21 19:09:27 +0000 |
---|---|---|
committer | Mickael Istria | 2021-10-26 07:01:25 +0000 |
commit | bfab362c5703231c6fd2677bef1128d7a1b9ed28 (patch) | |
tree | 1e1216ecfa04589b25a131333efdfde591ec8147 | |
parent | 8a4724cc33be1680a641d0d5c422d47b5ad54725 (diff) | |
download | eclipse.platform.ui-bfab362c5703231c6fd2677bef1128d7a1b9ed28.tar.gz eclipse.platform.ui-bfab362c5703231c6fd2677bef1128d7a1b9ed28.tar.xz eclipse.platform.ui-bfab362c5703231c6fd2677bef1128d7a1b9ed28.zip |
Bug 575453 - defaultShowIn improvements
* Rename attribute to something more explicit
* Introduce proper API to retrieve attribute value
* Simplify calling code
* Make ShowIn menu also leverage the setting by showing the default view
as 1st item
Change-Id: Ibeeccebeac6b96d134df9cb86091bcc8c630030f
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.ui/+/186894
Tested-by: Mickael Istria <mistria@redhat.com>
Reviewed-by: Mickael Istria <mistria@redhat.com>
9 files changed, 55 insertions, 50 deletions
diff --git a/bundles/org.eclipse.ui.ide.application/plugin.xml b/bundles/org.eclipse.ui.ide.application/plugin.xml index 65e7f269f96..b15185ae254 100644 --- a/bundles/org.eclipse.ui.ide.application/plugin.xml +++ b/bundles/org.eclipse.ui.ide.application/plugin.xml @@ -43,7 +43,7 @@ name="%Perspective.resourcePerspective" icon="$nl$/icons/full/eview16/resource_persp.png" class="org.eclipse.ui.internal.ide.application.ResourcePerspective" - showInId="org.eclipse.ui.navigator.ProjectExplorer" + defaultShowIn="org.eclipse.ui.navigator.ProjectExplorer" id="org.eclipse.ui.resourcePerspective"> <description> %Perspective.resourceDescription diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java index 8e231104242..65a55183d58 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/views/markers/ExtendedMarkersView.java @@ -1607,21 +1607,15 @@ public class ExtendedMarkersView extends ViewPart { } } - String showInId = ((WorkbenchPage) page).getShowInId(); - if (showIn(marker, page, showInId)) { - return; - } + showIn(marker, page, page.getPerspective().getDefaultShowIn()); } private static boolean showIn(IMarker marker, IWorkbenchPage page, String targetPartId) { + if (targetPartId == null || WorkbenchPlugin.getDefault().getViewRegistry().find(targetPartId) == null) { + return false; + } + ISelection selection = new StructuredSelection(marker.getResource()); try { - if (targetPartId == null) { - return false; - } - if (WorkbenchPlugin.getDefault().getViewRegistry().find(targetPartId) == null) { - return false; - } - ISelection selection = new StructuredSelection(marker.getResource()); IViewPart view = page.showView(targetPartId); if (view == null) { return false; diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IPerspectiveDescriptor.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IPerspectiveDescriptor.java index e304c8f5b55..86d62f670ac 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IPerspectiveDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IPerspectiveDescriptor.java @@ -80,4 +80,17 @@ public interface IPerspectiveDescriptor { * @return the label */ String getLabel(); + + /** + * Returns this perspective's preferred view to show resources when no better + * editor or view can be deduced from context. + * <p> + * For perspectives declared via an extension, this is the value of its + * <code>defaultShowIn</code> attribute. + * </p> + * + * @return the preferred view id, or <code>null</code>. + * @since 3.124 + */ + String getDefaultShowIn(); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java index 1c44a3f91bc..5a5e17df273 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java @@ -57,12 +57,9 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; @@ -2453,39 +2450,18 @@ public class WorkbenchPage implements IWorkbenchPage { * prompt */ public List<String> getShowInPartIds() { - MPerspective perspective = getPerspectiveStack().getSelectedElement(); - return ModeledPageLayout.getIds(perspective, ModeledPageLayout.SHOW_IN_PART_TAG); - } - - /** @return showInId configured by perspective or null if not configured **/ - public String getShowInId() { - String perspectiveId = getPerspective().getId(); - String showInIdFromRegistry = getShowInIdFromRegistry(perspectiveId); - return showInIdFromRegistry; - } - - public static String getShowInIdFromRegistry(String perspectiveId) { - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(PlatformUI.PLUGIN_ID, - IWorkbenchRegistryConstants.PL_PERSPECTIVES); - if (point == null) { - return null; - } - IExtension[] extensions = point.getExtensions(); - if (extensions == null) { - return null; - } - for (IExtension extension : extensions) { - IConfigurationElement[] configElements = extension.getConfigurationElements(); - for (IConfigurationElement configElement : configElements) { - String id = configElement.getAttribute("id"); //$NON-NLS-1$ - if (Objects.equals(perspectiveId, id)) { - String showInId = configElement.getAttribute("showInId"); //$NON-NLS-1$ - return showInId; - } + MPerspective mPerspective = getPerspectiveStack().getSelectedElement(); + List<String> ids = ModeledPageLayout.getIds(mPerspective, ModeledPageLayout.SHOW_IN_PART_TAG); + IPerspectiveDescriptor perspective = getPerspective(); + if (perspective != null && perspective.getDefaultShowIn() != null) { + ids = new ArrayList<>(ids); + if (ids.remove(perspective.getDefaultShowIn())) { + ids.add(0, perspective.getDefaultShowIn()); } } - return null; + return ids; } + /** * The user successfully performed a Show In... action on the specified part. * Update the list of Show In items accordingly. diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java index 00d796af99b..de8a266a528 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/IWorkbenchRegistryConstants.java @@ -1358,4 +1358,11 @@ public interface IWorkbenchRegistryConstants { String ATT_COLOR_AND_FONT_ID = "colorAndFontId"; //$NON-NLS-1$ String ATT_OS_VERSION = "os_version"; //$NON-NLS-1$ + + /** + * See {@link PerspectiveDescriptor#getDefaultShowIn()} + * + * @since 3.123 + */ + String ATT_DEFAULT_SHOW_IN = "defaultShowIn"; //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java index 82f0058617a..030b51f1744 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java @@ -51,6 +51,7 @@ public class PerspectiveDescriptor implements IPerspectiveDescriptor, IPluginCon private String pluginId; private String originalId; // ID of ancestor that was based on a config // element + private String defaultShowIn; public PerspectiveDescriptor(String id, String label, PerspectiveDescriptor originalDescriptor) { this.id = id; @@ -60,6 +61,7 @@ public class PerspectiveDescriptor implements IPerspectiveDescriptor, IPluginCon this.image = originalDescriptor.getImageDescriptor(); this.pluginId = originalDescriptor.getPluginId(); this.hasCustomDefinition = true; + this.defaultShowIn = originalDescriptor.getDefaultShowIn(); } } @@ -180,4 +182,11 @@ public class PerspectiveDescriptor implements IPerspectiveDescriptor, IPluginCon public String toString() { return this.getClass().getName() + " {id=" + getId() + "}"; //$NON-NLS-1$//$NON-NLS-2$ } + + @Override + public String getDefaultShowIn() { + return defaultShowIn == null && configElement != null + ? configElement.getAttribute(IWorkbenchRegistryConstants.ATT_DEFAULT_SHOW_IN) + : defaultShowIn; + } } diff --git a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF index 23c1176c7ef..a4735b4cca1 100644 --- a/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.ui.workbench/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.ui.workbench; singleton:=true -Bundle-Version: 3.123.100.qualifier +Bundle-Version: 3.124.0.qualifier Bundle-ClassPath: . Bundle-Activator: org.eclipse.ui.internal.WorkbenchPlugin Bundle-ActivationPolicy: lazy diff --git a/bundles/org.eclipse.ui.workbench/pom.xml b/bundles/org.eclipse.ui.workbench/pom.xml index 5601737cb6d..631faf68187 100644 --- a/bundles/org.eclipse.ui.workbench/pom.xml +++ b/bundles/org.eclipse.ui.workbench/pom.xml @@ -20,7 +20,7 @@ </parent> <groupId>org.eclipse.ui</groupId> <artifactId>org.eclipse.ui.workbench</artifactId> - <version>3.123.100-SNAPSHOT</version> + <version>3.124.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <properties> diff --git a/bundles/org.eclipse.ui/schema/perspectives.exsd b/bundles/org.eclipse.ui/schema/perspectives.exsd index c369e0b4129..ba712615b46 100644 --- a/bundles/org.eclipse.ui/schema/perspectives.exsd +++ b/bundles/org.eclipse.ui/schema/perspectives.exsd @@ -1,6 +1,6 @@ <?xml version='1.0' encoding='UTF-8'?> <!-- Schema file written by PDE --> -<schema targetNamespace="org.eclipse.ui"> +<schema targetNamespace="org.eclipse.ui" xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> <appInfo> <meta.schema plugin="org.eclipse.ui" id="perspective" name="Perspectives"/> @@ -11,6 +11,11 @@ </annotation> <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> <complexType> <sequence> <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/> @@ -98,10 +103,10 @@ with this perspective. </documentation> </annotation> </attribute> - <attribute name="showInId" type="string"> + <attribute name="defaultShowIn" type="string"> <annotation> <documentation> - the identifier of the view which will be shown by doubleclicking on a (problem) marker without file resource. The view needs to implement ISetSelectionTarget. + the identifier of a preferred view which will be shown when trying to open a resource and no better view or editor can be deduced by the context. This can be for example doubleclicking on a (problem) marker without file resource, or to prioritize this view in the Show In context-menu. The view needs to implement <code>org.eclipse.ui.part.ISetSelectionTarget</code>. </documentation> <appInfo> <meta.attribute kind="identifier" basedOn="org.eclipse.ui.views/view/@id,org.eclipse.ui.views/e4view/@id"/> @@ -122,6 +127,7 @@ with this perspective. </annotation> </element> + <annotation> <appInfo> <meta.section type="examples"/> |