IDEA-135132 Usability issues with resource bundles: Clicking "New Property" does...
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 15 Jan 2015 12:40:14 +0000 (15:40 +0300)
committerDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 15 Jan 2015 12:41:20 +0000 (15:41 +0300)
plugins/properties/src/com/intellij/lang/properties/editor/NewPropertyAction.java
plugins/properties/src/com/intellij/lang/properties/editor/ResourceBundleEditor.java

index 76be016f4f492f4c0de0aa03fdcef0bc6eb1a608..af29c65a45e3b862abd2664063d86826627ec232 100644 (file)
@@ -20,12 +20,10 @@ import com.intellij.lang.properties.PropertiesBundle;
 import com.intellij.lang.properties.ResourceBundle;
 import com.intellij.lang.properties.psi.PropertiesFile;
 import com.intellij.lang.properties.structureView.PropertiesPrefixGroup;
-import com.intellij.openapi.actionSystem.ActionPlaces;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileEditor.FileEditor;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.InputValidator;
@@ -55,11 +53,15 @@ class NewPropertyAction extends AnAction {
     if (project == null) {
       return;
     }
-    final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(e.getDataContext());
-    if (editor == null || !(editor instanceof ResourceBundleEditor)) {
-      return;
+    final ResourceBundleEditor resourceBundleEditor;
+    final DataContext context = e.getDataContext();
+    FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context);
+    if (fileEditor instanceof ResourceBundleEditor) {
+      resourceBundleEditor = (ResourceBundleEditor)fileEditor;
+    } else {
+      final Editor editor = CommonDataKeys.EDITOR.getData(context);
+      resourceBundleEditor = editor != null ? editor.getUserData(ResourceBundleEditor.RESOURCE_BUNDLE_EDITOR_KEY) : null;
     }
-    final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor)editor;
 
     final String prefix;
     final String separator;
index 40e5d679af9080fbc8075787e93723340b6f617d..921aedb8cf48fd0cdb08e54de746d84717454a58 100644 (file)
@@ -47,6 +47,7 @@ import com.intellij.openapi.fileEditor.*;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.UserDataHolderBase;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.*;
@@ -85,6 +86,7 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
     Logger.getInstance("#com.intellij.lang.properties.editor.ResourceBundleEditor");
   @NonNls private static final String VALUES               = "values";
   @NonNls private static final String NO_PROPERTY_SELECTED = "noPropertySelected";
+  public static final Key<ResourceBundleEditor> RESOURCE_BUNDLE_EDITOR_KEY = Key.create("resourceBundleEditor");
 
   private final StructureViewComponent      myStructureViewComponent;
   private final Map<PropertiesFile, Editor> myEditors;
@@ -798,11 +800,12 @@ public class ResourceBundleEditor extends UserDataHolderBase implements FileEdit
     }
   }
 
-  private static Editor createEditor() {
+  private Editor createEditor() {
     EditorFactory editorFactory = EditorFactory.getInstance();
     Document document = editorFactory.createDocument("");
     EditorEx editor = (EditorEx)editorFactory.createEditor(document);
     reinitSettings(editor);
+    editor.putUserData(RESOURCE_BUNDLE_EDITOR_KEY, this);
     return editor;
   }