1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 20:15:22 +02:00

[310215] SystemEditableRemoteFile.open does not behave as expected

This commit is contained in:
David McKnight 2010-06-23 14:11:56 +00:00
parent fdd5f9a1c3
commit 405af14b8c

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2002, 2009 IBM Corporation and others. * Copyright (c) 2002, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -38,6 +38,7 @@
* David McKnight (IBM) - [267247] Wrong encoding * David McKnight (IBM) - [267247] Wrong encoding
* David McKnight (IBM) - [272772] Exception handling in SystemEditableRemoteFile * David McKnight (IBM) - [272772] Exception handling in SystemEditableRemoteFile
* David McKnight (IBM) - [284420] nullprogressmonitor is needed * David McKnight (IBM) - [284420] nullprogressmonitor is needed
* David McKnight (IBM) - [310215] SystemEditableRemoteFile.open does not behave as expected
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.files.ui.resources; package org.eclipse.rse.files.ui.resources;
@ -1152,7 +1153,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
if (download(shell)) if (download(shell))
{ {
setLocalResourceProperties(); setLocalResourceProperties();
openEditor(); setFileAsReadOnly();
openEditor(remoteFile, readOnly);
setEditorAsReadOnly(); setEditorAsReadOnly();
} }
} }
@ -1162,7 +1164,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
{ {
addAsListener(); addAsListener();
setLocalResourceProperties(); setLocalResourceProperties();
openEditor(); openEditor(remoteFile, readOnly);
} }
} }
else else
@ -1188,8 +1190,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
if (download(shell)) if (download(shell))
{ {
setLocalResourceProperties(); setLocalResourceProperties();
setReadOnly(getLocalResource(), true); setFileAsReadOnly();
openEditor(); openEditor(remoteFile, readOnly);
setEditorAsReadOnly(); setEditorAsReadOnly();
} }
} }
@ -1197,7 +1199,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
} }
else if (result == OPEN_IN_SAME_PERSPECTIVE) else if (result == OPEN_IN_SAME_PERSPECTIVE)
{ {
openEditor(); openEditor(remoteFile, readOnly);
} }
else if (result == OPEN_IN_DIFFERENT_PERSPECTIVE) else if (result == OPEN_IN_DIFFERENT_PERSPECTIVE)
{ {
@ -1213,7 +1215,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
if (answer) if (answer)
{ {
openEditor(); setFileAsReadOnly();
openEditor(remoteFile, readOnly);
setEditorAsReadOnly(); // put editor in read only mode, but not file setEditorAsReadOnly(); // put editor in read only mode, but not file
} }
} }
@ -1282,7 +1285,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
if (download(monitor)) if (download(monitor))
{ {
setLocalResourceProperties(); setLocalResourceProperties();
openEditor(); setFileAsReadOnly();
openEditor(remoteFile, readOnly);
setEditorAsReadOnly(); setEditorAsReadOnly();
} }
} }
@ -1292,7 +1296,7 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
{ {
addAsListener(); addAsListener();
setLocalResourceProperties(); setLocalResourceProperties();
openEditor(); openEditor(remoteFile, readOnly);
} }
} }
else else
@ -1320,8 +1324,8 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
if (download(monitor)) if (download(monitor))
{ {
setLocalResourceProperties(); setLocalResourceProperties();
setReadOnly(getLocalResource(), true); setFileAsReadOnly();
openEditor(); openEditor(remoteFile, readOnly);
setEditorAsReadOnly(); setEditorAsReadOnly();
} }
} }
@ -1586,14 +1590,6 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
*/ */
public void openEditor() throws PartInitException public void openEditor() throws PartInitException
{ {
IWorkbenchPage activePage = this.page;
IWorkbench wb = PlatformUI.getWorkbench();
if (activePage == null)
{
activePage = wb.getActiveWorkbenchWindow().getActivePage();
}
IFile file = getLocalResource();
// get fresh remote file object // get fresh remote file object
remoteFile.markStale(true); // make sure we get the latest remote file (with proper permissions and all) remoteFile.markStale(true); // make sure we get the latest remote file (with proper permissions and all)
if (!remoteFile.getParentRemoteFileSubSystem().isOffline()){ if (!remoteFile.getParentRemoteFileSubSystem().isOffline()){
@ -1608,6 +1604,22 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
} }
} }
boolean readOnly = !remoteFile.canWrite(); boolean readOnly = !remoteFile.canWrite();
openEditor(remoteFile, readOnly);
}
/**
* Method to open the editor given an IRemoteFile and a specified readOnly property.
*/
private void openEditor(IRemoteFile remoteFile, boolean readOnly) throws PartInitException
{
IWorkbenchPage activePage = this.page;
IWorkbench wb = PlatformUI.getWorkbench();
if (activePage == null)
{
activePage = wb.getActiveWorkbenchWindow().getActivePage();
}
IFile file = getLocalResource();
ResourceAttributes attr = file.getResourceAttributes(); ResourceAttributes attr = file.getResourceAttributes();
if (attr!=null) { if (attr!=null) {
attr.setReadOnly(readOnly); attr.setReadOnly(readOnly);
@ -1622,7 +1634,6 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
} }
// set editor as preferred editor for this file // set editor as preferred editor for this file
String editorId = null; String editorId = null;
if (_editorDescriptor != null) if (_editorDescriptor != null)
editorId = _editorDescriptor.getId(); editorId = _editorDescriptor.getId();
@ -1698,6 +1709,10 @@ public class SystemEditableRemoteFile implements ISystemEditableRemoteObject, IP
{ {
((ISystemTextEditor) editor).setReadOnly(true); ((ISystemTextEditor) editor).setReadOnly(true);
} }
}
private void setFileAsReadOnly()
{
IFile file = getLocalResource(); IFile file = getLocalResource();
setReadOnly(file, true); setReadOnly(file, true);