Skip to content

Commit

Permalink
possibility to pass plugin product code to Register dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenezh committed Dec 8, 2021
1 parent 51208c4 commit eb79c16
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/company/license/CheckLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public static boolean isLicensed() {

public static void requestLicense(final String message) {
// ensure the dialog is appeared from UI thread and in a non-modal context
ApplicationManager.getApplication().invokeLater(() -> showRegisterDialog(message), ModalityState.NON_MODAL);
ApplicationManager.getApplication().invokeLater(() -> showRegisterDialog("PMAKECOFFEE", message), ModalityState.NON_MODAL);
}

private static void showRegisterDialog(final String message) {
private static void showRegisterDialog(final String productCode, final String message) {
final com.intellij.openapi.actionSystem.ActionManager actionManager = com.intellij.openapi.actionSystem.ActionManager.getInstance();
// first, assume we are running inside the opensource version
AnAction registerAction = actionManager.getAction("RegisterPlugins");
Expand All @@ -135,7 +135,7 @@ private static void showRegisterDialog(final String message) {
registerAction = actionManager.getAction("Register");
}
if (registerAction != null) {
registerAction.actionPerformed(AnActionEvent.createFromDataContext("", new Presentation(), asDataContext(message)));
registerAction.actionPerformed(AnActionEvent.createFromDataContext("", new Presentation(), asDataContext(productCode, message)));
}
}

Expand All @@ -144,11 +144,11 @@ private static void showRegisterDialog(final String message) {
// - productCode: the product corresponding to the passed productCode will be pre-selected in the opened dialog
// - message: optional message explaining the reason why the dialog has been shown
@NotNull
private static DataContext asDataContext(@Nullable String message) {
private static DataContext asDataContext(final String productCode, @Nullable String message) {
return dataId -> {
switch (dataId) {
// the same code as registered in plugin.xml, 'product-descriptor' tag
case "register.product-descriptor.code" : return "PMAKECOFFEE";
case "register.product-descriptor.code" : return productCode;

// optional message to be shown in the registration dialog that appears
case "register.message" : return message;
Expand Down

0 comments on commit eb79c16

Please sign in to comment.