mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-04 07:35:24 +02:00
[181458] support for copy paste and drag and drop from rse to windows explorer
This commit is contained in:
parent
bb8214b649
commit
8a2f96ce75
6 changed files with 145 additions and 64 deletions
|
@ -771,7 +771,7 @@ public class SystemTableTreeView
|
|||
protected void initDragAndDrop()
|
||||
{
|
||||
int ops = DND.DROP_COPY | DND.DROP_MOVE;
|
||||
Transfer[] dragtransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
Transfer[] dragtransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
Transfer[] droptransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
|
||||
addDragSupport(ops, dragtransfers, new SystemViewDataDragAdapter((ISelectionProvider) this));
|
||||
|
|
|
@ -5238,6 +5238,7 @@ public class SystemView extends SafeTreeViewer
|
|||
int ops = DND.DROP_COPY | DND.DROP_MOVE;
|
||||
Transfer[] dragtransfers = new Transfer[]
|
||||
{ PluginTransfer.getInstance(),
|
||||
FileTransfer.getInstance(),
|
||||
EditorInputTransfer.getInstance()
|
||||
};
|
||||
|
||||
|
|
|
@ -19,8 +19,11 @@ package org.eclipse.rse.internal.ui.view;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -28,6 +31,7 @@ import org.eclipse.rse.core.model.IHost;
|
|||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
import org.eclipse.rse.core.subsystems.ISystemDragDropAdapter;
|
||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.rse.ui.actions.LazyDownloadJob;
|
||||
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter;
|
||||
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
|
||||
|
@ -226,23 +230,24 @@ public class SystemViewDataDragAdapter extends DragSourceAdapter
|
|||
String[] fileNames = new String[ss.size()];
|
||||
Iterator iterator = ss.iterator();
|
||||
int i = 0;
|
||||
//while (iterator.hasNext())
|
||||
//{
|
||||
iterator.next();
|
||||
/** FIXME - IREmoteFile is systems.core independent now
|
||||
if (dragObject instanceof IRemoteFile)
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Object dragObject = iterator.next();
|
||||
if (dragObject instanceof IAdaptable)
|
||||
{
|
||||
IRemoteFile file = (IRemoteFile) dragObject;
|
||||
|
||||
String connectionType = file.getParentRemoteFileSubSystem().getHost().getSystemType().getName();
|
||||
if (connectionType.equals("Local"))
|
||||
ISystemViewElementAdapter adapter = (ISystemViewElementAdapter) ((IAdaptable) dragObject).getAdapter(ISystemViewElementAdapter.class);
|
||||
if (adapter.canDrag(dragObject))
|
||||
{
|
||||
fileNames[i] = file.getAbsolutePath();
|
||||
i++;
|
||||
IResource resource = getResource((IAdaptable)dragObject);
|
||||
if (resource != null)
|
||||
{
|
||||
String fileName = resource.getLocation().toOSString();
|
||||
fileNames[i] = fileName;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
//}
|
||||
}
|
||||
if (i > 0)
|
||||
{
|
||||
event.data = fileNames;
|
||||
|
@ -346,4 +351,68 @@ public class SystemViewDataDragAdapter extends DragSourceAdapter
|
|||
IEditorRegistry registry = getEditorRegistry();
|
||||
return registry.findEditor("org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
private IResource getResource(IAdaptable dragObject)
|
||||
{
|
||||
IResource resource = null;
|
||||
ISystemViewElementAdapter viewAdapter = (ISystemViewElementAdapter) dragObject.getAdapter(ISystemViewElementAdapter.class);
|
||||
ISystemRemoteElementAdapter remoteAdapter = (ISystemRemoteElementAdapter)dragObject.getAdapter(ISystemRemoteElementAdapter.class);
|
||||
|
||||
if (remoteAdapter != null)
|
||||
{
|
||||
|
||||
if (remoteAdapter.canEdit(dragObject))
|
||||
{
|
||||
ISystemEditableRemoteObject editable = remoteAdapter.getEditableRemoteObject(dragObject);
|
||||
// corresponds to a file
|
||||
IFile file = editable.getLocalResource();
|
||||
if (!file.exists())
|
||||
{
|
||||
// this is a drag and drop to windows explorer
|
||||
// because we're dealing with file paths we need to force this to complete before allowing the drop
|
||||
// so instead of doing the job, I'm forcing the transfer on this thread
|
||||
LazyDownloadJob job = new LazyDownloadJob(editable);
|
||||
job.run(new NullProgressMonitor());
|
||||
//job.setPriority(Job.INTERACTIVE);
|
||||
//job.schedule();
|
||||
}
|
||||
resource = file;
|
||||
}
|
||||
else if (viewAdapter != null)
|
||||
{
|
||||
if (viewAdapter.hasChildren(dragObject))
|
||||
{
|
||||
IContainer parentFolder = null;
|
||||
// corresponds to a folder
|
||||
Object[] children = viewAdapter.getChildren(new NullProgressMonitor(), dragObject);
|
||||
for (int i = 0; i < children.length; i++)
|
||||
{
|
||||
IAdaptable child = (IAdaptable)children[i];
|
||||
IResource childResource = getResource(child);
|
||||
if (childResource != null)
|
||||
{
|
||||
parentFolder = childResource.getParent();
|
||||
if (!parentFolder.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
parentFolder.touch(new NullProgressMonitor());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource = parentFolder;
|
||||
}
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation. All rights reserved.
|
||||
* This program and the accompanying materials are made available under the terms
|
||||
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
|
||||
* available at http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Initial Contributors:
|
||||
* The following IBM employees contributed to the Remote System Explorer
|
||||
* component that contains this file: David McKnight.
|
||||
*
|
||||
* Contributors:
|
||||
* {Name} (company) - description of contribution.
|
||||
********************************************************************************/
|
||||
package org.eclipse.rse.ui.actions;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||
|
||||
public class LazyDownloadJob extends Job
|
||||
{
|
||||
private ISystemEditableRemoteObject _editable;
|
||||
public LazyDownloadJob(ISystemEditableRemoteObject editable)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
super("Downloading " + editable.getAbsolutePath());
|
||||
_editable = editable;
|
||||
}
|
||||
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editable.download(monitor);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
|
@ -22,11 +22,7 @@ import org.eclipse.core.resources.IContainer;
|
|||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.rse.core.model.IHost;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
|
@ -58,30 +54,6 @@ import org.eclipse.ui.part.ResourceTransfer;
|
|||
*/
|
||||
public class SystemCopyToClipboardAction extends SystemBaseAction implements IValidatorRemoteSelection
|
||||
{
|
||||
private class LazyDownloadJob extends Job
|
||||
{
|
||||
private ISystemEditableRemoteObject _editable;
|
||||
public LazyDownloadJob(ISystemEditableRemoteObject editable)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
super("Downloading " + editable.getAbsolutePath());
|
||||
_editable = editable;
|
||||
}
|
||||
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
{
|
||||
try
|
||||
{
|
||||
_editable.download(monitor);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
|
||||
private IStructuredSelection _selection;
|
||||
private Clipboard _clipboard;
|
||||
private boolean _doResourceTransfer = true; //experiment
|
||||
|
@ -216,23 +188,16 @@ public class SystemCopyToClipboardAction extends SystemBaseAction implements IV
|
|||
|
||||
if (_doResourceTransfer)
|
||||
{
|
||||
resources.add(getResource((IAdaptable)dragObject));
|
||||
IResource resource = getResource((IAdaptable)dragObject);
|
||||
if (resource != null)
|
||||
{
|
||||
resources.add(resource);
|
||||
|
||||
String fileName = resource.getLocation().toOSString();
|
||||
fileNames.add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/** FIXME - files can't be coupled to systems.core!
|
||||
// support for external copy for local files
|
||||
if (dragObject instanceof IRemoteFile)
|
||||
{
|
||||
IRemoteFile file = (IRemoteFile) dragObject;
|
||||
|
||||
String connectionType = file.getParentRemoteFileSubSystem().getHost().getSystemType().getName();
|
||||
|
||||
if (connectionType.equals("Local"))
|
||||
{
|
||||
fileNames.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -248,14 +213,16 @@ public class SystemCopyToClipboardAction extends SystemBaseAction implements IV
|
|||
{
|
||||
ft[i] = (IResource) resources.get(i);
|
||||
}
|
||||
|
||||
String[] fn = new String[fileNames.size()];
|
||||
for (int j = 0; j < fn.length; j++)
|
||||
{
|
||||
fn[j] = (String)fileNames.get(j);
|
||||
}
|
||||
|
||||
_clipboard.setContents(new Object[] { data, ft, textStream.toString() }, new Transfer[] { PluginTransfer.getInstance(), ResourceTransfer.getInstance(), TextTransfer.getInstance()});
|
||||
_clipboard.setContents(new Object[] { data, ft, fn, textStream.toString() }, new Transfer[] { PluginTransfer.getInstance(), ResourceTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance()});
|
||||
|
||||
}
|
||||
else if (fileNames.size() == 0)
|
||||
{
|
||||
_clipboard.setContents(new Object[] { data, textStream.toString() }, new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance()});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String[] ft = new String[fileNames.size()];
|
||||
|
|
|
@ -814,7 +814,7 @@ public class SystemTableView
|
|||
protected void initDragAndDrop()
|
||||
{
|
||||
int ops = DND.DROP_COPY | DND.DROP_MOVE;
|
||||
Transfer[] dragtransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
Transfer[] dragtransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
Transfer[] droptransfers = new Transfer[] { PluginTransfer.getInstance(), TextTransfer.getInstance(), FileTransfer.getInstance(), EditorInputTransfer.getInstance()};
|
||||
|
||||
addDragSupport(ops, dragtransfers, new SystemViewDataDragAdapter((ISelectionProvider) this));
|
||||
|
|
Loading…
Add table
Reference in a new issue