From 08f710c4148ace359ffdc284bf9b8f15e7357fbb Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Tue, 24 Feb 2015 11:31:08 +0100 Subject: [PATCH] Bug 460655 - [terminal] Reparenting a terminal widget leaks resources When moving a terminal widget under a new SWT parent we have to take special care not to leak resources. Change-Id: I9b397b77c8473df55e6330e2c43d04cb668772ee Signed-off-by: Anton Leherbauer --- .../emulator/VT100TerminalControl.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/terminal/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/terminal/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 96987ef163a..28bf1505a05 100644 --- a/terminal/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -633,16 +633,33 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC */ public void setupTerminal(Composite parent) { Assert.isNotNull(parent); - fState=TerminalState.CLOSED; + boolean wasDisposed = true; + TerminalState oldState = fState; + fState = TerminalState.CLOSED; + if (fClipboard != null && !fClipboard.isDisposed()) { + // terminal was not disposed (DnD) + wasDisposed = false; + fClipboard.dispose(); + fPollingTextCanvasModel.stopPolling(); + } + if (fWndParent != null && !fWndParent.isDisposed()) { + // terminal widget gets a new parent (DnD) + fWndParent.dispose(); + } setupControls(parent); + setCommandInputField(fCommandInputField); setupListeners(); - if (fUseCommonPrefs) { + if (fUseCommonPrefs && wasDisposed) { updatePreferences(); onTerminalFontChanged(); TerminalPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPreferenceListener); JFaceResources.getFontRegistry().addListener(fFontListener); } setupHelp(fWndParent, TerminalPlugin.HELP_VIEW); + + if (!wasDisposed) { + fState = oldState; + } } /* @@ -699,13 +716,6 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC return fWndParent; } protected void setupControls(Composite parent) { - // The Terminal view now aims to be an ANSI-conforming terminal emulator, so it - // can't have a horizontal scroll bar (but a vertical one is ok). Also, do - // _not_ make the TextViewer read-only, because that prevents it from seeing a - // TAB character when the user presses TAB (instead, the TAB causes focus to - // switch to another Workbench control). We prevent local keyboard input from - // modifying the text in method TerminalVerifyKeyListener.verifyKey(). - fWndParent=new Composite(parent,SWT.NONE); GridLayout layout=new GridLayout(); layout.marginWidth=0; layout.marginHeight=0; layout.verticalSpacing=0; @@ -734,8 +744,6 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC fDisplay = getCtlText().getDisplay(); fClipboard = new Clipboard(fDisplay); -// fViewer.setDocument(new TerminalDocument()); -// setFont(JFaceResources.getTextFont()); } protected void setupListeners() {