diff --git a/platform/core-api/src/com/intellij/openapi/util/NlsUI.java b/platform/core-api/src/com/intellij/openapi/util/NlsUI.java index 672e45a50aee..84a49bee2c7c 100644 --- a/platform/core-api/src/com/intellij/openapi/util/NlsUI.java +++ b/platform/core-api/src/com/intellij/openapi/util/NlsUI.java @@ -28,12 +28,30 @@ public class NlsUI { public @interface Checkbox { } + @NlsContext(prefix = "combobox.item") + @Nls(capitalization = Nls.Capitalization.Title) + @Target(ElementType.TYPE_USE) + public @interface ComboboxItem { + } + @NlsContext(prefix = "checkbox.tooltip") @Nls(capitalization = Nls.Capitalization.Sentence) @Target(ElementType.TYPE_USE) public @interface CheckboxTooltip { } + @NlsContext(prefix = "tooltip.help") + @Nls(capitalization = Nls.Capitalization.Sentence) + @Target(ElementType.TYPE_USE) + public @interface Tooltip { + } + + @NlsContext(prefix = "comment.panel") + @Nls(capitalization = Nls.Capitalization.Sentence) + @Target(ElementType.TYPE_USE) + public @interface CommentPanel { + } + @NlsContext(prefix = "titled.separator") @Nls(capitalization = Nls.Capitalization.Title) @Target(ElementType.TYPE_USE) @@ -73,6 +91,12 @@ public class NlsUI { public @interface TextPane { } + @NlsContext(prefix = "text.area") + @Nls(capitalization = Nls.Capitalization.Sentence) + @Target(ElementType.TYPE_USE) + public @interface TextArea { + } + @NlsContext(prefix = "list.item") @Nls(capitalization = Nls.Capitalization.Sentence) @Target(ElementType.TYPE_USE) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/messages/MessageDialog.java b/platform/platform-api/src/com/intellij/openapi/ui/messages/MessageDialog.java index d6adcf745cc8..82f55937d5c4 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/messages/MessageDialog.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/messages/MessageDialog.java @@ -11,6 +11,7 @@ import com.intellij.openapi.wm.IdeFrame; import com.intellij.openapi.wm.WindowManager; import com.intellij.ui.mac.foundation.MacUtil; import com.intellij.util.Alarm; +import com.intellij.util.nls.NlsContexts; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; @@ -32,8 +33,8 @@ public class MessageDialog extends DialogWrapper { private MessagesBorderLayout myLayout; public MessageDialog(@Nullable Project project, - String message, - @Nls(capitalization = Nls.Capitalization.Title) String title, + @Nls @NlsContexts.DialogMessage String message, + @Nls @NlsContexts.DialogTitle String title, String @NotNull [] options, int defaultOptionIndex, @Nullable Icon icon, @@ -43,21 +44,21 @@ public class MessageDialog extends DialogWrapper { public MessageDialog(@Nullable Project project, - @Nullable Component parentComponent, - String message, - @Nls(capitalization = Nls.Capitalization.Title) String title, - String @NotNull [] options, - int defaultOptionIndex, - int focusedOptionIndex, - @Nullable Icon icon, - @Nullable DoNotAskOption doNotAskOption, - boolean canBeParent) { + @Nullable Component parentComponent, + @Nls @NlsContexts.DialogMessage String message, + @Nls @NlsContexts.DialogTitle String title, + String @NotNull [] options, + int defaultOptionIndex, + int focusedOptionIndex, + @Nullable Icon icon, + @Nullable DoNotAskOption doNotAskOption, + boolean canBeParent) { super(project, parentComponent, canBeParent, IdeModalityType.IDE); _init(title, message, options, defaultOptionIndex, focusedOptionIndex, icon, doNotAskOption); } - public MessageDialog(String message, - @Nls(capitalization = Nls.Capitalization.Title) String title, + public MessageDialog(@Nls @NlsContexts.DialogMessage String message, + @Nls @NlsContexts.DialogTitle String title, String @NotNull [] options, int defaultOptionIndex, @Nullable Icon icon) { @@ -76,8 +77,8 @@ public class MessageDialog extends DialogWrapper { super(project, canBeParent); } - protected void _init(@Nls(capitalization = Nls.Capitalization.Title) String title, - String message, + protected void _init(@Nls @NlsContexts.DialogTitle String title, + @Nls @NlsContexts.DialogMessage String message, String @NotNull [] options, int defaultOptionIndex, int focusedOptionIndex, diff --git a/platform/platform-api/src/com/intellij/openapi/ui/messages/MessagesService.java b/platform/platform-api/src/com/intellij/openapi/ui/messages/MessagesService.java index 0df0b6913a3e..2cdef2000e75 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/messages/MessagesService.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/messages/MessagesService.java @@ -6,10 +6,12 @@ import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.InputValidator; +import com.intellij.openapi.util.NlsUI; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.util.Function; import com.intellij.util.PairFunction; +import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,6 +19,8 @@ import javax.swing.*; import java.awt.*; import java.util.List; +import static com.intellij.util.nls.NlsContexts.*; + /** * Allows to replace the implementation of showing messages. If you, as a plugin developer, need to show * messages, please use the {@link com.intellij.openapi.ui.Messages} class. @@ -24,8 +28,8 @@ import java.util.List; public interface MessagesService { int showMessageDialog(@Nullable Project project, @Nullable Component parentComponent, - String message, - String title, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, String @NotNull [] options, int defaultOptionIndex, int focusedOptionIndex, @@ -34,61 +38,79 @@ public interface MessagesService { boolean alwaysUseIdeaUI); int showMoreInfoMessageDialog(Project project, - String message, - String title, - String moreInfo, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, + @Nls @NlsUI.TextArea String moreInfo, String[] options, int defaultOptionIndex, int focusedOptionIndex, Icon icon); - int showTwoStepConfirmationDialog(String message, - String title, + int showTwoStepConfirmationDialog(@Nls @DialogMessage String message, + @Nls @DialogTitle String title, String[] options, - String checkboxText, + @Nls @NlsUI.Checkbox String checkboxText, boolean checked, int defaultOptionIndex, int focusedOptionIndex, Icon icon, PairFunction exitFunc); - String showPasswordDialog(Project project, String message, String title, Icon icon, InputValidator validator); + String showPasswordDialog(Project project, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, + Icon icon, + InputValidator validator); - char @Nullable [] showPasswordDialog(@NotNull Component parentComponent, String message, String title, Icon icon, @Nullable InputValidator validator); + char @Nullable [] showPasswordDialog(@NotNull Component parentComponent, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, + Icon icon, + @Nullable InputValidator validator); String showInputDialog(@Nullable Project project, @Nullable Component parentComponent, - String message, - String title, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, @Nullable Icon icon, - @Nullable String initialValue, + @Nullable @Nls @InputDialogInitialValue String initialValue, @Nullable InputValidator validator, @Nullable TextRange selection, - @Nullable String comment); + @Nullable @Nls @DialogComment String comment); - String showMultilineInputDialog(Project project, String message, String title, String initialValue, Icon icon, @Nullable InputValidator validator); + String showMultilineInputDialog(Project project, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, + @Nls @InputDialogInitialValue String initialValue, + Icon icon, + @Nullable InputValidator validator); - Pair showInputDialogWithCheckBox(String message, - String title, - String checkboxText, + Pair showInputDialogWithCheckBox(@Nls @DialogMessage String message, + @Nls @DialogTitle String title, + @Nls @NlsUI.Checkbox String checkboxText, boolean checked, boolean checkboxEnabled, Icon icon, - String initialValue, + @Nls @InputDialogInitialValue String initialValue, InputValidator validator); - String showEditableChooseDialog(String message, String title, Icon icon, String[] values, String initialValue, InputValidator validator); + String showEditableChooseDialog(@Nls @DialogMessage String message, + @Nls @DialogTitle String title, + Icon icon, + String[] values, + @Nls @InputDialogInitialValue String initialValue, + InputValidator validator); int showChooseDialog(@Nullable Project project, @Nullable Component parentComponent, - String message, - String title, + @Nls @DialogMessage String message, + @Nls @DialogTitle String title, String[] values, - String initialValue, + @Nls @InputDialogInitialValue String initialValue, @Nullable Icon icon); void showTextAreaDialog(JTextField textField, - String title, + @Nls @DialogTitle String title, String dimensionServiceKey, Function> parser, Function, String> lineJoiner); diff --git a/platform/platform-api/src/com/intellij/openapi/ui/messages/TwoStepConfirmationDialog.java b/platform/platform-api/src/com/intellij/openapi/ui/messages/TwoStepConfirmationDialog.java index d9b2dd45ef61..077109f8078a 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/messages/TwoStepConfirmationDialog.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/messages/TwoStepConfirmationDialog.java @@ -1,7 +1,9 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.ui.messages; +import com.intellij.openapi.util.NlsUI; import com.intellij.util.PairFunction; +import com.intellij.util.nls.NlsContexts; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,10 +17,10 @@ public class TwoStepConfirmationDialog extends MessageDialog { private final boolean myChecked; private final PairFunction myExitFunc; - public TwoStepConfirmationDialog(String message, - @Nls(capitalization = Nls.Capitalization.Title) String title, + public TwoStepConfirmationDialog(@Nls @NlsContexts.DialogMessage String message, + @Nls @NlsContexts.DialogTitle String title, String @NotNull [] options, - String checkboxText, + @Nls @NlsUI.Checkbox String checkboxText, boolean checked, final int defaultOptionIndexed, final int focusedOptionIndex, diff --git a/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java index 9d6991a635bc..a82b88cce04d 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/panel/ComponentPanelBuilder.java @@ -5,6 +5,7 @@ import com.intellij.icons.AllIcons; import com.intellij.openapi.ui.ComponentValidator; import com.intellij.openapi.ui.ComponentWithBrowseButton; import com.intellij.openapi.ui.LabeledComponent; +import com.intellij.openapi.util.NlsUI; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.BrowserHyperlinkListener; @@ -19,6 +20,7 @@ import com.intellij.util.ui.JBEmptyBorder; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UI; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,7 +84,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { * @param labelText text for the label. * @return this */ - public ComponentPanelBuilder withLabel(@NotNull String labelText) { + public ComponentPanelBuilder withLabel(@NotNull @Nls @NlsUI.Label String labelText) { myLabelText = labelText; return this; } @@ -107,7 +109,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { * @param comment help context styled text written below the owner component. * @return this */ - public ComponentPanelBuilder withComment(@NotNull String comment) { + public ComponentPanelBuilder withComment(@NotNull @Nls @NlsUI.CommentPanel String comment) { myCommentText = comment; valid = StringUtil.isEmpty(comment) || StringUtil.isEmpty(myHTDescription); return this; @@ -156,7 +158,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { * @param description help tooltip description. * @return this */ - public ComponentPanelBuilder withTooltip(@NotNull String description) { + public ComponentPanelBuilder withTooltip(@NotNull @Nls @NlsUI.Tooltip String description) { myHTDescription = description; valid = StringUtil.isEmpty(myCommentText) || StringUtil.isEmpty(description); return this; @@ -171,7 +173,7 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { * * @return this */ - public ComponentPanelBuilder withTooltipLink(@NotNull String linkText, @NotNull Runnable action) { + public ComponentPanelBuilder withTooltipLink(@NotNull @Nls @NlsUI.LinkLabel String linkText, @NotNull Runnable action) { myHTLinkText = linkText; myHTAction = action; return this; @@ -261,17 +263,19 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { } @NotNull - public static JLabel createCommentComponent(@Nullable String commentText, boolean isCommentBelow) { + public static JLabel createCommentComponent(@Nullable @Nls @NlsUI.CommentPanel String commentText, boolean isCommentBelow) { return createCommentComponent(commentText, isCommentBelow, 70); } @NotNull - public static JLabel createCommentComponent(@Nullable String commentText, boolean isCommentBelow, int maxLineLength) { + public static JLabel createCommentComponent(@Nullable @Nls @NlsUI.CommentPanel String commentText, boolean isCommentBelow, int maxLineLength) { return createCommentComponent(() -> new JBLabel(""), commentText, isCommentBelow, maxLineLength); } - private static JLabel createCommentComponent(@NotNull Supplier labelSupplier, @Nullable String commentText, - boolean isCommentBelow, int maxLineLength) { + private static JLabel createCommentComponent(@NotNull Supplier labelSupplier, + @Nullable @Nls @NlsUI.CommentPanel String commentText, + boolean isCommentBelow, + int maxLineLength) { // todo why our JBLabel cannot render html if render panel without frame (test only) boolean isCopyable = SystemProperties.getBooleanProperty("idea.ui.comment.copyable", true); JLabel component = labelSupplier.get().setCopyable(isCopyable).setAllowAutoWrapping(true); @@ -290,14 +294,17 @@ public class ComponentPanelBuilder implements GridBagPanelBuilder { return component; } - public static JLabel createNonWrappingCommentComponent(@NotNull String commentText) { + public static JLabel createNonWrappingCommentComponent(@NotNull @Nls @NlsUI.CommentPanel String commentText) { JBLabel component = new JBLabel(commentText); component.setForeground(UIUtil.getContextHelpForeground()); setCommentFont(component); return component; } - private static void setCommentText(@NotNull JLabel component, @Nullable String commentText, boolean isCommentBelow, int maxLineLength) { + private static void setCommentText(@NotNull JLabel component, + @Nullable @Nls @NlsUI.CommentPanel String commentText, + boolean isCommentBelow, + int maxLineLength) { if (commentText != null) { String css = "