Skip to content

Commit

Permalink
Show only single editor when open plain BND files
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed Oct 28, 2023
1 parent 86e7922 commit 0aa2d7e
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
Expand All @@ -44,6 +45,7 @@
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.internal.ErrorEditorPart;
import org.eclipse.ui.texteditor.spelling.SpellingAnnotation;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -137,7 +139,17 @@ private void createAndOpenFile(String fileName, String fileContents) throws Cor
Thread.sleep(5000);
} catch (InterruptedException e) {
}

if (fEditor instanceof ErrorEditorPart errorpart) {
IStatus error = errorpart.getError();
if (error == null) {
fail("failed to open editor");
}
Throwable exception = error.getException();
if (exception != null) {
throw new AssertionError("fail to open editor", exception);
}
fail(error.toString());
}
PDEFormEditor editor = (PDEFormEditor) fEditor;
editor.setActivePage(PluginInputContext.CONTEXT_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,23 +776,21 @@ public IFormPage setActivePage(String pageId) {
protected void performGlobalAction(String id) {
// preserve selection
ISelection selection = getSelection();
boolean handled = ((PDEFormPage) getActivePageInstance()).performGlobalAction(id);
if (!handled) {
IFormPage page = getActivePageInstance();
if (page instanceof PDEFormPage) {
if (id.equals(ActionFactory.UNDO.getId())) {
fInputContextManager.undo();
return;
}
if (id.equals(ActionFactory.REDO.getId())) {
fInputContextManager.redo();
return;
}
if (id.equals(ActionFactory.CUT.getId()) || id.equals(ActionFactory.COPY.getId())) {
copyToClipboard(selection);
return;
}
}
IFormPage page = getActivePageInstance();
if (PDEFormPage.performGlobalAction(id, page)) {
return;
}
if (id.equals(ActionFactory.UNDO.getId())) {
fInputContextManager.undo();
return;
}
if (id.equals(ActionFactory.REDO.getId())) {
fInputContextManager.redo();
return;
}
if (id.equals(ActionFactory.CUT.getId()) || id.equals(ActionFactory.COPY.getId())) {
copyToClipboard(selection);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.editor.IFormPage;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
Expand Down Expand Up @@ -156,8 +157,8 @@ public IBaseModel getModel() {
public void contextMenuAboutToShow(IMenuManager menu) {
}

protected Control getFocusControl() {
IManagedForm form = getManagedForm();
protected static Control getFocusControl(IFormPage page) {
IManagedForm form = page.getManagedForm();
if (form == null)
return null;
Control control = form.getForm();
Expand All @@ -170,14 +171,14 @@ protected Control getFocusControl() {
return focusControl;
}

public boolean performGlobalAction(String actionId) {
Control focusControl = getFocusControl();
public static boolean performGlobalAction(String actionId, IFormPage formPage) {
Control focusControl = getFocusControl(formPage);
if (focusControl == null)
return false;

if (canPerformDirectly(actionId, focusControl))
return true;
AbstractFormPart focusPart = getFocusSection();
AbstractFormPart focusPart = getFocusSection(formPage);
if (focusPart != null) {
if (focusPart instanceof PDESection)
return ((PDESection) focusPart).doGlobalAction(actionId);
Expand All @@ -188,7 +189,7 @@ public boolean performGlobalAction(String actionId) {
}

public boolean canPaste(Clipboard clipboard) {
AbstractFormPart focusPart = getFocusSection();
AbstractFormPart focusPart = getFocusSection(this);
if (focusPart != null) {
if (focusPart instanceof PDESection) {
return ((PDESection) focusPart).canPaste(clipboard);
Expand All @@ -201,7 +202,7 @@ public boolean canPaste(Clipboard clipboard) {
}

public boolean canCopy(ISelection selection) {
AbstractFormPart focusPart = getFocusSection();
AbstractFormPart focusPart = getFocusSection(this);
if (focusPart != null) {
if (focusPart instanceof PDESection) {
return ((PDESection) focusPart).canCopy(selection);
Expand All @@ -214,7 +215,7 @@ public boolean canCopy(ISelection selection) {
}

public boolean canCut(ISelection selection) {
AbstractFormPart focusPart = getFocusSection();
AbstractFormPart focusPart = getFocusSection(this);
if (focusPart != null) {
if (focusPart instanceof PDESection) {
return ((PDESection) focusPart).canCut(selection);
Expand All @@ -226,8 +227,8 @@ public boolean canCut(ISelection selection) {
return false;
}

private AbstractFormPart getFocusSection() {
Control focusControl = getFocusControl();
private static AbstractFormPart getFocusSection(IFormPage page) {
Control focusControl = getFocusControl(page);
if (focusControl == null)
return null;
Composite parent = focusControl.getParent();
Expand All @@ -243,7 +244,15 @@ private AbstractFormPart getFocusSection() {
return targetPart;
}

protected boolean canPerformDirectly(String id, Control control) {
protected static boolean canPerformDirectly(String id, IFormPage page) {
Control focusControl = getFocusControl(page);
if (focusControl == null) {
return false;
}
return canPerformDirectly(id, focusControl);
}

protected static boolean canPerformDirectly(String id, Control control) {
if (control instanceof Text text) {
if (id.equals(ActionFactory.CUT.getId())) {
text.cut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public boolean isDirty() {
}

public void monitorFile(IFile file) {
if (file == null) {
return;
}
monitoredFiles.add(file);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -238,33 +236,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));
}
Expand Down Expand Up @@ -400,12 +393,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);
Expand Down Expand Up @@ -526,11 +521,17 @@ protected void createJarEntryContexts(InputContextManager manager, JarEntryEdito
@Override
protected void addEditorPages() {
try {
addPage(new OverviewPage(this));
addPage(new DependenciesPage(this));
addPage(new RuntimePage(this));
int extTabPosition;
if (fInputContextManager.hasContext(BundleInputContext.CONTEXT_ID)) {
addPage(new OverviewPage(this));
addPage(new DependenciesPage(this));
addPage(new RuntimePage(this));
extTabPosition = 3;
} else {
extTabPosition = 0;
}
if (showExtensionTabs()) {
addExtensionTabs();
addExtensionTabs(extTabPosition);
}
if (fInputContextManager.hasContext(BuildInputContext.CONTEXT_ID))
addPage(new BuildPage(this));
Expand Down Expand Up @@ -771,9 +772,9 @@ public boolean isEquinox() {
return fEquinox;
}

protected void addExtensionTabs() throws PartInitException {
addPage(3, new ExtensionPointsPage(this));
addPage(3, new ExtensionsPage(this));
protected void addExtensionTabs(int extTabPosition) throws PartInitException {
addPage(extTabPosition, new ExtensionPointsPage(this));
addPage(extTabPosition, new ExtensionsPage(this));
}

protected void setShowExtensions(boolean show) throws BackingStoreException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private void activateExtensionPages(String activePageId) {
return;
try {
ManifestEditor manifestEditor = (ManifestEditor) getEditor();
manifestEditor.addExtensionTabs();
manifestEditor.addExtensionTabs(3);
manifestEditor.setShowExtensions(true);
manifestEditor.setActivePage(activePageId);
} catch (PartInitException | BackingStoreException e) {
Expand Down

0 comments on commit 0aa2d7e

Please sign in to comment.