From f939f623b0b2c8cc50d5883289736be376954da4 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 19 Mar 2019 12:09:43 +0300 Subject: [PATCH] platform: generalize 'Send Feedback' action It's description refer to actual host instead of 'JetBrain Web site', $VERSION placeholder is supported in feedback URLs, action is hidden for OSes which don't have official distributions. This is needed to reuse the action in Android Studio instead of overriding it (IDEA-209167). --- .../ide/actions/SendFeedbackAction.java | 20 ++++++++++++++++++- .../src/messages/ActionsBundle.properties | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java b/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java index 56731c079c9a..a29419213257 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/SendFeedbackAction.java @@ -18,6 +18,7 @@ package com.intellij.ide.actions; import com.intellij.ide.BrowserUtil; import com.intellij.ide.FeedbackDescriptionProvider; +import com.intellij.idea.ActionsBundle; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.application.ex.ApplicationInfoEx; @@ -31,12 +32,28 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class SendFeedbackAction extends AnAction implements DumbAware { @Override public void update(@NotNull AnActionEvent e) { ApplicationInfoEx info = ApplicationInfoEx.getInstanceEx(); - e.getPresentation().setEnabledAndVisible(info != null && info.getFeedbackUrl() != null); + boolean isSupportedOS = SystemInfo.isMac || SystemInfo.isLinux || SystemInfo.isWindows; + if (info != null && info.getFeedbackUrl() != null && isSupportedOS) { + String feedbackSite = getFeedbackHost(info.getFeedbackUrl(), info.getCompanyName()); + e.getPresentation().setDescription(ActionsBundle.message("action.SendFeedback.detailed.description", feedbackSite)); + e.getPresentation().setEnabledAndVisible(true); + } + else { + e.getPresentation().setEnabledAndVisible(false); + } + } + + private static String getFeedbackHost(String feedbackUrl, String companyName) { + Pattern uriPattern = Pattern.compile("[^:/?#]+://(?:www\\.)?([^/?#]*).*", Pattern.DOTALL); + Matcher matcher = uriPattern.matcher(feedbackUrl); + return matcher.matches() ? matcher.group(1) : companyName; } @Override @@ -61,6 +78,7 @@ public class SendFeedbackAction extends AnAction implements DumbAware { String url = urlTemplate .replace("$BUILD", eap ? appInfo.getBuild().asStringWithoutProductCode() : appInfo.getBuild().asString()) .replace("$TIMEZONE", System.getProperty("user.timezone")) + .replace("$VERSION", appInfo.getFullVersion()) .replace("$EVAL", la != null && la.isEvaluationLicense() ? "true" : "false") .replace("$DESCR", description); BrowserUtil.browse(url, project); diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 9703339f1f4f..9c497b2be577 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -1251,7 +1251,7 @@ action.ShowCoverageInfo.text=Show Co&verage Info action.HideCoverageInfo.text=Hide Co&verage Info action.SendFeedback.text=Submit _Feedback... -action.SendFeedback.description=Submit feedback to the JetBrains Web site +action.SendFeedback.detailed.description=Submit feedback to {0} action.ShowLog.text=Show _Log in File Manager action.ShowLog.description=Opens folder with log file action.CollectZippedLogs.text=Compress Logs and Show in File Manager