mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
IJPL-156808 patch: fix validation in "Create Patch" dialog
The UI DSL panels employ different validation and are not backward-compatible when used for DialogWrapper component: 'DialogWrapper.continuousValidation()' is disabled. Fix regression after 9bb5766a9b28a242a4660df9de3f8caf96e38bdf GitOrigin-RevId: 8b788c0eec6f18abd07599c0e698277eeed76342
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4feb9ddd29
commit
4ea2725b48
@@ -505,7 +505,6 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
|
||||
super(project, true);
|
||||
myPanel = centralPanel;
|
||||
init();
|
||||
initValidation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -517,10 +516,5 @@ public abstract class HistoryDialog<T extends HistoryDialogModel> extends FrameW
|
||||
public @Nullable JComponent getPreferredFocusedComponent() {
|
||||
return IdeFocusTraversalPolicy.getPreferredFocusedComponent(myPanel.getPanel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ValidationInfo doValidate() {
|
||||
return myPanel.validateFields();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public interface CommitSession {
|
||||
* Show dialog with additional options before running pre-commit checks.
|
||||
*
|
||||
* @see com.intellij.openapi.vcs.changes.ui.SessionDialog
|
||||
* @see com.intellij.openapi.ui.DialogPanel
|
||||
*/
|
||||
@Nullable
|
||||
default JComponent getAdditionalConfigurationUI(@NotNull Collection<? extends Change> changes, @Nullable @NlsSafe String commitMessage) {
|
||||
|
||||
@@ -3358,23 +3358,6 @@ f:com.intellij.openapi.vcs.changes.patch.CreatePatchCommitExecutor$ShelfPatchBui
|
||||
- <init>(com.intellij.openapi.project.Project,com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList,java.util.List):V
|
||||
- buildPatches(java.nio.file.Path,java.util.Collection,Z,Z):java.util.List
|
||||
- isReverseSupported():Z
|
||||
f:com.intellij.openapi.vcs.changes.patch.CreatePatchConfigurationPanel
|
||||
- <init>(com.intellij.openapi.project.Project):V
|
||||
- f:getBaseDirName():java.lang.String
|
||||
- f:getEncoding():java.nio.charset.Charset
|
||||
- f:getFileName():java.lang.String
|
||||
- f:getPanel():javax.swing.JComponent
|
||||
- f:getProject():com.intellij.openapi.project.Project
|
||||
- f:isOkToExecute():Z
|
||||
- f:isReversePatch():Z
|
||||
- f:isToClipboard():Z
|
||||
- f:selectBasePath(java.lang.String):V
|
||||
- f:setCommonParentPath(java.io.File):V
|
||||
- f:setFileName(java.nio.file.Path):V
|
||||
- f:setReverseEnabledAndVisible(Z):V
|
||||
- f:setReversePatch(Z):V
|
||||
- f:setToClipboard(Z):V
|
||||
- f:validateFields():com.intellij.openapi.ui.ValidationInfo
|
||||
f:com.intellij.openapi.vcs.changes.patch.DefaultPatchBaseVersionProvider
|
||||
- <init>():V
|
||||
- s:getBaseVersionContent(com.intellij.openapi.project.Project,java.lang.String,com.intellij.openapi.vfs.VirtualFile,com.intellij.openapi.vcs.FilePath,com.intellij.util.Processor):V
|
||||
|
||||
@@ -13,10 +13,10 @@ import com.intellij.openapi.diff.impl.patch.FilePatch;
|
||||
import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder;
|
||||
import com.intellij.openapi.diff.impl.patch.TextFilePatch;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogPanel;
|
||||
import com.intellij.openapi.ui.DoNotAskOption;
|
||||
import com.intellij.openapi.ui.MessageDialogBuilder;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.ValidationInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.SystemIndependent;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -103,7 +102,7 @@ public final class CreatePatchCommitExecutor extends LocalCommitExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getAdditionalConfigurationUI(@NotNull Collection<? extends Change> changes, @Nullable String commitMessage) {
|
||||
public DialogPanel getAdditionalConfigurationUI(@NotNull Collection<? extends Change> changes, @Nullable String commitMessage) {
|
||||
String patchPath = StringUtil.nullize(PropertiesComponent.getInstance(myProject).getValue(VCS_PATCH_PATH_KEY));
|
||||
if (patchPath == null) {
|
||||
patchPath = VcsApplicationSettings.getInstance().PATCH_STORAGE_LOCATION;
|
||||
@@ -119,7 +118,7 @@ public final class CreatePatchCommitExecutor extends LocalCommitExecutor {
|
||||
myPanel.setReversePatch(false);
|
||||
myPanel.setReverseEnabledAndVisible(myPatchBuilder.isReverseSupported());
|
||||
|
||||
JComponent panel = myPanel.getPanel();
|
||||
DialogPanel panel = myPanel.getPanel();
|
||||
panel.putClientProperty(SessionDialog.VCS_CONFIGURATION_UI_TITLE, VcsBundle.message("create.patch.settings.dialog.title"));
|
||||
return panel;
|
||||
}
|
||||
@@ -188,12 +187,6 @@ public final class CreatePatchCommitExecutor extends LocalCommitExecutor {
|
||||
}, null, project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ValidationInfo validateFields() {
|
||||
return myPanel.validateFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getHelpId() {
|
||||
return "reference.dialogs.PatchFileSettings"; //NON-NLS
|
||||
|
||||
@@ -12,14 +12,17 @@ import com.intellij.openapi.vcs.VcsBundle.message
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.openapi.vfs.encoding.EncodingProjectManager
|
||||
import com.intellij.project.stateStore
|
||||
import com.intellij.ui.JBColor
|
||||
import com.intellij.ui.dsl.builder.*
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import javax.swing.*
|
||||
import javax.swing.DefaultComboBoxModel
|
||||
import javax.swing.JCheckBox
|
||||
import javax.swing.JRadioButton
|
||||
|
||||
@ApiStatus.Internal
|
||||
class CreatePatchConfigurationPanel(val project: Project) {
|
||||
private val panel: DialogPanel
|
||||
|
||||
@@ -29,7 +32,6 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
private lateinit var toClipboardRadioButton: JRadioButton
|
||||
private lateinit var reverseCheckBox: JCheckBox
|
||||
private lateinit var encodingComboBox: ComboBox<Charset>
|
||||
private lateinit var warningLabel: JLabel
|
||||
|
||||
private var commonParentDir: File? = null
|
||||
|
||||
@@ -69,6 +71,7 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
.columns(COLUMNS_LARGE)
|
||||
.align(AlignX.FILL)
|
||||
.enabledIf(toFileButton.selected)
|
||||
.validationOnInput { validateFileName() }
|
||||
}.layout(RowLayout.LABEL_ALIGNED)
|
||||
row {
|
||||
toClipboardRadioButton = radioButton(message("create.patch.to.clipboard"))
|
||||
@@ -80,6 +83,7 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
cell(basePathField)
|
||||
.columns(COLUMNS_LARGE)
|
||||
.align(AlignX.FILL)
|
||||
.validationOnInput { validateBaseDirPath() }
|
||||
}.topGap(TopGap.SMALL)
|
||||
row {
|
||||
reverseCheckBox = checkBox(message("create.patch.reverse.checkbox")).component
|
||||
@@ -88,13 +92,6 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
encodingComboBox = comboBox(DefaultComboBoxModel(CharsetToolkit.getAvailableCharsets())).component
|
||||
encodingComboBox.selectedItem = EncodingProjectManager.getInstance(project).defaultCharset
|
||||
}
|
||||
row {
|
||||
warningLabel = label("")
|
||||
.applyToComponent {
|
||||
foreground = JBColor.RED
|
||||
isVisible = false
|
||||
}.component
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +112,7 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
fun getPanel(): JComponent {
|
||||
fun getPanel(): DialogPanel {
|
||||
return panel
|
||||
}
|
||||
|
||||
@@ -153,27 +150,21 @@ class CreatePatchConfigurationPanel(val project: Project) {
|
||||
}
|
||||
|
||||
fun isOkToExecute(): Boolean {
|
||||
return validateFields() == null
|
||||
}
|
||||
|
||||
fun validateFields(): ValidationInfo? {
|
||||
warnIfFileExists()
|
||||
|
||||
return validateFileName() ?: validateBaseDirPath()
|
||||
}
|
||||
|
||||
private fun warnIfFileExists() {
|
||||
val fileName = getFileName()
|
||||
warningLabel.text = if (File(fileName).exists()) IdeBundle.message("error.file.with.name.already.exists", fileName) else ""
|
||||
warningLabel.isVisible = warningLabel.text.isNotBlank()
|
||||
return panel.validateAll().any { !it.warning }
|
||||
}
|
||||
|
||||
private fun validateFileName(): ValidationInfo? {
|
||||
val validateNameError = PatchNameChecker.validateName(getFileName())
|
||||
val fileName = getFileName()
|
||||
|
||||
val validateNameError = PatchNameChecker.validateName(fileName)
|
||||
if (validateNameError != null) {
|
||||
return ValidationInfo(validateNameError, fileNameField)
|
||||
}
|
||||
|
||||
if (File(fileName).exists()) {
|
||||
return ValidationInfo(IdeBundle.message("error.file.with.name.already.exists", fileName)).asWarning()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user