Index: Eclipse UI/org/eclipse/ui/IWorkbenchPartSite.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/IWorkbenchPartSite.java,v retrieving revision 1.20 diff -u -r1.20 IWorkbenchPartSite.java --- Eclipse UI/org/eclipse/ui/IWorkbenchPartSite.java 25 Feb 2005 20:52:16 -0000 1.20 +++ Eclipse UI/org/eclipse/ui/IWorkbenchPartSite.java 9 Aug 2005 12:54:03 -0000 @@ -124,5 +124,15 @@ * * @return the part associated with this site */ - public IWorkbenchPart getPart(); + public IWorkbenchPart getPart(); + + /** + * Returns the part reference associated with this site. It can + * return null. + * + * @since 3.1.1 + * + * @return the part reference, or null if there's none available. + */ + public IWorkbenchPartReference getPartReference(); } Index: Eclipse UI/org/eclipse/ui/internal/EditorManager.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorManager.java,v retrieving revision 1.87 diff -u -r1.87 EditorManager.java --- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 16 May 2005 21:16:50 -0000 1.87 +++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 9 Aug 2005 12:54:04 -0000 @@ -713,12 +713,17 @@ return null; } - /* - * Create the site and action bars for each inner editor. - */ - private IEditorReference[] openMultiEditor(final IEditorReference ref, - final MultiEditor part, final EditorDescriptor desc, - final MultiEditorInput input, final boolean setVisible) + /** + * Create the part and reference for each inner editor. + * + * @param ref the MultiEditor ref + * @param part the part + * @param input the MultiEditor input + * @return the array of inner references to store in the MultiEditor ref + */ + IEditorReference[] openMultiEditor(final IEditorReference ref, + final MultiEditor part, + final MultiEditorInput input) throws PartInitException { String[] editorArray = input.getEditors(); Index: Eclipse UI/org/eclipse/ui/internal/EditorReference.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorReference.java,v retrieving revision 1.5 diff -u -r1.5 EditorReference.java --- Eclipse UI/org/eclipse/ui/internal/EditorReference.java 16 May 2005 21:16:50 -0000 1.5 +++ Eclipse UI/org/eclipse/ui/internal/EditorReference.java 9 Aug 2005 12:54:04 -0000 @@ -44,6 +44,8 @@ import org.eclipse.ui.internal.registry.EditorDescriptor; import org.eclipse.ui.internal.util.Util; import org.eclipse.ui.part.IWorkbenchPartOrientation; +import org.eclipse.ui.part.MultiEditor; +import org.eclipse.ui.part.MultiEditorInput; import org.eclipse.ui.presentations.IPresentablePart; public class EditorReference extends WorkbenchPartReference implements @@ -80,6 +82,13 @@ IEditorInput restoredInput; + /** + * If the reference is instantiated as a MultiEditor, we need to dispose the + * inner references correctly. + */ + private IEditorReference[] multiEditorChildren = null; + + public EditorReference(EditorManager manager, IEditorInput input, EditorDescriptor desc) { this.manager = manager; initListenersAndHandlers(); @@ -241,7 +250,17 @@ } protected void doDisposePart() { - if (part != null) { + if (multiEditorChildren!=null) { + for (int i=0; inull. + */ public IEditorReference getActiveEditorReference() { - return activeEditorReference; + return (IEditorReference) getCorrectReference(activeEditorReference); } public IEditorPart getActiveEditor() { - return activeEditorReference == null ? null :activeEditorReference.getEditor(false); + return (IEditorPart)getPart(activeEditorReference); } public IWorkbenchPart getActivePart() { - return activePartReference == null ? null : activePartReference.getPart(false); + return getPart(activePartReference); } public void addPart(WorkbenchPartReference ref) { @@ -89,9 +110,9 @@ * @param ref */ public void setActivePart(IWorkbenchPartReference ref) { - if (ref == activePartReference) { - return; - } + if (ref == activePartReference && !isMultiReference(ref)) { + return; + } IWorkbenchPartReference oldPart = activePartReference; @@ -109,9 +130,9 @@ } public void setActiveEditor(IEditorReference ref) { - if (ref == activeEditorReference) { - return; - } + if (ref == activePartReference && !isMultiReference(ref)) { + return; + } // A part can't be activated until it is added //Assert.isTrue(ref == null || parts.contains(ref)); @@ -226,6 +247,40 @@ } /** + * Return the part for this reference. A convenience method + * that handles null cases. + * + * Try and deal with the MultiEditor ... which has implications for + * which "part" the partListeners should be notified about. + * + * @param ref The reference that might contain a MultiEditor. This + * can be null. + * @return the workbench part, the inner part if it's a MultiEditor, + * or null if the reference was null or + * the part hadn't been activated yet. + */ + protected IWorkbenchPart getPart(IWorkbenchPartReference ref) { + if (ref==null) { + return null; + } + IWorkbenchPart part = ref.getPart(false); + if (part != null && part instanceof MultiEditor) { + part = ((MultiEditor) part).getActiveEditor(); + } + return part; + } + + /** + * Check a reference to see if it's a ref to a MultiEditor. + * @param ref the reference to check. It can be null. + * @return true if the reference is to a MultiEditor. + */ + protected boolean isMultiReference(IWorkbenchPartReference ref) { + return ref instanceof EditorReference + && ((EditorReference) ref).isMultiReference(); + } + + /** * Fire the event indicating that a part reference was just realized. That is, the concrete * IWorkbenchPart has been attached to the part reference. * Index: Eclipse UI/org/eclipse/ui/internal/PartService.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/PartService.java,v retrieving revision 1.2 diff -u -r1.2 PartService.java --- Eclipse UI/org/eclipse/ui/internal/PartService.java 16 May 2005 16:30:34 -0000 1.2 +++ Eclipse UI/org/eclipse/ui/internal/PartService.java 9 Aug 2005 12:54:04 -0000 @@ -16,6 +16,7 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.internal.misc.UIListenerLogging; +import org.eclipse.ui.part.MultiEditor; public class PartService implements IPartService { private PartListenerList listeners = new PartListenerList(); @@ -67,7 +68,7 @@ * @param ref */ private void firePartActivated(IWorkbenchPartReference ref) { - IWorkbenchPart part = ref.getPart(false); + IWorkbenchPart part = getPart(ref); if(part != null) { UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_ACTIVATED); listeners.firePartActivated(part); @@ -81,7 +82,7 @@ * @param ref */ public void firePartBroughtToTop(IWorkbenchPartReference ref) { - IWorkbenchPart part = ref.getPart(false); + IWorkbenchPart part = getPart(ref); if(part != null) { UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_BROUGHT_TO_TOP); listeners.firePartBroughtToTop(part); @@ -94,7 +95,7 @@ * @param ref */ public void firePartClosed(IWorkbenchPartReference ref) { - IWorkbenchPart part = ref.getPart(false); + IWorkbenchPart part = getPart(ref); if(part != null) { UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_CLOSED); listeners.firePartClosed(part); @@ -107,7 +108,7 @@ * @param ref */ private void firePartDeactivated(IWorkbenchPartReference ref) { - IWorkbenchPart part = ref.getPart(false); + IWorkbenchPart part = getPart(ref); if(part != null) { UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_DEACTIVATED); listeners.firePartDeactivated(part); @@ -135,7 +136,7 @@ * @param ref */ public void firePartOpened(IWorkbenchPartReference ref) { - IWorkbenchPart part = ref.getPart(false); + IWorkbenchPart part = getPart(ref); if(part != null) { UIListenerLogging.logPartListenerEvent(debugListenersKey, this, part, UIListenerLogging.PE_PART_OPENED); listeners.firePartOpened(part); @@ -157,7 +158,7 @@ IWorkbenchPartReference oldRef = activePart; // Filter out redundant activation events - if (oldRef == ref) { + if (oldRef == ref && !isMultiReference(ref)) { return; } @@ -172,4 +173,37 @@ } } + /** + * Return the part for this reference. A convenience method + * that handles null cases. + * + * Try and deal with the MultiEditor ... which has implications for + * which "part" the partListeners should be notified about. + * + * @param ref The reference that might contain a MultiEditor. This + * can be null. + * @return the workbench part, the inner part if it's a MultiEditor, + * or null if the reference was null or + * the part hadn't been activated yet. + */ + private IWorkbenchPart getPart(IWorkbenchPartReference ref) { + if (ref==null) { + return null; + } + IWorkbenchPart part = ref.getPart(false); + if (part != null && part instanceof MultiEditor) { + part = ((MultiEditor) part).getActiveEditor(); + } + return part; + } + + /** + * Check a reference to see if it's a ref to a MultiEditor. + * @param ref the reference to check. It can be null. + * @return true if the reference is to a MultiEditor. + */ + private boolean isMultiReference(IWorkbenchPartReference ref) { + return ref instanceof EditorReference + && ((EditorReference) ref).isMultiReference(); + } } Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java,v retrieving revision 1.223 diff -u -r1.223 WorkbenchPage.java --- Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 22 Jun 2005 20:40:06 -0000 1.223 +++ Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java 9 Aug 2005 12:54:04 -0000 @@ -559,7 +559,7 @@ Platform.run(new SafeRunnable(WorkbenchMessages.WorkbenchPage_ErrorActivatingView) { public void run() { if (part != null) { - //part.setFocus(); + part.setFocus(); PartPane pane = getPane(part); pane.setFocus(); PartSite site = (PartSite) part.getSite(); @@ -1101,14 +1101,14 @@ * @param ref the editor to make active, or null for no active editor */ private void makeActiveEditor(IEditorReference ref) { - if (ref == getActiveEditor()) { - return; - } + if (ref == getActiveEditorReference() && !isMultiReference(ref)) { + return; + } - IEditorPart part = (ref == null) ? null : ref.getEditor(true); + IEditorPart part = (IEditorPart)getPart(ref, true); if (part != null) { - editorMgr.setVisibleEditor(ref, false); + editorMgr.setVisibleEditor(ref, true); navigationHistory.markEditor(part); } @@ -1473,6 +1473,7 @@ if (isZoomed()) zoomOut(); + makeActiveEditor(null); makeActive(null); // Close and dispose the editors. @@ -2171,6 +2172,7 @@ * This method is called when the page is deactivated. */ protected void onDeactivate() { + makeActiveEditor(null); makeActive(null); if (getActivePerspective() != null) getActivePerspective().onDeactivate(); @@ -2467,6 +2469,10 @@ if (!certifyPart(part)) return; + if (part!=null && part instanceof MultiEditor) { + part = ((MultiEditor)part).getActiveEditor(); + } + // Real work. setActivePart(part); } @@ -2810,11 +2816,14 @@ private void setActivePart(IWorkbenchPart newPart) { // Optimize it. if (getActivePart() == newPart) { - return; + IWorkbenchPartReference partref = getReference(newPart); + if (!isMultiReference(partref)) { + return; + } } if (partBeingActivated != null) { - if (partBeingActivated.getPart(false) != newPart) { + if (getPart(partBeingActivated, false) != newPart) { WorkbenchPlugin.log(new RuntimeException(NLS.bind( "WARNING: Prevented recursive attempt to activate part {0} while still in the middle of activating part {1}", //$NON-NLS-1$ getId(newPart), getId(partBeingActivated)))); @@ -2848,8 +2857,7 @@ if (newPart != null) { activationList.setActive(newPart); if (newPart instanceof IEditorPart) { - IEditorReference ref = (IEditorReference) getReference(newPart); - makeActiveEditor(ref); + makeActiveEditor((IEditorReference)partref); } } activatePart(newPart); @@ -3471,27 +3479,20 @@ */ void setActive(IWorkbenchPart part) { if (parts.size() <= 0) - return; - PartPane pane = ((PartSite) part.getSite()).getPane(); - if (pane instanceof MultiEditorInnerPane) { - MultiEditorInnerPane innerPane = (MultiEditorInnerPane) pane; - setActive(innerPane.getParentPane().getPartReference().getPart( - true)); - } else { - IWorkbenchPartReference ref = getReference(part); - if (ref != null) { - if (ref == parts.get(parts.size() - 1)) - return; - parts.remove(ref); - parts.add(ref); - } - } + return; + IWorkbenchPartReference ref = getReference(part); + if (ref != null) { + if (ref == parts.get(parts.size() - 1)) + return; + parts.remove(ref); + parts.add(ref); + } } /* - * Ensures that the given part appears AFTER any other part in the same - * container. - */ + * Ensures that the given part appears AFTER any other part in the same + * container. + */ void bringToTop(IWorkbenchPartReference ref) { ILayoutContainer targetContainer = getContainer(ref); @@ -4286,4 +4287,40 @@ return isPartVisible(part); } + + /** + * Return the part for this reference. A convenience method + * that handles null cases. + * + * Try and deal with the MultiEditor ... which has implications for + * which "part" the partListeners should be notified about. + * + * @param ref The reference that might contain a MultiEditor. This + * can be null. + * @param restore true to restore the part + * @return the workbench part, the inner part if it's a MultiEditor, + * or null if the reference was null or + * restore was false and the part hadn't been activated yet. + */ + protected IWorkbenchPart getPart(IWorkbenchPartReference ref, + boolean restore) { + if (ref==null) { + return null; + } + IWorkbenchPart part = ref.getPart(restore); + if (part != null && part instanceof MultiEditor) { + part = ((MultiEditor) part).getActiveEditor(); + } + return part; + } + + /** + * Check a reference to see if it's a ref to a MultiEditor. + * @param ref the reference to check. It can be null. + * @return true if the reference is to a MultiEditor. + */ + protected boolean isMultiReference(IWorkbenchPartReference ref) { + return ref instanceof EditorReference + && ((EditorReference) ref).isMultiReference(); + } } Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchPagePartList.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPagePartList.java,v retrieving revision 1.3 diff -u -r1.3 WorkbenchPagePartList.java --- Eclipse UI/org/eclipse/ui/internal/WorkbenchPagePartList.java 16 May 2005 16:26:55 -0000 1.3 +++ Eclipse UI/org/eclipse/ui/internal/WorkbenchPagePartList.java 9 Aug 2005 12:54:04 -0000 @@ -55,7 +55,7 @@ protected void fireActivePartChanged(IWorkbenchPartReference oldRef, IWorkbenchPartReference newRef) { partService.setActivePart(newRef); - IWorkbenchPart realPart = newRef == null? null : newRef.getPart(false); + IWorkbenchPart realPart = getPart(newRef); selectionService.setActivePart(realPart); } Index: Eclipse UI/org/eclipse/ui/internal/part/CompatibilityPartSite.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/part/CompatibilityPartSite.java,v retrieving revision 1.5 diff -u -r1.5 CompatibilityPartSite.java --- Eclipse UI/org/eclipse/ui/internal/part/CompatibilityPartSite.java 2 May 2005 18:24:22 -0000 1.5 +++ Eclipse UI/org/eclipse/ui/internal/part/CompatibilityPartSite.java 9 Aug 2005 12:54:04 -0000 @@ -24,6 +24,7 @@ import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.internal.PartSite; @@ -213,4 +214,13 @@ registerContextMenu(getId(), menuManager, selectionProvider, includeEditorInput); } + + /* + * This method doesn't quite make sense in the context of + * compatibility part sites, so it returns null. + */ + public IWorkbenchPartReference getPartReference() { + // TODO Validated that compatibility editors don't have references. + return null; + } } Index: Eclipse UI/org/eclipse/ui/part/MultiEditor.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiEditor.java,v retrieving revision 1.15 diff -u -r1.15 MultiEditor.java --- Eclipse UI/org/eclipse/ui/part/MultiEditor.java 25 Feb 2005 20:52:16 -0000 1.15 +++ Eclipse UI/org/eclipse/ui/part/MultiEditor.java 9 Aug 2005 12:54:04 -0000 @@ -77,21 +77,6 @@ return content; } - /** - * The MultiEditor implementation of this - * method extends the EditorPart implementation, - * and disposes any inner editors. Subclasses may extend. - * - * @since 3.0 - */ - public void dispose() { - super.dispose(); - IEditorPart[] editors = getInnerEditors(); - for (int i = 0; i < editors.length; i++) { - editors[i].dispose(); - } - } - /* * @see IEditorPart#doSaveAs() */ Index: Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java,v retrieving revision 1.16.2.1 diff -u -r1.16.2.1 MultiPageEditorSite.java --- Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java 2 Aug 2005 20:26:09 -0000 1.16.2.1 +++ Eclipse UI/org/eclipse/ui/part/MultiPageEditorSite.java 9 Aug 2005 12:54:04 -0000 @@ -28,6 +28,7 @@ import org.eclipse.ui.INestableKeyBindingService; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.internal.PartSite; import org.eclipse.ui.internal.PopupMenuExtender; @@ -409,4 +410,13 @@ registerContextMenu(getId(), menuManager, selectionProvider, includeEditorInput); } + + /* + * This method doesn't quite make sense in the context of + * MultiPageEditorPart, so it returns null + */ + public IWorkbenchPartReference getPartReference() { + // TODO Validated that inner editors don't have references. + return null; + } }