"Show Project Structure" action customized for Android Studio
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 1 Sep 2014 10:47:45 +0000 (14:47 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Mon, 1 Sep 2014 10:50:00 +0000 (14:50 +0400)
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionManagerImpl.java
platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ChameleonAction.java
platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml
platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeEP.java [moved from platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java with 65% similarity]
platform/projectModel-api/src/com/intellij/openapi/project/ProjectTypeService.java
plugins/devkit/src/dom/Action.java

index c5a9b01c4d21627fe6ecbddf75f0e8ef5dccb17a..c5b79637ca407e36a0234cff59a56c8e7c923584 100644 (file)
@@ -521,7 +521,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
 
     AnAction anAction = convertStub(stub);
 
-    addToMap(stub.getId(), anAction, stub.getPluginId(), stub.getProjectType() == null ? null : new ProjectType(stub.getProjectType()));
+    addToMap(stub.getId(), anAction, stub.getPluginId(), stub.getProjectType());
     myAction2Id.put(anAction, stub.getId());
 
     return anAction;
@@ -653,7 +653,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
         }
       }
       else {
-        registerAction(id, action, pluginId);
+        registerAction(id, action, pluginId, element.getAttributeValue(PROJECT_TYPE));
       }
     }
   }
@@ -991,8 +991,12 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
 
   @Override
   public void registerAction(@NotNull String actionId, @NotNull AnAction action, @Nullable PluginId pluginId) {
+    registerAction(actionId, action, pluginId, null);
+  }
+
+  public void registerAction(@NotNull String actionId, @NotNull AnAction action, @Nullable PluginId pluginId, @Nullable String projectType) {
     synchronized (myLock) {
-      if (!addToMap(actionId, action, pluginId, null)) return;
+      if (!addToMap(actionId, action, pluginId, projectType)) return;
       if (myAction2Id.containsKey(action)) {
         reportActionError(pluginId, "action was already registered for another ID. ID is " + myAction2Id.get(action) +
                                     getPluginInfo(pluginId));
@@ -1012,8 +1016,9 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
     }
   }
 
-  public boolean addToMap(String actionId, AnAction action, PluginId pluginId, ProjectType projectType) {
+  public boolean addToMap(String actionId, AnAction action, PluginId pluginId, String projectType) {
     if (myId2Action.containsKey(actionId)) {
+      ProjectType type = projectType == null ? null : new ProjectType(projectType);
       // make sure id+projectType is unique
       AnAction o = myId2Action.get(actionId);
       ChameleonAction chameleonAction;
@@ -1021,10 +1026,10 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
         chameleonAction = (ChameleonAction)o;
       }
       else {
-        chameleonAction = new ChameleonAction(o, projectType);
+        chameleonAction = new ChameleonAction(o, type);
         myId2Action.put(actionId, chameleonAction);
       }
-      AnAction old = chameleonAction.addAction(action, projectType);
+      AnAction old = chameleonAction.addAction(action, type);
       if (old != null) {
         reportActionError(pluginId,
                           "action with the ID \"" + actionId + "\" was already registered. Action being registered is " + action +
@@ -1053,7 +1058,7 @@ public final class ActionManagerImpl extends ActionManagerEx implements Applicat
           return;
         }
       }
-      AnAction oldValue = (AnAction)myId2Action.remove(actionId);
+      AnAction oldValue = myId2Action.remove(actionId);
       myAction2Id.remove(oldValue);
       myId2Index.remove(actionId);
       for (PluginId pluginName : myPlugin2Id.keySet()) {
index 849a218f534c1bf4cf01b75c9c6712d42bd5e666..edfd0975f9783b6809e133f2c3932f63a98ae2b7 100644 (file)
  */
 package com.intellij.openapi.actionSystem.impl;
 
-import com.intellij.openapi.actionSystem.ActionStub;
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.CommonDataKeys;
+import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectType;
 import com.intellij.openapi.project.ProjectTypeService;
@@ -37,6 +34,7 @@ public class ChameleonAction extends AnAction {
 
   public ChameleonAction(@NotNull AnAction first, ProjectType projectType) {
     addAction(first, projectType);
+    copyFrom(myActions.values().iterator().next());
   }
 
   public AnAction addAction(AnAction action, ProjectType projectType) {
@@ -55,7 +53,10 @@ public class ChameleonAction extends AnAction {
 
   @Override
   public void update(AnActionEvent e) {
-    super.update(e);
+    AnAction action = getAction(e);
+    action.update(e);
+    getTemplatePresentation().setEnabled(e.getPresentation().isEnabled());
+    getTemplatePresentation().setVisible(e.getPresentation().isVisible());
   }
 
   private AnAction getAction(AnActionEvent e) {
index baea70a67c7aab4e3d212a4c45e70f84cc9306e2..00bd38430d688d3739ca2d6b265eacabd38dca85 100644 (file)
@@ -10,7 +10,7 @@
                     interface="com.intellij.openapi.startup.StartupActivity"/>
 
     <extensionPoint name="defaultProjectTypeProvider"
-                    interface="com.intellij.openapi.project.DefaultProjectTypeProvider"/>
+                    beanClass="com.intellij.openapi.project.DefaultProjectTypeEP"/>
 
     <extensionPoint name="errorHandler"
                     interface="com.intellij.openapi.diagnostic.ErrorReportSubmitter"/>
similarity index 65%
rename from platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeProvider.java
rename to platform/projectModel-api/src/com/intellij/openapi/project/DefaultProjectTypeEP.java
index 81887eba0f985bde3ae2dbf291224b15b9cc4e65..3eb65af697c00b1de32b219150e8f577bc97da8c 100644 (file)
 package com.intellij.openapi.project;
 
 import com.intellij.openapi.extensions.ExtensionPointName;
+import com.intellij.util.xmlb.annotations.Attribute;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * @author Dmitry Avdeev
  */
-public abstract class DefaultProjectTypeProvider {
+public class DefaultProjectTypeEP {
 
-  private final static ExtensionPointName<DefaultProjectTypeProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.defaultProjectTypeProvider");
+  private final static ExtensionPointName<DefaultProjectTypeEP> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.defaultProjectTypeProvider");
+  @Attribute("type")
+  public String type;
 
   @Nullable
   public static ProjectType getDefaultProjectType() {
-    DefaultProjectTypeProvider[] extensions = EXTENSION_POINT_NAME.getExtensions();
-    return extensions.length > 0 ? extensions[0].getProjectType() : null;
+    DefaultProjectTypeEP[] extensions = EXTENSION_POINT_NAME.getExtensions();
+    return extensions.length > 0 ? new ProjectType(extensions[0].type) : null;
   }
-
-  protected abstract ProjectType getProjectType();
 }
index e43059390b1964d855616aa1186fef1e627d8540..a101743e38ce648b41f271317fe65f7084be6440 100644 (file)
@@ -41,7 +41,7 @@ public class ProjectTypeService implements PersistentStateComponent<ProjectType>
       projectType = getInstance(project).myProjectType;
       if (projectType != null) return projectType;
     }
-    return DefaultProjectTypeProvider.getDefaultProjectType();
+    return DefaultProjectTypeEP.getDefaultProjectType();
   }
 
   public static ProjectTypeService getInstance(@NotNull Project project) {
index ac879140fd4b6a98cee396e5e14510f439db9964..e28f2d13b9b4e8d0f571f467a8dd00bdfa0449d2 100644 (file)
@@ -165,4 +165,7 @@ public interface Action extends DomElement {
 
         @NotNull
         GenericAttributeValue<String> getKeymap();
+
+       @NotNull
+       GenericAttributeValue<String> getProjectType();
 }