simplify getting project from AnActionEvent

This commit is contained in:
Konstantin Bulenkov
2016-05-24 02:11:08 +02:00
parent 3ccad56e89
commit 2499aa71ec
7 changed files with 37 additions and 43 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -42,7 +42,7 @@ public abstract class AbstractIntegrateChangesAction<T extends SelectedCommitted
protected abstract T createChecker();
public final void update(final AnActionEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final Project project = e.getProject();
final CommittedChangesBrowserUseCase useCase = CommittedChangesBrowserUseCase.DATA_KEY.getData(e.getDataContext());
final Presentation presentation = e.getPresentation();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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,7 +17,6 @@ package org.jetbrains.idea.svn.branchConfig;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
@@ -31,7 +30,7 @@ import org.jetbrains.idea.svn.history.SvnChangeList;
public class ConfigureBranchesAction extends AnAction implements DumbAware {
public void update(final AnActionEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final Project project = e.getProject();
final Presentation presentation = e.getPresentation();
if (project == null) {
@@ -53,7 +52,7 @@ public class ConfigureBranchesAction extends AnAction implements DumbAware {
}
public void actionPerformed(final AnActionEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final Project project = e.getProject();
final ChangeList[] cls = e.getData(VcsDataKeys.CHANGE_LISTS);
if ((cls == null) || (cls.length == 0) ||
(! SvnVcs.getInstance(project).getName().equals(((CommittedChangeList) cls[0]).getVcs().getName())) ||
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -301,7 +301,7 @@ public class PropertiesComponent extends JPanel {
}
public void actionPerformed(AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
PropertyValue propValue = null;
try {
propValue = myVcs.getFactory(myFile).createPropertyClient()
@@ -343,7 +343,7 @@ public class PropertiesComponent extends JPanel {
}
public void actionPerformed(AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
SetPropertyDialog dialog = new SetPropertyDialog(project, new File[]{myFile}, null,
myFile.isDirectory());
boolean recursive = false;
@@ -364,7 +364,7 @@ public class PropertiesComponent extends JPanel {
}
public void actionPerformed(AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
SetPropertyDialog dialog = new SetPropertyDialog(project, new File[]{myFile}, getSelectedPropertyName(), myFile.isDirectory());
boolean recursive = false;
if (dialog.showAndGet()) {
@@ -407,7 +407,7 @@ public class PropertiesComponent extends JPanel {
File f = new File(vf.getPath());
if (!f.equals(myFile)) {
setFile(myVcs, f);
Project p = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project p = e.getProject();
ToolWindowManager.getInstance(p).getToolWindow(ID).setTitle(f.getName());
}
@@ -1,25 +1,23 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.tasks.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.LocalTask;
@@ -50,7 +48,7 @@ public abstract class BaseTaskAction extends AnAction implements DumbAware {
@Nullable
public static Project getProject(@Nullable AnActionEvent event) {
return event == null ? null : CommonDataKeys.PROJECT.getData(event.getDataContext());
return event == null ? null : event.getProject();
}
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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,7 +17,6 @@
package com.intellij.tasks.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
@@ -33,7 +32,7 @@ import com.intellij.tasks.impl.TaskManagerImpl;
public class CloseTaskAction extends BaseTaskAction {
public void actionPerformed(AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
assert project != null;
TaskManagerImpl taskManager = (TaskManagerImpl)TaskManager.getManager(project);
LocalTask task = taskManager.getActiveTask();
@@ -1,24 +1,23 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2016 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.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.tasks.actions;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.tasks.TaskManager;
@@ -54,7 +53,7 @@ public class OpenTaskInBrowserAction extends BaseTaskAction {
@Nullable
private static String getIssueUrl(AnActionEvent event) {
Project project = CommonDataKeys.PROJECT.getData(event.getDataContext());
Project project = event.getProject();
return project == null ? null : TaskManager.getManager(project).getActiveTask().getIssueUrl();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2016 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,6 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.util.Consumer;
import com.intellij.util.NotNullFunction;
import com.jetbrains.python.console.PyCodeExecutor;
import com.jetbrains.python.console.PydevConsoleRunner;
import com.jetbrains.python.console.PythonConsoleRunnerFactory;
@@ -96,7 +95,7 @@ public class PyExecuteSelectionAction extends AnAction {
private static void execute(final AnActionEvent e, final String selectionText) {
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
Module module = e.getData(LangDataKeys.MODULE);
findCodeExecutor(e, codeExecutor -> executeInConsole(codeExecutor, selectionText, editor), editor, project, module);
@@ -246,7 +245,7 @@ public class PyExecuteSelectionAction extends AnAction {
}
private static boolean canFindConsole(AnActionEvent e) {
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
Project project = e.getProject();
if (project != null) {
Collection<RunContentDescriptor> descriptors = getConsoles(project);
return descriptors.size() > 0;