Skip to content

Commit

Permalink
Add Setting for Folding
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-suliga committed Dec 20, 2024
1 parent 28c4ddd commit 649e208
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private OverlayKey[] createKeys() {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_IMPORTS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_HEADERS));

overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED));
return overlayKeys.toArray(new OverlayKey[overlayKeys.size()]);
}

Expand All @@ -102,6 +102,12 @@ public Control createControl(Composite composite) {
addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_methods, PreferenceConstants.EDITOR_FOLDING_METHODS, 0);
addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_imports, PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0);

Label label2= new Label(inner, SWT.LEFT);
label2.setText(""); //$NON-NLS-1$
Label label1= new Label(inner, SWT.LEFT);
label1.setText(FoldingMessages.DefaultJavaFoldingPreferenceBlock_New_Setting_Title);

addCheckBox(inner, FoldingMessages.DefaultJavaFoldingPreferenceBlock_New, PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED, 0);
return inner;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ private FoldingMessages() {
public static String DefaultJavaFoldingPreferenceBlock_innerTypes;
public static String DefaultJavaFoldingPreferenceBlock_methods;
public static String DefaultJavaFoldingPreferenceBlock_imports;
public static String DefaultJavaFoldingPreferenceBlock_New;
public static String DefaultJavaFoldingPreferenceBlock_headers;
public static String EmptyJavaFoldingPreferenceBlock_emptyCaption;
public static String JavaFoldingStructureProviderRegistry_warning_providerNotFound_resetToDefault;

public static String DefaultJavaFoldingPreferenceBlock_New_Setting_Title;
static {
NLS.initializeMessages(BUNDLE_NAME, FoldingMessages.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ DefaultJavaFoldingPreferenceBlock_innerTypes= Inner &types
DefaultJavaFoldingPreferenceBlock_methods= &Members
DefaultJavaFoldingPreferenceBlock_imports= &Imports
DefaultJavaFoldingPreferenceBlock_headers= &Header Comments

DefaultJavaFoldingPreferenceBlock_New = &New Folding (Experimental)
DefaultJavaFoldingPreferenceBlock_New_Setting_Title = &New Folding or old Folding
JavaFoldingStructureProviderRegistry_warning_providerNotFound_resetToDefault= The ''{0}'' folding provider could not be found. Resetting to the default folding provider.

EmptyJavaFoldingPreferenceBlock_emptyCaption=
12 changes: 12 additions & 0 deletions org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/PreferenceConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3411,6 +3411,16 @@ private PreferenceConstants() {
*/
public static final String EDITOR_FOLDING_ENABLED= "editor_folding_enabled"; //$NON-NLS-1$

/**
* A named preference that controls whether the new or the old folding is used.
* <p>
* Value is of type <code>Boolean</code>.
* </p>
*
* @since 3.34
*/
public static final String EDITOR_NEW_FOLDING_ENABLED= "editor_new_folding_enabled"; //$NON-NLS-1$

/**
* A named preference that stores the configured folding provider.
* <p>
Expand Down Expand Up @@ -4375,6 +4385,8 @@ public static void initializeDefaultValues(IPreferenceStore store) {
store.setDefault(EDITOR_JAVA_CODEMINING_FILTER_IMPLIED_PARAMETER_NAMES, true);
store.setDefault(EDITOR_JAVA_CODEMINING_DEFAULT_FILTER_FOR_PARAMETER_NAMES, true);

store.setDefault(EDITOR_NEW_FOLDING_ENABLED, false);

// Javadoc hover & view
JavaElementLinks.initDefaultPreferences(store);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ public void projectionDisabled() {
private boolean fCollapseInnerTypes= true;
private boolean fCollapseMembers= false;
private boolean fCollapseHeaderComments= true;
private boolean fNewFolding;

/* filters */
/** Member filter, matches nested members (but not top-level types). */
Expand Down Expand Up @@ -1195,6 +1196,7 @@ private void initializePreferences() {
fCollapseJavadoc= store.getBoolean(PreferenceConstants.EDITOR_FOLDING_JAVADOC);
fCollapseMembers= store.getBoolean(PreferenceConstants.EDITOR_FOLDING_METHODS);
fCollapseHeaderComments= store.getBoolean(PreferenceConstants.EDITOR_FOLDING_HEADERS);
fNewFolding = store.getBoolean(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED);
}

private void update(FoldingStructureComputationContext ctx) {
Expand Down Expand Up @@ -1279,12 +1281,12 @@ private void update(FoldingStructureComputationContext ctx) {
}

private void computeFoldingStructure(FoldingStructureComputationContext ctx) {
if (fInput instanceof ICompilationUnit) {
if (fNewFolding && fInput instanceof ICompilationUnit) {
processCompilationUnit((ICompilationUnit) fInput, ctx);
} else if (fInput instanceof ISourceReference) {
processComments(ctx);
} else {
processSourceReference((ISourceReference) fInput, ctx);
}
processComments(ctx);
}

private void processCompilationUnit(ICompilationUnit unit, FoldingStructureComputationContext ctx) {
Expand Down

0 comments on commit 649e208

Please sign in to comment.