Skip to content

Commit

Permalink
Fix styling enhancements menu not always reflecting Javadoc content
Browse files Browse the repository at this point in the history
- incorrect text was searched for inside HTML content to see if
enhancements are present
- menu actions for enhancements enabled state were not set / left only
when enhancements were present in content

Fixes eclipse-jdt#1442
  • Loading branch information
RedeemerSK committed Jun 29, 2024
1 parent 1253df6 commit 7d476d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ protected void appendTypeParameterSignaturesLabel(String[] typeParamSigs, long f
if (i > 0) {
fBuffer.append(JavaElementLabelsCore.COMMA_STRING);
}
appendTypeParameteSignatureLabel(Signature.getTypeVariable(typeParamSigs[i]));
appendTypeParameterSignatureLabel(Signature.getTypeVariable(typeParamSigs[i]));
}
appendGT();
}
Expand All @@ -915,7 +915,7 @@ protected void appendTypeParameterSignaturesLabel(String[] typeParamSigs, long f
*
* @param typeVariableName the type variable name
*/
protected void appendTypeParameteSignatureLabel(String typeVariableName) {
protected void appendTypeParameterSignatureLabel(String typeVariableName) {
fBuffer.append(typeVariableName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
*/
public class JavaElementLinks {

/**
* ID of the checkbox in generated HTML content that toggles formatting inside element labels.
*/
public static final String CHECKBOX_ID_FORMATTIG= "formattingSwitch"; //$NON-NLS-1$
private static final String CHECKBOX_FORMATTING_ID = "formattingSwitch"; //$NON-NLS-1$
// browser on windows changes single quotes to double quotes (other platforms don't do that) thus we use / primarily search for this one
private static final String CHECKBOX_FORMATTING_ID_ATTR_DQUOTES= "id=\"" + CHECKBOX_FORMATTING_ID + "\""; //$NON-NLS-1$ //$NON-NLS-2$
private static final String CHECKBOX_FORMATTING_ID_ATTR_SQUOTES= "id='" + CHECKBOX_FORMATTING_ID + "'"; //$NON-NLS-1$ //$NON-NLS-2$

private static final String PREFERENCE_KEY_POSTFIX_TYPE_PARAMETERS_REFERENCES_COLORING= "javadocElementsStyling.typeParamsReferencesColoring"; //$NON-NLS-1$

Expand Down Expand Up @@ -339,7 +339,7 @@ public void appendElementLabel(IJavaElement element, long flags) {
appendHoverParent= false;

// formatting checkbox
fBuffer.append("<input type='checkbox' id='" + CHECKBOX_ID_FORMATTIG + "' "); //$NON-NLS-1$ //$NON-NLS-2$
fBuffer.append("<input type='checkbox' " + CHECKBOX_FORMATTING_ID_ATTR_DQUOTES + " "); //$NON-NLS-1$ //$NON-NLS-2$
if (enableFormatting) {
fBuffer.append("checked=true "); //$NON-NLS-1$
}
Expand Down Expand Up @@ -487,18 +487,22 @@ protected void appendWildcardTypeSignature(String prefix, IJavaElement enclosing

@Override
protected void appendTypeArgumentSignaturesLabel(IJavaElement enclosingElement, String[] typeArgsSig, long flags) {
if (inBoundedTypeParam) {
inBoundedTypeParam= false;
if (noEnhancements || !inBoundedTypeParam) {
super.appendTypeArgumentSignaturesLabel(enclosingElement, typeArgsSig, flags);
inBoundedTypeParam= true;
} else {
inBoundedTypeParam= false;
super.appendTypeArgumentSignaturesLabel(enclosingElement, typeArgsSig, flags);
inBoundedTypeParam= true;
}
}

@Override
protected void appendTypeParameteSignatureLabel(String typeVariableName) {
super.appendTypeParameteSignatureLabel(wrapWithTypeClass(typeVariableName, typeVariableName));
protected void appendTypeParameterSignatureLabel(String typeVariableName) {
if (noEnhancements) {
super.appendTypeParameterSignatureLabel(typeVariableName);
} else {
super.appendTypeParameterSignatureLabel(wrapWithTypeClass(typeVariableName, typeVariableName));
}
}
}

Expand Down Expand Up @@ -858,6 +862,10 @@ public static void setColorPreferenceForTypeParamsReference(int referenceIndex,
PreferenceConverter.setValue(preferenceStore(), getColorPreferenceKey(PREFERENCE_KEY_PREFIX_TYPE_PARAMETERS_REFERENCE_COLOR, referenceIndex), color);
}

public static boolean isStylingPresent(String browserContent) {
return browserContent.contains(CHECKBOX_FORMATTING_ID_ATTR_DQUOTES) || browserContent.contains(CHECKBOX_FORMATTING_ID_ATTR_SQUOTES);
}

public static String modifyCssStyleSheet(String css, StringBuilder buffer) {
int startPos= buffer.indexOf(CSS_CLASS_SWITCH_PARENT);
if (startPos < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public SignatureStylingMenuToolbarAction(Shell parent, BrowserTextAccessor brows
new ToggleSignatureTypeParametersColoringAction(),
// widget for following action is being removed and re-added repeatedly, see SignatureStylingColorSubMenuItem.menuShown()
new SignatureStylingColorSubMenuItem(parent, javadocContentSupplier)};
actions= enabledActions;
actions= noStylingActions;
setMenuCreator(this);
this.parent= parent;
this.enhancementsReconfiguredTask= enhancementsReconfiguredTask;
Expand All @@ -76,7 +76,7 @@ public void browserContentChanged(Supplier<String> contentAccessor) {
return;
}
var content= contentAccessor.get();
if (content != null && !content.isBlank() && content.contains(JavaElementLinks.CHECKBOX_ID_FORMATTIG)) {
if (content != null && !content.isBlank() && JavaElementLinks.isStylingPresent(content)) {
reAddActionItems(enabledActions);
} else {
reAddActionItems(noStylingActions);
Expand Down Expand Up @@ -141,6 +141,8 @@ public void stylingStateChanged(boolean isEnabled) {
parent.getDisplay().execute(() -> {
enhancementsEnabled= isEnabled;
presentEnhancementsState();
// even if enhancements switched from off to on, only browserContentChanged() sets enabledActions
reAddActionItems(noStylingActions);
runEnhancementsReconfiguredTask();
});
}
Expand Down

0 comments on commit 7d476d3

Please sign in to comment.