diff --git a/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/RsExtractStructFieldsAction.kt b/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/RsExtractStructFieldsAction.kt index f5bb658462e..8de5e9caf35 100644 --- a/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/RsExtractStructFieldsAction.kt +++ b/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/RsExtractStructFieldsAction.kt @@ -42,7 +42,8 @@ class RsExtractStructFieldsAction : RsBaseEditorRefactoringAction() { project, struct, fields, - RsBundle.message("action.Rust.RsExtractStructFields.choose.fields.title") + RsBundle.message("action.Rust.RsExtractStructFields.choose.fields.title"), + allowEmptySelection = false ) ?: return if (chosenFields.isEmpty()) return diff --git a/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/ui.kt b/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/ui.kt index deffe8f52a5..e043954d4ac 100644 --- a/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/ui.kt +++ b/src/main/kotlin/org/rust/ide/refactoring/extractStructFields/ui.kt @@ -52,7 +52,7 @@ private class ExtractFieldsDialog(project: Project) : DialogWrapper(project, fal override fun doValidate(): ValidationInfo? { if (!isValidRustVariableIdentifier(input.text)) { - ValidationInfo(RsBundle.message("action.Rust.RsExtractStructFields.choose.name.dialog.invalid.name"), input) + return ValidationInfo(RsBundle.message("action.Rust.RsExtractStructFields.choose.name.dialog.invalid.name"), input) } return null } diff --git a/src/main/kotlin/org/rust/ide/refactoring/generate/BaseGenerateHandler.kt b/src/main/kotlin/org/rust/ide/refactoring/generate/BaseGenerateHandler.kt index 4dfe6fbf2f9..6d546ec4305 100644 --- a/src/main/kotlin/org/rust/ide/refactoring/generate/BaseGenerateHandler.kt +++ b/src/main/kotlin/org/rust/ide/refactoring/generate/BaseGenerateHandler.kt @@ -45,6 +45,8 @@ abstract class BaseGenerateHandler : LanguageCodeInsightActionHandler { override fun startInWriteAction() = false + open val allowEmptySelection: Boolean = false + private fun getContext(editor: Editor, file: PsiFile): Context? { val element = file.findElementAt(editor.caretModel.offset) ?: return null val struct = element.ancestorOrSelf() @@ -80,7 +82,8 @@ abstract class BaseGenerateHandler : LanguageCodeInsightActionHandler { context.struct.project, context.struct, context.fields, - dialogTitle + dialogTitle, + allowEmptySelection ) ?: return runWriteAction { performRefactoring(context.struct, context.implBlock, chosenFields, context.substitution, editor) diff --git a/src/main/kotlin/org/rust/ide/refactoring/generate/constructor/GenerateConstructorHandler.kt b/src/main/kotlin/org/rust/ide/refactoring/generate/constructor/GenerateConstructorHandler.kt index 5ce6c3ff7f2..4db2088b724 100644 --- a/src/main/kotlin/org/rust/ide/refactoring/generate/constructor/GenerateConstructorHandler.kt +++ b/src/main/kotlin/org/rust/ide/refactoring/generate/constructor/GenerateConstructorHandler.kt @@ -27,6 +27,8 @@ class GenerateConstructorAction : BaseGenerateAction() { class GenerateConstructorHandler : BaseGenerateHandler() { override val dialogTitle: String = "Select constructor parameters" + override val allowEmptySelection: Boolean = true + override fun isImplBlockValid(impl: RsImplItem): Boolean = super.isImplBlockValid(impl) && impl.isSuitableForConstructor diff --git a/src/main/kotlin/org/rust/ide/refactoring/generate/ui.kt b/src/main/kotlin/org/rust/ide/refactoring/generate/ui.kt index 8cdcffa8b72..a8d403d0f3c 100644 --- a/src/main/kotlin/org/rust/ide/refactoring/generate/ui.kt +++ b/src/main/kotlin/org/rust/ide/refactoring/generate/ui.kt @@ -22,12 +22,13 @@ fun showStructMemberChooserDialog( project: Project, structItem: RsStructItem, fields: List, - @Suppress("UnstableApiUsage") @DialogTitle title: String + @Suppress("UnstableApiUsage") @DialogTitle title: String, + allowEmptySelection: Boolean ): List? { val chooser = if (isUnitTestMode) { MOCK ?: error("You should set mock ui via `withMockStructMemberChooserUi`") } else { - DialogStructMemberChooserUi(title) + DialogStructMemberChooserUi(title, allowEmptySelection = allowEmptySelection) } val base = MemberChooserObjectBase(structItem.name, structItem.getIcon(0)) val arguments = fields.map { RsStructMemberChooserObject(base, it) } @@ -60,11 +61,15 @@ interface StructMemberChooserUi { } private class DialogStructMemberChooserUi( - @Suppress("UnstableApiUsage") @DialogTitle private val title: String + @Suppress("UnstableApiUsage") @DialogTitle private val title: String, + private val allowEmptySelection: Boolean ) : StructMemberChooserUi { - override fun selectMembers(project: Project, all: List): List? { + override fun selectMembers( + project: Project, + all: List + ): List? { val dialogTitle = title - val chooser = MemberChooser(all.toTypedArray(), true, true, project).apply { + val chooser = MemberChooser(all.toTypedArray(), allowEmptySelection, true, project).apply { title = dialogTitle selectElements(all.toTypedArray()) setCopyJavadocVisible(false) diff --git a/src/main/resources/messages/RsBundle.properties b/src/main/resources/messages/RsBundle.properties index 583b396cdd2..eb9c1cd78d6 100644 --- a/src/main/resources/messages/RsBundle.properties +++ b/src/main/resources/messages/RsBundle.properties @@ -47,7 +47,7 @@ action.Rust.ShareInPlayground.notification.title=Share in Rust Playground action.Rust.ShareInPlayground.progress.title=Posting code to Rust Playground action.Rust.ShareInPlayground.text=Share in Playground action.Rust.RsExtractStructFields.description=Extract selected struct fields into a separate struct -action.Rust.RsExtractStructFields.text=Extract Struct Fields +action.Rust.RsExtractStructFields.text=Extract Struct Fields... action.Rust.RsExtractStructFields.intention.text=Extract struct fields action.Rust.RsExtractStructFields.choose.fields.title=Choose Fields to Extract action.Rust.RsExtractStructFields.choose.name.dialog.title=Enter Name For the New Struct