diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/checkin/CheckinHandler.java b/platform/vcs-api/src/com/intellij/openapi/vcs/checkin/CheckinHandler.java index 9a3a6ea411b5..8aae09f6660e 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/checkin/CheckinHandler.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/checkin/CheckinHandler.java @@ -1,31 +1,21 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// 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 com.intellij.openapi.vcs.checkin; import com.intellij.openapi.Disposable; +import com.intellij.openapi.options.UnnamedConfigurable; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vcs.changes.CommitExecutor; import com.intellij.openapi.vcs.changes.LocalCommitExecutor; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.util.PairConsumer; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.List; +import static com.intellij.util.ObjectUtils.tryCast; + /** * A callback which can be used to extend the user interface of the Checkin Project/Checkin File * dialogs and to perform actions before commit, on successful commit and on failed commit. @@ -58,6 +48,12 @@ public abstract class CheckinHandler { return null; } + @ApiStatus.Experimental + @Nullable + public UnnamedConfigurable getBeforeCheckinSettings() { + return tryCast(getBeforeCheckinConfigurationPanel(), UnnamedConfigurable.class); + } + /** * Returns the panel which is inserted in the "After Check In" group box of the Checkin Project * or Checkin File dialogs. diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt index ed36af9953d4..4002520c9fc5 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt @@ -1,6 +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 com.intellij.openapi.vcs.changes.ui +import com.intellij.openapi.options.UnnamedConfigurable import com.intellij.openapi.vcs.CheckinProjectPanel import com.intellij.openapi.vcs.checkin.CheckinHandlerUtil import com.intellij.openapi.vcs.ui.RefreshableOnComponent @@ -12,7 +13,7 @@ open class BooleanCommitOption(panel: CheckinProjectPanel, text: String, disableWhenDumb: Boolean, private val getter: () -> Boolean, - private val setter: Consumer) : RefreshableOnComponent { + private val setter: Consumer) : RefreshableOnComponent, UnnamedConfigurable { protected val checkBox = NonFocusableCheckBox(text).also { if (disableWhenDumb) CheckinHandlerUtil.disableWhenDumb(panel.project, it, "Impossible until indices are up-to-date") } @@ -29,4 +30,12 @@ open class BooleanCommitOption(panel: CheckinProjectPanel, } override fun getComponent(): JComponent = checkBox + + override fun createComponent() = component + + override fun isModified() = checkBox.isSelected != getter() + + override fun apply() = saveState() + + override fun reset() = restoreState() } \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index 352dbfdaceb2..1cfb976e9948 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -451,9 +451,9 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } @NotNull - private static List createCheckinHandlers(@NotNull Project project, - @NotNull CheckinProjectPanel checkinPanel, - @NotNull CommitContext commitContext) { + public static List createCheckinHandlers(@NotNull Project project, + @NotNull CheckinProjectPanel checkinPanel, + @NotNull CommitContext commitContext) { List handlers = new ArrayList<>(); for (BaseCheckinHandlerFactory factory : getCheckInFactories(project)) { CheckinHandler handler = factory.createHandler(checkinPanel, commitContext); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt index 01016b9e5c37..8e0663aaaeed 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitOptionsPanel.kt @@ -116,10 +116,6 @@ class CommitOptionsPanel(private val myCommitPanel: CheckinProjectPanel, return false } - private fun verticalPanel(title: String) = JPanel(VerticalFlowLayout(0, 0)).apply { - border = createTitledBorder(title) - } - private fun addCheckinHandlerComponent(component: RefreshableOnComponent, container: JComponent) { container.add(component.component) myAdditionalComponents.add(component) @@ -127,4 +123,10 @@ class CommitOptionsPanel(private val myCommitPanel: CheckinProjectPanel, myCheckinChangeListSpecificComponents.add(component) } } + + companion object { + fun verticalPanel(title: String) = JPanel(VerticalFlowLayout(0, 0)).apply { + border = createTitledBorder(title) + } + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.form b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.form index 0b645965b285..cdad8af00b2f 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.form +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.form @@ -1,6 +1,6 @@
- + @@ -78,9 +78,15 @@ + + + + + + - + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.java index 45bcff178c47..c01b82bb716e 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/CommitDialogSettingsPanel.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// 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 com.intellij.openapi.vcs.configurable; import com.intellij.openapi.Disposable; @@ -36,6 +22,7 @@ public class CommitDialogSettingsPanel implements ConfigurableUi(GridLayout()), UnnamedConfigurable, Disposable { + private val checkinPanel = CheckinPanel(project) + private val commitContext = CommitContext() + private val checkinHandlers = createCheckinHandlers(project, checkinPanel, commitContext) + private val beforeSettings = checkinHandlers.mapNotNull { it.beforeCheckinSettings } + + init { + val actionName = removeMnemonic(checkinPanel.commitActionName) + add(verticalPanel(message("border.standard.checkin.options.group", actionName)).apply { + beforeSettings.mapNotNull { it.createComponent() }.forEach { add(it) } + }) + } + + override fun reset() = beforeSettings.forEach { it.reset() } + override fun isModified() = beforeSettings.any { it.isModified } + override fun apply() = beforeSettings.forEach { it.apply() } + override fun dispose() = beforeSettings.forEach { it.disposeUIResources() } + override fun createComponent() = this + + class CheckinPanel(private val project: Project) : CheckinProjectPanel { + override fun getComponent() = null + override fun getPreferredFocusedComponent() = null + + override fun getProject() = project + + override fun vcsIsAffected(name: String) = false + override fun hasDiffs() = false + override fun getRoots() = emptyList() + override fun getVirtualFiles() = emptyList() + override fun getSelectedChanges() = emptyList() + override fun getFiles() = emptyList() + + override fun getCommitActionName(): String = message("commit.dialog.default.commit.operation.name") + override fun setCommitMessage(currentDescription: String) {} + override fun getCommitMessage() = "" + + override fun refresh() {} + override fun saveState() {} + override fun restoreState() {} + } +} \ No newline at end of file