mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-09 10:05:24 +02:00
[160353] get rid of readAndDispatch for "open" action
This commit is contained in:
parent
68a11aebef
commit
5dd0e867cc
2 changed files with 153 additions and 7 deletions
|
@ -16,13 +16,18 @@
|
||||||
|
|
||||||
package org.eclipse.rse.files.ui.actions;
|
package org.eclipse.rse.files.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.rse.core.SystemBasePlugin;
|
import org.eclipse.rse.core.SystemBasePlugin;
|
||||||
import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants;
|
import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants;
|
||||||
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
|
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
|
||||||
|
import org.eclipse.rse.files.ui.resources.SystemIFileProperties;
|
||||||
|
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.IRemoteFile;
|
||||||
|
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
|
||||||
import org.eclipse.rse.ui.actions.SystemBaseAction;
|
import org.eclipse.rse.ui.actions.SystemBaseAction;
|
||||||
|
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,13 +82,83 @@ public class SystemEditFileAction extends SystemBaseAction implements ISystemRem
|
||||||
process((IRemoteFile)element);
|
process((IRemoteFile)element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the object: download file, open in editor, etc.
|
* Process the object: download file, open in editor, etc.
|
||||||
*/
|
*/
|
||||||
protected void process(IRemoteFile remoteFile) {
|
protected void process(IRemoteFile remoteFile) {
|
||||||
|
|
||||||
|
/*
|
||||||
SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, _editorId);
|
SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, _editorId);
|
||||||
editableFile.open(SystemBasePlugin.getActiveWorkbenchShell());
|
editableFile.open(SystemBasePlugin.getActiveWorkbenchShell());
|
||||||
|
*/
|
||||||
|
SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, _editorId);
|
||||||
|
if (editable != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.OPEN_IN_SAME_PERSPECTIVE)
|
||||||
|
{
|
||||||
|
if (isFileCached(editable, remoteFile))
|
||||||
|
{
|
||||||
|
editable.openEditor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DownloadJob oJob = new DownloadJob(editable, false);
|
||||||
|
oJob.schedule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
editable.setLocalResourceProperties();
|
||||||
|
editable.openEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,12 +20,15 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.rse.core.SystemBasePlugin;
|
|
||||||
import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants;
|
import org.eclipse.rse.files.ui.resources.ISystemRemoteEditConstants;
|
||||||
import org.eclipse.rse.files.ui.resources.SystemEditableRemoteFile;
|
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.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.IRemoteFile;
|
||||||
|
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
|
||||||
import org.eclipse.rse.ui.actions.SystemBaseAction;
|
import org.eclipse.rse.ui.actions.SystemBaseAction;
|
||||||
|
import org.eclipse.rse.ui.view.ISystemEditableRemoteObject;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.ui.IEditorDescriptor;
|
import org.eclipse.ui.IEditorDescriptor;
|
||||||
import org.eclipse.ui.IEditorRegistry;
|
import org.eclipse.ui.IEditorRegistry;
|
||||||
|
@ -98,21 +101,89 @@ public class SystemEditFilesAction extends SystemBaseAction implements ISystemRe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process the object: download file, open in editor, etc.
|
* Process the object: download file, open in editor, etc.
|
||||||
*/
|
*/
|
||||||
protected void process(IRemoteFile remoteFile)
|
protected void process(IRemoteFile remoteFile) {
|
||||||
{
|
|
||||||
String editorId = null;
|
String editorId = null;
|
||||||
IEditorDescriptor des = getDefaultEditor(remoteFile);
|
IEditorDescriptor des = getDefaultEditor(remoteFile);
|
||||||
if (des != null)
|
if (des != null)
|
||||||
{
|
{
|
||||||
editorId = des.getId();
|
editorId = des.getId();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
SystemEditableRemoteFile editableFile = new SystemEditableRemoteFile(remoteFile, editorId);
|
{
|
||||||
editableFile.open(SystemBasePlugin.getActiveWorkbenchShell());
|
editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemEditableRemoteFile editable = new SystemEditableRemoteFile(remoteFile, editorId);
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (editable.checkOpenInEditor() != ISystemEditableRemoteObject.OPEN_IN_SAME_PERSPECTIVE)
|
||||||
|
{
|
||||||
|
if (isFileCached(editable, remoteFile))
|
||||||
|
{
|
||||||
|
editable.openEditor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DownloadJob oJob = new DownloadJob(editable, false);
|
||||||
|
oJob.schedule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
editable.setLocalResourceProperties();
|
||||||
|
editable.openEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue