From 0385125747794016c35a49bfdf8d25b974f0eb3d Mon Sep 17 00:00:00 2001 From: marhali Date: Fri, 22 Apr 2022 15:23:28 +0200 Subject: [PATCH] fix possible npe on add-action Resolves #107 --- .../java/de/marhali/easyi18n/action/AddAction.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/marhali/easyi18n/action/AddAction.java b/src/main/java/de/marhali/easyi18n/action/AddAction.java index 2505a18..96e74f8 100644 --- a/src/main/java/de/marhali/easyi18n/action/AddAction.java +++ b/src/main/java/de/marhali/easyi18n/action/AddAction.java @@ -32,12 +32,23 @@ public class AddAction extends AnAction { @Override public void actionPerformed(@NotNull AnActionEvent e) { - new AddDialog(Objects.requireNonNull(e.getProject()), detectPreKey(e.getProject()), null).showAndHandle(); + Project project = Objects.requireNonNull(e.getProject()); + new AddDialog(project, detectPreKey(project), null).showAndHandle(); } + /** + * Detects a selected translation key in our tool-window. + * @param project Opened project + * @return Found key to prefill translation key or null if not applicable + */ private @Nullable KeyPath detectPreKey(@NotNull Project project) { KeyPathConverter converter = new KeyPathConverter(project); WindowManager window = WindowManager.getInstance(); + + if(window.getToolWindow() == null) { + return null; + } + Content manager = window.getToolWindow().getContentManager().getSelectedContent(); if(manager == null) {