in prettierJS/src/com/intellij/prettierjs/PrettierConfigurable.kt [65:225]
override fun createPanel(): DialogPanel {
val prettierConfiguration = PrettierConfiguration.getInstance(project)
val prettierState = prettierConfiguration.state
val defaultMode = prettierConfiguration.configurationMode
return panel {
buttonsGroup {
row {
disabledConfiguration = radioButton(JavaScriptBundle.message("settings.javascript.linters.autodetect.disabled", displayName))
.bindSelected(ConfigurationModeProperty(prettierState, defaultMode, ConfigurationMode.DISABLED))
.component
.apply {
addItemListener { e ->
if (e.stateChange == ItemEvent.SELECTED) {
runOnSaveCheckBox.isSelected = false
runOnPasteCheckBox.isSelected = false
codeStyleModifierCheckBox?.isSelected = false
}
}
}
}
row {
automaticConfiguration =
radioButton(JavaScriptBundle.message("settings.javascript.linters.autodetect.configure.automatically", displayName))
.bindSelected(ConfigurationModeProperty(prettierState, defaultMode, ConfigurationMode.AUTOMATIC))
.component
val autoConfigHelpText = JavaScriptBundle.message(
"settings.javascript.linters.autodetect.configure.automatically.help.text",
ApplicationNamesInfo.getInstance().fullProductName,
displayName,
".prettierrc.*"
)
val runOnSaveTooltip = PrettierBundle.message("run.on.save.auto-mode.tooltip")
val ignorePathHelpText = PrettierBundle.message(
"prettier.ignore.path.autodetect.configure.automatically.help.text",
ApplicationNamesInfo.getInstance().fullProductName,
PrettierUtil.IGNORE_FILE_NAME
)
val helpLabel = ContextHelpLabel.create(
PrettierBundle.message(
"prettier.automatic.configuration.tooltip.help",
autoConfigHelpText,
runOnSaveTooltip,
ignorePathHelpText
)
)
helpLabel.border = JBUI.Borders.emptyLeft(UIUtil.DEFAULT_HGAP)
cell(helpLabel)
}
row {
manualConfiguration =
radioButton(JavaScriptBundle.message("settings.javascript.linters.autodetect.configure.manually", displayName))
.bindSelected(ConfigurationModeProperty(prettierState, defaultMode, ConfigurationMode.MANUAL))
.component
}
}
row {
panel {
customize(UnscaledGaps(left = 21))
row(PrettierBundle.message("prettier.package.label")) {
packageField = NodePackageField(project, PrettierUtil.PACKAGE_NAME) {
NodeJsInterpreterManager.getInstance(project).interpreter
}
cell(packageField)
.align(AlignX.FILL)
.bind({ it.selectedRef }, { nodePackageField, nodePackageRef -> nodePackageField.selectedRef = nodePackageRef },
MutableProperty({ prettierConfiguration.packageRefForPackageFieldBindingInConfigurable },
{ prettierConfiguration.withLinterPackage(it) })
)
}
row(PrettierBundle.message("prettier.ignore.path.field.label")) {
customIgnorePathField = textFieldWithBrowseButton(project)
.align(AlignX.FILL)
.bind({ textField -> textField.text.trim() },
TextFieldWithBrowseButton::setText,
MutableProperty({ prettierState.customIgnorePath }, { prettierState.customIgnorePath = it }))
.component
customIgnorePathField.emptyText.setText(PrettierBundle.message("prettier.ignore.path.field.empty.text"))
}.enabledIf(manualConfiguration.selected)
row {
checkBox(PrettierBundle.message("run.on.code.reformat.label"))
.bindSelected({ prettierState.runOnReformat }, { prettierState.runOnReformat = it })
val shortcut = ActionManager.getInstance().getKeyboardShortcut(IdeActions.ACTION_EDITOR_REFORMAT)
shortcut?.let { comment(KeymapUtil.getShortcutText(it)) }
}.enabledIf(manualConfiguration.selected)
row {
checkBox(PrettierBundle.message("prettier.format.files.outside.dependency.scope.label"))
.bindSelected({ prettierState.formatFilesOutsideDependencyScope }, { prettierState.formatFilesOutsideDependencyScope = it })
val helpLabel = ContextHelpLabel.create(PrettierBundle.message("prettier.format.files.outside.dependency.scope.help.text"))
helpLabel.border = JBUI.Borders.emptyLeft(UIUtil.DEFAULT_HGAP)
cell(helpLabel)
}.enabledIf(manualConfiguration.selected)
separator()
}.visibleIf(manualConfiguration.selected)
}
row(PrettierBundle.message("run.for.files.label")) {
runForFilesField = textField()
.comment(PrettierBundle.message("files.pattern.comment"))
.align(AlignX.FILL)
.bind({ textField -> textField.text.trim() },
JTextComponent::setText,
MutableProperty({ prettierState.filesPattern }, { prettierState.filesPattern = it }))
.validationOnInput {
try {
FileSystems.getDefault().getPathMatcher("glob:" + it.text)
null
}
catch (e: PatternSyntaxException) {
@NlsSafe val firstLine = e.localizedMessage?.lines()?.firstOrNull()
ValidationInfo(firstLine ?: PrettierBundle.message("invalid.pattern"), it)
}
}
.component
}.enabledIf(!disabledConfiguration.selected)
row {
runOnSaveCheckBox = checkBox(PrettierBundle.message("run.on.save.label"))
.bindSelected({ prettierState.configurationMode != ConfigurationMode.DISABLED && prettierState.runOnSave }, { prettierState.runOnSave = it })
.component
val link = ActionsOnSaveConfigurable.createGoToActionsOnSavePageLink()
cell(link)
}.enabledIf(!disabledConfiguration.selected)
row {
runOnPasteCheckBox = checkBox(PrettierBundle.message("run.on.paste.label"))
.bindSelected({ prettierState.configurationMode != ConfigurationMode.DISABLED && prettierState.runOnPaste }, { prettierState.runOnPaste = it })
.component
}.enabledIf(!disabledConfiguration.selected)
row {
codeStyleModifierCheckBox = checkBox(PrettierBundle.message("prettier.checkbox.code.style.modification"))
.bindSelected({ prettierState.configurationMode != ConfigurationMode.DISABLED && prettierState.codeStyleSettingsModifierEnabled }, { prettierState.codeStyleSettingsModifierEnabled = it })
.component
val helpLabel = ContextHelpLabel.create(
PrettierBundle.message(
"prettier.checkbox.code.style.modification.help.text",
ApplicationNamesInfo.getInstance().fullProductName
)
)
helpLabel.border = JBUI.Borders.emptyLeft(UIUtil.DEFAULT_HGAP)
cell(helpLabel)
}.enabledIf(!disabledConfiguration.selected)
onApply {
PrettierLanguageServiceManager.getInstance(project).terminateServices()
CodeStyleSettingsManager.getInstance(project).notifyCodeStyleSettingsChanged()
// We must update the code style settings immediately because the code style modifier may have changed.
// To reflect the changes in the UI, we need to apply the code style settings.
applyCodeStyleSchemesFromContext(
DataManager.getInstance().getDataContext(codeStyleModifierCheckBox)
)
}
}
}