mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Fix NPEs when closing Old Terminal view and avoid opening on top of Welcome
This commit is contained in:
parent
fc2a5462c1
commit
11f2794bd6
1 changed files with 77 additions and 15 deletions
|
@ -11,10 +11,12 @@ package org.eclipse.tm.terminal.view.ui.view;
|
|||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.tm.terminal.view.ui.interfaces.IUIConstants;
|
||||
import org.eclipse.ui.IPartListener2;
|
||||
import org.eclipse.ui.IViewSite;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchPartReference;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +27,9 @@ import org.eclipse.ui.part.ViewPart;
|
|||
*/
|
||||
public class OldTerminalsViewHandler extends ViewPart {
|
||||
|
||||
boolean fReplaced;
|
||||
IPartListener2 fPartlistener;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
@ -37,26 +42,83 @@ public class OldTerminalsViewHandler extends ViewPart {
|
|||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
IWorkbenchPage page = window != null ? window.getActivePage() : null;
|
||||
|
||||
if (page != null) {
|
||||
// Show the new view
|
||||
try {
|
||||
page.showView(IUIConstants.ID);
|
||||
}
|
||||
catch (PartInitException e) { /* ignored on purpose */ }
|
||||
|
||||
// Hide ourself in the current perspective
|
||||
page.hideView(this);
|
||||
}
|
||||
replaceWithTerminalsView();
|
||||
}
|
||||
|
||||
protected void replaceWithTerminalsView() {
|
||||
if (fReplaced)
|
||||
return;
|
||||
IViewSite site = getViewSite();
|
||||
final IWorkbenchPage page = site.getPage();
|
||||
|
||||
site.getShell().getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (fReplaced)
|
||||
return;
|
||||
if (!page.isPageZoomed() || page.getActivePart() instanceof TerminalsView) {
|
||||
fReplaced = true;
|
||||
// Show the new view
|
||||
try {
|
||||
page.showView(IUIConstants.ID, null, IWorkbenchPage.VIEW_CREATE);
|
||||
}
|
||||
catch (PartInitException e) { /* ignored on purpose */ }
|
||||
|
||||
// Hide ourself in the current perspective
|
||||
page.hideView(OldTerminalsViewHandler.this);
|
||||
} else if (fPartlistener == null) {
|
||||
final IWorkbenchPart maximizedPart = page.getActivePart();
|
||||
page.addPartListener(fPartlistener = new IPartListener2() {
|
||||
@Override
|
||||
public void partVisible(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) == OldTerminalsViewHandler.this) {
|
||||
page.removePartListener(this);
|
||||
fPartlistener = null;
|
||||
replaceWithTerminalsView();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void partOpened(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
@Override
|
||||
public void partInputChanged(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
@Override
|
||||
public void partHidden(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
@Override
|
||||
public void partDeactivated(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
@Override
|
||||
public void partClosed(IWorkbenchPartReference partRef) {
|
||||
if (partRef.getPart(false) == OldTerminalsViewHandler.this) {
|
||||
page.removePartListener(this);
|
||||
fPartlistener = null;
|
||||
} else if (partRef.getPart(false) == maximizedPart) {
|
||||
page.removePartListener(this);
|
||||
fPartlistener = null;
|
||||
replaceWithTerminalsView();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void partBroughtToTop(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
@Override
|
||||
public void partActivated(IWorkbenchPartReference partRef) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.part.WorkbenchPart#setFocus()
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
// should not happen, but just in case - replace on focus
|
||||
replaceWithTerminalsView();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue