AnAction () { if (!canChooseColor()) return null; return new AnAction(DevKitThemesBundle.messagePointer("action.Anonymous.text.choose.color")) { @Override public void actionPerformed(@NotNull AnActionEvent e) { Editor editor = e.getData(CommonDataKeys.EDITOR); if (editor == null) return; Color currentColor = getColor(myColorText); if (currentColor == null) return; boolean withAlpha = isRgbaColorHex(myColorText); if (Registry.is("ide.new.color.picker")) { ColorChooserService.getInstance().showPopup(e.getProject(), currentColor, (c, l) -> applyColor(currentColor, withAlpha, c)); } else { Color newColor = ColorChooserService.getInstance().showDialog(editor.getProject(), editor.getComponent(), DevKitThemesBundle.message("theme.choose.color.dialog.title"), currentColor, withAlpha); applyColor(currentColor, withAlpha, newColor); } } private void applyColor(Color currentColor, boolean withAlpha, Color newColor) { if (newColor == null || newColor.equals(currentColor)) return; String newColorHex = "#" + ColorUtil.toHex(newColor, withAlpha); Project project = myLiteral.getProject(); JsonStringLiteral newLiteral = new JsonElementGenerator(project).createStringLiteral(newColorHex); WriteCommandAction.writeCommandAction(project, myLiteral.getContainingFile()).run( () -> myLiteral = (JsonStringLiteral)myLiteral.replace(newLiteral) ); } }; }