mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Ordering code style tabs/panels according to key IDE language (see IDEA-72177)
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ public class GenerationSettingsProvider extends CodeStyleSettingsProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return CODE_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.CODE_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,7 @@ public class ImportsSettingsProvider extends CodeStyleSettingsProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return CODE_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.CODE_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -67,6 +69,12 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisplayPriority getDisplayPriority() {
|
||||
if (PlatformUtils.isIdea()) return DisplayPriority.KEY_LANGUAGE_SETTINGS;
|
||||
return DisplayPriority.LANGUAGE_SETTINGS;
|
||||
}
|
||||
|
||||
private static final String GENERAL_CODE_SAMPLE =
|
||||
"public class Foo {\n" +
|
||||
" public int[] X = new int[]{1, 3, 5 7, 9, 11};\n" +
|
||||
|
||||
@@ -26,11 +26,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class CodeStyleSettingsProvider {
|
||||
public static final ExtensionPointName<CodeStyleSettingsProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.codeStyleSettingsProvider");
|
||||
|
||||
public final static int GENERAL_PRIORITY = 0;
|
||||
public final static int COMMON_SETTINGS_PRIORITY = 1;
|
||||
public final static int CODE_PRIORITY = 2;
|
||||
public final static int LANGUAGE_PRIORITY = 3;
|
||||
public final static int OTHER_PRIORITY = 4;
|
||||
|
||||
@Nullable
|
||||
public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) {
|
||||
@@ -55,7 +50,7 @@ public abstract class CodeStyleSettingsProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getPriority() {
|
||||
return LANGUAGE_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.LANGUAGE_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.codeStyle;
|
||||
|
||||
/**
|
||||
* Used in settings providers to indicate in which order a settings tab or panel must be shown in Settings UI.
|
||||
*
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
public enum DisplayPriority {
|
||||
/**
|
||||
* General settings (topmost)
|
||||
*/
|
||||
GENERAL_SETTINGS,
|
||||
/**
|
||||
* Any generic settings normally used by multiple languages.
|
||||
*/
|
||||
COMMON_SETTINGS,
|
||||
/**
|
||||
* Code arrangement settings like imports, etc.
|
||||
*/
|
||||
CODE_SETTINGS,
|
||||
/**
|
||||
* Key IDE language priority (depends on product), for exmaple, Java for IDEA, PHP for PhpStorm etc.
|
||||
*/
|
||||
KEY_LANGUAGE_SETTINGS,
|
||||
/**
|
||||
* Language-specific settings.
|
||||
*/
|
||||
LANGUAGE_SETTINGS,
|
||||
/**
|
||||
* Any other settings.
|
||||
*/
|
||||
OTHER_SETTINGS
|
||||
}
|
||||
+12
@@ -108,6 +108,10 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
return PredefinedCodeStyle.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public DisplayPriority getDisplayPriority() {
|
||||
return DisplayPriority.LANGUAGE_SETTINGS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Language[] getLanguagesWithCodeStyleSettings() {
|
||||
final ArrayList<Language> languages = new ArrayList<Language>();
|
||||
@@ -139,6 +143,7 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
return provider != null ? provider.getRightMargin(settingsType) : -1;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static Language getLanguage(String langName) {
|
||||
for (LanguageCodeStyleSettingsProvider provider : Extensions.getExtensions(EP_NAME)) {
|
||||
@@ -184,4 +189,11 @@ public abstract class LanguageCodeStyleSettingsProvider {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DisplayPriority getDisplayPriority(Language language) {
|
||||
LanguageCodeStyleSettingsProvider langProvider = forLanguage(language);
|
||||
if (langProvider == null) return DisplayPriority.LANGUAGE_SETTINGS;
|
||||
return langProvider.getDisplayPriority();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-6
@@ -28,10 +28,6 @@ import com.intellij.psi.codeStyle.CodeStyleScheme;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeImpl;
|
||||
import com.intellij.ui.ListUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.apache.commons.collections.ListUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -213,8 +209,8 @@ public class CodeStyleSchemesConfigurable extends SearchableConfigurable.Parent.
|
||||
Collections.sort(providers, new Comparator<CodeStyleSettingsProvider>() {
|
||||
@Override
|
||||
public int compare(CodeStyleSettingsProvider p1, CodeStyleSettingsProvider p2) {
|
||||
if (p1.getPriority() != p2.getPriority()) {
|
||||
return p1.getPriority() - p2.getPriority();
|
||||
if (!p1.getPriority().equals(p2.getPriority())) {
|
||||
return p1.getPriority().compareTo(p2.getPriority());
|
||||
}
|
||||
String name1 = p1.getConfigurableDisplayName();
|
||||
if (name1 == null) name1 = "";
|
||||
|
||||
@@ -29,7 +29,9 @@ import com.intellij.openapi.fileTypes.LanguageFileType;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import com.intellij.psi.codeStyle.FileTypeIndentOptionsProvider;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.ui.OptionGroup;
|
||||
import com.intellij.ui.TabbedPaneWrapper;
|
||||
@@ -41,10 +43,8 @@ import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneralCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.application.options.GeneralCodeStylePanel");
|
||||
@@ -74,7 +74,23 @@ public class GeneralCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
public GeneralCodeStylePanel(CodeStyleSettings settings) {
|
||||
super(settings);
|
||||
|
||||
final FileTypeIndentOptionsProvider[] indentOptionsProviders = Extensions.getExtensions(FileTypeIndentOptionsProvider.EP_NAME);
|
||||
final List<FileTypeIndentOptionsProvider> indentOptionsProviders =
|
||||
Arrays.asList(Extensions.getExtensions(FileTypeIndentOptionsProvider.EP_NAME));
|
||||
Collections.sort(indentOptionsProviders, new Comparator<FileTypeIndentOptionsProvider>() {
|
||||
@Override
|
||||
public int compare(FileTypeIndentOptionsProvider p1, FileTypeIndentOptionsProvider p2) {
|
||||
Language lang1 = getLanguage(p1.getFileType());
|
||||
if (lang1 == null) return -1;
|
||||
Language lang2 = getLanguage(p2.getFileType());
|
||||
if (lang2 == null) return 1;
|
||||
DisplayPriority priority1 = LanguageCodeStyleSettingsProvider.getDisplayPriority(lang1);
|
||||
DisplayPriority priority2 = LanguageCodeStyleSettingsProvider.getDisplayPriority(lang2);
|
||||
if (priority1.equals(priority2)) {
|
||||
return lang1.getDisplayName().compareTo(lang2.getDisplayName());
|
||||
}
|
||||
return priority1.compareTo(priority2);
|
||||
}
|
||||
});
|
||||
for (FileTypeIndentOptionsProvider indentOptionsProvider : indentOptionsProviders) {
|
||||
myIndentOptionsProviders.add(indentOptionsProvider);
|
||||
if (myAdditionalIndentOptions.containsKey(indentOptionsProvider.getFileType())) {
|
||||
@@ -106,6 +122,12 @@ public class GeneralCodeStylePanel extends CodeStyleAbstractPanel {
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Language getLanguage(FileType fileType) {
|
||||
return (fileType instanceof LanguageFileType) ? ((LanguageFileType)fileType).getLanguage() : null;
|
||||
}
|
||||
|
||||
|
||||
protected void somethingChanged() {
|
||||
super.somethingChanged();
|
||||
update();
|
||||
|
||||
+3
-2
@@ -21,6 +21,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -52,7 +53,7 @@ public class GeneralCodeStyleSettingsProvider extends CodeStyleSettingsProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return GENERAL_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.GENERAL_SETTINGS;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.sun.tools.javah.Gen;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -44,7 +45,7 @@ public class BlankLinesSettingsProvider extends CodeStyleSettingsProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return COMMON_SETTINGS_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.COMMON_SETTINGS;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import com.sun.tools.javah.Gen;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -43,7 +44,7 @@ public class SpacesSettingsProvider extends CodeStyleSettingsProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return COMMON_SETTINGS_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.COMMON_SETTINGS;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -22,6 +22,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider;
|
||||
import com.intellij.psi.codeStyle.DisplayPriority;
|
||||
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -56,7 +57,7 @@ public class WrappingAndBracesSettingsProvider extends CodeStyleSettingsProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return COMMON_SETTINGS_PRIORITY;
|
||||
public DisplayPriority getPriority() {
|
||||
return DisplayPriority.COMMON_SETTINGS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user