diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java index 0457fb874dde..5b446509ac13 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/views/HistoryDialog.java @@ -505,7 +505,6 @@ public abstract class HistoryDialog extends FrameW super(project, true); myPanel = centralPanel; init(); - initValidation(); } @Override @@ -517,10 +516,5 @@ public abstract class HistoryDialog extends FrameW public @Nullable JComponent getPreferredFocusedComponent() { return IdeFocusTraversalPolicy.getPreferredFocusedComponent(myPanel.getPanel()); } - - @Override - protected @Nullable ValidationInfo doValidate() { - return myPanel.validateFields(); - } } } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java index d96d2d41ba7f..9e7a529dc0e7 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/changes/CommitSession.java @@ -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 changes, @Nullable @NlsSafe String commitMessage) { diff --git a/platform/vcs-impl/api-dump.txt b/platform/vcs-impl/api-dump.txt index 05240c903d71..c4b6a0acf037 100644 --- a/platform/vcs-impl/api-dump.txt +++ b/platform/vcs-impl/api-dump.txt @@ -3358,23 +3358,6 @@ f:com.intellij.openapi.vcs.changes.patch.CreatePatchCommitExecutor$ShelfPatchBui - (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 -- (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 - ():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 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java index 6a194c7e207e..fa195911ff75 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java @@ -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 changes, @Nullable String commitMessage) { + public DialogPanel getAdditionalConfigurationUI(@NotNull Collection 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 diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.kt index 7a5f70605b0b..18aab4d92e78 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.kt +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.kt @@ -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 - 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 }