mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use DataContext instead of AnActionEvent
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,7 @@ public abstract class MavenProjectsNavigatorAction extends MavenToggleAction {
|
||||
}
|
||||
|
||||
private MavenProjectsNavigator getNavigator(AnActionEvent e) {
|
||||
return MavenProjectsNavigator.getInstance(MavenActionUtil.getProject(e));
|
||||
return MavenProjectsNavigator.getInstance(MavenActionUtil.getProject(e.getDataContext()));
|
||||
}
|
||||
|
||||
protected abstract boolean isSelected(MavenProjectsNavigator navigator);
|
||||
|
||||
+14
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,10 @@
|
||||
package org.jetbrains.idea.maven.project.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenAction;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
@@ -27,16 +29,18 @@ import java.util.Collections;
|
||||
public class AddFileAsMavenProjectAction extends MavenAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e);
|
||||
manager.addManagedFiles(Collections.singletonList(getSelectedFile(e)));
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(context);
|
||||
manager.addManagedFiles(Collections.singletonList(getSelectedFile(context)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
VirtualFile file = getSelectedFile(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
VirtualFile file = getSelectedFile(context);
|
||||
return super.isAvailable(e)
|
||||
&& MavenActionUtil.isMavenProjectFile(file)
|
||||
&& !isExistingProjectFile(e, file);
|
||||
&& !isExistingProjectFile(context, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,12 +48,13 @@ public class AddFileAsMavenProjectAction extends MavenAction {
|
||||
return super.isVisible(e) && isAvailable(e);
|
||||
}
|
||||
|
||||
private boolean isExistingProjectFile(AnActionEvent e, VirtualFile file) {
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e);
|
||||
private static boolean isExistingProjectFile(DataContext context, VirtualFile file) {
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(context);
|
||||
return manager.findProject(file) != null;
|
||||
}
|
||||
|
||||
private VirtualFile getSelectedFile(AnActionEvent e) {
|
||||
return e.getData(PlatformDataKeys.VIRTUAL_FILE);
|
||||
@Nullable
|
||||
private static VirtualFile getSelectedFile(DataContext context) {
|
||||
return PlatformDataKeys.VIRTUAL_FILE.getData(context);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import java.util.Arrays;
|
||||
public class AddManagedFilesAction extends MavenAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e);
|
||||
final MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
|
||||
FileChooserDescriptor singlePomSelection = new FileChooserDescriptor(true, false, false, false, false, true) {
|
||||
@Override
|
||||
public boolean isFileSelectable(VirtualFile file) {
|
||||
@@ -45,7 +45,7 @@ public class AddManagedFilesAction extends MavenAction {
|
||||
}
|
||||
};
|
||||
|
||||
Project project = MavenActionUtil.getProject(e);
|
||||
Project project = MavenActionUtil.getProject(e.getDataContext());
|
||||
VirtualFile fileToSelect = e.getData(PlatformDataKeys.VIRTUAL_FILE);
|
||||
|
||||
FileChooserDialog dialog = FileChooserFactory.getInstance().createFileChooser(singlePomSelection, project);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.idea.maven.utils.MavenSettings;
|
||||
public class EditSettingsAction extends MavenAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
showSettingsFor(MavenActionUtil.getProject(e));
|
||||
showSettingsFor(MavenActionUtil.getProject(e.getDataContext()));
|
||||
}
|
||||
|
||||
protected void showSettingsFor(Project project) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ public abstract class MavenOpenOrCreateFilesAction extends MavenAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Project project = MavenActionUtil.getProject(e);
|
||||
final Project project = MavenActionUtil.getProject(e.getDataContext());
|
||||
final List<File> files = getFiles(e);
|
||||
final List<VirtualFile> virtualFiles = collectVirtualFiles(files);
|
||||
|
||||
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.project.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenAction;
|
||||
@@ -26,12 +27,13 @@ import java.util.List;
|
||||
public abstract class MavenProjectsAction extends MavenAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return super.isAvailable(e) && !MavenActionUtil.getMavenProjects(e).isEmpty();
|
||||
return super.isAvailable(e) && !MavenActionUtil.getMavenProjects(e.getDataContext()).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
perform(MavenActionUtil.getProjectsManager(e), MavenActionUtil.getMavenProjects(e), e);
|
||||
final DataContext context = e.getDataContext();
|
||||
perform(MavenActionUtil.getProjectsManager(context), MavenActionUtil.getMavenProjects(context), e);
|
||||
}
|
||||
|
||||
protected abstract void perform(MavenProjectsManager manager, List<MavenProject> mavenProjects, AnActionEvent e);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
public abstract class MavenProjectsManagerAction extends MavenAction {
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
perform(MavenActionUtil.getProjectsManager(e));
|
||||
perform(MavenActionUtil.getProjectsManager(e.getDataContext()));
|
||||
}
|
||||
|
||||
protected abstract void perform(MavenProjectsManager manager);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
public class OpenOrCreateProfilesXmlAction extends MavenOpenOrCreateFilesAction {
|
||||
protected List<File> getFiles(AnActionEvent e) {
|
||||
List<File> result = new ArrayList<File>();
|
||||
for (MavenProject each : MavenActionUtil.getMavenProjects(e)) {
|
||||
for (MavenProject each : MavenActionUtil.getMavenProjects(e.getDataContext())) {
|
||||
result.add(each.getProfilesXmlIoFile());
|
||||
}
|
||||
return result;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
|
||||
public class OpenOrCreateSettingsXmlAction extends MavenOpenOrCreateFilesAction {
|
||||
protected List<File> getFiles(AnActionEvent e) {
|
||||
File file = MavenActionUtil.getProjectsManager(e).getGeneralSettings().getEffectiveUserSettingsIoFile();
|
||||
File file = MavenActionUtil.getProjectsManager(e.getDataContext()).getGeneralSettings().getEffectiveUserSettingsIoFile();
|
||||
return file != null ? Collections.singletonList(file) : Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.project.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenAction;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
@@ -23,14 +24,16 @@ import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
public class RemoveManagedFilesAction extends MavenAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
for (VirtualFile each : MavenActionUtil.getMavenProjectsFiles(e)) {
|
||||
if (MavenActionUtil.getProjectsManager(e).isManagedFile(each)) return true;
|
||||
final DataContext context = e.getDataContext();
|
||||
for (VirtualFile each : MavenActionUtil.getMavenProjectsFiles(context)) {
|
||||
if (MavenActionUtil.getProjectsManager(context).isManagedFile(each)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
MavenActionUtil.getProjectsManager(e).removeManagedFiles(MavenActionUtil.getMavenProjectsFiles(e));
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenActionUtil.getProjectsManager(context).removeManagedFiles(MavenActionUtil.getMavenProjectsFiles(context));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.project.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import org.jetbrains.idea.maven.execution.MavenRunConfigurationType;
|
||||
import org.jetbrains.idea.maven.execution.MavenRunnerParameters;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
@@ -28,26 +29,28 @@ import java.util.List;
|
||||
public class RunBuildAction extends MavenAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return super.isAvailable(e) && checkOrPerform(e, false);
|
||||
return super.isAvailable(e) && checkOrPerform(e.getDataContext(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
checkOrPerform(e, true);
|
||||
checkOrPerform(e.getDataContext(), true);
|
||||
}
|
||||
|
||||
private boolean checkOrPerform(AnActionEvent e, boolean perform) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(e);
|
||||
private static boolean checkOrPerform(DataContext context, boolean perform) {
|
||||
final MavenProject project = MavenActionUtil.getMavenProject(context);
|
||||
if (project == null) return false;
|
||||
|
||||
List<String> goals = e.getData(MavenDataKeys.MAVEN_GOALS);
|
||||
final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
|
||||
if (goals == null || goals.isEmpty()) return false;
|
||||
|
||||
if (!perform) return true;
|
||||
|
||||
MavenRunnerParameters params = new MavenRunnerParameters(
|
||||
true, project.getDirectory(), goals, MavenActionUtil.getProjectsManager(e).getExplicitProfiles());
|
||||
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(e), params, e.getDataContext(), null);
|
||||
final MavenRunnerParameters params = new MavenRunnerParameters(true,
|
||||
project.getDirectory(),
|
||||
goals,
|
||||
MavenActionUtil.getProjectsManager(context).getExplicitProfiles());
|
||||
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(context), params, context, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+12
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.project.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.options.ShowSettingsUtil;
|
||||
import org.jetbrains.idea.maven.project.MavenIgnoredFilesConfigurable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
@@ -32,8 +33,9 @@ public class ToggleIgnoredProjectsAction extends MavenAction {
|
||||
super.update(e);
|
||||
if (!isAvailable(e)) return;
|
||||
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
|
||||
|
||||
if (isIgnoredInSettings(projectsManager, projects)) {
|
||||
e.getPresentation().setText(ProjectBundle.message("maven.ignore.edit"));
|
||||
@@ -50,8 +52,9 @@ public class ToggleIgnoredProjectsAction extends MavenAction {
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
if (!super.isAvailable(e)) return false;
|
||||
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
|
||||
|
||||
if (projects == null || projects.isEmpty()) return false;
|
||||
|
||||
@@ -81,11 +84,12 @@ public class ToggleIgnoredProjectsAction extends MavenAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(context);
|
||||
List<MavenProject> projects = MavenActionUtil.getMavenProjects(context);
|
||||
|
||||
if (isIgnoredInSettings(projectsManager, projects)) {
|
||||
ShowSettingsUtil.getInstance().editConfigurable(MavenActionUtil.getProject(e), new MavenIgnoredFilesConfigurable(projectsManager));
|
||||
ShowSettingsUtil.getInstance().editConfigurable(MavenActionUtil.getProject(context), new MavenIgnoredFilesConfigurable(projectsManager));
|
||||
}
|
||||
else {
|
||||
projectsManager.setIgnoredState(projects, !isIgnored(projectsManager, projects));
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,11 +22,11 @@ import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
public class ToggleOfflineAction extends MavenToggleAction {
|
||||
@Override
|
||||
protected boolean doIsSelected(AnActionEvent e) {
|
||||
return MavenActionUtil.getProjectsManager(e).getGeneralSettings().isWorkOffline();
|
||||
return MavenActionUtil.getProjectsManager(e.getDataContext()).getGeneralSettings().isWorkOffline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
MavenActionUtil.getProjectsManager(e).getGeneralSettings().setWorkOffline(state);
|
||||
MavenActionUtil.getProjectsManager(e.getDataContext()).getGeneralSettings().setWorkOffline(state);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ public class ToggleProfileAction extends MavenAction {
|
||||
super.update(e);
|
||||
if (!isAvailable(e)) return;
|
||||
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e);
|
||||
MavenProjectsManager projectsManager = MavenActionUtil.getProjectsManager(e.getDataContext());
|
||||
List<String> profiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
|
||||
|
||||
e.getPresentation().setText(isActive(projectsManager, profiles)
|
||||
@@ -45,7 +45,7 @@ public class ToggleProfileAction extends MavenAction {
|
||||
List<String> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
|
||||
if (selectedProfiles == null || selectedProfiles.isEmpty()) return false;
|
||||
|
||||
Collection<String> activeProfiles = MavenActionUtil.getProjectsManager(e).getExplicitProfiles();
|
||||
Collection<String> activeProfiles = MavenActionUtil.getProjectsManager(e.getDataContext()).getExplicitProfiles();
|
||||
int activeCount = 0;
|
||||
for (String profile : selectedProfiles) {
|
||||
if (activeProfiles.contains(profile)) {
|
||||
@@ -61,7 +61,7 @@ public class ToggleProfileAction extends MavenAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e);
|
||||
MavenProjectsManager manager = MavenActionUtil.getProjectsManager(e.getDataContext());
|
||||
List<String> selectedProfiles = e.getData(MavenDataKeys.MAVEN_PROFILES);
|
||||
|
||||
Collection<String> activeProfiles = manager.getExplicitProfiles();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,11 +23,11 @@ import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
public class ToggleSkipTestsAction extends MavenToggleAction {
|
||||
@Override
|
||||
protected boolean doIsSelected(AnActionEvent e) {
|
||||
return MavenRunner.getInstance(MavenActionUtil.getProject(e)).getState().isSkipTests();
|
||||
return MavenRunner.getInstance(MavenActionUtil.getProject(e.getDataContext())).getState().isSkipTests();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state){
|
||||
MavenRunner.getInstance(MavenActionUtil.getProject(e)).getState().setSkipTests(state);
|
||||
MavenRunner.getInstance(MavenActionUtil.getProject(e.getDataContext())).getState().setSkipTests(state);
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,10 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.tasks;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.keymap.KeymapExtension;
|
||||
import com.intellij.openapi.keymap.KeymapGroup;
|
||||
import com.intellij.openapi.keymap.KeymapGroupFactory;
|
||||
@@ -182,11 +179,12 @@ public class MavenKeymapExtension implements KeymapExtension {
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final DataContext context = e.getDataContext();
|
||||
MavenRunnerParameters params = new MavenRunnerParameters(true,
|
||||
myMavenProject.getDirectory(),
|
||||
Arrays.asList(myGoal),
|
||||
MavenActionUtil.getProjectsManager(e).getExplicitProfiles());
|
||||
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(e), params, e.getDataContext(), null);
|
||||
MavenActionUtil.getProjectsManager(context).getExplicitProfiles());
|
||||
MavenRunConfigurationType.runConfiguration(MavenActionUtil.getProject(context), params, context, null);
|
||||
}
|
||||
|
||||
public MavenProject getMavenProject() {
|
||||
|
||||
+16
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.tasks.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.keymap.impl.ui.EditKeymapsDialog;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
@@ -29,35 +30,37 @@ import java.util.List;
|
||||
public class AssignShortcutAction extends MavenAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return super.isAvailable(e) && !isIgnoredProject(e) && getGoalActionId(e) != null;
|
||||
final DataContext context = e.getDataContext();
|
||||
return super.isAvailable(e) && !isIgnoredProject(context) && getGoalActionId(context) != null;
|
||||
}
|
||||
|
||||
private boolean isIgnoredProject(AnActionEvent e) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(e);
|
||||
private static boolean isIgnoredProject(DataContext context) {
|
||||
final MavenProject project = MavenActionUtil.getMavenProject(context);
|
||||
if (project == null) return false;
|
||||
return MavenActionUtil.getProjectsManager(e).isIgnored(project);
|
||||
return MavenActionUtil.getProjectsManager(context).isIgnored(project);
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
String actionId = getGoalActionId(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
String actionId = getGoalActionId(context);
|
||||
if (actionId != null) {
|
||||
new EditKeymapsDialog(MavenActionUtil.getProject(e), actionId).show();
|
||||
new EditKeymapsDialog(MavenActionUtil.getProject(context), actionId).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getGoalActionId(AnActionEvent e) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(e);
|
||||
private static String getGoalActionId(DataContext context) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(context);
|
||||
if (project == null) return null;
|
||||
|
||||
List<String> goals = e.getData(MavenDataKeys.MAVEN_GOALS);
|
||||
final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
|
||||
String goal = (goals == null || goals.size() != 1) ? null : goals.get(0);
|
||||
|
||||
return getShortcutsManager(e).getActionId(project.getPath(), goal);
|
||||
return getShortcutsManager(context).getActionId(project.getPath(), goal);
|
||||
}
|
||||
|
||||
protected MavenShortcutsManager getShortcutsManager(AnActionEvent e) {
|
||||
return MavenShortcutsManager.getInstance(MavenActionUtil.getProject(e));
|
||||
protected static MavenShortcutsManager getShortcutsManager(DataContext context) {
|
||||
return MavenShortcutsManager.getInstance(MavenActionUtil.getProject(context));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,49 +17,57 @@ package org.jetbrains.idea.maven.tasks.actions;
|
||||
|
||||
import com.intellij.execution.RunManagerEx;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.tasks.MavenBeforeRunTask;
|
||||
import org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider;
|
||||
import org.jetbrains.idea.maven.tasks.MavenTasksManager;
|
||||
import org.jetbrains.idea.maven.utils.MavenDataKeys;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenToggleAction;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenActionUtil;
|
||||
import org.jetbrains.idea.maven.utils.actions.MavenToggleAction;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ToggleBeforeRunTaskAction extends MavenToggleAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return super.isAvailable(e) && getTaskDesc(e) != null;
|
||||
return super.isAvailable(e) && getTaskDesc(e.getDataContext()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doIsSelected(AnActionEvent e) {
|
||||
Pair<MavenProject, String> desc = getTaskDesc(e);
|
||||
for (MavenBeforeRunTask each : getRunManager(e).getBeforeRunTasks(MavenBeforeRunTasksProvider.TASK_ID, true)) {
|
||||
if (each.isEnabled() && each.isFor(desc.first, desc.second)) return true;
|
||||
final DataContext context = e.getDataContext();
|
||||
final Pair<MavenProject, String> desc = getTaskDesc(context);
|
||||
if (desc != null) {
|
||||
for (MavenBeforeRunTask each : getRunManager(context).getBeforeRunTasks(MavenBeforeRunTasksProvider.TASK_ID, true)) {
|
||||
if (each.isEnabled() && each.isFor(desc.first, desc.second)) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(final AnActionEvent e, boolean state) {
|
||||
Pair<MavenProject, String> desc = getTaskDesc(e);
|
||||
new MavenExecuteBeforeRunDialog(MavenActionUtil.getProject(e), desc.first, desc.second).show();
|
||||
final DataContext context = e.getDataContext();
|
||||
final Pair<MavenProject, String> desc = getTaskDesc(context);
|
||||
if (desc != null) {
|
||||
new MavenExecuteBeforeRunDialog(MavenActionUtil.getProject(context), desc.first, desc.second).show();
|
||||
}
|
||||
}
|
||||
|
||||
protected Pair<MavenProject, String> getTaskDesc(AnActionEvent e) {
|
||||
MavenProject mavenProject = MavenActionUtil.getMavenProject(e);
|
||||
@Nullable
|
||||
protected static Pair<MavenProject, String> getTaskDesc(DataContext context) {
|
||||
MavenProject mavenProject = MavenActionUtil.getMavenProject(context);
|
||||
if (mavenProject == null) return null;
|
||||
|
||||
List<String> goals = e.getData(MavenDataKeys.MAVEN_GOALS);
|
||||
List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
|
||||
if (goals == null || goals.size() != 1) return null;
|
||||
|
||||
return Pair.create(mavenProject, goals.get(0));
|
||||
}
|
||||
|
||||
private RunManagerEx getRunManager(AnActionEvent e) {
|
||||
return RunManagerEx.getInstanceEx(MavenActionUtil.getProject(e));
|
||||
private static RunManagerEx getRunManager(DataContext context) {
|
||||
return RunManagerEx.getInstanceEx(MavenActionUtil.getProject(context));
|
||||
}
|
||||
}
|
||||
|
||||
+16
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.tasks.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.tasks.MavenCompilerTask;
|
||||
import org.jetbrains.idea.maven.tasks.MavenTasksManager;
|
||||
@@ -30,31 +31,33 @@ import java.util.List;
|
||||
public abstract class ToggleCompilerTasksAction extends MavenToggleAction {
|
||||
@Override
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return super.isAvailable(e) && !getTasks(e).isEmpty();
|
||||
return super.isAvailable(e) && !getTasks(e.getDataContext()).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doIsSelected(AnActionEvent e) {
|
||||
return hasTask(getTasksManager(e), getTasks(e).get(0));
|
||||
final DataContext context = e.getDataContext();
|
||||
return hasTask(getTasksManager(context), getTasks(context).get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
List<MavenCompilerTask> tasks = getTasks(e);
|
||||
final DataContext context = e.getDataContext();
|
||||
List<MavenCompilerTask> tasks = getTasks(context);
|
||||
if (state) {
|
||||
addTasks(getTasksManager(e), tasks);
|
||||
addTasks(getTasksManager(context), tasks);
|
||||
}
|
||||
else {
|
||||
removeTasks(getTasksManager(e), tasks);
|
||||
removeTasks(getTasksManager(context), tasks);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<MavenCompilerTask> getTasks(AnActionEvent e) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(e);
|
||||
if (project == null) return Collections.EMPTY_LIST;
|
||||
protected static List<MavenCompilerTask> getTasks(DataContext context) {
|
||||
MavenProject project = MavenActionUtil.getMavenProject(context);
|
||||
if (project == null) return Collections.emptyList();
|
||||
|
||||
List<String> goals = e.getData(MavenDataKeys.MAVEN_GOALS);
|
||||
if (goals == null || goals.isEmpty()) return Collections.EMPTY_LIST;
|
||||
final List<String> goals = MavenDataKeys.MAVEN_GOALS.getData(context);
|
||||
if (goals == null || goals.isEmpty()) return Collections.emptyList();
|
||||
|
||||
List<MavenCompilerTask> result = new ArrayList<MavenCompilerTask>();
|
||||
for (String each : goals) {
|
||||
@@ -69,7 +72,7 @@ public abstract class ToggleCompilerTasksAction extends MavenToggleAction {
|
||||
|
||||
protected abstract void removeTasks(MavenTasksManager manager, List<MavenCompilerTask> tasks);
|
||||
|
||||
private MavenTasksManager getTasksManager(AnActionEvent e) {
|
||||
return MavenTasksManager.getInstance(MavenActionUtil.getProject(e));
|
||||
private static MavenTasksManager getTasksManager(DataContext context) {
|
||||
return MavenTasksManager.getInstance(MavenActionUtil.getProject(context));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ public abstract class MavenAction extends AnAction implements DumbAware {
|
||||
}
|
||||
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return MavenActionUtil.getProject(e) != null;
|
||||
return MavenActionUtil.getProject(e.getDataContext()) != null;
|
||||
}
|
||||
|
||||
protected boolean isVisible(AnActionEvent e) {
|
||||
|
||||
+5
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.utils.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
|
||||
public class MavenActionGroup extends DefaultActionGroup {
|
||||
@@ -28,7 +29,8 @@ public class MavenActionGroup extends DefaultActionGroup {
|
||||
}
|
||||
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
if (MavenActionUtil.getProject(e) == null) return false;
|
||||
return !MavenActionUtil.getMavenProjects(e).isEmpty();
|
||||
final DataContext context = e.getDataContext();
|
||||
if (MavenActionUtil.getProject(context) == null) return false;
|
||||
return !MavenActionUtil.getMavenProjects(context).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
+31
-29
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.utils.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.project.MavenProject;
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager;
|
||||
import org.jetbrains.idea.maven.utils.MavenConstants;
|
||||
@@ -29,25 +30,25 @@ import org.jetbrains.idea.maven.utils.MavenUtil;
|
||||
import java.util.*;
|
||||
|
||||
public class MavenActionUtil {
|
||||
public static Project getProject(AnActionEvent e) {
|
||||
return e.getData(PlatformDataKeys.PROJECT);
|
||||
private MavenActionUtil() {
|
||||
}
|
||||
|
||||
public static MavenProjectsManager getProjectsManager(AnActionEvent e) {
|
||||
return MavenProjectsManager.getInstance(getProject(e));
|
||||
@Nullable
|
||||
public static Project getProject(DataContext context) {
|
||||
return PlatformDataKeys.PROJECT.getData(context);
|
||||
}
|
||||
|
||||
public static MavenProject getMavenProject(AnActionEvent e) {
|
||||
public static MavenProject getMavenProject(DataContext context) {
|
||||
MavenProject result;
|
||||
MavenProjectsManager manager = getProjectsManager(e);
|
||||
final MavenProjectsManager manager = getProjectsManager(context);
|
||||
|
||||
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
|
||||
final VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(context);
|
||||
if (file != null) {
|
||||
result = manager.findProject(file);
|
||||
if (result != null) return result;
|
||||
}
|
||||
|
||||
Module module = getModule(e);
|
||||
Module module = getModule(context);
|
||||
if (module != null) {
|
||||
result = manager.findProject(module);
|
||||
if (result != null) return result;
|
||||
@@ -56,48 +57,49 @@ public class MavenActionUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isMavenProject(AnActionEvent e) {
|
||||
return getMavenProject(e) != null;
|
||||
@Nullable
|
||||
private static Module getModule(DataContext context) {
|
||||
final Module module = DataKeys.MODULE.getData(context);
|
||||
return module != null ? module : DataKeys.MODULE_CONTEXT.getData(context);
|
||||
}
|
||||
|
||||
public static MavenProjectsManager getProjectsManager(DataContext context) {
|
||||
return MavenProjectsManager.getInstance(getProject(context));
|
||||
}
|
||||
|
||||
public static boolean isMavenProjectFile(VirtualFile file) {
|
||||
return file != null && !file.isDirectory() && MavenConstants.POM_XML.equals(file.getName());
|
||||
}
|
||||
|
||||
public static List<MavenProject> getMavenProjects(AnActionEvent e) {
|
||||
public static List<MavenProject> getMavenProjects(DataContext context) {
|
||||
Set<MavenProject> result = new LinkedHashSet<MavenProject>();
|
||||
for (VirtualFile each : getFiles(e)) {
|
||||
MavenProject project = getProjectsManager(e).findProject(each);
|
||||
for (VirtualFile each : getFiles(context)) {
|
||||
MavenProject project = getProjectsManager(context).findProject(each);
|
||||
if (project != null) result.add(project);
|
||||
}
|
||||
if (result.isEmpty()) {
|
||||
for (Module each : getModules(e)) {
|
||||
MavenProject project = getProjectsManager(e).findProject(each);
|
||||
for (Module each : getModules(context)) {
|
||||
MavenProject project = getProjectsManager(context).findProject(each);
|
||||
if (project != null) result.add(project);
|
||||
}
|
||||
}
|
||||
return new ArrayList<MavenProject>(result);
|
||||
}
|
||||
|
||||
public static List<VirtualFile> getMavenProjectsFiles(AnActionEvent e) {
|
||||
return MavenUtil.collectFiles(getMavenProjects(e));
|
||||
public static List<VirtualFile> getMavenProjectsFiles(DataContext context) {
|
||||
return MavenUtil.collectFiles(getMavenProjects(context));
|
||||
}
|
||||
|
||||
private static List<VirtualFile> getFiles(AnActionEvent e) {
|
||||
VirtualFile[] result = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
private static List<VirtualFile> getFiles(DataContext context) {
|
||||
VirtualFile[] result = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
|
||||
return result == null ? Collections.<VirtualFile>emptyList() : Arrays.asList(result);
|
||||
}
|
||||
|
||||
private static Module getModule(AnActionEvent e) {
|
||||
Module result = e.getData(DataKeys.MODULE);
|
||||
return result != null ? result : e.getData(DataKeys.MODULE_CONTEXT);
|
||||
}
|
||||
|
||||
private static List<Module> getModules(AnActionEvent e) {
|
||||
Module[] result = e.getData(DataKeys.MODULE_CONTEXT_ARRAY);
|
||||
private static List<Module> getModules(DataContext context) {
|
||||
Module[] result = DataKeys.MODULE_CONTEXT_ARRAY.getData(context);
|
||||
if (result != null) return Arrays.asList(result);
|
||||
|
||||
Module module = getModule(e);
|
||||
Module module = getModule(context);
|
||||
return module != null ? Collections.singletonList(module) : Collections.<Module>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ public abstract class MavenToggleAction extends ToggleAction implements DumbAwar
|
||||
}
|
||||
|
||||
protected boolean isAvailable(AnActionEvent e) {
|
||||
return MavenActionUtil.getProject(e) != null;
|
||||
return MavenActionUtil.getProject(e.getDataContext()) != null;
|
||||
}
|
||||
|
||||
public final boolean isSelected(AnActionEvent e) {
|
||||
|
||||
Reference in New Issue
Block a user