mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Show before commit options in project settings (IDEA-178045)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<Boolean>) : RefreshableOnComponent {
|
||||
private val setter: Consumer<Boolean>) : 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()
|
||||
}
|
||||
+3
-3
@@ -451,9 +451,9 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<CheckinHandler> createCheckinHandlers(@NotNull Project project,
|
||||
@NotNull CheckinProjectPanel checkinPanel,
|
||||
@NotNull CommitContext commitContext) {
|
||||
public static List<CheckinHandler> createCheckinHandlers(@NotNull Project project,
|
||||
@NotNull CheckinProjectPanel checkinPanel,
|
||||
@NotNull CommitContext commitContext) {
|
||||
List<CheckinHandler> handlers = new ArrayList<>();
|
||||
for (BaseCheckinHandlerFactory factory : getCheckInFactories(project)) {
|
||||
CheckinHandler handler = factory.createHandler(checkinPanel, commitContext);
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.openapi.vcs.configurable.CommitDialogSettingsPanel">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -78,9 +78,15 @@
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<component id="d6650" class="com.intellij.openapi.vcs.configurable.CommitOptionsConfigurable" binding="myCommitOptions" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<vspacer id="20c64">
|
||||
<constraints>
|
||||
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
</children>
|
||||
|
||||
+7
-16
@@ -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<VcsConfiguratio
|
||||
private JBCheckBox myShowUnversionedFiles;
|
||||
private JPanel myMainPanel;
|
||||
private CommitMessageInspectionsPanel myInspectionsPanel;
|
||||
private CommitOptionsConfigurable myCommitOptions;
|
||||
private JBCheckBox myClearInitialCommitMessage;
|
||||
private JBCheckBox myForceNonEmptyCommitMessage;
|
||||
private JBCheckBox myMoveUncommittedToAnotherChangeList;
|
||||
@@ -62,6 +49,7 @@ public class CommitDialogSettingsPanel implements ConfigurableUi<VcsConfiguratio
|
||||
myMoveUncommittedToAnotherChangeList.setSelected(settings.OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT);
|
||||
myMoveToFailedCommitChangeListModel.setSelectedItem(settings.MOVE_TO_FAILED_COMMIT_CHANGELIST);
|
||||
myInspectionsPanel.reset();
|
||||
myCommitOptions.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,7 +59,7 @@ public class CommitDialogSettingsPanel implements ConfigurableUi<VcsConfiguratio
|
||||
settings.FORCE_NON_EMPTY_COMMENT != myForceNonEmptyCommitMessage.isSelected() ||
|
||||
settings.OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT != myMoveUncommittedToAnotherChangeList.isSelected() ||
|
||||
settings.MOVE_TO_FAILED_COMMIT_CHANGELIST != myMoveToFailedCommitChangeListModel.getSelectedItem() ||
|
||||
myInspectionsPanel.isModified();
|
||||
myInspectionsPanel.isModified() || myCommitOptions.isModified();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +70,7 @@ public class CommitDialogSettingsPanel implements ConfigurableUi<VcsConfiguratio
|
||||
settings.OFFER_MOVE_TO_ANOTHER_CHANGELIST_ON_PARTIAL_COMMIT = myMoveUncommittedToAnotherChangeList.isSelected();
|
||||
settings.MOVE_TO_FAILED_COMMIT_CHANGELIST = myMoveToFailedCommitChangeListModel.getSelectedItem();
|
||||
myInspectionsPanel.apply();
|
||||
myCommitOptions.apply();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -92,11 +81,13 @@ public class CommitDialogSettingsPanel implements ConfigurableUi<VcsConfiguratio
|
||||
|
||||
private void createUIComponents() {
|
||||
myInspectionsPanel = new CommitMessageInspectionsPanel(myProject);
|
||||
myCommitOptions = new CommitOptionsConfigurable(myProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Disposer.dispose(myInspectionsPanel);
|
||||
Disposer.dispose(myCommitOptions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
// 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
|
||||
import com.intellij.openapi.options.UnnamedConfigurable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vcs.CheckinProjectPanel
|
||||
import com.intellij.openapi.vcs.VcsBundle.message
|
||||
import com.intellij.openapi.vcs.changes.Change
|
||||
import com.intellij.openapi.vcs.changes.CommitContext
|
||||
import com.intellij.openapi.vcs.changes.ui.CommitChangeListDialog.createCheckinHandlers
|
||||
import com.intellij.openapi.vcs.changes.ui.CommitOptionsPanel.Companion.verticalPanel
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.util.ui.UIUtil.removeMnemonic
|
||||
import java.awt.GridLayout
|
||||
import java.io.File
|
||||
|
||||
class CommitOptionsConfigurable(val project: Project) : JBPanel<CommitOptionsConfigurable>(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<VirtualFile>()
|
||||
override fun getVirtualFiles() = emptyList<VirtualFile>()
|
||||
override fun getSelectedChanges() = emptyList<Change>()
|
||||
override fun getFiles() = emptyList<File>()
|
||||
|
||||
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() {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user