Commit fb78774f authored by Yaroslav Pankratyev's avatar Yaroslav Pankratyev
Browse files

IDEA-196403 Color picker for color icons in theme JSONs

parent 78ceef7e
Showing with 34 additions and 6 deletions
+34 -6
......@@ -108,6 +108,8 @@ new.theme.dialog.name.text.field.text=Name:
new.theme.dialog.is.dark.checkbox.text=Dark theme
new.theme.dialog.name.empty=Theme Name must not be empty
theme.choose.color.dialog.title=Choose Color
new.menu.application.component.text=Application Component
new.menu.module.component.text=Module Component
new.menu.project.component.text=Project Component
......
......@@ -2,21 +2,29 @@
package org.jetbrains.idea.devkit.themes;
import com.intellij.codeInsight.daemon.LineMarkerSettings;
import com.intellij.json.psi.JsonElementGenerator;
import com.intellij.json.psi.JsonStringLiteral;
import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.ui.ColorChooser;
import com.intellij.ui.ColorLineMarkerProvider;
import com.intellij.ui.ColorUtil;
import com.intellij.util.ui.ColorIcon;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.devkit.DevKitBundle;
import javax.swing.*;
import java.awt.*;
......@@ -60,7 +68,7 @@ public class ThemeColorAnnotator implements Annotator {
private final JsonStringLiteral myLiteral;
private MyRenderer(String colorHex, JsonStringLiteral literal) {
private MyRenderer(@NotNull String colorHex, @NotNull JsonStringLiteral literal) {
myColorHex = colorHex;
myLiteral = literal;
}
......@@ -82,18 +90,36 @@ public class ThemeColorAnnotator implements Annotator {
return new AnAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
//TODO implement
Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
if (editor == null) return;
Color currentColor = getColor(myColorHex);
if (currentColor == null) return;
Color newColor = ColorChooser.chooseColor(editor.getComponent(),
DevKitBundle.message("theme.choose.color.dialog.title"),
currentColor);
if (newColor == null || newColor.equals(currentColor)) return;
String newColorHex = ColorUtil.toHtmlColor(newColor);
Project project = myLiteral.getProject();
JsonStringLiteral newLiteral = new JsonElementGenerator(project).createStringLiteral(newColorHex);
WriteCommandAction.writeCommandAction(project, myLiteral.getContainingFile()).run(() -> myLiteral.replace(newLiteral));
}
};
}
@Nullable
@Override
public String getTooltipText() {
return null; //TODO implement
private static Color getColor(@NotNull String colorHex) {
try {
return Color.decode(colorHex);
}
catch (NumberFormatException ignored) {
return null;
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment