mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Allow to move a standard code style option to another group [CR-IC-2192]
(cherry picked from commit 81c4f16)
This commit is contained in:
@@ -296,4 +296,11 @@ public interface CodeStyleSettingsCustomizable {
|
||||
Object... options);
|
||||
|
||||
void renameStandardOption(String fieldName, String newTitle);
|
||||
|
||||
/**
|
||||
* Moves a standard option to another group.
|
||||
* @param fieldName The field name of the option to move (as defined in <code>CommonCodeStyleSettings</code> class).
|
||||
* @param newGroup The new group name (the group may be one of existing ones). A custom group name can be used if supported by consumer.
|
||||
*/
|
||||
void moveStandardOption(String fieldName, String newGroup);
|
||||
}
|
||||
|
||||
+5
@@ -289,6 +289,11 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveStandardOption(String fieldName, String newGroup) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
public Set<String> getCollectedFields() {
|
||||
return myCollectedFields;
|
||||
}
|
||||
|
||||
+5
@@ -287,6 +287,11 @@ public abstract class MultilanguageCodeStyleAbstractPanel extends CodeStyleAbstr
|
||||
return getSelectedLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveStandardOption(String fieldName, String newGroup) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected <T extends OrderedOption>List<T> sortOptions(Collection<T> options) {
|
||||
Set<String> names = new THashSet<String>(ContainerUtil.map(options, new Function<OrderedOption, String>() {
|
||||
@Override
|
||||
|
||||
+46
-2
@@ -57,6 +57,7 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA
|
||||
private MultiMap<String, CustomBooleanOptionInfo> myCustomOptions = new MultiMap<String, CustomBooleanOptionInfo>();
|
||||
private boolean isFirstUpdate = true;
|
||||
private final Map<String, String> myRenamedFields = new THashMap<String, String>();
|
||||
private final Map<String, String> myRemappedGroups = new THashMap<String, String>();
|
||||
|
||||
|
||||
public OptionTreeWithPreviewPanel(CodeStyleSettings settings) {
|
||||
@@ -180,7 +181,7 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA
|
||||
String groupName = "";
|
||||
DefaultMutableTreeNode groupNode = null;
|
||||
|
||||
List<BooleanOptionKey> result = sortOptions(myKeys);
|
||||
List<BooleanOptionKey> result = sortOptions(orderByGroup(myKeys));
|
||||
|
||||
for (BooleanOptionKey key : result) {
|
||||
String newGroupName = key.groupName;
|
||||
@@ -235,6 +236,39 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA
|
||||
return optionsTree;
|
||||
}
|
||||
|
||||
private List<BooleanOptionKey> orderByGroup(final List<BooleanOptionKey> options) {
|
||||
final List<String> groupOrder = getGroupOrder(options);
|
||||
List<BooleanOptionKey> result = new ArrayList<BooleanOptionKey>(options.size());
|
||||
result.addAll(options);
|
||||
Collections.sort(result, new Comparator<BooleanOptionKey>(){
|
||||
@Override
|
||||
public int compare(BooleanOptionKey key1, BooleanOptionKey key2) {
|
||||
String group1 = key1.groupName;
|
||||
String group2 = key2.groupName;
|
||||
if (group1 == null) {
|
||||
return group2 == null ? 0 : 1;
|
||||
}
|
||||
if (group2 == null) {
|
||||
return -1;
|
||||
}
|
||||
Integer index1 = groupOrder.indexOf(group1);
|
||||
Integer index2 = groupOrder.indexOf(group2);
|
||||
if (index1 == -1 || index2 == -1) return group1.compareToIgnoreCase(group2);
|
||||
return index1.compareTo(index2);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<String> getGroupOrder(List<BooleanOptionKey> options) {
|
||||
List<String> groupOrder = new ArrayList<String>();
|
||||
for (BooleanOptionKey each : options) {
|
||||
if (each.groupName != null && !groupOrder.contains(each.groupName)) {
|
||||
groupOrder.add(each.groupName);
|
||||
}
|
||||
}
|
||||
return groupOrder;
|
||||
}
|
||||
|
||||
private void selectCheckbox(TreePath treePath) {
|
||||
if (treePath == null) {
|
||||
@@ -358,9 +392,10 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA
|
||||
try {
|
||||
Class styleSettingsClass = CodeStyleSettings.class;
|
||||
Field field = styleSettingsClass.getField(fieldName);
|
||||
String actualGroupName = getRemappedGroup(fieldName, groupName);
|
||||
|
||||
BooleanOptionKey key = new BooleanOptionKey(fieldName,
|
||||
getRenamedTitle(groupName, groupName),
|
||||
getRenamedTitle(actualGroupName, actualGroupName),
|
||||
getRenamedTitle(fieldName, title), field);
|
||||
myKeys.add(key);
|
||||
}
|
||||
@@ -622,4 +657,13 @@ public abstract class OptionTreeWithPreviewPanel extends MultilanguageCodeStyleA
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveStandardOption(String fieldName, String newGroup) {
|
||||
myRemappedGroups.put(fieldName, newGroup);
|
||||
}
|
||||
|
||||
private String getRemappedGroup(String fieldName, String defaultName) {
|
||||
return myRemappedGroups.containsKey(fieldName) ? myRemappedGroups.get(fieldName) : defaultName;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user