Skip to content

Commit

Permalink
find/replace overlay: clean up PreferenceChangeListener
Browse files Browse the repository at this point in the history
The PreferenceChangeListener now starts listening when an Overlay was
created and stops listening once the Overlay is disposed of. Fixes a
previous resource leak.

fixes jdt#1444
  • Loading branch information
Wittmaxi authored and iloveeclipse committed Jun 10, 2024
1 parent 577fcac commit 5179e72
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ public FindReplaceAction(ResourceBundle bundle, String prefix, IWorkbenchPart wo
Assert.isLegal(workbenchPart != null);
fWorkbenchPart= workbenchPart;
update();

hookDialogPreferenceListener();
}

/**
Expand Down Expand Up @@ -331,8 +329,6 @@ public FindReplaceAction(ResourceBundle bundle, String prefix, Shell shell, IFin
fTarget= target;
fShell= shell;
update();

hookDialogPreferenceListener();
}

/**
Expand All @@ -354,15 +350,18 @@ public FindReplaceAction(ResourceBundle bundle, String prefix, IWorkbenchWindow
super(bundle, prefix);
fWorkbenchWindow= workbenchWindow;
update();

hookDialogPreferenceListener();
}

private void hookDialogPreferenceListener() {
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(INSTANCE_SCOPE_NODE_NAME);
preferences.addPreferenceChangeListener(overlayDialogPreferenceListener);
}

private void removeDialogPreferenceListener() {
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(INSTANCE_SCOPE_NODE_NAME);
preferences.removePreferenceChangeListener(overlayDialogPreferenceListener);
}

@Override
public void run() {
if (fTarget == null) {
Expand Down Expand Up @@ -420,12 +419,14 @@ private void showOverlayInEditor() {
shellToUse = fShell;
}
overlay = new FindReplaceOverlay(shellToUse, fWorkbenchPart, fTarget);
hookDialogPreferenceListener();

FindReplaceOverlayFirstTimePopup.displayPopupIfNotAlreadyShown(shellToUse);
}

overlay.setPositionToTop(shouldPositionOverlayOnTop());
overlay.open();
overlay.getShell().addDisposeListener(__ -> removeDialogPreferenceListener());
}

@Override
Expand Down

0 comments on commit 5179e72

Please sign in to comment.