From 4143fe4c0a72770e50d343a8eb62c9d87ff5bb6c Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Mon, 13 Nov 2023 15:38:36 +0100 Subject: [PATCH] [mod-command] Intention preview for string change GitOrigin-RevId: c1026617c907a09043acb5aab30aab01a36b67cd --- .../messages/AnalysisBundle.properties | 1 + .../modcommand/ModCommandServiceImpl.java | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/platform/analysis-api/resources/messages/AnalysisBundle.properties b/platform/analysis-api/resources/messages/AnalysisBundle.properties index 1a170119a458..8efabdc83c9e 100644 --- a/platform/analysis-api/resources/messages/AnalysisBundle.properties +++ b/platform/analysis-api/resources/messages/AnalysisBundle.properties @@ -223,6 +223,7 @@ set.inspection.option.fix=Set inspection option set.option.description.uncheck=Uncheck option: set.option.description.check=Check option: set.option.description.input=Update numerical option: +set.option.description.string=Update string option: progress.title.submit.request=Submit progress.title.refresh=Refresh preview.cannot.perform.action=Cannot perform action: diff --git a/platform/analysis-impl/src/com/intellij/lang/impl/modcommand/ModCommandServiceImpl.java b/platform/analysis-impl/src/com/intellij/lang/impl/modcommand/ModCommandServiceImpl.java index b2134dd25d14..df7feaff0ea9 100644 --- a/platform/analysis-impl/src/com/intellij/lang/impl/modcommand/ModCommandServiceImpl.java +++ b/platform/analysis-impl/src/com/intellij/lang/impl/modcommand/ModCommandServiceImpl.java @@ -207,16 +207,18 @@ public class ModCommandServiceImpl implements ModCommandService { OptNumber optNumber = ObjectUtils.tryCast(control, OptNumber.class); if (optNumber == null) return HtmlChunk.empty(); LocMessage.PrefixSuffix prefixSuffix = optNumber.splitLabel().splitLabel(); - HtmlChunk.Element input = tag("input").attr("type", "text").attr("value", value) - .attr("size", value.toString().length() + 1).attr("readonly", "true"); - HtmlChunk info = tag("table").child(tag("tr").children( - tag("td").child(text(prefixSuffix.prefix())), - tag("td").child(input), - tag("td").child(text(prefixSuffix.suffix())) - )); + HtmlChunk info = getValueChunk(value, prefixSuffix); return new HtmlBuilder().append(AnalysisBundle.message("set.option.description.input")) .br().br().append(info).br().toFragment(); } + if (newValue instanceof String value) { + OptString optString = ObjectUtils.tryCast(control, OptString.class); + if (optString == null) return HtmlChunk.empty(); + LocMessage.PrefixSuffix prefixSuffix = optString.splitLabel().splitLabel(); + HtmlChunk info = getValueChunk(value, prefixSuffix); + return new HtmlBuilder().append(AnalysisBundle.message("set.option.description.string")) + .br().br().append(info).br().toFragment(); + } if (newValue instanceof List list) { OptStringList optList = ObjectUtils.tryCast(control, OptStringList.class); if (optList == null) return HtmlChunk.empty(); @@ -226,4 +228,15 @@ public class ModCommandServiceImpl implements ModCommandService { } throw new IllegalStateException("Value of type " + newValue.getClass() + " is not supported"); } + + @NotNull + private static HtmlChunk getValueChunk(Object value, LocMessage.PrefixSuffix prefixSuffix) { + HtmlChunk.Element input = tag("input").attr("type", "text").attr("value", String.valueOf(value)) + .attr("size", value.toString().length() + 1).attr("readonly", "true"); + return tag("table").child(tag("tr").children( + tag("td").child(text(prefixSuffix.prefix())), + tag("td").child(input), + tag("td").child(text(prefixSuffix.suffix())) + )); + } }