Search in sources :

Example 81 with DataContext

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

the class ScopeColorsPageFactory method createChooseScopePanel.

private static JPanel createChooseScopePanel() {
    Project[] projects = ProjectManager.getInstance().getOpenProjects();
    JPanel panel = new JPanel(new GridBagLayout());
    //panel.setBorder(new LineBorder(Color.red));
    if (projects.length == 0)
        return panel;
    GridBagConstraints gc = new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0);
    JButton button = new JButton("Manage Scopes...");
    button.setPreferredSize(new Dimension(230, button.getPreferredSize().height));
    panel.add(button, gc);
    gc.gridx = GridBagConstraints.REMAINDER;
    gc.weightx = 1;
    panel.add(new JPanel(), gc);
    gc.gridy++;
    gc.gridx = 0;
    gc.weighty = 1;
    panel.add(new JPanel(), gc);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            DataContext context = DataManager.getInstance().getDataContext(panel);
            Settings settings = Settings.KEY.getData(context);
            Project project = CommonDataKeys.PROJECT.getData(context);
            if (settings != null) {
                try {
                    if (settings.select(settings.find(ScopeChooserConfigurable.PROJECT_SCOPES)).isRejected()) {
                        EditScopesDialog.showDialog(project, null);
                    }
                } catch (IllegalStateException ex) {
                    EditScopesDialog.showDialog(project, null);
                }
            }
        }
    });
    return panel;
}
Also used : ActionEvent(java.awt.event.ActionEvent) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ActionListener(java.awt.event.ActionListener) Settings(com.intellij.openapi.options.ex.Settings)

Example 82 with DataContext

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

the class PasteHandler method execute.

@Override
public void execute(final Editor editor, final DataContext dataContext, @Nullable final Producer<Transferable> producer) {
    final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer);
    if (transferable == null)
        return;
    if (!EditorModificationUtil.checkModificationAllowed(editor))
        return;
    final Document document = editor.getDocument();
    if (!EditorModificationUtil.requestWriting(editor)) {
        return;
    }
    DataContext context = new DataContext() {

        @Override
        public Object getData(@NonNls String dataId) {
            return PasteAction.TRANSFERABLE_PROVIDER.is(dataId) ? (Producer<Transferable>) () -> transferable : dataContext.getData(dataId);
        }
    };
    final Project project = editor.getProject();
    if (project == null || editor.isColumnMode() || editor.getCaretModel().getCaretCount() > 1) {
        if (myOriginalHandler != null) {
            myOriginalHandler.execute(editor, null, context);
        }
        return;
    }
    final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
    if (file == null) {
        if (myOriginalHandler != null) {
            myOriginalHandler.execute(editor, null, context);
        }
        return;
    }
    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
    document.startGuardedBlockChecking();
    try {
        for (PasteProvider provider : Extensions.getExtensions(EP_NAME)) {
            if (provider.isPasteEnabled(context)) {
                provider.performPaste(context);
                return;
            }
        }
        doPaste(editor, project, file, document, transferable);
    } catch (ReadOnlyFragmentModificationException e) {
        EditorActionManager.getInstance().getReadonlyFragmentModificationHandler(document).handle(e);
    } finally {
        document.stopGuardedBlockChecking();
        DumbService.getInstance(project).setAlternativeResolveEnabled(false);
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PasteProvider(com.intellij.ide.PasteProvider) Transferable(java.awt.datatransfer.Transferable) PsiFile(com.intellij.psi.PsiFile)

Example 83 with DataContext

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

the class LongLineInspection method createOptionsPanel.

@Nullable
@Override
public JComponent createOptionsPanel() {
    final HyperlinkLabel codeStyleHyperlink = new HyperlinkLabel("Edit Code Style settings");
    codeStyleHyperlink.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {

                @Override
                public void consume(DataContext context) {
                    if (context != null) {
                        final Settings settings = Settings.KEY.getData(context);
                        if (settings != null) {
                            settings.select(settings.find(CodeStyleSchemesConfigurable.class));
                        } else {
                            ShowSettingsUtil.getInstance().showSettingsDialog(CommonDataKeys.PROJECT.getData(context), CodeStyleSchemesConfigurable.class);
                        }
                    }
                }
            });
        }
    });
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(codeStyleHyperlink, BorderLayout.NORTH);
    return panel;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) CodeStyleSchemesConfigurable(com.intellij.application.options.CodeStyleSchemesConfigurable) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Consumer(com.intellij.util.Consumer) HyperlinkListener(javax.swing.event.HyperlinkListener) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) Settings(com.intellij.openapi.options.ex.Settings) Nullable(org.jetbrains.annotations.Nullable)

Example 84 with DataContext

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

the class ExecutionManagerImpl method compileAndRun.

