mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.ex.AnActionListener;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.project.ProjectType;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -80,7 +81,7 @@ public abstract class ActionManager implements ApplicationComponent {
|
||||
* @param actionId Id of the registered action
|
||||
*
|
||||
* @return Action associated with the specified actionId, <code>null</code> if
|
||||
* there is no actions associated with the speicified actionId
|
||||
* there is no actions associated with the specified actionId
|
||||
*
|
||||
* @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
|
||||
*
|
||||
@@ -88,6 +89,20 @@ public abstract class ActionManager implements ApplicationComponent {
|
||||
*/
|
||||
public abstract AnAction getAction(@NonNls @NotNull String actionId);
|
||||
|
||||
/**
|
||||
* Returns action associated with the specified actionId.
|
||||
*
|
||||
* @param actionId Id of the registered action
|
||||
*
|
||||
* @return Action associated with the specified actionId, <code>null</code> if
|
||||
* there is no actions associated with the specified actionId
|
||||
*
|
||||
* @exception java.lang.IllegalArgumentException if <code>actionId</code> is <code>null</code>
|
||||
*
|
||||
* @see com.intellij.openapi.actionSystem.IdeActions
|
||||
*/
|
||||
public abstract AnAction getAction(@NonNls @NotNull String actionId, @Nullable ProjectType projectType);
|
||||
|
||||
/**
|
||||
* Returns actionId associated with the specified action.
|
||||
*
|
||||
|
||||
@@ -28,15 +28,16 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Extensions {
|
||||
private static LogProvider ourLogger = new SimpleLogProvider();
|
||||
|
||||
public static final ExtensionPointName<AreaListener> AREA_LISTENER_EXTENSION_POINT = new ExtensionPointName<AreaListener>("com.intellij.arealistener");
|
||||
|
||||
private static LogProvider ourLogger = new SimpleLogProvider();
|
||||
private static Map<AreaInstance,ExtensionsAreaImpl> ourAreaInstance2area = new THashMap<AreaInstance, ExtensionsAreaImpl>();
|
||||
private static Map<String,AreaClassConfiguration> ourAreaClass2Configuration = new THashMap<String, AreaClassConfiguration>();
|
||||
|
||||
@NotNull private static ExtensionsAreaImpl ourRootArea = createRootArea();
|
||||
|
||||
private Extensions() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ExtensionsAreaImpl createRootArea() {
|
||||
ExtensionsAreaImpl rootArea = new ExtensionsAreaImpl(null, null, null, ourLogger);
|
||||
@@ -44,9 +45,6 @@ public class Extensions {
|
||||
return rootArea;
|
||||
}
|
||||
|
||||
private Extensions() {
|
||||
}
|
||||
|
||||
public static void setSynchronized() {
|
||||
assert ourAreaInstance2area.isEmpty();
|
||||
assert ourAreaClass2Configuration.isEmpty();
|
||||
@@ -101,7 +99,7 @@ public class Extensions {
|
||||
@NotNull
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static <T> T[] getExtensions(@NotNull ExtensionPointName<T> extensionPointName, AreaInstance areaInstance) {
|
||||
return Extensions.<T>getExtensions(extensionPointName.getName(), areaInstance);
|
||||
return getExtensions(extensionPointName.getName(), areaInstance);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -29,6 +29,7 @@ public class ActionStub extends AnAction{
|
||||
private static final Logger LOG=Logger.getInstance("#com.intellij.openapi.actionSystem.ActionStub");
|
||||
|
||||
private final String myClassName;
|
||||
private final String myProjectType;
|
||||
private final String myId;
|
||||
private final String myText;
|
||||
private final ClassLoader myLoader;
|
||||
@@ -40,9 +41,10 @@ public class ActionStub extends AnAction{
|
||||
@NotNull String text,
|
||||
ClassLoader loader,
|
||||
PluginId pluginId,
|
||||
String iconPath) {
|
||||
String iconPath, String projectType) {
|
||||
myLoader = loader;
|
||||
myClassName=actionClass;
|
||||
myProjectType = projectType;
|
||||
LOG.assertTrue(!id.isEmpty());
|
||||
myId=id;
|
||||
myText=text;
|
||||
@@ -102,4 +104,7 @@ public class ActionStub extends AnAction{
|
||||
targetAction.setShortcutSet(getShortcutSet());
|
||||
}
|
||||
|
||||
public String getProjectType() {
|
||||
return myProjectType;
|
||||
}
|
||||
}
|
||||
|
||||
+505
-469
File diff suppressed because it is too large
Load Diff
+68
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
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.project.Project;
|
||||
import com.intellij.openapi.project.ProjectType;
|
||||
import com.intellij.openapi.project.ProjectTypeService;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class ChameleonAction extends AnAction {
|
||||
|
||||
private final Map<ProjectType, AnAction> myActions = new HashMap<ProjectType, AnAction>();
|
||||
|
||||
public ChameleonAction(@NotNull AnAction first, ProjectType projectType) {
|
||||
addAction(first, projectType);
|
||||
}
|
||||
|
||||
public AnAction addAction(AnAction action, ProjectType projectType) {
|
||||
if (action instanceof ActionStub) {
|
||||
String type = ((ActionStub)action).getProjectType();
|
||||
action = ActionManagerImpl.convertStub((ActionStub)action);
|
||||
projectType = type == null ? null : new ProjectType(type);
|
||||
}
|
||||
return myActions.put(projectType, action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
getAction(e).actionPerformed(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
}
|
||||
|
||||
private AnAction getAction(AnActionEvent e) {
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
ProjectType projectType = ProjectTypeService.getProjectType(project);
|
||||
AnAction action = myActions.get(projectType);
|
||||
if (action == null) action = myActions.get(null);
|
||||
if (action == null) action = myActions.values().iterator().next();
|
||||
return action;
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -40,7 +40,6 @@ public class ActionBean {
|
||||
@Attribute(ActionManagerImpl.ICON_ATTR_NAME)
|
||||
public String icon;
|
||||
|
||||
|
||||
@Attribute(ActionManagerImpl.POPUP_ATTR_NAME)
|
||||
public String isPopup;
|
||||
|
||||
@@ -58,4 +57,7 @@ public class ActionBean {
|
||||
|
||||
@Attribute(ActionManagerImpl.OVERRIDES_ATTR_NAME)
|
||||
public boolean overrides;
|
||||
|
||||
@Attribute(ActionManagerImpl.PROJECT_TYPE)
|
||||
public String projectType;
|
||||
}
|
||||
|
||||
@@ -46,16 +46,15 @@ import java.awt.event.ActionListener;
|
||||
public class ContextMenuImpl extends JPanel implements Disposable {
|
||||
@NonNls
|
||||
public static final String ACTION_GROUP = "EditorContextBarMenu";
|
||||
|
||||
private ActionGroup myActionGroup;
|
||||
private final JComponent myComponent;
|
||||
private final JLayeredPane myLayeredPane;
|
||||
private ActionGroup myActionGroup;
|
||||
private boolean myVisible = false;
|
||||
private boolean myShow = false;
|
||||
private int myCurrentOpacity;
|
||||
private Timer myTimer;
|
||||
private EditorImpl myEditor;
|
||||
private boolean myDisposed;
|
||||
private final JLayeredPane myLayeredPane;
|
||||
private ActionToolbar myActionToolbar;
|
||||
|
||||
public ContextMenuImpl(JLayeredPane layeredPane, @NotNull final JScrollPane container, @NotNull final EditorImpl editor) {
|
||||
@@ -81,7 +80,7 @@ public class ContextMenuImpl extends JPanel implements Disposable {
|
||||
}
|
||||
});
|
||||
|
||||
AnAction action = actionManager.getAction("EditorContextBarMenu");
|
||||
AnAction action = actionManager.getAction(ACTION_GROUP);
|
||||
if (action == null) {
|
||||
action = new DefaultActionGroup();
|
||||
actionManager.registerAction(ACTION_GROUP, action);
|
||||
@@ -107,6 +106,15 @@ public class ContextMenuImpl extends JPanel implements Disposable {
|
||||
return activationArea.contains(p.x, p.y - viewPosition.y);
|
||||
}
|
||||
|
||||
public static boolean mayShowToolbar(@Nullable final Document document) {
|
||||
if (document == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
|
||||
return file != null && file.isValid() && (file.isInLocalFileSystem() || file instanceof HttpVirtualFile);
|
||||
}
|
||||
|
||||
private void toggleContextToolbar(final boolean show) {
|
||||
final Component toolbar = myComponent.getComponent(0);
|
||||
final int count = ((Container)toolbar).getComponentCount();
|
||||
@@ -201,15 +209,6 @@ public class ContextMenuImpl extends JPanel implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean mayShowToolbar(@Nullable final Document document) {
|
||||
if (document == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final VirtualFile file = FileDocumentManager.getInstance().getFile(document);
|
||||
return file != null && file.isValid() && (file.isInLocalFileSystem() || file instanceof HttpVirtualFile);
|
||||
}
|
||||
|
||||
private void scheduleHide() {
|
||||
if (myTimer != null && myTimer.isRunning()) {
|
||||
myTimer.stop();
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
<extensionPoint name="postStartupActivity"
|
||||
interface="com.intellij.openapi.startup.StartupActivity"/>
|
||||
|
||||
<extensionPoint name="defaultProjectTypeProvider"
|
||||
interface="com.intellij.openapi.project.DefaultProjectTypeProvider"/>
|
||||
|
||||
<extensionPoint name="errorHandler"
|
||||
interface="com.intellij.openapi.diagnostic.ErrorReportSubmitter"/>
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@
|
||||
serviceImplementation="com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.startup.StartupManager"
|
||||
serviceImplementation="com.intellij.ide.startup.impl.StartupManagerImpl"/>
|
||||
<projectService serviceImplementation="com.intellij.openapi.project.ProjectTypeService"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.ui.MasterDetailsStateService" serviceImplementation="com.intellij.openapi.ui.MasterDetailsStateService"/>
|
||||
<projectService serviceInterface="com.intellij.ide.SelectInManager" serviceImplementation="com.intellij.ide.SelectInManager"/>
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.project;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public abstract class DefaultProjectTypeProvider {
|
||||
|
||||
private final static ExtensionPointName<DefaultProjectTypeProvider> EXTENSION_POINT_NAME = ExtensionPointName.create("com.intellij.defaultProjectTypeProvider");
|
||||
|
||||
@Nullable
|
||||
public static ProjectType getDefaultProjectType() {
|
||||
DefaultProjectTypeProvider[] extensions = EXTENSION_POINT_NAME.getExtensions();
|
||||
return extensions.length > 0 ? extensions[0].getProjectType() : null;
|
||||
}
|
||||
|
||||
protected abstract ProjectType getProjectType();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.project;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class ProjectType {
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* For serialization.
|
||||
*/
|
||||
public ProjectType() {
|
||||
}
|
||||
|
||||
public ProjectType(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ProjectType type = (ProjectType)o;
|
||||
|
||||
if (id != null ? !id.equals(type.id) : type.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id != null ? id.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.project;
|
||||
|
||||
import com.intellij.openapi.components.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
|
||||
@State(
|
||||
name = "ProjectType",
|
||||
storages = {
|
||||
@Storage(file = StoragePathMacros.PROJECT_FILE),
|
||||
@Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/misc.xml", scheme = StorageScheme.DIRECTORY_BASED)
|
||||
}
|
||||
)
|
||||
public class ProjectTypeService implements PersistentStateComponent<ProjectType> {
|
||||
|
||||
private ProjectType myProjectType;
|
||||
|
||||
@Nullable
|
||||
public static ProjectType getProjectType(@Nullable Project project) {
|
||||
ProjectType projectType;
|
||||
if (project != null) {
|
||||
projectType = getInstance(project).myProjectType;
|
||||
if (projectType != null) return projectType;
|
||||
}
|
||||
return DefaultProjectTypeProvider.getDefaultProjectType();
|
||||
}
|
||||
|
||||
public static ProjectTypeService getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, ProjectTypeService.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ProjectType getState() {
|
||||
return myProjectType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(ProjectType state) {
|
||||
myProjectType = state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user