From 078112b3a5c790f421a026c99f56137e2d7a0e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Wed, 25 Oct 2023 20:34:07 +0200 Subject: [PATCH] Show only single editor when open plain BND files Currently the manifest editor shows an error when one opens a plain bnd file. This is because no "manifest first" parts are found and the bnd form page is only added for pde.bnd files. This now fixes the issue by making manifest-first files completely optional and show a plain bnd editor instead in case of only a bnd file. --- .../editor/context/InputContextManager.java | 3 ++ .../ui/editor/plugin/ManifestEditor.java | 51 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java index 2f1b8ad965d..69fe66d4149 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java @@ -201,6 +201,9 @@ public boolean isDirty() { } public void monitorFile(IFile file) { + if (file == null) { + return; + } monitoredFiles.add(file); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java index 17da51af37e..7bc4b4f81f8 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestEditor.java @@ -33,12 +33,10 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.osgi.service.resolver.BaseDescription; import org.eclipse.osgi.service.resolver.BundleDescription; -import org.eclipse.osgi.util.NLS; import org.eclipse.pde.core.IBaseModel; import org.eclipse.pde.core.IIdentifiable; import org.eclipse.pde.core.build.IBuild; @@ -239,33 +237,28 @@ protected void createResourceContexts(InputContextManager manager, IFileEditorIn manifestFile = container.getFile(ICoreConstants.MANIFEST_PATH); } else if (name.endsWith(BndProject.INSTRUCTIONS_FILE_EXTENSION)) { IProject project = file.getProject(); - manifestFile = PDEProject.getManifest(project); - buildFile = PDEProject.getBuildProperties(project); - pluginFile = PDEProject.getPluginXml(project); if (name.equalsIgnoreCase(BndProject.INSTRUCTIONS_FILE)) { - IEditorInput in = new FileEditorInput(file); - BndInputContext bndInputContext = new BndInputContext(this, in, true); - manager.putContext(in, bndInputContext); - manager.monitorFile(file); - manager.addInputContextListener(bndInputContext); + manifestFile = PDEProject.getManifest(project); + buildFile = PDEProject.getBuildProperties(project); + pluginFile = PDEProject.getPluginXml(project); } + IEditorInput in = new FileEditorInput(file); + BndInputContext bndInputContext = new BndInputContext(this, in, true); + manager.putContext(in, bndInputContext); + manager.monitorFile(file); + manager.addInputContextListener(bndInputContext); } - if (manifestFile == null) { - MessageDialog.openError(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.OpenPluginManifestsAction_title, - NLS.bind(PDEUIMessages.OpenManifestsAction_cannotOpenThisFile, name)); - return; - } - if (manifestFile.exists()) { + if (manifestFile != null && manifestFile.exists()) { IEditorInput in = new FileEditorInput(manifestFile); manager.putContext(in, new BundleInputContext(this, in, file == manifestFile)); } manager.monitorFile(manifestFile); - if (pluginFile.exists()) { + if (pluginFile != null && pluginFile.exists()) { FileEditorInput in = new FileEditorInput(pluginFile); manager.putContext(in, new PluginInputContext(this, in, file == pluginFile, fragment)); } manager.monitorFile(pluginFile); - if (buildFile.exists()) { + if (buildFile != null && buildFile.exists()) { FileEditorInput in = new FileEditorInput(buildFile); manager.putContext(in, new BuildInputContext(this, in, false)); } @@ -401,12 +394,14 @@ public void contextRemoved(InputContext context) { private void updateFirstThreePages() { try { int index = getActivePage(); - removePage(0); - removePage(0); - removePage(0); - addPage(0, new RuntimePage(this)); - addPage(0, new DependenciesPage(this)); - addPage(0, new OverviewPage(this)); + removePage(RuntimePage.PAGE_ID); + removePage(DependenciesPage.PAGE_ID); + removePage(OverviewPage.PAGE_ID); + if (fInputContextManager.hasContext(BundleInputContext.CONTEXT_ID)) { + addPage(0, new RuntimePage(this)); + addPage(0, new DependenciesPage(this)); + addPage(0, new OverviewPage(this)); + } setActivePage(index); } catch (PartInitException e) { PDEPlugin.logException(e); @@ -527,9 +522,11 @@ protected void createJarEntryContexts(InputContextManager manager, JarEntryEdito @Override protected void addEditorPages() { try { - addPage(new OverviewPage(this)); - addPage(new DependenciesPage(this)); - addPage(new RuntimePage(this)); + if (fInputContextManager.hasContext(BundleInputContext.CONTEXT_ID)) { + addPage(new OverviewPage(this)); + addPage(new DependenciesPage(this)); + addPage(new RuntimePage(this)); + } if (showExtensionTabs()) { addExtensionTabs(); }