Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find/replace overlay: clean up PreferenceChangeListener #1948

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to move overlayDialogPreferenceListener to the FindReplaceOverlay itself? There one could simply add listener in constructor and remove on close().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had moved this listener out of the FindReplaceOverlay as a response to @HeikoKlare's comment: #1192 (comment)

I believe that he is right and believe that it is indeed best if the Overlay is independent from the "global parametrization".

}

@Override
Expand Down
Loading