@Override
public void compileAndRun(@NotNull final Runnable startRunnable, @NotNull final ExecutionEnvironment environment, @Nullable final RunProfileState state, @Nullable final Runnable onCancelRunnable) {
    long id = environment.getExecutionId();
    if (id == 0) {
        id = environment.assignNewExecutionId();
    }
    RunProfile profile = environment.getRunProfile();
    if (!(profile instanceof RunConfiguration)) {
        startRunnable.run();
        return;
    }
    final RunConfiguration runConfiguration = (RunConfiguration) profile;
    final List<BeforeRunTask> beforeRunTasks = RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(runConfiguration);
    if (beforeRunTasks.isEmpty()) {
        startRunnable.run();
    } else {
        DataContext context = environment.getDataContext();
        final DataContext projectContext = context != null ? context : SimpleDataContext.getProjectContext(myProject);
        final long finalId = id;
        final Long executionSessionId = new Long(id);
        ApplicationManager.getApplication().executeOnPooledThread(() -> {
            for (BeforeRunTask task : beforeRunTasks) {
                if (myProject.isDisposed()) {
                    return;
                }
                @SuppressWarnings("unchecked") BeforeRunTaskProvider<BeforeRunTask> provider = BeforeRunTaskProvider.getProvider(myProject, task.getProviderId());
                if (provider == null) {
                    LOG.warn("Cannot find BeforeRunTaskProvider for id='" + task.getProviderId() + "'");
                    continue;
                }
                ExecutionEnvironment taskEnvironment = new ExecutionEnvironmentBuilder(environment).contentToReuse(null).build();
                taskEnvironment.setExecutionId(finalId);
                EXECUTION_SESSION_ID_KEY.set(taskEnvironment, executionSessionId);
                if (!provider.executeTask(projectContext, runConfiguration, taskEnvironment, task)) {
                    if (onCancelRunnable != null) {
                        SwingUtilities.invokeLater(onCancelRunnable);
                    }
                    return;
                }
            }
            doRun(environment, startRunnable);
        });
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunProfile(com.intellij.execution.configurations.RunProfile) CompatibilityAwareRunProfile(com.intellij.execution.configuration.CompatibilityAwareRunProfile) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder)

Example 85 with DataContext

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

the class ProjectStartupConfigurable method createNewWrapper.

private ChooseRunConfigurationPopup.ItemWrapper<Void> createNewWrapper(final AnActionButton button) {
    return new ChooseRunConfigurationPopup.ItemWrapper<Void>(null) {

        @Override
        public Icon getIcon() {
            return IconUtil.getAddIcon();
        }

        @Override
        public String getText() {
            return UIUtil.removeMnemonic(ExecutionBundle.message("add.new.run.configuration.acrtion.name"));
        }

        @Override
        public void perform(@NotNull final Project project, @NotNull final Executor executor, @NotNull DataContext context) {
            final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(project);
            final ConfigurationType[] factories = runManager.getConfigurationFactories();
            final Condition<ConfigurationType> filter = new Condition<ConfigurationType>() {

                private final RunnerRegistry myRegistry = RunnerRegistry.getInstance();

                @Override
                public boolean value(ConfigurationType configurationType) {
                    ConfigurationFactory factory;
                    return !UnknownConfigurationType.INSTANCE.equals(configurationType) && ((factory = runManager.getFactory(configurationType.getId(), null)) != null) && myRegistry.getRunner(executor.getId(), runManager.getConfigurationTemplate(factory).getConfiguration()) != null;
                }
            };
            final List<ConfigurationType> factoriesList = ContainerUtil.filter(Arrays.asList(factories), filter);
            final ListPopup popup = NewRunConfigurationPopup.createAddPopup(factoriesList, "", factory -> ApplicationManager.getApplication().invokeLater(() -> {
                final EditConfigurationsDialog dialog = new EditConfigurationsDialog(project, factory);
                if (dialog.showAndGet()) {
                    ApplicationManager.getApplication().invokeLater(() -> {
                        RunnerAndConfigurationSettings configuration = RunManager.getInstance(project).getSelectedConfiguration();
                        if (configuration != null) {
                            addConfiguration(configuration);
                        }
                    }, ModalityState.any(), project.getDisposed());
                }
            }, ModalityState.any(), project.getDisposed()), null, EmptyRunnable.getInstance(), false);
            showPopup(button, popup);
        }

        @Override
        public boolean available(Executor executor) {
            return true;
        }
    };
}
Also used : ConfigurationType(com.intellij.execution.configurations.ConfigurationType) UnknownConfigurationType(com.intellij.execution.configurations.UnknownConfigurationType) Condition(com.intellij.openapi.util.Condition) EditConfigurationsDialog(com.intellij.execution.impl.EditConfigurationsDialog) ListPopup(com.intellij.openapi.ui.popup.ListPopup) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) RunManagerImpl(com.intellij.execution.impl.RunManagerImpl)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)204 Project (com.intellij.openapi.project.Project)73 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)22 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)17 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 DataManager (com.intellij.ide.DataManager)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 List (java.util.List)9 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6