Created
August 20, 2018 22:01
-
-
Save alshain/518f74e6b074f821c9f78b3d2be4e328 to your computer and use it in GitHub Desktop.
LivePlugin: Add actions to navigation bar
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
import com.intellij.ide.ui.customization.ActionUrl | |
import com.intellij.ide.ui.customization.CustomActionsSchema | |
import com.intellij.ide.ui.customization.CustomisedActionGroup | |
import com.intellij.ide.ui.customization.CustomizableActionGroupProvider | |
import com.intellij.ide.ui.customization.CustomizableActionGroupProvider.CustomizableActionGroupRegistrar | |
import com.intellij.openapi.actionSystem.* | |
import com.intellij.openapi.extensions.Extensions | |
import static liveplugin.PluginUtil.* | |
show("Current project: ${project.name}") | |
void removeOldEntriesInToolbar(List<String> oldIds) { | |
def instance = CustomActionsSchema.getInstance() | |
for(ActionUrl actionUrl : instance.getActions()) { | |
for(String oldId : oldIds) { | |
if (actionUrl.getComponent() == oldId) { | |
actionUrl.setActionType(ActionUrl.DELETED) | |
} | |
} | |
} | |
} | |
DefaultActionGroup actionGroupInMainToolbarAndNavBar(String uniqueId) { | |
DefaultActionGroup actionGroup = registerAction(uniqueId, new DefaultActionGroup()) | |
def instance = CustomActionsSchema.getInstance() | |
removeOldEntriesInToolbar([uniqueId]) | |
instance.addAction(new ActionUrl(["root", "Navigation Bar Toolbar"], uniqueId, ActionUrl.ADDED, 0)) | |
instance.addAction(new ActionUrl(["root", "Main Toolbar"], uniqueId, ActionUrl.ADDED, 100)) | |
CustomActionsSchema.setCustomizationSchemaForCurrentProjects() | |
return actionGroup | |
} | |
class MyAction extends AnAction { | |
@Override | |
void actionPerformed(AnActionEvent e) { | |
show("Performed MyAction1234") | |
} | |
} | |
DefaultActionGroup actionGroup = actionGroupInMainToolbarAndNavBar("my-fancy-action-group") | |
def myFancyAction = registerAction("my-fancy-action", new MyAction()) | |
def myFancyAction2 = registerAction("my-fancy-action2", new MyAction()) | |
actionGroup.add(myFancyAction) | |
actionGroup.add(myFancyAction2) | |
//def action1 = ActionManager.getInstance().getAction("NavBarToolBar") | |
// | |
//printInfos("NavBarToolBar", action1) | |
//def printInfos(String description, AnAction anAction) { | |
// show(description + ": " + anAction) | |
// if (anAction != null) { | |
// | |
// show(description + ": " + anAction.getClass()) | |
// } | |
//} | |
// | |
//show(action1) | |
//def action = ActionManager.getInstance().getAction(ActionPlaces.NAVIGATION_BAR_TOOLBAR) | |
// | |
//printInfos("Other", action) | |
// | |
//class MyAction extends AnAction { | |
// @Override | |
// void actionPerformed(AnActionEvent e) { | |
// show("Performed MyAction") | |
// } | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment