Skip to content

Commit

Permalink
fix: always show icons of install guide links in the same color
Browse files Browse the repository at this point in the history
  • Loading branch information
jansorg committed Aug 1, 2023
1 parent da5ce14 commit df5a991
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,28 @@
import appland.Icons;
import appland.telemetry.TelemetryService;
import com.intellij.ide.BrowserUtil;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ui.HyperlinkAdapter;
import com.intellij.ui.components.JBLabel;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class UrlLabel extends JBLabel {
public UrlLabel(@NotNull String label, @NotNull String url) {
super(createLink(label, url));

setIcon(Icons.LINK_VISITED);

// to enable link support
setCopyable(true);

setIcon(iconFor(url));
}

private static Icon iconFor(String url) {
return isLinkVisited(url) ? Icons.LINK_VISITED : Icons.LINK;
}

private static String createLink(String label, String url) {
return String.format("<html><a href='%s'>%s</a></html>", url, label);
}

private static boolean isLinkVisited(String url) {
return PropertiesComponent.getInstance().isTrueValue(urlPropertyKey(url));
}

@NotNull
private static String urlPropertyKey(String url) {
return "appland.url." + url;
Expand All @@ -48,8 +38,6 @@ protected void hyperlinkActivated(HyperlinkEvent e) {
var url = e.getDescription();
BrowserUtil.browse(url);

PropertiesComponent.getInstance().setValue(urlPropertyKey(url), true);
setIcon(iconFor(url));
TelemetryService.getInstance().sendEvent("click_docs_link_in_tree", eventData -> {
eventData.property("appmap.docs_path", StringUtils.remove(url, "https://appmap.io"));
return eventData;
Expand Down

0 comments on commit df5a991

Please sign in to comment.