mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
EditorConfig status bar UI refactoring
This commit is contained in:
@@ -204,4 +204,5 @@ config.export=Export
|
||||
|
||||
action.disable=Disable EditorConfig for Project
|
||||
action.open.file=Open {0} File...
|
||||
disabled.notification=EditorConfig disabled
|
||||
disabled.notification=EditorConfig disabled
|
||||
config.code.style.overridden=One or more code style options are overridden by EditorConfig
|
||||
@@ -2,6 +2,7 @@
|
||||
package org.editorconfig;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
@@ -37,7 +38,9 @@ import java.util.Map;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final String FULL_SETTINGS_SUPPORT_REG_KEY = "editor.config.full.settings.support";
|
||||
public static final String FULL_SETTINGS_SUPPORT_REG_KEY = "editor.config.full.settings.support";
|
||||
private static final String PROJECT_ADVERTISEMENT_FLAG = "editor.config.ad.shown";
|
||||
|
||||
private static boolean ourIsFullSettingsSupportEnabledInTest;
|
||||
|
||||
public static String configValueForKey(List<? extends OutPair> outPairs, String key) {
|
||||
@@ -195,4 +198,12 @@ public class Utils {
|
||||
}
|
||||
result.append("\n");
|
||||
}
|
||||
|
||||
public static boolean isShowAdvertisementText(@NotNull Project project) {
|
||||
final PropertiesComponent projectProperties = PropertiesComponent.getInstance(project);
|
||||
boolean adFlag = projectProperties.getBoolean(PROJECT_ADVERTISEMENT_FLAG);
|
||||
if (adFlag) return false;
|
||||
projectProperties.setValue(PROJECT_ADVERTISEMENT_FLAG, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-74
@@ -1,9 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.editorconfig.configmanagement;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.ide.actions.ShowSettingsUtilImpl;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationDisplayType;
|
||||
import com.intellij.notification.NotificationGroup;
|
||||
@@ -13,67 +11,31 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions;
|
||||
import com.intellij.psi.codeStyle.IndentStatusBarUIContributor;
|
||||
import com.intellij.psi.codeStyle.modifier.TransientCodeStyleSettings;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.editorconfig.language.messages.EditorConfigBundle;
|
||||
import org.editorconfig.settings.EditorConfigSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorConfigStatusUIContributor extends IndentStatusBarUIContributor {
|
||||
|
||||
private static final String PROJECT_ADVERTISEMENT_FLAG = "editor.config.ad.shown";
|
||||
|
||||
private final boolean myEditorConfigIndentOptions;
|
||||
|
||||
public class EditorConfigActionUtil {
|
||||
private static final NotificationGroup NOTIFICATION_GROUP =
|
||||
new NotificationGroup("EditorConfig", NotificationDisplayType.STICKY_BALLOON, true);
|
||||
|
||||
public EditorConfigStatusUIContributor(TransientCodeStyleSettings transientSettings) {
|
||||
super(getOverriddenIndentOptions(transientSettings));
|
||||
myEditorConfigIndentOptions = true;
|
||||
|
||||
public static AnAction[] createNavigationActions(@NotNull PsiFile file) {
|
||||
List<AnAction> actions = ContainerUtil.newArrayList();
|
||||
EditorConfigNavigationActionsFactory navigationActionsFactory =
|
||||
EditorConfigNavigationActionsFactory.getInstance(file.getVirtualFile());
|
||||
actions.addAll(navigationActionsFactory.getNavigationActions(file.getProject()));
|
||||
return actions.toArray(AnAction.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
public EditorConfigStatusUIContributor(IndentOptions options) {
|
||||
super(options);
|
||||
myEditorConfigIndentOptions = options.getFileIndentOptionsProvider() instanceof EditorConfigIndentOptionsProvider;
|
||||
}
|
||||
|
||||
private static IndentOptions getOverriddenIndentOptions(@NotNull TransientCodeStyleSettings transientSettings) {
|
||||
PsiFile file = transientSettings.getPsiFile();
|
||||
return transientSettings.getLanguageIndentOptions(file.getLanguage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areActionsAvailable(@NotNull VirtualFile file) {
|
||||
return myEditorConfigIndentOptions;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction[] getActions(@NotNull PsiFile file) {
|
||||
if (myEditorConfigIndentOptions) {
|
||||
List<AnAction> actions = ContainerUtil.newArrayList();
|
||||
EditorConfigNavigationActionsFactory navigationActionsFactory =
|
||||
EditorConfigNavigationActionsFactory.getInstance(file.getVirtualFile());
|
||||
actions.addAll(navigationActionsFactory.getNavigationActions(file.getProject()));
|
||||
return actions.toArray(AnAction.EMPTY_ARRAY);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction createDisableAction(@NotNull Project project) {
|
||||
public static AnAction createDisableAction(@NotNull Project project) {
|
||||
return DumbAwareAction.create(
|
||||
EditorConfigBundle.message("action.disable"),
|
||||
e -> {
|
||||
@@ -84,22 +46,6 @@ public class EditorConfigStatusUIContributor extends IndentStatusBarUIContributo
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHint() {
|
||||
return myEditorConfigIndentOptions ? "EditorConfig" : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getAdvertisementText(@NotNull PsiFile psiFile) {
|
||||
final PropertiesComponent projectProperties = PropertiesComponent.getInstance(psiFile.getProject());
|
||||
boolean adFlag = projectProperties.getBoolean(PROJECT_ADVERTISEMENT_FLAG);
|
||||
if (adFlag) return null;
|
||||
projectProperties.setValue(PROJECT_ADVERTISEMENT_FLAG, true);
|
||||
return EditorConfigBundle.message("advertisement.text");
|
||||
}
|
||||
|
||||
private static void showDisabledDetectionNotification(@NotNull Project project) {
|
||||
EditorConfigDisabledNotification notification = new EditorConfigDisabledNotification(project);
|
||||
notification.notify(project);
|
||||
@@ -111,10 +57,12 @@ public class EditorConfigStatusUIContributor extends IndentStatusBarUIContributo
|
||||
EditorConfigBundle.message("disabled.notification"), "",
|
||||
NotificationType.INFORMATION);
|
||||
addAction(new ReEnableAction(project, this));
|
||||
addAction(new ShowEditorConfigOption(ApplicationBundle.message("code.style.indent.provider.notification.settings")));
|
||||
addAction(new ShowEditorConfigOption(
|
||||
ApplicationBundle.message("code.style.indent.provider.notification.settings")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ShowEditorConfigOption extends DumbAwareAction {
|
||||
private ShowEditorConfigOption(@Nullable String text) {
|
||||
super(text);
|
||||
@@ -146,13 +94,4 @@ public class EditorConfigStatusUIContributor extends IndentStatusBarUIContributo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowFileIndentOptionsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -163,7 +163,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
|
||||
@Nullable
|
||||
@Override
|
||||
public IndentStatusBarUIContributor getIndentStatusBarUiContributor(@NotNull IndentOptions indentOptions) {
|
||||
return new EditorConfigStatusUIContributor(indentOptions);
|
||||
return new EditorConfigIndentStatusBarUIContributor(indentOptions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.editorconfig.configmanagement;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions;
|
||||
import com.intellij.psi.codeStyle.IndentStatusBarUIContributor;
|
||||
import org.editorconfig.Utils;
|
||||
import org.editorconfig.language.messages.EditorConfigBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EditorConfigIndentStatusBarUIContributor extends IndentStatusBarUIContributor {
|
||||
|
||||
private final boolean myEditorConfigIndentOptions;
|
||||
|
||||
public EditorConfigIndentStatusBarUIContributor(IndentOptions options) {
|
||||
super(options);
|
||||
myEditorConfigIndentOptions = options.getFileIndentOptionsProvider() instanceof EditorConfigIndentOptionsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areActionsAvailable(@NotNull VirtualFile file) {
|
||||
return myEditorConfigIndentOptions;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction[] getActions(@NotNull PsiFile file) {
|
||||
if (myEditorConfigIndentOptions) {
|
||||
return EditorConfigActionUtil.createNavigationActions(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction createDisableAction(@NotNull Project project) {
|
||||
return EditorConfigActionUtil.createDisableAction(project);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHint() {
|
||||
return myEditorConfigIndentOptions ? "EditorConfig" : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getAdvertisementText(@NotNull PsiFile psiFile) {
|
||||
return Utils.isShowAdvertisementText(psiFile.getProject()) ? EditorConfigBundle.message("advertisement.text") : null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isShowFileIndentOptionsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-10
@@ -14,7 +14,6 @@ import com.intellij.psi.codeStyle.modifier.CodeStyleStatusBarUIContributor;
|
||||
import com.intellij.psi.codeStyle.modifier.TransientCodeStyleSettings;
|
||||
import org.editorconfig.Utils;
|
||||
import org.editorconfig.configmanagement.EditorConfigNavigationActionsFactory;
|
||||
import org.editorconfig.configmanagement.EditorConfigStatusUIContributor;
|
||||
import org.editorconfig.core.EditorConfig;
|
||||
import org.editorconfig.core.EditorConfigException;
|
||||
import org.editorconfig.core.ParserCallback;
|
||||
@@ -55,13 +54,7 @@ public class EditorConfigCodeStyleSettingsModifier implements CodeStyleSettingsM
|
||||
@Nullable
|
||||
@Override
|
||||
public CodeStyleStatusBarUIContributor getStatusBarUiContributor(@NotNull TransientCodeStyleSettings transientSettings) {
|
||||
return new EditorConfigStatusUIContributor(transientSettings) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getStatusText(@NotNull PsiFile psiFile) {
|
||||
return "EditorConfig";
|
||||
}
|
||||
};
|
||||
return new EditorConfigCodeStyleStatusBarUIContributor();
|
||||
}
|
||||
|
||||
private static boolean applyCodeStyleSettings(@NotNull List<OutPair> editorConfigOptions,
|
||||
@@ -95,8 +88,8 @@ public class EditorConfigCodeStyleSettingsModifier implements CodeStyleSettingsM
|
||||
|
||||
@Nullable
|
||||
private static CodeStylePropertyAccessor findAccessor(@NotNull AbstractCodeStylePropertyMapper mapper,
|
||||
@NotNull String propertyName,
|
||||
@Nullable String langPrefix) {
|
||||
@NotNull String propertyName,
|
||||
@Nullable String langPrefix) {
|
||||
if (langPrefix != null) {
|
||||
if (propertyName.startsWith(langPrefix)) {
|
||||
final String prefixlessName = StringUtil.trimStart(propertyName, langPrefix);
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package org.editorconfig.configmanagement.extended;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.modifier.CodeStyleStatusBarUIContributor;
|
||||
import org.editorconfig.Utils;
|
||||
import org.editorconfig.configmanagement.EditorConfigActionUtil;
|
||||
import org.editorconfig.language.messages.EditorConfigBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class EditorConfigCodeStyleStatusBarUIContributor implements CodeStyleStatusBarUIContributor {
|
||||
|
||||
@Override
|
||||
public boolean areActionsAvailable(@NotNull VirtualFile file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction[] getActions(@NotNull PsiFile file) {
|
||||
return EditorConfigActionUtil.createNavigationActions(file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return EditorConfigBundle.message("config.code.style.overridden");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getAdvertisementText(@NotNull PsiFile psiFile) {
|
||||
return Utils.isShowAdvertisementText(psiFile.getProject()) ? EditorConfigBundle.message("config.code.style.overridden") : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AnAction createDisableAction(@NotNull Project project) {
|
||||
return EditorConfigActionUtil.createDisableAction(project);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getStatusText(@NotNull PsiFile psiFile) {
|
||||
return EditorConfigBundle.message("config.title");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user