Search in sources :

Example 71 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project intellij-community by JetBrains.

the class CheckRegExpForm method createUIComponents.

private void createUIComponents() {
    myProject = myRegexpFile.getProject();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
    final Language language = myRegexpFile.getLanguage();
    final LanguageFileType fileType;
    if (language instanceof RegExpLanguage) {
        fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
    } else {
        // for correct syntax highlighting
        fileType = new RegExpFileType(language);
    }
    myRegExp = new EditorTextField(document, myProject, fileType);
    final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
    mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {

        @Override
        protected void updateBorder(@NotNull EditorEx editor) {
            setupBorder(editor);
        }
    };
    mySampleText.setOneLineMode(false);
    int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
    myRegExp.setPreferredWidth(preferredWidth);
    mySampleText.setPreferredWidth(preferredWidth);
    myRootPanel = new JPanel(new BorderLayout()) {

        Disposable disposable;

        Alarm updater;

        @Override
        public void addNotify() {
            super.addNotify();
            disposable = Disposer.newDisposable();
            IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
            new AnAction() {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
                }
            }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
            updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
            DocumentAdapter documentListener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    update();
                }
            };
            myRegExp.addDocumentListener(documentListener);
            mySampleText.addDocumentListener(documentListener);
            update();
            mySampleText.selectAll();
        }

        public void update() {
            final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
            updater.cancelAllRequests();
            if (!updater.isDisposed()) {
                updater.addRequest(() -> {
                    final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
                    TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
                }, 200);
            }
        }

        @Override
        public void removeNotify() {
            super.removeNotify();
            Disposer.dispose(disposable);
            PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
        }
    };
    myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TransactionId(com.intellij.openapi.application.TransactionId) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) EditorTextField(com.intellij.ui.EditorTextField) Alarm(com.intellij.util.Alarm)

Example 72 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project android by JetBrains.

the class GutterIconRenderer method getClickAction.

@Nullable
@Override
public AnAction getClickAction() {
    return new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
            if (editor != null) {
                Project project = editor.getProject();
                VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByIoFile(myFile);
                if (project != null && virtualFile != null) {
                    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile, -1);
                    FileEditorManager.getInstance(project).openEditor(descriptor, true);
                }
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Editor(com.intellij.openapi.editor.Editor) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 73 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project android by JetBrains.

the class TargetArtifactsPanel method setHeaderActions.

private void setHeaderActions() {
    List<AnAction> additionalActions = Lists.newArrayList();
    additionalActions.add(new AbstractBaseExpandAllAction(myTree) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            myTree.requestFocusInWindow();
            myTreeBuilder.expandAllNodes();
        }
    });
    additionalActions.add(new AbstractBaseCollapseAllAction(myTree) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            myTree.requestFocusInWindow();
            myTreeBuilder.collapseAllNodes();
        }
    });
    getHeader().setAdditionalActions(additionalActions);
}
Also used : AbstractBaseExpandAllAction(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractBaseExpandAllAction) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) AbstractBaseCollapseAllAction(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractBaseCollapseAllAction)

Example 74 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project android by JetBrains.

the class GradleBuildTreeViewPanel method fillRightToolbarGroup.

@Override
protected void fillRightToolbarGroup(DefaultActionGroup group) {
    super.fillRightToolbarGroup(group);
    group.add(new DumbAwareAction("Show Console Output", null, AndroidIcons.GradleConsole) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(GradleConsoleToolWindowFactory.ID);
            if (window != null) {
                window.activate(null, false);
            }
        }

        @Override
        public void update(AnActionEvent e) {
            e.getPresentation().setEnabledAndVisible(true);
        }
    });
    DefaultActionGroup filterGroup = new DefaultActionGroup("GradleBuildMessagesFilter", true) {

        @Override
        public void update(AnActionEvent e) {
            Presentation presentation = e.getPresentation();
            presentation.setDescription("Filter messages to display");
            presentation.setIcon(AllIcons.General.Filter);
        }

        @Override
        public boolean isDumbAware() {
            return true;
        }
    };
    // We could have iterated through ErrorTreeElementKind.values() and have less code, but we want to keep this order:
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.ERROR));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.WARNING));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.INFO));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.NOTE));
    filterGroup.add(new FilterMessagesByKindAction(ErrorTreeElementKind.GENERIC));
    group.add(filterGroup);
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup)

Example 75 with AnActionEvent

use of com.intellij.openapi.actionSystem.AnActionEvent in project android by JetBrains.

the class ConfigurationMenuAction method addMultiConfigActions.

private void addMultiConfigActions(DefaultActionGroup group) {
    Configuration configuration = mySurface.getConfiguration();
    if (configuration == null) {
        return;
    }
    VirtualFile file = configuration.getFile();
    if (file == null) {
        return;
    }
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    group.addSeparator();
    group.add(new PreviewAction(mySurface, "Preview Representative Sample", ACTION_PREVIEW_MODE, RenderPreviewMode.DEFAULT, true));
    addScreenSizeAction(mySurface, group);
    boolean haveMultipleLocales = configurationManager.getLocales().size() > 1;
    addLocalePreviewAction(mySurface, group, haveMultipleLocales);
    addRtlPreviewAction(mySurface, group);
    addApiLevelPreviewAction(mySurface, group);
    // TODO: Support included layouts
    boolean DISABLE_RENDER_INCLUDED = true;
    boolean canPreviewIncluded = !DISABLE_RENDER_INCLUDED && hasCapability(mySurface, Features.EMBEDDED_LAYOUT);
    group.add(new PreviewAction(mySurface, "Preview Included", ACTION_PREVIEW_MODE, RenderPreviewMode.INCLUDES, canPreviewIncluded));
    List<VirtualFile> variations = ResourceHelper.getResourceVariations(file, true);
    group.add(new PreviewAction(mySurface, "Preview Layout Versions", ACTION_PREVIEW_MODE, RenderPreviewMode.VARIATIONS, variations.size() > 1));
    group.add(new PreviewAction(mySurface, "None", ACTION_PREVIEW_MODE, RenderPreviewMode.NONE, true));
    // Debugging only
    group.addSeparator();
    group.add(new AnAction("Toggle Layout Mode") {

        @Override
        public void actionPerformed(AnActionEvent e) {
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)130 AnAction (com.intellij.openapi.actionSystem.AnAction)67 Project (com.intellij.openapi.project.Project)27 NotNull (org.jetbrains.annotations.NotNull)25 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 Nullable (org.jetbrains.annotations.Nullable)20 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)15 List (java.util.List)14 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)13 ArrayList (java.util.ArrayList)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 StringUtil (com.intellij.openapi.util.text.StringUtil)9 CommonDataKeys (com.intellij.openapi.actionSystem.CommonDataKeys)8 JBTable (com.intellij.ui.table.JBTable)8 DataContext (com.intellij.openapi.actionSystem.DataContext)7 Pair (com.intellij.openapi.util.Pair)7 Logger (com.intellij.openapi.diagnostic.Logger)6 Ref (com.intellij.openapi.util.Ref)6 AnActionButton (com.intellij.ui.AnActionButton)6