[mod-command] Intention preview for string change

GitOrigin-RevId: c1026617c907a09043acb5aab30aab01a36b67cd
This commit is contained in:
Tagir Valeev
2023-11-14 11:01:11 +00:00
committed by intellij-monorepo-bot
parent 34479d8af2
commit 4143fe4c0a
2 changed files with 21 additions and 7 deletions
@@ -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:
@@ -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()))
));
}
}