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

custom folding regions #1825

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.eclipse.jdt.ui.tests.folding;

import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;

@Suite
@SelectClasses({
CustomFoldingRegionTest.class
})
public class FoldingTest {
}
11 changes: 11 additions & 0 deletions org.eclipse.jdt.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,17 @@
<keywordReference id="org.eclipse.jdt.ui.saveparticipant"/>
</page>

<page
name="%editorFoldingPage"
class="org.eclipse.jdt.internal.ui.preferences.FoldingPreferencePage"
category="org.eclipse.jdt.ui.propertyPages.JavaEditorPropertyPage"
id="org.eclipse.jdt.ui.propertyPages.FoldingPreferencePage">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.jdt.core.javanature"/>
</adapt>
</enabledWhen>
</page>
<page
name="%classpathContainerPageName"
class="org.eclipse.jdt.internal.ui.preferences.ClasspathContainerPreferencePage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IScopeContext;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.layout.PixelConverter;
Expand All @@ -46,8 +47,10 @@

import org.eclipse.jdt.internal.corext.util.Messages;

import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.folding.IJavaFoldingPreferenceBlock;
import org.eclipse.jdt.ui.text.folding.IScopedJavaFoldingPreferenceBlock;

import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
Expand All @@ -61,7 +64,7 @@
*
* @since 3.0
*/
class FoldingConfigurationBlock implements IPreferenceConfigurationBlock {
class FoldingConfigurationBlock implements IPreferenceAndPropertyConfigurationBlock {

private static class ErrorPreferences implements IJavaFoldingPreferenceBlock {
private String fMessage;
Expand Down Expand Up @@ -117,14 +120,20 @@ public void dispose() {
private final Map<String, IJavaFoldingPreferenceBlock> fProviderPreferences;
private final Map<String, Control> fProviderControls;

private IScopeContext fContext;

public FoldingConfigurationBlock(OverlayPreferenceStore store) {
private boolean fIsProjectPreferencePage;


public FoldingConfigurationBlock(OverlayPreferenceStore store, IScopeContext context, boolean isProjectPreferencePage) {
Assert.isNotNull(store);
fStore= store;
fStore.addKeys(createOverlayStoreKeys());
fProviderDescriptors= createListModel();
fProviderPreferences= new HashMap<>();
fProviderControls= new HashMap<>();
this.fContext= context;
this.fIsProjectPreferencePage= isProjectPreferencePage;
}

private Map<String, JavaFoldingStructureProviderDescriptor> createListModel() {
Expand Down Expand Up @@ -289,6 +298,14 @@ void updateListDependencies() {
if (prefs == null) {
try {
prefs= desc.createPreferences();
if (fIsProjectPreferencePage) {
if (prefs instanceof IScopedJavaFoldingPreferenceBlock scopedPrefs) {
scopedPrefs.setScopeContext(fContext);
} else {
String message= Messages.format(PreferencesMessages.FoldingConfigurationBlock_error_project_prefs_not_supported, desc.getName());
prefs= new ErrorPreferences(message);
}
}
fProviderPreferences.put(id, prefs);
} catch (CoreException e) {
JavaPlugin.log(e);
Expand Down Expand Up @@ -369,4 +386,19 @@ private void restoreFromPreferences() {
else
fProviderViewer.setSelection(new StructuredSelection(provider), true);
}

@Override
public void disableProjectSettings() {
if(fContext != null) {
fContext.getNode(JavaUI.ID_PLUGIN).remove(PreferenceConstants.EDITOR_FOLDING_ENABLED);
}
}

@Override
public void enableProjectSettings() {
if(fContext != null) {
fContext.getNode(JavaUI.ID_PLUGIN).putBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED, fStore.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,85 @@
package org.eclipse.jdt.internal.ui.preferences;


import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.core.runtime.preferences.IScopeContext;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;

import org.eclipse.ui.preferences.ScopedPreferenceStore;

import org.eclipse.jdt.ui.JavaUI;

import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;

/**
* The page for setting the editor options.
*/
public final class FoldingPreferencePage extends AbstractConfigurationBlockPreferencePage {
public final class FoldingPreferencePage extends AbstractConfigurationBlockPreferenceAndPropertyPage {

public static final String PROPERTY_PAGE_ID= "org.eclipse.jdt.ui.propertyPages.FoldingPreferencePage"; //$NON-NLS-1$
public static final String PREFERENCE_PAGE_ID= "org.eclipse.jdt.ui.preferences.FoldingPreferencePage"; //$NON-NLS-1$
private OverlayPreferenceStore fOverlayStore;


public FoldingPreferencePage() {
setDescription(PreferencesMessages.JavaEditorPreferencePage_folding_title);
}

/*
* @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#getHelpId()
* @see org.eclipse.jdt.internal.ui.preferences.AbstractConfigurationBlockPreferenceAndPropertyPage#getHelpId()
*/
@Override
protected String getHelpId() {
return IJavaHelpContextIds.JAVA_EDITOR_PREFERENCE_PAGE;
}

/*
* @see org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setDescription()
*/
@Override
protected void setDescription() {
String description= PreferencesMessages.JavaEditorPreferencePage_folding_title;
setDescription(description);
protected IPreferenceAndPropertyConfigurationBlock createConfigurationBlock(IScopeContext context) {
ScopedPreferenceStore scopedStore= new ScopedPreferenceStore(context, JavaUI.ID_PLUGIN);
fOverlayStore= new OverlayPreferenceStore(
scopedStore,
new OverlayPreferenceStore.OverlayKey[] {});
FoldingConfigurationBlock foldingConfigurationBlock= new FoldingConfigurationBlock(fOverlayStore, context, isProjectPreferencePage());
fOverlayStore.load();
fOverlayStore.start();
return foldingConfigurationBlock;
}

/*
* @see org.org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setPreferenceStore()
*/
@Override
protected void setPreferenceStore() {
setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
protected boolean hasProjectSpecificOptions(IProject project) {
return JavaPlugin.getDefault().getFoldingStructureProviderRegistry().hasProjectSpecificOptions(new ProjectScope(project));
}

@Override
protected String getPreferencePageID() {
return PREFERENCE_PAGE_ID;
}

@Override
protected Label createDescriptionLabel(Composite parent) {
return null; // no description for new look.
protected String getPropertyPageID() {
return PROPERTY_PAGE_ID;
}

/*
* @see org.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#createConfigurationBlock(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore)
*/
@Override
protected IPreferenceConfigurationBlock createConfigurationBlock(OverlayPreferenceStore overlayPreferenceStore) {
return new FoldingConfigurationBlock(overlayPreferenceStore);
public boolean performOk() {
boolean result= super.performOk();
fOverlayStore.propagate();
return result;
}

@Override
public void performDefaults() {
fOverlayStore.loadDefaults();
super.performDefaults();

}

@Override
public void dispose() {
super.dispose();
fOverlayStore.stop();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ private PreferencesMessages() {
public static String FoldingConfigurationBlock_combo_caption;
public static String FoldingConfigurationBlock_info_no_preferences;
public static String FoldingConfigurationBlock_error_not_exist;
public static String FoldingConfigurationBlock_error_project_prefs_not_supported;
public static String FoldingConfigurationBlock_warning_providerNotFound_resetToDefault;
public static String PropertiesFileEditorPreferencePage_key;
public static String PropertiesFileEditorPreferencePage_value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ FoldingConfigurationBlock_enable= Enable f&olding
FoldingConfigurationBlock_combo_caption= Select folding to &use:
FoldingConfigurationBlock_info_no_preferences= The selected folding provider did not provide a preference control
FoldingConfigurationBlock_error_not_exist= The ''{0}'' folding provider does not exist.
FoldingConfigurationBlock_error_project_prefs_not_supported=The ''{0}'' folding provider does not support project specific preferences.
FoldingConfigurationBlock_warning_providerNotFound_resetToDefault= The ''{0}'' folding provider could not be found. Resetting to the default folding provider.

# Properties File Editor
Expand Down
Loading