mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:10:43 +07:00
move TransferableWrapper to platforrm-impl to re-use ProjectViewDropTarget functionality (moved to FileCopyPasteUtil)
This commit is contained in:
@@ -17,7 +17,7 @@ package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.dnd.*;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.projectView.impl.TransferableWrapper;
|
||||
import com.intellij.ide.dnd.TransferableWrapper;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.intellij.ide.dnd.DnDManager;
|
||||
import com.intellij.ide.dnd.DnDSource;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.projectView.impl.ProjectViewTree;
|
||||
import com.intellij.ide.projectView.impl.TransferableWrapper;
|
||||
import com.intellij.ide.dnd.TransferableWrapper;
|
||||
import com.intellij.ide.util.scopeChooser.EditScopesDialog;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.intellij.ide.navigationToolbar.ui.NavBarUIManager;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.projectView.impl.AbstractProjectViewPane;
|
||||
import com.intellij.ide.projectView.impl.ProjectRootsUtil;
|
||||
import com.intellij.ide.projectView.impl.TransferableWrapper;
|
||||
import com.intellij.ide.dnd.TransferableWrapper;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.ide.ui.customization.CustomActionsSchema;
|
||||
import com.intellij.ide.util.DeleteHandler;
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.dnd.DnDEvent;
|
||||
import com.intellij.ide.dnd.DnDNativeTarget;
|
||||
import com.intellij.ide.dnd.FileCopyPasteUtil;
|
||||
import com.intellij.ide.dnd.TransferableWrapper;
|
||||
import com.intellij.ide.projectView.impl.nodes.DropTargetNode;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
@@ -103,8 +104,8 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
else {
|
||||
// it seems like it's not possible to obtain dragged items _before_ accepting _drop_ on Macs, so just skip this check
|
||||
if (!SystemInfo.isMac) {
|
||||
final PsiFileSystemItem[] psiFiles = getPsiFiles(getFileListFromAttachedObject(attached));
|
||||
if (psiFiles == null) return false;
|
||||
final PsiFileSystemItem[] psiFiles = getPsiFiles(FileCopyPasteUtil.getFileListFromAttachedObject(attached));
|
||||
if (psiFiles == null || psiFiles.length == 0) return false;
|
||||
if (!MoveHandler.isValidTarget(getPsiElement(targetNode), psiFiles)) return false;
|
||||
}
|
||||
}
|
||||
@@ -115,17 +116,6 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<File> getFileListFromAttachedObject(Object attached) {
|
||||
if (attached instanceof TransferableWrapper) {
|
||||
return ((TransferableWrapper)attached).asFileList();
|
||||
}
|
||||
else if (attached instanceof EventInfo) {
|
||||
return FileCopyPasteUtil.getFileList(((EventInfo)attached).getTransferable());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(DnDEvent event) {
|
||||
final Object attached = event.getAttachedObject();
|
||||
@@ -135,8 +125,8 @@ class ProjectViewDropTarget implements DnDNativeTarget {
|
||||
final int dropAction = event.getAction().getActionId();
|
||||
if (sourceNodes == null) {
|
||||
if (FileCopyPasteUtil.isFileListFlavorSupported(event)) {
|
||||
final List<File> fileList = getFileListFromAttachedObject(attached);
|
||||
if (fileList != null) {
|
||||
List<File> fileList = FileCopyPasteUtil.getFileListFromAttachedObject(attached);
|
||||
if (!fileList.isEmpty()) {
|
||||
getDropHandler(dropAction).doDropFiles(fileList, targetNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package com.intellij.ide.dnd;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,6 +29,8 @@ import java.awt.datatransfer.FlavorMap;
|
||||
import java.awt.datatransfer.SystemFlavorMap;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -115,4 +119,34 @@ public class FileCopyPasteUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<File> getFileListFromAttachedObject(Object attached) {
|
||||
List<File> result;
|
||||
if (attached instanceof TransferableWrapper) {
|
||||
result = ((TransferableWrapper)attached).asFileList();
|
||||
}
|
||||
else if (attached instanceof DnDNativeTarget.EventInfo) {
|
||||
result = getFileList(((DnDNativeTarget.EventInfo)attached).getTransferable());
|
||||
}
|
||||
else {
|
||||
result = null;
|
||||
}
|
||||
return result == null? Collections.<File>emptyList() : result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<VirtualFile> getVirtualFileListFromAttachedObject(Object attached) {
|
||||
List<VirtualFile> result;
|
||||
List<File> fileList = getFileListFromAttachedObject(attached);
|
||||
if (fileList.isEmpty()) {
|
||||
result = Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
result = new ArrayList<VirtualFile>(fileList.size());
|
||||
for (File file : fileList) {
|
||||
ContainerUtil.addIfNotNull(result, VfsUtil.findFileByIoFile(file, true));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.projectView.impl;
|
||||
package com.intellij.ide.dnd;
|
||||
|
||||
import com.intellij.ide.dnd.FileFlavorProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
Reference in New Issue
Block a user