mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-21 14:37:45 +07:00
Shortcut Promoter initial
This commit is contained in:
Generated
+1
@@ -10,6 +10,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-tests/IntelliLang-tests.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-tests/IntelliLang-tests.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-xml.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" filepath="$PROJECT_DIR$/RegExpSupport/RegExpSupport.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/ShortcutPromoter/ShortcutPromoter.iml" filepath="$PROJECT_DIR$/plugins/ShortcutPromoter/ShortcutPromoter.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/analysis-api/analysis-api.iml" filepath="$PROJECT_DIR$/platform/analysis-api/analysis-api.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/analysis-impl/analysis-impl.iml" filepath="$PROJECT_DIR$/platform/analysis-impl/analysis-impl.iml" group="platform" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/annotations/annotations.iml" filepath="$PROJECT_DIR$/platform/annotations/annotations.iml" group="platform" />
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="core-api" />
|
||||
<orderEntry type="module" module-name="editor-ui-api" />
|
||||
<orderEntry type="module" module-name="platform-api" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<idea-plugin version="2">
|
||||
<name>Shortcut Promoter</name>
|
||||
<id>com.intellij.promoter</id>
|
||||
<version>1.0</version>
|
||||
<vendor>JetBrains</vendor>
|
||||
<description>The plugin advertises to use shortcuts instead of mouse clicks</description>
|
||||
<depends>com.intellij.modules.platform</depends>
|
||||
|
||||
<application-components>
|
||||
<component>
|
||||
<implementation-class>com.intellij.promoter.ShortcutPromoterManager</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
<extensionPoints>
|
||||
<extensionPoint qualifiedName="com.intellij.shortcutPromoter" beanClass="com.intellij.promoter.ShortcutPromoterEP"/>
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<errorHandler implementation="com.intellij.diagnostic.ITNReporter"/>
|
||||
<shortcutPromoter actionId="Debug" skip="3" repeat="2"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.intellij.promoter;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class PromoterState {
|
||||
private int myClicks;
|
||||
|
||||
public int getClicks() {
|
||||
return myClicks;
|
||||
}
|
||||
|
||||
public void setClicks(int clicks) {
|
||||
myClicks = clicks;
|
||||
}
|
||||
|
||||
public void incClicks() {
|
||||
myClicks++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.intellij.promoter;
|
||||
|
||||
import com.intellij.openapi.extensions.AbstractExtensionPointBean;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ShortcutPromoterEP extends AbstractExtensionPointBean {
|
||||
public static final ExtensionPointName<ShortcutPromoterEP> EP_NAME = new ExtensionPointName<ShortcutPromoterEP>("com.intellij.shortcutPromoter");
|
||||
|
||||
@Attribute("actionId")
|
||||
public String actionId;
|
||||
|
||||
@Attribute("skip")
|
||||
public int skip;
|
||||
|
||||
@Attribute("repeat")
|
||||
public int repeat;
|
||||
|
||||
@Nullable
|
||||
public static ShortcutPromoterEP find(@Nullable String actionId) {
|
||||
for (ShortcutPromoterEP ep : EP_NAME.getExtensions()) {
|
||||
if (ep.actionId.equals(actionId)) {
|
||||
return ep;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.intellij.promoter;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.ex.AnActionListener;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.*;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
@State(
|
||||
name = "ShortcutPromoterManager",
|
||||
roamingType = RoamingType.PER_PLATFORM,
|
||||
storages = {
|
||||
@Storage(
|
||||
file = StoragePathMacros.APP_CONFIG + "/promoter.xml"
|
||||
)}
|
||||
)
|
||||
public class ShortcutPromoterManager implements ApplicationComponent, AnActionListener, ExportableApplicationComponent,
|
||||
PersistentStateComponent<Element> {
|
||||
private final HashMap<String, PromoterState> myState = new HashMap<String, PromoterState>();
|
||||
private final HashMap<String, ShortcutPromoterEP> myExtensions = new HashMap<String, ShortcutPromoterEP>();
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
myExtensions.clear();
|
||||
myState.clear();
|
||||
|
||||
for (ShortcutPromoterEP ep : ShortcutPromoterEP.EP_NAME.getExtensions()) {
|
||||
myExtensions.put(ep.actionId, ep);
|
||||
}
|
||||
ActionManager.getInstance().addAnActionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
ActionManager.getInstance().removeAnActionListener(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
|
||||
final InputEvent input = event.getInputEvent();
|
||||
if (input instanceof MouseEvent) {
|
||||
final String id = ActionManager.getInstance().getId(action);
|
||||
final ShortcutPromoterEP ep = myExtensions.get(id);
|
||||
if (ep != null) {
|
||||
PromoterState state = myState.get(id);
|
||||
if (state == null) {
|
||||
state = new PromoterState();
|
||||
myState.put(id, state);
|
||||
}
|
||||
state.incClicks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEditorTyping(char c, DataContext dataContext) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{PathManager.getOptionsFile("shortcutPromoter")};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
return "Shortcut Promoter";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Element getState() {
|
||||
final Element actions = new Element("actions");
|
||||
for (String id : myState.keySet()) {
|
||||
final Element action = new Element("action");
|
||||
action.setAttribute("actionId", id);
|
||||
action.setAttribute("clicks", String.valueOf(myState.get(id).getClicks()));
|
||||
actions.addContent(action);
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
myState.clear();
|
||||
for (Element action : state.getChildren("action")) {
|
||||
final String id = action.getAttributeValue("actionId");
|
||||
final String clicks = action.getAttributeValue("clicks");
|
||||
try {
|
||||
final PromoterState info = new PromoterState();
|
||||
info.setClicks(Integer.parseInt(clicks));
|
||||
myState.put(id, info);
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
<orderEntry type="module" module-name="python-ide-community" />
|
||||
<orderEntry type="module" module-name="platform-main" />
|
||||
<orderEntry type="module" module-name="jira" />
|
||||
<orderEntry type="module" module-name="ShortcutPromoter" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user