Skip to content

Commit 0d7c003

Browse files
authored
Replace BrowserTextAccessor with InputChangeListener for Javadoc views (eclipse-jdt#2168)
BrowserTextAccessor came with Javadoc styling enhancements and was used to fill SignatureStylingMenuToolbarAction's menu based on the content of the browser showing Javadoc. It is however not working with the Edge SWT browser that is now default on Windows. Fixes eclipse-jdt#2165
1 parent 3965fae commit 0d7c003

File tree

5 files changed

+37
-227
lines changed

5 files changed

+37
-227
lines changed

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/infoviews/JavadocView.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.eclipse.jface.text.Document;
7373
import org.eclipse.jface.text.IDocument;
7474
import org.eclipse.jface.text.IDocumentExtension3;
75+
import org.eclipse.jface.text.IInputChangedListener;
7576
import org.eclipse.jface.text.ITextSelection;
7677
import org.eclipse.jface.text.ITypedRegion;
7778
import org.eclipse.jface.text.Region;
@@ -155,7 +156,6 @@
155156
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
156157
import org.eclipse.jdt.internal.ui.viewsupport.BindingLinkedLabelComposer;
157158
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
158-
import org.eclipse.jdt.internal.ui.viewsupport.browser.BrowserTextAccessor;
159159
import org.eclipse.jdt.internal.ui.viewsupport.javadoc.SignatureStylingMenuToolbarAction;
160160

161161

@@ -428,6 +428,12 @@ protected boolean canEnableFor(IStructuredSelection selection) {
428428
*/
429429
private volatile boolean fIgnoringNewInputOverride;
430430

431+
/**
432+
* The listeners to be notified when the input changed.
433+
* @since 3.35
434+
*/
435+
private ListenerList<IInputChangedListener> fInputChangeListeners= new ListenerList<>(ListenerList.IDENTITY);
436+
431437
/**
432438
* The Javadoc view's select all action.
433439
*/
@@ -681,13 +687,13 @@ protected void fillToolBar(IToolBarManager tbm) {
681687
tbm.add(new Separator());
682688

683689
if (fIsUsingBrowserWidget) {
684-
BrowserTextAccessor browserAccessor= new BrowserTextAccessor(fBrowser);
685690
Runnable viewRefreshTask= () -> {
686691
fIgnoringNewInputOverride= true;
687692
setLinkingEnabled(isLinkingEnabled()); // triggers refresh of the view using last set selection
688693
};
689694
// toolbar widget is being re-created later so we need to do our setup then
690-
var stylingMenuAction= new SignatureStylingMenuToolbarAction(fBrowser.getParent().getShell(), browserAccessor, () -> fOriginalInput, viewRefreshTask) {
695+
var stylingMenuAction= new SignatureStylingMenuToolbarAction(fBrowser.getParent().getShell(),
696+
fInputChangeListeners::add, viewRefreshTask) {
691697
// we take advantage of this method being called after toolbar item creation (in ActionContributionItem.fill()) which happens when whole toolbar is being re-created to be displayed
692698
@Override
693699
public void addPropertyChangeListener(IPropertyChangeListener listener) {
@@ -931,6 +937,9 @@ protected void doSetInput(Object input) {
931937
fText.setText(javadocHtml);
932938
TextPresentation.applyTextPresentation(fPresentation, fText);
933939
}
940+
for (IInputChangedListener listener : fInputChangeListeners) {
941+
listener.inputChanged(javadocHtml);
942+
}
934943
}
935944

936945
/**

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/hover/JavadocHover.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
import org.eclipse.jdt.internal.ui.text.javadoc.JavadocContentAccess2;
134134
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLabelComposer;
135135
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
136-
import org.eclipse.jdt.internal.ui.viewsupport.browser.BrowserTextAccessor;
137136
import org.eclipse.jdt.internal.ui.viewsupport.javadoc.SignatureStylingMenuToolbarAction;
138137

139138

@@ -378,10 +377,8 @@ public IInformationControl doCreateInformationControl(Shell parent) {
378377
};
379378
ToolBarManager tbmSecondary= new ToolBarManager(SWT.FLAT);
380379
tbmSecondary.createControl(toolbarComposite).setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, false));
381-
BrowserTextAccessor browserAccessor= new BrowserTextAccessor(iControl);
382-
var stylingMenuAction= new SignatureStylingMenuToolbarAction(iControl.getShell(), browserAccessor,
383-
() -> iControl.getInput() == null ? null : iControl.getInput().getHtml(),
384-
viewRefreshTask);
380+
var stylingMenuAction= new SignatureStylingMenuToolbarAction(iControl.getShell(),
381+
iControl::addInputChangeListener, viewRefreshTask);
385382
tbmSecondary.add(stylingMenuAction);
386383
tbmSecondary.update(true);
387384
stylingMenuAction.setup(tbmSecondary.getControl());

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/ArmListeningMenuItemsConfigurer.java

Lines changed: 0 additions & 123 deletions
This file was deleted.

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/browser/BrowserTextAccessor.java

Lines changed: 0 additions & 84 deletions
This file was deleted.

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/viewsupport/javadoc/SignatureStylingMenuToolbarAction.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package org.eclipse.jdt.internal.ui.viewsupport.javadoc;
1515

1616
import java.util.Objects;
17-
import java.util.function.Supplier;
1817
import java.util.stream.Stream;
1918

2019
import org.eclipse.swt.widgets.Control;
@@ -27,17 +26,18 @@
2726
import org.eclipse.jface.action.ActionContributionItem;
2827
import org.eclipse.jface.action.IAction;
2928
import org.eclipse.jface.action.IMenuCreator;
29+
import org.eclipse.jface.internal.text.html.BrowserInformationControlInput;
30+
31+
import org.eclipse.jface.text.IInputChangedListener;
3032

3133
import org.eclipse.jdt.internal.ui.JavaPluginImages;
3234
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks;
3335
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.IStylingConfigurationListener;
34-
import org.eclipse.jdt.internal.ui.viewsupport.browser.BrowserTextAccessor;
35-
import org.eclipse.jdt.internal.ui.viewsupport.browser.BrowserTextAccessor.IBrowserContentChangeListener;
3636

3737
/**
3838
* Toolbar item action for building &amp; presenting javadoc styling menu.
3939
*/
40-
public class SignatureStylingMenuToolbarAction extends Action implements IMenuCreator, IBrowserContentChangeListener, IStylingConfigurationListener {
40+
public class SignatureStylingMenuToolbarAction extends Action implements IMenuCreator, IInputChangedListener, IStylingConfigurationListener {
4141
private final Action[] noStylingActions= { new NoStylingEnhancementsAction() };
4242
private final Action[] enabledActions;
4343
private final Shell parent;
@@ -46,36 +46,43 @@ public class SignatureStylingMenuToolbarAction extends Action implements IMenuCr
4646
private Action[] actions;
4747
protected Menu menu= null;
4848
private boolean enhancementsEnabled= JavaElementLinks.getStylingEnabledPreference();
49+
private String javadocContent;
4950

50-
public SignatureStylingMenuToolbarAction(Shell parent, BrowserTextAccessor browserAccessor, Supplier<String> javadocContentSupplier, Runnable enhancementsReconfiguredTask) {
51+
public SignatureStylingMenuToolbarAction(Shell parent, JavadocContentInputAccessor contentInputAccessor, Runnable enhancementsReconfiguredTask) {
5152
super(JavadocStylingMessages.JavadocStyling_enabledTooltip, IAction.AS_DROP_DOWN_MENU);
5253
Objects.requireNonNull(parent);
54+
Objects.requireNonNull(contentInputAccessor);
5355
setImageDescriptor(JavaPluginImages.DESC_ETOOL_JDOC_HOVER_EDIT);
5456
// SignatureStylingColorSubMenuItem requires top level shell to display native color picker
55-
// JavadocView passes to level shell but JavadocHover passes hover's shell
57+
// JavadocView passes top level shell but JavadocHover passes hover's shell
5658
// (Display.getActiveShell() would not work since JavadocView is created when active shell is startup splash screen shell)
5759
Shell topLevelShell = (parent.getParent() instanceof Shell parentShell) ? parentShell : parent;
5860
enabledActions= new Action[] {
5961
new ToggleSignatureTypeParametersColoringAction(),
60-
new SignatureStylingColorSubMenuItem(topLevelShell, javadocContentSupplier)};
62+
new SignatureStylingColorSubMenuItem(topLevelShell, () -> this.javadocContent)};
6163
actions= noStylingActions;
6264
setMenuCreator(this);
6365
this.parent= parent;
6466
this.enhancementsReconfiguredTask= enhancementsReconfiguredTask;
6567
presentEnhancementsState();
6668
setHoverImageDescriptor(null);
6769
setId(SignatureStylingMenuToolbarAction.class.getSimpleName());
68-
browserAccessor.addContentChangedListener(this); // remove not necessary since lifecycle of this action is the same as that of the browser widget
70+
contentInputAccessor.addInputChangedListener(this);
6971
JavaElementLinks.addStylingConfigurationListener(this);
7072
}
7173

7274
@Override
73-
public void browserContentChanged(Supplier<String> contentAccessor) {
75+
public void inputChanged(Object newInput) {
76+
javadocContent = null;
7477
if (!enhancementsEnabled) {
7578
return;
7679
}
77-
var content= contentAccessor.get();
78-
if (content != null && !content.isBlank() && JavaElementLinks.isStylingPresent(content)) {
80+
if (newInput instanceof String str) {
81+
javadocContent = str;
82+
} else if (newInput instanceof BrowserInformationControlInput bicInput) {
83+
javadocContent = bicInput.getHtml();
84+
}
85+
if (javadocContent != null && !javadocContent.isBlank() && JavaElementLinks.isStylingPresent(javadocContent)) {
7986
actions= enabledActions;
8087
} else {
8188
actions= noStylingActions;
@@ -127,7 +134,7 @@ public void stylingStateChanged(boolean isEnabled) {
127134
parent.getDisplay().execute(() -> {
128135
enhancementsEnabled= isEnabled;
129136
presentEnhancementsState();
130-
// even if enhancements switched from off to on, only browserContentChanged() sets enabledActions
137+
// even if enhancements switched from off to on, only inputChanged() sets enabledActions
131138
actions= noStylingActions;
132139
runEnhancementsReconfiguredTask();
133140
});
@@ -171,4 +178,8 @@ public void run() {
171178
}
172179

173180
}
181+
182+
public interface JavadocContentInputAccessor {
183+
void addInputChangedListener(IInputChangedListener changeListener);
184+
}
174185
}

0 commit comments

Comments
 (0)