mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: move methods to util class
This commit is contained in:
+5
-11
@@ -37,7 +37,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -71,7 +70,7 @@ public class AnnotateLocalFileAction {
|
||||
|
||||
private static boolean isSuspended(AnActionEvent e) {
|
||||
VirtualFile file = assertNotNull(VcsContextFactory.SERVICE.getInstance().createContextOn(e).getSelectedFile());
|
||||
return AnnotateToggleAction.getBackgroundableLock(e.getRequiredData(CommonDataKeys.PROJECT), file).isLocked();
|
||||
return VcsAnnotateUtil.getBackgroundableLock(e.getRequiredData(CommonDataKeys.PROJECT), file).isLocked();
|
||||
}
|
||||
|
||||
private static boolean isAnnotated(AnActionEvent e) {
|
||||
@@ -129,7 +128,7 @@ public class AnnotateLocalFileAction {
|
||||
final Ref<FileAnnotation> fileAnnotationRef = new Ref<FileAnnotation>();
|
||||
final Ref<VcsException> exceptionRef = new Ref<VcsException>();
|
||||
|
||||
AnnotateToggleAction.getBackgroundableLock(project, file).lock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
|
||||
|
||||
final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {
|
||||
@Override
|
||||
@@ -155,7 +154,7 @@ public class AnnotateLocalFileAction {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
AnnotateToggleAction.getBackgroundableLock(project, file).unlock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
|
||||
|
||||
if (!exceptionRef.isNull()) {
|
||||
LOG.warn(exceptionRef.get());
|
||||
@@ -173,13 +172,8 @@ public class AnnotateLocalFileAction {
|
||||
@NotNull
|
||||
private static List<Editor> getEditors(@NotNull VcsContext context) {
|
||||
Project project = assertNotNull(context.getProject());
|
||||
List<Editor> list = new ArrayList<Editor>();
|
||||
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getEditors(context.getSelectedFile())) {
|
||||
if (fileEditor instanceof TextEditor) {
|
||||
list.add(((TextEditor)fileEditor).getEditor());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
VirtualFile file = assertNotNull(context.getSelectedFile());
|
||||
return VcsAnnotateUtil.getEditors(project, file);
|
||||
}
|
||||
|
||||
public static class Provider implements AnnotateToggleAction.Provider {
|
||||
|
||||
+3
-10
@@ -7,7 +7,6 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.AbstractVcsHelper;
|
||||
@@ -16,7 +15,6 @@ import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.annotate.AnnotationProvider;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.impl.BackgroundableActionLock;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.diff.Diff;
|
||||
import com.intellij.util.diff.FilesTooBigForDiffException;
|
||||
@@ -58,7 +56,7 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
AnnotationProvider provider = vcs.getCachingAnnotationProvider();
|
||||
if (provider == null || !provider.isAnnotationValid(fileRevision)) return false;
|
||||
|
||||
if (getBackgroundableLock(vcs.getProject(), file).isLocked()) return false;
|
||||
if (VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).isLocked()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -83,7 +81,7 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
final Ref<Integer> newLineRef = new Ref<Integer>();
|
||||
final Ref<VcsException> exceptionRef = new Ref<VcsException>();
|
||||
|
||||
getBackgroundableLock(vcs.getProject(), file).lock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).lock();
|
||||
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(vcs.getProject(), VcsBundle.message("retrieving.annotations"), true) {
|
||||
public void run(@NotNull ProgressIndicator indicator) {
|
||||
@@ -115,7 +113,7 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
getBackgroundableLock(vcs.getProject(), file).unlock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).unlock();
|
||||
|
||||
if (!exceptionRef.isNull()) {
|
||||
AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("operation.name.annotate"));
|
||||
@@ -126,9 +124,4 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static BackgroundableActionLock getBackgroundableLock(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
return AnnotateToggleAction.getBackgroundableLock(project, file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.annotate.LineAnnotationAspect;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.impl.BackgroundableActionLock;
|
||||
import com.intellij.openapi.vcs.impl.UpToDateLineNumberProviderImpl;
|
||||
import com.intellij.openapi.vcs.impl.VcsBackgroundableActions;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -236,11 +234,6 @@ public class AnnotateToggleAction extends ToggleAction implements DumbAware, Ann
|
||||
commitAuthorColors.size() > 1 ? commitAuthorColors : null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BackgroundableActionLock getBackgroundableLock(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
return BackgroundableActionLock.getLock(project, VcsBackgroundableActions.ANNOTATE, file.getPath());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Provider getProvider(AnActionEvent e) {
|
||||
for (Provider provider : EP_NAME.getExtensions()) {
|
||||
|
||||
+6
-21
@@ -19,9 +19,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
@@ -43,7 +40,6 @@ import com.intellij.vcsUtil.VcsUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -60,7 +56,7 @@ public class AnnotateVcsVirtualFileAction {
|
||||
VirtualFile file = selectedFiles[0];
|
||||
if (file.isDirectory() || file.getFileType().isBinary()) return false;
|
||||
|
||||
if (getEditors(project, file).isEmpty()) return false;
|
||||
if (VcsAnnotateUtil.getEditors(project, file).isEmpty()) return false;
|
||||
|
||||
AnnotationData data = extractData(project, file);
|
||||
if (data == null) return false;
|
||||
@@ -71,13 +67,13 @@ public class AnnotateVcsVirtualFileAction {
|
||||
|
||||
private static boolean isSuspended(AnActionEvent e) {
|
||||
VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY)[0];
|
||||
return AnnotateToggleAction.getBackgroundableLock(e.getRequiredData(CommonDataKeys.PROJECT), file).isLocked();
|
||||
return VcsAnnotateUtil.getBackgroundableLock(e.getRequiredData(CommonDataKeys.PROJECT), file).isLocked();
|
||||
}
|
||||
|
||||
private static boolean isAnnotated(AnActionEvent e) {
|
||||
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY)[0];
|
||||
List<Editor> editors = getEditors(project, file);
|
||||
List<Editor> editors = VcsAnnotateUtil.getEditors(project, file);
|
||||
return ContainerUtil.exists(editors, new Condition<Editor>() {
|
||||
@Override
|
||||
public boolean value(Editor editor) {
|
||||
@@ -89,7 +85,7 @@ public class AnnotateVcsVirtualFileAction {
|
||||
private static void perform(AnActionEvent e, boolean selected) {
|
||||
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
final VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE_ARRAY)[0];
|
||||
List<Editor> editors = getEditors(project, file);
|
||||
List<Editor> editors = VcsAnnotateUtil.getEditors(project, file);
|
||||
|
||||
if (!selected) {
|
||||
for (Editor editor : editors) {
|
||||
@@ -113,7 +109,7 @@ public class AnnotateVcsVirtualFileAction {
|
||||
final Ref<FileAnnotation> fileAnnotationRef = new Ref<FileAnnotation>();
|
||||
final Ref<VcsException> exceptionRef = new Ref<VcsException>();
|
||||
|
||||
AnnotateToggleAction.getBackgroundableLock(project, file).lock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(project, file).lock();
|
||||
|
||||
final Task.Backgroundable annotateTask = new Task.Backgroundable(project, VcsBundle.message("retrieving.annotations"), true) {
|
||||
@Override
|
||||
@@ -139,7 +135,7 @@ public class AnnotateVcsVirtualFileAction {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
AnnotateToggleAction.getBackgroundableLock(project, file).unlock();
|
||||
VcsAnnotateUtil.getBackgroundableLock(project, file).unlock();
|
||||
|
||||
if (!exceptionRef.isNull()) {
|
||||
LOG.warn(exceptionRef.get());
|
||||
@@ -154,17 +150,6 @@ public class AnnotateVcsVirtualFileAction {
|
||||
ProgressManager.getInstance().run(annotateTask);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Editor> getEditors(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
List<Editor> list = new ArrayList<Editor>();
|
||||
for (FileEditor fileEditor : FileEditorManager.getInstance(project).getEditors(file)) {
|
||||
if (fileEditor instanceof TextEditor) {
|
||||
list.add(((TextEditor)fileEditor).getEditor());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AnnotationData extractData(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
FilePath filePath = null;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.actions;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.impl.BackgroundableActionLock;
|
||||
import com.intellij.openapi.vcs.impl.VcsBackgroundableActions;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class VcsAnnotateUtil {
|
||||
@NotNull
|
||||
public static List<Editor> getEditors(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
FileEditor[] editors = FileEditorManager.getInstance(project).getEditors(file);
|
||||
return ContainerUtil.mapNotNull(editors, new Function<FileEditor, Editor>() {
|
||||
@Override
|
||||
public Editor fun(FileEditor fileEditor) {
|
||||
return fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BackgroundableActionLock getBackgroundableLock(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
return BackgroundableActionLock.getLock(project, VcsBackgroundableActions.ANNOTATE, file.getPath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user