Skip to content

Commit

Permalink
i18n for plugins configurable, initial
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 078433dbd1ade70a92c5e937cbe7f2638947e297
  • Loading branch information
ignatov authored and intellij-monorepo-bot committed Jan 27, 2020
1 parent ddc2d2d commit ebb07b0
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 41 deletions.
Expand Up @@ -2,6 +2,7 @@
package com.intellij.ui.components.fields;

import com.intellij.ui.scale.JBUIScale;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand Down Expand Up @@ -61,7 +62,7 @@ static Extension create(@NotNull Icon icon, String tooltip, Runnable action) {
return create(icon, icon, tooltip, action);
}

static Extension create(@NotNull Icon defaultIcon, @NotNull Icon hoveredIcon, String tooltip, Runnable action) {
static Extension create(@NotNull Icon defaultIcon, @NotNull Icon hoveredIcon, @Nls String tooltip, Runnable action) {
return new Extension() {
@Override
public Icon getIcon(boolean hovered) {
Expand Down
Expand Up @@ -12,6 +12,7 @@
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.accessibility.ScreenReader;
import gnu.trove.THashSet;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -47,16 +48,16 @@ public LinkLabel() {
this("", AllIcons.Ide.Link);
}

public LinkLabel(String text, @Nullable Icon icon) {
public LinkLabel(@Nls String text, @Nullable Icon icon) {
this(text, icon, null, null, null);
}

public LinkLabel(String text, @Nullable Icon icon, @Nullable LinkListener<T> aListener) {
public LinkLabel(@Nls String text, @Nullable Icon icon, @Nullable LinkListener<T> aListener) {
this(text, icon, aListener, null, null);
}

@NotNull
public static LinkLabel<?> create(@Nullable String text, @Nullable Runnable action) {
public static LinkLabel<?> create(@Nullable @Nls String text, @Nullable Runnable action) {
return new LinkLabel<>(text, null, action == null ? null : new LinkListener<Object>() {
@Override
public void linkSelected(LinkLabel source, Object linkData) {
Expand All @@ -65,11 +66,11 @@ public void linkSelected(LinkLabel source, Object linkData) {
}, null, null);
}

public LinkLabel(String text, @Nullable Icon icon, @Nullable LinkListener<T> aListener, @Nullable T aLinkData) {
public LinkLabel(@Nls String text, @Nullable Icon icon, @Nullable LinkListener<T> aListener, @Nullable T aLinkData) {
this(text, icon, aListener, aLinkData, null);
}

public LinkLabel(String text,
public LinkLabel(@Nls String text,
@Nullable Icon icon,
@Nullable LinkListener<T> aListener,
@Nullable T aLinkData,
Expand Down
Expand Up @@ -10,6 +10,7 @@
import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -178,11 +179,11 @@ public String getText() {
return myText;
}

public StatusText setText(String text) {
public StatusText setText(@Nls String text) {
return setText(text, DEFAULT_ATTRIBUTES);
}

public StatusText setText(String text, SimpleTextAttributes attrs) {
public StatusText setText(@Nls String text, SimpleTextAttributes attrs) {
return clear().appendText(text, attrs);
}

Expand Down Expand Up @@ -230,7 +231,7 @@ public void setIsVerticalFlow(boolean isVerticalFlow) {
}

@NotNull
public StatusText appendSecondaryText(@NotNull String text, @NotNull SimpleTextAttributes attrs, @Nullable ActionListener listener) {
public StatusText appendSecondaryText(@NotNull @Nls String text, @NotNull SimpleTextAttributes attrs, @Nullable ActionListener listener) {
mySecondaryComponent.append(text, attrs);
mySecondaryListeners.add(listener);
if (listener != null) {
Expand Down
Expand Up @@ -49,6 +49,7 @@
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.net.HttpConfigurable;
import com.intellij.util.ui.*;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -250,7 +251,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
return actions;
}

private static void showRightBottomPopup(@NotNull Component component, @NotNull String title, @NotNull ActionGroup group) {
private static void showRightBottomPopup(@NotNull Component component, @NotNull @Nls String title, @NotNull ActionGroup group) {
DefaultActionGroup actions = new GroupByActionGroup();
actions.addSeparator(" " + title);
actions.addAll(group);
Expand Down Expand Up @@ -367,10 +368,10 @@ protected JComponent createPluginsPanel(@NotNull Consumer<? super PluginsGroupCo
Map<String, List<IdeaPluginDescriptor>> customRepositoriesMap = pair.second;

try {
addGroup(groups, allRepositoriesMap, "Featured", "is_featured_search=true", "/sortBy:featured");
addGroup(groups, allRepositoriesMap, "New and Updated", "orderBy=update+date", "/sortBy:updated");
addGroup(groups, allRepositoriesMap, "Top Downloads", "orderBy=downloads", "/sortBy:downloads");
addGroup(groups, allRepositoriesMap, "Top Rated", "orderBy=rating", "/sortBy:rating");
addGroup(groups, allRepositoriesMap, IdeBundle.message("plugins.configurable.featured"), "is_featured_search=true", "/sortBy:featured");
addGroup(groups, allRepositoriesMap, IdeBundle.message("plugins.configurable.new.and.updated"), "orderBy=update+date", "/sortBy:updated");
addGroup(groups, allRepositoriesMap, IdeBundle.message("plugins.configurable.top.downloads"), "orderBy=downloads", "/sortBy:downloads");
addGroup(groups, allRepositoriesMap, IdeBundle.message("plugins.configurable.top.rated"), "orderBy=rating", "/sortBy:rating");
}
catch (IOException e) {
PluginManagerMain.LOG
Expand All @@ -380,7 +381,7 @@ protected JComponent createPluginsPanel(@NotNull Consumer<? super PluginsGroupCo
for (String host : UpdateSettings.getInstance().getPluginHosts()) {
List<IdeaPluginDescriptor> allDescriptors = customRepositoriesMap.get(host);
if (allDescriptors != null) {
addGroup(groups, "Repository: " + host, "/repository:\"" + host + "\"", descriptors -> {
addGroup(groups, IdeBundle.message("plugins.configurable.repository.0", host), "/repository:\"" + host + "\"", descriptors -> {
int allSize = allDescriptors.size();
descriptors.addAll(ContainerUtil.getFirstItems(allDescriptors, ITEMS_PER_GROUP));
PluginsGroup.sortByName(descriptors);
Expand Down Expand Up @@ -414,7 +415,7 @@ protected JComponent createPluginsPanel(@NotNull Consumer<? super PluginsGroupCo
ApplicationManager.getApplication().executeOnPooledThread(runnable);
};

myMarketplacePanel.getEmptyText().setText("Marketplace plugins are not loaded.")
myMarketplacePanel.getEmptyText().setText(IdeBundle.message("plugins.configurable.marketplace.plugins.not.loaded"))
.appendSecondaryText("Check the internet connection and ", StatusText.DEFAULT_ATTRIBUTES, null)
.appendSecondaryText("refresh", SimpleTextAttributes.LINK_PLAIN_ATTRIBUTES, e -> myMarketplaceRunnable.run());

Expand Down Expand Up @@ -539,7 +540,7 @@ private Icon getIcon() {

//noinspection unchecked
myMarketplaceSortByAction.setListener(
(component, __) -> showRightBottomPopup(component.getParent().getParent(), "Sort By", myMarketplaceSortByGroup), null);
(component, __) -> showRightBottomPopup(component.getParent().getParent(), IdeBundle.message("plugins.configurable.sort.by"), myMarketplaceSortByGroup), null);

myMarketplaceSortByCallback = updateAction -> {
MarketplaceSortByAction removeAction = null;
Expand Down Expand Up @@ -716,8 +717,9 @@ protected void handleQuery(@NotNull String query, @NotNull PluginsGroup result)
catch (IOException e) {
PluginManagerMain.LOG.info(e);

ApplicationManager.getApplication().invokeLater(() -> myPanel.getEmptyText().setText("Search result are not loaded.")
.appendSecondaryText("Check the internet connection.", StatusText.DEFAULT_ATTRIBUTES, null), ModalityState.any());
ApplicationManager.getApplication().invokeLater(() -> myPanel.getEmptyText().setText(
IdeBundle.message("plugins.configurable.search.result.not.loaded"))
.appendSecondaryText(IdeBundle.message("plugins.configurable.check.internet"), StatusText.DEFAULT_ATTRIBUTES, null), ModalityState.any());
}
}
};
Expand All @@ -735,14 +737,15 @@ private void createInstalledTab() {
}

myInstalledTab = new PluginsTab() {
@SuppressWarnings("HardCodedStringLiteral")
@Override
protected void createSearchTextField(int flyDelay) {
super.createSearchTextField(flyDelay);

JBTextField textField = mySearchTextField.getTextEditor();
textField.putClientProperty("search.extension", ExtendableTextComponent.Extension
.create(AllIcons.Actions.More, AllIcons.Actions.More, "Search Options", // TODO: icon
() -> showRightBottomPopup(textField, "Show", myInstalledSearchGroup)));
.create(AllIcons.Actions.More, AllIcons.Actions.More, IdeBundle.message("plugins.configurable.search.options"), // TODO: icon
() -> showRightBottomPopup(textField, IdeBundle.message("plugins.configurable.show"), myInstalledSearchGroup)));
textField.putClientProperty("JTextField.variant", null);
textField.putClientProperty("JTextField.variant", "search");

Expand Down Expand Up @@ -773,27 +776,28 @@ protected JComponent createPluginsPanel(@NotNull Consumer<? super PluginsGroupCo

PluginLogo.startBatchMode();

PluginsGroup installing = new PluginsGroup("Installing");
PluginsGroup installing = new PluginsGroup(IdeBundle.message("plugins.configurable.installing"));
installing.descriptors.addAll(MyPluginModel.getInstallingPlugins());
if (!installing.descriptors.isEmpty()) {
installing.sortByName();
installing.titleWithCount();
myInstalledPanel.addGroup(installing);
}

PluginsGroup downloaded = new PluginsGroup("Downloaded");
PluginsGroup downloaded = new PluginsGroup(IdeBundle.message("plugins.configurable.downloaded"));
downloaded.descriptors.addAll(InstalledPluginsState.getInstance().getInstalledPlugins());

boolean groupBundled = Registry.is("plugins.group.bundled.category", false);
Map<String, List<IdeaPluginDescriptor>> bundledGroups = new HashMap<>();
PluginsGroup bundled = new PluginsGroup("Bundled");
PluginsGroup bundled = new PluginsGroup(IdeBundle.message("plugins.configurable.bundled"));

ApplicationInfoEx appInfo = ApplicationInfoEx.getInstanceEx();
int bundledEnabled = 0;
int downloadedEnabled = 0;

boolean hideImplDetails = PluginManagerCore.hideImplementationDetails();

String otherCategoryTitle = IdeBundle.message("plugins.configurable.other.bundled");
for (IdeaPluginDescriptor descriptor : PluginManagerCore.getPlugins()) {
if (!appInfo.isEssentialPlugin(descriptor.getPluginId())) {
if (descriptor.isBundled()) {
Expand All @@ -802,7 +806,7 @@ protected JComponent createPluginsPanel(@NotNull Consumer<? super PluginsGroupCo
}
bundled.descriptors.add(descriptor);
if (groupBundled) {
String category = StringUtil.defaultIfEmpty(descriptor.getCategory(), "Other Bundled");
String category = StringUtil.defaultIfEmpty(descriptor.getCategory(), otherCategoryTitle);
List<IdeaPluginDescriptor> groupDescriptors = bundledGroups.get(category);
if (groupDescriptors == null) {
bundledGroups.put(category, groupDescriptors = new ArrayList<>());
Expand Down Expand Up @@ -868,7 +872,7 @@ public void titleWithCount(int enabled) {
}

ContainerUtil.sort(groups, (o1, o2) -> StringUtil.compare(o1.title, o2.title, true));
PluginsGroup otherGroup = ContainerUtil.find(groups, group -> group.title.equals("Other Bundled"));
PluginsGroup otherGroup = ContainerUtil.find(groups, group -> group.title.equals(otherCategoryTitle));
if (otherGroup != null) {
groups.remove(otherGroup);
groups.add(otherGroup);
Expand Down Expand Up @@ -1006,8 +1010,8 @@ protected void handleAttribute(@NotNull String name, @NotNull String value) {
myInstalledSearchPanel = new SearchResultPanel(installedController, panel, 0, 0) {
@Override
protected void setEmptyText() {
myPanel.getEmptyText().setText("Nothing found.");
myPanel.getEmptyText().appendSecondaryText("Search in Marketplace", SimpleTextAttributes.LINK_PLAIN_ATTRIBUTES,
myPanel.getEmptyText().setText(IdeBundle.message("plugins.configurable.nothing.found"));
myPanel.getEmptyText().appendSecondaryText(IdeBundle.message("plugins.configurable.search.in.marketplace"), SimpleTextAttributes.LINK_PLAIN_ATTRIBUTES,
e -> myTabHeaderComponent.setSelectionWithEvents(MARKETPLACE_TAB));
}

Expand Down Expand Up @@ -1561,15 +1565,15 @@ private Pair<Map<PluginId, IdeaPluginDescriptor>, Map<String, List<IdeaPluginDes
}

private void addGroup(@NotNull List<? super PluginsGroup> groups,
@NotNull String name,
@NotNull @Nls String name,
@NotNull String showAllQuery,
@NotNull ThrowableNotNullFunction<? super List<IdeaPluginDescriptor>, Boolean, ? extends IOException> function)
throws IOException {
PluginsGroup group = new PluginsGroup(name);

if (Boolean.TRUE.equals(function.fun(group.descriptors))) {
//noinspection unchecked
group.rightAction = new LinkLabel("Show All", null, myMarketplaceTab.mySearchListener, showAllQuery);
group.rightAction = new LinkLabel(IdeBundle.message("plugins.configurable.show.all"), null, myMarketplaceTab.mySearchListener, showAllQuery);
group.rightAction.setBorder(JBUI.Borders.emptyRight(5));
}

Expand All @@ -1580,7 +1584,7 @@ private void addGroup(@NotNull List<? super PluginsGroup> groups,

private void addGroup(@NotNull List<? super PluginsGroup> groups,
@NotNull Map<PluginId, IdeaPluginDescriptor> allRepositoriesMap,
@NotNull String name,
@NotNull @Nls String name,
@NotNull String query,
@NotNull String showAllQuery) throws IOException {
addGroup(groups, name, showAllQuery, descriptors -> PluginRepositoryRequests.loadPlugins(descriptors, allRepositoriesMap, query));
Expand Down
@@ -1,8 +1,10 @@
// 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.ide.plugins.newui;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.plugins.PluginManagerConfigurable;
import com.intellij.ui.JBColor;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
Expand Down Expand Up @@ -44,7 +46,7 @@ public InstallButton(boolean fill) {
}

protected void setTextAndSize() {
setText("Install");
setText(IdeBundle.message("action.AnActionButton.text.install"));
setWidth72(this);
}

Expand All @@ -53,7 +55,7 @@ public void setEnabled(boolean b) {
super.setEnabled(b);
}

public void setEnabled(boolean enabled, @Nullable String statusText) {
public void setEnabled(boolean enabled, @Nullable @Nls String statusText) {
super.setEnabled(enabled);
if (enabled) {
setTextAndSize();
Expand Down
Expand Up @@ -2,6 +2,7 @@
package com.intellij.ide.plugins.newui;

import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.plugins.*;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -152,7 +153,8 @@ private void createButtons() {

myInstallButton
.addActionListener(e -> myPluginModel.installOrUpdatePlugin(this, myPlugin, null, ModalityState.stateForComponent(myInstallButton)));
myInstallButton.setEnabled(PluginManagerCore.getPlugin(myPlugin.getPluginId()) == null, "Installed");
myInstallButton.setEnabled(PluginManagerCore.getPlugin(myPlugin.getPluginId()) == null,
IdeBundle.message("plugin.status.installed"));
ColorButton.setWidth72(myInstallButton);
}
}
Expand Down Expand Up @@ -234,7 +236,8 @@ private void createMetricsPanel() {
}
}
else {
String version = !myPlugin.isBundled() || myPlugin.allowBundledUpdate() ? myPlugin.getVersion() : "bundled";
String version = !myPlugin.isBundled() || myPlugin.allowBundledUpdate() ? myPlugin.getVersion() : IdeBundle.message("plugin.status.bundled");

if (!StringUtil.isEmptyOrSpaces(version)) {
myVersion = createRatingLabel(panel, version, null);
}
Expand Down Expand Up @@ -480,11 +483,11 @@ public void hideProgress(boolean success, boolean restartRequired) {
enableRestart();
}
else if (myInstallButton != null) {
myInstallButton.setEnabled(false, "Installed");
myInstallButton.setEnabled(false, IdeBundle.message("plugin.status.installed"));
}
else if (myUpdateButton != null) {
myUpdateButton.setEnabled(false);
myUpdateButton.setText("Installed");
myUpdateButton.setText(IdeBundle.message("plugin.status.installed"));
}
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.components.labels.LinkLabel;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand All @@ -24,7 +25,7 @@ public class PluginsGroup {
public UIPluginGroup ui;
public Runnable clearCallback;

public PluginsGroup(@NotNull String title) {
public PluginsGroup(@NotNull @Nls String title) {
myTitlePrefix = title;
this.title = title;
}
Expand Down
@@ -1,6 +1,7 @@
// Copyright 2000-2019 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.ide.plugins.newui;

import com.intellij.ide.IdeBundle;
import com.intellij.ide.plugins.PluginManagerConfigurable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.newEditor.SettingsDialog;
Expand Down Expand Up @@ -32,6 +33,6 @@ public RestartButton(@NotNull MyPluginModel pluginModel) {

@Override
protected void setTextAndSize() {
setText("Restart IDE");
setText(IdeBundle.message("plugins.configurable.restart.ide.button"));
}
}
@@ -1,6 +1,7 @@
// 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.ide.plugins.newui;

import com.intellij.ide.IdeBundle;
import com.intellij.ui.JBColor;

import java.awt.*;
Expand All @@ -19,7 +20,7 @@ public UpdateButton() {
setBgColor(BackgroundColor);
setBorderColor(BorderColor);

setText("Update");
setText(IdeBundle.message("plugins.configurable.update.button"));
setWidth72(this);
}
}

0 comments on commit ebb07b0

Please sign in to comment.