mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +02:00
Bug 160788 fix and additional changes to make "open with->" occur as cancellable job
This commit is contained in:
parent
1cd962c374
commit
07421cba57
5 changed files with 131 additions and 16 deletions
|
@ -29,9 +29,13 @@ import org.eclipse.jface.viewers.IStructuredSelection;
|
|||
import org.eclipse.rse.core.SystemBasePlugin;
|
||||
import org.eclipse.rse.files.ui.FileResources;
|
||||
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
|
||||
import org.eclipse.rse.files.ui.resources.SystemIFileProperties;
|
||||
import org.eclipse.rse.files.ui.resources.UniversalFileTransferUtility;
|
||||
import org.eclipse.rse.files.ui.view.DownloadJob;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
|
||||
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
|
||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
|
@ -173,19 +177,93 @@ protected void createMenuItem(Menu menu, final IEditorDescriptor descriptor, fin
|
|||
}
|
||||
|
||||
|
||||
protected void openEditor(IRemoteFile file, IEditorDescriptor descriptor)
|
||||
protected void openEditor(IRemoteFile remoteFile, IEditorDescriptor descriptor)
|
||||
{
|
||||
SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(file, descriptor.getId());
|
||||
if (descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID))
|
||||
|
||||
SystemEditableRemoteFile editable = null;
|
||||
if (descriptor == null)
|
||||
{
|
||||
editableFile.openInSystemEditor(SystemBasePlugin.getActiveWorkbenchShell());
|
||||
editable = new SystemEditableRemoteFile(remoteFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
editable = new SystemEditableRemoteFile(remoteFile, descriptor.getId());
|
||||
}
|
||||
boolean systemEditor = descriptor != null && descriptor.getId().equals(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
|
||||
|
||||
|
||||
if (isFileCached(editable, remoteFile))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (systemEditor)
|
||||
{
|
||||
editable.openSystemEditor();
|
||||
}
|
||||
else
|
||||
{
|
||||
editable.openEditor();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadJob oJob = new DownloadJob(editable, systemEditor);
|
||||
oJob.schedule();
|
||||
}
|
||||
|
||||
/*
|
||||
else
|
||||
{
|
||||
editableFile.open(SystemBasePlugin.getActiveWorkbenchShell());
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
private boolean isFileCached(ISystemEditableRemoteObject editable, IRemoteFile remoteFile)
|
||||
{
|
||||
// DY: check if the file exists and is read-only (because it was previously opened
|
||||
// in the system editor)
|
||||
IFile file = editable.getLocalResource();
|
||||
SystemIFileProperties properties = new SystemIFileProperties(file);
|
||||
boolean newFile = !file.exists();
|
||||
|
||||
// detect whether there exists a temp copy already
|
||||
if (!newFile && file.exists())
|
||||
{
|
||||
// we have a local copy of this file, so we need to compare timestamps
|
||||
|
||||
// get stored modification stamp
|
||||
long storedModifiedStamp = properties.getRemoteFileTimeStamp();
|
||||
|
||||
// get updated remoteFile so we get the current remote timestamp
|
||||
//remoteFile.markStale(true);
|
||||
IRemoteFileSubSystem subsystem = remoteFile.getParentRemoteFileSubSystem();
|
||||
try
|
||||
{
|
||||
remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// get the remote modified stamp
|
||||
long remoteModifiedStamp = remoteFile.getLastModified();
|
||||
|
||||
// get dirty flag
|
||||
boolean dirty = properties.getDirty();
|
||||
|
||||
boolean remoteNewer = (storedModifiedStamp != remoteModifiedStamp);
|
||||
return (!dirty && !remoteNewer);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local cache of the remote file, or <code>null</code> if none.
|
||||
|
@ -224,8 +302,14 @@ protected IEditorDescriptor getDefaultEditor(IRemoteFile remoteFile)
|
|||
if (localFile == null) {
|
||||
return registry.getDefaultEditor(remoteFile.getName());
|
||||
}
|
||||
else {
|
||||
return IDE.getDefaultEditor(localFile);
|
||||
else
|
||||
{
|
||||
IEditorDescriptor descriptor = IDE.getDefaultEditor(localFile);
|
||||
if (descriptor == null)
|
||||
{
|
||||
descriptor = getDefaultTextEditor();
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
|
||||
private Exception e;
|
||||
private boolean completed = false;
|
||||
|
||||
private boolean failed = false;
|
||||
|
||||
/**
|
||||
* Constructor for InternalDownloadFileRunnable
|
||||
*/
|
||||
|
@ -117,7 +118,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
|
||||
try
|
||||
{
|
||||
completed = SystemEditableRemoteFile.this.download(monitor);
|
||||
failed = !SystemEditableRemoteFile.this.download(monitor);
|
||||
completed = true;
|
||||
monitor.done();
|
||||
}
|
||||
catch (CoreException e)
|
||||
|
@ -145,6 +147,11 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
{
|
||||
return completed;
|
||||
}
|
||||
|
||||
public boolean didFail()
|
||||
{
|
||||
return failed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the exception that may have been thrown
|
||||
|
@ -467,7 +474,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
|
||||
listener.removeIgnoreFile(localFile);
|
||||
downloadFileRunnable.throwException();
|
||||
return downloadFileRunnable.didComplete();
|
||||
return !downloadFileRunnable.didFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -591,6 +598,10 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
}
|
||||
|
||||
subsystem.downloadUTF8(remoteFile, localPath, monitor);
|
||||
if (monitor.isCanceled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get fresh remote file object
|
||||
remoteFile = subsystem.getRemoteFileObject(remoteFile.getAbsolutePath());
|
||||
|
@ -1493,7 +1504,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
|
|||
/**
|
||||
* Open the system editor
|
||||
*/
|
||||
private void openSystemEditor() throws PartInitException
|
||||
public void openSystemEditor() throws PartInitException
|
||||
{
|
||||
IWorkbenchPage activePage = this.page;
|
||||
if (activePage == null)
|
||||
|
|
|
@ -21,6 +21,7 @@ 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.files.ui.resources.SystemEditableRemoteFile;
|
||||
import org.eclipse.rse.files.ui.resources.SystemUniversalTempFileListener;
|
||||
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
@ -30,9 +31,11 @@ public class DownloadJob extends Job
|
|||
public static class OpenEditorRunnable implements Runnable
|
||||
{
|
||||
private ISystemEditableRemoteObject _editable;
|
||||
public OpenEditorRunnable(ISystemEditableRemoteObject editable)
|
||||
private boolean _systemEditor;
|
||||
public OpenEditorRunnable(ISystemEditableRemoteObject editable, boolean systemEditor)
|
||||
{
|
||||
_editable = editable;
|
||||
_systemEditor = systemEditor;
|
||||
}
|
||||
|
||||
public void run()
|
||||
|
@ -41,7 +44,14 @@ public class DownloadJob extends Job
|
|||
{
|
||||
_editable.addAsListener();
|
||||
_editable.setLocalResourceProperties();
|
||||
_editable.openEditor();
|
||||
if (_systemEditor)
|
||||
{
|
||||
((SystemEditableRemoteFile)_editable).openSystemEditor();
|
||||
}
|
||||
else
|
||||
{
|
||||
_editable.openEditor();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -52,10 +62,12 @@ public class DownloadJob extends Job
|
|||
}
|
||||
|
||||
private ISystemEditableRemoteObject _editable;
|
||||
public DownloadJob(ISystemEditableRemoteObject editable)
|
||||
private boolean _systemEditor;
|
||||
public DownloadJob(ISystemEditableRemoteObject editable, boolean systemEditor)
|
||||
{
|
||||
super("Download");
|
||||
_editable = editable;
|
||||
_systemEditor = systemEditor;
|
||||
}
|
||||
|
||||
public IStatus run(IProgressMonitor monitor)
|
||||
|
@ -71,8 +83,11 @@ public class DownloadJob extends Job
|
|||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
OpenEditorRunnable oe = new OpenEditorRunnable(_editable);
|
||||
Display.getDefault().asyncExec(oe);
|
||||
if (!monitor.isCanceled())
|
||||
{
|
||||
OpenEditorRunnable oe = new OpenEditorRunnable(_editable, _systemEditor);
|
||||
Display.getDefault().asyncExec(oe);
|
||||
}
|
||||
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
|
|
@ -2738,7 +2738,7 @@ public class SystemViewRemoteFileAdapter
|
|||
}
|
||||
else
|
||||
{
|
||||
DownloadJob oJob = new DownloadJob(editable);
|
||||
DownloadJob oJob = new DownloadJob(editable, false);
|
||||
oJob.schedule();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -454,6 +454,11 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
|
|||
SystemMessageDialog dlg = new SystemMessageDialog(getShell(), e.getSystemMessage());
|
||||
dlg.open();
|
||||
}
|
||||
|
||||
if (monitor.isCanceled())
|
||||
{
|
||||
localFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isBinary(String localEncoding, String hostEncoding, String remotePath)
|
||||
|
|
Loading…
Add table
Reference in a new issue