1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-03 23:25:26 +02:00

[api] [163820] Allow encodings to be queried for IRemoteFile and implementations for encodings through a remote file encoding manager.

This commit is contained in:
Kushal Munir 2007-02-06 15:23:19 +00:00
parent 51ae4ccdf6
commit e7d2f267ca
8 changed files with 101 additions and 17 deletions

View file

@ -33,6 +33,7 @@ import org.eclipse.rse.ui.propertypages.SystemBasePropertyPage;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
@ -52,9 +53,15 @@ public class SystemFilePropertyPage extends SystemBasePropertyPage
//protected Button cbReadablePrompt, cbWritablePrompt;
protected Button cbReadonlyPrompt, cbHiddenPrompt;
protected Label labelName, labelType, labelPath, labelSize, labelModified, labelReadable, labelWritable, labelHidden;
protected Button inheritedEncodingButton, otherEncodingButton;
protected Combo otherEncodingCombo;
protected String errorMessage;
protected boolean initDone = false;
protected boolean wasReadOnly = false;
private boolean encodingFieldAdded = false;
private String defaultEncoding = null;
private boolean isValidBefore = true;
/**
* Constructor for SystemFilterPropertyPage

View file

@ -61,6 +61,7 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
private int _bufferUploadSize = IUniversalDataStoreConstants.BUFFER_SIZE;
private int _bufferDownloadSize = IUniversalDataStoreConstants.BUFFER_SIZE;
protected ISystemFileTypes _fileTypeRegistry;
private String remoteEncoding;
private static String _percentMsg = SystemMessage.sub(SystemMessage.sub(SystemMessage.sub(ServiceResources.DStore_Service_Percent_Complete_Message, "&0", "{0}"), "&1", "{1}"), "&2", "{2}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
@ -1274,6 +1275,26 @@ public class DStoreFileService extends AbstractDStoreService implements IFileSer
return false;
}
/**
* Queries the remote system for the platform encoding.
* @see org.eclipse.rse.services.files.IFileService#getEncoding(org.eclipse.core.runtime.IProgressMonitor)
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException {
if (remoteEncoding == null) {
DataStore ds = getDataStore();
DataElement encodingElement = ds.createObject(null, UNIVERSAL_TEMP_DESCRIPTOR, ""); //$NON-NLS-1$
DataElement queryCmd = ds.localDescriptorQuery(encodingElement.getDescriptor(), C_SYSTEM_ENCODING);
DataElement status = ds.command(queryCmd, encodingElement, true);
remoteEncoding = encodingElement.getValue();
}
return remoteEncoding;
}
}

View file

@ -88,8 +88,6 @@ public class LocalFileService extends AbstractFileService implements IFileServic
public LocalFileService(ISystemFileTypes fileTypeRegistry)
{
_fileTypeRegistry = fileTypeRegistry;
}

View file

@ -93,6 +93,13 @@ public abstract class AbstractFileService implements IFileService
}
return ok;
}
/**
* Returns the local platform encoding by default. Subclasses should override to return the actual remote encoding.
* @see org.eclipse.rse.services.files.IFileService#getEncoding(org.eclipse.core.runtime.IProgressMonitor)
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException {
return System.getProperty("file.encoding");
}
}

View file

@ -284,4 +284,13 @@ public interface IFileService extends IService
* @return true if the readonly permission was changed successfully
*/
public boolean setReadOnly(IProgressMonitor monitor, String parent, String name, boolean readOnly) throws SystemMessageException;
/**
* Gets the remote encoding.
* @param monitor the progress monitor.
* @return the encoding.
* @throws SystemMessageException if an error occurs.
* @since 2.0
*/
public String getEncoding(IProgressMonitor monitor) throws SystemMessageException;
}

View file

@ -118,13 +118,6 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
{
return _hostFileToRemoteFileAdapter;
}
public String getRemoteEncoding()
{
return System.getProperty("file.encoding"); //$NON-NLS-1$
}
public void setHostFileToRemoteFileAdapter(IHostFileToRemoteFileAdapter hostFileAdapter)
{
@ -899,4 +892,22 @@ public final class FileServiceSubSystem extends RemoteFileSubSystem implements I
_userHome = null;
}
}
/**
* Returns the encoding from the file service being used by this subsystem.
* @see RemoteFileSubSystem#getRemoteEncoding()
*/
public String getRemoteEncoding() {
String encoding = null;
try {
encoding = getFileService().getEncoding(null);
}
catch (SystemMessageException e) {
SystemMessageDialog dlg = new SystemMessageDialog(getShell(), e.getSystemMessage());
dlg.open();
encoding = super.getRemoteEncoding();
}
return encoding;
}
}

View file

@ -212,14 +212,30 @@ public interface IRemoteFileSubSystem extends ISubSystem{
* Given a folder or file, return its parent folder name, fully qualified
* @param folderOrFile folder or file to return parent of.
*/
public String getParentFolderName(IRemoteFile folderOrFile);
public String getParentFolderName(IRemoteFile folderOrFile);
/**
* Returns whether the file subsystem supports encodings. There are file subsystems that deal with codepages and encodings
* using other mechanisms besides encodings, and such platforms should return <code>false</code>. Other file subsystems
* may not deal with encodings at all.
* @return <code>true<code> if the file subsystem supports encodings, <code>false</code> otherwise.
* @since 2.0
*/
public boolean supportsEncoding();
/**
* Get the default encoding of the target system
* @return the encoding
* Returns the encoding of the remote system.
* @return the encoding of the remote system.
*/
public String getRemoteEncoding();
/**
* Returns the encoding of the file with the remote path.
* @param remotePath the remote path of the file.
* @return the encoding of the remote file.
*/
// public String getEncoding(String remotePath);
/**
* Given a set of fully qualified file or folder names, return an ISystemResourceSet object for it.
* @param folderOrFileNames Fully qualified folder or file names

View file

@ -1742,8 +1742,6 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
return null;
}
/**
* @deprecated
*/
@ -1752,4 +1750,21 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
// TODO Auto-generated method stub
}
/**
* Returns <code>true</code> by default. Subclasses should override if they do not support encodings.
* @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#supportsEncoding()
* @since 2.0
*/
public boolean supportsEncoding() {
return true;
}
/**
* Returns the local platform encoding by default. Subclasses should override to return the actual remote encoding.
* @see org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem#getRemoteEncoding()
*/
public String getRemoteEncoding() {
return System.getProperty("file.encoding");
}
}