diff --git a/java/compiler/impl/src/com/intellij/compiler/options/CompilerConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/CompilerConfigurable.java index 12bdcbee83ef..fa41e14f7ec6 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/CompilerConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/CompilerConfigurable.java @@ -1,16 +1,25 @@ -// 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.compiler.options; +import com.intellij.compiler.CompilerWorkspaceConfiguration; +import com.intellij.ide.actionsOnSave.*; import com.intellij.openapi.compiler.JavaCompilerBundle; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.project.Project; +import com.intellij.ui.components.ActionLink; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import java.util.Collection; +import java.util.Collections; +import java.util.List; public class CompilerConfigurable implements SearchableConfigurable.Parent, Configurable.NoScroll { + private static final String CONFIGURABLE_ID = "project.propCompiler"; + private final CompilerUIConfigurable myCompilerUIConfigurable; public CompilerConfigurable(Project project) { @@ -30,7 +39,7 @@ public class CompilerConfigurable implements SearchableConfigurable.Parent, Conf @Override @NotNull public String getId() { - return getHelpTopic(); + return CONFIGURABLE_ID; } @Override @@ -67,4 +76,62 @@ public class CompilerConfigurable implements SearchableConfigurable.Parent, Conf public Configurable @NotNull [] getConfigurables() { return new Configurable[0]; } + + + public static class BuildOnSaveInfoProvider extends ActionOnSaveInfoProvider { + @Override + protected @NotNull Collection getActionOnSaveInfos(@NotNull Project project) { + for (CompilerOptionsFilter filter : CompilerOptionsFilter.EP_NAME.getExtensionList()) { + if (!filter.isAvailable(CompilerOptionsFilter.Setting.AUTO_MAKE, project)) return Collections.emptyList(); + } + + return List.of(new BuildOnSaveInfo(project)); + } + } + + + private static class BuildOnSaveInfo extends ActionOnSaveBackedByOwnConfigurable { + private final @NotNull Project myProject; + + private BuildOnSaveInfo(@NotNull Project project) { + super(CONFIGURABLE_ID, CompilerConfigurable.class); + myProject = project; + } + + @Override + public @NotNull String getActionOnSaveName() { + return JavaCompilerBundle.message("settings.actions.on.save.page.build.project.on.save.checkbox"); + } + + @Override + protected @Nullable ActionOnSaveComment getCommentAccordingToStoredState() { + return ActionOnSaveComment.info(JavaCompilerBundle.message("settings.actions.on.save.page.build.project.on.save.checkbox.comment")); + } + + @Override + protected @Nullable ActionOnSaveComment getCommentAccordingToUiState(@NotNull CompilerConfigurable configurable) { + return ActionOnSaveComment.info(JavaCompilerBundle.message("settings.actions.on.save.page.build.project.on.save.checkbox.comment")); + } + + @Override + protected boolean isActionOnSaveEnabledAccordingToStoredState() { + return CompilerWorkspaceConfiguration.getInstance(myProject).MAKE_PROJECT_ON_SAVE; + } + + @Override + protected boolean isActionOnSaveEnabledAccordingToUiState(@NotNull CompilerConfigurable configurable) { + return configurable.myCompilerUIConfigurable.getBuildOnSaveCheckBox().isSelected(); + } + + @Override + protected void setActionOnSaveEnabled(@NotNull CompilerConfigurable configurable, boolean enabled) { + configurable.myCompilerUIConfigurable.getBuildOnSaveCheckBox().setSelected(enabled); + } + + @Override + public @NotNull List getActionLinks() { + String linkText = JavaCompilerBundle.message("settings.actions.on.save.page.compiler.settings.link"); + return List.of(ActionsOnSaveConfigurable.createGoToPageInSettingsLink(linkText, CONFIGURABLE_ID)); + } + } } diff --git a/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java b/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java index a5f519571112..6ab68e510ac3 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/CompilerUIConfigurable.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.compiler.options; import com.intellij.codeInsight.NullableNotNullDialog; @@ -336,6 +336,10 @@ public class CompilerUIConfigurable implements SearchableConfigurable, Configura return myPanel; } + JCheckBox getBuildOnSaveCheckBox() { + return myCbEnableAutomake; + } + private void createUIComponents() { myResourcePatternsField = new RawCommandLineEditor(ParametersListUtil.COLON_LINE_PARSER, ParametersListUtil.COLON_LINE_JOINER); myResourcePatternsField.setDialogCaption("Resource patterns"); diff --git a/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties b/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties index 0b9d59977b3b..6345d7badb17 100644 --- a/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties +++ b/java/compiler/openapi/resources/messages/JavaCompilerBundle.properties @@ -124,6 +124,9 @@ configurable.CompilerUIConfigurable.display.name=General configurable.AnnotationProcessorsConfigurable.display.name=Annotation Processors settings.configure.annotations=&Configure annotations... settings.build.project.automatically=Build project automatically +settings.actions.on.save.page.build.project.on.save.checkbox=Build project +settings.actions.on.save.page.build.project.on.save.checkbox.comment=Build not auto-triggered during run/debug session +settings.actions.on.save.page.compiler.settings.link=Compiler settings... settings.compile.independent.modules.in.parallel=Compile independent modules in parallel settings.rebuild.module.on.dependency.change=Rebuild module on dependency change settings.build.process.heap.size=Shared build process heap size (Mbytes): diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml index dda6f71ee971..297679338b6c 100644 --- a/java/java-impl/src/META-INF/JavaPlugin.xml +++ b/java/java-impl/src/META-INF/JavaPlugin.xml @@ -508,6 +508,10 @@ key="rmi.compiler.description" bundle="messages.JavaCompilerBundle"/> + +