-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #92 IJ 2020 compatibility - better solution (service, postStart…
…upActivity)
- Loading branch information
Showing
13 changed files
with
171 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 0 additions & 132 deletions
132
src/osmedile/intellij/stringmanip/MyApplicationComponent.java
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
src/osmedile/intellij/stringmanip/MyApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package osmedile.intellij.stringmanip; | ||
|
||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.ex.ActionManagerEx; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.extensions.PluginId; | ||
import org.jetbrains.annotations.NotNull; | ||
import osmedile.intellij.stringmanip.styles.custom.CustomActionModel; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class MyApplicationService { | ||
private static final Logger LOG = Logger.getInstance(MyApplicationService.class); | ||
|
||
private Class lastAction; | ||
private CustomActionModel lastCustomActionModel; | ||
private Map<Class, AnAction> classToActionMap; | ||
|
||
public static MyApplicationService getInstance() { | ||
return ServiceManager.getService(MyApplicationService.class); | ||
} | ||
|
||
public AnAction getAnAction() { | ||
if (lastCustomActionModel != null) { | ||
return ActionManagerEx.getInstanceEx().getAction(lastCustomActionModel.getId()); | ||
} | ||
return getActionMap().get(lastAction); | ||
} | ||
|
||
public static void setAction(Class aClass, CustomActionModel customActionModel) { | ||
if (aClass != null) { | ||
MyApplicationService instance = getInstance(); | ||
instance.lastAction = aClass; | ||
instance.lastCustomActionModel = customActionModel; | ||
} | ||
} | ||
|
||
public static void setAction(Class aClass) { | ||
setAction(aClass, null); | ||
} | ||
|
||
@NotNull | ||
protected Map<Class, AnAction> getActionMap() { | ||
if (this.classToActionMap == null) { | ||
ActionManagerEx instanceEx = ActionManagerEx.getInstanceEx(); | ||
PluginId pluginId = PluginId.getId("String Manipulation"); | ||
|
||
HashMap<Class, AnAction> classToActionMap = new HashMap<Class, AnAction>(); | ||
for (String string_manipulation : instanceEx.getPluginActions(pluginId)) { | ||
AnAction action = instanceEx.getAction(string_manipulation); | ||
classToActionMap.put(action.getClass(), action); | ||
} | ||
this.classToActionMap = classToActionMap; | ||
} | ||
return this.classToActionMap; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/osmedile/intellij/stringmanip/ShortcutStartupActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package osmedile.intellij.stringmanip; | ||
|
||
import com.intellij.openapi.actionSystem.ActionManager; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.Constraints; | ||
import com.intellij.openapi.actionSystem.DefaultActionGroup; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.extensions.PluginId; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.startup.StartupActivity; | ||
import org.jetbrains.annotations.NotNull; | ||
import osmedile.intellij.stringmanip.config.PluginPersistentStateComponent; | ||
import osmedile.intellij.stringmanip.styles.custom.CustomAction; | ||
import osmedile.intellij.stringmanip.styles.custom.CustomActionModel; | ||
import shaded.org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class ShortcutStartupActivity implements StartupActivity { | ||
|
||
private static final Logger LOG = Logger.getInstance(ShortcutStartupActivity.class); | ||
|
||
private volatile boolean registered = false; | ||
|
||
@Override | ||
public void runActivity(@NotNull Project project) { | ||
if (!registered) { | ||
registerActions(); | ||
registered = true; | ||
} | ||
} | ||
|
||
|
||
public static void registerActions() { | ||
ActionManager actionManager = ActionManager.getInstance(); | ||
DefaultActionGroup group = (DefaultActionGroup) actionManager.getAction("StringManipulation.Group.SwitchCase"); | ||
List<CustomActionModel> customActionModels = PluginPersistentStateComponent.getInstance().getCustomActionModels(); | ||
|
||
unRegisterActions(customActionModels); | ||
|
||
for (int i = customActionModels.size() - 1; i >= 0; i--) { | ||
CustomActionModel customActionModel = customActionModels.get(i); | ||
registerAction(actionManager, group, customActionModel); | ||
} | ||
} | ||
|
||
protected static void registerAction(ActionManager actionManager, DefaultActionGroup group, CustomActionModel customActionModel) { | ||
String actionId = customActionModel.getId(); | ||
if (StringUtils.isNotBlank(actionId) && StringUtils.isNotBlank(customActionModel.getName())) { | ||
CustomAction action = new CustomAction(customActionModel); | ||
LOG.info("Registering " + action + " id:" + actionId); | ||
actionManager.registerAction(actionId, action, PluginId.getId("String Manipulation")); | ||
group.add(action, Constraints.FIRST); | ||
} | ||
} | ||
|
||
public static void unRegisterActions(List<CustomActionModel> customActionModels) { | ||
ActionManager instance = ActionManager.getInstance(); | ||
DefaultActionGroup group = (DefaultActionGroup) instance.getAction("StringManipulation.Group.SwitchCase"); | ||
for (CustomActionModel actionModel : customActionModels) { | ||
String id = actionModel.getId(); | ||
if (StringUtils.isNotBlank(id)) { | ||
unRegisterAction(instance, id, group); | ||
} | ||
} | ||
} | ||
|
||
private static void unRegisterAction(ActionManager instance, String actionId, DefaultActionGroup group) { | ||
AnAction action = instance.getActionOrStub(actionId); | ||
if (action != null) { | ||
LOG.info("Unregistering " + action + " id:" + actionId); | ||
group.remove(action); | ||
instance.unregisterAction(actionId); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.