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;
}
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);
}
}
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;
}
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);
});
}
}
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;
}
};
}
Aggregations